Skip to content

Commit aef3898

Browse files
rfrankeOpenModelica-Hudson
authored andcommitted
Append underscore to variable names in Cpp runtime
This is to avoid name clashes with predefined variables of runtime, like _conditions, _simTime or _b -- a model variable b is now called _b_
1 parent 0b5f0dd commit aef3898

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

Compiler/Template/CodegenCppCommon.tpl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,20 @@ template crefToCStrForArray(ComponentRef cr, Text& dims)
6161
::=
6262
match cr
6363
case CREF_IDENT(__) then
64-
let &dims+=listLength(subscriptLst)
65-
'<%ident%>'
66-
case CREF_QUAL(__) then '<%ident%><%subscriptsToCStrForArray(subscriptLst)%>_P_<%crefToCStrForArray(componentRef,dims)%>'
67-
64+
let &dims+=listLength(subscriptLst)
65+
'<%ident%>_'
66+
case CREF_QUAL(__) then
67+
'<%ident%><%subscriptsToCStrForArray(subscriptLst)%>_P_<%crefToCStrForArray(componentRef,dims)%>'
6868
case WILD(__) then ' '
6969
else "CREF_NOT_IDENT_OR_QUAL"
7070
end crefToCStrForArray;
7171

72-
7372
template crefToCStr1(ComponentRef cr, Boolean useFlatArrayNotation)
7473
::=
7574
match cr
76-
case CREF_IDENT(__) then '<%ident%>'
77-
case CREF_QUAL(__) then '<%ident%><%subscriptsToCStrForArray(subscriptLst)%>_P_<%crefToCStr1(componentRef,useFlatArrayNotation)%>'
78-
75+
case CREF_IDENT(__) then '<%ident%>_'
76+
case CREF_QUAL(__) then
77+
'<%ident%><%subscriptsToCStrForArray(subscriptLst)%>_P_<%crefToCStr1(componentRef,useFlatArrayNotation)%>'
7978
case WILD(__) then ' '
8079
else "CREF_NOT_IDENT_OR_QUAL"
8180
end crefToCStr1;
@@ -316,7 +315,7 @@ template crefToCStr(ComponentRef cr, Boolean useFlatArrayNotation)
316315
"Helper function to cref."
317316
::=
318317
match cr
319-
case CREF_IDENT(__) then '<%ident%><%subscriptsToCStr(subscriptLst, useFlatArrayNotation)%>'
318+
case CREF_IDENT(__) then '<%ident%>_<%subscriptsToCStr(subscriptLst, useFlatArrayNotation)%>'
320319
case CREF_QUAL(__) then '<%ident%><%subscriptsToCStrForArray(subscriptLst)%>_P_<%crefToCStr(componentRef,useFlatArrayNotation)%>'
321320
case WILD(__) then ''
322321
else "CREF_NOT_IDENT_OR_QUAL"
@@ -2810,7 +2809,7 @@ case CREF(componentRef = cr, ty=DAE.T_COMPLEX(varLst = varLst, complexClassType=
28102809
let lhsStr = contextCref(crefStripSubs(cr), context, simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
28112810
<<
28122811
<% varLst |> var as TYPES_VAR(__) hasindex i1 fromindex 0 =>
2813-
'_<%lhsStr%>_P_<%var.name%> = <%rhsStr%>.<%var.name%>;'
2812+
'_<%lhsStr%>P_<%var.name%>_ = <%rhsStr%>.<%var.name%>;'
28142813
; separator="\n"
28152814
%>
28162815
>>

0 commit comments

Comments
 (0)