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

Commit b2744b0

Browse files
perostOpenModelica-Hudson
authored andcommitted
Simple typing of subscripts for nfinst.
1 parent c28fb0c commit b2744b0

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

Compiler/NFFrontEnd/NFSubscript.mo

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,15 @@ public
9898
string := List.toString(subscripts, toString, "", "[", ", ", "]", false);
9999
end toStringList;
100100

101+
function isIndex
102+
input Subscript subscript;
103+
output Boolean isIndex;
104+
algorithm
105+
isIndex := match subscript
106+
case INDEX() then true;
107+
else false;
108+
end match;
109+
end isIndex;
110+
101111
annotation(__OpenModelica_Interface="frontend");
102112
end NFSubscript;

Compiler/NFFrontEnd/NFType.mo

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ protected
3737
public
3838
import Dimension = NFDimension;
3939
import NFInstNode.InstNode;
40+
import Subscript = NFSubscript;
4041

4142
record INTEGER
4243
end INTEGER;
@@ -121,6 +122,21 @@ public
121122
end match;
122123
end liftArrayLeftList;
123124

125+
function unliftArray
126+
input output Type ty;
127+
protected
128+
Type el_ty;
129+
list<Dimension> dims;
130+
algorithm
131+
ARRAY(el_ty, _ :: dims) := ty;
132+
133+
if listEmpty(dims) then
134+
ty := el_ty;
135+
else
136+
ty := ARRAY(el_ty, dims);
137+
end if;
138+
end unliftArray;
139+
124140
function isInteger
125141
input Type ty;
126142
output Boolean isInteger;
@@ -400,5 +416,16 @@ public
400416
end match;
401417
end toDAE;
402418

419+
function subscript
420+
input output Type ty;
421+
input list<Subscript> subs;
422+
algorithm
423+
for sub in subs loop
424+
if Subscript.isIndex(sub) then
425+
ty := unliftArray(ty);
426+
end if;
427+
end for;
428+
end subscript;
429+
403430
annotation(__OpenModelica_Interface="frontend");
404431
end NFType;

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,10 @@ algorithm
576576
comp := InstNode.component(cref.node);
577577
ty := Component.getType(comp);
578578
variability := ComponentRef.getVariability(cref);
579-
cref.ty := ty;
580579
cref.subscripts := typeSubscripts(cref.subscripts, info);
580+
cref.ty := Type.subscript(ty, cref.subscripts);
581581
then
582-
(Expression.CREF(cref), ty, variability);
582+
(Expression.CREF(cref), cref.ty, variability);
583583

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

0 commit comments

Comments
 (0)