Skip to content

Commit

Permalink
- Added source information to some error messages.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15656 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Mar 27, 2013
1 parent 2912dda commit c5d7999
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 289 deletions.
27 changes: 15 additions & 12 deletions Compiler/FrontEnd/Algorithm.mo
Expand Up @@ -434,7 +434,7 @@ algorithm
case (e, DAE.PROP(type_ = t), tb, eib, fb, _)
equation
(e, _) = Types.matchType(e, t, DAE.T_BOOL_DEFAULT, true);
else_ = makeElse(eib, fb);
else_ = makeElse(eib, fb, source);
then
{DAE.STMT_IF(e, tb, else_, source)};
case (e, DAE.PROP(type_ = t), _, _, _, _)
Expand Down Expand Up @@ -525,34 +525,37 @@ end optimizeElseIf;

protected function makeElse "function: makeElse
This function creates the ELSE part of the DAE.STMT_IF and checks if is correct."
input list<tuple<DAE.Exp, DAE.Properties, list<Statement>>> inTplExpExpTypesPropertiesStatementLstLst;
input list<tuple<DAE.Exp, DAE.Properties, list<Statement>>> inTuple;
input list<Statement> inStatementLst;
input DAE.ElementSource inSource;
output Else outElse;
algorithm
outElse:=
matchcontinue (inTplExpExpTypesPropertiesStatementLstLst, inStatementLst)
outElse := matchcontinue(inTuple, inStatementLst, inSource)
local
list<Statement> fb, b;
Else else_;
DAE.Exp e;
list<tuple<DAE.Exp, DAE.Properties, list<Statement>>> xs;
Ident e_str, t_str;
DAE.Type t;
case ({}, {}) then DAE.NOELSE(); /* This removes empty else branches */
case ({}, fb) then DAE.ELSE(fb);
case (((DAE.BCONST(true), DAE.PROP(type_ = t), b) :: xs), fb) then DAE.ELSE(b);
case (((DAE.BCONST(false), DAE.PROP(type_ = t), b) :: xs), fb) then makeElse(xs, fb);
case (((e, DAE.PROP(type_ = t), b) :: xs), fb)
Absyn.Info info;

case ({}, {}, _) then DAE.NOELSE(); /* This removes empty else branches */
case ({}, fb, _) then DAE.ELSE(fb);
case (((DAE.BCONST(true), DAE.PROP(type_ = t), b) :: xs), fb, _) then DAE.ELSE(b);
case (((DAE.BCONST(false), DAE.PROP(type_ = t), b) :: xs), fb, _) then makeElse(xs, fb, inSource);
case (((e, DAE.PROP(type_ = t), b) :: xs), fb, _)
equation
(e, _) = Types.matchType(e, t, DAE.T_BOOL_DEFAULT, true);
else_ = makeElse(xs, fb);
else_ = makeElse(xs, fb, inSource);
then
DAE.ELSEIF(e, b, else_);
case (((e, DAE.PROP(type_ = t), _) :: _), _)
case (((e, DAE.PROP(type_ = t), _) :: _), _, _)
equation
e_str = ExpressionDump.printExpStr(e);
t_str = Types.unparseType(t);
Error.addMessage(Error.IF_CONDITION_TYPE_ERROR, {e_str, t_str});
info = DAEUtil.getElementSourceFileInfo(inSource);
Error.addSourceMessage(Error.IF_CONDITION_TYPE_ERROR, {e_str, t_str}, info);
then
fail();
end matchcontinue;
Expand Down
29 changes: 18 additions & 11 deletions Compiler/FrontEnd/CevalFunction.mo
Expand Up @@ -118,6 +118,7 @@ algorithm
Env.Cache cache;
SymbolTable st;
Boolean partialPrefix;
DAE.ElementSource src;

