Skip to content

Commit

Permalink
Fixed error messages (rollback/deleteCheckpoint)
Browse files Browse the repository at this point in the history
Both in ErrorExt.cpp(bug) and in Inst.mo(structural error).

Rewritten the handling of builtin functions. 
Now if a builtinfunction that has a handler failes, the translation fails. 
Builtin handlers also vectorize calls now. 


git-svn-id: https://openmodelica.org/svn/OpenModelica/branches/MathCoreOSMC@3917 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Björn Zachrisson committed Feb 26, 2009
1 parent e4f19c6 commit 945d80b
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 213 deletions.
7 changes: 5 additions & 2 deletions Compiler/Builtin.mo
Expand Up @@ -2800,11 +2800,14 @@ algorithm
*/
env = Env.extendFrameT(env, "cardinality", anyconnector2int);
env = Env.extendFrameT(env, "div", realReal2real) "non-differentiable functions" ;
env = Env.extendFrameT(env, "div", intInt2int) "non-differentiable functions" ;
env = Env.extendFrameT(env, "rem", realReal2real);
env = Env.extendFrameT(env, "ceil", real2int);
env = Env.extendFrameT(env, "rem", intInt2int);
env = Env.extendFrameT(env, "ceil", real2real);
envb = Env.extendFrameT(env, "floor", real2int);
env = Env.extendFrameT(envb, "integer", real2int);
env = Env.extendFrameT(env, "abs", real2real) "differentiable functions" ;
env = Env.extendFrameT(env, "abs", int2int) "differentiable functions" ;
env = Env.extendFrameT(env, "sign", real2real);
env = Env.extendFrameT(env, "sin", real2real) "Not in the report" ;
env = Env.extendFrameT(env, "cos", real2real);
Expand Down Expand Up @@ -3235,8 +3238,8 @@ algorithm
env = Env.extendFrameT(env, "skew", array1dimreal2array3dimreal);
env = Env.extendFrameT(env, "sqrt", int2real);
env = Env.extendFrameT(env, "sqrt", real2real);
env = Env.extendFrameT(env, "mod", intInt2int);
env = Env.extendFrameT(env, "mod", realReal2real);
env = Env.extendFrameT(env, "mod", intInt2int);
env = Env.extendFrameT(env, "constrain", realrealreal2real);
env = Env.extendFrameT(env, "constrain", array1dimrealarray1dimrealarray1dimreal2array1dimreal);
/*
Expand Down
9 changes: 5 additions & 4 deletions Compiler/Ceval.mo
Expand Up @@ -2098,7 +2098,7 @@ algorithm
(outCache,outValue,outInteractiveInteractiveSymbolTableOption):=
matchcontinue (inCache,inEnv,inExpExpLst,inBoolean,inInteractiveInteractiveSymbolTableOption,inMsg)
local
Real rv,rv_1,rvt,rv_2;
Real rv,rv_1,rvt,rv_2,realRet;
Integer ri,ri_1;
list<Env.Frame> env;
Exp.Exp exp;
Expand All @@ -2112,17 +2112,18 @@ algorithm
rv_1 = realFloor(rv);
ri = realInt(rv_1);
rvt = intReal(ri);
(rvt ==. rv) = true;
(rvt ==. rv) = true;
then
(cache,Values.INTEGER(ri),st);
(cache,Values.REAL(rvt),st);
case (cache,env,{exp},impl,st,msg)
equation
(cache,Values.REAL(rv),_) = ceval(cache,env, exp, impl, st, NONE, msg);
rv_1 = realFloor(rv);
ri = realInt(rv_1);
ri_1 = ri + 1;
realRet = intReal(ri_1);
then
(cache,Values.INTEGER(ri_1),st);
(cache,Values.REAL(realRet),st);
end matchcontinue;
end cevalBuiltinCeil;

Expand Down
11 changes: 9 additions & 2 deletions Compiler/Error.mo
Expand Up @@ -207,8 +207,11 @@ public constant ErrorID WARNING_RELATION_ON_REAL=509;
public constant ErrorID ERROR_BUILTIN_DELAY=510;
public constant ErrorID When_With_IF=511;
public constant ErrorID OUTER_MODIFICATION=512;
public constant ErrorID DERIVATIVE_NON_REAL=514;
public constant ErrorID REDUNDANT_GUESS=513 "Used by MathCore in Backend";



public constant ErrorID INDEX_REDUCTION_NOTIFICATION=1000;
public constant ErrorID SELECTED_STATE_DUE_TO_START_NOTIFICATION = 1001;
protected constant list<tuple<Integer, MessageType, Severity, String>> errorTable={(SYNTAX_ERROR,SYNTAX(),ERROR(),"Syntax error near: %s"),
Expand Down Expand Up @@ -350,7 +353,7 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(DIFFERENT_DIM_SIZE_IN_ARGUMENTS,TRANSLATION(),ERROR(),
"Different dimension sizes in arguments to %s"),
(DER_APPLIED_TO_CONST,TRANSLATION(),ERROR(),
"der operator applied to constant expression"),
"der operator applied to constant expression der(%s)"),
(ARGUMENT_MUST_BE_INTEGER_OR_REAL,TRANSLATION(),ERROR(),
"%s argument to %s must be Integer or Real expression"),
(ARGUMENT_MUST_BE_INTEGER,TRANSLATION(),ERROR(),
Expand Down Expand Up @@ -456,11 +459,13 @@ protected constant list<tuple<Integer, MessageType, Severity, String>> errorTabl
(When_With_IF,TRANSLATION(),ERROR(),
"When equations using if-statements on form 'if a then b=c else b = d' not implemented yet, use 'b=if a then c else d' as work around\n%s"),
(OUTER_MODIFICATION,TRANSLATION(),ERROR(),
"Modification on outer element: %s"),
"Modification on outer element: %s"),
(REDUNDANT_GUESS,TRANSLATION(),WARNING(),
"Start value is assigned for variable: %s, but not used since %s"),
(MISSING_INNER_PREFIX,TRANSLATION(),ERROR(),
"No corresponding 'INNER' declaration found for component %s declared as '%s'."),
(DERIVATIVE_NON_REAL,TRANSLATION(),ERROR(),
"Illegal derivative. der(%s) where %s is of type %s, which is not a subtype of real"),
(IMPLICIT_ITERATOR_NOT_FOUND_IN_LOOP_BODY,TRANSLATION(),ERROR(),
"Identificator %s of implicit for iterator must be present as array subscript in the loop body.")
};
Expand Down Expand Up @@ -509,10 +514,12 @@ algorithm
MessageTokens tokens;
case (error_id,tokens)
equation
//print(" adding message: " +& intString(error_id) +& "\n");
(msg_type,severity,msg) = lookupMessage(error_id);
msg_type_str = messageTypeStr(msg_type);
severity_string = severityStr(severity);
ErrorExt.addMessage(error_id, msg_type_str, severity_string, msg, tokens);
//print(" succ add " +& msg_type_str +& " " +& severity_string +& ", " +& msg +& "\n");
then
();
case (error_id,tokens)
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Exp.mo
Expand Up @@ -9841,7 +9841,7 @@ algorithm oty := matchcontinue(subs,ty)
case({},ty) then ty;
case(_::rest, ty)
equation
ty = unliftArray(ty);
ty = unliftArray(ty);
ty = unliftArrayTypeWithSubs(rest,ty);
then
ty;
Expand Down Expand Up @@ -11093,7 +11093,7 @@ algorithm str := matchcontinue(inExp)
case(CREF(cr,_)) then debugPrintComponentRefTypeStr(cr);
case(ARRAY(_,_,expl))
equation
s1 = Util.stringAppendList(Util.listMap(expl,debugPrintComponentRefExp));
s1 = "{" +& Util.stringAppendList(Util.listMap(expl,debugPrintComponentRefExp)) +& "}";
then
s1;
case(inExp) then printExpStr(inExp); // when not cref, print expression anyways since it is used for some debugging.
Expand Down
52 changes: 43 additions & 9 deletions Compiler/Inst.mo
Expand Up @@ -2380,7 +2380,7 @@ protected function instBasictypeBaseclass
end RealSignal;
Such classes can not have any other components,
and can only inherit one basic type."
input Env.Cache inCache;
input Env.Cache inCache;
input Env inEnv1;
input list<SCode.Element> inSCodeElementLst2;
input list<SCode.Element> inSCodeElementLst3;
Expand Down Expand Up @@ -2419,9 +2419,47 @@ algorithm
ErrorExt.rollBack();
then
(cache,SOME(ty),tys);
case (cache,env,{SCode.EXTENDS(baseClassPath = path,modifications = mod)},{},mods,inst_dims)
equation
ErrorExt.delCheckpoint();
then fail();
case (cache,env,{SCode.EXTENDS(baseClassPath = path,modifications = mod)},(_ :: _),mods,inst_dims) /* Inherits baseclass -and- has components */
equation
ErrorExt.setCheckpoint();
instBasictypeBaseclass2(inCache,inEnv1,inSCodeElementLst2,inSCodeElementLst3,inMod4,inInstDims5);
then
fail();
end matchcontinue;
end instBasictypeBaseclass;

