@@ -135,6 +135,7 @@ public
135135
136136 function fromCref
137137 input ComponentRef cref;
138+ input Attributes attr = NFAttributes . DEFAULT_ATTR ;
138139 input Binding binding = NFBinding . EMPTY_BINDING ;
139140 output Variable variable;
140141 protected
@@ -144,10 +145,10 @@ public
144145 SourceInfo info;
145146 algorithm
146147 node := ComponentRef . node(cref);
147- ty := ComponentRef . getSubscriptedType(cref, true );
148- vis := InstNode . visibility(node);
148+ ty := ComponentRef . getSubscriptedType(cref, true );
149+ vis := InstNode . visibility(node);
149150 info := InstNode . info(node);
150- variable := Variable . VARIABLE (cref, ty, binding, vis, NFAttributes . DEFAULT_ATTR , {}, {}, NONE (), info, NFBackendExtension . DUMMY_BACKEND_INFO );
151+ variable := Variable . VARIABLE (cref, ty, binding, vis, attr , {}, {}, NONE (), info, NFBackendExtension . DUMMY_BACKEND_INFO );
151152 end fromCref;
152153
153154 function makeVarPtrCyclic
@@ -533,7 +534,7 @@ public
533534 state := getVarPointer(cref);
534535 derNode := InstNode . VAR_NODE (DERIVATIVE_STR , dummy_ptr);
535536 der_cref := ComponentRef . append(cref, ComponentRef . fromNode(derNode, ComponentRef . scalarType(cref)));
536- var := fromCref(der_cref);
537+ var := fromCref(der_cref, Variable . attributes( Pointer . access(state)) );
537538 var . backendinfo := BackendExtension . BackendInfo . setVarKind(var . backendinfo, BackendExtension . STATE_DER (state, NONE ()));
538539 (var_ptr, der_cref) := makeVarPtrCyclic(var , der_cref);
539540 then ();
@@ -740,7 +741,8 @@ public
740741 function makePreVar
741742 "Creates a previous variable pointer from the discrete variable cref.
742743 e.g. isOpen -> $PRE.isOpen"
743- input output ComponentRef cref "old component reference to new component reference" ;
744+ input ComponentRef cref "old component reference" ;
745+ output ComponentRef pre_cref "new component reference" ;
744746 output Pointer < Variable > var_ptr "pointer to new variable" ;
745747 algorithm
746748 () := match ComponentRef . node(cref)
@@ -752,10 +754,10 @@ public
752754 algorithm
753755 disc := BVariable . getVarPointer(cref);
754756 qual. name := PREVIOUS_STR ;
755- cref := ComponentRef . append(cref, ComponentRef . fromNode(qual, ComponentRef . scalarType(cref)));
756- var := fromCref(cref );
757+ pre_cref := ComponentRef . append(cref, ComponentRef . fromNode(qual, ComponentRef . scalarType(cref)));
758+ var := fromCref(pre_cref, Variable . attributes( Pointer . access(disc)) );
757759 var . backendinfo := BackendExtension . BackendInfo . setVarKind(var . backendinfo, BackendExtension . PREVIOUS (disc));
758- (var_ptr, cref ) := makeVarPtrCyclic(var , cref );
760+ (var_ptr, pre_cref ) := makeVarPtrCyclic(var , pre_cref );
759761 then ();
760762
761763 else algorithm
@@ -808,7 +810,7 @@ public
808810 // prepend the seed str and the matrix name and create the new cref
809811 qual. name := SEED_STR + "_" + name;
810812 cref := ComponentRef . append(cref, ComponentRef . fromNode(qual, ComponentRef . scalarType(cref)));
811- var := fromCref(cref);
813+ var := fromCref(cref, NFAttributes . IMPL_DISCRETE_ATTR );
812814 // update the variable to be a seed and pass the pointer to the original variable
813815 var . backendinfo := BackendExtension . BackendInfo . setVarKind(var . backendinfo, BackendExtension . SEED_VAR (old_var_ptr));
814816 // create the new variable pointer and safe it to the component reference
@@ -825,9 +827,10 @@ public
825827 "Creates a partial derivative variable pointer from a cref. Used in NBJacobian and NBHessian
826828 to represent generic gradient equations.
827829 e.g: (speed, 'Jac') -> $pDer_Jac.speed"
828- input output ComponentRef cref "old component reference to new component reference" ;
830+ input ComponentRef cref "old component reference" ;
829831 input String name "name of the matrix this partial derivative belongs to" ;
830832 input Boolean isTmp "sets variable kind for tmpVar or resultVar accordingly" ;
833+ output ComponentRef pder_cref "new component reference" ;
831834 output Pointer < Variable > var_ptr "pointer to new variable" ;
832835 protected
833836 VariableKind varKind = if isTmp then BackendExtension . JAC_TMP_VAR () else BackendExtension . JAC_VAR ();
@@ -841,12 +844,12 @@ public
841844 case qual as InstNode . VAR_NODE () algorithm
842845 // prepend the seed str and the matrix name and create the new cref_DIFF_DIFF
843846 qual. name := PARTIAL_DERIVATIVE_STR + "_" + name;
844- cref := ComponentRef . append(cref, ComponentRef . fromNode(qual, ComponentRef . scalarType(cref)));
845- var := fromCref(cref);
847+ pder_cref := ComponentRef . append(cref, ComponentRef . fromNode(qual, ComponentRef . scalarType(cref)));
848+ var := fromCref(pder_cref, Variable . attributes(getVar( cref)) );
846849 // update the variable kind and pass the pointer to the original variable
847850 var . backendinfo := BackendExtension . BackendInfo . setVarKind(var . backendinfo, varKind);
848851 // create the new variable pointer and safe it to the component reference
849- (var_ptr, cref ) := makeVarPtrCyclic(var , cref );
852+ (var_ptr, pder_cref ) := makeVarPtrCyclic(var , pder_cref );
850853 then ();
851854
852855 else algorithm
@@ -880,7 +883,8 @@ public
880883 function makeStartVar
881884 "Creates a start variable pointer from a cref. Used in NBInitialization.
882885 e.g: angle -> $START.angle"
883- input output ComponentRef cref "old component reference to new component reference" ;
886+ input ComponentRef cref "old component reference" ;
887+ output ComponentRef start_cref "new component reference" ;
884888 output Pointer < Variable > var_ptr "pointer to new variable" ;
885889 algorithm
886890 () := match ComponentRef . node(cref)
@@ -894,13 +898,13 @@ public
894898 old_var_ptr := BVariable . getVarPointer(cref);
895899 // prepend the seed str and the matrix name and create the new cref
896900 qual. name := START_STR ;
897- cref := ComponentRef . append(cref, ComponentRef . fromNode(qual, ComponentRef . scalarType(cref)));
898- var := fromCref(cref);
901+ start_cref := ComponentRef . append(cref, ComponentRef . fromNode(qual, ComponentRef . scalarType(cref)));
902+ var := fromCref(start_cref, Variable . attributes(getVar( cref)) );
899903 // update the variable to be a seed and pass the pointer to the original variable
900904 var . backendinfo := BackendExtension . BackendInfo . setVarKind(var . backendinfo, BackendExtension . START (old_var_ptr));
901905 // create the new variable pointer and safe it to the component reference
902906 var_ptr := Pointer . create(var );
903- cref := BackendDAE . lowerComponentReferenceInstNode(cref , var_ptr);
907+ start_cref := BackendDAE . lowerComponentReferenceInstNode(start_cref , var_ptr);
904908 then ();
905909
906910 else algorithm
@@ -966,16 +970,16 @@ public
966970 cref := ComponentRef . CREF (node, iter_subs, ty, NFComponentRef . Origin . CREF , ComponentRef . EMPTY ());
967971 var_cref := ComponentRef . CREF (node, {}, ty, NFComponentRef . Origin . CREF , ComponentRef . EMPTY ());
968972 // create variable
969- var := fromCref(var_cref);
973+ var := fromCref(var_cref, NFAttributes . IMPL_DISCRETE_ATTR );
970974 // update the variable to be discrete and pass the pointer to the original variable
971975 var . backendinfo := BackendExtension . BackendInfo . setVarKind(var . backendinfo, BackendExtension . DISCRETE ());
972976 // create the new variable pointer and safe it to the component reference
973977 (var_ptr, cref) := makeVarPtrCyclic(var , cref);
974978 end makeEventVar;
975979
976980 function makeAuxStateVar
977- "Creates a generic boolean variable pointer from a unique index and context name .
978- e.g. ( \" $WHEN \" , 4 ) --> $WHEN_4 "
981+ "Creates a auxiliary state variable from an expression .
982+ e.g. der(x^2 + y ) --> der(aux) "
979983 input Integer uniqueIndex "unique identifier index" ;
980984 input Option < Expression > binding "optional binding expression" ;
981985 output Pointer < Variable > var_ptr "pointer to new variable" ;
@@ -993,7 +997,7 @@ public
993997 // create variable and add optional binding
994998 if isSome(binding) then
995999 bnd := Util . getOption(binding);
996- var := fromCref(cref, Binding . FLAT_BINDING (bnd, Expression . variability(bnd), NFBinding . Source . BINDING ));
1000+ var := fromCref(cref, NFAttributes . DEFAULT_ATTR , Binding . FLAT_BINDING (bnd, Expression . variability(bnd), NFBinding . Source . BINDING ));
9971001 else
9981002 var := fromCref(cref);
9991003 end if ;
0 commit comments