Skip to content

Commit

Permalink
#2158 Add a maximum recursion depth for Ceval.ceval
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15850 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Apr 17, 2013
1 parent 0080a4c commit d5733f8
Show file tree
Hide file tree
Showing 14 changed files with 900 additions and 852 deletions.
2 changes: 1 addition & 1 deletion Compiler/BackEnd/BackendDAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ algorithm
// much faster at runtime.
//((e, _)) = Expression.traverseExp(e, replaceCrefsWithValues, (vars, cr_orign));
true = Expression.isConst(e);
(_, v, _) = Ceval.ceval(cache, env, e, false, NONE(), Ceval.NO_MSG());
(_, v, _) = Ceval.ceval(cache, env, e, false, NONE(), Ceval.NO_MSG(),0);
then
BackendDAE.VAR(cr, vk, vd, prl, ty, SOME(e), SOME(v), dims, src, va, c, ct);
else inVar;
Expand Down
10 changes: 5 additions & 5 deletions Compiler/BackEnd/EvaluateParameter.mo
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ algorithm
// apply replacements
(e1,_) = BackendVarTransform.replaceExp(e, iRepl, NONE());
// evaluate expression
(cache, value,_) = Ceval.ceval(iCache, env, e1, false, NONE(), Ceval.NO_MSG());
(cache, value,_) = Ceval.ceval(iCache, env, e1, false, NONE(), Ceval.NO_MSG(),0);
e1 = ValuesUtil.valueExp(value);
// set bind value
v = BackendVariable.setBindExp(var, e1);
Expand Down Expand Up @@ -504,7 +504,7 @@ algorithm
// apply replacements
(e1,_) = BackendVarTransform.replaceExp(e, iRepl, NONE());
// evaluate expression
(cache, value,_) = Ceval.ceval(iCache, env, e1, false, NONE(), Ceval.NO_MSG());
(cache, value,_) = Ceval.ceval(iCache, env, e1, false, NONE(), Ceval.NO_MSG(),0);
e1 = ValuesUtil.valueExp(value);
// set bind value
v = BackendVariable.setBindExp(var, e1);
Expand Down Expand Up @@ -537,7 +537,7 @@ algorithm
// apply replacements
(e1,_) = BackendVarTransform.replaceExp(e, iRepl, NONE());
// evaluate expression
(cache, value,_) = Ceval.ceval(iCache, env, e1, false, NONE(), Ceval.NO_MSG());
(cache, value,_) = Ceval.ceval(iCache, env, e1, false, NONE(), Ceval.NO_MSG(),0);
e1 = ValuesUtil.valueExp(value);
// set bind value
v = BackendVariable.setVarStartValue(var,e1);
Expand Down Expand Up @@ -593,7 +593,7 @@ algorithm
// applay replacements
(e,_) = BackendVarTransform.replaceExp(e, iRepl, NONE());
// evaluate expression
(cache, value,_) = Ceval.ceval(iCache, env, e, false, NONE(), Ceval.NO_MSG());
(cache, value,_) = Ceval.ceval(iCache, env, e, false, NONE(), Ceval.NO_MSG(), 0);
e1 = ValuesUtil.valueExp(value);
// save replacement
repl = BackendVarTransform.addReplacement(iRepl, cr, e1, NONE());
Expand All @@ -616,7 +616,7 @@ algorithm
// applay replacements
(e,_) = BackendVarTransform.replaceExp(e, iRepl, NONE());
// evaluate expression
(cache, value,_) = Ceval.ceval(iCache, env, e, false, NONE(), Ceval.NO_MSG());
(cache, value,_) = Ceval.ceval(iCache, env, e, false, NONE(), Ceval.NO_MSG(),0);
e1 = ValuesUtil.valueExp(value);
// save replacement
repl = BackendVarTransform.addReplacement(iRepl, cr, e1, NONE());
Expand Down
1,493 changes: 793 additions & 700 deletions Compiler/FrontEnd/Ceval.mo

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Compiler/FrontEnd/CevalFunction.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ protected function cevalExp
output Values.Value outValue;
output SymbolTable outST;
algorithm
(outCache, outValue, outST) := Ceval.ceval(inCache, inEnv, inExp, true, inST, Ceval.NO_MSG());
(outCache, outValue, outST) := Ceval.ceval(inCache, inEnv, inExp, true, inST, Ceval.NO_MSG(), 0);
end cevalExp;

protected function cevalExpList
Expand All @@ -1487,7 +1487,7 @@ protected function cevalExpList
output list<Values.Value> outValue;
output SymbolTable outST;
algorithm
(outCache, outValue, outST) := Ceval.cevalList(inCache, inEnv, inExpLst, true, inST, Ceval.NO_MSG());
(outCache, outValue, outST) := Ceval.cevalList(inCache, inEnv, inExpLst, true, inST, Ceval.NO_MSG(), 0);
end cevalExpList;