// The DAE.FUNCTION structure might contain an optional function derivative
// mapping which is why functions below is a list. We only evaluate the
Expand All @@ -126,11 +127,12 @@ algorithm
path = p,
functions = func :: _,
type_ = ty,
partialPrefix = false), _, st)
partialPrefix = false,
source = src), _, st)
equation
func_name = Absyn.pathString(p);
(cache, result, st) = evaluateFunctionDefinition(inCache, inEnv, func_name,
func, ty, inFunctionArguments, st);
func, ty, inFunctionArguments, src, st);
then
(cache, result, st);

Expand All @@ -155,13 +157,14 @@ protected function evaluateFunctionDefinition
input DAE.FunctionDefinition inFunc;
input DAE.Type inFuncType;
input list<Values.Value> inFuncArgs;
input DAE.ElementSource inSource;
input SymbolTable inST;
output Env.Cache outCache;
output Values.Value outResult;
output SymbolTable outST;
algorithm
(outCache, outResult, outST) :=
matchcontinue(inCache, inEnv, inFuncName, inFunc, inFuncType, inFuncArgs, inST)
matchcontinue(inCache, inEnv, inFuncName, inFunc, inFuncType, inFuncArgs, inSource, inST)
local
list<DAE.Element> body;
list<DAE.Element> vars, output_vars;
Expand All @@ -175,7 +178,7 @@ algorithm
list<DAE.ExtArg> ext_fun_args;
DAE.ExtArg ext_fun_ret;

case (_, _, _, DAE.FUNCTION_DEF(body = body), _, _, st)
case (_, _, _, DAE.FUNCTION_DEF(body = body), _, _, _, st)
equation
// Split the definition into function variables and statements.
(vars, body) = List.splitOnFirstMatch(body, DAEUtil.isNotVar);
Expand All @@ -188,7 +191,7 @@ algorithm
// Pair the input arguments to input parameters and sort the function
// variables by dependencies.
func_params = pairFuncParamsWithArgs(vars, inFuncArgs);
func_params = sortFunctionVarsByDependency(func_params);
func_params = sortFunctionVarsByDependency(func_params, inSource);

// Create an environment for the function and add all function variables.
(cache, env, st) =
Expand All @@ -205,7 +208,7 @@ algorithm
case (_, _, _, DAE.FUNCTION_EXT(body = body, externalDecl =
DAE.EXTERNALDECL(name = ext_fun_name,
args = ext_fun_args,
returnArg = ext_fun_ret)), _, _, st)
returnArg = ext_fun_ret)), _, _, _, st)
equation
// Get all variables from the function. Ignore everything else, since
// external functions shouldn't have statements.
Expand All @@ -219,7 +222,7 @@ algorithm
// Pair the input arguments to input parameters and sort the function
// variables by dependencies.
func_params = pairFuncParamsWithArgs(vars, inFuncArgs);
func_params = sortFunctionVarsByDependency(func_params);
func_params = sortFunctionVarsByDependency(func_params, inSource);

// Create an environment for the function and add all function variables.
(cache, env, st) =
Expand Down Expand Up @@ -2591,14 +2594,15 @@ protected function sortFunctionVarsByDependency
the list of variables so that any dependencies to a variable will be before
the variable in resulting list."
input list<FunctionVar> inFuncVars;
input DAE.ElementSource inSource;
output list<FunctionVar> outFuncVars;
protected
list<tuple<FunctionVar, list<FunctionVar>>> cycles;
algorithm
(outFuncVars, cycles) := Graph.topologicalSort(
Graph.buildGraph(inFuncVars, getElementDependencies, inFuncVars),
isElementEqual);
checkCyclicalComponents(cycles);
checkCyclicalComponents(cycles, inSource);
end sortFunctionVarsByDependency;

protected function getElementDependencies
Expand Down Expand Up @@ -2802,17 +2806,19 @@ protected function checkCyclicalComponents
not empty, print an error message and fail, since it's not allowed for
constants or parameters to have cyclic dependencies."
input list<tuple<FunctionVar, list<FunctionVar>>> inCycles;
input DAE.ElementSource inSource;
algorithm
_ := match(inCycles)
_ := match(inCycles, inSource)
local
list<list<FunctionVar>> cycles;
list<list<DAE.Element>> elements;
list<list<DAE.ComponentRef>> crefs;
list<list<String>> names;
list<String> cycles_strs;
String cycles_str, scope_str;
Absyn.Info info;

