Skip to content

Commit

Permalink
Simple typing of subscripts for nfinst.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jun 19, 2017
1 parent c28fb0c commit b2744b0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Compiler/NFFrontEnd/NFSubscript.mo
Expand Up @@ -98,5 +98,15 @@ public
string := List.toString(subscripts, toString, "", "[", ", ", "]", false);
end toStringList;

function isIndex
input Subscript subscript;
output Boolean isIndex;
algorithm
isIndex := match subscript
case INDEX() then true;
else false;
end match;
end isIndex;

annotation(__OpenModelica_Interface="frontend");
end NFSubscript;
27 changes: 27 additions & 0 deletions Compiler/NFFrontEnd/NFType.mo
Expand Up @@ -37,6 +37,7 @@ protected
public
import Dimension = NFDimension;
import NFInstNode.InstNode;
import Subscript = NFSubscript;

record INTEGER
end INTEGER;
Expand Down Expand Up @@ -121,6 +122,21 @@ public
end match;
end liftArrayLeftList;

function unliftArray
input output Type ty;
protected
Type el_ty;
list<Dimension> dims;
algorithm
ARRAY(el_ty, _ :: dims) := ty;

if listEmpty(dims) then
ty := el_ty;
else
ty := ARRAY(el_ty, dims);
end if;
end unliftArray;

function isInteger
input Type ty;
output Boolean isInteger;
Expand Down Expand Up @@ -400,5 +416,16 @@ public
end match;
end toDAE;

function subscript
input output Type ty;
input list<Subscript> subs;
algorithm
for sub in subs loop
if Subscript.isIndex(sub) then
ty := unliftArray(ty);
end if;
end for;
end subscript;

annotation(__OpenModelica_Interface="frontend");
end NFType;
4 changes: 2 additions & 2 deletions Compiler/NFFrontEnd/NFTyping.mo
Expand Up @@ -576,10 +576,10 @@ algorithm
comp := InstNode.component(cref.node);
ty := Component.getType(comp);
variability := ComponentRef.getVariability(cref);
cref.ty := ty;
cref.subscripts := typeSubscripts(cref.subscripts, info);
cref.ty := Type.subscript(ty, cref.subscripts);
then
(Expression.CREF(cref), ty, variability);
(Expression.CREF(cref), cref.ty, variability);

case ComponentRef.WILD()
then (Expression.CREF(ComponentRef.WILD()), Type.UNKNOWN(), DAE.Const.C_VAR());
Expand Down

0 comments on commit b2744b0

Please sign in to comment.