Skip to content

Commit

Permalink
- fix bug #2882 (careful with the evaluation of expressions having DA…
Browse files Browse the repository at this point in the history
…E.T_CODE type)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23131 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Nov 1, 2014
1 parent 7ce663d commit 5db2495
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 19 deletions.
104 changes: 90 additions & 14 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -7599,7 +7599,7 @@ algorithm
fail();
case (cache,env,fn,args,nargs,impl,st as SOME(_),pre,_,_) /* impl LS: Check if a builtin function call, e.g. size() and calculate if so */
equation
(cache,e,prop,st) = BackendInterface.elabCallInteractive(cache,env, fn, args, nargs, impl,st,pre,info) "Elaborate interactive function calls, such as simulate(), plot() etc." ;
(cache,e,prop,st) = BackendInterface.elabCallInteractive(cache, env, fn, args, nargs, impl, st, pre, info) "Elaborate interactive function calls, such as simulate(), plot() etc." ;
ErrorExt.rollBack("elabCall_InteractiveFunction");
then
(cache,e,prop,st);
Expand Down Expand Up @@ -13836,21 +13836,16 @@ algorithm
DAE.Type ty;
DAE.CodeType ct2;

// First; try to elaborate the exp (maybe there is a binding in the environment that says v is a VariableName, etc...
// first; try to elaborate the exp (maybe there is a binding in the environment that says v is a VariableName
case (_,_,_,_,_,_)
equation
ErrorExt.setCheckpoint("elabCodeExp");
(_,dexp,prop,_) = elabExpInExpression(cache,env,exp,false,st,false,Prefix.NOPRE(),info);
DAE.T_CODE(ty=ct2) = Types.getPropType(prop);
true = valueEq(ct,ct2);
ErrorExt.delCheckpoint("elabCodeExp");
// print(ExpressionDump.printExpStr(dexp) + " " + Types.unparseType(ty) + "\n");
then dexp;

case (_,_,_,_,_,_)
equation
ErrorExt.rollBack("elabCodeExp");
then fail();
// adrpo: be very careful with this as it can take quite a long time, for example a call to:
// getDerivedClassModifierValue(Modelica.Fluid.Vessels.BaseClasses.PartialLumpedVessel.Medium.MassFlowRate,unit);
// will instantiate Modelica.Fluid.Vessels.BaseClasses.PartialLumpedVessel.Medium.MassFlowRate
// if we're not careful
dexp = elabCodeExp_dispatch(exp,cache,env,ct,st,info);
then
dexp;

// Expression
case (_,_,_,DAE.C_EXPRESSION(),_,_)
Expand Down Expand Up @@ -13894,6 +13889,87 @@ algorithm
end matchcontinue;
end elabCodeExp;

public function elabCodeExp_dispatch
"@author: adrpo
evaluate a code expression.
be careful how much you lookup"
input Absyn.Exp exp;
input FCore.Cache cache;
input FCore.Graph env;
input DAE.CodeType ct;
input Option<GlobalScript.SymbolTable> st;
input Absyn.Info info;
output DAE.Exp outExp;
algorithm
outExp := matchcontinue (exp,cache,env,ct,st,info)
local
String s1,s2;
Absyn.ComponentRef cr;
Absyn.Path path;
list<DAE.Exp> es_1;
list<Absyn.Exp> es;
DAE.Type et;
Integer i;
DAE.Exp dexp;
DAE.Properties prop;
DAE.Type ty;
DAE.CodeType ct2;
Absyn.Ident id;

// for a component reference make sure the first ident is either "OpenModelica" or not a class
case (Absyn.CREF(componentRef=cr),_,_,_,_,_)
equation
ErrorExt.setCheckpoint("elabCodeExp_dispatch1");
id = Absyn.crefFirstIdent(cr);
_ = matchcontinue(id)
case (_) // if the first one is OpenModelica, search
equation
true = id == "OpenModelica";
(_,dexp,prop,_) = elabExpInExpression(cache,env,exp,false,st,false,Prefix.NOPRE(),info);
then
();

case (_) // not a class or OpenModelica, continue
equation
failure((_,_,_) = Lookup.lookupClass(cache, env, Absyn.IDENT(id), false));
(_,dexp,prop,_) = elabExpInExpression(cache,env,exp,false,st,false,Prefix.NOPRE(),info);
then
();

