@@ -158,7 +158,7 @@ function update_kwargs_and_metadata!(dict, kwargs, a, def, indices, type, var,
158158 else
159159 push! (kwargs, Expr (:kw , :($ a:: Union{Nothing, $type} ), nothing ))
160160 end
161- dict[:kwargs ][getname (var) ] = Dict (:value => def, :type => type)
161+ dict[:kwargs ][a ] = Dict (:value => def, :type => type)
162162 else
163163 vartype = gensym (:T )
164164 push! (kwargs,
@@ -171,15 +171,70 @@ function update_kwargs_and_metadata!(dict, kwargs, a, def, indices, type, var,
171171 else
172172 push! (where_types, :($ vartype <: $type ))
173173 end
174- dict[:kwargs ][getname (var) ] = Dict (:value => def, :type => AbstractArray{type})
174+ dict[:kwargs ][a ] = Dict (:value => def, :type => AbstractArray{type})
175175 end
176176 if dict[varclass] isa Vector
177- dict[varclass][1 ][getname (var) ][:type ] = AbstractArray{type}
177+ dict[varclass][1 ][a ][:type ] = AbstractArray{type}
178178 else
179- dict[varclass][getname (var) ][:type ] = type
179+ dict[varclass][a ][:type ] = type
180180 end
181181end
182182
183+ function update_readable_metadata! (varclass_dict, meta:: Dict , varname)
184+ metatypes = [(:connection_type , VariableConnectType),
185+ (:description , VariableDescription),
186+ (:unit , VariableUnit),
187+ (:bounds , VariableBounds),
188+ (:noise , VariableNoiseType),
189+ (:input , VariableInput),
190+ (:output , VariableOutput),
191+ (:irreducible , VariableIrreducible),
192+ (:state_priority , VariableStatePriority),
193+ (:misc , VariableMisc),
194+ (:disturbance , VariableDisturbance),
195+ (:tunable , VariableTunable),
196+ (:dist , VariableDistribution)]
197+
198+
199+ var_dict = get! (varclass_dict, varname) do
200+ Dict {Symbol, Any} ()
201+ end
202+
203+ for (type, key) in metatypes
204+ if (mt = get (meta, key, nothing )) != = nothing
205+ key == VariableConnectType && (mt = nameof (mt))
206+ var_dict[type] = mt
207+ end
208+ end
209+ end
210+
211+ function push_array_kwargs_and_metadata! (dict, indices, meta, type, varclass, varname, varval)
212+ dict[varclass] = get! (dict, varclass) do
213+ Dict {Symbol, Dict{Symbol, Any}} ()
214+ end
215+ varclass_dict = dict[varclass] isa Vector ? Ref (dict[varclass][1 ]) : Ref (dict[varclass])
216+
217+ merge! (varclass_dict[], Dict (varname => Dict (
218+ :size => tuple ([index_arg. args[end ] for index_arg in indices]. .. ),
219+ :value => varval,
220+ :type => type
221+ )))
222+
223+ # Useful keys for kwargs entry are: value, type and size.
224+ dict[:kwargs ][varname] = varclass_dict[][varname]
225+
226+ meta != = nothing && update_readable_metadata! (varclass_dict[], meta, varname)
227+ end
228+
229+ function unit_handled_variable_value (meta, varname)
230+ varval = if meta isa Nothing || get (meta, VariableUnit, nothing ) isa Nothing
231+ varname
232+ else
233+ :($ convert_units ($ (meta[VariableUnit]), $ varname))
234+ end
235+ return varval
236+ end
237+
183238function parse_variable_def! (dict, mod, arg, varclass, kwargs, where_types;
184239 def = nothing , indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing ,
185240 type:: Type = Real, meta = Dict {DataType, Expr} ())
0 commit comments