Skip to content

Commit

Permalink
Don't allow checkModel on functions/packages
Browse files Browse the repository at this point in the history
- Refactor CevalScriptBackend.runFrontEndWork so that the check for
  functions/packages is done regardless of which frontend is used.
- Remove case for functions in checkModel.
  • Loading branch information
perost committed Feb 1, 2021
1 parent 141624b commit 854b3c4
Showing 1 changed file with 26 additions and 40 deletions.
66 changes: 26 additions & 40 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -3297,35 +3297,33 @@ protected function runFrontEndWork
output String flatString = "";
protected
Integer numError = Error.getNumErrorMessages();
Absyn.Restriction restriction;
Absyn.Program p = SymbolTable.getAbsyn();
algorithm
try
Absyn.CLASS(restriction = restriction) := Interactive.getPathedClassInProgram(className, p, true);
else
Error.addMessage(Error.LOOKUP_ERROR, {AbsynUtil.pathString(className),"<TOP>"});
fail();
end try;

if not relaxedFrontEnd and (AbsynUtil.isFunctionRestriction(restriction) or
AbsynUtil.isPackageRestriction(restriction)) then
Error.addSourceMessage(Error.INST_INVALID_RESTRICTION,
{AbsynUtil.pathString(className), AbsynUtil.restrString(restriction)},
AbsynUtil.dummyInfo);
fail();
end if;

(cache,env,dae) := matchcontinue (inCache,inEnv,className)
local
Absyn.Restriction restriction;
Absyn.Class absynClass;
String str,re;
SCode.Program scodeP;
Absyn.Program p;
DAE.FunctionTree funcs;
NFFlatModel flat_model;
NFFlatten.FunctionTree nf_funcs;

case (cache,env,_)
equation
true = Flags.isSet(Flags.GRAPH_INST);
false = Flags.isSet(Flags.SCODE_INST);

System.realtimeTick(ClockIndexes.RT_CLOCK_FINST);
str = AbsynUtil.pathString(className);
(Absyn.CLASS(restriction = restriction)) = Interactive.getPathedClassInProgram(className, SymbolTable.getAbsyn(), true);
re = AbsynUtil.restrString(restriction);
Error.assertionOrAddSourceMessage(relaxedFrontEnd or not (AbsynUtil.isFunctionRestriction(restriction) or AbsynUtil.isPackageRestriction(restriction)),
Error.INST_INVALID_RESTRICTION,{str,re},AbsynUtil.dummyInfo);

System.realtimeTick(ClockIndexes.RT_CLOCK_FINST);

dae = FInst.instPath(className, SymbolTable.getSCode());
then (cache,env,dae);

case (_, _, _)
algorithm
false := Flags.isSet(Flags.GRAPH_INST);
Expand All @@ -3337,19 +3335,21 @@ algorithm
cache := FCore.emptyCache();
FCore.setCachedFunctionTree(cache, funcs);
env := FGraph.empty();

then (cache, env, dae);

case (cache,env,_)
equation
true = Flags.isSet(Flags.GRAPH_INST);
false = Flags.isSet(Flags.SCODE_INST);

System.realtimeTick(ClockIndexes.RT_CLOCK_FINST);
dae = FInst.instPath(className, SymbolTable.getSCode());
then (cache,env,dae);

case (cache,env,_)
equation
false = Flags.isSet(Flags.GRAPH_INST);
false = Flags.isSet(Flags.SCODE_INST);
str = AbsynUtil.pathString(className);
p = SymbolTable.getAbsyn();
(Absyn.CLASS(restriction = restriction)) = Interactive.getPathedClassInProgram(className, p, true);
re = AbsynUtil.restrString(restriction);
Error.assertionOrAddSourceMessage(relaxedFrontEnd or not (AbsynUtil.isFunctionRestriction(restriction) or AbsynUtil.isPackageRestriction(restriction)),
Error.INST_INVALID_RESTRICTION,{str,re},AbsynUtil.dummyInfo);

//System.stopTimer();
//print("\nExists+Dependency: " + realString(System.getTimerIntervalTime()));
Expand Down Expand Up @@ -3378,12 +3378,6 @@ algorithm
DAEUtil.getFunctionList(FCore.getFunctionTree(cache),failOnError=true); // Make sure that the functions are valid before returning success
then (cache,env,dae);

case (_,_,_)
equation
failure(Interactive.getPathedClassInProgram(className, SymbolTable.getAbsyn()));
Error.addMessage(Error.LOOKUP_ERROR, {AbsynUtil.pathString(className),"<TOP>"});
then fail();

else
equation
str = AbsynUtil.pathString(className);
Expand Down Expand Up @@ -5684,14 +5678,6 @@ algorithm
varSizeStr," variable(s).\n",simpleEqnSizeStr," of these are trivial equation(s)."});
then Values.STRING(retStr);

// handle functions
case (env,_,_)
equation
Absyn.CLASS(restriction=restriction) = Interactive.getPathedClassInProgram(className, SymbolTable.getAbsyn());
true = AbsynUtil.isFunctionRestriction(restriction) or AbsynUtil.isPackageRestriction(restriction);
(cache,env,_) = runFrontEnd(cache,env,className,true);
then Values.STRING("");

case (_,_,_)
equation
classNameStr = AbsynUtil.pathString(className);
Expand Down

0 comments on commit 854b3c4

Please sign in to comment.