From d37a91dc15452f948df9d10c55c90c10e6fd416b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Tue, 28 Apr 2020 12:40:26 +0200 Subject: [PATCH] [NF] Improve lookup for expandable connectors. - Check that the scope is an expandable connector instance before allowing lookup of non-existing names. - Don't continue the lookup if a non-existing name is found in an expandable connector, just convert the remaining cref and return it. - Exit early in Type.subscript if the type is unknown, since a subscripted unknown type is still unknown. --- .CI/compliance-newinst.failures | 1 - OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo | 10 ++++------ .../Compiler/NFFrontEnd/NFExpandableConnectors.mo | 8 ++++++++ OMCompiler/Compiler/NFFrontEnd/NFLookup.mo | 5 +++-- OMCompiler/Compiler/NFFrontEnd/NFType.mo | 2 +- .../modelica/scodeinst/ExpandableConnectorNonDecl3.mo | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.CI/compliance-newinst.failures b/.CI/compliance-newinst.failures index 91ea3d3c8c8..606225a6239 100644 --- a/.CI/compliance-newinst.failures +++ b/.CI/compliance-newinst.failures @@ -72,7 +72,6 @@ ModelicaCompliance.Connections.Declarations.OperatorRecordMissingAddition ModelicaCompliance.Connections.Declarations.OperatorRecordMissingNegation ModelicaCompliance.Connections.Declarations.OperatorRecordMissingZero ModelicaCompliance.Connections.Expandable.AugmentArray -ModelicaCompliance.Connections.Expandable.AugmentArrayElement ModelicaCompliance.Connections.Expandable.AugmentComplex ModelicaCompliance.Connections.Expandable.FlowInConnectorInExpandable ModelicaCompliance.Connections.Expandable.MissingNonInput diff --git a/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo b/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo index 39ec54ce493..7685522aa39 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo @@ -108,18 +108,16 @@ public function fromAbsynCref input Absyn.ComponentRef acref; + input ComponentRef restCref = EMPTY(); output ComponentRef cref; algorithm cref := match acref case Absyn.ComponentRef.CREF_IDENT() - then CREF(InstNode.NAME_NODE(acref.name), - list(Subscript.RAW_SUBSCRIPT(s) for s in acref.subscripts), - Type.UNKNOWN(), Origin.CREF, EMPTY()); + then fromAbsyn(InstNode.NAME_NODE(acref.name), acref.subscripts, restCref); case Absyn.ComponentRef.CREF_QUAL() - then CREF(InstNode.NAME_NODE(acref.name), - list(Subscript.RAW_SUBSCRIPT(s) for s in acref.subscripts), - Type.UNKNOWN(), Origin.CREF, fromAbsynCref(acref.componentRef)); + then fromAbsynCref(acref.componentRef, + fromAbsyn(InstNode.NAME_NODE(acref.name), acref.subscripts, restCref)); case Absyn.ComponentRef.CREF_FULLYQUALIFIED() then fromAbsynCref(acref.componentRef); diff --git a/OMCompiler/Compiler/NFFrontEnd/NFExpandableConnectors.mo b/OMCompiler/Compiler/NFFrontEnd/NFExpandableConnectors.mo index fa4bd7c5671..b8f9144cfca 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFExpandableConnectors.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFExpandableConnectors.mo @@ -382,6 +382,14 @@ protected algorithm exp_name := Connector.name(conn); exp_node := ComponentRef.node(exp_name); + + if InstNode.isName(exp_node) then + Error.addInternalError( + "Augmenting a virtual element in an expandable connector is not yet supported.", + Connector.getInfo(conn)); + fail(); + end if; + cls_node := InstNode.classScope(exp_node); cls := InstNode.getClass(cls_node); cls_tree := Class.classTree(cls); diff --git a/OMCompiler/Compiler/NFFrontEnd/NFLookup.mo b/OMCompiler/Compiler/NFFrontEnd/NFLookup.mo index d16e6619be7..57083849b6d 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFLookup.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFLookup.mo @@ -799,8 +799,9 @@ algorithm (n, is_import) := Class.lookupElement(name, cls); else true := InstNode.isComponent(node); - n := InstNode.NAME_NODE(name); - is_import := false; + true := Class.isExpandableConnectorClass(cls); + foundCref := ComponentRef.fromAbsynCref(cref, foundCref); + return; end try; if is_import then diff --git a/OMCompiler/Compiler/NFFrontEnd/NFType.mo b/OMCompiler/Compiler/NFFrontEnd/NFType.mo index 012257131f4..cbf6202cd9e 100644 --- a/OMCompiler/Compiler/NFFrontEnd/NFType.mo +++ b/OMCompiler/Compiler/NFFrontEnd/NFType.mo @@ -897,7 +897,7 @@ public Dimension dim; list dims, subbed_dims = {}; algorithm - if listEmpty(subs) then + if listEmpty(subs) or isUnknown(ty) then return; end if; diff --git a/testsuite/flattening/modelica/scodeinst/ExpandableConnectorNonDecl3.mo b/testsuite/flattening/modelica/scodeinst/ExpandableConnectorNonDecl3.mo index cb15d71e83e..f5ed48c0cef 100644 --- a/testsuite/flattening/modelica/scodeinst/ExpandableConnectorNonDecl3.mo +++ b/testsuite/flattening/modelica/scodeinst/ExpandableConnectorNonDecl3.mo @@ -19,7 +19,7 @@ end ExpandableConnectorNonDecl3; // Result: // Error processing file: ExpandableConnectorNonDecl3.mo -// [flattening/modelica/scodeinst/ExpandableConnectorNonDecl3.mo:17:3-17:23:writable] Error: Variable ec.c.ri not found in scope ExpandableConnectorNonDecl3. +// [flattening/modelica/scodeinst/ExpandableConnectorNonDecl3.mo:0:0-0:0:writable] Error: Internal error Augmenting a virtual element in an expandable connector is not yet supported. // // # Error encountered! Exiting... // # Please check the error message and the flags.