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

Commit 3f4c043

Browse files
rfrankeOpenModelica-Hudson
authored andcommitted
Reactivate Cpp code generation for SimCode.SES_FOR_LOOP
Belonging to [master]: - #2692 - OpenModelica/OpenModelica-testsuite#1044
1 parent 6952465 commit 3f4c043

File tree

3 files changed

+7
-24
lines changed

3 files changed

+7
-24
lines changed

Compiler/Template/CodegenCpp.tpl

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11577,34 +11577,15 @@ template equationForLoop(SimEqSystem eq, Context context, Text &varDecls, SimCod
1157711577
let endExp = daeExp(endIt, context, preExp, varDecls, simCode, extraFuncs, extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, false)
1157811578
let expPart = daeExp(exp, context, preExp, varDecls, simCode, extraFuncs, extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, false)
1157911579
let crefPart = daeExp(crefExp(cref), context, preExp, varDecls, simCode, extraFuncs, extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, false)
11580-
let crefWithIdx = crefWithIndex(cref, context, varDecls, simCode, extraFuncs, extraFuncsDecl, extraFuncsNamespace, stateDerVectorName /*=__zDot*/, useFlatArrayNotation)
11581-
let lhs = getLHS(cref, startExp, useFlatArrayNotation)
1158211580
<<
11583-
<%preExp%>
11584-
//double *result = &<%cref(cref, false)%>[0];
11585-
double *result = &<%lhs%>;
11586-
for(int <%iterExp%> = <%startExp%>; <%iterExp%> != <%endExp%>+1; <%iterExp%>++)
11587-
result[i] = <%expPart%>;
11581+
for (int <%iterExp%> = <%startExp%>; <%iterExp%> <= <%endExp%>; <%iterExp%>++) {
11582+
<%preExp%>
11583+
<%crefPart%> = <%expPart%>;
11584+
}
1158811585
>>
1158911586
end equationForLoop;
1159011587

1159111588

11592-
template getLHS(ComponentRef cr, Text startExp, Boolean useFlatArrayNotation)
11593-
"Returns the left hand side of a for loop with the right var index, e.g., _resistor1_P_i.
11594-
Assumption: lhs = 'cref' + 'startIndex of for loop'."
11595-
::=
11596-
match cr
11597-
case CREF_QUAL(__) then
11598-
//"_" + '<%ident%><%startExp%><%subscriptsToCStrForArray(subscriptLst)%>_P_<%crefToCStr(componentRef,useFlatArrayNotation)%>'
11599-
"_" + '<%crefAppendedSubs(cr)%>'
11600-
else "CREF_NOT_QUAL"
11601-
end match
11602-
end getLHS;
11603-
11604-
11605-
11606-
11607-
1160811589
template testDaeDimensionExp(Exp exp)
1160911590
"Generates code for an expression."
1161011591
::=

Compiler/Template/CodegenCppCommon.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ template subscriptToCStr(Subscript subscript)
5353
match exp
5454
case ICONST(integer=i) then i
5555
case ENUM_LITERAL(index=i) then i
56+
case CREF(componentRef=cr) then crefToCStr(cr, false)
5657
end match
5758
else "UNKNOWN_SUBSCRIPT"
5859
end subscriptToCStr;

Compiler/Template/CodegenUtil.tpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ end subscriptsStr;
124124

125125
template subscriptStr(Subscript subscript)
126126
"Generates a single subscript.
127-
Only works for constant integer indicies."
127+
Only works for constant integer and cref indicies."
128128

129129
::=
130130
match subscript
131131
case INDEX(exp=ICONST(integer=i)) then i
132132
case INDEX(exp=ENUM_LITERAL(name=n)) then dotPath(n)
133+
case INDEX(exp=CREF()) then printExpStr(exp)
133134
case SLICE(exp=ICONST(integer=i)) then i
134135
case INDEX(__)
135136
case SLICE(__) then 'UNKNOWN_SUBSCRIPT /* <%escapeCComments(printExpStr(exp))%> */'

0 commit comments

Comments
 (0)