Skip to content

Commit

Permalink
- Fix order of cases in updateComponentInEnv in order to fix librarie…
Browse files Browse the repository at this point in the history
…s testcases.

  - Also updated Multibody testcases due to Adrian's previous changes.
- Fix testsuite/rtest to print time spent when it gets equation mismatch.
- Refactoring Lookup.mo (Derived classes are no more).


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5283 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Apr 9, 2010
1 parent 9aef184 commit 0d5d932
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 100 deletions.
40 changes: 19 additions & 21 deletions Compiler/Inst.mo
Expand Up @@ -7142,9 +7142,24 @@ algorithm
Option<Absyn.ConstrainClass> cc;
DAE.DAElist dae,dae1,dae2,dae3,dae4;
DAE.FunctionTree funcs;
/* Variables that have Element in Environment, i.e. no type
* information are instantiated here to get the type.
*/
/* If first part of ident is a class, e.g StateSelect.None, nothing to update*/
case (cache,env,ih,pre,mods,(cref /*as Absyn.CREF_QUAL(name = id)*/),ci_state,csets,impl,updatedComps)
equation
id = Absyn.crefFirstIdent(cref);
(cache,cl,cenv) = Lookup.lookupClass(cache,env, Absyn.IDENT(id), false);
then
(cache,env,ih,csets,updatedComps,DAEUtil.emptyDae);

/* Variable with NONE element is already instantiated. */
case (cache,env,ih,pre,mods,cref,ci_state,csets,impl,updatedComps)
local DAE.Var ty; Env.InstStatus is;
equation
id = Absyn.crefFirstIdent(cref);
(cache,ty,_,is) = Lookup.lookupIdent(cache,env,id);
true = Env.isTyped(is) "If InstStatus is typed, return";
then
(cache,env,ih,csets,updatedComps,DAEUtil.emptyDae);

case (cache,env,ih,pre,mods,cref,ci_state,csets,impl,updatedComps)
equation
id = Absyn.crefFirstIdent(cref);
Expand All @@ -7166,24 +7181,6 @@ algorithm
then
(cache,env_1,ih,csets_1,updatedComps,dae);

/* If first part of ident is a class, e.g StateSelect.None, nothing to update*/
case (cache,env,ih,pre,mods,(cref /*as Absyn.CREF_QUAL(name = id)*/),ci_state,csets,impl,updatedComps)
equation
id = Absyn.crefFirstIdent(cref);
(cache,cl,cenv) = Lookup.lookupClass(cache,env, Absyn.IDENT(id), false);
then
(cache,env,ih,csets,updatedComps,DAEUtil.emptyDae);

/* Variable with NONE element is already instantiated. */
case (cache,env,ih,pre,mods,cref,ci_state,csets,impl,updatedComps)
local DAE.Var ty; Env.InstStatus is;
equation
id = Absyn.crefFirstIdent(cref);
(cache,ty,_,is) = Lookup.lookupIdent(cache,env,id);
true = Env.isTyped(is) "If InstStatus is typed, return";
then
(cache,env,ih,csets,updatedComps,DAEUtil.emptyDae);

/* report an error! */
case (cache,env,ih,pre,mod,cref,ci_state,csets,impl,updatedComps)
equation
Expand Down Expand Up @@ -7258,6 +7255,7 @@ algorithm
Option<Absyn.ConstrainClass> cc;
DAE.DAElist dae,dae1,dae2,dae3,dae4;
DAE.FunctionTree funcs;
SCode.Variability var;
case (cache,env,cenv,ih,pre,path,name,ad,cl,attr,dattr,prot,finalPrefix,io,info,m,cmod,mod,cref,ci_state,csets,impl,updatedComps)
equation
1 = HashTable5.get(cref, updatedComps);
Expand Down
89 changes: 10 additions & 79 deletions Compiler/Lookup.mo
Expand Up @@ -2196,38 +2196,7 @@ protected function lookupClassInEnv "
Helper function to lookupClass2. Searches the environment for the class.
It first checks the current scope, and then base classes. The specification
says that we first search elements in the current scope (+ the ones inherited
from base classes), but this does not include derived environment. All elements
are already part of the current scope. Thus, we need to make sure that the derived
environment is searched last.
"
input Env.Cache inCache;
input Env.Env inEnv;
input String id;
input list<Env.Frame> inPrevFrames;
input Util.StatefulBoolean inState;
input Boolean inMsg;
output Env.Cache outCache;
output SCode.Class outClass;
output Env.Env outEnv;
output list<Env.Frame> outPrevFrames;
algorithm
(outCache,outClass,outEnv,outPrevFrames) := matchcontinue(inCache,inEnv,id,inPrevFrames,inState,inMsg)
case (inCache,inEnv,id,inPrevFrames,inState,inMsg)
equation
(outCache,outClass,outEnv,outPrevFrames) = lookupClassInEnvCurrentScope(inCache,inEnv,id,inPrevFrames,inState,inMsg);
Util.setStatefulBoolean(inState,true);
then (outCache,outClass,outEnv,outPrevFrames);
case (inCache,inEnv,id,inPrevFrames,inState,inMsg)
equation
(outCache,outClass,outEnv,outPrevFrames) = lookupClassInEnvDerivedScopes(inCache,inEnv,id,inPrevFrames,inState,inMsg);
Util.setStatefulBoolean(inState,true);
then (outCache,outClass,outEnv,outPrevFrames);
end matchcontinue;
end lookupClassInEnv;

