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

Commit 7c50cbc

Browse files
perostOpenModelica-Hudson
authored andcommitted
NFInst improvements.
- Rename NFMod to NFModifier, since that's the actual package name. - Add instance tree hierarchy level to components, and have bindings keep track of which level they're from instead of keeping track of how many levels they've been pushed down. - Added Expression.SUBSCRIPTED_EXP to handle subscripting of expressions that can't be scalarized. - Add missing cases for Call.UNTYPED_MAP_CALL and CAll.TYPED_MAP_CALL to some Expression functions. Belonging to [master]: - #2015 - OpenModelica/OpenModelica-testsuite#779
1 parent d55e7e1 commit 7c50cbc

18 files changed

+176
-140
lines changed

Compiler/NFFrontEnd/NFBinding.mo

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ public
4747
record RAW_BINDING
4848
Absyn.Exp bindingExp;
4949
InstNode scope;
50-
Integer propagatedLevels;
50+
Integer originLevel;
5151
SourceInfo info;
5252
end RAW_BINDING;
5353

5454
record UNTYPED_BINDING
5555
Expression bindingExp;
5656
Boolean isProcessing;
5757
InstNode scope;
58-
Integer propagatedLevels;
58+
Integer originLevel;
5959
SourceInfo info;
6060
end UNTYPED_BINDING;
6161

6262
record TYPED_BINDING
6363
Expression bindingExp;
6464
Type bindingType;
6565
Variability variability;
66-
Integer propagatedLevels;
66+
Integer originLevel;
6767
SourceInfo info;
6868
end TYPED_BINDING;
6969

@@ -75,20 +75,21 @@ public
7575
function fromAbsyn
7676
input Option<Absyn.Exp> bindingExp;
7777
input SCode.Each eachPrefix;
78+
input Integer level;
7879
input InstNode scope;
7980
input SourceInfo info;
8081
output Binding binding;
8182
algorithm
8283
binding := match bindingExp
8384
local
8485
Absyn.Exp exp;
85-
Integer pd;
86+
Integer lvl;
8687

8788
case SOME(exp)
8889
algorithm
89-
pd := if SCode.eachBool(eachPrefix) then -1 else 0;
90+
lvl := if SCode.eachBool(eachPrefix) then -level else level;
9091
then
91-
RAW_BINDING(exp, scope, pd, info);
92+
RAW_BINDING(exp, scope, lvl, info);
9293

9394
else UNBOUND();
9495
end match;
@@ -189,9 +190,9 @@ public
189190
output Boolean isEach;
190191
algorithm
191192
isEach := match binding
192-
case RAW_BINDING() then binding.propagatedLevels == -1;
193-
case UNTYPED_BINDING() then binding.propagatedLevels == -1;
194-
case TYPED_BINDING() then binding.propagatedLevels == -1;
193+
case RAW_BINDING() then binding.originLevel < 0;
194+
case UNTYPED_BINDING() then binding.originLevel < 0;
195+
case TYPED_BINDING() then binding.originLevel < 0;
195196
else false;
196197
end match;
197198
end isEach;

Compiler/NFFrontEnd/NFBuiltin.mo

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import NFComponent.Component;
5050
import Expression = NFExpression;
5151
import NFInstNode.InstNode;
5252
import NFInstNode.InstNodeType;
53-
import NFMod.Modifier;
53+
import NFModifier.Modifier;
5454
import Type = NFType;
5555
import BuiltinFuncs = NFBuiltinFuncs;
5656
import Pointer;
@@ -237,6 +237,7 @@ constant InstNode STATESELECT_NEVER =
237237
STATESELECT_NEVER_BINDING,
238238
NFComponent.CONSTANT_ATTR,
239239
Absyn.dummyInfo)),
240+
0,
240241
STATESELECT_NODE);
241242

242243
constant ComponentRef STATESELECT_NEVER_CREF =
@@ -252,6 +253,7 @@ constant InstNode STATESELECT_AVOID =
252253
STATESELECT_AVOID_BINDING,
253254
NFComponent.CONSTANT_ATTR,
254255
Absyn.dummyInfo)),
256+
0,
255257
STATESELECT_NODE);
256258

257259
constant ComponentRef STATESELECT_AVOID_CREF =
@@ -267,6 +269,7 @@ constant InstNode STATESELECT_DEFAULT =
267269
STATESELECT_DEFAULT_BINDING,
268270
NFComponent.CONSTANT_ATTR,
269271
Absyn.dummyInfo)),
272+
0,
270273
STATESELECT_NODE);
271274

