@@ -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,71 @@ 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+     var_dict =  get! (varclass_dict, varname) do 
199+         Dict {Symbol, Any} ()
200+     end 
201+ 
202+     for  (type, key) in  metatypes
203+         if  (mt =  get (meta, key, nothing )) != =  nothing 
204+             key ==  VariableConnectType &&  (mt =  nameof (mt))
205+             var_dict[type] =  mt
206+         end 
207+     end 
208+ end 
209+ 
210+ function  push_array_kwargs_and_metadata! (
211+         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[],
218+         Dict (varname =>  Dict (
219+             :size  =>  tuple ([index_arg. args[end ] for  index_arg in  indices]. .. ),
220+             :value  =>  varval,
221+             :type  =>  type
222+         )))
223+ 
224+     #  Useful keys for kwargs entry are: value, type and size.
225+     dict[:kwargs ][varname] =  varclass_dict[][varname]
226+ 
227+     meta != =  nothing  &&  update_readable_metadata! (varclass_dict[], meta, varname)
228+ end 
229+ 
230+ function  unit_handled_variable_value (meta, varname)
231+     varval =  if  meta isa  Nothing ||  get (meta, VariableUnit, nothing ) isa  Nothing
232+         varname
233+     else 
234+         :($ convert_units ($ (meta[VariableUnit]), $ varname))
235+     end 
236+     return  varval
237+ end 
238+ 
183239function  parse_variable_def! (dict, mod, arg, varclass, kwargs, where_types;
184240        def =  nothing , indices:: Union{Vector{UnitRange{Int}}, Nothing}  =  nothing ,
185241        type:: Type  =  Real, meta =  Dict {DataType, Expr} ())
0 commit comments