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

Commit

Permalink
[NF] Fix scoping of imported components.
Browse files Browse the repository at this point in the history
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 22, 2018
1 parent 59e722e commit 59944ec
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Compiler/NFFrontEnd/NFClass.mo
Expand Up @@ -166,8 +166,9 @@ uniontype Class
input String name;
input Class cls;
output InstNode node;
output Boolean isImport;
algorithm
node := ClassTree.lookupElement(name, classTree(cls));
(node, isImport) := ClassTree.lookupElement(name, classTree(cls));
end lookupElement;

function lookupAttribute
Expand Down
12 changes: 7 additions & 5 deletions Compiler/NFFrontEnd/NFClassTree.mo
Expand Up @@ -676,11 +676,12 @@ public
input String name;
input ClassTree tree;
output InstNode element;
output Boolean isImport;
protected
LookupTree.Entry entry;
algorithm
entry := LookupTree.get(lookupTree(tree), name);
element := resolveEntry(entry, tree);
(element, isImport) := resolveEntry(entry, tree);
end lookupElement;

function lookupElementPtr
Expand Down Expand Up @@ -1214,11 +1215,12 @@ public
input LookupTree.Entry entry;
input ClassTree tree;
output InstNode element;
output Boolean isImport;
algorithm
element := match entry
case LookupTree.Entry.CLASS() then resolveClass(entry.index, tree);
case LookupTree.Entry.COMPONENT() then resolveComponent(entry.index, tree);
case LookupTree.Entry.IMPORT() then resolveImport(entry.index, tree);
(element, isImport) := match entry
case LookupTree.Entry.CLASS() then (resolveClass(entry.index, tree), false);
case LookupTree.Entry.COMPONENT() then (resolveComponent(entry.index, tree), false);
case LookupTree.Entry.IMPORT() then (resolveImport(entry.index, tree), true);
end match;
end resolveEntry;

Expand Down
24 changes: 16 additions & 8 deletions Compiler/NFFrontEnd/NFLookup.mo
Expand Up @@ -657,15 +657,17 @@ function lookupSimpleCref
input InstNode scope;
output InstNode node;
output InstNode foundScope = scope;
protected
Boolean is_import;
algorithm
// Look for the name in the given scope, and if not found there continue
// through the enclosing scopes of that scope until we either run out of
// scopes or for some reason exceed the recursion depth limit.
for i in 1:Global.recursionDepthLimit loop
try
node := match foundScope
(node, is_import) := match foundScope
case InstNode.IMPLICIT_SCOPE()
then lookupIterator(name, foundScope.locals);
then (lookupIterator(name, foundScope.locals), false);
case InstNode.CLASS_NODE()
then Class.lookupElement(name, InstNode.getClass(foundScope));
case InstNode.COMPONENT_NODE()
Expand All @@ -674,8 +676,10 @@ algorithm
then Class.lookupElement(name, InstNode.getClass(foundScope.innerNode));
end match;

// If the node is an outer node, return the inner instead.
if InstNode.isInnerOuterNode(node) then
if is_import then
foundScope := InstNode.parent(node);
elseif InstNode.isInnerOuterNode(node) then
// If the node is an outer node, return the inner instead.
node := InstNode.resolveInner(node);
foundScope := InstNode.parent(node);
end if;
Expand All @@ -700,10 +704,12 @@ function lookupLocalSimpleCref
input InstNode scope;
output InstNode node;
output InstNode foundScope = scope;
protected
Boolean is_import;
algorithm
node := match foundScope
(node, is_import) := match foundScope
case InstNode.IMPLICIT_SCOPE()
then lookupIterator(name, foundScope.locals);
then (lookupIterator(name, foundScope.locals), false);
case InstNode.CLASS_NODE()
then Class.lookupElement(name, InstNode.getClass(foundScope));
case InstNode.COMPONENT_NODE()
Expand All @@ -712,8 +718,10 @@ algorithm
then Class.lookupElement(name, InstNode.getClass(foundScope.innerNode));
end match;

// If the node is an outer node, return the inner instead.
if InstNode.isInnerOuterNode(node) then
if is_import then
foundScope := InstNode.parent(node);
elseif InstNode.isInnerOuterNode(node) then
// If the node is an outer node, return the inner instead.
node := InstNode.resolveInner(node);
foundScope := InstNode.parent(node);
end if;
Expand Down

0 comments on commit 59944ec

Please sign in to comment.