Skip to content

Commit

Permalink
Use dumpExp instead of printExpStr in templates
Browse files Browse the repository at this point in the history
Note: In the future, Susan should probably gain a capability to print
text using text escape sequences directly.
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 21, 2016
1 parent f07d894 commit 3bd7ac2
Show file tree
Hide file tree
Showing 14 changed files with 624 additions and 611 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -10,5 +10,6 @@ configure.ac text eol=native
Makefile* text eol=native
*.pro text eol=native
*.mo eol=lf
*.tpl eol=lf
*.po eol=lf
*.g text eol=lf
23 changes: 12 additions & 11 deletions Compiler/Template/CodegenAdevs.tpl
Expand Up @@ -46,6 +46,7 @@
package CodegenAdevs
import interface SimCodeTV;
import CodegenUtil.*;
import ExpressionDumpTpl;

template translateModel(SimCode simCode)
"Generates Cpp code and header file for an adevs model."
Expand Down Expand Up @@ -2128,7 +2129,7 @@ template extReturnType(SimExtArg extArg)
match extArg
case ex as SIMEXTARG(__) then extType(type_,true /*Treat this as an input (pass by value)*/,false)
case SIMNOEXTARG(__) then "void"
case SIMEXTARGEXP(__) then error(sourceInfo(), 'Expression types are unsupported as return arguments <%printExpStr(exp)%>')
case SIMEXTARGEXP(__) then error(sourceInfo(), 'Expression types are unsupported as return arguments <%ExpressionDumpTpl.dumpExp(exp,"\"")%>')
else error(sourceInfo(), "Unsupported return argument")
end extReturnType;

