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

Commit ae5e0b1

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Connection handling improvements.
- Fixed typing error in ComponentRef.setSubscriptsList, the crefs type shouldn't take subscripts into account. - Expand connector expressions before creating connectors from them. - Fixed error in Expression.expandCref2 that caused some array crefs to be erroneously expanded into an empty array. Belonging to [master]: - #2380 - OpenModelica/OpenModelica-testsuite#926
1 parent ff81880 commit ae5e0b1

File tree

4 files changed

+38
-8
lines changed

4 files changed

+38
-8
lines changed

Compiler/NFFrontEnd/NFComponentRef.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public
328328
algorithm
329329
rest_cref := setSubscriptsList(rest_subs, cref.restCref);
330330
then
331-
CREF(cref.node, subs, Type.arrayElementType(cref.ty), cref.origin, rest_cref);
331+
CREF(cref.node, subs, cref.ty, cref.origin, rest_cref);
332332

333333
case ({}, _) then cref;
334334
end match;

Compiler/NFFrontEnd/NFConnections.mo

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ public
7676
Component comp;
7777
ComponentRef cr, lhs, rhs;
7878
Connector c1, c2;
79-
Type ty1, ty2;
8079
DAE.ElementSource source;
8180
list<Equation> eql = {};
81+
list<Connector> cl1, cl2;
8282
algorithm
8383
// Collect all flow variables.
8484
for var in flatModel.variables loop
@@ -94,13 +94,17 @@ public
9494
// Collect all connects.
9595
for eq in flatModel.equations loop
9696
eql := match eq
97-
case Equation.CONNECT(lhs = Expression.CREF(cref = lhs, ty = ty1),
98-
rhs = Expression.CREF(cref = rhs, ty = ty2), source = source)
97+
case Equation.CONNECT(lhs = Expression.CREF(cref = lhs),
98+
rhs = Expression.CREF(cref = rhs), source = source)
9999
algorithm
100100
if not (ComponentRef.isDeleted(lhs) or ComponentRef.isDeleted(rhs)) then
101-
c1 := Connector.fromCref(lhs, ty1, source);
102-
c2 := Connector.fromCref(rhs, ty2, source);
103-
conns := addConnection(Connection.CONNECTION(c1, c2), conns);
101+
cl1 := Connector.fromExp(Expression.expand(eq.lhs), source);
102+
cl2 := Connector.fromExp(Expression.expand(eq.rhs), source);
103+
104+
for c1 in cl1 loop
105+
c2 :: cl2 := cl2;
106+
conns := addConnection(Connection.CONNECTION(c1, c2), conns);
107+
end for;
104108
end if;
105109
then
106110
eql;

Compiler/NFFrontEnd/NFConnector.mo

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,31 @@ public
8181
Component.connectorType(InstNode.component(node)), NONE(), source);
8282
end fromFacedCref;
8383

84+
function fromExp
85+
"Constructs a list of Connectors from a cref or an array of crefs."
86+
input Expression exp;
87+
input DAE.ElementSource source;
88+
input output list<Connector> conns = {};
89+
algorithm
90+
conns := match exp
91+
case Expression.CREF() then fromCref(exp.cref, exp.ty, source) :: conns;
92+
case Expression.ARRAY()
93+
algorithm
94+
for e in listReverse(exp.elements) loop
95+
conns := fromExp(e, source, conns);
96+
end for;
97+
then
98+
conns;
99+
100+
else
101+
algorithm
102+
Error.assertion(false, getInstanceName() + " got unknown expression " +
103+
Expression.toString(exp), sourceInfo());
104+
then
105+
fail();
106+
end match;
107+
end fromExp;
108+
84109
function getType
85110
input Connector conn;
86111
output Type ty = conn.ty;

Compiler/NFFrontEnd/NFExpression.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,8 @@ public
21362136
dims := Type.arrayDims(cref.ty);
21372137
cr_subs := Subscript.expandList(cref.subscripts, dims);
21382138
then
2139-
if listEmpty(cr_subs) then {} else expandCref2(cref.restCref, cr_subs :: subs);
2139+
if listEmpty(cr_subs) and not listEmpty(dims) then
2140+
{} else expandCref2(cref.restCref, cr_subs :: subs);
21402141

21412142
else subs;
21422143
end match;

0 commit comments

Comments
 (0)