case ({}) then ();
case ({}, _) then ();

else
equation
Expand All @@ -2825,7 +2831,8 @@ algorithm
cycles_str = stringDelimitList(cycles_strs, "}, {");
cycles_str = "{" +& cycles_str +& "}";
scope_str = "";
Error.addMessage(Error.CIRCULAR_COMPONENTS, {scope_str, cycles_str});
info = DAEUtil.getElementSourceFileInfo(inSource);
Error.addSourceMessage(Error.CIRCULAR_COMPONENTS, {scope_str, cycles_str}, info);
then
fail();

Expand Down
49 changes: 45 additions & 4 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -2534,6 +2534,7 @@ algorithm
DAE.ElementSource source "the element origin";
list<list<DAE.ComponentRef>> crefslist;
Boolean b;
Absyn.Info info;

case({},acc) then acc;

Expand Down Expand Up @@ -2595,7 +2596,8 @@ algorithm
case(el::_,acc)
equation
msg = "- DAEUtil.verifyWhenEquationStatements failed on: " +& DAEDump.dumpElementsStr({el});
Error.addMessage(Error.INTERNAL_ERROR,{msg});
info = getElementSourceFileInfo(getElementSource(el));
Error.addSourceMessage(Error.INTERNAL_ERROR,{msg}, info);
then
fail();
end match;
Expand Down Expand Up @@ -3367,6 +3369,8 @@ algorithm
DAE.ComponentRef cr1,cr2;
DAE.Type ty,ty1,ty2;
String str;
Absyn.Info info;

// normal equation
case(DAE.EQUATION(e1,e2,_))
equation
Expand Down Expand Up @@ -3439,7 +3443,8 @@ algorithm
case(eq)
equation
str = "- DAEUtil.makeEquationToResidualExp failed to transform equation: " +& DAEDump.dumpEquationStr(eq) +& " to residual form!";
Error.addMessage(Error.INTERNAL_ERROR, {str});
info = getElementSourceFileInfo(getElementSource(eq));
Error.addSourceMessage(Error.INTERNAL_ERROR, {str}, info);
then fail();
end matchcontinue;
end makeEquationToResidualExp;
Expand Down Expand Up @@ -4051,6 +4056,7 @@ algorithm
list<DAE.Exp> expl;
DAE.ElementSource source "the origin of the element";
Type_a extraArg;
Absyn.Info info;

case(DAE.VAR(cr,kind,dir,prl,prot,tp,optExp,dims,ct,source,attr,cmt,io),_,extraArg)
equation
Expand Down Expand Up @@ -4238,9 +4244,12 @@ algorithm
(elt,extraArg);

// Empty function call - stefan
case(DAE.NORETCALL(_, _, _),_,extraArg)
case(DAE.NORETCALL(source = source),_,extraArg)
equation
Error.addMessage(Error.UNSUPPORTED_LANGUAGE_FEATURE, {"Empty function call in equations", "Move the function calls to appropriate algorithm section"});
info = getElementSourceFileInfo(source);
Error.addSourceMessage(Error.UNSUPPORTED_LANGUAGE_FEATURE,
{"Empty function call in equations",
"Move the function calls to appropriate algorithm section"}, info);
then
fail();

Expand Down Expand Up @@ -6684,4 +6693,36 @@ algorithm
end match;
end getElementSource;

public function getStatementSource
"Returns the element source associated with a statement."
input DAE.Statement inStatement;
output DAE.ElementSource outSource;
algorithm
outSource := match(inStatement)
local
DAE.ElementSource source;

