Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 50.0% 4 / 0 / 8
Functions: -% 0 / 1 / 1
Branches: -% 0 / 0 / 0

OMCompiler/Compiler/Util/HashTableCrefSimVar.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 HashTableCrefSimVar
37
38 /* Below is the instance specific code. For each hashtable the user must define:
39
40 Key - The key used to uniquely define elements in a hashtable
41 Value - The data to associate with each key
42 hashFunc - A function that maps a key to a positive integer.
43 keyEqual - A comparison function between two keys, returns true if equal.
44 */
45
46 /* HashTable instance specific code */
47
48 import BaseHashTable;
49 import DAE;
50 import SimCodeVar;
51 import Error.addInternalError;
52
53 type Key = DAE.ComponentRef;
54 type Value = SimCodeVar.SimVar;
55
56 protected
57
58 import ComponentReferenceBasics;
59
60 public
61
62 type HashTableCrefFunctionsType = tuple<FuncHashCref,FuncCrefEqual,FuncCrefStr,FuncExpStr>;
63 type HashTable = tuple<
64 array<list<tuple<Key,Integer>>>,
65 tuple<Integer,Integer,array<Option<tuple<Key,Value>>>>,
66 Integer,
67 HashTableCrefFunctionsType
68 >;
69
70 partial function FuncHashCref
71 input Key cr;
72 output Integer res;
73 end FuncHashCref;
74
75 partial function FuncCrefEqual
76 input Key cr1;
77 input Key cr2;
78 output Boolean res;
79 end FuncCrefEqual;
80
81 partial function FuncCrefStr
82 input Key cr;
83 output String res;
84 end FuncCrefStr;
85
86 partial function FuncExpStr
87 input Value exp;
88 output String res;
89 end FuncExpStr;
90
91 function emptyHashTable
92 "
93 Returns an empty HashTable.
94 Using the default bucketsize..
95 "
96 output HashTable hashTable;
97 algorithm
98 ✗ hashTable := emptyHashTableSized(BaseHashTable.defaultBucketSize);
99 end emptyHashTable;
100
101 function emptyHashTableSized
102 "Returns an empty HashTable.
103 Using the bucketsize size."
104 input Integer size;
105 output HashTable hashTable;
106 algorithm
107 5398 hashTable := BaseHashTable.emptyHashTableWork(size,(ComponentReferenceBasics.hashComponentRef,ComponentReferenceBasics.crefEqual,ComponentReferenceBasics.printComponentRefStr,opaqueStr));
108 end emptyHashTableSized;
109
110 protected
111 function opaqueStr
112 input SimCodeVar.SimVar var;
113 output String str;
114 algorithm
115 ✗ str := "#SimVar(index="+String(var.index)+",name="+ComponentReferenceBasics.printComponentRefStr(var.name)+")#";
116 end opaqueStr;
117
118
119 public function addSimVarToHashTable
120 "adds SimVar to hash table inHT and returns extended hash table"
121 input SimCodeVar.SimVar simvarIn;
122 input HashTable inHT;
123 output HashTable outHT;
124 algorithm
125 outHT :=
126 matchcontinue simvarIn
127 local
128 DAE.ComponentRef cr, acr;
129 SimCodeVar.SimVar sv;
130
131 case sv as SimCodeVar.SIMVAR(name = cr, arrayCref = NONE())
132 algorithm
133 //print("addSimVarToHashTable: handling variable '" + ComponentReferenceBasics.printComponentRefStr(cr) + "'\n");
134 723996 outHT := BaseHashTable.add((cr, sv), inHT);
135 then outHT;
136 // add the whole array crefs to the hashtable, too
137 case sv as SimCodeVar.SIMVAR(name = cr, arrayCref = SOME(acr))
138 algorithm
139 //print("addSimVarToHashTable: handling array variable '" + ComponentReferenceBasics.printComponentRefStr(cr) + "'\n");
140 100935 outHT := BaseHashTable.add((acr, sv), inHT);
141 100935 outHT := BaseHashTable.add((cr, sv), outHT);
142 then outHT;
143 else
144 algorithm
145 ✗ Error.addInternalError("function addSimVarToHashTable failed", sourceInfo());
146 ✗ then
147 fail();
148 end matchcontinue;
149 end addSimVarToHashTable;
150
151 annotation(__OpenModelica_Interface="simcode_types");
152 end HashTableCrefSimVar;
153