// [EENV] Environment extension functions (add variables).
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/DAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ algorithm
equation
// Debug.fprintln(Flags.FAILTRACE, "- DAEUtil.daeToRecordValue typeOfRHS: " +& ExpressionDump.typeOfString(rhs));
info = getElementSourceFileInfo(source);
(cache, value,_) = Ceval.ceval(cache, env, rhs, impl, NONE(), Ceval.MSG(info));
(cache, value,_) = Ceval.ceval(cache, env, rhs, impl, NONE(), Ceval.MSG(info),0);
(cache, Values.RECORD(cname,vals,names,ix)) = daeToRecordValue(cache, env, cname, rest, impl);
cr_str = ComponentReference.printComponentRefStr(cr);
then
Expand Down Expand Up @@ -3058,7 +3058,7 @@ algorithm
true = intEq(i,0);
// evalute expression
((e1,(ht,_,_))) = Expression.traverseExp(e,evaluateAnnotationTraverse,(ht,0,0));
(cache, value,_) = Ceval.ceval(inCache, env, e1, false,NONE(),Ceval.NO_MSG());
(cache, value,_) = Ceval.ceval(inCache, env, e1, false,NONE(),Ceval.NO_MSG(),0);
e1 = ValuesUtil.valueExp(value);
// e1 = e;
ht1 = BaseHashTable.add((cr,e1),ht);
Expand Down
10 changes: 5 additions & 5 deletions Compiler/FrontEnd/Inst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ algorithm
case (_,DAE.INITIAL_IF_EQUATION(condition1 = conds, equations2=tbs, equations3=fb, source=source),cache,_)
equation
//print(" (Initial if)To ceval: " +& stringDelimitList(List.map(conds,ExpressionDump.printExpStr),", ") +& "\n");
(cache,valList,_) = Ceval.cevalList(cache,env, conds, true, NONE(), Ceval.NO_MSG());
(cache,valList,_) = Ceval.cevalList(cache,env, conds, true, NONE(), Ceval.NO_MSG(),0);
//print(" Ceval res: ("+&stringDelimitList(List.map(valList,ValuesUtil.printValStr),",")+&")\n");

blist = List.map(valList,ValuesUtil.valueBool);
Expand Down Expand Up @@ -2547,7 +2547,7 @@ algorithm
equation
false = valueEq(c,DAE.C_VAR());
(bind1,t_1) = Types.matchType(bind,bindTp,expectedTp,true);
(cache,v,_) = Ceval.ceval(cache, env, bind1, false, NONE(), Ceval.NO_MSG());
(cache,v,_) = Ceval.ceval(cache, env, bind1, false, NONE(), Ceval.NO_MSG(), 0);
then DAE.TYPES_VAR(id,DAE.dummyAttrParam,t_1,
DAE.EQBOUND(bind1,SOME(v),DAE.C_PARAM(),DAE.BINDING_FROM_DEFAULT_VALUE()),NONE());

Expand All @@ -2557,7 +2557,7 @@ algorithm
true = Flags.getConfigBool(Flags.CHECK_MODEL);
expectedTp = Types.liftArray(expectedTp, d);
(bind1,t_1) = Types.matchType(bind,bindTp,expectedTp,true);
(cache,v,_) = Ceval.ceval(cache,env, bind1, false,NONE(), Ceval.NO_MSG());
(cache,v,_) = Ceval.ceval(cache,env, bind1, false,NONE(), Ceval.NO_MSG(), 0);
then DAE.TYPES_VAR(id,DAE.dummyAttrParam,t_1,
DAE.EQBOUND(bind1,SOME(v),DAE.C_PARAM(),DAE.BINDING_FROM_DEFAULT_VALUE()),NONE());

