Skip to content

Commit

Permalink
-Fixed bug with infinite recursion when trying to constant evaluate p…
Browse files Browse the repository at this point in the history
…arameter that has no binding (must be allowed when e.g. checking models). Testcase in multibody/checkingModels/BodyCylinder.mos

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5871 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jul 20, 2010
1 parent 0df1c74 commit c6a172f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
19 changes: 19 additions & 0 deletions Compiler/Ceval.mo
Expand Up @@ -4956,6 +4956,11 @@ algorithm
subsc = Exp.crefLastSubs(cr);
(cache,_,tp,_,_,_,_,_) = Lookup.lookupVar(cache,env, cr_1) "DAE.CREF_IDENT(id,{})" ;
sizelst = Types.getDimensionSizes(tp);

// TODO: Ugly hack to prevent infinite recursion. If we have a binding r = r that
// can for instance come from a modifier, this can cause an infinite loop here if r has no value.
false=isRecursiveBinding(cr,exp);

(cache,v,_) = ceval(cache, env, exp, impl, NONE, NONE, msg);
(cache,res) = cevalSubscriptValue(cache, env, subsc, v, sizelst, impl, msg);
then
Expand Down Expand Up @@ -4986,6 +4991,20 @@ algorithm
end matchcontinue;
end cevalCrefBinding;

protected function isRecursiveBinding " help function to cevalCrefBinding"
input DAE.ComponentRef cr;
input DAE.Exp exp;
output Boolean res;
algorithm
res := matchcontinue(cr,exp)
case(cr,exp) equation
res = Util.boolOrList(Util.listMap1(Exp.getCrefFromExp(exp),Exp.crefEqual,cr));
then res;
case(_,_) then false;
end matchcontinue;
end isRecursiveBinding;


protected function cevalSubscriptValue "function: cevalSubscriptValue
Helper function to cevalCrefBinding. It applies
subscripts to array values to extract array elements."
Expand Down
7 changes: 4 additions & 3 deletions Compiler/ConnectUtil.mo
Expand Up @@ -528,7 +528,7 @@ algorithm

// no deleted components
case(sets as Connect.SETS(s,crs,{},outerConn),pre,isTopScope,graph)
equation
equation
dae = equations2(sets);
then
(dae, graph);
Expand All @@ -538,6 +538,7 @@ algorithm
equation
cr = deletedComp;
s = removeComponentInSets(cr,s);

// remove all branches/connections/roots in the connection graph leading to the deleted components
graph = ConnectionGraph.removeDeletedComponentsFromCG(graph, cr);
// recursive call with all the rest of deleted components.
Expand Down Expand Up @@ -568,15 +569,15 @@ algorithm
equation
//print("Deleting: " +& Exp.printComponentRefStr(compName) +& "\n");
crs = Util.listSelect1(crs,compName,crefTupleNotPrefixOf);
//print("Result Connect.EQU after remove: " +& Util.stringDelimitList(Util.listMap(crs, Exp.printComponentRefStr), ", ") +& "\n");
//print("Result Connect.EQU after remove: " +& Util.stringDelimitList(Util.listMap(Util.listMap(crs,Util.tuple21), Exp.printComponentRefStr), ", ") +& "\n");
s = removeComponentInSets(compName,s);
then Connect.EQU(crs)::s;
// we have a flow component
case(compName, Connect.FLOW(fcrs)::s)
equation
//print("Deleting: " +& Exp.printComponentRefStr(compName) +& "\n");
fcrs = Util.listSelect1(fcrs,compName,flowTupleNotPrefixOf);
//print("Result Connect.FLOW after remove: " +& Util.stringDelimitList(Util.listMap(Util.listMap(fcrs, Util.tuple21), Exp.printComponentRefStr), ", ") +& "\n");
//print("Result Connect.FLOW after remove: " +& Util.stringDelimitList(Util.listMap(Util.listMap(fcrs, Util.tuple31), Exp.printComponentRefStr), ", ") +& "\n");
s = removeComponentInSets(compName,s);
then Connect.FLOW(fcrs)::s;
// failure
Expand Down

0 comments on commit c6a172f

Please sign in to comment.