@@ -47,6 +47,7 @@ encapsulated package ClassTree
4747 end CLASS ;
4848
4949 record COMPONENT
50+ Integer node;
5051 Integer index;
5152 end COMPONENT ;
5253 end Entry ;
@@ -89,7 +90,7 @@ uniontype Class
8990
9091 record EXPANDED_CLASS
9192 ClassTree . Tree elements;
92- list < InstNode > extendsNodes;
93+ array < InstNode > extendsNodes;
9394 array< InstNode > components;
9495 Modifier modifier;
9596 list< Equation > equations;
@@ -129,35 +130,30 @@ uniontype Class
129130 input ClassTree . Tree classes;
130131 output Class cls;
131132 algorithm
132- cls := EXPANDED_CLASS (classes, {} , listArray({}), Modifier . NOMOD (), {}, {}, {}, {});
133+ cls := EXPANDED_CLASS (classes, listArray({}) , listArray({}), Modifier . NOMOD (), {}, {}, {}, {});
133134 end initExpandedClass;
134135
135136 function instExpandedClass
136137 input array< InstNode > components;
137138 input Class expandedClass;
138139 output Class instancedClass;
139140 protected
140- list< Equation > eqs = {}, eqs1 = {}, eqs2 = {} ;
141- list< Equation > ieqs = {}, ieqs1 = {}, ieqs2 = {} ;
142- list< list< Statement >> algs = {}, algs1 = {}, algs2 = {} ;
143- list< list< Statement >> ialgs = {}, ialgs1 = {}, ialgs2 = {} ;
141+ list< Equation > eqs;
142+ list< Equation > ieqs;
143+ list< list< Statement >> algs;
144+ list< list< Statement >> ialgs;
144145 algorithm
145146 instancedClass := match expandedClass
146147 case EXPANDED_CLASS ()
147148 algorithm
148- eqs1 := expandedClass. equations;
149- ieqs1 := expandedClass. initialEquations;
150- algs1 := expandedClass. algorithms;
151- ialgs1 := expandedClass. initialAlgorithms;
152-
153- // append the sections from the inherited classes
154- for ext in expandedClass. extendsNodes loop
155- (eqs2, ieqs2, algs2, ialgs2) := collectInherited(ext, eqs2, ieqs2, algs2, ialgs2);
156- end for ;
157- eqs := listAppend(eqs2, eqs1);
158- ieqs := listAppend(ieqs2, ieqs1);
159- algs := listAppend(algs2, algs1);
160- ialgs := listAppend(ialgs2, ialgs1);
149+ eqs := expandedClass. equations;
150+ ieqs := expandedClass. initialEquations;
151+ algs := expandedClass. algorithms;
152+ ialgs := expandedClass. initialAlgorithms;
153+
154+ // ***TODO***: Sections should *not* be appended here, they need to be
155+ // instantiated and typed in the correct scope. They should be
156+ // collected from the extends nodes when flattening the class.
161157 then
162158 INSTANCED_CLASS (expandedClass. elements, components, eqs, ieqs, algs, ialgs);
163159 end match;
@@ -251,6 +247,13 @@ uniontype Class
251247 end match;
252248 end setElements;
253249
250+ function extendsNodes
251+ input Class cls;
252+ output array< InstNode > extendsNodes;
253+ algorithm
254+ EXPANDED_CLASS (extendsNodes = extendsNodes) := cls;
255+ end extendsNodes;
256+
254257 function setSections
255258 input list< Equation > equations;
256259 input list< Equation > initialEquations;
@@ -283,12 +286,23 @@ uniontype Class
283286 end match;
284287
285288 element := ClassTree . get(scope, name);
289+ node := resolveElement(element, cls);
290+ end lookupElement;
286291
292+ function resolveElement
293+ input Class . Element element;
294+ input Class cls;
295+ output InstNode node;
296+ algorithm
287297 node := match element
288298 case Element . CLASS () then element. node;
289- case Element . COMPONENT () then arrayGet(components(cls), element. index);
299+ case Element . COMPONENT (node = 0 )
300+ then arrayGet(components(cls), element. index);
301+ case Element . COMPONENT ()
302+ then arrayGet(components(InstNode . getClass(
303+ arrayGet(extendsNodes(cls), element. node))), element. index);
290304 end match;
291- end lookupElement ;
305+ end resolveElement ;
292306
293307 function isBuiltin
294308 input Class cls;
@@ -352,22 +366,14 @@ uniontype Class
352366 local
353367 ClassTree . Tree tree;
354368
355- // case PARTIAL_CLASS()
356- // algorithm
357- // instance.classes := ClassTree.map(instance.classes, cloneEntry);
358- // then
359- // ();
360-
361369 case EXPANDED_CLASS ()
362370 algorithm
363- // instance.elements := ClassTree.map(instance.elements, cloneEntry);
364371 cls. components := Array . map(cls. components, InstNode . clone);
365372 then
366373 ();
367374
368375 case INSTANCED_CLASS ()
369376 algorithm
370- // instance.elements := ClassTree.map(instance.elements, cloneEntry);
371377 cls. components := Array . map(cls. components, InstNode . clone);
372378 then
373379 ();
@@ -386,6 +392,31 @@ uniontype Class
386392 else entry;
387393 end match;
388394 end cloneEntry;
395+
396+ function resolveExtendsRef
397+ input InstNode ref;
398+ input Class scope;
399+ output InstNode ext;
400+ algorithm
401+ ext := match (ref, scope)
402+ case (InstNode . REF_NODE (), EXPANDED_CLASS ())
403+ then arrayGet(scope. extendsNodes, ref. index);
404+ end match;
405+ end resolveExtendsRef;
406+
407+ function updateExtends
408+ input InstNode ref;
409+ input InstNode ext;
410+ input output Class scope;
411+ algorithm
412+ () := match (ref, scope)
413+ case (InstNode . REF_NODE (), EXPANDED_CLASS ())
414+ algorithm
415+ arrayUpdate(scope. extendsNodes, ref. index, ext);
416+ then
417+ ();
418+ end match;
419+ end updateExtends;
389420end Class ;
390421
391422annotation(__OpenModelica_Interface= "frontend" );
0 commit comments