Skip to content

Commit

Permalink
Improved some error messages
Browse files Browse the repository at this point in the history
* Error.NON_EXISTING_DERIVATIVE
* ExpressionSolve
  • Loading branch information
lochel committed Oct 7, 2015
1 parent 7bf48ba commit 4cdc91b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 54 deletions.
33 changes: 10 additions & 23 deletions Compiler/BackEnd/Differentiate.mo
Expand Up @@ -120,7 +120,6 @@ public function differentiateExpTime
output DAE.Exp outExp;
output BackendDAE.Shared outShared;
protected
String msg;
DAE.Exp dexp;
DAE.FunctionTree funcs;
BackendDAE.DifferentiateInputData diffData;
Expand All @@ -140,8 +139,7 @@ algorithm
//Error.addSourceMessage(Error.INTERNAL_ERROR, {msg}, DAEUtil.getElementSourceFileInfo(DAE.emptyElementSource));

if Flags.isSet(Flags.FAILTRACE) then
msg := "\nDifferentiate.differentiateExpTime failed for " + ExpressionDump.printExpStr(inExp) + "\n\n";
Error.addMessage(Error.NON_EXISTING_DERIVATIVE, {msg});
Error.addSourceMessage(Error.NON_EXISTING_DERIVATIVE, {ExpressionDump.printExpStr(inExp), "time"}, sourceInfo());
end if;
fail();
end try;
Expand All @@ -155,7 +153,6 @@ public function differentiateExpSolve
output DAE.Exp outExp;
protected
list<DAE.Exp> fac = Expression.factors(inExp);
String msg;
DAE.Exp dexp;
BackendDAE.DifferentiateInputData diffData;
DAE.FunctionTree fun;
Expand All @@ -175,24 +172,22 @@ algorithm
(outExp, _) := ExpressionSimplify.simplify(dexp);
else
if Flags.isSet(Flags.FAILTRACE) then
msg := "\nDifferentiate.differentiateExpSolve failed for " + ExpressionDump.printExpStr(inExp) + "\n\n";
Error.addMessage(Error.NON_EXISTING_DERIVATIVE, {msg});
Error.addSourceMessage(Error.NON_EXISTING_DERIVATIVE, {ExpressionDump.printExpStr(inExp), ComponentReference.crefStr(inCref)}, sourceInfo());
end if;
fail();
end try;
end differentiateExpSolve;


public function differentiateExpCrefFullJacobian
"Differentiates an equation with respect to the time variable."
"Differentiates an expression inExp with respect to inCref."
input DAE.Exp inExp;
input DAE.ComponentRef inCref;
input BackendDAE.Variables inVariables;
input BackendDAE.Shared inShared;
output DAE.Exp outExp;
output BackendDAE.Shared outShared;
protected
String msg;
DAE.Exp dexp;
DAE.FunctionTree funcs;
BackendDAE.DifferentiateInputData diffData;
Expand All @@ -212,8 +207,7 @@ algorithm
//Error.addSourceMessage(Error.INTERNAL_ERROR, {msg}, DAEUtil.getElementSourceFileInfo(DAE.emptyElementSource));

if Flags.isSet(Flags.FAILTRACE) then
msg := "\nDifferentiate.differentiateCrefFullJacobian failed for " + ExpressionDump.printExpStr(inExp) + "\n\n";
Error.addMessage(Error.NON_EXISTING_DERIVATIVE, {msg});
Error.addSourceMessage(Error.NON_EXISTING_DERIVATIVE, {ExpressionDump.printExpStr(inExp), ComponentReference.crefStr(inCref)}, sourceInfo());
end if;
fail();
end try;
Expand Down Expand Up @@ -244,7 +238,6 @@ algorithm
DAE.FunctionTree funcs;
list<BackendDAE.Equation> rest, eqns;
BackendDAE.Equation eqn;
String msg;

case {} then (listReverse(inEquationsAccum), inFunctionTree);

Expand All @@ -258,8 +251,7 @@ algorithm