272275
constant ComponentRef STATESELECT_DEFAULT_CREF =
@@ -282,6 +285,7 @@ constant InstNode STATESELECT_PREFER =
282285
STATESELECT_PREFER_BINDING,
283286
NFComponent.CONSTANT_ATTR,
284287
Absyn.dummyInfo)),
288+
0,
285289
STATESELECT_NODE);
286290

287291
constant ComponentRef STATESELECT_PREFER_CREF =
@@ -297,6 +301,7 @@ constant InstNode STATESELECT_ALWAYS =
297301
STATESELECT_ALWAYS_BINDING,
298302
NFComponent.CONSTANT_ATTR,
299303
Absyn.dummyInfo)),
304+
0,
300305
STATESELECT_NODE);
301306

302307
constant ComponentRef STATESELECT_ALWAYS_CREF =
@@ -321,6 +326,7 @@ constant InstNode TIME =
321326
Binding.UNBOUND(),
322327
NFComponent.INPUT_ATTR,
323328
Absyn.dummyInfo)),
329+
0,
324330
InstNode.EMPTY_NODE());
325331

326332
constant ComponentRef TIME_CREF = ComponentRef.CREF(TIME, {}, Type.REAL(), Origin.CREF, ComponentRef.EMPTY());

Compiler/NFFrontEnd/NFBuiltinFuncs.mo

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,39 +64,39 @@ constant Component INT_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NO
6464

6565
constant InstNode INT_PARAM = InstNode.COMPONENT_NODE("i",
6666
Visibility.PUBLIC,
67-
Pointer.createImmutable(INT_COMPONENT), InstNode.EMPTY_NODE());
67+
Pointer.createImmutable(INT_COMPONENT), 0, InstNode.EMPTY_NODE());
6868

6969
// Default Real parameter.
7070
constant Component REAL_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
7171
Type.REAL(), Binding.UNBOUND(), Binding.UNBOUND(), Component.Attributes.DEFAULT(), Absyn.dummyInfo);
7272

7373
constant InstNode REAL_PARAM = InstNode.COMPONENT_NODE("r",
7474
Visibility.PUBLIC,
75-
Pointer.createImmutable(REAL_COMPONENT), InstNode.EMPTY_NODE());
75+
Pointer.createImmutable(REAL_COMPONENT), 0, InstNode.EMPTY_NODE());
7676

7777
// Default Boolean parameter.
7878
constant Component BOOL_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
7979
Type.BOOLEAN(), Binding.UNBOUND(), Binding.UNBOUND(), Component.Attributes.DEFAULT(), Absyn.dummyInfo);
8080

8181
constant InstNode BOOL_PARAM = InstNode.COMPONENT_NODE("b",
8282
Visibility.PUBLIC,
83-
Pointer.createImmutable(BOOL_COMPONENT), InstNode.EMPTY_NODE());
83+
Pointer.createImmutable(BOOL_COMPONENT), 0, InstNode.EMPTY_NODE());
8484

8585
// Default String parameter.
8686
constant Component STRING_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
8787
Type.STRING(), Binding.UNBOUND(), Binding.UNBOUND(), Component.Attributes.DEFAULT(), Absyn.dummyInfo);
8888

8989
constant InstNode STRING_PARAM = InstNode.COMPONENT_NODE("s",
9090
Visibility.PUBLIC,
91-
Pointer.createImmutable(STRING_COMPONENT), InstNode.EMPTY_NODE());
91+
Pointer.createImmutable(STRING_COMPONENT), 0, InstNode.EMPTY_NODE());
9292

9393
// Default enumeration(:) parameter.
9494
constant Component ENUM_COMPONENT = Component.TYPED_COMPONENT(NFInstNode.EMPTY_NODE(),
9595
Type.ENUMERATION_ANY(), Binding.UNBOUND(), Binding.UNBOUND(), Component.Attributes.DEFAULT(), Absyn.dummyInfo);
9696

9797
constant InstNode ENUM_PARAM = InstNode.COMPONENT_NODE("e",
9898
Visibility.PUBLIC,
99-
Pointer.createImmutable(ENUM_COMPONENT), InstNode.EMPTY_NODE());
99+
Pointer.createImmutable(ENUM_COMPONENT), 0, InstNode.EMPTY_NODE());
100100

