@@ -3394,6 +3394,7 @@ public function mergeAliasVars
33943394 input BackendDAE . Var inVar;
33953395 input BackendDAE . Var inAVar "the alias var" ;
33963396 input Boolean negate;
3397+ input BackendDAE . Variables knVars "the KnownVars, needd to report Warnings" ;
33973398 output BackendDAE . Var outVar;
33983399protected
33993400 BackendDAE . Var v,va,v1,v2;
@@ -3408,7 +3409,7 @@ algorithm
34083409 // start
34093410 sv := varStartValueOption(inVar);
34103411 sva := varStartValueOption(inAVar);
3411- (v1) := mergeStartFixed(inVar,fixed,sv,inAVar,fixeda,sva,negate);
3412+ (v1) := mergeStartFixed(inVar,fixed,sv,inAVar,fixeda,sva,negate,knVars );
34123413 // nominal
34133414 v2 := mergeNominalAttribute(inAVar,v1,negate);
34143415 // minmax
@@ -3424,72 +3425,61 @@ protected function mergeStartFixed
34243425 input Boolean fixeda;
34253426 input Option < DAE . Exp > sva;
34263427 input Boolean negate;
3428+ input BackendDAE . Variables knVars "the KnownVars, needd to report Warnings" ;
34273429 output BackendDAE . Var outVar;
34283430algorithm
34293431 outVar :=
3430- matchcontinue (inVar,fixed,sv,inAVar,fixeda,sva,negate)
3432+ matchcontinue (inVar,fixed,sv,inAVar,fixeda,sva,negate,knVars )
34313433 local
34323434 BackendDAE . Var v,va,v1,v2;
34333435 DAE . ComponentRef cr,cra;
34343436 DAE . Exp sa,sb,e;
34353437 String s,s1,s2,s3,s4,s5;
3436- case (v as BackendDAE . VAR (varName= cr),true ,SOME (sa),va as BackendDAE . VAR (varName= cra),true ,SOME (sb),_)
3438+ case (v as BackendDAE . VAR (varName= cr),true ,SOME (sa),va as BackendDAE . VAR (varName= cra),true ,SOME (sb),_,_ )
34373439 equation
34383440 e = getNonZeroStart(sa,sb,negate);
34393441 v1 = setVarStartValue(v,e);
34403442 then v1;
3441- case (v as BackendDAE . VAR (varName= cr),true ,SOME (sa),va as BackendDAE . VAR (varName= cra),true ,SOME (sb),_)
3443+ case (v as BackendDAE . VAR (varName= cr),true ,SOME (sa),va as BackendDAE . VAR (varName= cra),true ,SOME (sb),_,_ )
34423444 equation
3443- s1 = ComponentReference . printComponentRefStr(cr);
3444- s2 = Util . if_(negate," = -" ," = " );
3445- s3 = ComponentReference . printComponentRefStr(cra);
3446- s4 = ExpressionDump . printExpStr(sa);
3447- s5 = ExpressionDump . printExpStr(sb);
3448- s = stringAppendList({"Alias variables " ,s1,s2,s3," both fixed and have start values " ,s4," != " ,s5,". Use value from " ,s1,". \n " });
3449- Error . addMessage(Error . COMPILER_WARNING ,{s});
3445+ mergeStartFixed1(cr,sa,cra,sb,negate," both fixed and have start values " ,"" ,knVars);
34503446 then v;
3451- case (v,true ,SOME (sa),va,true ,NONE (),_)
3447+ case (v,true ,SOME (sa),va,true ,NONE (),_,_ )
34523448 then v;
3453- case (v,true ,SOME (sa),va,false ,SOME (sb),_)
3449+ case (v,true ,SOME (sa),va,false ,SOME (sb),_,_ )
34543450 equation
34553451 e = getNonZeroStart(sa,sb,negate);
34563452 v1 = setVarStartValue(v,e);
34573453 then v1;
3458- case (v as BackendDAE . VAR (varName= cr),true ,SOME (sa),va as BackendDAE . VAR (varName= cra),false ,SOME (sb),_)
3454+ case (v as BackendDAE . VAR (varName= cr),true ,SOME (sa),va as BackendDAE . VAR (varName= cra),false ,SOME (sb),_,_ )
34593455 equation
3460- s1 = ComponentReference . printComponentRefStr(cr);
3461- s2 = Util . if_(negate," = -" ," = " );
3462- s3 = ComponentReference . printComponentRefStr(cra);
3463- s4 = ExpressionDump . printExpStr(sa);
3464- s5 = ExpressionDump . printExpStr(sb);
3465- s = stringAppendList({"Alias variables " ,s1,s2,s3," have start values " ,s4," != " ,s5,". Use value from " ,s1," because this is fixed. \n " });
3466- Error . addMessage(Error . COMPILER_WARNING ,{s});
3456+ mergeStartFixed1(cr,sa,cra,sb,negate," have start values " ," because this is fixed" ,knVars);
34673457 then v;
3468- case (v,true ,SOME (sa),va,false ,NONE (),_)
3458+ case (v,true ,SOME (sa),va,false ,NONE (),_,_ )
34693459 then v;
3470- case (v,true ,NONE (),va,true ,SOME (sb),_)
3460+ case (v,true ,NONE (),va,true ,SOME (sb),_,_ )
34713461 equation
34723462 v1 = setVarStartValue(v,sb);
34733463 then v1;
3474- case (v,true ,NONE (),va,true ,NONE (),_)
3464+ case (v,true ,NONE (),va,true ,NONE (),_,_ )
34753465 then v;
3476- case (v,true ,NONE (),va,false ,SOME (sb),_)
3466+ case (v,true ,NONE (),va,false ,SOME (sb),_,_ )
34773467 equation
34783468 v1 = setVarStartValue(v,sb);
34793469 then v1;
3480- case (v,true ,NONE (),va,false ,NONE (),_)
3470+ case (v,true ,NONE (),va,false ,NONE (),_,_ )
34813471 then v;
3482- case (v,false ,SOME (sa),va,true ,SOME (sb),_)
3472+ case (v,false ,SOME (sa),va,true ,SOME (sb),_,_ )
34833473 equation
34843474 e = getNonZeroStart(sa,sb,negate);
34853475 v1 = setVarStartValue(v,e);
34863476 v2 = setVarFixed(v1,true );
34873477 then v2;
3488- case (v,false ,SOME (sa),va,true ,NONE (),_)
3478+ case (v,false ,SOME (sa),va,true ,NONE (),_,_ )
34893479 equation
34903480 v1 = setVarFixed(v,true );
34913481 then v1;
3492- case (v,false ,SOME (sa),va,false ,SOME (sb),_)
3482+ case (v,false ,SOME (sa),va,false ,SOME (sb),_,_ )
34933483 equation
34943484 e = getNonZeroStart(sa,sb,negate);
34953485 v1 = setVarStartValue(v,e);
@@ -3498,45 +3488,101 @@ algorithm
34983488 // adrpo: TODO! FIXME! maybe we should use another heuristic here such as:
34993489 // use the value from the variable that is closer to the top of the
35003490 // hierarchy i.e. A.B value has priority over X.Y.Z value!
3501- case (v as BackendDAE . VAR (varName= cr),false ,SOME (sa),va as BackendDAE . VAR (varName= cra),false ,SOME (sb),_)
3491+ case (v as BackendDAE . VAR (varName= cr),false ,SOME (sa),va as BackendDAE . VAR (varName= cra),false ,SOME (sb),_,_ )
35023492 equation
35033493 true = intGt(ComponentReference . crefDepth(cr), ComponentReference . crefDepth(cra));
35043494 // invert arguments
3505- v = mergeStartFixed(inAVar,fixeda,sva,inVar,fixed,sv,negate);
3495+ v = mergeStartFixed(inAVar,fixeda,sva,inVar,fixed,sv,negate,knVars );
35063496 then v;
35073497
3508- case (v as BackendDAE . VAR (varName= cr),false ,SOME (sa),va as BackendDAE . VAR (varName= cra),false ,SOME (sb),_)
3498+ case (v as BackendDAE . VAR (varName= cr),false ,SOME (sa),va as BackendDAE . VAR (varName= cra),false ,SOME (sb),_,_ )
35093499 equation
3510- s1 = ComponentReference . printComponentRefStr(cr);
3511- s2 = Util . if_(negate," = -" ," = " );
3512- s3 = ComponentReference . printComponentRefStr(cra);
3513- s4 = ExpressionDump . printExpStr(sa);
3514- s5 = ExpressionDump . printExpStr(sb);
3515- s = stringAppendList({"Alias variables " ,s1,s2,s3," have start values " ,s4," != " ,s5,". Use value from " ,s1,". \n " });
3516- Error . addMessage(Error . COMPILER_WARNING ,{s});
3500+ mergeStartFixed1(cr,sa,cra,sb,negate," have start values " ,"" ,knVars);
35173501 then v;
3518- case (v,false ,SOME (sa),va,false ,NONE (),_)
3502+ case (v,false ,SOME (sa),va,false ,NONE (),_,_ )
35193503 then v;
3520- case (v,false ,NONE (),va,true ,SOME (sb),_)
3504+ case (v,false ,NONE (),va,true ,SOME (sb),_,_ )
35213505 equation
35223506 e = Debug . bcallret1(negate,Expression . negate,sb,sb);
35233507 v1 = setVarStartValue(v,e);
35243508 v2 = setVarFixed(v1,true );
35253509 then v2;
3526- case (v,false ,NONE (),va,true ,NONE (),_)
3510+ case (v,false ,NONE (),va,true ,NONE (),_,_ )
35273511 equation
35283512 v1 = setVarFixed(v,true );
35293513 then v1;
3530- case (v,false ,NONE (),va,false ,SOME (sb),_)
3514+ case (v,false ,NONE (),va,false ,SOME (sb),_,_ )
35313515 equation
35323516 e = Debug . bcallret1(negate,Expression . negate,sb,sb);
35333517 v1 = setVarStartValue(v,e);
35343518 then v1;
3535- case (v,false ,NONE (),va,false ,NONE (),_)
3519+ case (v,false ,NONE (),va,false ,NONE (),_,_ )
35363520 then v;
35373521 end matchcontinue;
35383522end mergeStartFixed;
35393523
3524+ protected function mergeStartFixed1
3525+ "autor: Frenkel TUD 2011-04"
3526+ input DAE . ComponentRef cr;
3527+ input DAE . Exp sv;
3528+ input DAE . ComponentRef cra;
3529+ input DAE . Exp sva;
3530+ input Boolean negate;
3531+ input String s4;
3532+ input String s7;
3533+ input BackendDAE . Variables knVars "the KnownVars, needd to report Warnings" ;
3534+ algorithm
3535+ _ :=
3536+ matchcontinue (cr,sv,cra,sva,negate,s4,s7,knVars)
3537+ local
3538+ String s,s1,s2,s3,s5,s6;
3539+ DAE . Exp sv1,sva1;
3540+ // report nothing if equal start values
3541+ case (_,_,_,_,_,_,_,_)
3542+ equation
3543+ true = Expression . expEqual(sv, sva);
3544+ then
3545+ ();
3546+ case (_,_,_,_,_,_,_,_)
3547+ equation
3548+ ((sv1, _)) = Expression . traverseExp(sv, replaceCrefWithBindExp, knVars);
3549+ ((sva1, _)) = Expression . traverseExp(sva, replaceCrefWithBindExp, knVars);
3550+ true = Expression . expEqual(sv1, sva1);
3551+ then
3552+ ();
3553+ case (_,_,_,_,_,_,_,_)
3554+ equation
3555+ s1 = ComponentReference . printComponentRefStr(cr);
3556+ s2 = Util . if_(negate," = -" ," = " );
3557+ s3 = ComponentReference . printComponentRefStr(cra);
3558+ s5 = ExpressionDump . printExpStr(sv);
3559+ s6 = ExpressionDump . printExpStr(sva);
3560+ s = stringAppendList({"Alias variables " ,s1,s2,s3,s4,s5," != " ,s6,". Use value from " ,s1,s7,". \n " });
3561+ Error . addMessage(Error . COMPILER_WARNING ,{s});
3562+ then
3563+ ();
3564+ end matchcontinue;
3565+ end mergeStartFixed1;
3566+
3567+ public function replaceCrefWithBindExp
3568+ input tuple< DAE . Exp , BackendDAE . Variables > inTuple;
3569+ output tuple< DAE . Exp , BackendDAE . Variables > outTuple;
3570+ algorithm
3571+ outTuple := matchcontinue(inTuple)
3572+ local
3573+ DAE . Exp e;
3574+ BackendDAE . Variables vars;
3575+ DAE . ComponentRef cr;
3576+ case ((DAE . CREF (componentRef= cr), vars))
3577+ equation
3578+ ({BackendDAE . VAR (bindExp = SOME (e))}, _) = getVar(cr, vars);
3579+ ((e, _)) = Expression . traverseExp(e, replaceCrefWithBindExp, vars);
3580+ then
3581+ ((e, vars));
3582+ else then inTuple;
3583+ end matchcontinue;
3584+ end replaceCrefWithBindExp;
3585+
35403586protected function getNonZeroStart
35413587"autor: Frenkel TUD 2011-04"
35423588 input DAE . Exp exp1;
0 commit comments