Skip to content

Commit

Permalink
fix in cpp template for pre operator
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17158 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Sep 10, 2013
1 parent 6d05575 commit 4988564
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -3928,7 +3928,7 @@ case CREF_QUAL(ident = "$PRE") then
'_event_handling.pre(<%contextCref(componentRef,context,simCode)%>,"<%cref(componentRef)%>")'
else
match context
case FUNCTION_CONTEXT(__) then crefStr(cr)
case FUNCTION_CONTEXT(__) then '<%crefToCStr(cr)%>'
else cref1(cr,simCode,context)
end contextCref;

Expand Down Expand Up @@ -4697,6 +4697,8 @@ template daeExpRange(Exp exp, Context context, Text &preExp /*BUFP*/,
'<%tmp%>'
end daeExpRange;



template daeExpReduction(Exp exp, Context context, Text &preExp /*BUFP*/,
Text &varDecls /*BUFP*/,SimCode simCode)
"Generates code for a reduction expression. The code is quite messy because it handles all
Expand Down Expand Up @@ -4737,7 +4739,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp /*BUFP*/,
let bodyExprType = expTypeArrayIf(typeof(r.expr))
let reductionBodyExprWork = daeExp(r.expr, context, &bodyExpPre, &tmpVarDecls,simCode)
let &tmpVarDecls += '<%bodyExprType%> <%reductionBodyExpr%>;<%\n%>'
let &bodyExpPre += '<%reductionBodyExpr%> = <%reductionBodyExprWork%>//Test;<%\n%>'
let &bodyExpPre += '<%reductionBodyExpr%> = <%reductionBodyExprWork%>;<%\n%>'
let foldExp = match ri.path
case IDENT(name="list") then
<<
Expand Down Expand Up @@ -4795,10 +4797,9 @@ template daeExpReduction(Exp exp, Context context, Text &preExp /*BUFP*/,
{
<%identType%> <%iteratorName%>;
<%iteratorName%> = <%loopVar%>[<%firstIndex%>++];
>>
let loopTail = match identType
case "modelica_metatype" then "}"
let loopTail = '}'
let &preExp += <<
{
Expand All @@ -4815,7 +4816,7 @@ template daeExpReduction(Exp exp, Context context, Text &preExp /*BUFP*/,
<%&bodyExpPre%>
<%foldExp%>
}
<%loopTail%>
<%loopTail%>
<% if not ri.defaultValue then 'if (!<%foundFirst%>) MMC_THROW();' %>
<% if resTail then '*<%resTail%> = mmc_mk_nil();' %>
<% resTmp %> = <% res %>;
Expand Down Expand Up @@ -5725,15 +5726,15 @@ template daeExpCrefRhs(Exp exp, Context context, Text &preExp /*BUFP*/,
// by daeExpRecordCrefRhs only in a simulation context, not in a function.
case CREF(componentRef = cr, ty = t as T_COMPLEX(complexClassType = RECORD(path = _))) then
match context case FUNCTION_CONTEXT(__) then
daeExpCrefRhs2(exp, context, &preExp, &varDecls,simCode)
'<%daeExpCrefRhs2(exp, context, &preExp, &varDecls,simCode)%>'
else
daeExpRecordCrefRhs(t, cr, context, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode)

case CREF(componentRef = cr, ty = T_FUNCTION_REFERENCE_FUNC(__)) then
'((modelica_fnptr)boxptr_<%crefFunctionName(cr)%>)'
case CREF(componentRef = cr, ty = T_FUNCTION_REFERENCE_VAR(__)) then
'((modelica_fnptr) _<%crefStr(cr)%>)'
else daeExpCrefRhs2(exp, context, &preExp, &varDecls,simCode)
else '<%daeExpCrefRhs2(exp, context, &preExp, &varDecls,simCode)%>'
end daeExpCrefRhs;

template daeExpRecordCrefRhs(DAE.Type ty, ComponentRef cr, Context context, Text &preExp /*BUFP*/,
Expand Down Expand Up @@ -5858,9 +5859,9 @@ template representationCref(ComponentRef inCref, SimCode simCode, Context contex

case ALGLOOP_CONTEXT(genInitialisation = false)

then << _system-><%cref(inCref)%>>>
then <<_system-><%cref(inCref)%>>>
else
<< <%cref(inCref)%>>>
<<<%cref(inCref)%>>>
end representationCref;


Expand Down Expand Up @@ -6246,9 +6247,7 @@ end errorMsg;
template contextIteratorName(Ident name, Context context)
"Generates code for an iterator variable."
::=
match context
case FUNCTION_CONTEXT(__) then "_" + name
else name
name
end contextIteratorName;


Expand Down Expand Up @@ -6609,7 +6608,7 @@ template handleSystemEvents(list<ZeroCrossing> zeroCrossings,list<SimWhenClause>
}

if(iter>2*_dimZeroFunc && restart ){
throw std::runtime_error("Number of event iteration steps exceeded. " );}
throw std::runtime_error("Number of event iteration steps exceeded at time: " + boost::lexical_cast<string>(_simTime) );}
return state_vars_reinitialized;
}
>>
Expand Down Expand Up @@ -7362,10 +7361,11 @@ template algStatement(DAE.Statement stmt, Context context, Text &varDecls,SimCod
case s as STMT_TRY(__) then "STMT TRY"
case s as STMT_CATCH(__) then "STMT CATCH"
case s as STMT_THROW(__) then "STMT THROW"
case s as STMT_RETURN(__) then "STMT RETURN"
case s as STMT_RETURN(__) then "break;/*Todo stm return*/"
case s as STMT_NORETCALL(__) then algStmtNoretcall(s, context, &varDecls /*BUFD*/,simCode)
case s as STMT_REINIT(__) then algStmtReinit(s, context, &varDecls /*BUFD*/,simCode)
else error(sourceInfo(), 'ALG_STATEMENT NYI')

<<
<%modelicaLine(getElementSourceFileInfo(getStatementSource(stmt)))%>
<%res%>
Expand Down Expand Up @@ -7560,11 +7560,13 @@ template algStmtReinit(DAE.Statement stmt, Context context, Text &varDecls /*BUF
let &preExp = buffer "" /*BUFD*/
let expPart1 = daeExp(var, context, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode)
let expPart2 = daeExp(value, context, &preExp /*BUFC*/, &varDecls /*BUFD*/,simCode)
/*<<
/*
<<
$P$PRE<%expPart1%> = <%expPart1%>;
<%preExp%>
<%expPart1%> = <%expPart2%>;
>>*/
>>
*/
<<
_event_handling.save(<%expPart1%>,"<%expPart1%>");
<%preExp%>
Expand Down

0 comments on commit 4988564

Please sign in to comment.