110110
111111function parse_variable_def! (dict, mod, arg, varclass, kwargs;
112112 def = nothing , indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing ,
113- type:: Union{ Type, Nothing} = nothing )
113+ type:: Type = Real )
114114 metatypes = [(:connection_type , VariableConnectType),
115115 (:description , VariableDescription),
116116 (:unit , VariableUnit),
@@ -133,7 +133,7 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs;
133133 else
134134 push! (kwargs, Expr (:kw , Expr (:(:: ), a, Union{Nothing, type}), nothing ))
135135 end
136- var = generate_var! (dict, a, varclass; indices)
136+ var = generate_var! (dict, a, varclass; indices, type )
137137 dict[:kwargs ][getname (var)] = Dict (:value => def, :type => type)
138138 (var, def)
139139 end
@@ -153,15 +153,15 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs;
153153 else
154154 push! (kwargs, Expr (:kw , Expr (:(:: ), a, Union{Nothing, type}), nothing ))
155155 end
156- var = generate_var! (dict, a, b, varclass; indices)
156+ var = generate_var! (dict, a, b, varclass; indices, type )
157157 type != = nothing && (dict[varclass][getname (var)][:type ] = type)
158158 dict[:kwargs ][getname (var)] = Dict (:value => def, :type => type)
159159 (var, def)
160160 end
161161 Expr (:(= ), a, b) => begin
162162 Base. remove_linenums! (b)
163163 def, meta = parse_default (mod, b)
164- var, def = parse_variable_def! (dict, mod, a, varclass, kwargs; def)
164+ var, def = parse_variable_def! (dict, mod, a, varclass, kwargs; def, type )
165165 dict[varclass][getname (var)][:default ] = def
166166 if meta != = nothing
167167 for (type, key) in metatypes
@@ -179,7 +179,7 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs;
179179 (var, def)
180180 end
181181 Expr (:tuple , a, b) => begin
182- var, def = parse_variable_def! (dict, mod, a, varclass, kwargs)
182+ var, def = parse_variable_def! (dict, mod, a, varclass, kwargs; type )
183183 meta = parse_metadata (mod, b)
184184 if meta != = nothing
185185 for (type, key) in metatypes
@@ -200,34 +200,39 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs;
200200 Expr (:ref , a, b... ) => begin
201201 indices = map (i -> UnitRange (i. args[2 ], i. args[end ]), b)
202202 parse_variable_def! (dict, mod, a, varclass, kwargs;
203- def, indices)
203+ def, indices, type )
204204 end
205205 _ => error (" $arg cannot be parsed" )
206206 end
207207end
208208
209209function generate_var (a, varclass;
210- indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing )
211- var = indices === nothing ? Symbolics. variable (a) : first (@variables $ a[indices... ])
210+ indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing ,
211+ type = Real)
212+ var = indices === nothing ? Symbolics. variable (a; T = type) :
213+ first (@variables $ a[indices... ]:: type )
212214 if varclass == :parameters
213215 var = toparam (var)
214216 end
215217 var
216218end
217219
218220function generate_var! (dict, a, varclass;
219- indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing )
221+ indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing ,
222+ type = Real)
220223 vd = get! (dict, varclass) do
221224 Dict {Symbol, Dict{Symbol, Any}} ()
222225 end
223226 vd isa Vector && (vd = first (vd))
224227 vd[a] = Dict {Symbol, Any} ()
225228 indices != = nothing && (vd[a][:size ] = Tuple (lastindex .(indices)))
226- generate_var (a, varclass; indices)
229+ generate_var (a, varclass; indices, type )
227230end
228231
229232function generate_var! (dict, a, b, varclass;
230- indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing )
233+ indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing ,
234+ type = Real)
235+ # (type isa Nothing && type = Real)
231236 iv = generate_var (b, :variables )
232237 prev_iv = get! (dict, :independent_variable ) do
233238 iv
@@ -239,10 +244,10 @@ function generate_var!(dict, a, b, varclass;
239244 vd isa Vector && (vd = first (vd))
240245 vd[a] = Dict {Symbol, Any} ()
241246 var = if indices === nothing
242- Symbolics. variable (a, T = SymbolicUtils. FnType{Tuple{Any}, Real })(iv)
247+ Symbolics. variable (a, T = SymbolicUtils. FnType{Tuple{Any}, type })(iv)
243248 else
244249 vd[a][:size ] = Tuple (lastindex .(indices))
245- first (@variables $ a (iv)[indices... ])
250+ first (@variables $ a (iv)[indices... ]:: type )
246251 end
247252 if varclass == :parameters
248253 var = toparam (var)
0 commit comments