protected function instBasictypeBaseclass2 "
Author: BZ, 2009-02
Helper function for instBasictypeBaseClass
Handles the fail case rollbacks/deleteCheckpoint of errors.
"
input Env.Cache inCache;
input Env inEnv1;
input list<SCode.Element> inSCodeElementLst2;
input list<SCode.Element> inSCodeElementLst3;
input Mod inMod4;
input InstDims inInstDims5;
algorithm _ := matchcontinue(inCache,inEnv1,inSCodeElementLst2,inSCodeElementLst3,inMod4,inInstDims5)
local
Types.Mod m_1,m_2,mods;
SCode.Class cdef,cdef_1;
list<Env.Frame> cenv,env_1,env;
list<DAE.Element> dae;
tuple<Types.TType, Option<Absyn.Path>> ty;
list<Types.Var> tys;
ClassInf.State st;
Boolean b1,b2,b3;
Absyn.Path path;
SCode.Mod mod;
InstDims inst_dims;
String classname;
Env.Cache cache;
case (cache,env,{SCode.EXTENDS(baseClassPath = path,modifications = mod)},(_ :: _),mods,inst_dims) /* Inherits baseclass -and- has components */
equation
(cache,m_1) = Mod.elabMod(cache,env, Prefix.NOPRE(), mod, true) "impl" ;
(cache,cdef,cenv) = Lookup.lookupClass(cache,env, path, true);
cdef_1 = SCode.classSetPartial(cdef, false);
Expand All @@ -2433,14 +2471,10 @@ algorithm
ErrorExt.rollBack();
Error.addMessage(Error.INHERIT_BASIC_WITH_COMPS, {classname});
then
fail();
case (cache,env,_,_,mods,inst_dims)
equation
ErrorExt.delCheckpoint();
then
fail();
end matchcontinue;
end instBasictypeBaseclass;
();
case(_,_,_,_,_,_) equation ErrorExt.delCheckpoint(); then ();
end matchcontinue;
end instBasictypeBaseclass2;

protected function addConnectionSetToEnv
"function: addConnectionSetToEnv
Expand Down

0 comments on commit 945d80b

Please sign in to comment.