Skip to content

Commit

Permalink
- Moved valueExp from Static to ValuesUtil.
Browse files Browse the repository at this point in the history
- Added a new cevalIfConstant function to Ceval, and removed the old one from
  Static.
- Removed calls to cevalIfConstant in Static, and added calls to cevalIfConstant
to Inst, Interactive and Mod where appropriate.
- Updated testcases due to changes in constant evaluation.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5857 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Jul 13, 2010
1 parent faf9a63 commit fcad441
Show file tree
Hide file tree
Showing 13 changed files with 1,196 additions and 1,028 deletions.
30 changes: 30 additions & 0 deletions Compiler/Algorithm.mo
Expand Up @@ -259,6 +259,36 @@ algorithm
end matchcontinue;
end makeAssignment2;

public function makeAssignmentsList
input list<DAE.Exp> lhsExps;
input list<DAE.Properties> lhsProps;
input list<DAE.Exp> rhsExps;
input list<DAE.Properties> rhsProps;
input SCode.Accessibility accessibility;
input SCode.Initial initial_;
input DAE.ElementSource source;
output list<Statement> assignments;
algorithm
assignments := matchcontinue(lhsExps, lhsProps, rhsExps, rhsProps,
accessibility, initial_, source)
case ({}, {}, {}, {}, _, _, _) then {};
case (lhs :: rest_lhs, lhs_prop :: rest_lhs_prop,
rhs :: rest_rhs, rhs_prop :: rest_rhs_prop, _, _, _)
local
DAE.Exp lhs, rhs;
list<DAE.Exp> rest_lhs, rest_rhs;
DAE.Properties lhs_prop, rhs_prop;
list<DAE.Properties> rest_lhs_prop, rest_rhs_prop;
DAE.Statement ass;
list<DAE.Statement> rest_ass;
equation
ass = makeAssignment(lhs, lhs_prop, rhs, rhs_prop, accessibility, initial_, source);
rest_ass = makeAssignmentsList(rest_lhs, rest_lhs_prop, rest_rhs, rest_rhs_prop, accessibility, initial_, source);
then
ass :: rest_ass;
end matchcontinue;
end makeAssignmentsList;

