Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 0.0% 0 / 0 / 120
Functions: -% 0 / 1 / 1
Branches: 0.0% 0 / 0 / 156

OMCompiler/Compiler/FFrontEnd/FResolve.mo
Line Branch Exec Source
1 /*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36 encapsulated package FResolve
37 " file: FResolve.mo
38 package: FResolve
39 description: Resolving of types paths, component references, class extends
40
41
42 "
43
44 // public imports
45 public
46 import Absyn;
47 import AbsynUtil;
48 import FCore;
49 import FNode;
50 import FLookup;
51
52 protected
53 import SCode;
54 import SCodeUtil;
55 import FGraphBuild;
56 import List;
57 import ClassInf;
58 import ClassInfUtil;
59
60 public
61 type Name = FCore.Name;
62 type Id = FCore.Id;
63 type Seq = FCore.Seq;
64 type Next = FCore.Next;
65 type Node = FCore.Node;
66 type Data = FCore.Data;
67 type Kind = FCore.Kind;
68 type Ref = FCore.Ref;
69 type Refs = FCore.Refs;
70 type Children = FCore.Children;
71 type Parents = FCore.Parents;
72 type ImportTable = FCore.ImportTable;
73 type Extra = FCore.Extra;
74 type Visited = FCore.Visited;
75 type Import = FCore.Import;
76 type Graph = FCore.Graph;
77
78 type Msg = Option<SourceInfo>;
79
80 public function ext
81 "@author: adrpo
82 for all extends nodes lookup the type and add $ref nodes to the result"
83 input Ref inRef;
84 input Graph ig;
85 output Graph og;
86 algorithm
87 og := match ig
88 local
89 Graph g;
90
91 case g
92 algorithm
93 // apply on all extends nodes
94 ✗ g := FNode.apply1(inRef, ext_one, g);
95 then
96 g;
97
98 end match;
99 end ext;
100
101 public function ext_one
102 "@author: adrpo
103 helper"
104 input Name name;
105 input Ref inRef;
106 input Graph ig;
107 output Graph og;
108 algorithm
109 og := matchcontinue(inRef, ig)
110 local
111 Ref r, rr;
112 Absyn.Path p;
113 SCode.Element e;
114 Graph g;
115
116 // found extends that has a ref node
117 case (r, g)
118 algorithm
119 ✗ true := FNode.isRefExtends(r);
120 ✗ false := FNode.isRefDerived(r);
121 // it does have a reference child already!
122 ✗ true := FNode.isRefRefResolved(r);
123 ✗ then
124 g;
125
126 // found extends
127 case (r, g)
128 algorithm
129 ✗ true := FNode.isRefExtends(r);
130 ✗ false := FNode.isRefDerived(r);
131 ✗ FCore.EX(e = e) := FNode.refData(r);
132 ✗ p := SCodeUtil.getBaseClassPath(e);
133 ✗ (g, rr) := FLookup.name(g, r, p, FLookup.ignoreNothing, FLookup.dummyLookupOption);
134 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {rr}, r, g);
135 then
136 g;
137
138 // not found ref
139 case (r, g)
140 algorithm
141 ✗ true := FNode.isRefExtends(r);
142 ✗ false := FNode.isRefDerived(r);
143 ✗ FCore.EX(e = e) := FNode.refData(r);
144 ✗ p := SCodeUtil.getBaseClassPath(e);
145 ✗ failure(FLookup.name(g, r, p, FLookup.ignoreNothing, FLookup.dummyLookupOption));
146 ✗ print("FResolve.ext_one: baseclass: " + AbsynUtil.pathString(p) +
147 " not found in: " + FNode.toPathStr(FNode.fromRef(r)) +"!\n");
148 // put it in the graph as unresolved ref
149 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {}, r, g);
150 then
151 g;
152
153 else ig;
154
155 end matchcontinue;
156 end ext_one;
157
158 public function derived
159 "@author: adrpo
160 for all derived nodes lookup the type and add $ref nodes to the result"
161 input Ref inRef;
162 input Graph ig;
163 output Graph og;
164 algorithm
165 og := match ig
166 local
167 Graph g;
168
169 case g
170 algorithm
171 // apply on all derived nodes
172 ✗ g := FNode.apply1(inRef, derived_one, g);
173 then
174 g;
175
176 end match;
177 end derived;
178
179 public function derived_one
180 "@author: adrpo
181 helper"
182 input Name name;
183 input Ref inRef;
184 input Graph ig;
185 output Graph og;
186 algorithm
187 og := matchcontinue(inRef, ig)
188 local
189 Ref r, rr;
190 Absyn.Path p;
191 Graph g;
192
193 // found derived that has a ref node
194 case (r, g)
195 algorithm
196 ✗ true := FNode.isRefDerived(r);
197 // it does have a reference child already!
198 ✗ true := FNode.isRefRefResolved(r);
199 ✗ then
200 g;
201
202 // found derived
203 case (r, g)
204 algorithm
205 ✗ true := FNode.isRefDerived(r);
206 ✗ FCore.CL(e = SCode.CLASS(classDef = SCode.DERIVED(typeSpec = Absyn.TPATH(p, _)))) := FNode.refData(r);
207 ✗ (g, rr) := FLookup.name(g, r, p, FLookup.ignoreNothing, FLookup.dummyLookupOption);
208 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {rr}, r, g);
209 then
210 g;
211
212 // not found ref
213 case (r, g)
214 algorithm
215 ✗ true := FNode.isRefDerived(r);
216 ✗ FCore.CL(e = SCode.CLASS(classDef = SCode.DERIVED(typeSpec = Absyn.TPATH(p, _)))) := FNode.refData(r);
217 ✗ failure(FLookup.name(g, r, p, FLookup.ignoreNothing, FLookup.dummyLookupOption));
218 ✗ print("FResolve.derived_one: baseclass: " + AbsynUtil.pathString(p) +
219 " not found in: " + FNode.toPathStr(FNode.fromRef(r)) +"!\n");
220 // put it in the graph as unresolved ref
221 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {}, r, g);
222 then
223 g;
224
225 else ig;
226
227 end matchcontinue;
228 end derived_one;
229
230 public function ty
231 "@author: adrpo
232 for all component nodes lookup the type and add $ref nodes to the result"
233 input Ref inRef;
234 input Graph ig;
235 output Graph og;
236 algorithm
237 og := match ig
238 local
239 Graph g;
240
241 case g
242 algorithm
243 // apply to all component nodes
244 ✗ g := FNode.apply1(inRef, ty_one, g);
245 then
246 g;
247
248 end match;
249 end ty;
250
251 public function ty_one
252 "@author: adrpo
253 helper"
254 input Name name;
255 input Ref inRef;
256 input Graph ig;
257 output Graph og;
258 algorithm
259 og := matchcontinue(inRef, ig)
260 local
261 Ref r, rr;
262 Absyn.Path p;
263 SCode.Element e;
264 Graph g;
265
266 // found component that has a ref node
267 case (r, g)
268 algorithm
269 ✗ true := FNode.isRefComponent(r);
270 // it does have a reference child already!
271 ✗ true := FNode.isRefRefResolved(r);
272 ✗ then
273 g;
274
275 // found component
276 case (r, g)
277 algorithm
278 ✗ true := FNode.isRefComponent(r);
279 ✗ FCore.CO(e = e) := FNode.refData(r);
280 ✗ p := SCodeUtil.getElementTypePath(e);
281 ✗ (g, rr) := FLookup.name(g, r, p, FLookup.ignoreNothing, FLookup.dummyLookupOption);
282 // print("Resolving ty: " + AbsynUtil.pathString(p) + " -> " + FNode.toStr(FNode.fromRef(rr)) + "\n");
283 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {rr}, r, g);
284 then
285 g;
286
287 // not found ref
288 case (r, g)
289 algorithm
290 ✗ true := FNode.isRefComponent(r);
291 ✗ FCore.CO(e = e) := FNode.refData(r);
292 ✗ p := SCodeUtil.getElementTypePath(e);
293 ✗ failure(FLookup.name(g, r, p, FLookup.ignoreNothing, FLookup.dummyLookupOption));
294 ✗ print("FResolve.ty_one: component type path: " + AbsynUtil.pathString(p) +
295 " not found in: " + FNode.toPathStr(FNode.fromRef(r)) +"!\n");
296 // put it in the graph as unresolved ref
297 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {}, r, g);
298 then
299 g;
300
301 else ig;
302
303 end matchcontinue;
304 end ty_one;
305
306 public function cc
307 "@author: adrpo
308 for all constrained class nodes lookup the type and add $ref nodes to the result"
309 input Ref inRef;
310 input Graph ig;
311 output Graph og;
312 algorithm
313 og := match ig
314 local
315 Graph g;
316
317 case g
318 algorithm
319 // apply on all constraintby nodes
320 ✗ g := FNode.apply1(inRef, cc_one, g);
321 then
322 g;
323
324 end match;
325 end cc;
326
327 public function cc_one
328 "@author: adrpo
329 helper"
330 input Name name;
331 input Ref inRef;
332 input Graph ig;
333 output Graph og;
334 algorithm
335 og := matchcontinue(inRef, ig)
336 local
337 Ref r, rr;
338 Absyn.Path p;
339 Graph g;
340
341 // found constraint class that has a ref node
342 case (r, g)
343 algorithm
344 ✗ true := FNode.isRefConstrainClass(r);
345 // it does have a reference child already!
346 ✗ true := FNode.isRefRefResolved(r);
347 ✗ then
348 g;
349
350 // found constraint class
351 case (r, g)
352 algorithm
353 ✗ true := FNode.isRefConstrainClass(r);
354 ✗ FCore.CC(SCode.CONSTRAINCLASS(constrainingClass = p)) := FNode.refData(r);
355 ✗ (g, rr) := FLookup.name(g, r, p, FLookup.ignoreNothing, FLookup.dummyLookupOption);
356 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {rr}, r, g);
357 then
358 g;
359
360 // not found ref
361 case (r, g)
362 algorithm
363 ✗ true := FNode.isRefConstrainClass(r);
364 ✗ FCore.CC(SCode.CONSTRAINCLASS(constrainingClass = p)) := FNode.refData(r);
365 ✗ failure(FLookup.name(g, r, p, FLookup.ignoreNothing, FLookup.dummyLookupOption));
366 ✗ print("FResolve.cc_one: constrained class: " + AbsynUtil.pathString(p) +
367 " not found in: " + FNode.toPathStr(FNode.fromRef(r)) +"!\n");
368 // put it in the graph as unresolved ref
369 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {}, r, g);
370 then
371 g;
372
373 else ig;
374
375 end matchcontinue;
376 end cc_one;
377
378 public function clsext
379 "@author: adrpo
380 for all class extends nodes lookup the base class and add $ref nodes to the result"
381 input Ref inRef;
382 input Graph ig;
383 output Graph og;
384 algorithm
385 og := match ig
386 local
387 Graph g;
388
389 case g
390 algorithm
391 // apply on all class extends nodes
392 ✗ g := FNode.apply1(inRef, clsext_one, g);
393 then
394 g;
395
396 end match;
397 end clsext;
398
399 public function clsext_one
400 "@author: adrpo
401 helper"
402 input Name name;
403 input Ref inRef;
404 input Graph ig;
405 output Graph og;
406 algorithm
407 og := matchcontinue(inRef, ig)
408 local
409 Ref r, rr, p;
410 SCode.Element e;
411 Name id;
412 Graph g;
413
414 // found class extends that has a ref node
415 case (r, g)
416 algorithm
417 ✗ true := FNode.isRefClassExtends(r);
418 // it does have a reference child already!
419 ✗ true := FNode.isRefRefResolved(r);
420 ✗ then
421 g;
422
423 // found class extends
424 case (r, g)
425 algorithm
426 ✗ true := FNode.isRefClassExtends(r);
427 ✗ FCore.CL(e = SCode.CLASS(name = id)) := FNode.refData(r);
428 // get the parent where the extends are!
429 ✗ p := FNode.contextualParent(FNode.fromRef(r));
430 // search ONLY in extends!
431 ✗ (g, rr) := FLookup.ext(g, p, id, FLookup.ignoreParentsAndImports, FLookup.dummyLookupOption);
432 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {rr}, r, g);
433 then
434 g;
435
436 // not found ref
437 case (r, g)
438 algorithm
439 ✗ true := FNode.isRefClassExtends(r);
440 ✗ FCore.CL(e = SCode.CLASS(name = id)) := FNode.refData(r);
441 // get the parent where the extends are!
442 ✗ p := FNode.contextualParent(FNode.fromRef(r));
443 // search ONLY in extends!
444 ✗ failure(FLookup.ext(g, p, id, FLookup.ignoreParentsAndImports, FLookup.dummyLookupOption));
445 ✗ print("FResolve.clsext_one: class extends: " + id + " scope: " + FNode.toPathStr(FNode.fromRef(r)) +
446 " not found in extends of: " + FNode.toPathStr(FNode.fromRef(p)) + ":\n");
447 ✗ print("\t" + stringDelimitList(List.map(List.map(FNode.extendsRefs(p), FNode.fromRef), FNode.toPathStr), "\n\t") + "\n");
448 // put it in the graph as unresolved ref
449 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {}, r, g);
450 then
451 g;
452
453 else ig;
454
455 end matchcontinue;
456 end clsext_one;
457
458 public function cr
459 "@author: adrpo
460 for all crefs lookup the cref node and add $ref nodes to the result"
461 input Ref inRef;
462 input Graph ig;
463 output Graph og;
464 algorithm
465 og := match ig
466 local
467 Graph g;
468
469 case g
470 algorithm
471 // apply on all component reference nodes
472 ✗ g := FNode.apply1(inRef, cr_one, g);
473 then
474 g;
475
476 end match;
477 end cr;
478
479 public function cr_one
480 "@author: adrpo
481 helper"
482 input Name name;
483 input Ref inRef;
484 input Graph ig;
485 output Graph og;
486 algorithm
487 og := matchcontinue(inRef, ig)
488 local
489 Ref r, rr;
490 Absyn.ComponentRef cr;
491 Graph g;
492
493
494 // found cref that has a ref node
495 case (r, g)
496 algorithm
497 ✗ true := FNode.isRefCref(r);
498 // it does have a reference child already!
499 ✗ true := FNode.isRefRefResolved(r);
500 ✗ then
501 g;
502
503 // found cref
504 case (r, g)
505 algorithm
506 ✗ true := FNode.isRefCref(r);
507 ✗ FCore.CR(r = cr) := FNode.refData(r);
508 ✗ (g, rr) := FLookup.cr(g, r, cr, FLookup.ignoreNothing, FLookup.dummyLookupOption); // SOME(Absyn.dummyInfo));
509 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {rr}, r, g);
510 then
511 g;
512
513 // not found ref
514 case (r, g)
515 algorithm
516 ✗ true := FNode.isRefCref(r);
517 ✗ FCore.CR(r = cr) := FNode.refData(r);
518 ✗ failure(FLookup.cr(g, r, cr, FLookup.ignoreNothing, FLookup.dummyLookupOption));
519 ✗ print("FResolve.cr_one: component reference: " + AbsynUtil.crefString(cr) +
520 " not found in: " + FNode.toPathStr(FNode.fromRef(r)) +"!\n");
521 // put it in the graph as unresolved ref
522 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {}, r, g);
523 then
524 g;
525
526 else ig;
527
528 end matchcontinue;
529 end cr_one;
530
531 public function mod
532 "@author: adrpo
533 for all mods lookup the modifier node and add $ref nodes to the result"
534 input Ref inRef;
535 input Graph ig;
536 output Graph og;
537 algorithm
538 og := match ig
539 local
540 Graph g;
541
542 case g
543 algorithm
544 // apply on all modifier nodes
545 ✗ g := FNode.apply1(inRef, mod_one, g);
546 then
547 g;
548
549 end match;
550 end mod;
551
552 public function mod_one
553 "@author: adrpo
554 helper"
555 input Name name;
556 input Ref inRef;
557 input Graph ig;
558 output Graph og;
559 algorithm
560 og := matchcontinue(inRef, ig)
561 local
562 Ref r, rr;
563 Absyn.ComponentRef cr;
564 Graph g;
565
566 // found mod that has a ref node
567 case (r, g)
568 algorithm
569 ✗ true := FNode.isRefMod(r) and
570 (not FNode.isRefModHolder(r)) and
571 (not ClassInfUtil.isBasicTypeComponentName(FNode.refName(r)));
572 // it does have a reference child already!
573 ✗ true := FNode.isRefRefResolved(r);
574 ✗ then
575 g;
576
577 // found mod
578 case (r, g)
579 algorithm
580 ✗ true := FNode.isRefMod(r) and
581 (not FNode.isRefModHolder(r)) and
582 (not ClassInfUtil.isBasicTypeComponentName(FNode.refName(r)));
583 ✗ cr := AbsynUtil.pathToCref(AbsynUtil.stringListPath(FNode.namesUpToParentName(r, FNode.modNodeName)));
584 ✗ (g, rr) := FLookup.cr(g, FNode.getModifierTarget(r), cr, FLookup.ignoreNothing, FLookup.dummyLookupOption); // SOME(Absyn.dummyInfo));
585 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {rr}, r, g);
586 then
587 g;
588
589 // not found mod
590 case (r, g)
591 algorithm
592 ✗ true := FNode.isRefMod(r) and
593 (not FNode.isRefModHolder(r)) and
594 (not ClassInfUtil.isBasicTypeComponentName(FNode.refName(r)));
595 ✗ cr := AbsynUtil.pathToCref(AbsynUtil.stringListPath(FNode.namesUpToParentName(r, FNode.modNodeName)));
596 ✗ failure(FLookup.cr(g, FNode.getModifierTarget(r), cr, FLookup.ignoreNothing, FLookup.dummyLookupOption));
597 ✗ print("FResolve.mod_one: modifier: " + AbsynUtil.crefString(cr) +
598 " not found in: " + FNode.toPathStr(FNode.fromRef(r)) +"!\n");
599 // put it in the graph as unresolved ref
600 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {}, r, g);
601 then
602 g;
603
604 else ig;
605
606 end matchcontinue;
607 end mod_one;
608
609 public function elred
610 "@author: adrpo
611 for all redeclare as element lookup the base class and add $ref nodes to the result"
612 input Ref inRef;
613 input Graph ig;
614 output Graph og;
615 algorithm
616 og := match ig
617 local
618 Graph g;
619
620 case g
621 algorithm
622 // apply on all class extends nodes
623 ✗ g := FNode.apply1(inRef, elred_one, g);
624 then
625 g;
626
627 end match;
628 end elred;
629
630 public function elred_one
631 "@author: adrpo
632 helper"
633 input Name name;
634 input Ref inRef;
635 input Graph ig;
636 output Graph og;
637 algorithm
638 og := matchcontinue(inRef, ig)
639 local
640 Ref r, rr, p;
641 Name id;
642 Graph g;
643
644 // found redeclare as element that has a ref node
645 case (r, g)
646 algorithm
647 ✗ true := FNode.isRefRedeclare(r);
648 ✗ true := (FNode.isRefClass(r) and (not FNode.isRefClassExtends(r))) or FNode.isRefComponent(r);
649 // it does have a reference child already!
650 ✗ true := FNode.isRefRefResolved(r);
651 ✗ then
652 g;
653
654 // found redeclare as element
655 case (r, g)
656 algorithm
657 ✗ true := FNode.isRefRedeclare(r);
658 ✗ true := (FNode.isRefClass(r) and (not FNode.isRefClassExtends(r))) or FNode.isRefComponent(r);
659 ✗ id := SCodeUtil.elementName(FNode.getElement(FNode.fromRef(r)));
660 // get the parent where the extends are!
661 ✗ p := FNode.contextualParent(FNode.fromRef(r));
662 // search ONLY in extends!
663 ✗ (g, rr) := FLookup.ext(g, p, id, FLookup.ignoreParentsAndImports, FLookup.dummyLookupOption);
664 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {rr}, r, g);
665 then
666 g;
667
668 // not found ref
669 case (r, g)
670 algorithm
671 ✗ true := FNode.isRefRedeclare(r);
672 ✗ true := (FNode.isRefClass(r) and (not FNode.isRefClassExtends(r))) or FNode.isRefComponent(r);
673 ✗ id := SCodeUtil.elementName(FNode.getElement(FNode.fromRef(r)));
674 // get the parent where the extends are!
675 ✗ p := FNode.contextualParent(FNode.fromRef(r));
676 // search ONLY in extends!
677 ✗ failure(FLookup.ext(g, p, id, FLookup.ignoreParentsAndImports, FLookup.dummyLookupOption));
678 ✗ print("FResolve.elred_one: redeclare as element: " + id + " scope: " + FNode.toPathStr(FNode.fromRef(r)) +
679 " not found in extends of: " + FNode.toPathStr(FNode.fromRef(p)) + ":\n");
680 ✗ print("\t" + stringDelimitList(List.map(List.map(FNode.extendsRefs(p), FNode.fromRef), FNode.toPathStr), "\n\t") + "\n");
681 // put it in the graph as unresolved ref
682 ✗ g := FGraphBuild.mkRefNode(FNode.refNodeName, {}, r, g);
683 then
684 g;
685
686 else ig;
687
688 end matchcontinue;
689 end elred_one;
690
691 annotation(__OpenModelica_Interface="frontend");
692 end FResolve;
693