Skip to content

Commit

Permalink
[NF] Inner/outer fixes.
Browse files Browse the repository at this point in the history
- Fix lookup of inner components by instantiating the class tree of a
  derived class earlier, to make sure that the node inside the
  InstNodeType.BASE_CLASS() of the base class node points to the
  instance created by Inst.instClass and not the shared expanded node.
- Fix adding generated inner components when the class being
  instantiated is a short class definition.

Belonging to [master]:
  - OpenModelica/OMCompiler#2961
  - OpenModelica/OpenModelica-testsuite#1131
  • Loading branch information
perost authored and OpenModelica-Hudson committed Mar 4, 2019
1 parent b55fb1b commit ae2ddcb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Compiler/NFFrontEnd/NFClassTree.mo
Expand Up @@ -692,7 +692,7 @@ public
algorithm
node := InstNode.setNodeType(
InstNodeType.BASE_CLASS(clsNode, InstNode.definition(node)), node);
(node, _, classCount, compCount) := instantiate(node);
(node, instance, classCount, compCount) := instantiate(node, instance, scope);
cls.baseClass := node;
then
();
Expand Down
25 changes: 16 additions & 9 deletions Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -743,7 +743,14 @@ algorithm
() := match cls
case Class.EXPANDED_CLASS(restriction = res)
algorithm
(node, par) := ClassTree.instantiate(node, parent);
// Skip instantiating the class tree if the class is a base class,
// it has (hopefully) already been instantiated in that case.
if InstNode.isBaseClass(node) then
par := parent;
else
(node, par) := ClassTree.instantiate(node, parent);
end if;

updateComponentType(parent, node);
attributes := updateClassConnectorType(res, attributes);
inst_cls as Class.EXPANDED_CLASS(elements = cls_tree) := InstNode.getClass(node);
Expand Down Expand Up @@ -786,7 +793,8 @@ algorithm

case Class.EXPANDED_DERIVED()
algorithm
node := InstNode.replaceClass(cls, node);
(node, par) := ClassTree.instantiate(node, parent);
Class.EXPANDED_DERIVED(baseClass = base_node) := InstNode.getClass(node);

// Merge outer modifiers and attributes.
mod := Modifier.fromElement(InstNode.definition(node), {node}, InstNode.parent(node));
Expand All @@ -795,12 +803,8 @@ algorithm
attrs := updateClassConnectorType(cls.restriction, cls.attributes);
attributes := mergeDerivedAttributes(attrs, attributes, parent);

// Mark the base class node as a base class.
base_node := InstNode.setNodeType(
InstNodeType.BASE_CLASS(node, InstNode.definition(cls.baseClass)), cls.baseClass);

// Instantiate the base class and update the nodes.
(base_node, attributes) := instClass(base_node, mod, attributes, useBinding, parent);
(base_node, attributes) := instClass(base_node, mod, attributes, useBinding, par);
cls.baseClass := base_node;
cls.attributes := attributes;
cls.dims := arrayCopy(cls.dims);
Expand Down Expand Up @@ -842,6 +846,7 @@ algorithm
case Class.INSTANCED_CLASS()
algorithm
node := InstNode.replaceClass(Class.NOT_INSTANTIATED(), node);
node := InstNode.setNodeType(InstNodeType.NORMAL_CLASS(), node);
node := expand(node);
node := instClass(node, outerMod, attributes, useBinding, parent);
updateComponentType(parent, node);
Expand Down Expand Up @@ -2983,6 +2988,7 @@ protected
String name, str;
Class cls;
ClassTree cls_tree;
InstNode base_node;
algorithm
CachedData.TOP_SCOPE(addedInner = inner_tree) := InstNode.getInnerOuterCache(topScope);

Expand Down Expand Up @@ -3023,9 +3029,10 @@ algorithm

// If we found any components, add them to the component list of the class tree.
if not listEmpty(inner_comps) then
cls := InstNode.getClass(node);
base_node := Class.lastBaseClass(node);
cls := InstNode.getClass(base_node);
cls_tree := ClassTree.appendComponentsToInstTree(inner_comps, Class.classTree(cls));
InstNode.updateClass(Class.setClassTree(cls_tree, cls), node);
InstNode.updateClass(Class.setClassTree(cls_tree, cls), base_node);
end if;
end insertGeneratedInners;

Expand Down
10 changes: 10 additions & 0 deletions Compiler/NFFrontEnd/NFInstNode.mo
Expand Up @@ -362,6 +362,16 @@ uniontype InstNode
end match;
end isUserdefinedClass;

function isDerivedClass
input InstNode node;
output Boolean isDerived;
algorithm
isDerived := match node
case CLASS_NODE(nodeType = InstNodeType.DERIVED_CLASS()) then true;
else false;
end match;
end isDerivedClass;

function isFunction
input InstNode node;
output Boolean isFunc;
Expand Down

0 comments on commit ae2ddcb

Please sign in to comment.