@@ -3460,52 +3460,76 @@ algorithm
34603460end extractConstrainingComps;
34613461
34623462public function moveBindings
3463- "mahge:
3464- This function takes two daelists, the first variable declarations
3465- and the second with equations generated for the variables' bindings by InstBinding.instModEquation.
3466- Then it moves the equations back as bindings for the variables.
3467- used for fixing record bindings."
3468- input DAE . DAElist inDae1;
3469- input DAE . DAElist inDae2;
3470- output DAE . DAElist outDae;
3471- algorithm
3472- outDae := match(inDae1,inDae2)
3473- local
3474- DAE . ComponentRef cref;
3475- DAE . VarKind kind;
3476- DAE . VarDirection dir;
3477- DAE . VarParallelism prl;
3478- DAE . VarVisibility vis;
3479- DAE . Type ty;
3480- Option < DAE . Exp > bind;
3481- DAE . InstDims dims;
3482- DAE . ConnectorType ct;
3483- DAE . ElementSource src;
3484- Option < DAE . VariableAttributes > varAttOpt;
3485- Option < SCode . Comment > commOpt;
3486- Absyn . InnerOuter inOut;
3487- list< DAE . Element > restDae1;
3488- list< DAE . Element > restDae2;
3489- DAE . Exp newBindExp;
3490-
3491- case (_,DAE . DAE ({})) then inDae1;
3492- case (DAE . DAE ({}),_) then inDae2;
3493-
3494- case (DAE . DAE (DAE . EQUATION (scalar = newBindExp)::{}),DAE . DAE (DAE . VAR (cref, kind, dir, prl, vis, ty, bind, dims, ct, src, varAttOpt, commOpt, inOut)::{}))
3495- then (DAE . DAE ({DAE . VAR (cref, kind, dir, prl, vis, ty, SOME (newBindExp), dims, ct, src, varAttOpt, commOpt, inOut)}));
3496-
3497- case (DAE . DAE (DAE . EQUATION (scalar = newBindExp)::restDae1),DAE . DAE (DAE . VAR (cref, kind, dir, prl, vis, ty, bind, dims, ct, src, varAttOpt, commOpt, inOut)::restDae2))
3498- equation
3499- DAE . DAE (restDae2) = moveBindings(DAE . DAE (restDae1),DAE . DAE (restDae2));
3500- then (DAE . DAE (DAE . VAR (cref, kind, dir, prl, vis, ty, SOME (newBindExp), dims, ct, src, varAttOpt, commOpt, inOut)::restDae2));
3501-
3502- case (DAE . DAE (restDae1),DAE . DAE (restDae2))
3503- equation
3504- Debug . fprintln(Flags . FAILTRACE , "- Inst.moveBindings failed:" +& DAEDump . dumpElementsStr(restDae1) +& " ### " +& DAEDump . dumpElementsStr(restDae2));
3505- then fail();
3506- end match;
3463+ "This function takes two DAElists, the first with equations generated by
3464+ InstBinding.instModEquation and the second the variables that bindings
3465+ belonged to. The function moves the equations back as bindings for the
3466+ variables, used for fixing record bindings."
3467+ input DAE . DAElist inEquations;
3468+ input DAE . DAElist inVariables;
3469+ output DAE . DAElist outVariables;
3470+ protected
3471+ list< DAE . Element > eqs, vars;
3472+ algorithm
3473+ DAE . DAE (elementLst = eqs) := inEquations;
3474+ DAE . DAE (elementLst = vars) := inVariables;
3475+ Error . assertion(intEq(listLength(eqs), listLength(vars)),
3476+ "- InstUtil.moveBindings: Mismatched number of equations and variables." , Absyn . dummyInfo);
3477+ vars := List . threadMap(eqs, vars, moveBindings2);
3478+ outVariables := DAE . DAE (vars);
35073479end moveBindings;
35083480
3481+ protected function moveBindings2
3482+ input DAE . Element inEquation;
3483+ input DAE . Element inVariable;
3484+ output DAE . Element outVariable;
3485+ algorithm
3486+ outVariable := matchcontinue(inEquation, inVariable)
3487+ local
3488+ DAE . ComponentRef cref;
3489+ DAE . VarKind kind;
3490+ DAE . VarDirection dir;
3491+ DAE . VarParallelism prl;
3492+ DAE . VarVisibility vis;
3493+ DAE . Type ty;
3494+ DAE . InstDims dims;
3495+ DAE . ConnectorType ct;
3496+ DAE . ElementSource src;
3497+ Option < DAE . VariableAttributes > attr;
3498+ Option < SCode . Comment > cmt;
3499+ Absyn . InnerOuter io;
3500+ DAE . Exp bind_exp;
3501+
3502+ case (_, DAE . VAR (cref, kind, dir, prl, vis, ty, _, dims, ct, src, attr, cmt, io))
3503+ equation
3504+ bind_exp = moveBindings3(inEquation);
3505+ then
3506+ DAE . VAR (cref, kind, dir, prl, vis, ty, SOME (bind_exp), dims, ct, src, attr, cmt, io);
3507+
3508+ case (_, DAE . VAR (componentRef = cref))
3509+ equation
3510+ true = Flags . isSet(Flags . FAILTRACE );
3511+ Debug . traceln("- InstUtil.moveBindings failed on " +&
3512+ ComponentReference . printComponentRefStr(cref));
3513+ then
3514+ fail();
3515+
3516+ end matchcontinue;
3517+ end moveBindings2;
3518+
3519+ protected function moveBindings3
3520+ input DAE . Element inEquation;
3521+ output DAE . Exp outBinding;
3522+ algorithm
3523+ outBinding := match(inEquation)
3524+ local
3525+ DAE . Exp bind_exp;
3526+
3527+ case DAE . EQUATION (scalar = bind_exp) then bind_exp;
3528+ case DAE . DEFINE (exp = bind_exp) then bind_exp;
3529+
3530+ end match;
3531+ end moveBindings3;
3532+
35093533public function checkModificationOnOuter
35103534 input Env . Cache inCache;
35113535 input Env . Env inEnv;
0 commit comments