case DAE.STMT_ASSIGN(source = source) then source;
case DAE.STMT_TUPLE_ASSIGN(source = source) then source;
case DAE.STMT_ASSIGN_ARR(source = source) then source;
case DAE.STMT_IF(source = source) then source;
case DAE.STMT_FOR(source = source) then source;
case DAE.STMT_PARFOR(source = source) then source;
case DAE.STMT_WHILE(source = source) then source;
case DAE.STMT_WHEN(source = source) then source;
case DAE.STMT_ASSERT(source = source) then source;
case DAE.STMT_TERMINATE(source = source) then source;
case DAE.STMT_REINIT(source = source) then source;
case DAE.STMT_NORETCALL(source = source) then source;
case DAE.STMT_RETURN(source = source) then source;
case DAE.STMT_BREAK(source = source) then source;
case DAE.STMT_ARRAY_INIT(source = source) then source;
case DAE.STMT_FAILURE(source = source) then source;
case DAE.STMT_TRY(source = source) then source;
case DAE.STMT_CATCH(source = source) then source;
case DAE.STMT_THROW(source = source) then source;

end match;
end getStatementSource;

end DAEUtil;
36 changes: 21 additions & 15 deletions Compiler/FrontEnd/InnerOuter.mo
Expand Up @@ -1051,6 +1051,8 @@ algorithm
String str,str2; DAE.ComponentRef cr; DAE.Element v;
list<DAE.ComponentRef> crs;
Absyn.InnerOuter io;
DAE.ElementSource source;
Absyn.Info info;

case(DAE.VAR(componentRef=cr),innerVars)
equation
Expand All @@ -1065,13 +1067,14 @@ algorithm
// ?? adrpo: NOT USED! TODO! FIXME! str = ComponentReference.printComponentRefStr(cr);
failExceptForCheck();
then ();
case(DAE.VAR(componentRef=cr, innerOuter = io),innerVars)
case(DAE.VAR(componentRef=cr, innerOuter = io, source = source),innerVars)
equation
crs = List.map(innerVars,DAEUtil.varCref);
{} = List.select1(crs, isInnerOuterMatch, cr);
str2 = Dump.unparseInnerouterStr(io);
str = ComponentReference.printComponentRefStr(cr);
Error.addMessage(Error.MISSING_INNER_PREFIX,{str,str2});
info = DAEUtil.getElementSourceFileInfo(source);
Error.addSourceMessage(Error.MISSING_INNER_PREFIX, {str,str2}, info);
then fail();
end matchcontinue;
end checkMissingInnerDecl2;
Expand Down Expand Up @@ -1272,21 +1275,24 @@ According to specification modifiers on outer elements is not allowed."
input DAE.Mod inMod;
input Absyn.InnerOuter io;
input Boolean impl;
input Absyn.Info inInfo;
output Boolean modd;
algorithm
modd := matchcontinue(cache,env,ih,prefix,componentName,cr,inMod,io,impl)
local
String s1,s2,s;
// if we don't have the same modification on inner report error!
case(_,_,_,_,_,_,DAE.MOD(finalPrefix = _),Absyn.OUTER(),_)
equation
s1 = ComponentReference.printComponentRefStr(cr);
s2 = Mod.prettyPrintMod(inMod, 0);
s = s1 +& " " +& s2;
Error.addMessage(Error.OUTER_MODIFICATION, {s});
then
true;
case(_,_,_,_,_,_,_,_,_) then false;
modd := matchcontinue(cache,env,ih,prefix,componentName,cr,inMod,io,impl,inInfo)
local
String s1,s2,s;
// if we don't have the same modification on inner report error!
case(_,_,_,_,_,_,DAE.MOD(finalPrefix = _),Absyn.OUTER(),_,_)
equation
s1 = ComponentReference.printComponentRefStr(cr);
s2 = Mod.prettyPrintMod(inMod, 0);
s = s1 +& " " +& s2;
Error.addSourceMessage(Error.OUTER_MODIFICATION, {s}, inInfo);
then
true;

else false;

end matchcontinue;
end modificationOnOuter;

Expand Down

0 comments on commit c5d7999

Please sign in to comment.