Expand Down Expand Up @@ -14858,7 +14858,7 @@ algorithm
case (cache,env,_,DAE.MOD(eqModOption = SOME(DAE.TYPED(e,_,DAE.PROP(e_tp,_)))),tp,_,_)
equation
(e_1,_) = Types.matchType(e, e_tp, tp);
(cache,v,_) = Ceval.ceval(cache,env, e_1, false,NONE(), NONE(), Ceval.NO_MSG());
(cache,v,_) = Ceval.ceval(cache,env, e_1, false,NONE(), NONE(), Ceval.NO_MSG(),0);
then
(cache,DAE.VALBOUND(v, DAE.BINDING_FROM_DEFAULT_VALUE()));
*/
Expand Down Expand Up @@ -16746,7 +16746,7 @@ algorithm
Static.elabExp(inCache, inEnv, cond, false, NONE(), false, pre, info);
true = Types.isBoolean(t);
true = Types.isParameterOrConstant(c);
(cache, Values.BOOL(b), _) = Ceval.ceval(cache, inEnv, e, false, NONE(), Ceval.MSG(info));
(cache, Values.BOOL(b), _) = Ceval.ceval(cache, inEnv, e, false, NONE(), Ceval.MSG(info), 0);
then
(b, cache);
case (_, _, _, _, _, _)
Expand Down
10 changes: 5 additions & 5 deletions Compiler/FrontEnd/InstSection.mo
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ algorithm
(cache, expl1,props,_) = Static.elabExpList(cache,env, conditions, impl,NONE(),true,pre,info);
DAE.PROP(DAE.T_BOOL(varLst = _),cnst) = Types.propsAnd(props);
true = Types.isParameterOrConstant(cnst);
(cache,valList,_) = Ceval.cevalList(cache, env, expl1, impl, NONE(), Ceval.NO_MSG());
(cache,valList,_) = Ceval.cevalList(cache, env, expl1, impl, NONE(), Ceval.NO_MSG(),0);
// check if valList contains Values.EMPTY()
containsEmpty = ValuesUtil.containsEmpty(valList);
generateNoConstantBindingError(containsEmpty, info);
Expand Down Expand Up @@ -557,7 +557,7 @@ algorithm
equation
(cache, expl1,props,_) = Static.elabExpList(cache,env, conditions, impl,NONE(),true,pre,info);
DAE.PROP(DAE.T_BOOL(varLst = _),_) = Types.propsAnd(props);
(cache,valList,_) = Ceval.cevalList(cache, env, expl1, impl, NONE(), Ceval.NO_MSG());
(cache,valList,_) = Ceval.cevalList(cache, env, expl1, impl, NONE(), Ceval.NO_MSG(),0);
blist = List.map(valList,ValuesUtil.valueBool);
b = Util.selectList(blist, tb, fb);
(cache,env_1,ih,dae,csets_1,ci_state_1,graph) = Inst.instList(cache,env,ih, mod, pre, csets, ci_state, instEInitialEquation, b, impl, Inst.alwaysUnroll, graph);
Expand Down Expand Up @@ -660,7 +660,7 @@ algorithm
(cache,e_1,DAE.PROP(type_ = DAE.T_ARRAY(ty = id_t), constFlag = cnst),_) =
Static.elabExp(cache,env, e, impl,NONE(),true, pre, info);
env_1 = addForLoopScope(env, i, id_t, SCode.VAR(), SOME(cnst));
(cache,v,_) = Ceval.ceval(cache,env, e_1, impl,NONE(), Ceval.MSG(info)) "FIXME: Check bounds" ;
(cache,v,_) = Ceval.ceval(cache,env, e_1, impl,NONE(), Ceval.MSG(info), 0) "FIXME: Check bounds" ;
(cache,dae,csets_1,graph) = unroll(cache, env_1, ih, mod, pre, csets, ci_state, i, id_t, v, el, initial_, impl, graph);
ci_state_1 = instEquationCommonCiTrans(ci_state, initial_);
then
Expand All @@ -671,7 +671,7 @@ algorithm
equation
(cache,e_1,DAE.PROP(type_ = DAE.T_ARRAY(ty = id_t), constFlag = cnst),_) = Static.elabExp(cache,env, e, impl,NONE(),true, pre, info);
env_1 = addForLoopScope(env, i, id_t, SCode.VAR(), SOME(cnst));
(cache,v,_) = Ceval.ceval(cache,env, e_1, impl,NONE(), Ceval.NO_MSG()) "FIXME: Check bounds" ;
(cache,v,_) = Ceval.ceval(cache,env, e_1, impl,NONE(), Ceval.NO_MSG(), 0) "FIXME: Check bounds" ;
(cache,dae,csets_1,graph) = unroll(cache, env_1, ih, mod, pre, csets, ci_state, i, id_t, v, el, initial_, impl,graph);
ci_state_1 = instEquationCommonCiTrans(ci_state, initial_);
then
Expand Down Expand Up @@ -1906,7 +1906,7 @@ algorithm
env_1 = addForLoopScope(env, i, id_t, SCode.VAR(), SOME(cnst));
(cache,DAE.ATTR(connectorType = SCode.POTENTIAL(), parallelism = SCode.NON_PARALLEL()),_,DAE.UNBOUND(),_,_,_,_,_)
= Lookup.lookupVar(cache, env_1, ComponentReference.makeCrefIdent(i,DAE.T_UNKNOWN_DEFAULT,{}));
(cache,v,_) = Ceval.ceval(cache, env_1, e_1, impl, NONE(), Ceval.MSG(info)) "FIXME: Check bounds";
(cache,v,_) = Ceval.ceval(cache, env_1, e_1, impl, NONE(), Ceval.MSG(info), 0) "FIXME: Check bounds";
(cache,stmts) = loopOverRange(cache, env_1, ih, pre, ci_state, i, v, sl, source, initial_, impl, unrollForLoops);
then
(cache,stmts);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Mod.mo
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ algorithm
false = Types.constIsVariable(c);
// Show error messages from ceval only if the expression is a constant.
msg = Util.if_(Types.constIsConst(c) and not impl, Ceval.MSG(inInfo), Ceval.NO_MSG());
(cache,v,_) = Ceval.ceval(inCache, inEnv, inExp, false,NONE(), msg);
(cache,v,_) = Ceval.ceval(inCache,inEnv,inExp,false,NONE(),msg,0);
then
(inCache /*Yeah; this makes sense :)*/,SOME(v));
// Constant evaluation failed, return no value.
Expand Down

0 comments on commit d5733f8

Please sign in to comment.