Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 27 / 0 / 27
Functions: 100.0% 3 / 0 / 3
Branches: 100.0% 6 / 0 / 6

OMCompiler/SimulationRuntime/c/meta/meta_modelica_string.h
Line Branch Exec Source
1 /*
2 * This file belongs to the OpenModelica Run-Time System
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), c/o Linköpings
5 * universitet, Department of Computer and Information Science, SE-58183 Linköping, Sweden. All rights
6 * reserved.
7 *
8 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
9 * AGPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. ANY
10 * USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
11 * ACCEPTANCE OF THE BSD NEW LICENSE OR THE OSMC PUBLIC LICENSE OR THE AGPL
12 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
13 *
14 * The OpenModelica software and the OSMC (Open Source Modelica Consortium) Public License
15 * (OSMC-PL) are obtained from OSMC, either from the above address, from the URLs:
16 * http://www.openmodelica.org or https://github.com/OpenModelica/ or
17 * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica distribution. GNU
18 * AGPL version 3 is obtained from: https://www.gnu.org/licenses/licenses.html#GPL. The BSD NEW
19 * License is obtained from: http://www.opensource.org/licenses/BSD-3-Clause.
20 *
21 * This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY
23 * SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF
24 * OSMC-PL.
25 *
26 */
27
28
29 #ifndef META_MODELICA_STRING_H_
30 #define META_MODELICA_STRING_H_
31
32 /* The MetaModelica string: a tagged pointer to an mmc_header'd object. The
33 * simulation's (util/omc_string.h) is counted and untagged. */
34
35 #include <string.h>
36 #include <stdarg.h>
37 #include "meta_modelica_data.h"
38 #include "meta_modelica_string_lit.h"
39
40 #if defined(__cplusplus)
41 extern "C" {
42 #endif
43
44 /* The string vocabulary generated code uses; both runtimes define these. */
45 #define omc_string_data(x) MMC_STRINGDATA(x)
46 #define omc_string_len(x) MMC_STRLEN(x)
47 #define omc_string_new(s) mmc_mk_scon(s)
48 #define omc_string_new_len(s,n) mmc_mk_scon_n((s),(n))
49 #define omc_string_new_persist(s) mmc_mk_scon_persist(s)
50 #define omc_string_alloc(n) mmc_alloc_scon(n)
51 #define omc_string_empty mmc_emptystring
52 #define omc_strings_len1 mmc_strings_len1
53 #define omc_string_uninitialized mmc_string_uninitialized
54 #define omc_strings_boolString mmc_strings_boolString
55 /* Collected, so a store is a plain assignment. */
56 #define omc_string_store(SLOT, S) (*(SLOT) = (S))
57 #define omc_string_move(SLOT, S) (*(SLOT) = (S))
58 #define omc_string_retain(S) (S)
59 #define omc_string_release(S) ((void)0)
60 /* Nothing was owned, so there is nothing to give up. */
61 #define omc_string_disown(S) ((void)0)
62
63 extern void* stringAppend(void *s1, void *s2);
64 extern modelica_integer mmc_stringCompare(const void *str1, const void *str2);
65 #define stringCompare(x,y) mmc_stringCompare(x,y)
66 #define stringEqual(x,y) (MMC_STRLEN(x) == MMC_STRLEN(y) && !stringCompare(x,y))
67
68 #include "../util/omc_str_utils.h"
69
70 4558258 static inline void* mmc_alloc_scon(size_t nbytes)
71 {
72 4558258 mmc_uint_t header = MMC_STRINGHDR(nbytes);
73 4558258 mmc_uint_t nwords = MMC_HDRSLOTS(header) + 1;
74 struct mmc_string *p;
75
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4558252 times.
4558258 if (nbytes == 0) return mmc_emptystring;
76 4558252 p = (struct mmc_string *) mmc_check_out_of_memory(omc_alloc_interface.malloc_atomic(nwords*sizeof(void*)));
77 4558252 p->header = header;
78 4558252 p->data[0] = 0;
79 4558252 return MMC_TAGPTR(p);
80 }
81
82 33491052 static inline void* mmc_mk_scon_len(mmc_uint_t nbytes)
83 {
84 33491052 mmc_uint_t header = MMC_STRINGHDR(nbytes);
85 33491052 mmc_uint_t nwords = MMC_HDRSLOTS(header) + 1;
86 struct mmc_string *p;
87 33491052 p = (struct mmc_string *) mmc_check_out_of_memory(omc_alloc_interface.malloc_atomic(nwords*sizeof(void*)));
88 33491052 p->header = header;
89 33491052 return MMC_TAGPTR(p);
90 }
91
92 static inline void* mmc_mk_scon_n(const char *s, int length)
93 {
94 size_t header = MMC_STRINGHDR(length);
95 size_t nwords = MMC_HDRSLOTS(header) + 1;
96 struct mmc_string *p;
97 void *res;
98 if (length == 0) return mmc_emptystring;
99 if (length == 1) {
100 unsigned char c = *s;
101 return mmc_strings_len1[(unsigned int)c];
102 }
103 p = (struct mmc_string *) mmc_check_out_of_memory(omc_alloc_interface.malloc_atomic(nwords*sizeof(void*)));
104 p->header = header;
105 memcpy(p->data, s, length);
106 p->data[length] = '\0';
107 res = MMC_TAGPTR(p);
108 MMC_CHECK_STRING(res);
109 return res;
110 }
111
112 65630413 static inline void* mmc_mk_scon(const char *s)
113 {
114 65630413 size_t nbytes = strlen(s);
115 65630413 size_t header = MMC_STRINGHDR(nbytes);
116 65630413 size_t nwords = MMC_HDRSLOTS(header) + 1;
117 struct mmc_string *p;
118 void *res;
119
2/2
✓ Branch 0 taken 5489904 times.
✓ Branch 1 taken 60140509 times.
65630413 if (nbytes == 0) return mmc_emptystring;
120
2/2
✓ Branch 0 taken 3197515 times.
✓ Branch 1 taken 56942994 times.
60140509 if (nbytes == 1) {
121 3197515 unsigned char c = *s;
122 3197515 return mmc_strings_len1[(unsigned int)c];
123 }
124 56942994 p = (struct mmc_string *) mmc_check_out_of_memory(omc_alloc_interface.malloc_atomic(nwords*sizeof(void*)));
125 56942994 p->header = header;
126 56942994 memcpy(p->data, s, nbytes+1);
127 56942994 res = MMC_TAGPTR(p);
128 MMC_CHECK_STRING(res);
129 56942994 return res;
130 }
131
132 static inline void* mmc_mk_scon_persist(const char *s)
133 {
134 size_t nbytes = strlen(s);
135 size_t header = MMC_STRINGHDR(nbytes);
136 size_t nwords = MMC_HDRSLOTS(header) + 1;
137 struct mmc_string *p;
138 void *res;
139 if (nbytes == 0) return mmc_emptystring;
140 if (nbytes == 1) {
141 unsigned char c = *s;
142 return mmc_strings_len1[(unsigned int)c];
143 }
144 p = (struct mmc_string *) mmc_check_out_of_memory(omc_alloc_interface.malloc_string_persist(nwords*sizeof(void*)));
145 p->header = header;
146 memcpy(p->data, s, nbytes+1);
147 res = MMC_TAGPTR(p);
148 MMC_CHECK_STRING(res);
149 return res;
150 }
151
152 #if defined(__cplusplus)
153 } /* end extern "C" */
154 #endif
155
156 #endif /* META_MODELICA_STRING_H_ */
157