case eqn::_
equation
msg = "\nDifferentiate.differentiateEquations failed for " + BackendDump.equationString(eqn) + "\n\n";
Error.addMessage(Error.NON_EXISTING_DERIVATIVE, {msg});
Error.addSourceMessage(Error.NON_EXISTING_DERIVATIVE, {BackendDump.equationString(eqn), ComponentReference.crefStr(inDiffwrtCref)}, sourceInfo());
then
fail();
end matchcontinue;
Expand All @@ -284,7 +276,7 @@ algorithm
list<DAE.Exp> out1, expExpLst, expExpLst1;
DAE.Type exptyp;
list<Integer> dimSize;
String msg, se1, dse1, se2, dse2;
String se1, dse1, se2, dse2;
DAE.SymbolicOperation op1, op2;
DAE.FunctionTree funcs;
DAE.Algorithm alg;
Expand Down Expand Up @@ -399,8 +391,7 @@ algorithm

else
equation
msg = "\nDifferentiate.differentiateEquation failed for " + BackendDump.equationString(inEquation) + "\n\n";
Error.addMessage(Error.NON_EXISTING_DERIVATIVE, {msg});
Error.addSourceMessage(Error.NON_EXISTING_DERIVATIVE, {BackendDump.equationString(inEquation), ComponentReference.crefStr(inDiffwrtCref)}, sourceInfo());
then
fail();
end match;
Expand Down Expand Up @@ -436,10 +427,9 @@ algorithm
(eqnsLst, funcs) = differentiateEquationsLst(rest, inDiffwrtCref, inInputData, inDiffType, eqnsLst, funcs);
then (eqnsLst, funcs);

else
case eqns::_
equation
msg = "\nDifferentiate.differentiateEquationsLst failed.\n\n";
Error.addMessage(Error.NON_EXISTING_DERIVATIVE, {msg});
Error.addSourceMessage(Error.NON_EXISTING_DERIVATIVE, {BackendDump.equationListString(eqns, "equation list"), ComponentReference.crefStr(inDiffwrtCref)}, sourceInfo());
then
fail();
end matchcontinue;
Expand Down Expand Up @@ -1343,10 +1333,7 @@ algorithm
/*
case (e as DAE.CALL(expLst = _), _, _, _, _)
equation
s1 = ExpressionDump.printExpStr(e);
s2 = ComponentReference.printComponentRefStr(inDiffwrtCref);
serr = stringAppendList({"\n- Function differentiateCalls failed. differentiateExp ",s1," w.r.t: ",s2," failed\n"});
Error.addMessage(Error.NON_EXISTING_DERIVATIVE, {serr});
Error.addMessage(Error.NON_EXISTING_DERIVATIVE, {ExpressionDump.printExpStr(e), ComponentReference.printComponentRefStr(inDiffwrtCref)});
then
fail();
*/
Expand Down
52 changes: 22 additions & 30 deletions Compiler/BackEnd/ExpressionSolve.mo
Expand Up @@ -250,22 +250,18 @@ algorithm
ExpressionDump.dumpExpStr(inExp2,0) + " with respect to: " +
ExpressionDump.printExpStr(inExp3) + "\n");
*/
(outExp,outAsserts,dummy1, dummy2, dummyI) := matchcontinue(inExp1, inExp2, inExp3)
case(_,_,_) then solveSimple(inExp1, inExp2, inExp3,0);
case(_,_,_) then solveSimple(inExp2, inExp1, inExp3,0);
case(_,_,_) then solveWork(inExp1, inExp2, inExp3, NONE(), NONE(), 0);
else
equation
if Flags.isSet(Flags.FAILTRACE) then
print("\n-ExpressionSolve.solve failed:\n");
print(ExpressionDump.printExpStr(inExp1) + " = " + ExpressionDump.printExpStr(inExp2));
print(" with respect to: " + ExpressionDump.printExpStr(inExp3));
end if;
then fail();
end matchcontinue;
(outExp,outAsserts,dummy1, dummy2, dummyI) := matchcontinue inExp1
case _ then solveSimple(inExp1, inExp2, inExp3, 0);
case _ then solveSimple(inExp2, inExp1, inExp3, 0);
case _ then solveWork(inExp1, inExp2, inExp3, NONE(), NONE(), 0);
else equation
if Flags.isSet(Flags.FAILTRACE) then
Error.addInternalError("Failed to solve \"" + ExpressionDump.printExpStr(inExp1) + " = " + ExpressionDump.printExpStr(inExp2) + "\" w.r.t. \"" + ExpressionDump.printExpStr(inExp3) + "\"", sourceInfo());
end if;
then fail();
end matchcontinue;

