Skip to content

Commit

Permalink
- Optimized Env.getEnvPath to speed up some Media models a bit.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@9414 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Jul 5, 2011
1 parent a5af394 commit ba0d37c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
64 changes: 37 additions & 27 deletions Compiler/FrontEnd/Env.mo
Expand Up @@ -896,46 +896,56 @@ algorithm
end match;
end getClassName;

public function getEnvName "returns the FQ name of the environment, see also getEnvPath"
input Env env;
output Absyn.Path path;
algorithm
path := matchcontinue(env)
case(env) equation
SOME(path) = getEnvPath(env);
then path;
case _
equation
true = RTOpts.debugFlag("failtrace");
Debug.traceln("- Env.getEnvName failed");
_ = getEnvPath(env);
then fail();
end matchcontinue;
public function getEnvName
"Returns the FQ name of the environment, see also getEnvPath"
input Env inEnv;
output Absyn.Path outPath;
protected
Ident id;
Env rest;
algorithm
FRAME(optName = SOME(id)) :: rest := inEnv;
outPath := getEnvName2(rest, Absyn.IDENT(id));
end getEnvName;

public function getEnvName2
input Env inEnv;
input Absyn.Path inPath;
output Absyn.Path outPath;
algorithm
outPath := match(inEnv, inPath)
local
Ident id;
Env rest;

case (FRAME(optName = SOME(id)) :: rest, _)
then getEnvName2(rest, Absyn.QUALIFIED(id, inPath));

else inPath;
end match;
end getEnvName2;

public function getEnvPath "function: getEnvPath
This function returns all partially instantiated parents as an Absyn.Path
option I.e. it collects all identifiers of each frame until it reaches
the topmost unnamed frame. If the environment is only the topmost frame,
NONE() is returned."
input Env inEnv;
output Option<Absyn.Path> outAbsynPathOption;
output Option<Absyn.Path> outEnvPath;
algorithm
outAbsynPathOption := match (inEnv)
outEnvPath := matchcontinue(inEnv)
local
Ident id;
Absyn.Path path,path_1;
Env rest;
case ({FRAME(optName = SOME(id)),FRAME(optName = NONE())}) then SOME(Absyn.IDENT(id));
case ((FRAME(optName = SOME(id)) :: rest))
Absyn.Path path;

case _
equation
SOME(path) = getEnvPath(rest);
path_1 = Absyn.joinPaths(path, Absyn.IDENT(id));
path = getEnvName(inEnv);
then
SOME(path_1);
SOME(path);

else NONE();
end match;
end getEnvPath;
end matchcontinue;
end getEnvPath;

public function getEnvPathNoImplicitScope "function: getEnvPath
This function returns all partially instantiated parents as an Absyn.Path
Expand Down
8 changes: 4 additions & 4 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -390,7 +390,7 @@ algorithm
case (cache,env,path,prevFrames,inState,msg)
equation
// Debug.traceln("lookupClass " +& Absyn.pathString(path) +& " s:" +& Env.printEnvPathStr(env));
SOME(scope) = Env.getEnvPath(env);
scope = Env.getEnvName(env);
f::fs = Env.cacheGet(scope,path,cache);
Util.setStatefulBoolean(inState,true);
id = Absyn.pathLastIdent(path);
Expand Down Expand Up @@ -468,7 +468,7 @@ algorithm
case (cache,env,id,path,NONE(),prevFrames,inState,msg)
equation
// false = Util.getStatefulBoolean(inState); ???
SOME(scope) = Env.getEnvPath(env);
scope = Env.getEnvName(env);
env = Env.cacheGet(scope,Absyn.IDENT(id),cache);
Util.setStatefulBoolean(inState,true);
(cache,c,env,prevFrames) = lookupClass2(cache,env,path,{},inState,msg);
Expand Down Expand Up @@ -1217,7 +1217,7 @@ algorithm
case (cache,env,cr as DAE.CREF_QUAL(ident = id,subscriptLst = {},componentRef = cref),prevFrames,inState) /* First part of name is a class. */
equation
(NONE(),prevFrames) = lookupPrevFrames(id,prevFrames);
SOME(scope) = Env.getEnvPath(env);
scope = Env.getEnvName(env);
path = ComponentReference.crefToPath(cr);
id = Absyn.pathLastIdent(path);
path = Absyn.stripLast(path);
Expand Down Expand Up @@ -1476,7 +1476,7 @@ algorithm
case(cache,env,path,mod,msg) /* Should we only lookup if it is SCode.NOMOD? */
equation
(cache,(c as SCode.CLASS(name=cn2,encapsulatedPrefix=enc2,restriction=r)),cenv) = lookupClass(cache,env,path,msg);
SOME(scope) = Env.getEnvPath(cenv);
scope = Env.getEnvName(cenv);
ident = Absyn.pathLastIdent(path);
classEnv = Env.cacheGet(scope,Absyn.IDENT(ident),cache);
then
Expand Down

0 comments on commit ba0d37c

Please sign in to comment.