Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 83.3% 10 / 0 / 12
Functions: 66.7% 2 / 1 / 4
Branches: 66.7% 4 / 0 / 6

OMCompiler/Compiler/Util/Pointer.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 uniontype Pointer<T>
37 "Creating shared (sometimes mutable) objects.
38
39 This uniontype contains routines for creating and updating objects,
40 similar to array<> structures. Use this uniontype over the Mutable
41 package if you need to be able to create constants that are just
42 pointers to static, immutable data. Use the Mutable uniontype if you
43 do not need to create constants (that package has lower overhead
44 since it does no extra checks)."
45
46 21907747 impure function create
47 input T data;
48 output Pointer<T> ptr;
49 external "C" ptr=pointerCreate(data) annotation(Include="
50 static inline void* pointerCreate(void *data)
51 {
52 21907747 return mmc_mk_box1(0, data);
53 }
54 ");
55 end create;
56
57 21907747 function createImmutable
58 input T data;
59 output Pointer<T> ptr;
60 external "builtin" ptr=mmc_mk_some(data);
61 end createImmutable;
62
63 ✗ impure function update
64 input Pointer<T> mutable;
65 input T data;
66 external "C" pointerUpdate(OpenModelica.threadData(), mutable, data) annotation(Include="
67 static inline void pointerUpdate(threadData_t *threadData, void *ptr, void *data)
68 {
69 17162340 if (valueConstructor(ptr)!=0) {
70 ✗ MMC_THROW_INTERNAL();
71 }
72 17162340 MMC_STRUCTDATA(ptr)[0] = data;
73 }
74 ");
75 end update;
76
77
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17162340 times.
17162340 impure function access
78 input Pointer<T> mutable;
79 output T data;
80 external "C" data=pointerAccess(mutable) annotation(Include="
81 static inline void* pointerAccess(void *ptr)
82 {
83 160857736 return MMC_STRUCTDATA(ptr)[0];
84 }
85 ");
86 end access;
87
88 function clone
89 input output Pointer<T> mutable = create(access(mutable));
90 end clone;
91
92 function apply
93 input output Pointer<T> mutable;
94 input Func func;
95 partial function Func
96 input output T value;
97 end Func;
98 protected
99 T new;
100 algorithm
101
1/2
✓ Branch 0 taken 646 times.
✗ Branch 1 not taken.
646 new := func(access(mutable));
102
2/2
✓ Branch 1 taken 29 times.
✓ Branch 2 taken 617 times.
646 if not referenceEq(new, access(mutable)) then
103 617 update(mutable, new);
104 end if;
105 end apply;
106
107 annotation(__OpenModelica_Interface="util_datatypes_basic");
108 end Pointer;
109