Skip to content

Commit

Permalink
Fix bug: #2412
Browse files Browse the repository at this point in the history
- propagate program inside CACHE so we have access to it even if there is not symbol table available.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@19290 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Feb 25, 2014
1 parent e445894 commit d24eea4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 19 deletions.
1 change: 1 addition & 0 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -1133,6 +1133,7 @@ public constant TimeStamp dummyTimeStamp = TIMESTAMP(0.0,0.0);
public constant ClassDef dummyParts = PARTS({},{},{},{},NONE());
public constant Info dummyInfo = INFO("",false,0,0,0,0,dummyTimeStamp);
public constant TimeStamp newTimeStamp = TIMESTAMP(0.0,1.0);
public constant Program dummyProgram = PROGRAM({},TOP(),dummyTimeStamp);

public function getNewTimeStamp
"generate a new timestamp with edittime>buildtime."
Expand Down
64 changes: 50 additions & 14 deletions Compiler/FrontEnd/Env.mo
Expand Up @@ -129,6 +129,7 @@ public uniontype Cache
array<DAE.FunctionTree> functions "set of Option<DAE.Function>; NONE() means instantiation started; SOME() means it's finished";
StructuralParameters evaluatedParams "ht of prefixed crefs and a stack of evaluated but not yet prefix crefs";
Absyn.Path modelName "name of the model being instantiated";
Absyn.Program program "send the program around if we don't have a symbol table";
end CACHE;
record NO_CACHE
end NO_CACHE;
Expand Down Expand Up @@ -265,7 +266,7 @@ protected
algorithm
instFuncs := arrayCreate(1, DAE.emptyFuncTree);
ht := (HashTable.emptyHashTableSized(BaseHashTable.lowBucketSize),{});
cache := CACHE(NONE(),instFuncs,ht,Absyn.IDENT("##UNDEFINED##"));
cache := CACHE(NONE(),instFuncs,ht,Absyn.IDENT("##UNDEFINED##"),Absyn.dummyProgram);
end emptyCache;


Expand Down Expand Up @@ -2006,6 +2007,34 @@ algorithm
end match;
end printFrameElementStr;

public function getProgramFromCache
input Cache inCache;
output Absyn.Program program;
algorithm
program := match(inCache)
case NO_CACHE() then Absyn.dummyProgram;
case CACHE(program = program) then program;
end match;
end getProgramFromCache;

public function setProgramInCache
input Cache inCache;
input Absyn.Program program;
output Cache outCache;
algorithm
outCache := match(inCache,program)
local
array<DAE.FunctionTree> ef;
StructuralParameters ht;
Absyn.Path p;
Absyn.Program program;
Option<Env> oenv;

case (CACHE(oenv,ef,ht,p,_),_) then CACHE(oenv,ef,ht,p,program);
else inCache;
end match;
end setProgramInCache;

public function getCachedInitialEnv "get the initial environment from the cache"
input Cache cache;
output Env env;
Expand All @@ -2025,8 +2054,9 @@ algorithm
array<DAE.FunctionTree> ef;
StructuralParameters ht;
Absyn.Path p;
Absyn.Program program;

case (CACHE(_,ef,ht,p),_) then CACHE(SOME(env),ef,ht,p);
case (CACHE(_,ef,ht,p,program),_) then CACHE(SOME(env),ef,ht,p,program);
else inCache;
end match;
end setCachedInitialEnv;
Expand All @@ -2040,12 +2070,13 @@ protected
array<DAE.FunctionTree> ef;
StructuralParameters ht;
Absyn.Path p;
Absyn.Program program;
algorithm
outCache := match (inCache,inFunctions)
case (CACHE(env, _, ht, p), _)
case (CACHE(env, _, ht, p, program), _)
equation
ef = arrayCreate(1, inFunctions);
then CACHE(env, ef, ht, p);
then CACHE(env, ef, ht, p, program);
else inCache;
end match;
end setCachedFunctionTree;
Expand Down Expand Up @@ -2867,17 +2898,18 @@ algorithm
Option<Env> ienv;
StructuralParameters ht;
Absyn.Path p;
Absyn.Program program;

// Don't overwrite SOME() with NONE()
case (_, _)
equation
checkCachedInstFuncGuard(cache, func);
then cache;

case (CACHE(ienv,ef,ht,p),Absyn.FULLYQUALIFIED(_))
case (CACHE(ienv,ef,ht,p,program),Absyn.FULLYQUALIFIED(_))
equation
ef = arrayUpdate(ef,1,DAEUtil.avlTreeAdd(arrayGet(ef, 1),func,NONE()));
then CACHE(ienv,ef,ht,p);
then CACHE(ienv,ef,ht,p,program);

// Non-FQ paths mean aliased functions; do not add these to the cache
case (_,_) then (cache);
Expand All @@ -2897,11 +2929,12 @@ algorithm
Option<Env> ienv;
StructuralParameters ht;
Absyn.Path p;
Absyn.Program program;

