Changeset a489e50 in OpenModelica


Ignore:
Timestamp:
2021-02-15T12:30:31+01:00 (3 years ago)
Author:
GitHub <noreply@…>
Branches:
Added-citation-metadata, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master, omlib-staging
Children:
423386c, c5f65dbc
Parents:
3de3ab4
git-author:
perost <perost86@…> (02/15/21 12:30:31)
git-committer:
GitHub <noreply@…> (02/15/21 12:30:31)
Message:

Fix #7156 (#7157)

  • Try to inline operator record constructors instead of evaluating them when trying to split them during flattening.
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo

    r9220249b ra489e50  
    9393import ArrayConnections = NFArrayConnections;
    9494import UnorderedMap;
     95import Inline = NFInline;
    9596
    9697public
     
    592593      binding_exp := Expression.stripBindingInfo(Ceval.evalExp(binding_exp));
    593594    elseif binding_var == Variability.PARAMETER and Component.isFinal(comp) then
     595      // Try to use inlining first.
    594596      try
    595         binding_exp_eval := Expression.stripBindingInfo(Ceval.evalExp(binding_exp));
    596         // Throw away the evaluated binding if the number of dimensions no
    597         // longer match after evaluation, in case Ceval fails to apply the
    598         // subscripts correctly.
    599         // TODO: Fix this, it shouldn't be needed.
    600         0 := Type.dimensionDiff(ty, Expression.typeOf(binding_exp_eval));
    601         binding_exp := binding_exp_eval;
     597        binding_exp := Inline.inlineRecordConstructorCall(binding_exp);
    602598      else
    603599      end try;
     600
     601      // If inlining fails, try to evaluate the binding instead.
     602      if not Expression.isRecord(binding_exp) then
     603        try
     604          binding_exp_eval := Expression.stripBindingInfo(Ceval.evalExp(binding_exp));
     605
     606          // Throw away the evaluated binding if the number of dimensions no
     607          // longer match after evaluation, in case Ceval fails to apply the
     608          // subscripts correctly.
     609          // TODO: Fix this, it shouldn't be needed.
     610          0 := Type.dimensionDiff(ty, Expression.typeOf(binding_exp_eval));
     611          binding_exp := binding_exp_eval;
     612        else
     613        end try;
     614      end if;
    604615    else
    605616      binding_exp := SimplifyExp.simplify(binding_exp);
  • OMCompiler/Compiler/NFFrontEnd/NFInline.mo

    r918333e ra489e50  
    3232encapsulated package NFInline
    3333
     34import Call = NFCall;
     35import Expression = NFExpression;
     36
     37protected
     38import Binding = NFBinding;
     39import Class = NFClass;
     40import Component = NFComponent;
    3441import ComponentRef = NFComponentRef;
    3542import DAE.InlineType;
    3643import Dimension = NFDimension;
    37 import Expression = NFExpression;
    3844import Flags;
    39 import Call = NFCall;
    4045import NFFunction.Function;
    4146import NFInstNode.InstNode;
     
    4449import Type = NFType;
    4550
     51public
    4652function inlineCallExp
    4753  input Expression callExp;
     
    114120end inlineCall;
    115121
     122function inlineRecordConstructorCall
     123  input Expression exp;
     124  output Expression outExp;
     125protected
     126  Function fn;
     127  Expression arg;
     128  list<Expression> args;
     129  list<Statement> body;
     130  Binding binding;
     131algorithm
     132  outExp := match exp
     133    case Expression.CALL(call = Call.TYPED_CALL(fn = fn, arguments = args))
     134        guard InstNode.name(InstNode.parentScope(fn.node)) == "'constructor'"
     135      algorithm
     136        body := Function.getBody(fn);
     137        true := listEmpty(body);
     138        true := listEmpty(fn.locals);
     139
     140        binding := Component.getBinding(InstNode.component(listHead(fn.outputs)));
     141
     142        if Binding.hasExp(binding) then
     143          outExp := Binding.getExp(binding);
     144          true := Expression.isRecord(outExp);
     145        else
     146          outExp := Class.makeRecordExp(listHead(fn.outputs));
     147        end if;
     148
     149        for i in fn.inputs loop
     150          arg :: args := args;
     151          outExp := Expression.map(outExp, func = function replaceCrefNode(node = i, value = arg));
     152        end for;
     153      then
     154        outExp;
     155  end match;
     156end inlineRecordConstructorCall;
     157
    116158protected
    117159function replaceCrefNode
  • testsuite/flattening/modelica/scodeinst/Makefile

    r63e15e6 ra489e50  
    610610ImpureCall1.mo \
    611611Inline1.mo \
     612Inline2.mo \
    612613InnerOuter1.mo \
    613614InnerOuter2.mo \
Note: See TracChangeset for help on using the changeset viewer.