Skip to content

Commit

Permalink
[NF] Improve lookup for expandable connectors.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
perost committed Apr 28, 2020
1 parent 38a1cbb commit d37a91d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
1 change: 0 additions & 1 deletion .CI/compliance-newinst.failures
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions OMCompiler/Compiler/NFFrontEnd/NFComponentRef.mo
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions OMCompiler/Compiler/NFFrontEnd/NFExpandableConnectors.mo
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions OMCompiler/Compiler/NFFrontEnd/NFLookup.mo
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFType.mo
Expand Up @@ -897,7 +897,7 @@ public
Dimension dim;
list<Dimension> dims, subbed_dims = {};
algorithm
if listEmpty(subs) then
if listEmpty(subs) or isUnknown(ty) then
return;
end if;

Expand Down
Expand Up @@ -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.
Expand Down

0 comments on commit d37a91d

Please sign in to comment.