Skip to content

Commit

Permalink
Add array dimensions to created temporary variables
Browse files Browse the repository at this point in the history
This addresses #10519 --
Model translation warns about failed assignments and fails with -d=dumpSimCode.
  • Loading branch information
rfranke committed Apr 28, 2023
1 parent 9b202f8 commit 808f7de
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions OMCompiler/Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -3004,6 +3004,7 @@ algorithm
DAE.Ident name;
DAE.Type ty;
DAE.ComponentRef cr, arraycref;
list<String> numArrayElement;
list<DAE.ComponentRef> crlst;
SimCodeVar.SimVar var;

Expand All @@ -3027,21 +3028,22 @@ algorithm
detects first elements of arrays to generate VARNAME_indexed(..) macros for accessing the array
with variable indexes.*/
arraycref := ComponentReference.crefStripSubs(cr);
numArrayElement := List.map(ComponentReference.crefDims(cr), ExpressionDump.dimensionString);
ty := ComponentReference.crefTypeFull(cr);
if FMI.isFMIVersion20() then
var := SimCodeVar.SIMVAR(cr, BackendDAE.VARIABLE(), "", "", "", 0, NONE(), NONE(), NONE(), NONE(), false, ty, false, SOME(arraycref), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SOME(SimCodeVar.LOCAL()), NONE(), NONE(), {}, false, true, SOME(true), NONE(), false, NONE(), NONE(), NONE(), SOME(cr));
var := SimCodeVar.SIMVAR(cr, BackendDAE.VARIABLE(), "", "", "", 0, NONE(), NONE(), NONE(), NONE(), false, ty, false, SOME(arraycref), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SOME(SimCodeVar.LOCAL()), NONE(), NONE(), numArrayElement, false, true, SOME(true), NONE(), false, NONE(), NONE(), NONE(), SOME(cr));
else
var := SimCodeVar.SIMVAR(cr, BackendDAE.VARIABLE(), "", "", "", 0, NONE(), NONE(), NONE(), NONE(), false, ty, false, SOME(arraycref), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SOME(SimCodeVar.NONECAUS()), NONE(), NONE(), {}, false, true, SOME(true), NONE(), false, NONE(), NONE(), NONE(), SOME(cr));
var := SimCodeVar.SIMVAR(cr, BackendDAE.VARIABLE(), "", "", "", 0, NONE(), NONE(), NONE(), NONE(), false, ty, false, SOME(arraycref), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SOME(SimCodeVar.NONECAUS()), NONE(), NONE(), numArrayElement, false, true, SOME(true), NONE(), false, NONE(), NONE(), NONE(), SOME(cr));
end if;

/* The rest don't need to be marked i.e. we have 'NONE()'. Just create simvars. */
ttmpvars := {var};
for cr in crlst loop
ty := ComponentReference.crefTypeFull(cr);
if FMI.isFMIVersion20() then
var := SimCodeVar.SIMVAR(cr, BackendDAE.VARIABLE(), "", "", "", 0, NONE(), NONE(), NONE(), NONE(), false, ty, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SOME(SimCodeVar.LOCAL()), NONE(), NONE(), {}, false, true, SOME(true), NONE(), false, NONE(), NONE(), NONE(), SOME(cr));
var := SimCodeVar.SIMVAR(cr, BackendDAE.VARIABLE(), "", "", "", 0, NONE(), NONE(), NONE(), NONE(), false, ty, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SOME(SimCodeVar.LOCAL()), NONE(), NONE(), numArrayElement, false, true, SOME(true), NONE(), false, NONE(), NONE(), NONE(), SOME(cr));
else
var := SimCodeVar.SIMVAR(cr, BackendDAE.VARIABLE(), "", "", "", 0, NONE(), NONE(), NONE(), NONE(), false, ty, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SOME(SimCodeVar.NONECAUS()), NONE(), NONE(), {}, false, true, SOME(true), NONE(), false, NONE(), NONE(), NONE(), SOME(cr));
var := SimCodeVar.SIMVAR(cr, BackendDAE.VARIABLE(), "", "", "", 0, NONE(), NONE(), NONE(), NONE(), false, ty, false, NONE(), SimCodeVar.NOALIAS(), DAE.emptyElementSource, SOME(SimCodeVar.NONECAUS()), NONE(), NONE(), numArrayElement, false, true, SOME(true), NONE(), false, NONE(), NONE(), NONE(), SOME(cr));
end if;
ttmpvars := var::ttmpvars;
end for;
Expand Down

0 comments on commit 808f7de

Please sign in to comment.