Skip to content

Commit

Permalink
- if-equation to if-expr residual translation now ignores NORETCALL, …
Browse files Browse the repository at this point in the history
…and prints a warning

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8372 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Mar 26, 2011
1 parent 4e04df2 commit 7c3fb86
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
12 changes: 11 additions & 1 deletion Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -1107,6 +1107,8 @@ algorithm
String s1,s2,s3,s4,s5,str;
DAE.Exp e1,e2,e;
DAE.ComponentRef c,cr1,cr2;
list<DAE.Exp> es;
Absyn.Path path;

case (DAE.EQUATION(exp = e1,scalar = e2))
equation
Expand Down Expand Up @@ -1167,8 +1169,16 @@ algorithm
str = stringAppendList({" terminate(",s1,");\n"});
then
str;

case (DAE.NORETCALL(functionName=path,functionArgs=es))
equation
s1 = Absyn.pathString(path);
s2 = ExpressionDump.printExpStr(DAE.TUPLE(es));
str = stringAppendList({" ",s1,s2,";\n"});
then
str;
// adrpo: TODO! FIXME! should we say UNKNOWN equation here? we don't handle all cases!
case _ then "";
case _ then "#UNKNOWN_EQUATION#";
end matchcontinue;
end dumpEquationStr;

Expand Down
34 changes: 22 additions & 12 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -2868,6 +2868,9 @@ algorithm
// ignore terminate!
case (DAE.TERMINATE(message=_)::rest)
then countEquations(rest);
// ignore noretcall
case (DAE.NORETCALL(functionName=_)::rest)
then countEquations(rest);
// For an if-equation, count equations in branches
case (DAE.IF_EQUATION(equations2=tb,equations3=fb,source=source)::rest)
equation
Expand All @@ -2878,7 +2881,7 @@ algorithm
equation
n = countEquationsInBranches(tb,fb,source);
nr = countEquations(rest);
then nr + n;
then nr + n;
// any other case, just add 1
case (elt::rest)
equation
Expand Down Expand Up @@ -3000,7 +3003,7 @@ algorithm
then
{exp};
end matchcontinue;
end makeEquationToResidualExpLst;
end makeEquationToResidualExpLst;

protected function makeEquationToResidualExp ""
input DAE.Element eq;
Expand All @@ -3011,6 +3014,7 @@ algorithm
DAE.Exp e1,e2;
DAE.ComponentRef cr1,cr2;
DAE.ExpType ty,ty1,ty2;
String str;
// normal equation
case(DAE.EQUATION(e1,e2,_))
equation
Expand Down Expand Up @@ -3082,9 +3086,8 @@ algorithm
// failure
case(eq)
equation
true = RTOpts.debugFlag("failtrace");
Debug.fprintln("failtrace", "- DAEUtil.makeEquationToResidualExp failed to transform equation: " +&
DAEDump.dumpEquationStr(eq) +& " to residual form!");
str = "- DAEUtil.makeEquationToResidualExp failed to transform equation: " +& DAEDump.dumpEquationStr(eq) +& " to residual form!";
Error.addMessage(Error.INTERNAL_ERROR, {str});
then fail();
end matchcontinue;
end makeEquationToResidualExp;
Expand All @@ -3101,13 +3104,6 @@ algorithm
DAE.ElementSource source;
String str;
case ({}) then {};
case (eq::rest)
equation
exps1 = makeEquationToResidualExpLst(eq);
exps2 = makeEquationLstToResidualExpLst(rest);
exps = listAppend(exps1,exps2);
then
exps;
case ((eq as DAE.ASSERT(source = source))::rest)
equation
str = DAEDump.dumpEquationStr(eq);
Expand All @@ -3122,6 +3118,20 @@ algorithm
Error.addSourceMessage(Error.IF_EQUATION_WARNING,{str},getElementSourceFileInfo(source));
exps = makeEquationLstToResidualExpLst(rest);
then exps;
case ((eq as DAE.NORETCALL(source = source))::rest)
equation
str = DAEDump.dumpEquationStr(eq);
str = Util.stringReplaceChar(str,"\n","");
Error.addSourceMessage(Error.IF_EQUATION_WARNING,{str},getElementSourceFileInfo(source));
exps = makeEquationLstToResidualExpLst(rest);
then exps;
case (eq::rest)
equation
exps1 = makeEquationToResidualExpLst(eq);
exps2 = makeEquationLstToResidualExpLst(rest);
exps = listAppend(exps1,exps2);
then
exps;
end matchcontinue;
end makeEquationLstToResidualExpLst;

Expand Down
5 changes: 5 additions & 0 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -4120,6 +4120,7 @@ match stmt
case STMT_FOR(__) then
let iterType = expType(type_, iterIsArray)
let arrayType = expTypeArray(type_)

let stmtStr = (statementLst |> stmt =>
algStatement(stmt, context, &varDecls) ;separator="\n")
algStmtForGeneric_impl(range, iter, iterType, arrayType, iterIsArray, stmtStr,
Expand Down Expand Up @@ -4996,6 +4997,10 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/,
let &preExp += '<%retVar%> = <%cast%>pre(<%cref(arg.componentRef)%>);<%\n%>'
'<%retVar%>'

case CALL(path=IDENT(name="print"), expLst={e1}) then
let var1 = daeExp(e1, context, &preExp, &varDecls)
if acceptMetaModelicaGrammar() then 'print(<%var1%>)' else 'puts(<%var1%>)'

case CALL(tuple_=false, builtin=true,
path=IDENT(name="max"), ty = ET_REAL(), expLst={e1,e2}) then
let var1 = daeExp(e1, context, &preExp, &varDecls)
Expand Down

0 comments on commit 7c3fb86

Please sign in to comment.