Expand Down Expand Up @@ -3628,7 +3629,7 @@ template daeExp(Exp exp, Context context, Text &preExp /*BUFP*/, Text &varDecls
case e as BOX(__) then daeExpBox(e, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
case e as UNBOX(__) then daeExpUnbox(e, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
case e as SHARED_LITERAL(__) then daeExpSharedLiteral(e, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
else error(sourceInfo(), 'Unknown expression: <%ExpressionDump.printExpStr(exp)%>')
else error(sourceInfo(), 'Unknown expression: <%ExpressionDumpTpl.dumpExp(exp,"\"")%>')
end daeExp;


Expand Down Expand Up @@ -4125,17 +4126,17 @@ template daeExpCall(Exp call, Context context, Text &preExp /*BUFP*/,
case CALL(path=IDENT(name="der"), expLst={arg as CREF(__)}) then
'_DER<%cref(arg.componentRef)%>'
case CALL(path=IDENT(name="der"), expLst={exp}) then
error(sourceInfo(), 'Code generation does not support der(<%printExpStr(exp)%>)')
error(sourceInfo(), 'Code generation does not support der(<%ExpressionDumpTpl.dumpExp(exp,"\"")%>)')
case CALL(path=IDENT(name="pre"), expLst={arg}) then
daeExpCallPre(arg, context, preExp, varDecls)
case CALL(path=IDENT(name="edge"), expLst={arg as CREF(__)}) then
'(<%cref(arg.componentRef)%> && !_PRE<%cref(arg.componentRef)%>)'
case CALL(path=IDENT(name="edge"), expLst={exp}) then
error(sourceInfo(), 'Code generation does not support edge(<%printExpStr(exp)%>)')
error(sourceInfo(), 'Code generation does not support edge(<%ExpressionDumpTpl.dumpExp(exp,"\"")%>)')
case CALL(path=IDENT(name="change"), expLst={arg as CREF(__)}) then
'(<%cref(arg.componentRef)%> != _PRE<%cref(arg.componentRef)%>)'
case CALL(path=IDENT(name="change"), expLst={exp}) then
error(sourceInfo(), 'Code generation does not support change(<%printExpStr(exp)%>)')
error(sourceInfo(), 'Code generation does not support change(<%ExpressionDumpTpl.dumpExp(exp,"\"")%>)')

case CALL(path=IDENT(name="print"), expLst={e1}) then
let var1 = daeExp(e1, context, &preExp, &varDecls)
Expand Down Expand Up @@ -4623,7 +4624,7 @@ template daeExpCallPre(Exp exp, Context context, Text &preExp /*BUFP*/,
let cref = cref(cr.componentRef)
'*(&_PRE<%cref%> + <%offset%>)'
else
error(sourceInfo(), 'Code generation does not support pre(<%printExpStr(exp)%>)')
error(sourceInfo(), 'Code generation does not support pre(<%ExpressionDumpTpl.dumpExp(exp,"\"")%>)')
end daeExpCallPre;

template daeExpSize(Exp exp, Context context, Text &preExp /*BUFP*/,
Expand Down Expand Up @@ -4760,7 +4761,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp /*BUFP*/,
}<%\n%>
>>
resTmp
else error(sourceInfo(), 'Code generation does not support multiple iterators: <%printExpStr(exp)%>')
else error(sourceInfo(), 'Code generation does not support multiple iterators: <%ExpressionDumpTpl.dumpExp(exp,"\"")%>')
end daeExpReduction;

template daeExpMatch(Exp exp, Context context, Text &preExp /*BUFP*/, Text &varDecls /*BUFP*/)
Expand Down Expand Up @@ -4805,7 +4806,7 @@ case exp as MATCHEXPRESSION(__) then

'<%prefix%>_in<%switchIndex%>'
case MATCH(switch=SOME(_)) then
error(sourceInfo(), 'Unknown switch: <%printExpStr(exp)%>')
error(sourceInfo(), 'Unknown switch: <%ExpressionDumpTpl.dumpExp(exp,"\"")%>')
else tempDecl('int', &varDeclsInner)
let done = tempDecl('int', &varDeclsInner)
let onPatternFail = match exp.matchType case MATCHCONTINUE(__) then "MMC_THROW()" case MATCH(__) then "break"
Expand Down Expand Up @@ -5308,7 +5309,7 @@ template expTypeFromExpFlag(Exp exp, Integer flag)
case BOX(__) then match flag case 1 then "metatype" else "modelica_metatype"
case c as UNBOX(__) then expTypeFlag(c.ty, flag)
case c as SHARED_LITERAL(__) then expTypeFromExpFlag(c.exp, flag)
else error(sourceInfo(), 'expTypeFromExpFlag:<%printExpStr(exp)%>')
else error(sourceInfo(), 'expTypeFromExpFlag:<%ExpressionDumpTpl.dumpExp(exp,"\"")%>')
end expTypeFromExpFlag;


Expand Down Expand Up @@ -5541,7 +5542,7 @@ template literalExpConst(Exp lit, Integer index) "These should all be declared s
static const MMC_DEFSTRUCTLIT(<%tmp%>,<%intAdd(1,listLength(args))%>,<%newIndex%>) {&<%underscorePath(path)%>__desc,<%args |> exp => literalExpConstBoxedVal(exp); separator=","%>}};
#define <%name%> MMC_REFSTRUCTLIT(<%tmp%>)
>>
else error(sourceInfo(), 'literalExpConst failed: <%printExpStr(lit)%>')
else error(sourceInfo(), 'literalExpConst failed: <%ExpressionDumpTpl.dumpExp(lit,"\"")%>')
end literalExpConst;

template literalExpConstBoxedVal(Exp lit)
Expand All @@ -5559,7 +5560,7 @@ template literalExpConstBoxedVal(Exp lit)
>>
case BOX(__) then literalExpConstBoxedVal(exp)
case lit as SHARED_LITERAL(__) then '_OMC_LIT<%lit.index%>'
else error(sourceInfo(), 'literalExpConstBoxedVal failed: <%printExpStr(lit)%>')
else error(sourceInfo(), 'literalExpConstBoxedVal failed: <%ExpressionDumpTpl.dumpExp(lit,"\"")%>')
end literalExpConstBoxedVal;

template error(builtin.SourceInfo srcInfo, String errMessage)
Expand Down
21 changes: 11 additions & 10 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -49,6 +49,7 @@ import interface SimCodeTV;
import interface SimCodeBackendTV;
import CodegenUtil.*;
import CodegenCFunctions.*;
import ExpressionDumpTpl.*;

/* public */ template translateModel(SimCode simCode)
"Generates C code and Makefile for compiling and running a simulation of a
Expand Down Expand Up @@ -2882,7 +2883,7 @@ template functionRemovedInitialEquationsBody(SimEqSystem eq, Text &varDecls, Tex
<% if profileAll() then 'SIM_PROF_ACC_EQ(<%e.index%>);' %>
if(fabs(res) > 1e-5)
{
errorStreamPrint(LOG_INIT, 0, "The initialization problem is inconsistent due to the following equation: 0 != %g = <%ExpressionDump.printExpStr(exp)%>", res);
errorStreamPrint(LOG_INIT, 0, "The initialization problem is inconsistent due to the following equation: 0 != %g = <%dumpExp(exp,"\"")%>", res);
return 1;
}
>>
Expand Down Expand Up @@ -3809,7 +3810,7 @@ template functionZeroCrossing(list<ZeroCrossing> zeroCrossings, list<SimEqSystem
let &varDecls2 = buffer ""
let zeroCrossingsCode = zeroCrossingsTpl(zeroCrossings, &varDecls2, &auxFunction)
let resDesc = (zeroCrossings |> ZERO_CROSSING(__) => '"<%Util.escapeModelicaStringToCString(ExpressionDump.printExpStr(relation_))%>"'
let resDesc = (zeroCrossings |> ZERO_CROSSING(__) => '"<%Util.escapeModelicaStringToCString(dumpExp(relation_,"\""))%>"'
;separator=",\n")
let desc = match zeroCrossings
Expand Down Expand Up @@ -3962,7 +3963,7 @@ template functionRelations(list<ZeroCrossing> relations, String modelNamePrefix)
let relationsCode = relationsTpl(relations, contextZeroCross, &varDecls, &auxFunction)
let relationsCodeElse = relationsTpl(relations, contextOther, &varDecls, &auxFunction)
let resDesc = (relations |> ZERO_CROSSING(__) => '"<%ExpressionDump.printExpStr(relation_)%>"'
let resDesc = (relations |> ZERO_CROSSING(__) => '"<%dumpExp(relation_,"\"")%>"'
;separator=",\n")
let desc = match relations
Expand Down Expand Up @@ -4660,14 +4661,14 @@ case SES_FOR_LOOP(__) then
let expPart = daeExp(exp, context, &preExp, &varDecls, &auxFunction)
let crefPart = daeExp(crefExp(cref), context, &preExp, &varDecls, &auxFunction)
//let bodyStr = daeExpIteratedCref(body)
let start = printExpStr(startIt)
let stop = printExpStr(endIt)
let start = dumpExp(startIt,"\"")
let stop = dumpExp(endIt,"\"")
let iterVar = daeExp(iter, context, &preExp, &varDecls, &auxFunction)
<<
<%modelicaLine(eqInfo(eq))%>
modelica_integer $P<%printExpStr(iter)%> = 0; // the iterator
modelica_integer $P<%dumpExp(iter,"\"")%> = 0; // the iterator
// the for-equation
for($P<%printExpStr(iter)%> = <%start%>; $P<%printExpStr(iter)%> != <%stop%>+1; $P<%printExpStr(iter)%>++)
for($P<%dumpExp(iter,"\"")%> = <%start%>; $P<%dumpExp(iter,"\"")%> != <%stop%>+1; $P<%dumpExp(iter,"\"")%>++)
{
<%crefPart%> += <%expPart%>;
}
Expand Down Expand Up @@ -4709,7 +4710,7 @@ case eqn as SES_ARRAY_CALL_ASSIGN(lhs=lhs as CREF(__)) then
<%preExp%>
copy_string_array_data(<%expPart%>, &<%lhsstr%>);
>>
else error(sourceInfo(), 'No runtime support for this sort of array call: <%printExpStr(eqn.exp)%>')
else error(sourceInfo(), 'No runtime support for this sort of array call: <%dumpExp(eqn.exp,"\"")%>')
%>
<%endModelicaLine()%>
>>
Expand Down Expand Up @@ -5026,7 +5027,7 @@ match ty
copy_string_array_data_mem(<%expPart%>, &<%cref(left)%>);
>>
else
error(sourceInfo(), 'No runtime support for this sort of array call: <%cref(left)%> = <%printExpStr(right)%>')
error(sourceInfo(), 'No runtime support for this sort of array call: <%cref(left)%> = <%dumpExp(right,"\"")%>')
end match
else
let &preExp = buffer ""
Expand Down Expand Up @@ -5085,7 +5086,7 @@ end equationIfEquationAssign;
#endif
<%literals |> literal hasindex i0 fromindex 0 =>
(if typeinfo() then '/* <%Util.escapeModelicaStringToCString(printExpStr(literal))%> */<%\n%>') +
(if typeinfo() then '/* <%Util.escapeModelicaStringToCString(dumpExp(literal,"\""))%> */<%\n%>') +
literalExpConst(literal,i0)
; separator="\n"; empty %>
Expand Down

0 comments on commit 3bd7ac2

Please sign in to comment.