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

Commit

Permalink
[NF] Implemented expansion of cat and promote.
Browse files Browse the repository at this point in the history
- Refactored expression expansion code into a new module NFExpandExp.
- Implemented expansion of cat and promote to avoid them being
  subscripted and blowing up the flat model during scalarization.

Belonging to [master]:
  - #2463
  - OpenModelica/OpenModelica-testsuite#960
  • Loading branch information
perost authored and OpenModelica-Hudson committed May 24, 2018
1 parent 2ea6748 commit e80e927
Show file tree
Hide file tree
Showing 9 changed files with 670 additions and 563 deletions.
84 changes: 42 additions & 42 deletions Compiler/NFFrontEnd/NFCeval.mo
Expand Up @@ -1312,48 +1312,6 @@ function evalNormalCall
output Expression result = EvalFunction.evaluate(fn, args);
end evalNormalCall;

protected

function printUnboundError
input EvalTarget target;
input Expression exp;
algorithm
() := match target
case EvalTarget.DIMENSION()
algorithm
Error.addSourceMessage(Error.STRUCTURAL_PARAMETER_OR_CONSTANT_WITH_NO_BINDING,
{Expression.toString(exp), InstNode.name(target.component)}, target.info);
then
fail();

case EvalTarget.CONDITION()
algorithm
Error.addSourceMessage(Error.CONDITIONAL_EXP_WITHOUT_VALUE,
{Expression.toString(exp)}, target.info);
then
fail();

case EvalTarget.GENERIC()
algorithm
Error.addMultiSourceMessage(Error.UNBOUND_CONSTANT,
{Expression.toString(exp)},
{InstNode.info(ComponentRef.node(Expression.toCref(exp))), target.info});
then
fail();

else ();
end match;
end printUnboundError;

function printWrongArgsError
input String evalFunc;
input list<Expression> args;
input SourceInfo info;
algorithm
Error.addInternalError(evalFunc + " got invalid arguments " +
List.toString(args, Expression.toString, "", "(", ", ", ")", true), info);
end printWrongArgsError;

function evalBuiltinAbs
input Expression arg;
output Expression result;
Expand Down Expand Up @@ -2362,5 +2320,47 @@ algorithm
end match;
end evalSubscript;

protected

function printUnboundError
input EvalTarget target;
input Expression exp;
algorithm
() := match target
case EvalTarget.DIMENSION()
algorithm
Error.addSourceMessage(Error.STRUCTURAL_PARAMETER_OR_CONSTANT_WITH_NO_BINDING,
{Expression.toString(exp), InstNode.name(target.component)}, target.info);
then
fail();

case EvalTarget.CONDITION()
algorithm
Error.addSourceMessage(Error.CONDITIONAL_EXP_WITHOUT_VALUE,
{Expression.toString(exp)}, target.info);
then
fail();

case EvalTarget.GENERIC()
algorithm
Error.addMultiSourceMessage(Error.UNBOUND_CONSTANT,
{Expression.toString(exp)},
{InstNode.info(ComponentRef.node(Expression.toCref(exp))), target.info});
then
fail();

else ();
end match;
end printUnboundError;

function printWrongArgsError
input String evalFunc;
input list<Expression> args;
input SourceInfo info;
algorithm
Error.addInternalError(evalFunc + " got invalid arguments " +
List.toString(args, Expression.toString, "", "(", ", ", ")", true), info);
end printWrongArgsError;

annotation(__OpenModelica_Interface="frontend");
end NFCeval;
5 changes: 3 additions & 2 deletions Compiler/NFFrontEnd/NFConnections.mo
Expand Up @@ -44,6 +44,7 @@ protected
import Type = NFType;
import MetaModelica.Dangerous.listReverseInPlace;
import ElementSource;
import ExpandExp = NFExpandExp;

public
record CONNECTIONS
Expand Down Expand Up @@ -98,8 +99,8 @@ public
rhs = Expression.CREF(cref = rhs), source = source)
algorithm
if not (ComponentRef.isDeleted(lhs) or ComponentRef.isDeleted(rhs)) then
cl1 := Connector.fromExp(Expression.expand(eq.lhs), source);
cl2 := Connector.fromExp(Expression.expand(eq.rhs), source);
cl1 := Connector.fromExp(ExpandExp.expand(eq.lhs), source);
cl2 := Connector.fromExp(ExpandExp.expand(eq.rhs), source);

for c1 in cl1 loop
c2 :: cl2 := cl2;
Expand Down

0 comments on commit e80e927

Please sign in to comment.