Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 95.5% 42 / 0 / 44
Functions: -% 0 / 1 / 1
Branches: 63.3% 19 / 0 / 30

OMCompiler/Compiler/NFFrontEnd/NFFlatModelicaUtil.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 NFFlatModelicaUtil
37 import Absyn;
38 import AbsynUtil;
39 import DAE;
40 import DAEDumpTypes;
41 import Dump;
42 import ElementSource;
43 import IOStream;
44 import SCode;
45 import SCodeUtil;
46 import System;
47 import Util;
48
49 // Used to indicate what type of element an annotation comes from, to allow
50 // filtering out specific annotations for dumping.
51 type ElementType = enumeration(
52 ROOT_CLASS,
53 CLASS,
54 FUNCTION,
55 COMPONENT,
56 EQUATION,
57 ALGORITHM,
58 OTHER
59 );
60
61 function appendElementSourceCommentString
62 input DAE.ElementSource source;
63 input output IOStream.IOStream s;
64 protected
65 Option<SCode.Comment> opt_cmt;
66 algorithm
67 32 opt_cmt := ElementSource.getOptComment(source);
68
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
32 if isSome(opt_cmt) then
69 32 s := appendCommentString(Util.getOption(opt_cmt), s);
70 end if;
71 end appendElementSourceCommentString;
72
73 function appendElementSourceCommentAnnotation
74 input DAE.ElementSource source;
75 input ElementType elementType;
76 input String indent;
77 input String ending;
78 input output IOStream.IOStream s;
79 protected
80 Option<SCode.Comment> opt_cmt;
81 algorithm
82 32 opt_cmt := ElementSource.getOptComment(source);
83
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
32 if isSome(opt_cmt) then
84 32 s := appendCommentAnnotation(Util.getOption(opt_cmt), elementType, indent, ending, s);
85 end if;
86 end appendElementSourceCommentAnnotation;
87
88 function appendElementSourceComment
89 input DAE.ElementSource source;
90 input ElementType elementType;
91 input output IOStream.IOStream s;
92 algorithm
93 382 s := appendCommentOpt(ElementSource.getOptComment(source), elementType, s);
94 end appendElementSourceComment;
95
96 function appendCommentOpt
97 input Option<SCode.Comment> comment;
98 input ElementType elementType;
99 input output IOStream.IOStream s;
100 algorithm
101
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 382 times.
✓ Branch 2 taken 358 times.
✓ Branch 3 taken 24 times.
382 if isSome(comment) then
102 358 s := appendComment(Util.getOption(comment), elementType, s);
103 end if;
104 end appendCommentOpt;
105
106 function appendComment
107 input SCode.Comment comment;
108 input ElementType elementType;
109 input output IOStream.IOStream s;
110 algorithm
111 1205 s := appendCommentString(comment, s);
112 1205 s := appendCommentAnnotation(comment, elementType, " ", "", s);
113 end appendComment;
114
115 function appendCommentString
116 input SCode.Comment comment;
117 input output IOStream.IOStream s;
118 protected
119 String str;
120 algorithm
121 () := match comment
122 case SCode.Comment.COMMENT(comment = SOME(str))
123 algorithm
124 19 s := IOStream.append(s, " \"");
125 19 s := IOStream.append(s, System.escapedString(str, false));
126 19 s := IOStream.append(s, "\"");
127 then
128 ();
129
130 else ();
131 end match;
132 end appendCommentString;
133
134 function appendCommentAnnotation
135 input SCode.Comment comment;
136 input ElementType elementType;
137 input String indent;
138 input String ending;
139 input output IOStream.IOStream s;
140 protected
141 SCode.Mod mod;
142 algorithm
143 () := match comment
144 case SCode.Comment.COMMENT(annotation_ =
145 SOME(SCode.Annotation.ANNOTATION(modification = mod)))
146 algorithm
147 mod := match elementType
148 25 case ElementType.ROOT_CLASS then filterRootClassAnnotations(mod);
149 6 else DAEDumpTypes.filterStructuralMods(mod);
150 end match;
151
152
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 25 times.
31 if not SCodeUtil.isEmptyMod(mod) then
153 6 s := IOStream.append(s, indent);
154 6 s := IOStream.append(s, "annotation");
155 6 s := appendAnnotationMod(mod, s);
156 6 s := IOStream.append(s, ending);
157 end if;
158 then
159 ();
160
161 else ();
162 end match;
163 end appendCommentAnnotation;
164
165 function filterRootClassAnnotations
166 input output SCode.Mod mod;
167 protected
168 function filter
169 input SCode.SubMod smod;
170 output Boolean keep;
171 algorithm
172 keep := match smod.ident
173 case "experiment" then true;
174 else false;
175 end match;
176 end filter;
177 algorithm
178 25 mod := SCodeUtil.filterSubMods(mod, filter);
179 end filterRootClassAnnotations;
180
181 function appendAnnotationMod
182 input SCode.Mod mod;
183 input output IOStream.IOStream s;
184 algorithm
185 () := match mod
186 case SCode.Mod.MOD()
187 algorithm
188
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 10 times.
19 if not listEmpty(mod.subModLst) then
189 9 s := IOStream.append(s, "(");
190 9 s := appendAnnotationSubMod(listHead(mod.subModLst), s);
191
192
2/2
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 9 times.
13 for m in listRest(mod.subModLst) loop
193 4 s := IOStream.append(s, ", ");
194 4 s := appendAnnotationSubMod(m, s);
195 end for;
196
197 9 s := IOStream.append(s, ")");
198 end if;
199
200
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 7 times.
19 if isSome(mod.binding) then
201 12 s := IOStream.append(s, " = ");
202 12 s := appendExp(Util.getOption(mod.binding), s);
203 end if;
204 then
205 ();
206
207 else ();
208 end match;
209 end appendAnnotationMod;
210
211 function appendAnnotationSubMod
212 input SCode.SubMod mod;
213 input output IOStream.IOStream s;
214 protected
215 SCode.Mod m = mod.mod;
216 algorithm
217 () := match m
218 case SCode.Mod.MOD()
219 algorithm
220
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
13 if SCodeUtil.finalBool(m.finalPrefix) then
221 ✗ s := IOStream.append(s, "final ");
222 end if;
223
224
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
13 if SCodeUtil.eachBool(m.eachPrefix) then
225 ✗ s := IOStream.append(s, "each ");
226 end if;
227
228 13 s := IOStream.append(s, mod.ident);
229 13 s := appendAnnotationMod(m, s);
230 then
231 ();
232
233 else ();
234 end match;
235 end appendAnnotationSubMod;
236
237 function appendExp
238 input Absyn.Exp exp;
239 input output IOStream.IOStream s;
240 protected
241 Absyn.Exp e;
242 algorithm
243 12 (e, _) := AbsynUtil.traverseExp(exp, quoteCref, 0);
244 12 s := IOStream.append(s, Dump.printExpStr(e));
245 end appendExp;
246
247 function quoteCref
248 input output Absyn.Exp exp;
249 input output Integer dummy;
250 protected
251 String str;
252 algorithm
253 () := match exp
254 case Absyn.Exp.CREF()
255 guard not AbsynUtil.crefIsWild(exp.componentRef)
256 algorithm
257 4 str := Dump.printComponentRefStr(exp.componentRef);
258
259
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
4 if str <> "time" then
260 4 str := Util.makeQuotedIdentifier(str);
261 8 exp.componentRef := Absyn.ComponentRef.CREF_IDENT(str, {});
262 end if;
263 then
264 ();
265
266 else ();
267 end match;
268 end quoteCref;
269
270 annotation(__OpenModelica_Interface="nf_frontend");
271 end NFFlatModelicaUtil;
272