@@ -163,7 +163,7 @@ function update_kwargs_and_metadata!(dict, kwargs, a, def, indices, type, var,
163
163
push! (kwargs,
164
164
Expr (:kw , :($ a:: Union{Nothing, Missing, $NoValue, $type} ), NO_VALUE))
165
165
end
166
- dict[:kwargs ][getname (var) ] = Dict (:value => def, :type => type)
166
+ dict[:kwargs ][a ] = Dict (:value => def, :type => type)
167
167
else
168
168
vartype = gensym (:T )
169
169
push! (kwargs,
@@ -177,15 +177,71 @@ function update_kwargs_and_metadata!(dict, kwargs, a, def, indices, type, var,
177
177
else
178
178
push! (where_types, :($ vartype <: $type ))
179
179
end
180
- dict[:kwargs ][getname (var) ] = Dict (:value => def, :type => AbstractArray{type})
180
+ dict[:kwargs ][a ] = Dict (:value => def, :type => AbstractArray{type})
181
181
end
182
182
if dict[varclass] isa Vector
183
- dict[varclass][1 ][getname (var) ][:type ] = AbstractArray{type}
183
+ dict[varclass][1 ][a ][:type ] = AbstractArray{type}
184
184
else
185
- dict[varclass][getname (var) ][:type ] = type
185
+ dict[varclass][a ][:type ] = type
186
186
end
187
187
end
188
188
189
+ function update_readable_metadata! (varclass_dict, meta:: Dict , varname)
190
+ metatypes = [(:connection_type , VariableConnectType),
191
+ (:description , VariableDescription),
192
+ (:unit , VariableUnit),
193
+ (:bounds , VariableBounds),
194
+ (:noise , VariableNoiseType),
195
+ (:input , VariableInput),
196
+ (:output , VariableOutput),
197
+ (:irreducible , VariableIrreducible),
198
+ (:state_priority , VariableStatePriority),
199
+ (:misc , VariableMisc),
200
+ (:disturbance , VariableDisturbance),
201
+ (:tunable , VariableTunable),
202
+ (:dist , VariableDistribution)]
203
+
204
+ var_dict = get! (varclass_dict, varname) do
205
+ Dict {Symbol, Any} ()
206
+ end
207
+
208
+ for (type, key) in metatypes
209
+ if (mt = get (meta, key, nothing )) != = nothing
210
+ key == VariableConnectType && (mt = nameof (mt))
211
+ var_dict[type] = mt
212
+ end
213
+ end
214
+ end
215
+
216
+ function push_array_kwargs_and_metadata! (
217
+ dict, indices, meta, type, varclass, varname, varval)
218
+ dict[varclass] = get! (dict, varclass) do
219
+ Dict {Symbol, Dict{Symbol, Any}} ()
220
+ end
221
+ varclass_dict = dict[varclass] isa Vector ? Ref (dict[varclass][1 ]) : Ref (dict[varclass])
222
+
223
+ merge! (varclass_dict[],
224
+ Dict (varname => Dict (
225
+ :size => tuple ([index_arg. args[end ] for index_arg in indices]. .. ),
226
+ :value => varval,
227
+ :type => type
228
+ )))
229
+
230
+ # Useful keys for kwargs entry are: value, type and size.
231
+ dict[:kwargs ][varname] = varclass_dict[][varname]
232
+
233
+ meta != = nothing && update_readable_metadata! (varclass_dict[], meta, varname)
234
+ end
235
+
236
+ function unit_handled_variable_value (meta, varname)
237
+ varval = if meta isa Nothing || get (meta, VariableUnit, nothing ) isa Nothing
238
+ varname
239
+ else
240
+ :($ convert_units ($ (meta[VariableUnit]), $ varname))
241
+ end
242
+ return varval
243
+ end
244
+
189
245
function parse_variable_def! (dict, mod, arg, varclass, kwargs, where_types;
190
246
def = nothing , indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing ,
191
247
type:: Type = Real, meta = Dict {DataType, Expr} ())
0 commit comments