From b4635bbb1a9d24219fa9c1d4a1d8d56c1bc38c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Tue, 27 Mar 2018 13:29:34 +0200 Subject: [PATCH] [NF] More derived scope fixes. Belonging to [master]: - OpenModelica/OMCompiler#2322 - OpenModelica/OpenModelica-testsuite#902 --- Compiler/NFFrontEnd/NFComponent.mo | 2 +- Compiler/NFFrontEnd/NFInst.mo | 5 +++-- Compiler/NFFrontEnd/NFInstNode.mo | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Compiler/NFFrontEnd/NFComponent.mo b/Compiler/NFFrontEnd/NFComponent.mo index 620972fc423..5a773c6ba21 100644 --- a/Compiler/NFFrontEnd/NFComponent.mo +++ b/Compiler/NFFrontEnd/NFComponent.mo @@ -605,7 +605,7 @@ uniontype Component function isConnector input Component component; output Boolean isConnector = - Class.isConnectorClass(InstNode.getClass(classInstance(component))); + Class.isConnectorClass(InstNode.getDerivedClass(classInstance(component))); end isConnector; function isIdentical diff --git a/Compiler/NFFrontEnd/NFInst.mo b/Compiler/NFFrontEnd/NFInst.mo index bf09d1c94ac..289d3ea84dd 100644 --- a/Compiler/NFFrontEnd/NFInst.mo +++ b/Compiler/NFFrontEnd/NFInst.mo @@ -750,6 +750,8 @@ algorithm case Class.DERIVED_CLASS() algorithm node := InstNode.replaceClass(cls, node); + updateComponentType(parent, node); + // Merge outer modifiers and attributes. mod := Modifier.fromElement(InstNode.definition(node), InstNode.level(parent), InstNode.parent(node)); mod := Modifier.merge(outerMod, mod); @@ -760,14 +762,13 @@ algorithm 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); + (base_node, attributes) := instClass(base_node, mod, attributes, parent); cls.baseClass := base_node; cls.attributes := attributes; // Update the dimensions and the parent's type with the new class instance. cls.dims := list(Dimension.setScope(dim, node) for dim in cls.dims); node := InstNode.updateClass(cls, node); - updateComponentType(parent, node); then (); diff --git a/Compiler/NFFrontEnd/NFInstNode.mo b/Compiler/NFFrontEnd/NFInstNode.mo index 845d9f4968d..92dd4735082 100644 --- a/Compiler/NFFrontEnd/NFInstNode.mo +++ b/Compiler/NFFrontEnd/NFInstNode.mo @@ -537,6 +537,20 @@ uniontype InstNode end match; end getClass; + function getDerivedClass + input InstNode node; + output Class cls; + algorithm + cls := match node + local + InstNode parent; + + case CLASS_NODE(nodeType = InstNodeType.BASE_CLASS(parent = parent)) then getDerivedClass(parent); + case CLASS_NODE() then Pointer.access(node.cls); + case COMPONENT_NODE() then getDerivedClass(Component.classInstance(Pointer.access(node.component))); + end match; + end getDerivedClass; + function updateClass input Class cls; input output InstNode node;