Skip to content

Commit

Permalink
-Changed implmentation of ErrorExt: setCheckpoint,delCheckpoint and r…
Browse files Browse the repository at this point in the history
…ollBack. They now take unique indentifiers. If rollback and delCheckpoint passes identifier that doesn't match what is on the top of the stack, the application exits. This is to make absolutely sure that error message checkpoints are handled correctly.

-Also fixed bugs to make sure that above is fullfilled.
-Fixed bug with wrong type inside crefs
-Removed Static.generateCompiledFunction since it is not used.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@5160 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Mar 17, 2010
1 parent f27bf7c commit 808ffb4
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 244 deletions.
10 changes: 9 additions & 1 deletion Compiler/Ceval.mo
Expand Up @@ -91,6 +91,7 @@ protected import Cevalfunc;
protected import InnerOuter;
protected import Prefix;
protected import Connect;
protected import ErrorExt;

public function ceval "
This function is used when the value of a constant expression is
Expand Down Expand Up @@ -289,13 +290,20 @@ algorithm
/* Call functions FIXME: functions are always generated. Put back the check
and write another rule for the false case that generates the function */
equation
ErrorExt.setCheckpoint("cevalCall");
// do not handle Connection.isRoot here!
false = stringEqual("Connection.isRoot", Absyn.pathString(funcpath));
(cache,vallst) = cevalList(cache,env, expl, impl, st, msg);
(cache,newval,st)= cevalCallFunction(cache, env, e, vallst, impl, st, dimOpt, msg);
ErrorExt.rollBack("cevalCall");
then
(cache,newval,st);

// make rollback for case above
case(_,_,DAE.CALL(path = funcpath,expLst = expl,builtin = builtin),_,_,_,_) equation
ErrorExt.rollBack("cevalCall");
then fail();


/* Try Interactive functions last */
case (cache,env,(e as DAE.CALL(path = _)),(impl as true),SOME(st),_,msg)
local
Expand Down
6 changes: 3 additions & 3 deletions Compiler/Cevalfunc.mo
Expand Up @@ -64,7 +64,7 @@ algorithm
sc as SCode.CLASS(partialPrefix=false,restriction=SCode.R_FUNCTION(),
classDef=SCode.PARTS(elementLst=elementList) ),daeList)
equation
ErrorExt.setCheckpoint();
ErrorExt.setCheckpoint("cevalUserFunc");
true = OptManager.setOption("envCache",false);
str = Absyn.pathString(funcpath);
replacements = createReplacementRules(inArgs,elementList);
Expand All @@ -77,7 +77,7 @@ algorithm
env2 = evaluateStatements(env1,sc,ht2);
retVals = getOutputVarValues(elementList, env2);
retVal = convertOutputVarValues(retVals);
ErrorExt.rollBack();
ErrorExt.rollBack("cevalUserFunc");
true = OptManager.setOption("envCache",true);
then
retVal;
Expand All @@ -87,7 +87,7 @@ algorithm
sc as SCode.CLASS(partialPrefix=false,restriction=SCode.R_FUNCTION(),
classDef=SCode.PARTS(elementLst=elementList) ),daeList)
equation
ErrorExt.rollBack();
ErrorExt.rollBack("cevalUserFunc");
_ = OptManager.setOption("envCache",true);
then fail();

Expand Down
17 changes: 13 additions & 4 deletions Compiler/ErrorExt.mo
Expand Up @@ -118,13 +118,18 @@ public function errorOn
external "C" ;
end errorOn;

public function setCheckpoint

public function setCheckpoint "sets a checkpoint for the error messages, so error messages can be rolled back (i.e. deleted) up to this point
A unique identifier for this checkpoint must be provided. It is checked when doing rollback or deletion"
input String id "uniqe identifier for the checkpoint (up to the programmer to guarantee uniqueness)";
external "C" ;
end setCheckpoint;

public function delCheckpoint
public function delCheckpoint "deletes the checkpoint at the top of the stack without
removing the error messages issued since that checkpoint.
If the checkpoint id doesn't match, the application exits with -1.
"