protected function lookupClassInEnvCurrentScope "
Helper function to lookupClassInEnv. Searches the environment for the class.
Does not search base classes.
from base classes)
"
input Env.Cache inCache;
input Env.Env inEnv;
Expand All @@ -2253,55 +2222,15 @@ algorithm
case (cache,env as (frame::_),id,prevFrames,inState,msg) /* msg */
equation
(cache,c,env_1,prevFrames) = lookupClassInFrame(cache,frame,env,id,prevFrames,inState,msg);
Util.setStatefulBoolean(inState,true);
then
(cache,c,env_1,prevFrames);

case (cache,(env as ((frame as Env.FRAME(optName = SOME(sid),isEncapsulated = true)) :: fs)),id,prevFrames,inState,_)
equation
equality(id = sid) "Special case if looking up the class that -is- encapsulated. That must be allowed." ;
(cache,c,env,prevFrames) = lookupClassInEnvCurrentScope(cache,fs, id, frame::prevFrames, inState, true);
then
(cache,c,env,prevFrames);

case (cache,(frame as Env.FRAME(optName = SOME(_), isEncapsulated = false)) :: fs,id,prevFrames,inState,msgflag) /* if not found and not encapsulated, and no ident has been previously found, look in next enclosing scope */
equation
false = Util.getStatefulBoolean(inState);
(cache,c,env_1,prevFrames) = lookupClassInEnvCurrentScope(cache,fs, id, frame::prevFrames, inState, msgflag);
then
(cache,c,env_1,prevFrames);

end matchcontinue;
end lookupClassInEnvCurrentScope;

protected function lookupClassInEnvDerivedScopes "
Helper function to lookupClassInEnv. Searches the environment for the class.
Only searches search base classes.
"
input Env.Cache inCache;
input Env.Env inEnv;
input String id;
input list<Env.Frame> inPrevFrames;
input Util.StatefulBoolean inState;
input Boolean inMsg;
output Env.Cache outCache;
output SCode.Class outClass;
output Env.Env outEnv;
output list<Env.Frame> outPrevFrames;
algorithm
(outCache,outClass,outEnv,outPrevFrames) := matchcontinue (inCache,inEnv,id,inPrevFrames,inState,inMsg)
local
SCode.Class c;
list<Env.Frame> env_1,env,fs,i_env,prevFrames;
Env.Frame frame,f;
String id,sid,scope;
Boolean msg,msgflag;
Absyn.Path aid,path;
Env.Cache cache;

case (cache,(env as ((frame as Env.FRAME(optName = SOME(sid),isEncapsulated = true)) :: fs)),id,prevFrames,inState,_)
equation
equality(id = sid) "Special case if looking up the class that -is- encapsulated. That must be allowed." ;
(cache,c,env,prevFrames) = lookupClassInEnvDerivedScopes(cache,fs, id, frame::prevFrames, inState, true);
(cache,c,env,prevFrames) = lookupClassInEnv(cache,fs, id, frame::prevFrames, inState, true);
Util.setStatefulBoolean(inState,true);
then
(cache,c,env,prevFrames);

Expand All @@ -2310,7 +2239,7 @@ algorithm
case (cache,(env as (Env.FRAME(optName = SOME(sid),isEncapsulated = true) :: fs)),id,prevFrames,inState,true)
equation
(cache,i_env) = Builtin.initialEnv(cache);
failure((_,_,_,_) = lookupClassInEnvCurrentScope(cache,i_env, id, {}, inState, false));
failure((_,_,_,_) = lookupClassInEnv(cache,i_env, id, {}, inState, false));
scope = Env.printEnvPathStr(env);
Error.addMessage(Error.LOOKUP_ERROR, {id,scope});
then
Expand All @@ -2321,19 +2250,21 @@ algorithm
Option<String> sid;
equation
(cache,i_env) = Builtin.initialEnv(cache);
(cache,c,env_1,prevFrames) = lookupClassInEnvCurrentScope(cache,i_env, id, {}, inState, msgflag);
(cache,c,env_1,prevFrames) = lookupClassInEnv(cache,i_env, id, {}, inState, msgflag);
Util.setStatefulBoolean(inState,true);
then
(cache,c,env_1,prevFrames);

case (cache,(frame as Env.FRAME(optName = SOME(_), isEncapsulated = false)) :: fs,id,prevFrames,inState,msgflag) /* if not found and not encapsulated, and no ident has been previously found, look in next enclosing scope */
equation
false = Util.getStatefulBoolean(inState);
(cache,c,env_1,prevFrames) = lookupClassInEnvDerivedScopes(cache,fs, id, frame::prevFrames, inState, msgflag);
(cache,c,env_1,prevFrames) = lookupClassInEnv(cache,fs, id, frame::prevFrames, inState, msgflag);
Util.setStatefulBoolean(inState,true);
then
(cache,c,env_1,prevFrames);

end matchcontinue;
end lookupClassInEnvDerivedScopes;
end lookupClassInEnv;

protected function lookupClassInFrame "function: lookupClassInFrame

Expand Down

0 comments on commit 0d5d932

Please sign in to comment.