Skip to content

Commit

Permalink
[NF] Fix type in Ceval.evalArrayConstructor.
Browse files Browse the repository at this point in the history
- Create a new type based on the actual sizes of the created arrays in
  evalArrayConstructor, instead of using the original type which might
  have non-constant dimensions.

Belonging to [master]:
  - OpenModelica/OMCompiler#2870
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 14, 2019
1 parent 3c1d34e commit 8481cc5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -2707,7 +2707,7 @@ protected
algorithm
e := evalExpPartial(exp);
(e, ranges, iters) := createIterationRanges(e, iterators);
result := evalArrayConstructor2(e, ty, ranges, iters);
result := evalArrayConstructor2(e, ranges, iters);
end evalArrayConstructor;

function createIterationRanges
Expand All @@ -2731,33 +2731,38 @@ end createIterationRanges;

function evalArrayConstructor2
input Expression exp;
input Type ty;
input list<Expression> ranges;
input list<Mutable<Expression>> iterators;
output Expression result;
protected
Expression range;
Expression range, e;
list<Expression> ranges_rest, expl = {};
Mutable<Expression> iter;
list<Mutable<Expression>> iters_rest;
ExpressionIterator range_iter;
Expression value;
Type el_ty;
Type ty;
algorithm
if listEmpty(ranges) then
result := evalExp(exp);
else
range :: ranges_rest := ranges;
iter :: iters_rest := iterators;
range_iter := ExpressionIterator.fromExp(range);
el_ty := Type.unliftArray(ty);

while ExpressionIterator.hasNext(range_iter) loop
(range_iter, value) := ExpressionIterator.next(range_iter);
Mutable.update(iter, value);
expl := evalArrayConstructor2(exp, el_ty, ranges_rest, iters_rest) :: expl;
expl := evalArrayConstructor2(exp, ranges_rest, iters_rest) :: expl;
end while;

if listEmpty(expl) then
ty := Type.unliftArray(Expression.typeOf(exp));
else
ty := Expression.typeOf(listHead(expl));
end if;

ty := Type.liftArrayLeft(ty, Dimension.fromInteger(listLength(expl)));
result := Expression.makeArray(ty, listReverseInPlace(expl), literal = true);
end if;
end evalArrayConstructor2;
Expand Down

0 comments on commit 8481cc5

Please sign in to comment.