diff --git a/Compiler/Ceval.mo b/Compiler/Ceval.mo index 6ed618590ab..b04279fd624 100644 --- a/Compiler/Ceval.mo +++ b/Compiler/Ceval.mo @@ -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 @@ -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 diff --git a/Compiler/Cevalfunc.mo b/Compiler/Cevalfunc.mo index 76d568f4b87..b2614021707 100644 --- a/Compiler/Cevalfunc.mo +++ b/Compiler/Cevalfunc.mo @@ -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); @@ -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; @@ -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(); diff --git a/Compiler/ErrorExt.mo b/Compiler/ErrorExt.mo index f740b6daf89..b0086c8594b 100644 --- a/Compiler/ErrorExt.mo +++ b/Compiler/ErrorExt.mo @@ -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; @@ -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; diff --git a/Compiler/Inst.mo b/Compiler/Inst.mo index d134caddd32..870e2e1b986 100644 --- a/Compiler/Inst.mo +++ b/Compiler/Inst.mo @@ -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); @@ -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(); @@ -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) @@ -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; @@ -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; @@ -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}); @@ -6363,7 +6364,7 @@ algorithm tuple 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. @@ -6375,6 +6376,7 @@ 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. @@ -6382,12 +6384,14 @@ algorithm (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; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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> 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; diff --git a/Compiler/Interactive.mo b/Compiler/Interactive.mo index df0fa3c01a6..2e99f0e66a6 100644 --- a/Compiler/Interactive.mo +++ b/Compiler/Interactive.mo @@ -1936,9 +1936,9 @@ algorithm lstVarVal = iv,compiledFunctions = cf, loadedFiles = lf))) equation - ErrorExt.setCheckpoint(); + ErrorExt.setCheckpoint("getComponentAnnotations"); resstr = getComponentAnnotations(cr, p); - ErrorExt.rollBack(); + ErrorExt.rollBack("getComponentAnnotations"); then (resstr,st); @@ -1949,9 +1949,9 @@ algorithm lstVarVal = iv,compiledFunctions = cf, loadedFiles = lf))) equation - ErrorExt.setCheckpoint(); + ErrorExt.setCheckpoint("getNthComponentAnnotation"); resstr = getNthComponentAnnotation(cr, p, n); - ErrorExt.rollBack(); + ErrorExt.rollBack("getNthComponentAnnotation"); then (resstr,st); @@ -2052,9 +2052,9 @@ algorithm lstVarVal = iv,compiledFunctions = cf, loadedFiles = lf))) equation - ErrorExt.setCheckpoint(); + ErrorExt.setCheckpoint("getNthConnectionAnnotation"); resstr = getNthConnectionAnnotation(cr, p, n); - ErrorExt.rollBack(); + ErrorExt.rollBack("getNthConnectionAnnotation"); then (resstr,st); @@ -2087,9 +2087,9 @@ algorithm lstVarVal = iv,compiledFunctions = cf, loadedFiles = lf))) equation - ErrorExt.setCheckpoint(); + ErrorExt.setCheckpoint("getNthConnectorIconAnnotation"); resstr = getNthConnectorIconAnnotation(cr, p, n); - ErrorExt.rollBack(); + ErrorExt.rollBack("getNthConnectorIconAnnotation"); then (resstr,st); @@ -2102,9 +2102,9 @@ algorithm local Absyn.Path path; equation path = Absyn.crefToPath(cr); - ErrorExt.setCheckpoint(); + ErrorExt.setCheckpoint("getIconAnnotation"); resstr = getIconAnnotation(path, p); - ErrorExt.rollBack(); + ErrorExt.rollBack("getIconAnnotation"); then (resstr,st); @@ -2117,9 +2117,9 @@ algorithm local Absyn.Path path; equation path = Absyn.crefToPath(cr); - ErrorExt.setCheckpoint(); + ErrorExt.setCheckpoint("getDiagramAnnotation"); resstr = getDiagramAnnotation(path, p); - ErrorExt.rollBack(); + ErrorExt.rollBack("getDiagramAnnotation"); then (resstr,st); @@ -2127,9 +2127,9 @@ algorithm {IEXP(exp = Absyn.CALL(function_ = Absyn.CREF_IDENT(name = "getNthInheritedClassIconMapAnnotation"),functionArgs = Absyn.FUNCTIONARGS(args = {Absyn.CREF(componentRef = cr),Absyn.INTEGER(value = n)})))}), (st as SYMBOLTABLE(ast = p,depends = aDep,explodedAst = s,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf))) equation - ErrorExt.setCheckpoint(); + ErrorExt.setCheckpoint("getNthInheritedClassIconMapAnnotation"); resstr = getNthInheritedClassIconMapAnnotation(cr, n, p); - ErrorExt.rollBack(); + ErrorExt.rollBack("getNthInheritedClassIconMapAnnotation"); then (resstr,st); @@ -2137,9 +2137,9 @@ algorithm {IEXP(exp = Absyn.CALL(function_ = Absyn.CREF_IDENT(name = "getNthInheritedClassDiagramMapAnnotation"),functionArgs = Absyn.FUNCTIONARGS(args = {Absyn.CREF(componentRef = cr),Absyn.INTEGER(value = n)})))}), (st as SYMBOLTABLE(ast = p,depends = aDep,explodedAst = s,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf))) equation - ErrorExt.setCheckpoint(); + ErrorExt.setCheckpoint("getNthInheritedClassDiagramMapAnnotation"); resstr = getNthInheritedClassDiagramMapAnnotation(cr, n, p); - ErrorExt.rollBack(); + ErrorExt.rollBack("getNthInheritedClassDiagramMapAnnotation"); then (resstr,st); @@ -2149,9 +2149,9 @@ algorithm local Absyn.Path path; equation path = Absyn.crefToPath(cr); - ErrorExt.setCheckpoint(); + ErrorExt.setCheckpoint("getDocumentationAnnotation"); resstr = getNamedAnnotation(path, p,"Documentation",getDocumentationAnnotationString); - ErrorExt.rollBack(); + ErrorExt.rollBack("getDocumentationAnnotation"); then (resstr,st); diff --git a/Compiler/Static.mo b/Compiler/Static.mo index 65d5fb70b96..f3ed8987edc 100644 --- a/Compiler/Static.mo +++ b/Compiler/Static.mo @@ -6671,13 +6671,11 @@ algorithm Debug.fprintln("sei", "elab_call 3"); fn_1 = Absyn.crefToPath(fn); (cache,e,prop,dae) = elabCallArgs(cache,env, fn_1, args, nargs, impl, st); - // adrpo: for function calls DO NOT GENERATE CODE during static elaboration! - st_1 = st; // (cache,st_1) = generateCompiledFunction(cache,env, fn, e, prop, st); Debug.fprint("sei", "elab_call 3 succeeded: "); fnstr = Dump.printComponentRefStr(fn); Debug.fprintln("sei", fnstr); then - (cache,e,prop,st_1,dae); + (cache,e,prop,st,dae); /* Non-interactive mode */ case (cache,env,fn,args,nargs,(impl as false),st) @@ -6688,12 +6686,10 @@ algorithm Debug.fprintln("sei", fnstr); fn_1 = Absyn.crefToPath(fn); (cache,e,prop,dae) = elabCallArgs(cache,env, fn_1, args, nargs, impl, st); - // adrpo: for non-interactive function calls DO NOT GENERATE CODE or DLL! - st_1 = st; /* (cache,st_1) = generateCompiledFunction(cache,env, fn, e, prop, st); */ Debug.fprint("sei", "elab_call 4 succeeded: "); Debug.fprintln("sei", fnstr); then - (cache,e,prop,st_1,dae); + (cache,e,prop,st,dae); case (cache,env,fn,args,nargs,impl,st) equation true = RTOpts.debugFlag("failtrace"); @@ -7807,172 +7803,6 @@ algorithm end matchcontinue; end needToRebuild; -protected function generateCompiledFunction -"function: generateCompiledFunction - TODO: This currently only works for top level functions. For functions inside packages - we need to reimplement without using lookup functions, since we can not build - correct env for packages containing functions." - input Env.Cache inCache; - input Env.Env inEnv; - input Absyn.ComponentRef inComponentRef; - input DAE.Exp inExp; - input DAE.Properties inProperties; - input Option inInteractiveInteractiveSymbolTableOption; - output Env.Cache outCache; - output Option outInteractiveInteractiveSymbolTableOption; -algorithm - (outCache,outInteractiveInteractiveSymbolTableOption) := - matchcontinue (inCache,inEnv,inComponentRef,inExp,inProperties,inInteractiveInteractiveSymbolTableOption) - local - Absyn.Path pfn,path; - list env,env_1,env_2; - Absyn.ComponentRef fn,cr; - DAE.Exp e,exp; - DAE.Properties prop; - Interactive.InteractiveSymbolTable st; - Absyn.Program p; - AbsynDep.Depends aDep; - list cflist; - SCode.Class cdef,cls; - Ident fid,pathstr,filename,str1,str2; - Option extdecl; - Option id,lan; - Option out; - list args; - list p_1,a; - DAE.DAElist d,d_1; - list libs; - tuple> t; - list b; - list c; - Env.Cache cache; - list lf; - Real buildTime; - Real fileLoadTime; - String fNew,fOld; - Real edit, build; - - case (cache,env,fn,e,prop,st) /* Do not compile if the function is a \"known\" external function, e.g. math lib. */ - local Option st; - equation - path = Absyn.crefToPath(fn); - (cache,cdef,env_1) = Lookup.lookupClass(cache,env, path, false); - SCode.CLASS(name = fid,restriction = SCode.R_EXT_FUNCTION(),classDef = SCode.PARTS(externalDecl = extdecl)) = cdef; - SOME(Absyn.EXTERNALDECL(id,lan,out,args,_)) = extdecl; - Ceval.isKnownExternalFunc(fid, id); - Debug.fprintln("sei", "function is known external func"); - then - (cache,st); - - /* adrpo: TODO! this needs more work as if we don't have a symtab we run into unloading of dlls problem */ - // see if we have the function and we dont'e need to rebuild! - case (cache,env,fn,e,prop,SOME((st as Interactive.SYMBOLTABLE(p,_,_,_,_,cflist,_)))) - equation - Debug.fprintln("sei", "generate_compiled_function: start1"); - pfn = Absyn.crefToPath(fn); - (true, _, buildTime, fOld) = isFunctionInCflist(cflist, pfn); - Absyn.CLASS(_,_,_,_,Absyn.R_FUNCTION(),_,Absyn.INFO(fileName = fNew)) = Interactive.getPathedClassInProgram(pfn, p); - false = stringEqual(fNew,""); // see if the WE have a file or not! - false = needToRebuild(fNew,fOld,buildTime); // we don't need to rebuild! - Debug.fprintln("sei", "function is in Cflist"); - then - (cache,SOME(st)); - /* adrpo: TODO! this needs more work as if we don't have a symtab we run into unloading of dlls problem */ - // see if we have the function and we dont'e need to rebuild based on ast build times - case (cache,env,fn,e,prop,SOME((st as Interactive.SYMBOLTABLE(p as Absyn.PROGRAM(globalBuildTimes=Absyn.TIMESTAMP(_,edit)),_,_,_,_,cflist,_)))) - equation - Debug.fprintln("sei", "generate_compiled_function: start1.5"); - pfn = Absyn.crefToPath(fn); - (true, _, buildTime, fOld) = isFunctionInCflist(cflist, pfn); - Absyn.CLASS(_,_,_,_,Absyn.R_FUNCTION(),_,Absyn.INFO(fileName=fNew, buildTimes=Absyn.TIMESTAMP(build,_))) = Interactive.getPathedClassInProgram(pfn, p); - - // note, this should only work for classes that have no file name! - true = stringEqual(fNew,""); // see that we don't have a file! - - // see if the build time from the class is the same as the build time from the compiled functions list - true = (buildTime >=. build); - true = (buildTime >. edit); - Debug.fprintln("sei", "function is in Cflist with the same build time as the class"); - then - (cache,SOME(st)); - /* adrpo: TODO! this needs more work as if we don't have a symtab we run into unloading of dlls problem */ - case (cache,env,fn,e,prop,SOME((st as Interactive.SYMBOLTABLE(p as Absyn.PROGRAM(globalBuildTimes=ts),aDep,a,b,c,cflist,lf)))) - local - Absyn.TimeStamp ts; - Integer libHandle, funcHandle; - String funcstr,f; - Real buildTime; - Boolean ifFuncInList; - list newCF; - String name; - Boolean ppref, fpref, epref; - Absyn.Restriction restriction "Restriction" ; - Absyn.ClassDef body; - Absyn.Info info; - Absyn.Within w; - String funcFileNameStr; - equation - Debug.fprintln("sei", "generate_compiled_function: start2"); - path = Absyn.crefToPath(fn); - (cache,false) = isExternalObjectFunction(cache,env,path); - newCF = Interactive.removeCf(path, cflist); // remove it as it might be there with an older build time. - - Absyn.CLASS(name,ppref,fpref,epref,Absyn.R_FUNCTION(),body,info) = Interactive.getPathedClassInProgram(path, p); - // p_1 = SCodeUtil.translateAbsyn2SCode(p); - Debug.fprintln("sei", "generate_compiled_function: elaborated"); - (cache,cls,env_1) = Lookup.lookupClass(cache,env, path, false) " Inst.instantiate_implicit(p\') => d & message" ; - Debug.fprintln("sei", "generate_compiled_function: class looked up"); - (_,env_2,_,d) = Inst.implicitFunctionInstantiation(cache, env_1, InnerOuter.emptyInstHierarchy, - DAE.NOMOD(), Prefix.NOPRE(), Connect.emptySet, cls, {}); - Debug.fprintln("sei", "generate_compiled_function: function instantiated"); - Print.clearBuf(); - // - // d_1 = ModUtil.stringPrefixParams(DAE.DAE(d)); - // libs = Codegen.generateFunctions(d_1); - // - Debug.fprintln("sei", "generate_compiled_function: function generated"); - (cache, funcstr) = CevalScript.cevalGenerateFunction(cache,env_2,path); - t = Types.getPropType(prop) " & Debug.fprintln(\"sei\", \"generate_compiled_function: compiled\")" ; - libHandle = System.loadLibrary(funcstr); - funcHandle = System.lookupFunction(libHandle, stringAppend("in_", funcstr)); - System.freeLibrary(libHandle); - buildTime = System.getCurrentTime(); - // adrpo: TODO! this needs more work as if we don't have a symtab we run into unloading of dlls problem - // update the build time in the class! - info = Absyn.setBuildTimeInInfo(buildTime,info); - ts = Absyn.setTimeStampBuild(ts, buildTime); - w = Interactive.buildWithin(path); - Debug.fprintln("dynload", "Updating build time for function path: " +& Absyn.pathString(path) +& " within: " +& Dump.unparseWithin(0, w) +& "\n"); - p = Interactive.updateProgram(Absyn.PROGRAM({Absyn.CLASS(name,ppref,fpref,epref,Absyn.R_FUNCTION(),body,info)},w,ts), p); - f = Absyn.getFileNameFromInfo(info); - Debug.fprintln("sei", "Static: added the function in the compiled functions list"); - then - (cache,SOME(Interactive.SYMBOLTABLE(p,aDep,a,b,c, Interactive.CFunction(path,t,funcHandle,buildTime,f) :: newCF,lf))); - - case (cache,env,fn,e,prop,NONE) /* PROP_TUPLE? */ - equation - Debug.fprintln("sei", "generate_compiled_function: start3"); - then - (cache,NONE); - case (cache,env,cr,exp,prop,st) - local Option st; - equation - Debug.fprintln("failtrace", "- generate_compiled_function failed4"); - str1 = Dump.printComponentRefStr(cr); - str2 = Exp.printExpStr(exp); - Debug.fprint("failtrace", str1); - Debug.fprint("failtrace", " -- "); - Debug.fprintln("failtrace", str2); - then - (cache,st); - case (cache,_,_,_,_,st) - local Option st; - /* If fails, skip it. */ - then - (cache,st); - end matchcontinue; -end generateCompiledFunction; - public function isFunctionInCflist "function: isFunctionInCflist This function returns true if a function, named by an Absyn.Path, @@ -11348,14 +11178,14 @@ algorithm case (cache,env,subs,dims,impl) equation - ErrorExt.setCheckpoint(); + ErrorExt.setCheckpoint("elabSubscriptsDims"); (outCache,outSubs,outConst,dae) = elabSubscriptsDims2(cache,env,subs,dims,impl); - ErrorExt.rollBack(); + ErrorExt.rollBack("elabSubscriptsDims"); then (outCache,outSubs,outConst,dae); case (cache,env,subs,dims,impl) equation - ErrorExt.rollBack(); + ErrorExt.rollBack("elabSubscriptsDims"); s1 = Dump.printSubscriptsStr(subs); s2 = Types.printDimensionsStr(dims); //print(" adding error for {{" +& s1 +& "}},,{{" +& s2 +& "}} "); diff --git a/Compiler/runtime/errorext.cpp b/Compiler/runtime/errorext.cpp index 3686e7137c7..201ed543936 100644 --- a/Compiler/runtime/errorext.cpp +++ b/Compiler/runtime/errorext.cpp @@ -33,6 +33,7 @@ #include #include #include +#include using namespace std; @@ -73,7 +74,8 @@ bool error_on=true; absyn_info finfo; bool haveInfo(false); stack errorMessageQueue; // Global variable of all error messages. - vector checkPoints; + vector > checkPoints; // a checkpoint has a message index no, and a unique identifier + /* Adds a message without file info. */ void add_message(int errorID, char* type, @@ -174,32 +176,50 @@ extern "C" } RML_BEGIN_LABEL(ErrorExt__setCheckpoint) { - checkPoints.push_back(errorMessageQueue.size()); - //printf(" ERROREXT: setting checkpoint: %d\n",errorMessageQueue.size()); + char* id = RML_STRINGDATA(rmlA0); + + checkPoints.push_back(make_pair(errorMessageQueue.size(),string(id))); + //printf("checkPoint(%s)\n",id); + //printf(" ERROREXT: setting checkpoint: (%d,%s)\n",errorMessageQueue.size(),id); RML_TAILCALLK(rmlSC); } RML_END_LABEL RML_BEGIN_LABEL(ErrorExt__delCheckpoint) { + char* id = RML_STRINGDATA(rmlA0); + //printf("delCheckpoint(%s)\n",id); if(checkPoints.size() > 0){ //printf(" ERROREXT: deleting checkpoint: %d\n", checkPoints[checkPoints.size()-1]); + + // extract last checkpoint + pair cp; + cp = checkPoints[checkPoints.size()-1]; + if (cp.second != string(id)) { + printf("ERROREXT: deleting checkpoint called with id:%s but top of checkpoint stack has id %s\n", + cp.second.c_str(), + id); + exit(-1); + } checkPoints.pop_back(); } else{ - //printf(" ERROREXT: nothing to delete\n"); + printf(" ERROREXT: nothing to delete when calling delCheckPoint(%s)\n",id); + exit(-1); } RML_TAILCALLK(rmlSC); } RML_END_LABEL RML_BEGIN_LABEL(ErrorExt__rollBack) { + char* id = RML_STRINGDATA(rmlA0); + //printf("rollBack(%s)\n",id); if(checkPoints.size() > 0){ //printf(" ERROREXT: rollback to: %d from %d\n",checkPoints.back(),errorMessageQueue.size()); std::string res(""); //printf(res.c_str()); - //printf(" rollback from: %d to: %d\n",errorMessageQueue.size(),checkPoints.back()); - while(errorMessageQueue.size() > checkPoints.back() && errorMessageQueue.size() > 0){ - //printf("*** %d deleted %d ***\n",errorMessageQueue.size(),checkPoints.back()); + //printf(" rollback from: %d to: %d\n",errorMessageQueue.size(),checkPoints.back().first); + while(errorMessageQueue.size() > checkPoints.back().first && errorMessageQueue.size() > 0){ + //printf("*** %d deleted %d ***\n",errorMessageQueue.size(),checkPoints.back().first); /*if(!errorMessageQueue.empty()){ res = res+errorMessageQueue.top()->getMessage()+string("\n"); printf( (string("Deleted: ") + res).c_str()); @@ -210,8 +230,19 @@ extern "C" res = res+errorMessageQueue.top()->getMessage()+string("\n"); printf("(%d)new bottom message: %s\n",checkPoints.size(),res.c_str()); }*/ + pair cp; + cp = checkPoints[checkPoints.size()-1]; + if (cp.second != string(id)) { + printf("ERROREXT: deleting checkpoint called with id:%s but top of checkpoint stack has id %s\n", + cp.second.c_str(), + id); + exit(-1); + } checkPoints.pop_back(); - } + } else { + printf("ERROREXT: caling rollback with id: %s on empty checkpoint stack\n",id); + exit(-1); + } RML_TAILCALLK(rmlSC); } RML_END_LABEL