Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
[NF] Improve Expression.hasArrayCall.
Browse files Browse the repository at this point in the history
- Use Expression.contains instead of Expression.fold.
- Handle "tuple subscripted" calls correctly.

Belonging to [master]:
  - #2810
  • Loading branch information
perost authored and OpenModelica-Hudson committed Dec 3, 2018
1 parent 809abfc commit 99e1c39
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Compiler/NFFrontEnd/NFExpression.mo
Expand Up @@ -4116,17 +4116,30 @@ public
input Expression exp;
output Boolean hasArrayCall;
algorithm
hasArrayCall := fold(exp, hasArrayCall2, false);
hasArrayCall := contains(exp, hasArrayCall2);
end hasArrayCall;

function hasArrayCall2
input Expression exp;
input output Boolean hasArrayCall;
output Boolean hasArrayCall;
protected
Call call;
Type ty;
algorithm
hasArrayCall := match exp
case CALL() then hasArrayCall or
(Type.isArray(Call.typeOf(exp.call)) and Call.isVectorizeable(exp.call));
else hasArrayCall;
case CALL(call = call)
algorithm
ty := Call.typeOf(call);
then
Type.isArray(ty) and Call.isVectorizeable(call);

case TUPLE_ELEMENT(tupleExp = CALL(call = call))
algorithm
ty := Type.nthTupleType(Call.typeOf(call), exp.index);
then
Type.isArray(ty) and Call.isVectorizeable(call);

else false;
end match;
end hasArrayCall2;

Expand Down
12 changes: 12 additions & 0 deletions Compiler/NFFrontEnd/NFType.mo
Expand Up @@ -448,6 +448,18 @@ public
end match;
end firstTupleType;

function nthTupleType
input Type ty;
input Integer n;
output Type outTy;
algorithm
outTy := match ty
case TUPLE() then listGet(ty.types, n);
case ARRAY() then Type.ARRAY(nthTupleType(ty.elementType, n), ty.dimensions);
else ty;
end match;
end nthTupleType;

function arrayElementType
"Returns the common type of the elements in an array, or just the type
itself if it's not an array type."
Expand Down

0 comments on commit 99e1c39

Please sign in to comment.