Skip to content

Commit

Permalink
[NF] Improve expression expansion.
Browse files Browse the repository at this point in the history
- 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]:
  - OpenModelica/OMCompiler#2538
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jun 28, 2018
1 parent 592a4a4 commit 5615485
Show file tree
Hide file tree
Showing 5 changed files with 384 additions and 146 deletions.
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -1009,7 +1009,7 @@ function evalLogicBinaryOp
input Expression exp1;
input Operator op;
input Expression exp2;
input EvalTarget target;
input EvalTarget target = EvalTarget.IGNORE_ERRORS();
output Expression exp;
algorithm
exp := match op.op
Expand Down
30 changes: 26 additions & 4 deletions Compiler/NFFrontEnd/NFConnections.mo
Expand Up @@ -82,6 +82,7 @@ public
list<Connector> cl1, cl2;
Expression e1, e2;
Type ty1, ty2;
Boolean b1, b2;
algorithm
// Collect all flow variables.
for var in flatModel.variables loop
Expand All @@ -101,10 +102,8 @@ public
rhs = Expression.CREF(ty = ty2, cref = rhs), source = source)
algorithm
if not (ComponentRef.isDeleted(lhs) or ComponentRef.isDeleted(rhs)) then
e1 := Expression.CREF(ty1, ComponentRef.simplifySubscripts(lhs));
cl1 := Connector.fromExp(ExpandExp.expand(e1), source);
e2 := Expression.CREF(ty2, ComponentRef.simplifySubscripts(rhs));
cl2 := Connector.fromExp(ExpandExp.expand(e2), source);
cl1 := makeConnectors(lhs, ty1, source);
cl2 := makeConnectors(rhs, ty2, source);

for c1 in cl1 loop
c2 :: cl2 := cl2;
Expand All @@ -123,5 +122,28 @@ public
end if;
end collect;

function makeConnectors
input ComponentRef cref;
input Type ty;
input DAE.ElementSource source;
output list<Connector> connectors;
protected
Expression cref_exp;
Boolean expanded;
algorithm
cref_exp := Expression.CREF(ty, ComponentRef.simplifySubscripts(cref));
(cref_exp, expanded) := ExpandExp.expand(cref_exp);

if expanded then
connectors := Connector.fromExp(cref_exp, source);
else
// Connectors should only have structural parameter subscripts, so it
// should always be possible to expand them.
Error.assertion(false, getInstanceName() + " failed to expand connector `" +
ComponentRef.toString(cref) + "\n", ElementSource.getInfo(source));
end if;
end makeConnectors;


annotation(__OpenModelica_Interface="frontend");
end NFConnections;

0 comments on commit 5615485

Please sign in to comment.