(outExp,_) := ExpressionSimplify.simplify1(outExp);

end solve;


Expand All @@ -292,23 +288,19 @@ algorithm
ExpressionDump.dumpExpStr(inExp2,0) + " with respect to: " +
ExpressionDump.printExpStr(inExp3) + "\n");
*/
(outExp,outAsserts,eqnForNewVars,newVarsCrefs,dummyI) := matchcontinue(inExp1, inExp2, inExp3, functions, uniqueEqIndex)
case(_,_,_,_,_) then solveSimple(inExp1, inExp2, inExp3,0);
case(_,_,_,_,_) then solveSimple(inExp2, inExp1, inExp3,0);
case(_,_,_,_,_) then solveWork(inExp1, inExp2, inExp3, functions, uniqueEqIndex, 0);
else
equation
if Flags.isSet(Flags.FAILTRACE) then
print("\n-ExpressionSolve.solve2 failed:\n");
print(ExpressionDump.printExpStr(inExp1) + " = " + ExpressionDump.printExpStr(inExp2));
print(" with respect to: " + ExpressionDump.printExpStr(inExp3));
end if;
then fail();
end matchcontinue;

outExp := symEuler_helper(outExp, inExp3);
(outExp,_) := ExpressionSimplify.simplify1(outExp);
(outExp,outAsserts,eqnForNewVars,newVarsCrefs,dummyI) := matchcontinue inExp1
case _ then solveSimple(inExp1, inExp2, inExp3, 0);
case _ then solveSimple(inExp2, inExp1, inExp3, 0);
case _ then solveWork(inExp1, inExp2, inExp3, functions, uniqueEqIndex, 0);
else equation
if Flags.isSet(Flags.FAILTRACE) then
Error.addInternalError("Failed to solve \"" + ExpressionDump.printExpStr(inExp1) + " = " + ExpressionDump.printExpStr(inExp2) + "\" w.r.t. \"" + ExpressionDump.printExpStr(inExp3) + "\"", sourceInfo());
end if;
then fail();
end matchcontinue;

outExp := symEuler_helper(outExp, inExp3);
(outExp,_) := ExpressionSimplify.simplify1(outExp);
end solve2;


Expand Down
2 changes: 1 addition & 1 deletion Compiler/Util/Error.mo
Expand Up @@ -199,7 +199,7 @@ public constant Message STRUCT_SINGULAR_SYSTEM = MESSAGE(34, SYMBOLIC(), ERROR()
public constant Message UNSUPPORTED_LANGUAGE_FEATURE = MESSAGE(35, TRANSLATION(), ERROR(),
Util.gettext("The language feature %s is not supported. Suggested workaround: %s"));
public constant Message NON_EXISTING_DERIVATIVE = MESSAGE(36, SYMBOLIC(), ERROR(),
Util.gettext("Derivative of expression %s is non-existent."));
Util.gettext("Derivative of expression \"%s\" w.r.t. \"%s\" is non-existent."));
public constant Message NO_CLASSES_LOADED = MESSAGE(37, TRANSLATION(), ERROR(),
Util.gettext("No classes are loaded."));
public constant Message INST_PARTIAL_CLASS = MESSAGE(38, TRANSLATION(), ERROR(),
Expand Down

0 comments on commit 4cdc91b

Please sign in to comment.