else // a class which is not OpenModelica, fail
then fail();
end matchcontinue;
DAE.T_CODE(ty=ct2) = Types.getPropType(prop);
true = valueEq(ct,ct2);
ErrorExt.delCheckpoint("elabCodeExp_dispatch1");
// print(ExpressionDump.printExpStr(dexp) + " " + Types.unparseType(ty) + "\n");
then dexp;

case (Absyn.CREF(componentRef=cr),_,_,_,_,_)
equation
ErrorExt.rollBack("elabCodeExp_dispatch1");
then fail();

case (_,_,_,_,_,_)
equation
false = Absyn.isCref(exp);
ErrorExt.setCheckpoint("elabCodeExp_dispatch");
(_,dexp,prop,_) = elabExpInExpression(cache,env,exp,false,st,false,Prefix.NOPRE(),info);
DAE.T_CODE(ty=ct2) = Types.getPropType(prop);
true = valueEq(ct,ct2);
ErrorExt.delCheckpoint("elabCodeExp_dispatch");
// print(ExpressionDump.printExpStr(dexp) + " " + Types.unparseType(ty) + "\n");
then dexp;

case (_,_,_,_,_,_)
equation
false = Absyn.isCref(exp);
ErrorExt.rollBack("elabCodeExp_dispatch");
then fail();

end matchcontinue;
end elabCodeExp_dispatch;

public function elabArrayDims
"Elaborates a list of array dimensions."
input FCore.Cache inCache;
Expand Down
10 changes: 5 additions & 5 deletions Compiler/Script/StaticScript.mo
Expand Up @@ -283,7 +283,7 @@ public function elabCallInteractive "This function elaborates the functions defi
equation
ErrorExt.setCheckpoint("Scripting");
cr = Absyn.joinCrefs(Absyn.CREF_QUAL("OpenModelica",{},Absyn.CREF_IDENT("Scripting",{})),cr2);
(cache,exp_1,prop,st_1) = elabExp(cache,env,Absyn.CALL(cr,Absyn.FUNCTIONARGS(inExps,inNamedArgs)),impl,SOME(st),false,inPrefix,info);
(cache,exp_1,prop,st_1) = Static.elabExp(cache,env,Absyn.CALL(cr,Absyn.FUNCTIONARGS(inExps,inNamedArgs)),impl,SOME(st),false,inPrefix,info);
ErrorExt.delCheckpoint("Scripting");
then (cache,exp_1,prop,st_1);

Expand Down Expand Up @@ -525,7 +525,7 @@ algorithm
Prefix.Prefix pre;
case (cache,env,Absyn.CALL(function_ = fn,functionArgs = Absyn.FUNCTIONARGS(args = args,argNames = nargs)),impl,st,_,pre,_,_)
equation
(cache,e_1,prop,st_1) = elabCall(cache,env, fn, args, nargs, impl, st,pre,info,Error.getNumErrorMessages());
(cache,e_1,prop,st_1) = elabCall(cache, env, fn, args, nargs, impl, st, pre, info, Error.getNumErrorMessages());
_ = Types.propAllConst(prop);
(e_1,_) = ExpressionSimplify.simplify1(e_1);
then
Expand All @@ -541,7 +541,7 @@ end elabExp2;

protected function elabCall "
function: elabCall
This is an special case tha considers elabCallInteractive."
This is an special case that considers elabCallInteractive."
input FCore.Cache inCache;
input FCore.Graph inEnv;
input Absyn.ComponentRef inComponentRef;
Expand Down Expand Up @@ -570,9 +570,9 @@ algorithm
Boolean impl;
FCore.Cache cache;
Prefix.Prefix pre;
case (cache,env,fn,args,nargs,impl,st as SOME(_),pre,_,_) /* impl LS: Check if a builtin function call, e.g. size() and calculate if so */
case (cache,env,fn,args,nargs,impl,st as SOME(_),pre,_,_)
equation
(cache,e,prop,st) = elabCallInteractive(cache,env, fn, args, nargs, impl,st,pre,info) "Elaborate interactive function calls, such as simulate(), plot() etc." ;
(cache,e,prop,st) = elabCallInteractive(cache, env, fn, args, nargs, impl, st, pre, info) "Elaborate interactive function calls, such as simulate(), plot() etc." ;
then
(cache,e,prop,st);
end match;
Expand Down

0 comments on commit 5db2495

Please sign in to comment.