input String id "unique identifier";
external "C" ;
end delCheckpoint;

Expand All @@ -133,7 +138,11 @@ public function printErrorsNoWarning
external "C" ;
end printErrorsNoWarning;

public function rollBack
public function rollBack "rolls back error messages until the latest checkpoint,
deleting all error messages added since that point in time. A unique identifier for the checkpoint must be provided
The application will exit with return code -1 if this identifier does not match.
"
input String id "unique identifier";
external "C" ;
end rollBack;

Expand Down
70 changes: 35 additions & 35 deletions Compiler/Inst.mo
Expand Up @@ -3732,7 +3732,7 @@ algorithm

case (cache,env,ih,store,{SCode.EXTENDS(baseClassPath = path,modifications = mod)},{},mods,inst_dims)
equation
ErrorExt.setCheckpoint();
ErrorExt.setCheckpoint("instBasictypeBaseclass");
(cache,m_1,_) = Mod.elabModForBasicType(cache,env, Prefix.NOPRE(), mod, true);
m_2 = Mod.merge(mods, m_1, env, Prefix.NOPRE());
(cache,cdef,cenv) = Lookup.lookupClass(cache,env, path, true);
Expand All @@ -3741,19 +3741,19 @@ algorithm
b2 = Types.arrayType(ty);
b3 = Types.extendsBasicType(ty);
true = Util.boolOrList({b1, b2, b3});
ErrorExt.rollBack();
ErrorExt.rollBack("instBasictypeBaseclass");
then
(cache,ih,store,SOME(ty),tys);
case (cache,env,ih,store,{SCode.EXTENDS(baseClassPath = path,modifications = mod)},{},mods,inst_dims)
equation
rollbackCheck(path) "only rollback errors affection basic types";
rollbackCheck(path) "only rollback errors affecting basic types";
then fail();

/* Inherits baseclass -and- has components */
case (cache,env,ih,store,{SCode.EXTENDS(baseClassPath = path,modifications = mod)},inSCodeElementLst3,mods,inst_dims)
equation
true = (listLength(inSCodeElementLst3) > 0);
ErrorExt.setCheckpoint();
ErrorExt.setCheckpoint("instBasictypeBaseclass2") "rolled back or deleted inside call below";
instBasictypeBaseclass2(cache,env,ih,store,inSCodeElementLst2,inSCodeElementLst3,mods,inst_dims);
then
fail();
Expand All @@ -3764,7 +3764,7 @@ end instBasictypeBaseclass;

