Skip to content

Commit

Permalink
Fixes for bug #1040:
Browse files Browse the repository at this point in the history
- Added optional scope information to Env.Frame, so that it's possible to see if
  the current scope is a function or not. This is needed for bug 1040.
- This means that we can now check if we're inside a function or not in
  Static.warnUnsafeRelations, so that we don't print a warning about == and !=
  inside of a function.
- Added new function Env.newEnvironment to create a new empty environment, and
  made Env.newFrame protected, since newFrame was only used to create empty
  environments anyway.
- Extended Env.newFrame to set name and type of the new frame.
- Updated test case libraries/msl31/Modelica.Math, since the erronous warnings
  about == on Reals are no longer issued.



git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@6278 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Oct 4, 2010
1 parent 583ec4f commit 192ac5f
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 159 deletions.
4 changes: 2 additions & 2 deletions Compiler/Builtin.mo
Expand Up @@ -2347,7 +2347,7 @@ val array_array2int
"
output list<Env.Frame> env;
algorithm
env := Env.openScope(Env.emptyEnv, false, NONE) "Debug.fprint (\"insttr\",\"Creating initial env.\\n\") &" ;
env := Env.newEnvironment() "Debug.fprint (\"insttr\",\"Creating initial env.\\n\") &" ;
env := Env.extendFrameC(env, rlType);
env := Env.extendFrameC(env, intType);
env := Env.extendFrameC(env, strType);
Expand Down Expand Up @@ -2388,7 +2388,7 @@ algorithm
then (cache,env);
// if no cached version found create initial env.
case (cache) equation
env = Env.openScope(Env.emptyEnv, false, NONE);
env = Env.openScope(Env.emptyEnv, false, NONE, NONE);
env = Env.extendFrameC(env, rlType);
env = Env.extendFrameC(env, intType);
env = Env.extendFrameC(env, strType);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Ceval.mo
Expand Up @@ -913,7 +913,7 @@ algorithm
ReductionOperator op;
equation
(cache, Values.ARRAY(valueLst = vals), st_1) = ceval(cache, env, iterexp, impl, st, dimOpt, msg);
env = Env.openScope(env, false, SOME(Env.forScopeName));
env = Env.openScope(env, false, SOME(Env.forScopeName), NONE);
op = lookupReductionOp(reductionName);
(cache, value, st_1) = cevalReduction(cache, env, reductionName, op, exp, iter, vals, impl, st, dimOpt, msg);
then (cache, value, st_1);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/CevalScript.mo
Expand Up @@ -3596,7 +3596,7 @@ algorithm
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
(cache,env) = Inst.makeEnvFromProgram(cache,p_1, Absyn.IDENT(""));
(cache,(c as SCode.CLASS(name=n,encapsulatedPrefix=encflag,restriction=r)),env_1) = Lookup.lookupClass(cache,env, classname_1, true);
env3 = Env.openScope(env_1, encflag, SOME(n));
env3 = Env.openScope(env_1, encflag, SOME(n), SOME(Env.CLASS_SCOPE));
ci_state = ClassInf.start(r, Env.getEnvName(env3));
(cache,env4,_,_,dae1,csets_1,ci_state_1,tys,_,_,_,_) = Inst.instClassIn(cache,env3, InnerOuter.emptyInstHierarchy,UnitAbsyn.noStore,DAE.NOMOD(), Prefix.NOPRE(), Connect.emptySet,
ci_state, c, false, {}, false, ConnectionGraph.EMPTY,NONE);
Expand Down Expand Up @@ -3637,7 +3637,7 @@ algorithm
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
(cache,env) = Inst.makeEnvFromProgram(cache,p_1, Absyn.IDENT(""));
(cache,(c as SCode.CLASS(name=n,encapsulatedPrefix=encflag,restriction=r)),env_1) = Lookup.lookupClass(cache,env, classname_1, true);
env3 = Env.openScope(env_1, encflag, SOME(n));
env3 = Env.openScope(env_1, encflag, SOME(n), SOME(Env.CLASS_SCOPE));
ci_state = ClassInf.start(r, Env.getEnvName(env3));
(cache,env4,_,_,dae1,csets_1,ci_state_1,tys,_,_,_,_) = Inst.instClassIn(cache,env3, InnerOuter.emptyInstHierarchy, UnitAbsyn.noStore,DAE.NOMOD(), Prefix.NOPRE(), Connect.emptySet,
ci_state, c, false, {}, false, ConnectionGraph.EMPTY,NONE);
Expand Down
23 changes: 9 additions & 14 deletions Compiler/Cevalfunc.mo
Expand Up @@ -86,7 +86,7 @@ algorithm
replacements = createReplacementRules(inArgs,elementList);
ht2 = generateHashMap(replacements,HashTable2.emptyHashTable());
str = Util.stringAppendList({"cevalfunc_",str});
env3 = Env.openScope(env, false, SOME(str));
env3 = Env.openScope(env, false, SOME(str), SOME(Env.FUNCTION_SCOPE));
env1 = extendEnvWithInputArgs(env3,elementList,inArgs,crefArgs, ht2) "also output arguments";
// print("evalfunc env: " +& Env.printEnvStr(env) +& "\n");
// print("evalfunc env1: " +& Env.printEnvStr(env1) +& "\n");
Expand Down Expand Up @@ -154,7 +154,6 @@ algorithm
Values.Value val1,vv;
list<Values.Value> vals1;
Env.Env env1,env2,complexEnv;
Env.Frame compFrame;
String varName, str;
DAE.Var tvar;
DAE.Attributes tattr;
Expand Down Expand Up @@ -220,8 +219,7 @@ algorithm
(val1 as Values.RECORD(record_ = _)) :: vals1, e1 :: restExps, ht2)
equation
(tty as (DAE.T_COMPLEX(recordconst,typeslst,cto,_),_)) = makeComplexForEnv(e1, val1);
compFrame = Env.newFrame(false);
complexEnv = makeComplexEnv({compFrame},typeslst);
complexEnv = makeComplexEnv(Env.newEnvironment(),typeslst);
env1 = Env.extendFrameV(env,
DAE.TYPES_VAR(
varName,
Expand Down Expand Up @@ -462,9 +460,8 @@ algorithm oenv := matchcontinue(env, tvars)
//print(" array :: fail " +& name +& ", " +& Types.printTypeStr(ty) +& "\n");
((ty_flat as (DAE.T_COMPLEX(_,typeslst,_,_),_)),_)=Types.flattenArrayType(ty);
//print(" is complex tough\n");
complexEnv = Env.newFrame(false);
//typeslst = Util.listMap1(typeslst,addbindingtodaevar,bind);
complexEnv = makeComplexEnv({complexEnv},typeslst);
complexEnv = makeComplexEnv(Env.newEnvironment(),typeslst);
// print("makeComplexEnv -> 2 component: " +& name +& " ty: " +& Types.printTypeStr(ty) +& "\n");
env1 = Env.extendFrameV(env,
DAE.TYPES_VAR(name,DAE.ATTR(false,false,SCode.RW(),SCode.VAR(),Absyn.BIDIR(),Absyn.UNSPECIFIED()),
Expand All @@ -484,8 +481,7 @@ algorithm oenv := matchcontinue(env, tvars)
// no base type
case(env, (tv as DAE.TYPES_VAR(name,attr,prot,ty as (DAE.T_COMPLEX(_,typeslst,_,_),_),_,constOfForIteratorRange))::vars)
equation
complexEnv = Env.newFrame(false);
complexEnv = makeComplexEnv({complexEnv},typeslst);
complexEnv = makeComplexEnv(Env.newEnvironment(),typeslst);
// print("makeComplexEnv -> 3 component: " +& name +& " ty: " +& Types.printTypeStr(ty) +& "\n");
env1 = Env.extendFrameV(env,
DAE.TYPES_VAR(name,DAE.ATTR(false,false,SCode.RW(),SCode.VAR(),Absyn.BIDIR(),Absyn.UNSPECIFIED()),
Expand Down Expand Up @@ -1053,7 +1049,6 @@ This function updates a generic-variable in the enviroment."
algorithm outVal := matchcontinue(inVal,env,toAssign)
local
DAE.Type t;
Env.Frame fr;
Env.Env env1,complexEnv;
String str,str2,dbgString;
Values.Value value,value2;
Expand All @@ -1070,8 +1065,7 @@ algorithm outVal := matchcontinue(inVal,env,toAssign)
equation
(_,_,t as (DAE.T_COMPLEX(_,typeslst,_,_),_),_,_,_,_,_,_) = Lookup.lookupVar(Env.emptyCache(),env, DAE.CREF_IDENT(str,DAE.ET_OTHER(),{}));
nlist = setValuesInRecord(typeslst,names,vals);
fr = Env.newFrame(false);
complexEnv = makeComplexEnv({fr},nlist);
complexEnv = makeComplexEnv(Env.newEnvironment(),nlist);
// print("setValue -> component: " +& str +& " ty: " +& Types.printTypeStr(t) +& "\n");
env1 = Env.updateFrameV(env,
DAE.TYPES_VAR(str,DAE.ATTR(false,false,SCode.RW(),SCode.VAR(),Absyn.BIDIR(),Absyn.UNSPECIFIED()),
Expand Down Expand Up @@ -1121,7 +1115,7 @@ protected function addForLoopScope
algorithm
baseType := Types.typeOfValue(startValue);
baseValue := typeOfValue(baseType);
newEnv := Env.openScope(env, false, SOME(Env.forScopeName));
newEnv := Env.openScope(env, false, SOME(Env.forScopeName), NONE);
newEnv := Env.extendFrameForIterator(newEnv, iterName, baseType, DAE.VALBOUND(baseValue,DAE.BINDING_FROM_DEFAULT_VALUE()), iterVariability, constOfForIteratorRange);
end addForLoopScope;

Expand All @@ -1136,6 +1130,7 @@ algorithm oenv := matchcontinue(env,inVal,inCr)
Env.Frame frame;
list<Env.Frame> frames,newFrames;
Option<String> farg1;
Option<Env.ScopeType> st;
Env.AvlTree farg2,farg22;
Env.AvlTree farg3;
list<Env.Item> farg4;
Expand All @@ -1147,13 +1142,13 @@ algorithm oenv := matchcontinue(env,inVal,inCr)
Integer hash;

// try the first frame
case( ( (frame as Env.FRAME(farg1, farg2, farg3, farg4, farg6, farg7,defineUnits) ) :: frames),inVal,inCr)
case( ( (frame as Env.FRAME(farg1, st, farg2, farg3, farg4, farg6, farg7,defineUnits) ) :: frames),inVal,inCr)
equation
str = Absyn.crefFirstIdent(inCr);
(_,_,_,_,_,_,_,_,_) = Lookup.lookupVar(Env.emptyCache(), {frame}, DAE.CREF_IDENT(str,DAE.ET_OTHER(),{}));
farg22 = setQualValue2(farg2, inVal,inCr,0);
then
Env.FRAME(farg1,farg22,farg3,farg4,farg6,farg7,defineUnits) :: frames;
Env.FRAME(farg1,st,farg22,farg3,farg4,farg6,farg7,defineUnits) :: frames;
// try next frame
case( frame :: frames, inVal,inCr ) // didn't find in this frame.
equation
Expand Down
6 changes: 3 additions & 3 deletions Compiler/Dependency.mo
Expand Up @@ -1206,15 +1206,15 @@ algorithm
/* First try partial instantiation */
case(p,p_class,env) equation
(cache,(cl as SCode.CLASS(name=id,encapsulatedPrefix=encflag,restriction=restr)),env_1) = Lookup.lookupClass(Env.emptyCache(),env, p_class, false);
env2 = Env.openScope(env_1, encflag, SOME(id));
env2 = Env.openScope(env_1, encflag, SOME(id), Env.restrictionToScopeType(restr));
ci_state = ClassInf.start(restr, Env.getEnvName(env2));
(cache,env_2,_,_) = Inst.partialInstClassIn(cache, env2, InnerOuter.emptyInstHierarchy,
DAE.NOMOD(), Prefix.NOPRE(), Connect.emptySet,
ci_state, cl, false, {});
then env_2;
case(p,p_class,env) equation
(cache,(cl as SCode.CLASS(name=id,encapsulatedPrefix=encflag,restriction=restr)),env_1) = Lookup.lookupClass(Env.emptyCache(),env, p_class, false);
env2 = Env.openScope(env_1, encflag, SOME(id));
env2 = Env.openScope(env_1, encflag, SOME(id), Env.restrictionToScopeType(restr));
ci_state = ClassInf.start(restr, Env.getEnvName(env2));
(cache,env_2,_,_,_,_,_,_,_,_,_,_) = Inst.instClassIn(cache,env2, InnerOuter.emptyInstHierarchy,
UnitAbsyn.noStore,DAE.NOMOD(), Prefix.NOPRE(), Connect.emptySet,
Expand Down Expand Up @@ -1265,4 +1265,4 @@ algorithm
)})},NONE),info);
end createTopLevelTotalClass;

end Dependency;
end Dependency;

0 comments on commit 192ac5f

Please sign in to comment.