@@ -48,6 +48,7 @@ import NFInstance.ClassTree;
4848import NFInstance.Instance ;
4949import NFInstanceTree.InstanceTree ;
5050import NFInstNode.InstNode ;
51+ import NFInstNode.InstParent ;
5152import NFMod.Modifier ;
5253import NFMod.ModifierScope ;
5354import NFEquation.Equation ;
@@ -76,7 +77,7 @@ algorithm
7677 inst_tree := makeTree(program);
7778
7879 (cls, inst_tree) := Lookup . lookupClassName(classPath, inst_tree, Absyn . dummyInfo);
79- (cls, inst_tree) := instantiate(cls, Modifier . NOMOD (), inst_tree);
80+ (cls, inst_tree) := instantiate(cls, Modifier . NOMOD (), InstParent . NO_PARENT (), inst_tree);
8081
8182 // TODO: Why is this a separate phase? Could be done in instComponent?
8283 (cls, inst_tree) := instBindings(cls, inst_tree);
@@ -92,19 +93,21 @@ end instClassInProgram;
9293function instantiate
9394 input output InstNode node;
9495 input Modifier modifier;
96+ input InstParent parent;
9597 input output InstanceTree tree;
9698algorithm
9799 (node, tree) := partialInstClass(node, tree);
98- (node, tree) := expandClass(node, tree);
100+ (node, tree) := expandClass(node, parent, tree);
99101 (node, tree) := instClass(node, modifier, tree);
100102end instantiate;
101103
102104function expand
103105 input output InstNode node;
106+ input InstParent parent;
104107 input output InstanceTree tree;
105108algorithm
106109 (node, tree) := partialInstClass(node, tree);
107- (node, tree) := expandClass(node, tree);
110+ (node, tree) := expandClass(node, parent, tree);
108111end expand;
109112
110113function makeTree
@@ -148,7 +151,7 @@ algorithm
148151 case SCode . CLASS ()
149152 algorithm
150153 idx := idx + 1 ;
151- node := InstNode . new(e. name, e, idx, scope_id);
154+ node := InstNode . new(e. name, e, idx, scope_id, InstParent . NO_PARENT () );
152155 il := node :: il;
153156 scope := addElementIdToScope(e. name, ClassTree . Entry . CLASS (idx), e. info, scope);
154157 then
@@ -236,7 +239,7 @@ algorithm
236239 end match;
237240 end for ;
238241
239- tree := InstanceTree . setCurrentScope (tree, scope_idx);
242+ tree := InstanceTree . setCurrentScopeIndex (tree, scope_idx);
240243end addImportsToScope;
241244
242245function partialInstClass
@@ -250,7 +253,7 @@ algorithm
250253
251254 case InstNode . INST_NODE (instance = Instance . NOT_INSTANTIATED (), definition = SOME (def))
252255 algorithm
253- tree := InstanceTree . setCurrentScope(tree, InstNode . index( node) );
256+ tree := InstanceTree . setCurrentScope(tree, node);
254257 (instance, tree) := partialInstClass2(def, tree);
255258 node. instance := instance;
256259 tree := InstanceTree . updateNode(node, tree);
@@ -283,6 +286,7 @@ end partialInstClass2;
283286
284287function expandClass
285288 input output InstNode node;
289+ input InstParent parent;
286290 input output InstanceTree tree;
287291algorithm
288292 _ := match node
@@ -291,19 +295,20 @@ algorithm
291295
292296 case InstNode . INST_NODE (instance = Instance . PARTIAL_CLASS (), definition = SOME (def))
293297 algorithm
294- (node, tree) := expandClass2(node, def, tree);
298+ (node, tree) := expandClass2(node, def, parent, tree);
295299 then
296300 ();
297301
298302 else ();
299303 end match;
300304
301- tree := InstanceTree . setCurrentScope(tree, InstNode . index( node) );
305+ tree := InstanceTree . setCurrentScope(tree, node);
302306end expandClass;
303307
304308function expandClass2
305309 input InstNode node;
306310 input SCode . Element definition;
311+ input InstParent parent;
307312 output InstNode expandedNode = node;
308313 input output InstanceTree tree;
309314algorithm
@@ -333,7 +338,7 @@ algorithm
333338 def. classDef := SCode . PARTS ({ext}, {}, {}, {}, {}, {}, {}, NONE ());
334339 i := Instance . PARTIAL_CLASS (ClassTree . new(), {ext});
335340 inode := InstNode . setInstance(node, i);
336- (expandedNode, tree) := expandClass2(inode, def, tree);
341+ (expandedNode, tree) := expandClass2(inode, def, parent, tree);
337342 then
338343 ();
339344// case SCode.CLASS(classDef = SCode.DERIVED(typeSpec = ty, modifications = der_mod))
@@ -344,7 +349,7 @@ algorithm
344349//
345350// // Derived classes have no scope of their own, use the parent scope.
346351// scope_id := InstNode.parent(expandedNode);
347- // tree := InstanceTree.setCurrentScope (tree, scope_id);
352+ // tree := InstanceTree.setCurrentScopeIndex (tree, scope_id);
348353//
349354// // Lookup and expand the derived class.
350355// Absyn.TPATH(path = ty_path) := ty;
@@ -372,13 +377,14 @@ algorithm
372377 algorithm
373378 Instance . PARTIAL_CLASS (classes = scope, elements = elements) :=
374379 InstNode . instance(expandedNode);
375- tree := InstanceTree . setCurrentScope(tree, InstNode . index( expandedNode) );
380+ tree := InstanceTree . setCurrentScope(tree, expandedNode);
376381 i := Instance . initExpandedClass(scope);
377382 expandedNode := InstNode . setInstance(expandedNode, i);
378383 tree := InstanceTree . updateNode(expandedNode, tree);
379384
380385 // Expand all extends clauses.
381- (components, scope, tree) := expandExtends(elements, definition. name, scope, tree);
386+ (components, scope, tree) := expandExtends(elements, definition. name,
387+ scope, parent, tree);
382388
383389 // Add component ids to the scope.
384390 idx := 1 ;
@@ -402,6 +408,7 @@ algorithm
402408
403409 // Update the instance in the tree.
404410 expandedNode := InstNode . setInstance(expandedNode, i);
411+ expandedNode := InstNode . setInstParent(expandedNode, parent);
405412 tree := InstanceTree . updateNode(expandedNode, tree);
406413 then
407414 ();
@@ -421,6 +428,7 @@ function expandExtends
421428 input String className;
422429 output list< Component > components = {};
423430 input output ClassTree . Tree scope;
431+ input InstParent parent;
424432 input output InstanceTree tree;
425433protected
426434 InstNode ext_node;
@@ -440,7 +448,7 @@ algorithm
440448 ext_node := InstNode . setIndex(ext_node, InstanceTree . instanceCount(tree) + 1 );
441449 ext_node := InstNode . rename(ext_node, className);
442450 tree := InstanceTree . addInstances({ext_node}, tree);
443- (ext_node, tree) := expand(ext_node, tree);
451+ (ext_node, tree) := expand(ext_node, parent, tree);
444452
445453 // Initialize the modifier from the extends clause.
446454 mod_scope := ModifierScope . EXTENDS_SCOPE (e. baseClassPath);
@@ -597,7 +605,7 @@ algorithm
597605 case InstNode . INST_NODE (instance = i as Instance . EXPANDED_CLASS (elements = scope))
598606 algorithm
599607 comp_count := arrayLength(i. components);
600- tree := InstanceTree . setCurrentScope(tree, InstNode . index( node) );
608+ tree := InstanceTree . setCurrentScope(tree, node);
601609
602610 if comp_count > 0 then
603611 components := Dangerous . arrayCreateNoInit(comp_count,
@@ -679,17 +687,18 @@ algorithm
679687 case Component . COMPONENT_DEF (definition = comp as SCode . COMPONENT ())
680688 algorithm
681689 scope := InstanceTree . currentScopeIndex(tree);
682- tree := InstanceTree . setCurrentScope (tree, component. scope);
690+ tree := InstanceTree . setCurrentScopeIndex (tree, component. scope);
683691 comp_mod := Modifier . create(comp. modifications, comp. name,
684692 ModifierScope . COMPONENT_SCOPE (comp. name), component. scope);
685693 comp_mod := Modifier . merge(component. modifier, comp_mod);
686694 comp_mod := Modifier . propagate(comp_mod, listLength(comp. attributes. arrayDims));
687- (cls, tree) := instTypeSpec(comp. typeSpec, comp_mod, comp. info, tree);
695+ (cls, tree) := instTypeSpec(comp. typeSpec, comp_mod,
696+ InstParent . COMPONENT (component), comp. info, tree);
688697 (dims, tree) := instDimensions(comp. attributes. arrayDims, tree);
689698 Modifier . checkEach(comp_mod, listEmpty(dims), comp. name);
690699 attr := instComponentAttributes(comp. attributes, comp. prefixes);
691700 binding := Modifier . binding(comp_mod);
692- tree := InstanceTree . setCurrentScope (tree, scope);
701+ tree := InstanceTree . setCurrentScopeIndex (tree, scope);
693702 then
694703 (Component . UNTYPED_COMPONENT (comp. name, cls, listArray(dims), binding, attr, comp. info), tree);
695704
@@ -724,6 +733,7 @@ end instComponentAttributes;
724733function instTypeSpec
725734 input Absyn . TypeSpec typeSpec;
726735 input Modifier modifier;
736+ input InstParent parent;
727737 input SourceInfo info;
728738 output InstNode node;
729739 input output InstanceTree tree;
@@ -732,7 +742,7 @@ algorithm
732742 case Absyn . TPATH ()
733743 algorithm
734744 (node, tree) := Lookup . lookupClassName(typeSpec. path, tree, info);
735- (node, tree) := instantiate(node, modifier, tree);
745+ (node, tree) := instantiate(node, modifier, parent, tree);
736746 then
737747 (node, tree);
738748
0 commit comments