110
110
111
111
function parse_variable_def! (dict, mod, arg, varclass, kwargs;
112
112
def = nothing , indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing ,
113
- type:: Union{ Type, Nothing} = nothing )
113
+ type:: Type = Real )
114
114
metatypes = [(:connection_type , VariableConnectType),
115
115
(:description , VariableDescription),
116
116
(:unit , VariableUnit),
@@ -133,7 +133,7 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs;
133
133
else
134
134
push! (kwargs, Expr (:kw , Expr (:(:: ), a, Union{Nothing, type}), nothing ))
135
135
end
136
- var = generate_var! (dict, a, varclass; indices)
136
+ var = generate_var! (dict, a, varclass; indices, type )
137
137
dict[:kwargs ][getname (var)] = Dict (:value => def, :type => type)
138
138
(var, def)
139
139
end
@@ -153,15 +153,15 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs;
153
153
else
154
154
push! (kwargs, Expr (:kw , Expr (:(:: ), a, Union{Nothing, type}), nothing ))
155
155
end
156
- var = generate_var! (dict, a, b, varclass; indices)
156
+ var = generate_var! (dict, a, b, varclass; indices, type )
157
157
type != = nothing && (dict[varclass][getname (var)][:type ] = type)
158
158
dict[:kwargs ][getname (var)] = Dict (:value => def, :type => type)
159
159
(var, def)
160
160
end
161
161
Expr (:(= ), a, b) => begin
162
162
Base. remove_linenums! (b)
163
163
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 )
165
165
dict[varclass][getname (var)][:default ] = def
166
166
if meta != = nothing
167
167
for (type, key) in metatypes
@@ -179,7 +179,7 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs;
179
179
(var, def)
180
180
end
181
181
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 )
183
183
meta = parse_metadata (mod, b)
184
184
if meta != = nothing
185
185
for (type, key) in metatypes
@@ -200,34 +200,38 @@ function parse_variable_def!(dict, mod, arg, varclass, kwargs;
200
200
Expr (:ref , a, b... ) => begin
201
201
indices = map (i -> UnitRange (i. args[2 ], i. args[end ]), b)
202
202
parse_variable_def! (dict, mod, a, varclass, kwargs;
203
- def, indices)
203
+ def, indices, type )
204
204
end
205
205
_ => error (" $arg cannot be parsed" )
206
206
end
207
207
end
208
208
209
209
function 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) : first (@variables $ a[indices... ]:: type )
212
213
if varclass == :parameters
213
214
var = toparam (var)
214
215
end
215
216
var
216
217
end
217
218
218
219
function generate_var! (dict, a, varclass;
219
- indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing )
220
+ indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing ,
221
+ type = Real)
220
222
vd = get! (dict, varclass) do
221
223
Dict {Symbol, Dict{Symbol, Any}} ()
222
224
end
223
225
vd isa Vector && (vd = first (vd))
224
226
vd[a] = Dict {Symbol, Any} ()
225
227
indices != = nothing && (vd[a][:size ] = Tuple (lastindex .(indices)))
226
- generate_var (a, varclass; indices)
228
+ generate_var (a, varclass; indices, type )
227
229
end
228
230
229
231
function generate_var! (dict, a, b, varclass;
230
- indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing )
232
+ indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing ,
233
+ type = Real)
234
+ # (type isa Nothing && type = Real)
231
235
iv = generate_var (b, :variables )
232
236
prev_iv = get! (dict, :independent_variable ) do
233
237
iv
@@ -239,10 +243,10 @@ function generate_var!(dict, a, b, varclass;
239
243
vd isa Vector && (vd = first (vd))
240
244
vd[a] = Dict {Symbol, Any} ()
241
245
var = if indices === nothing
242
- Symbolics. variable (a, T = SymbolicUtils. FnType{Tuple{Any}, Real })(iv)
246
+ Symbolics. variable (a, T = SymbolicUtils. FnType{Tuple{Any}, type })(iv)
243
247
else
244
248
vd[a][:size ] = Tuple (lastindex .(indices))
245
- first (@variables $ a (iv)[indices... ])
249
+ first (@variables $ a (iv)[indices... ]:: type )
246
250
end
247
251
if varclass == :parameters
248
252
var = toparam (var)
0 commit comments