OMCompiler/Compiler/FrontEnd/AvlTreePathFunction.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 AvlTreePathFunction | ||
| 37 | " file: AvlTreePathFunction.mo | ||
| 38 | package: AvlTreePathFunction | ||
| 39 | description: AVL tree for managing paths to functions" | ||
| 40 | |||
| 41 | import Absyn; | ||
| 42 | import BaseAvlTree; | ||
| 43 | import DAE; | ||
| 44 | |||
| 45 | protected import AbsynUtil; | ||
| 46 | public | ||
| 47 | |||
| 48 | extends BaseAvlTree; | ||
| 49 | redeclare type Key = Absyn.Path; | ||
| 50 | redeclare type Value = Option<DAE.Function>; | ||
| 51 | redeclare function extends keyStr | ||
| 52 | algorithm | ||
| 53 | ✗ | outString := AbsynUtil.pathString(inKey); | |
| 54 | end keyStr; | ||
| 55 | redeclare function extends valueStr | ||
| 56 | algorithm | ||
| 57 | outString := match inValue | ||
| 58 | local | ||
| 59 | Absyn.Path path; | ||
| 60 | ✗ | case SOME(DAE.FUNCTION(path=path)) then AbsynUtil.pathString(path); | |
| 61 | ✗ | case SOME(DAE.RECORD_CONSTRUCTOR(path=path)) then AbsynUtil.pathString(path); | |
| 62 | case SOME(DAE.RECORD_CONSTRUCTOR()) then "<SOME_FUNCTION>"; | ||
| 63 | else "<NO_FUNCTION>"; | ||
| 64 | end match; | ||
| 65 | end valueStr; | ||
| 66 | redeclare function extends keyCompare | ||
| 67 | algorithm | ||
| 68 | 3794894 | outResult := AbsynUtil.pathCompareNoQual(inKey1,inKey2); | |
| 69 | end keyCompare; | ||
| 70 | |||
| 71 | redeclare function addConflictDefault = addConflictReplace; | ||
| 72 | |||
| 73 | public function addDaeFunction "add functions present in the element list to the function tree" | ||
| 74 | input list<DAE.Function> functions; | ||
| 75 | input output Tree functionTree; | ||
| 76 | algorithm | ||
| 77 |
2/2✓ Branch 1 taken 18618 times.
✓ Branch 2 taken 18618 times.
|
37236 | for f in functions loop |
| 78 | 18618 | functionTree := add(functionTree, functionName(f), SOME(f)); | |
| 79 | end for; | ||
| 80 | end addDaeFunction; | ||
| 81 | |||
| 82 | public function addDaeExtFunction "add the external functions present in the element list to the function tree (normal functions are skipped)" | ||
| 83 | input list<DAE.Function> functions; | ||
| 84 | input output Tree functionTree; | ||
| 85 | algorithm | ||
| 86 |
2/2✓ Branch 0 taken 33843 times.
✓ Branch 1 taken 33843 times.
|
67686 | for f in functions loop |
| 87 |
1/2✓ Branch 1 taken 33843 times.
✗ Branch 2 not taken.
|
33843 | if isExtFunction(f) then |
| 88 | 33843 | functionTree := add(functionTree, functionName(f), SOME(f)); | |
| 89 | end if; | ||
| 90 | end for; | ||
| 91 | end addDaeExtFunction; | ||
| 92 | |||
| 93 | protected function functionName "returns the name of a FUNCTION or RECORD_CONSTRUCTOR" | ||
| 94 | input DAE.Function elt; | ||
| 95 | output Absyn.Path name; | ||
| 96 | algorithm | ||
| 97 | name := match elt | ||
| 98 | case DAE.FUNCTION(path=name) then name; | ||
| 99 | case DAE.RECORD_CONSTRUCTOR(path=name) then name; | ||
| 100 | end match; | ||
| 101 | end functionName; | ||
| 102 | |||
| 103 | protected function isExtFunction "returns true if element matches an external function" | ||
| 104 | input DAE.Function elt; | ||
| 105 | output Boolean res; | ||
| 106 | algorithm | ||
| 107 | res := match elt | ||
| 108 | case DAE.FUNCTION(functions=DAE.FUNCTION_EXT()::_) then true; | ||
| 109 | else false; | ||
| 110 | end match; | ||
| 111 | end isExtFunction; | ||
| 112 | |||
| 113 | annotation(__OpenModelica_Interface="frontend_dump"); | ||
| 114 | end AvlTreePathFunction; | ||
| 115 |