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

Commit 53c7b25

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Collect more functions during flattening.
- Collect functions in the type of equality equations and assignments as well as in for statement ranges. - Add type to Statement.ASSIGNMENT. Belonging to [master]: - #2558 - OpenModelica/OpenModelica-testsuite#998
1 parent 25d5df2 commit 53c7b25

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

Compiler/NFFrontEnd/NFConvertDAE.mo

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,7 @@ protected
735735
DAE.Exp dlhs, drhs;
736736
list<Expression> expl;
737737
algorithm
738-
Statement.ASSIGNMENT(lhs, rhs, src) := stmt;
739-
ty := Expression.typeOf(lhs);
738+
Statement.ASSIGNMENT(lhs, rhs, ty, src) := stmt;
740739

741740
if Type.isTuple(ty) then
742741
Expression.TUPLE(elements = expl) := lhs;
@@ -748,7 +747,6 @@ algorithm
748747
// (lhs) := call(...) => lhs := TSUB[call(...), 1]
749748
case {lhs}
750749
algorithm
751-
ty := Expression.typeOf(lhs);
752750
dty := Type.toDAE(ty);
753751
dlhs := Expression.toDAE(lhs);
754752
drhs := DAE.Exp.TSUB(Expression.toDAE(rhs), 1, dty);

Compiler/NFFrontEnd/NFFlatten.mo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,16 +1042,20 @@ algorithm
10421042
algorithm
10431043
funcs := collectExpFuncs(eq.lhs, funcs);
10441044
funcs := collectExpFuncs(eq.rhs, funcs);
1045+
funcs := collectTypeFuncs(eq.ty, funcs);
10451046
then
10461047
();
10471048

10481049
case Equation.ARRAY_EQUALITY()
10491050
algorithm
10501051
// Lhs is always a cref, no need to check it.
10511052
funcs := collectExpFuncs(eq.rhs, funcs);
1053+
funcs := collectTypeFuncs(eq.ty, funcs);
10521054
then
10531055
();
10541056

1057+
// For equations are always unrolled, so functions in the range doesn't
1058+
// matter since they are always evaluated.
10551059
case Equation.FOR()
10561060
algorithm
10571061
funcs := List.fold(eq.body, collectEquationFuncs, funcs);
@@ -1132,12 +1136,14 @@ algorithm
11321136
algorithm
11331137
funcs := collectExpFuncs(stmt.lhs, funcs);
11341138
funcs := collectExpFuncs(stmt.rhs, funcs);
1139+
funcs := collectTypeFuncs(stmt.ty, funcs);
11351140
then
11361141
();
11371142

11381143
case Statement.FOR()
11391144
algorithm
11401145
funcs := List.fold(stmt.body, collectStatementFuncs, funcs);
1146+
funcs := collectExpFuncs(Util.getOption(stmt.range), funcs);
11411147
then
11421148
();
11431149

Compiler/NFFrontEnd/NFInst.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,7 @@ algorithm
26602660
exp1 := instExp(scodeStmt.assignComponent, scope, info);
26612661
exp2 := instExp(scodeStmt.value, scope, info);
26622662
then
2663-
Statement.ASSIGNMENT(exp1, exp2, makeSource(scodeStmt.comment, info));
2663+
Statement.ASSIGNMENT(exp1, exp2, Type.UNKNOWN(), makeSource(scodeStmt.comment, info));
26642664

26652665
case SCode.Statement.ALG_FOR(info = info)
26662666
algorithm

Compiler/NFFrontEnd/NFStatement.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public
4545
record ASSIGNMENT
4646
Expression lhs "The asignee";
4747
Expression rhs "The expression";
48+
Type ty;
4849
DAE.ElementSource source;
4950
end ASSIGNMENT;
5051

@@ -229,7 +230,7 @@ public
229230
e2 := func(stmt.rhs);
230231
then
231232
if referenceEq(e1, stmt.lhs) and referenceEq(e2, stmt.rhs) then
232-
stmt else ASSIGNMENT(e1, e2, stmt.source);
233+
stmt else ASSIGNMENT(e1, e2, stmt.ty, stmt.source);
233234

234235
case FOR()
235236
algorithm

Compiler/NFFrontEnd/NFTyping.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,7 @@ algorithm
24272427
(e2, ty2) := typeExp(st.rhs, intBitOr(origin, ExpOrigin.RHS), info);
24282428

24292429
// TODO: Should probably only be allowUnknown = true if in a function.
2430-
(e2,_, mk) := TypeCheck.matchTypes(ty2, ty1, e2, allowUnknown = true);
2430+
(e2, ty3, mk) := TypeCheck.matchTypes(ty2, ty1, e2, allowUnknown = true);
24312431

24322432
if TypeCheck.isIncompatibleMatch(mk) then
24332433
Error.addSourceMessage(Error.ASSIGN_TYPE_MISMATCH_ERROR,
@@ -2436,7 +2436,7 @@ algorithm
24362436
fail();
24372437
end if;
24382438
then
2439-
Statement.ASSIGNMENT(e1, e2, st.source);
2439+
Statement.ASSIGNMENT(e1, e2, ty3, st.source);
24402440

24412441
case Statement.FOR()
24422442
algorithm

0 commit comments

Comments
 (0)