Skip to content

Commit

Permalink
[NF] Handle empty arrays better.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Feb 12, 2018
1 parent 5614078 commit 3be99fe
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
10 changes: 8 additions & 2 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -2069,8 +2069,14 @@ public
case CREF(cref = ComponentRef.CREF())
algorithm
subs := expandCref2(crefExp.cref);

if listEmpty(subs) then
arrayExp := ARRAY(Type.ARRAY(Type.arrayElementType(crefExp.ty), {Dimension.INTEGER(0)}), {});
else
arrayExp := expandCref3(subs, crefExp.cref, Type.arrayElementType(crefExp.ty));
end if;
then
expandCref3(subs, crefExp.cref, Type.arrayElementType(crefExp.ty));
arrayExp;

else crefExp;
end match;
Expand All @@ -2091,7 +2097,7 @@ public
dims := Type.arrayDims(cref.ty);
cr_subs := Subscript.expandList(cref.subscripts, dims);
then
expandCref2(cref.restCref, cr_subs :: subs);
if listEmpty(cr_subs) then {} else expandCref2(cref.restCref, cr_subs :: subs);

else subs;
end match;
Expand Down
5 changes: 5 additions & 0 deletions Compiler/NFFrontEnd/NFScalarize.mo
Expand Up @@ -102,6 +102,11 @@ algorithm
if Type.isArray(var.ty) then
Variable.VARIABLE(name, ty, binding, vis, attr, ty_attr, cmt, info) := var;
crefs := ComponentRef.scalarize(name);

if listEmpty(crefs) then
return;
end if;

ty := Type.arrayElementType(ty);
(ty_attr_names, ty_attr_iters) := scalarizeTypeAttributes(ty_attr);

Expand Down
19 changes: 17 additions & 2 deletions Compiler/NFFrontEnd/NFSubscript.mo
Expand Up @@ -303,14 +303,29 @@ public
protected
Dimension dim;
list<Dimension> rest_dims = dimensions;
list<Subscript> subs;
algorithm
for s in subscripts loop
dim :: rest_dims := rest_dims;
outSubscripts := expand(s, dim) :: outSubscripts;
subs := expand(s, dim);

if listEmpty(subs) then
outSubscripts := {};
return;
else
outSubscripts := subs :: outSubscripts;
end if;
end for;

for d in rest_dims loop
outSubscripts := RangeIterator.map(RangeIterator.fromDim(d), makeIndex) :: outSubscripts;
subs := RangeIterator.map(RangeIterator.fromDim(d), makeIndex);

if listEmpty(subs) then
outSubscripts := {};
return;
else
outSubscripts := subs :: outSubscripts;
end if;
end for;

outSubscripts := listReverse(outSubscripts);
Expand Down
8 changes: 6 additions & 2 deletions Compiler/Util/List.mo
Expand Up @@ -6935,8 +6935,12 @@ public function combination<TI>
protected
list<list<TI>> elems;
algorithm
elems := combination_tail(inElements, {}, {});
outElements := listReverse(elems);
if listEmpty(inElements) then
outElements := {};
else
elems := combination_tail(inElements, {}, {});
outElements := listReverse(elems);
end if;
end combination;

protected function combination_tail<TI>
Expand Down

0 comments on commit 3be99fe

Please sign in to comment.