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

Commit 5615485

Browse files
perostOpenModelica-Hudson
authored andcommitted
[NF] Improve expression expansion.
- Improved ExpandExp so that it doesn't try to expand expressions that can't be expanded and triggering assertions, but instead returning a flag that indicates whether the expansion was successful or not. Belonging to [master]: - #2538
1 parent 592a4a4 commit 5615485

File tree

5 files changed

+384
-146
lines changed

5 files changed

+384
-146
lines changed

Compiler/NFFrontEnd/NFCeval.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ function evalLogicBinaryOp
10091009
input Expression exp1;
10101010
input Operator op;
10111011
input Expression exp2;
1012-
input EvalTarget target;
1012+
input EvalTarget target = EvalTarget.IGNORE_ERRORS();
10131013
output Expression exp;
10141014
algorithm
10151015
exp := match op.op

Compiler/NFFrontEnd/NFConnections.mo

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public
8282
list<Connector> cl1, cl2;
8383
Expression e1, e2;
8484
Type ty1, ty2;
85+
Boolean b1, b2;
8586
algorithm
8687
// Collect all flow variables.
8788
for var in flatModel.variables loop
@@ -101,10 +102,8 @@ public
101102
rhs = Expression.CREF(ty = ty2, cref = rhs), source = source)
102103
algorithm
103104
if not (ComponentRef.isDeleted(lhs) or ComponentRef.isDeleted(rhs)) then
104-
e1 := Expression.CREF(ty1, ComponentRef.simplifySubscripts(lhs));
105-
cl1 := Connector.fromExp(ExpandExp.expand(e1), source);
106-
e2 := Expression.CREF(ty2, ComponentRef.simplifySubscripts(rhs));
107-
cl2 := Connector.fromExp(ExpandExp.expand(e2), source);
105+
cl1 := makeConnectors(lhs, ty1, source);
106+
cl2 := makeConnectors(rhs, ty2, source);
108107

109108
for c1 in cl1 loop
110109
c2 :: cl2 := cl2;
@@ -123,5 +122,28 @@ public
123122
end if;
124123
end collect;
125124

125+
function makeConnectors
126+
input ComponentRef cref;
127+
input Type ty;
128+
input DAE.ElementSource source;
129+
output list<Connector> connectors;
130+
protected
131+
Expression cref_exp;
132+
Boolean expanded;
133+
algorithm
134+
cref_exp := Expression.CREF(ty, ComponentRef.simplifySubscripts(cref));
135+
(cref_exp, expanded) := ExpandExp.expand(cref_exp);
136+
137+
if expanded then
138+
connectors := Connector.fromExp(cref_exp, source);
139+
else
140+
// Connectors should only have structural parameter subscripts, so it
141+
// should always be possible to expand them.
142+
Error.assertion(false, getInstanceName() + " failed to expand connector `" +
143+
ComponentRef.toString(cref) + "\n", ElementSource.getInfo(source));
144+
end if;
145+
end makeConnectors;
146+
147+
126148
annotation(__OpenModelica_Interface="frontend");
127149
end NFConnections;

0 commit comments

Comments
 (0)