protected function rollbackCheck "
Author BZ 2009-08
Rollsback errors on builtin classes.
Rollsback errors on builtin classes and deletes checkpoint for other classes.
"
input Absyn.Path p;
algorithm _ := matchcontinue(p)
Expand All @@ -3773,12 +3773,13 @@ algorithm _ := matchcontinue(p)
equation
n = Absyn.pathString(p);
true = isBuiltInClass(n);
ErrorExt.rollBack();
ErrorExt.rollBack("instBasictypeBaseclass");
then ();
case(p)
equation
n = Absyn.pathString(p);
false = isBuiltInClass(n);
ErrorExt.delCheckpoint("instBasictypeBaseclass");
then ();
end matchcontinue;
end rollbackCheck;
Expand Down Expand Up @@ -3821,14 +3822,14 @@ algorithm _ := matchcontinue(inCache,inEnv1,inIH,store,inSCodeElementLst2,inSCod
b2 = Types.arrayType(ty);
true = boolOr(b1, b2);
classname = Env.printEnvPathStr(env);
ErrorExt.rollBack();
ErrorExt.rollBack("instBasictypeBaseclass2");
Error.addMessage(Error.INHERIT_BASIC_WITH_COMPS, {classname});
then
();
// if not error above, then do not report error at all, try another case in instClassdef.
case (_,_,_,_,_,_,_,_)
equation
ErrorExt.rollBack();
ErrorExt.rollBack("instBasictypeBaseclass2");
then ();
end matchcontinue;
end instBasictypeBaseclass2;
Expand Down Expand Up @@ -4201,9 +4202,9 @@ algorithm
//print("REDECL acquired mods: " +& Mod.printModStr(cmod2) +& "\n");

(cache,env2,ih,csets,dae) = updateComponentsInEnv(cache, env, ih, pre, cmod2, crefs, ci_state, csets, impl);
ErrorExt.setCheckpoint();
ErrorExt.setCheckpoint("updateCompeltsMods");
(cache,env2,ih,csets,dae1) = updateComponentsInEnv(cache, env2, ih, pre, DAE.MOD(false,Absyn.NON_EACH,{DAE.NAMEMOD(name, cmod)},NONE()), {cref}, ci_state, csets, impl);
ErrorExt.rollBack() "roll back any errors";
ErrorExt.rollBack("updateCompeltsMods") "roll back any errors";
(cache,cmod_1,dae2) = Mod.updateMod(cache,env2, pre, cmod, impl);
(cache,env3,ih,res,csets,dae3) = updateCompeltsMods(cache, env2, ih, pre, xs, ci_state, csets, impl);
dae = DAEUtil.joinDaeLst({dae,dae1,dae2,dae3});
Expand Down Expand Up @@ -6363,7 +6364,7 @@ algorithm
tuple<SCode.Element,DAE.Mod> newComp;
Boolean alreadyDeclared;

case (_,_,_,_,_,_,_,_,_) equation /*print(" dupe check setting ");*/ ErrorExt.setCheckpoint(); then fail();
case (_,_,_,_,_,_,_,_,_) equation /*print(" dupe check setting ");*/ ErrorExt.setCheckpoint("checkMultiplyDeclared"); then fail();

/* If a variable is declared multiple times, the first is used.
* If the two variables are not identical, an error is given.
Expand All @@ -6375,19 +6376,22 @@ algorithm
(_,_,SOME((oldElt,oldMod)),instStatus,_) = Lookup.lookupIdentLocal(cache, env, n);
checkMultipleElementsIdentical((oldElt,oldMod),newComp);
alreadyDeclared = instStatusToBool(instStatus);
ErrorExt.delCheckpoint("checkMultiplyDeclared");
then alreadyDeclared;

// If not multiply declared, return.
case (cache,env,mod,prefix,csets,ciState,
(newComp as (SCode.COMPONENT(component = n,finalPrefix = finalPrefix,replaceablePrefix = repl,protectedPrefix = prot),_)),_,_)
equation
failure((_,_,SOME((oldElt,oldMod)),_,_) = Lookup.lookupIdentLocal(cache,env, n));
ErrorExt.rollBack("checkMultiplyDeclared");
then false;

// failure
case (cache,env,mod,prefix,csets,ciState,_,_,_)
equation
Debug.fprint("failtrace","-Inst.checkMultiplyDeclared failed\n");
ErrorExt.delCheckpoint("checkMultiplyDeclared");
then fail();
end matchcontinue;
end checkMultiplyDeclared;
Expand Down Expand Up @@ -7861,11 +7865,11 @@ algorithm
crefs_2 = removeCrefFromCrefs(crefs_1, cref);
updatedComps = HashTable5.add((cref,0),updatedComps);
(cache,env2,ih,csets,updatedComps,dae4) = updateComponentsInEnv2(cache, env, ih, pre, mods, crefs_2, ci_state, csets, impl, updatedComps);
ErrorExt.setCheckpoint();
ErrorExt.setCheckpoint("updateComponentInEnv");
(cache,m_1,dae1) = Mod.elabMod(cache,env2, Prefix.NOPRE(), m, impl)
"Prefix does not matter, since we only update types
in env, and does not make any dae elements, etc.." ;
ErrorExt.rollBack()
ErrorExt.rollBack("updateComponentInEnv")
"Rollback all error since we are only interested in type, not value at this point.
Errors that occurse in elabMod which does not fail the function will be accepted.";
classmod = Mod.lookupModificationP(mods, t);
Expand Down Expand Up @@ -7934,10 +7938,10 @@ algorithm
/* Prefix does not matter, since we only update types in env, and does
not make any dae elements, etc..
*/
ErrorExt.setCheckpoint();
ErrorExt.setCheckpoint("updateComponentInEnv2");
(cache,m_1,dae3) = Mod.elabMod(cache,env2, Prefix.NOPRE(), m, impl);
ErrorExt.rollBack() "Rollback all error since we are only interested in type, not value at this point. Errors that occur in elabMod which does not fail the function will be accepted.";

ErrorExt.rollBack("updateComponentInEnv2") "Rollback all error since we are only interested in type, not value at this point.
Errors that occur in elabMod which does not fail the function will be accepted.";
/* lookup and merge modifications */
classmod = Mod.lookupModificationP(mods, t) ;
mm = Mod.lookupCompModification(mods, n);
Expand Down Expand Up @@ -8511,10 +8515,10 @@ algorithm
/* Special case when instantiating Real[0]. We need to know the type */
case (cache,env,ih,store,ci_state,mod,pre,csets,n,(cl,attr),prot,i,DIMINT(0),dims,idxs,inst_dims,impl,comment,io,finalPrefix,graph)
equation
ErrorExt.setCheckpoint();
ErrorExt.setCheckpoint("instArray");
(cache,compenv,ih,store,_,csets,ty,graph) =
instVar2(cache,env,ih,store, ci_state, mod, pre, csets, n, cl, attr,prot, dims, (0 :: idxs), inst_dims, impl, comment,io,finalPrefix,graph);
ErrorExt.rollBack();
ErrorExt.rollBack("instArray");
then
(cache,compenv,ih,store,DAEUtil.emptyDae,csets,ty,graph);

Expand Down Expand Up @@ -9701,9 +9705,9 @@ algorithm element := matchcontinue(subs,elemDecl,baseFunc,inCache,inEnv,inPrefix
(_,deriveFunc) = makeFullyQualified(inCache,inEnv,deriveFunc);
order = getDerivativeOrder(subs2);

ErrorExt.setCheckpoint() "don't report errors on modifers in functions";
ErrorExt.setCheckpoint("getDeriveAnnotation3") "don't report errors on modifers in functions";
conditionRefs = getDeriveCondition(subs2,elemDecl,inCache,inEnv,inPrefix);
ErrorExt.rollBack();
ErrorExt.rollBack("getDeriveAnnotation3");

conditionRefs = Util.sort(conditionRefs,DAEUtil.derivativeOrder);
defaultDerivative = getDerivativeSubModsOptDefault(subs,inCache,inEnv,inPrefix);
Expand Down Expand Up @@ -16996,37 +17000,33 @@ protected function makeCrefBaseType "Function: makeCrefBaseType"
algorithm ety := matchcontinue(baseType,dims)
local
DAE.ExpType ty;
DAE.Type tp_1;
DAE.Type tp_1,btp;
list<Option<Integer>> lst;
case(baseType, dims)

// Types extending basic type has dimensions already added
case(baseType as (DAE.T_COMPLEX(complexTypeOption=SOME(btp)),_),dims) equation
ty = Types.elabType(btp);
then ty;

case(baseType, dims)
equation
lst = instdimsIntOptList(Util.listLast(dims));
tp_1 = arrayBasictypeBaseclass2(lst, baseType);
ty = Types.elabType(tp_1);
then
ty;

case(baseType, dims)
equation
failure(_ = instdimsIntOptList(Util.listLast(dims)));
ty = Types.elabType(baseType);
then
ty;
case(baseType, dims)
equation
lst = instdimsIntOptList(Util.listLast(dims));
tp_1 = liftNonBasicTypesNDimensions(baseType,lst);
ty = Types.elabType(tp_1);
then
ty;
case(baseType, dims)
equation
failure(_ = instdimsIntOptList(Util.listLast(dims)));
ty = Types.elabType(baseType);
then
ty;

case(_,_)
equation
Debug.fprint("failtrace", "- make_makeCrefBaseType failed\n");
print("makCrefBaseType failed\n");
then
fail();
end matchcontinue;
Expand Down

0 comments on commit 808ffb4

Please sign in to comment.