case (CACHE(ienv,ef,ht,p),_)
case (CACHE(ienv,ef,ht,p,program),_)
equation
ef = arrayUpdate(ef,1,DAEUtil.addDaeFunction(funcs, arrayGet(ef, 1)));
then CACHE(ienv,ef,ht,p);
then CACHE(ienv,ef,ht,p,program);
else inCache;

end match;
Expand All @@ -2919,11 +2952,12 @@ algorithm
Option<Env> ienv;
StructuralParameters ht;
Absyn.Path p;
Absyn.Program program;

case (CACHE(ienv,ef,ht,p),_)
case (CACHE(ienv,ef,ht,p,program),_)
equation
ef = arrayUpdate(ef,1,DAEUtil.addDaeExtFunction(funcs, arrayGet(ef,1)));
then CACHE(ienv,ef,ht,p);
then CACHE(ienv,ef,ht,p,program);
else inCache;

end match;
Expand Down Expand Up @@ -3013,9 +3047,10 @@ algorithm
list<list<DAE.ComponentRef>> st;
list<DAE.ComponentRef> crs;
Absyn.Path p;
Absyn.Program program;

case (CACHE(initialEnv,functions,(ht,crs::st),p),SCode.PARAM(),_)
then CACHE(initialEnv,functions,(ht,(cr::crs)::st),p);
case (CACHE(initialEnv,functions,(ht,crs::st),p,program),SCode.PARAM(),_)
then CACHE(initialEnv,functions,(ht,(cr::crs)::st),p,program);

else cache;

Expand Down Expand Up @@ -3048,9 +3083,10 @@ algorithm
array<DAE.FunctionTree> ef;
StructuralParameters ht;
Option<Env> ienv;
Absyn.Program program;

case (CACHE(ienv,ef,ht,_),_)
then CACHE(ienv,ef,ht,p);
case (CACHE(ienv,ef,ht,_,program),_)
then CACHE(ienv,ef,ht,p,program);
else inCache;
end match;
end setCacheClassName;
Expand Down
8 changes: 5 additions & 3 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -8447,7 +8447,8 @@ algorithm
HashTable.HashTable ht;
list<list<DAE.ComponentRef>> crs;
Absyn.Path p;
case Env.CACHE(ie,f,(ht,crs),p) then Env.CACHE(ie,f,(ht,{}::crs),p);
Absyn.Program program;
case Env.CACHE(ie,f,(ht,crs),p,program) then Env.CACHE(ie,f,(ht,{}::crs),p,program);
else cache;
end match;
end pushStructuralParameters;
Expand All @@ -8466,10 +8467,11 @@ algorithm
list<DAE.ComponentRef> crs;
list<list<DAE.ComponentRef>> crss;
Absyn.Path p;
case (Env.CACHE(ie,f,(ht,crs::crss),p),_)
Absyn.Program program;
case (Env.CACHE(ie,f,(ht,crs::crss),p,program),_)
equation
ht = prefixAndAddCrefsToHt(cache,ht,pre,crs);
then Env.CACHE(ie,f,(ht,crss),p);
then Env.CACHE(ie,f,(ht,crss),p,program);
case (Env.NO_CACHE(),_) then cache;
end match;
end popStructuralParameters;
Expand Down
8 changes: 6 additions & 2 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -3348,7 +3348,10 @@ public function runFrontEnd
output DAE.DAElist dae;
output GlobalScript.SymbolTable st;
algorithm
(cache,env,dae,st) := runFrontEndWork(inCache,inEnv,className,inInteractiveSymbolTable,relaxedFrontEnd,Error.getNumErrorMessages());
// add program to the cache so it can be used to lookup modelica://
// URIs in external functions IncludeDirectory/LibraryDirectory
cache := Env.setProgramInCache(inCache, Interactive.getSymbolTableAST(inInteractiveSymbolTable));
(cache,env,dae,st) := runFrontEndWork(cache,inEnv,className,inInteractiveSymbolTable,relaxedFrontEnd,Error.getNumErrorMessages());
end runFrontEnd;

protected function runFrontEndWork
Expand Down Expand Up @@ -6884,7 +6887,8 @@ algorithm

// we might actually have a function loaded here already!
// we need to unload all functions to not get conflicts!
(cache,funcstr,fileName) = cevalGenerateFunction(cache, env, Absyn.PROGRAM({},Absyn.TOP(),Absyn.dummyTimeStamp), funcpath);
p = Env.getProgramFromCache(cache);
(cache,funcstr,fileName) = cevalGenerateFunction(cache, env, p, funcpath);
// generate a uniquely named dll!
Debug.bcall1(Flags.isSet(Flags.DYN_LOAD), print,"[dynload]: cevalCallFunction: about to execute " +& funcstr +& "\n");
print_debug = Flags.isSet(Flags.DYN_LOAD);
Expand Down

0 comments on commit d24eea4

Please sign in to comment.