You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# - additional checks: when generating functions (constraints, dynamics, costs), there should not be any x or u left
7
6
# (but the user might indeed do so); meaning that has(ee, x/u/t) must be false (postcondition)
8
7
# - tests exceptions (parsing and semantics/runtime)
@@ -17,6 +16,13 @@ function set_prefix(p)
17
16
returnnothing
18
17
end
19
18
19
+
const E_PREFIX =Ref(:OptimalControl) # prefix for exceptions in generated code, assumed to be evaluated within OptimalControl.jl; can be CTBase for tests
20
+
21
+
functionset_e_prefix(p)
22
+
E_PREFIX[] = p
23
+
returnnothing
24
+
end
25
+
20
26
"""
21
27
$(TYPEDEF)
22
28
@@ -30,7 +36,7 @@ $(TYPEDEF)
30
36
tf::Union{Real,Symbol,Expr,Nothing}=nothing
31
37
x::Union{Symbol,Nothing}=nothing
32
38
u::Union{Symbol,Nothing}=nothing
33
-
is_scalar_x::Bool=false# todo: remove when allowing componentwise declaration of dynamics
39
+
is_scalar_x::Bool=false# todo: remove in future, when allowing componentwise declaration of dynamics
34
40
aliases::OrderedDict{Union{Symbol,Expr},Union{Real,Symbol,Expr}}=__init_aliases() # Dict ordered by Symbols *and Expr* just for scalar variable / state / control
35
41
lnum::Int=0
36
42
line::String=""
@@ -47,13 +53,13 @@ __init_aliases(; max_dim=20) = begin
47
53
al[:integral] =:∫
48
54
al[:(=>)] = :→
49
55
al[:in] = :∈
50
-
al
56
+
returnal
51
57
end
52
58
53
-
__throw(ex, n, line) =quote
54
-
local info
55
-
info =string("\nLine ", $n, ": ", $line)
56
-
throw(CTBase.ParsingError(info *"\n"*$ex))
59
+
__throw(mess, n, line) =begin
60
+
e_prefix = E_PREFIX[]
61
+
info =string("\nLine ", n, ": ", line, "\n", mess)
62
+
return :( throw($e_prefix.ParsingError($info)) )
57
63
end
58
64
59
65
__wrap(e, n, line) =quote
@@ -224,9 +230,6 @@ function p_alias!(p, p_ocp, a, e; log=false)
224
230
a isa Symbol ||return__throw("forbidden alias name: $a", p.lnum, p.line)
225
231
aa =QuoteNode(a)
226
232
ee =QuoteNode(e)
227
-
#for i in 1:9
228
-
# p.aliases[Symbol(a, CTBase.ctupperscripts(i))] = :($a^$i) # todo: remove? (cf. such aliases now removed for variable, state and control)
0 commit comments