Skip to content

Commit

Permalink
NFInst fixes.
Browse files Browse the repository at this point in the history
- Use correct parent scope in Lookup.lookupSimpleName.
- Cache packages before instantiating them, to avoid loops.

Belonging to [master]:
  - OpenModelica/OMCompiler#1922
  • Loading branch information
perost authored and OpenModelica-Hudson committed Oct 18, 2017
1 parent ac679f7 commit 625bb65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -643,6 +643,10 @@ algorithm
end updateComponentClass;

function instPackage
"This function instantiates a package given a package node. If the package has
already been instantiated, then the cached instance from the node is
returned. Otherwise the node is fully instantiated, the instance is added to
the node's cache, and the instantiated node is returned."
input output InstNode node;
protected
CachedData cache;
Expand All @@ -655,7 +659,12 @@ algorithm

case CachedData.NO_CACHE()
algorithm
// Cache the package node itself first, to avoid instantiation loops if
// the package uses itself somehow.
InstNode.setCachedData(CachedData.PACKAGE(node), node);
// Instantiate the node.
inst := instantiate(node);
// Cache the instantiated node and instantiate expressions in it too.
InstNode.setCachedData(CachedData.PACKAGE(inst), node);
instExpressions(inst);
then
Expand Down
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFLookup.mo
Expand Up @@ -350,7 +350,7 @@ algorithm
return;
else
// Otherwise, continue in the enclosing scope.
cur_scope := InstNode.parent(cur_scope);
cur_scope := InstNode.parentScope(cur_scope);
end if;
end try;
end for;
Expand Down

0 comments on commit 625bb65

Please sign in to comment.