@@ -163,7 +163,7 @@ function update_kwargs_and_metadata!(dict, kwargs, a, def, indices, type, var,
163163 push! (kwargs,
164164 Expr (:kw , :($ a:: Union{Nothing, Missing, $NoValue, $type} ), NO_VALUE))
165165 end
166- dict[:kwargs ][getname (var) ] = Dict (:value => def, :type => type)
166+ dict[:kwargs ][a ] = Dict (:value => def, :type => type)
167167 else
168168 vartype = gensym (:T )
169169 push! (kwargs,
@@ -177,15 +177,71 @@ function update_kwargs_and_metadata!(dict, kwargs, a, def, indices, type, var,
177177 else
178178 push! (where_types, :($ vartype <: $type ))
179179 end
180- dict[:kwargs ][getname (var) ] = Dict (:value => def, :type => AbstractArray{type})
180+ dict[:kwargs ][a ] = Dict (:value => def, :type => AbstractArray{type})
181181 end
182182 if dict[varclass] isa Vector
183- dict[varclass][1 ][getname (var) ][:type ] = AbstractArray{type}
183+ dict[varclass][1 ][a ][:type ] = AbstractArray{type}
184184 else
185- dict[varclass][getname (var) ][:type ] = type
185+ dict[varclass][a ][:type ] = type
186186 end
187187end
188188
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+
189245function parse_variable_def! (dict, mod, arg, varclass, kwargs, where_types;
190246 def = nothing , indices:: Union{Vector{UnitRange{Int}}, Nothing} = nothing ,
191247 type:: Type = Real, meta = Dict {DataType, Expr} ())
0 commit comments