101101
// Integer(e)
102102
constant Function INTEGER = Function.FUNCTION(Path.IDENT("Integer"),

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ uniontype Call
293293
outIters := {};
294294
iter_scope := scope;
295295
for Absiter in inIters loop
296-
binding := Binding.fromAbsyn(Absiter.range, SCode.NOT_EACH(), iter_scope, info);
296+
binding := Binding.fromAbsyn(Absiter.range, SCode.NOT_EACH(), 0, iter_scope, info);
297297
binding := Inst.instBinding(binding);
298298
(iter_scope, iter) := Inst.addIteratorToScope(Absiter.name, binding, info, iter_scope);
299299
outIters := iter::outIters;
@@ -646,6 +646,7 @@ uniontype Call
646646
algorithm
647647
ty := match call
648648
case TYPED_CALL(attributes = CallAttributes.CALL_ATTR(ty = ty)) then ty;
649+
case TYPED_MAP_CALL() then call.ty;
649650
else Type.UNKNOWN();
650651
end match;
651652
end typeOf;

Compiler/NFFrontEnd/NFClass.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
encapsulated package NFClass
3333

3434
import NFInstNode.InstNode;
35-
import NFMod.Modifier;
35+
import NFModifier.Modifier;
3636
import NFStatement.Statement;
3737
import SCode.Element;
3838
import Type = NFType;

Compiler/NFFrontEnd/NFComponent.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import Binding = NFBinding;
3636
import NFClass.Class;
3737
import Dimension = NFDimension;
3838
import NFInstNode.InstNode;
39-
import NFMod.Modifier;
39+
import NFModifier.Modifier;
4040
import SCode.Element;
4141
import SCode;
4242
import Type = NFType;

Compiler/NFFrontEnd/NFConvertDAE.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import ExecStat.execStat;
4444
import ElementSource;
4545
import ComponentRef = NFComponentRef;
4646
import Type = NFType;
47-
import NFMod.Modifier;
47+
import NFModifier.Modifier;
4848
import Expression = NFExpression;
4949
import NFComponent.Component;
5050
import Prefixes = NFPrefixes;

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ public
161161
Type ty;
162162
end UNBOX;
163163

164+
record SUBSCRIPTED_EXP
165+
Expression exp;
166+
list<Expression> subscripts;
167+
Type ty;
168+
end SUBSCRIPTED_EXP;
169+
164170
record TUPLE_ELEMENT
165171
Expression tupleExp;
166172
Integer index;
@@ -393,6 +399,17 @@ public
393399
then
394400
compare(exp1.exp, e1);
395401

402+
case SUBSCRIPTED_EXP()
403+
algorithm
404+
SUBSCRIPTED_EXP(exp = e1, subscripts = expl) := exp2;
405+
comp := compare(exp1.exp, e1);
406+
407+
if comp == 0 then
408+
comp := compareList(exp1.subscripts, expl);
409+
end if;
410+
then
411+
comp;
412+
396413
case TUPLE_ELEMENT()
397414
algorithm
398415
TUPLE_ELEMENT(tupleExp = e1, index = i) := exp2;
@@ -482,6 +499,7 @@ public
482499
case IF() then typeOf(exp.trueBranch);
483500
case CAST() then exp.ty;
484501
case UNBOX() then exp.ty;
502+
case SUBSCRIPTED_EXP() then exp.ty;
485503
case TUPLE_ELEMENT() then exp.ty;
486504
else Type.UNKNOWN();
487505
end match;
@@ -564,6 +582,10 @@ public
564582
then
565583
CREF(Type.unliftArray(array.ty), cref);
566584

585+
case SUBSCRIPTED_EXP()
586+
then SUBSCRIPTED_EXP(array.exp, listAppend(array.subscripts, {INTEGER(index)}), Type.unliftArray(array.ty));
587+
588+
else SUBSCRIPTED_EXP(array, {INTEGER(index)}, Type.unliftArray(typeOf(array)));
567589
end match;
568590
end arrayElement;
569591

@@ -689,6 +711,7 @@ public
689711

690712
case UNBOX() then "UNBOX(" + toString(exp.exp) + ")";
691713
case CAST() then "CAST(" + Type.toString(exp.ty) + ", " + toString(exp.exp) + ")";
714+
case SUBSCRIPTED_EXP() then toString(exp.exp) + "[" + stringDelimitList(list(toString(e) for e in exp.subscripts), ", ") + "]";
692715
case TUPLE_ELEMENT() then toString(exp.tupleExp) + "[" + intString(exp.index) + "]";
693716

694717
else anyString(exp);
@@ -769,6 +792,9 @@ public
769792
case UNBOX()
770793
then DAE.UNBOX(toDAE(exp.exp), Type.toDAE(exp.ty));
771794

795+
case SUBSCRIPTED_EXP()
796+
then DAE.ASUB(toDAE(exp.exp), list(toDAE(s) for s in exp.subscripts));
797+
772798
case TUPLE_ELEMENT()
773799
then DAE.TSUB(toDAE(exp.tupleExp), exp.index, Type.toDAE(exp.ty));
774800

@@ -792,6 +818,7 @@ public
792818
case RANGE() then Type.dimensionCount(exp.ty);
793819
case SIZE(dimIndex = NONE()) then dimensionCount(exp.exp);
794820
case CAST() then dimensionCount(exp.exp);
821+
case SUBSCRIPTED_EXP() then Type.dimensionCount(exp.ty);
795822
case TUPLE_ELEMENT() then Type.dimensionCount(exp.ty);
796823
// TODO: Add more expressions.
797824
else 0;
@@ -908,6 +935,9 @@ public
908935
then
909936
if referenceEq(exp.exp, e1) then exp else UNBOX(e1, exp.ty);
910937

938+
case SUBSCRIPTED_EXP()
939+
then SUBSCRIPTED_EXP(map(exp.exp, func), list(map(e, func) for e in exp.subscripts), exp.ty);
940+
911941
case TUPLE_ELEMENT()
912942
algorithm
913943
e1 := map(exp.tupleExp, func);
@@ -995,6 +1025,18 @@ public
9951025
then
9961026
Call.TYPED_CALL(call.fn, args, call.attributes);
9971027

1028+
case Call.UNTYPED_MAP_CALL()
1029+
algorithm
1030+
e := map(call.exp, func);
1031+
then
1032+
Call.UNTYPED_MAP_CALL(call.ref, e, call.iters);
1033+
1034+
case Call.TYPED_MAP_CALL()
1035+
algorithm
1036+
e := map(call.exp, func);
1037+
then
1038+
Call.TYPED_MAP_CALL(call.fn, call.ty, e, call.iters);
1039+
9981040
end match;
9991041
end mapCall;
10001042

@@ -1114,6 +1156,13 @@ public
11141156

11151157
case CAST() then fold(exp.exp, func, arg);
11161158
case UNBOX() then fold(exp.exp, func, arg);
1159+
1160+
case SUBSCRIPTED_EXP()
1161+
algorithm
1162+
result := fold(exp.exp, func, arg);
1163+
then
1164+
List.fold(exp.subscripts, func, result);
1165+
11171166
case TUPLE_ELEMENT() then fold(exp.tupleExp, func, arg);
11181167

11191168
else arg;
@@ -1167,6 +1216,18 @@ public
11671216
then
11681217
();
11691218

1219+
case Call.UNTYPED_MAP_CALL()
1220+
algorithm
1221+
arg := fold(call.exp, func, arg);
1222+
then
1223+
();
1224+
1225+
case Call.TYPED_MAP_CALL()
1226+
algorithm
1227+
arg := fold(call.exp, func, arg);
1228+
then
1229+
();
1230+
11701231
end match;
11711232
end foldCall;
11721233

@@ -1345,6 +1406,13 @@ public
13451406
then
13461407
if referenceEq(exp.exp, e1) then exp else UNBOX(e1, exp.ty);
13471408

1409+
case SUBSCRIPTED_EXP()
1410+
algorithm
1411+
(e1, arg) := mapFold(exp.exp, func, arg);
1412+
(expl, arg) := List.map1Fold(exp.subscripts, mapFold, func, arg);
1413+
then
1414+
SUBSCRIPTED_EXP(e1, expl, exp.ty);
1415+
13481416
case TUPLE_ELEMENT()
13491417
algorithm
13501418
(e1, arg) := mapFold(exp.tupleExp, func, arg);
@@ -1437,6 +1505,18 @@ public
14371505
then
14381506
Call.TYPED_CALL(call.fn, args, call.attributes);
14391507

1508+
case Call.UNTYPED_MAP_CALL()
1509+
algorithm
1510+
(e, foldArg) := mapFold(call.exp, func, foldArg);
1511+
then
1512+
Call.UNTYPED_MAP_CALL(call.ref, e, call.iters);
1513+
1514+
case Call.TYPED_MAP_CALL()
1515+
algorithm
1516+
(e, foldArg) := mapFold(call.exp, func, foldArg);
1517+
then
1518+
Call.TYPED_MAP_CALL(call.fn, call.ty, e, call.iters);
1519+
14401520
end match;
14411521
end mapFoldCall;
14421522

0 commit comments

Comments
 (0)