Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Additionally check for array element, ticket:4093
Browse files Browse the repository at this point in the history
See e.g.
PowerSystems.Examples.Spot.AC1ph_DC.Inverter
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Oct 29, 2016
1 parent 4a3540b commit c60d86d
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions Compiler/Template/CodegenCpp.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11254,21 +11254,27 @@ template preCallExp(Exp left, Exp right, Context context, Text &varDecls, SimCod
(eLst |> e => preCallExp(e, right, context, &varDecls, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation);separator="\n")
case left as DAE.CREF(componentRef = cr) then
let var = cref1(cr, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, context, varDecls, stateDerVectorName, useFlatArrayNotation)
match cref2simvar(cr, simCode)
case SIMVAR(arrayCref = NONE()) then
// ckeck for array element -- var ends with ')'
if intEq(stringGet(var, stringLength(var)), 41) then
<<
<%var%> = _discrete_events->pre(<%var%>);
>>
case SIMVAR(numArrayElement = nums) then
let forLoops = nums |> num hasindex i1 fromindex 1 =>
'for (int i<%i1%> = 1; i<%i1%> <= <%num%>; i<%i1%>++)' ;separator=" "
let indices = nums |> num hasindex i1 fromindex 1 =>
'i<%i1%>' ;separator=","
<<
<%forLoops%>
<%var%>(<%indices%>) = _discrete_events->pre(<%var%>(<%indices%>));
>>
end match
else
match cref2simvar(cr, simCode)
case SIMVAR(arrayCref = NONE()) then
<<
<%var%> = _discrete_events->pre(<%var%>);
>>
case SIMVAR(numArrayElement = nums) then
let forLoops = nums |> num hasindex i1 fromindex 1 =>
'for (int i<%i1%> = 1; i<%i1%> <= <%num%>; i<%i1%>++)' ;separator=" "
let indices = nums |> num hasindex i1 fromindex 1 =>
'i<%i1%>' ;separator=","
<<
<%forLoops%>
<%var%>(<%indices%>) = _discrete_events->pre(<%var%>(<%indices%>));
>>
end match
else
<<
#error unknown preCallExp <%ExpressionDumpTpl.dumpExp(left, "\"")%>
Expand Down

0 comments on commit c60d86d

Please sign in to comment.