public function makeTupleAssignment "function: makeTupleAssignment
This function creates an `DAE.STMT_TUPLE_ASSIGN\' construct, and checks that the
assignment is semantically valid, which means that the component
Expand Down
125 changes: 120 additions & 5 deletions Compiler/Ceval.mo
Expand Up @@ -92,6 +92,7 @@ protected import InnerOuter;
protected import Prefix;
protected import Connect;
protected import ErrorExt;
protected import OptManager;

public function ceval "
This function is used when the value of a constant expression is
Expand Down Expand Up @@ -260,7 +261,7 @@ algorithm
equation
true = RTOpts.acceptMetaModelicaGrammar();
(cache,vallst) = cevalList(cache, env, expl, impl, st, msg);
then (cache,Values.META_TUPLE(vallst),st);
then (cache,Values.TUPLE(vallst),st);

case (cache,env,DAE.CREF(componentRef = c),(impl as false),SOME(st),_,msg)
local
Expand Down Expand Up @@ -905,6 +906,120 @@ algorithm
end matchcontinue;
end ceval;

public function cevalIfConstant
"This function constant evaluates an expression if the expression is constant,
or if the expression is a call of parameter constness whose return type
contains unknown dimensions (in which case we need to determine the size of
those dimensions)."
input Env.Cache inCache;
input Env.Env inEnv;
input DAE.Exp inExp;
input DAE.Properties inProp;
input Boolean impl;
output Env.Cache outCache;
output DAE.Exp outExp;
output DAE.Properties outProp;
algorithm
(inCache, outExp, outProp) := matchcontinue(inCache, inEnv, inExp, inProp, impl)
local
DAE.Exp e;
Values.Value v;
Env.Cache cache;
DAE.Properties prop;
case (_, _, e as DAE.CALL(ty = DAE.ET_ARRAY(arrayDimensions = _)),
DAE.PROP(constFlag = DAE.C_PARAM()), _)
equation
(e, prop) = cevalWholedimRetCall(e, inCache, inEnv);
then
(inCache, e, prop);
case (_, _, e, DAE.PROP(constFlag = DAE.C_PARAM(), type_ = tp), _) // BoschRexroth specifics
local DAE.Type tp;
equation
false = OptManager.getOption("cevalEquation");
then
(inCache, e, DAE.PROP(tp, DAE.C_VAR()));
case (_, _, e, DAE.PROP(constFlag = DAE.C_CONST()), _)
equation
(cache, v, _) = ceval(inCache, inEnv, e, impl, NONE, NONE, NO_MSG());
e = ValuesUtil.valueExp(v);
then
(cache, e, inProp);
case (_, _, e, _, _)
equation
DAE.C_CONST() = Types.propAllConst(inProp);
(cache, v, _) = ceval(inCache, inEnv, e, impl, NONE, NONE, NO_MSG());
e = ValuesUtil.valueExp(v);
then
(cache, e, inProp);
case (_, _, e, _, _) // BoschRexroth specifics
equation
false = OptManager.getOption("cevalEquation");
DAE.C_PARAM() = Types.propAllConst(inProp);
print(" tuple non constant evaluation not implemented yet\n");
then
fail();
case (_, _, _, _, _) then (inCache, inExp, inProp);
end matchcontinue;
end cevalIfConstant;

protected function cevalWholedimRetCall
"Helper function to cevalIfConstant. Determines the size of any unknown
dimensions in a function calls return type."
input DAE.Exp inExp;
input Env.Cache inCache;
input Env.Env inEnv;
output DAE.Exp outExp;
output DAE.Properties outProp;
algorithm
(outExp, outProp) := matchcontinue(inExp, inCache, inEnv)
case (e as DAE.CALL(path = p, expLst = el, tuple_ = t, builtin = b,
ty = DAE.ET_ARRAY(arrayDimensions = dims), inlineType = i), _, _)
local
DAE.Exp e;
Absyn.Path p;
list<DAE.Exp> el;
Boolean t, b;
DAE.InlineType i;
list<Option<Integer>> dims;
Values.Value v;
DAE.Type cevalType;
DAE.ExpType cevalExpType;
equation
true = Exp.arrayContainWholeDimension(dims);
(_, v, _) = ceval(inCache, inEnv, e, true, NONE, NONE, MSG());
cevalType = Types.typeOfValue(v);
cevalExpType = Types.elabType(cevalType);
then
(DAE.CALL(p, el, t, b, cevalExpType, i), DAE.PROP(cevalType, DAE.C_PARAM));
end matchcontinue;
end cevalWholedimRetCall;

public function cevalRangeIfConstant
"Constant evaluates the limits of a range if they are constant."
input Env.Cache inCache;
input Env.Env inEnv;
input DAE.Exp inExp;
input DAE.Properties inProp;
input Boolean impl;
output Env.Cache outCache;
output DAE.Exp outExp;
algorithm
(outCache, outExp, outProp) := matchcontinue(inCache, inEnv, inExp, inProp, impl)
case (_, _, DAE.RANGE(ty = ty, exp = e1, range = e2, expOption = e3), _, _)
local
DAE.Exp e1, e2;
Option<DAE.Exp> e3;
DAE.ExpType ty;
Env.Cache cache;
equation
(cache, e1, _) = cevalIfConstant(inCache, inEnv, e1, inProp, impl);
(cache, e2, _) = cevalIfConstant(cache, inEnv, e2, inProp, impl);
then
(inCache, DAE.RANGE(ty, e1, e3, e2));
case (_, _, _, _, _) then (inCache, inExp);
end matchcontinue;
end cevalRangeIfConstant;

protected function cevalBuiltin
"function: cevalBuiltin
Helper for ceval. Parts for builtin calls are moved here, for readability.
Expand Down Expand Up @@ -1160,7 +1275,7 @@ algorithm
cevalIsExternalObjectConstructor(cache,funcpath,env);
then
fail();

// adrpo: 2009-11-17 re-enable the Cevalfunc after dealing with record constructors!
case (cache,env,(e as DAE.CALL(path = funcpath,expLst = expl,builtin = builtin)),vallst,impl,st,dim,msg)
local Env.Cache garbageCache;
Expand Down Expand Up @@ -5038,7 +5153,7 @@ algorithm
case (cache,env,DAE.INDEX(exp = e1),dim,impl,msg)
equation
(cache,v1 as Values.INTEGER(indx),_) = ceval(cache,env, e1, impl, NONE, SOME(dim), msg);
e1_1 = Static.valueExp(v1);
e1_1 = ValuesUtil.valueExp(v1);
true = indx <= dim;
then
(cache,DAE.INDEX(e1_1));
Expand All @@ -5047,7 +5162,7 @@ algorithm
case (cache,env,DAE.INDEX(exp = e1),dim,impl,msg)
equation
(cache,v1 as Values.ENUM(index = indx),_) = ceval(cache,env, e1, impl, NONE, SOME(dim), msg);
e1_1 = Static.valueExp(v1);
e1_1 = ValuesUtil.valueExp(v1);
true = indx <= dim;
then
(cache,DAE.INDEX(e1_1));
Expand All @@ -5056,7 +5171,7 @@ algorithm
case (cache,env,DAE.SLICE(exp = e1),dim,impl,msg)
equation
(cache,v1,_) = ceval(cache,env, e1, impl, NONE, SOME(dim), msg);
e1_1 = Static.valueExp(v1);
e1_1 = ValuesUtil.valueExp(v1);
true = dimensionSliceInRange(v1,dim);
then
(cache,DAE.SLICE(e1_1));
Expand Down
4 changes: 3 additions & 1 deletion Compiler/Cevalfunc.mo
Expand Up @@ -685,11 +685,12 @@ algorithm
list<tuple<Absyn.Exp, list<SCode.Statement>>> elseifexpitemlist,trueBranch,elseBranch,branches1,branches2;
tuple<Absyn.Exp, list<SCode.Statement>> trueBranch;
list<SCode.Statement> algitemlist,elseitemlist;
DAE.Properties prop;

// algorithm assign
case(env, SCode.ALG_ASSIGN(assignComponent = ae1 as Absyn.CREF(_), value = ae2),ht2)
equation
(_,e1,DAE.PROP(t,_),_,_) = Static.elabExp(Env.emptyCache(),env,ae2,true,NONE,false);
(_,e1,_,_,_) = Static.elabExp(Env.emptyCache(),env,ae2,true,NONE,false);
e1 = replaceComplex(e1,ht2);
(_,value,_) = Ceval.ceval(Env.emptyCache(),env, e1, true, NONE, NONE, Ceval.MSG());
env1 = setValue(value, env, ae1);
Expand Down Expand Up @@ -1394,6 +1395,7 @@ algorithm oval := matchcontinue(inType)
then Values.ENUM(idx,path,names);
// then Values.ENUM(DAE.CREF_IDENT("",Exp.ENUM(),{}),0);
// case((DAE.T_ENUM,_)) then Values.ENUM(DAE.CREF_IDENT("",Exp.ENUM(),{}),0);
case((DAE.T_METATUPLE(types = _), _)) then Values.META_TUPLE({});
case((DAE.T_COMPLEX(ClassInf.RECORD(path), typesVar,_,_),_))
local
list<DAE.Var> typesVar;
Expand Down
5 changes: 5 additions & 0 deletions Compiler/DAEUtil.mo
Expand Up @@ -2297,6 +2297,11 @@ algorithm
lhsCrefs = listAppend(crefs1,lhsCrefs);
then
lhsCrefs;
case(DAE.ARRAY_EQUATION(exp = DAE.CREF(cref, _)) :: rest)
equation
lhsCrefs = verifyWhenEquationStatements(rest);
then
cref :: lhsCrefs;
case(DAE.EQUEQUATION(cr1=cref,cr2=_)::rest)
equation
lhsCrefs = verifyWhenEquationStatements(rest);
Expand Down

0 comments on commit fcad441

Please sign in to comment.