@@ -98,7 +98,10 @@ algorithm
9898
9999 // Update the instantiated class inside the top component.
100100 top_comp := Component . setClassInstance(cls, top_comp);
101- top_comp_node := ComponentNode . replaceComponent(top_comp, top_comp_node);
101+ // Then update the component inside the top component node, which makes sure
102+ // that this change is propagated to any component which uses this node as
103+ // their parent (since the component in the node is inside an array).
104+ top_comp_node := ComponentNode . updateComponent(top_comp, top_comp_node);
102105
103106 cls := Typing . typeClass(cls, top_comp_node);
104107 dae := NFFlatten . flattenClass(cls);
@@ -362,9 +365,9 @@ algorithm
362365 // Add component ID:s to the scope.
363366 idx := 1 ;
364367 for c in components loop
365- // // TODO: Handle components with the same name.
366- // // TODO: If duplicate components should be handled here, also
367- // // remove them from the list of components.
368+ // TODO: Handle components with the same name.
369+ // TODO: If duplicate components should be handled here, also
370+ // remove them from the list of components.
368371 scope := ClassTree . add(scope, ComponentNode . name(c),
369372 ClassTree . Entry . COMPONENT (idx), ClassTree . addConflictReplace);
370373
@@ -384,7 +387,7 @@ algorithm
384387
385388 else
386389 algorithm
387- Error . addInternalError( "NFInst.expandClass2 got unknown class." , Absyn . dummyInfo );
390+ assert ( false , getInstanceName() + " got unknown class" );
388391 then
389392 fail();
390393
@@ -464,7 +467,7 @@ algorithm
464467
465468 else
466469 algorithm
467- Error . addInternalError( "NFInst.expandExtends got unknown element!" , Absyn . dummyInfo );
470+ assert ( false , getInstanceName() + " got unknown element" );
468471 then
469472 fail();
470473
@@ -585,6 +588,8 @@ algorithm
585588
586589 end match;
587590 end for ;
591+
592+ instance. elements := elements;
588593 then
589594 ();
590595
@@ -618,8 +623,7 @@ algorithm
618623 // Any other component shouldn't show up here.
619624 else
620625 algorithm
621- Error . addInternalError("NFInst.addInheritedComponentRefs got unknown component." ,
622- ComponentNode . info(cn));
626+ assert (false , getInstanceName() + " got unknown component." );
623627 then
624628 fail();
625629 end match;
@@ -659,32 +663,30 @@ function instClass
659663 input Modifier modifier;
660664 input ComponentNode parent;
661665protected
662- Instance i, i_mod ;
666+ Instance i;
663667 array< ComponentNode > components;
664- ClassTree . Tree scope;
665668 Modifier type_mod, mod;
666669 list< Modifier > type_mods, inst_type_mods;
667670 Binding binding;
668671 InstNode n, cur_scope;
669672 list< ComponentNode > ext_nodes;
670- Component c ;
673+ String name ;
671674algorithm
672- i := InstNode . instance(node);
673-
674- () := match i
675+ () := match InstNode . instance(node)
675676 // A normal class.
676- case Instance . EXPANDED_CLASS (elements = scope )
677+ case Instance . EXPANDED_CLASS ()
677678 algorithm
678679 // Clone the instance node, since each component needs a unique instance.
679680 node := InstNode . clone(node);
681+ i := InstNode . instance(node);
682+ Instance . EXPANDED_CLASS (modifier = mod, extendsNodes = ext_nodes) := i;
680683
681684 // Apply the modifier to the instance.
682- mod := Modifier . merge(modifier, i . modifier );
683- i_mod := applyModifier(modifier, i,
685+ mod := Modifier . merge(modifier, mod );
686+ i := applyModifier(modifier, i,
684687 ModifierScope . CLASS_SCOPE (InstNode . name(node)));
685688
686689 // Instantiate all the extends nodes first.
687- Instance . EXPANDED_CLASS (extendsNodes = ext_nodes) := i_mod;
688690 for ext in ext_nodes loop
689691 Component . EXTENDS_NODE (node = n) := ComponentNode . component(ext);
690692 // No modifier, the modifier on the extends clause has already been
@@ -694,25 +696,28 @@ algorithm
694696
695697 // Instantiate all local components. This will skip inherited
696698 // components, since those have already been instantiated.
697- components := Array . map(Instance . components(i_mod ),
699+ components := Array . map(Instance . components(i ),
698700 function instComponent(parent = parent, scope = node));
699701
700702 // Update the instance node with the new instance.
701- i_mod := Instance . INSTANCED_CLASS (scope, components,
702- i. equations, i. initialEquations, i. algorithms, i. initialAlgorithms);
703- node := InstNode . setInstance(i_mod, node);
703+ i := Instance . instExpandedClass(components, i);
704+ node := InstNode . setInstance(i, node);
704705 then
705706 ();
706707
707708 // A builtin type.
708709 case Instance . PARTIAL_BUILTIN ()
709710 algorithm
711+ // Clone the instance node, since each component needs a unique instance.
710712 node := InstNode . clone(node);
711- inst_type_mods := {};
713+ i := InstNode . instance(node);
714+ Instance . PARTIAL_BUILTIN (name = name, modifier = mod) := i;
715+
712716 // Merge any outer modifiers on the class with the class' own modifier.
713- type_mod := Modifier . merge(modifier, i . modifier );
717+ type_mod := Modifier . merge(modifier, mod );
714718
715719 // If the modifier isn't empty, instantiate it.
720+ inst_type_mods := {};
716721 if not Modifier . isEmpty(type_mod) then
717722 type_mods := Modifier . toList(type_mod);
718723 cur_scope := InstNode . parentScope(node);
@@ -734,8 +739,8 @@ algorithm
734739 end for ;
735740 end if ;
736741
737- i_mod := Instance . INSTANCED_BUILTIN (i . name, inst_type_mods);
738- node := InstNode . setInstance(i_mod , node);
742+ i := Instance . INSTANCED_BUILTIN (name, inst_type_mods);
743+ node := InstNode . setInstance(i , node);
739744 then
740745 ();
741746
@@ -772,7 +777,6 @@ algorithm
772777 case Component . COMPONENT_DEF (definition = comp as SCode . COMPONENT ())
773778 algorithm
774779 name := ComponentNode . name(node);
775- node := ComponentNode . clone(node);
776780 node := ComponentNode . setOrphanParent(parent, node);
777781
778782 // Merge the modifier from the component.
@@ -1140,8 +1144,7 @@ algorithm
11401144
11411145 else
11421146 algorithm
1143- Error . addInternalError("NFInst.instEEquation: Unknown equation" ,
1144- SCode . getEEquationInfo(scodeEq));
1147+ assert (false , getInstanceName() + " got unknown equation" );
11451148 then
11461149 fail();
11471150
@@ -1269,8 +1272,7 @@ algorithm
12691272
12701273 else
12711274 algorithm
1272- Error . addInternalError("NFInst.instStatement: Unknown statement" ,
1273- SCode . getStatementInfo(scodeStmt));
1275+ assert (false , getInstanceName() + " got unknown statement" );
12741276 then
12751277 fail();
12761278
0 commit comments