Skip to content

Commit

Permalink
[NF] Retype array constructors after ceval.
Browse files Browse the repository at this point in the history
- Retype array constructors in EvalConstants.evalExp when necessary,
  to avoid the scalarization failing due to non-constant dimensions.
- Handle 'each' in Variable.toString.

Belonging to [master]:
  - OpenModelica/OMCompiler#2855
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 9, 2019
1 parent 15e62b7 commit 5c68648
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
24 changes: 24 additions & 0 deletions Compiler/NFFrontEnd/NFCall.mo
Expand Up @@ -810,6 +810,30 @@ uniontype Call
end match;
end isVectorizeable;

function retype
input output Call call;
algorithm
() := match call
local
Type ty;
list<Dimension> dims;

case TYPED_ARRAY_CONSTRUCTOR()
algorithm
dims := {};

for i in listReverse(call.iters) loop
dims := listAppend(Type.arrayDims(Expression.typeOf(Util.tuple22(i))), dims);
end for;

call.ty := Type.liftArrayLeftList(Type.arrayElementType(call.ty), dims);
then
();

else ();
end match;
end retype;

protected
function instNormalCall
input Absyn.ComponentRef functionName;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFEvalConstants.mo
Expand Up @@ -168,7 +168,7 @@ algorithm
(outExp, outChanged) := Expression.mapFoldShallow(exp,
function evaluateExpTraverser(isExternalArg = Call.isExternal(exp.call)), false);
then
outExp;
if outChanged then Expression.retype(outExp) else outExp;

else
algorithm
Expand Down
6 changes: 6 additions & 0 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -4701,6 +4701,12 @@ public
then
();

case CALL(call = Call.TYPED_ARRAY_CONSTRUCTOR())
algorithm
exp.call := Call.retype(exp.call);
then
();

else ();
end match;
end retype;
Expand Down
9 changes: 8 additions & 1 deletion Compiler/NFFrontEnd/NFVariable.mo
Expand Up @@ -97,6 +97,7 @@ public
protected
IOStream.IOStream s;
Boolean first;
Binding b;
algorithm
s := IOStream.create(getInstanceName(), IOStream.IOStreamType.LIST());

Expand All @@ -122,9 +123,15 @@ public
s := IOStream.append(s, ", ");
end if;

b := Util.tuple22(a);

if Binding.isEach(b) then
s := IOStream.append(s, "each ");
end if;

s := IOStream.append(s, Util.tuple21(a));
s := IOStream.append(s, " = ");
s := IOStream.append(s, Binding.toString(Util.tuple22(a)));
s := IOStream.append(s, Binding.toString(b));
end for;

s := IOStream.append(s, ")");
Expand Down

0 comments on commit 5c68648

Please sign in to comment.