diff --git a/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo b/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo index 4944629d575..4217d750338 100644 --- a/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo +++ b/OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo @@ -1228,31 +1228,6 @@ public end match; end setRHS; - function fromLHSandRHS - input Expression lhs; - input Expression rhs; - input Pointer idx; - input String context; - input EquationAttributes attr = EquationAttributes.default(EquationKind.UNKNOWN, false); - input DAE.ElementSource src = DAE.emptyElementSource; - output Pointer eqn_ptr; - protected - Type ty; - Equation eqn; - Option opt_rec_size; - Integer rec_size; - algorithm - ty := Expression.typeOf(lhs); - opt_rec_size := Type.complexSize(ty); - eqn := match (ty, opt_rec_size) - case (Type.ARRAY(), _) then ARRAY_EQUATION(ty, lhs, rhs, src, attr, opt_rec_size); - case (Type.COMPLEX(), SOME(rec_size)) then RECORD_EQUATION(ty, lhs, rhs, src, attr, rec_size); - else SCALAR_EQUATION(ty, lhs, rhs, src, attr); - end match; - eqn_ptr := Pointer.create(eqn); - Equation.createName(eqn_ptr, idx, context); - end fromLHSandRHS; - function updateLHSandRHS input output Equation eqn; input Expression lhs; @@ -1767,20 +1742,13 @@ public if Iterator.isEmpty(iter) then lhs := Expression.fromCref(var.name); - eqn := Equation.fromLHSandRHS(lhs, rhs, idx, context, eqnAttr); + eqn := Equation.makeAssignment(lhs, rhs, idx, context, Iterator.EMPTY(), eqnAttr); else rhs := Expression.map(rhs, Expression.repairOperator); (sub_crefs, _) := Iterator.getFrames(iter); subs := list(Subscript.fromTypedExp(Expression.fromCref(cref)) for cref in sub_crefs); lhs := Expression.fromCref(ComponentRef.mergeSubscripts(subs, var.name, true, true)); - eqn := Equation.fromLHSandRHS(lhs, rhs, idx, context, eqnAttr); - eqn := Pointer.create(Equation.FOR_EQUATION( - size = ComponentRef.size(var.name), - iter = iter, - body = {Pointer.access(eqn)}, - source = DAE.emptyElementSource, - attr = eqnAttr)); - Equation.createName(eqn, idx, context); + eqn := Equation.makeAssignment(lhs, rhs, idx, context, iter, eqnAttr); // this could lead to non existing variables, should not be a problem though Equation.renameIterators(eqn, "$i"); end if; diff --git a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo index bd9c1f1860d..f9243e6c222 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo @@ -58,7 +58,7 @@ protected import BEquation = NBEquation; import BVariable = NBVariable; import Differentiate = NBDifferentiate; - import NBEquation.{Equation, EquationPointers, EqData, WhenEquationBody, WhenStatement, IfEquationBody}; + import NBEquation.{Equation, EquationPointers, EqData, EquationAttributes, EquationKind, Iterator, WhenEquationBody, WhenStatement, IfEquationBody}; import NBVariable.{VariablePointers, VarData}; // Util @@ -265,7 +265,7 @@ protected if Expression.fold(arg, checkAlgebraic, 0) > 1 then // more than one algebraic variable > create auxiliary state (state_var, state_cref, der_var, der_cref) := BVariable.makeAuxStateVar(Pointer.access(uniqueIndex), SOME(arg)); - aux_equation := Equation.fromLHSandRHS(Expression.fromCref(state_cref), arg, uniqueIndex, NBVariable.AUXILIARY_STR); + aux_equation := Equation.makeAssignment(Expression.fromCref(state_cref), arg, uniqueIndex, NBVariable.AUXILIARY_STR, Iterator.EMPTY(), EquationAttributes.default(EquationKind.CONTINUOUS, false)); returnExp := Expression.fromCref(der_cref); Pointer.update(acc_states, state_var :: Pointer.access(acc_states)); diff --git a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBEvents.mo b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBEvents.mo index fba46daf5e5..ff67b1989e3 100644 --- a/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBEvents.mo +++ b/OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBEvents.mo @@ -211,7 +211,7 @@ public for tpl in cev_lst loop (cond, cev) := tpl; if not BVariable.isDummyVariable(cev.auxiliary) then - aux_eqn := Equation.fromLHSandRHS(Expression.fromCref(BVariable.getVarName(cev.auxiliary)), cond.exp, idx, context, EquationAttributes.default(EquationKind.DISCRETE, false)); + aux_eqn := Equation.makeAssignment(Expression.fromCref(BVariable.getVarName(cev.auxiliary)), cond.exp, idx, context, Iterator.EMPTY(), EquationAttributes.default(EquationKind.DISCRETE, false)); auxiliary_vars := cev.auxiliary :: auxiliary_vars; auxiliary_eqns := aux_eqn :: auxiliary_eqns; end if; @@ -413,7 +413,7 @@ public guard(Operator.getMathClassification(exp.operator) == NFOperator.MathClassification.RELATION) algorithm // create auxiliary equation and solve for TIME - tmpEqn := Pointer.access(Equation.fromLHSandRHS(exp.exp1, exp.exp2, Pointer.create(0), "TMP")); + tmpEqn := Pointer.access(Equation.makeAssignment(exp.exp1, exp.exp2, Pointer.create(0), "TMP", Iterator.EMPTY(), EquationAttributes.default(EquationKind.UNKNOWN, false))); _ := Equation.map(tmpEqn, function containsTimeTraverseExp(b = containsTime), SOME(function containsTimeTraverseCref(b = containsTime))); if Pointer.access(containsTime) then (tmpEqn, _, status, invert) := Solve.solveBody(tmpEqn, NFBuiltin.TIME_CREF, funcTree);