Skip to content

Commit

Permalink
Fix NFInst lookup of inherited names.
Browse files Browse the repository at this point in the history
- Keep a list of instantiated extends nodes in instantiated classes,
  to make lookup of inherited names work in them.
  • Loading branch information
perost authored and OpenModelica-Hudson committed Jan 31, 2017
1 parent ff80ea0 commit 4ffbdb4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
19 changes: 9 additions & 10 deletions Compiler/NFFrontEnd/NFClass.mo
Expand Up @@ -101,6 +101,7 @@ uniontype Class

record INSTANCED_CLASS
ClassTree.Tree elements;
array<InstNode> extendsNodes;
array<InstNode> components;
list<Equation> equations;
list<Equation> initialEquations;
Expand All @@ -124,12 +125,6 @@ uniontype Class

type Element = ClassTree.Entry;

function emptyInstancedClass
output Class cls;
algorithm
cls := INSTANCED_CLASS(ClassTree.new(), listArray({}), {}, {}, {}, {});
end emptyInstancedClass;

function initExpandedClass
input ClassTree.Tree classes;
output Class cls;
Expand All @@ -139,6 +134,7 @@ uniontype Class

function instExpandedClass
input array<InstNode> components;
input array<InstNode> extendsNodes;
input Class expandedClass;
output Class instancedClass;
protected
Expand All @@ -159,7 +155,7 @@ uniontype Class
// instantiated and typed in the correct scope. They should be
// collected from the extends nodes when flattening the class.
then
INSTANCED_CLASS(expandedClass.elements, components, eqs, ieqs, algs, ialgs);
INSTANCED_CLASS(expandedClass.elements, extendsNodes, components, eqs, ieqs, algs, ialgs);
end match;
end instExpandedClass;

Expand Down Expand Up @@ -257,7 +253,10 @@ uniontype Class
input Class cls;
output array<InstNode> extendsNodes;
algorithm
EXPANDED_CLASS(extendsNodes = extendsNodes) := cls;
extendsNodes := match cls
case EXPANDED_CLASS() then cls.extendsNodes;
case INSTANCED_CLASS() then cls.extendsNodes;
end match;
end extendsNodes;

function setSections
Expand All @@ -273,8 +272,8 @@ uniontype Class
cls.modifier, equations, initialEquations, algorithms, initialAlgorithms);

case INSTANCED_CLASS()
then INSTANCED_CLASS(cls.elements, cls.components, equations,
initialEquations, algorithms, initialAlgorithms);
then INSTANCED_CLASS(cls.elements, cls.extendsNodes, cls.components,
equations, initialEquations, algorithms, initialAlgorithms);
end match;
end setSections;

Expand Down
14 changes: 10 additions & 4 deletions Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -782,7 +782,7 @@ function instClass
input InstNode parent;
protected
Class c;
array<InstNode> components;
array<InstNode> components, ext_nodes;
Modifier type_mod, mod;
list<Modifier> type_mods, inst_type_mods;
Binding binding;
Expand All @@ -809,10 +809,11 @@ algorithm
par := if InstNode.isEmpty(parent) then node else parent;

// Instantiate the components.
components := instComponents(Class.components(c), par, node);
(components, ext_nodes) :=
instComponents(Class.components(c), Class.extendsNodes(c), par, node);

// Update the node with the new instance.
c := Class.instExpandedClass(components, c);
c := Class.instExpandedClass(components, ext_nodes, c);
node := InstNode.updateClass(c, node);
then
();
Expand Down Expand Up @@ -864,13 +865,17 @@ end instClass;

function instComponents
input array<InstNode> nodes;
input array<InstNode> extendsNodes;
input InstNode parent;
input InstNode scope;
output array<InstNode> instNodes;
output array<InstNode> instExtendsNodes;
protected
InstNode node, ext;
Integer ext_idx = 1;
algorithm
instNodes := arrayCopy(nodes);
instExtendsNodes := arrayCopy(extendsNodes);

for i in 1:arrayLength(nodes) loop
node := nodes[i];
Expand All @@ -881,7 +886,8 @@ algorithm
ext := Class.resolveExtendsRef(node, InstNode.getClass(scope));
ext := instClass(ext, Modifier.NOMOD(), InstNode.EMPTY_NODE());
instNodes[i] := ext;
//Class.updateExtends(node, ext, InstNode.getClass(scope));
instExtendsNodes[ext_idx] := ext;
ext_idx := ext_idx + 1;
end if;
end for;
end instComponents;
Expand Down

0 comments on commit 4ffbdb4

Please sign in to comment.