Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 87.3% 69 / 0 / 79
Functions: -% 0 / 0 / 0
Branches: -% 0 / 0 / 0

OMCompiler/Compiler/Template/AbsynDumpTpl.tpl
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 package AbsynDumpTpl
37
38 import interface AbsynDumpTV;
39
40 196 template dump(Absyn.Program program, DumpOptions options)
41 ::=
42 match program
43 case PROGRAM(classes = {}) then ""
44 case PROGRAM(__) then
45 let within_str = dumpWithin(within_)
46 let cls_str = (classes |> cls => dumpClass(cls, ";", options) ;separator="\n\n")
47 '<%within_str%><%cls_str%>'
48 end dump;
49
50 201 template dumpClass(Absyn.Class cls, String sc, DumpOptions options)
51 ::= dumpClassElement(cls, "", "", "" , "", sc, options)
52 end dumpClass;
53
54 4 template dumpWithin(Absyn.Within within)
55 ::=
56 match within
57 case TOP(__) then ""
58 case WITHIN(__) then
59 let path_str = dumpPath(path)
60 <<
61 within <%path_str%>;
62
63 >>
64 else Tpl.addSourceTemplateError("Unknown operation", sourceInfo())
65 end dumpWithin;
66
67 7085 template dumpClassHeader(Absyn.Class cls, String final_str,
68 String redecl_str, String repl_str, String io_str)
69 ::=
70 match cls
71 case CLASS(__) then
72 let res_str = dumpRestriction(restriction)
73 let pref_str = dumpClassPrefixes(cls, final_str, redecl_str, repl_str, io_str)
74 '<%pref_str%><%res_str%>'
75 end dumpClassHeader;
76
77 7085 template dumpClassElement(Absyn.Class cls, String final_str,
78 String redecl_str, String repl_str, String io_str, String sc, DumpOptions options)
79 ::=
80 match cls
81 case CLASS(__) then
82 let header_str = dumpClassHeader(cls, final_str, redecl_str, repl_str, io_str)
83 let body_str = dumpClassDef(body, name, commentsBeforeEnd, options)
84 let beforeComment = '<%if commentsBeforeClass then (commentsBeforeClass |> cmt => cmt) + "\n" else ""%>'
85 '<%beforeComment%><%header_str%> <%body_str%><%sc%><%if commentsAfterEnd then "\n" + commentsAfterEnd |> cmt => cmt%>'
86 end dumpClassElement;
87
88 5538 template dumpClassDef(Absyn.ClassDef cdef, String cls_name, list<String> commentsBeforeEnd, DumpOptions options)
89 ::=
90 match cdef
91 case PARTS(__) then
92 let tvs_str = if typeVars then '<<%(typeVars |> typevar => typevar ;separator=", ")%>>'
93 let ann_str = (listReverse(ann) |> a => dumpAnnotation(a) ;separator=";\n")
94 let cmt_str = dumpStringCommentOption(comment)
95 let body_str = (classParts |> class_part hasindex idx =>
96 dumpClassPart(class_part, idx, options) ;separator="")
97 <<
98 <%cls_name%><%tvs_str%><%cmt_str%><%\n%>
99 <%body_str%>
100 <%if ann_str then '<%ann_str%>;'%>
101 <%commentsBeforeEnd |> cmt => cmt%>
102 end <%cls_name%>
103 >>
104 case DERIVED(__) then
105 let attr_str = dumpElementAttr(attributes)
106 let ty_str = dumpTypeSpec(typeSpec)
107 let mod_str = if arguments then
108 '(<%dumpElementArgList(arguments, ', ')%>)'
109 let cmt_str = dumpCommentOpt(comment)
110 '<%cls_name%> = <%attr_str%><%ty_str%><%mod_str%><%cmt_str%><%commentsBeforeEnd |> cmt => cmt%>'
111 case CLASS_EXTENDS(__) then
112 let body_str = (parts |> class_part hasindex idx =>
113 dumpClassPart(class_part, idx, options) ;separator="\n")
114 let mod_str = if modifications then
115 '(<%dumpElementArgList(modifications, ', ')%>)'
116 let cmt_str = dumpStringCommentOption(comment)
117 let ann_str = (listReverse(ann) |> a => dumpAnnotation(a) ;separator=";\n")
118 <<
119 extends <%baseClassName%><%mod_str%><%cmt_str%>
120 <%body_str%>
121 <%if ann_str then '<%ann_str%>;'%>
122 <%commentsBeforeEnd |> cmt => cmt%>
123 end <%cls_name%>
124 >>
125 case ENUMERATION(__) then
126 let enum_str = dumpEnumDef(enumLiterals)
127 let cmt_str = dumpCommentOpt(comment)
128 '<%cls_name%> = enumeration(<%enum_str%>)<%cmt_str%><%commentsBeforeEnd |> cmt => cmt%>'
129 case OVERLOAD(__) then
130 let funcs_str = (functionNames |> fn => dumpPath(fn) ;separator=", ")
131 let cmt_str = dumpCommentOpt(comment)
132 '<%cls_name%> = $overload(<%funcs_str%>)<%cmt_str%><%commentsBeforeEnd |> cmt => cmt%>'
133 case PDER(__) then
134 let fn_str = dumpPath(functionName)
135 let vars_str = (vars |> var => var ;separator=", ")
136 '<%cls_name%> = der(<%fn_str%>, <%vars_str%>)<%commentsBeforeEnd |> cmt => cmt%>'
137 end dumpClassDef;
138
139 58 template dumpEnumDef(Absyn.EnumDef enum_def)
140 ::=
141 match enum_def
142 case ENUMLITERALS(__) then
143 (enumLiterals |> lit => dumpEnumLiteral(lit) ;separator=", ")
144 case ENUM_COLON() then ":"
145 end dumpEnumDef;
146
147 227 template dumpEnumLiteral(Absyn.EnumLiteral lit)
148 ::=
149 match lit
150 case ENUMLITERAL(__) then
151 let cmt_str = dumpCommentOpt(comment)
152 '<%literal%><%cmt_str%>'
153 end dumpEnumLiteral;
154
155 7085 template dumpClassPrefixes(Absyn.Class cls, String final_str,
156 String redecl_str, String repl_str, String io_str)
157 ::=
158 match cls
159 case CLASS(__) then
160 let enc_str = if encapsulatedPrefix then "encapsulated "
161 let partial_str = if partialPrefix then "partial "
162 let fin_str = dumpFinal(finalPrefix)
163 '<%redecl_str%><%fin_str%><%io_str%><%repl_str%><%enc_str%><%partial_str%>'
164 end dumpClassPrefixes;
165
166 81 template dumpPurity(Absyn.FunctionPurity purity)
167 ::=
168 match purity
169 case PURE(__) then "pure "
170 case IMPURE(__) then "impure "
171 case NO_PURITY(__) then ""
172 end dumpPurity;
173
174 2129 template dumpRestriction(Absyn.Restriction restriction)
175 ::=
176 match restriction
177 case R_CLASS(__) then "class"
178 case R_OPTIMIZATION(__) then "optimization"
179 case R_MODEL(__) then "model"
180 case R_RECORD(__) then "record"
181 case R_BLOCK(__) then "block"
182 case R_CONNECTOR(__) then "connector"
183 case R_EXP_CONNECTOR(__) then "expandable connector"
184 case R_TYPE(__) then "type"
185 case R_PACKAGE(__) then "package"
186 case R_FUNCTION(__) then
187 let prefix_str = match functionRestriction
188 case FR_NORMAL_FUNCTION() then dumpPurity(purity)
189 case FR_OPERATOR_FUNCTION() then "operator "
190 case FR_PARALLEL_FUNCTION() then "parallel "
191 case FR_KERNEL_FUNCTION() then "kernel "
192 '<%prefix_str%>function'
193 case R_OPERATOR(__) then "operator"
194 case R_OPERATOR_RECORD(__) then "operator record"
195 case R_ENUMERATION(__) then "enumeration"
196 case R_PREDEFINED_INTEGER(__) then "Integer"
197 case R_PREDEFINED_REAL(__) then "Real"
198 case R_PREDEFINED_STRING(__) then "String"
199 case R_PREDEFINED_BOOLEAN(__) then "Boolean"
200 case R_PREDEFINED_ENUMERATION(__) then "enumeration(:)"
201 case R_UNIONTYPE(__) then "uniontype"
202 case R_METARECORD(__) then 'metarecord<% if typeVars then ("<" + (typeVars |> tv => tv; separator=",") + ">") %>'
203 case R_UNKNOWN(__) then "*unknown*"
204 end dumpRestriction;
205
206 5980 template dumpClassPart(Absyn.ClassPart class_part, Integer idx, DumpOptions options)
207 ::=
208 match class_part
209 case PUBLIC(__) then
210 // Skip printing out "public" if it's the first section.
211 let section_str = if idx then "public" else ""
212 let el_str = dumpElementItems(contents, "", true, options)
213 <<
214 <%section_str%>
215 <%el_str%>
216 >>
217 case PROTECTED(__) then
218 let el_str = dumpElementItems(contents, "", true, options)
219 <<
220 protected
221 <%el_str%>
222 >>
223 //<%(contents |> ei => dumpElementItem(ei) ;separator="\n")%>
224 case CONSTRAINTS(__) then
225 <<
226 constraint
227 <%(contents |> exp => dumpExp(exp) ;separator="; ")%>
228 >>
229 case EQUATIONS(__) then
230 <<
231 equation
232 <%(contents |> eq => dumpEquationItem(eq) ;separator="\n")%><%\n%>
233 >>
234 case INITIALEQUATIONS(__) then
235 <<
236 initial equation
237 <%(contents |> eq => dumpEquationItem(eq) ;separator="\n")%><%\n%>
238 >>
239 case ALGORITHMS(__) then
240 <<
241 algorithm
242 <%(contents |> eq => dumpAlgorithmItem(eq) ;separator="\n")%><%\n%>
243 >>
244 case INITIALALGORITHMS(__) then
245 <<
246 initial algorithm
247 <%(contents |> eq => dumpAlgorithmItem(eq) ;separator="\n")%><%\n%>
248 >>
249 case EXTERNAL(__) then
250 let ann_str = match annotation_ case SOME(ann) then ' <%dumpAnnotation(ann)%>;'
251 match externalDecl
252 case EXTERNALDECL(__) then
253 let fn_str = match funcName case SOME(fn) then fn
254 let lang_str = match lang case SOME(l) then '"<%l%>" '
255 let output_str = match output_ case SOME(o) then '<%dumpCref(o)%> = '
256 let args_str = if args then '(<%(args |> arg => dumpExp(arg) ;separator=", ")%>)' else (if fn_str then "()")
257 let ann2_str = dumpAnnotationOptSpace(annotation_)
258 <<
259
260 external <%lang_str%><%output_str%><%fn_str%><%args_str%><%ann2_str%>;<%ann_str%>
261 >>
262 end dumpClassPart;
263
264 46907 template dumpElementItems(list<Absyn.ElementItem> items, String prevSpacing, Boolean first, DumpOptions options)
265 ::=
266 match items
267 case item :: rest_items then
268 let spacing = dumpElementItemSpacing(item)
269 let pre_spacing = if not first then
270 dumpElementItemPreSpacing(spacing, prevSpacing)
271 let item_str = dumpElementItem(item, options)
272 let rest_str = dumpElementItems(rest_items, spacing, false, options)
273 let post_spacing = if rest_str then spacing
274 <<
275 <%pre_spacing%>
276 <%item_str%><%post_spacing%><%\n%>
277 <%if rest_str then rest_str%>
278 >>
279 end dumpElementItems;
280
281 40081 template dumpElementItemPreSpacing(String curSpacing, String prevSpacing)
282 ::= if not prevSpacing then curSpacing
283 end dumpElementItemPreSpacing;
284
285 6565 template dumpElementItemSpacing(Absyn.ElementItem item)
286 ::=
287 match item
288 case ELEMENTITEM(element = ELEMENT(specification = CLASSDEF(class_ = CLASS(body = cdef))))
289 then dumpClassDefSpacing(cdef)
290 end dumpElementItemSpacing;
291
292 5337 template dumpClassDefSpacing(Absyn.ClassDef cdef)
293 ::=
294 match cdef
295 case PARTS(__) then '<%\n%>'
296 case CLASS_EXTENDS(__) then '<%\n%>'
297 end dumpClassDefSpacing;
298
299 45547 template dumpElementItem(Absyn.ElementItem eitem, DumpOptions options)
300 ::=
301 match eitem
302 case ELEMENTITEM(__) then dumpElement(element, options)
303 case LEXER_COMMENT(__) then System.trimWhitespace(comment)
304 end dumpElementItem;
305
306 45547 template dumpElement(Absyn.Element elem, DumpOptions options)
307 ::=
308 match elem
309 case ELEMENT(__) then
310 if boolOr(boolUnparseFileFromInfo(info, options), boolNot(isClassdef(elem))) then
311 let final_str = dumpFinal(finalPrefix)
312 let redecl_str = match redeclareKeywords case SOME(re) then dumpRedeclare(re)
313 let repl_str = match redeclareKeywords case SOME(re) then dumpReplaceable(re)
314 let io_str = dumpInnerOuter(innerOuter)
315 let ec_str = dumpElementSpec(specification, final_str, redecl_str, repl_str, io_str, options)
316 let cc_str = match constrainClass case SOME(cc) then dumpConstrainClass(cc)
317 '<%ec_str%><%cc_str%>;'
318 case DEFINEUNIT(__) then
319 let args_str = if args then '(<%(args |> arg => dumpNamedArg(arg))%>)'
320 'defineunit <%name%><%args_str%>;'
321 case TEXT(__) then
322 if boolUnparseFileFromInfo(info, options) then
323 let name_str = match optName case SOME(name) then name
324 let info_str = dumpInfo(info)
325 '/* Absyn.TEXT(SOME("<%name_str%>"), "<%string%>", "<%info_str%>"); */'
326 end dumpElement;
327
328 ✗ template dumpInfo(builtin.SourceInfo info)
329 ::=
330 match info
331 case SOURCEINFO(__) then
332 let rm_str = if isReadOnly then "readonly" else "writable"
333 'SOURCEINFO("<%fileName%>", <%rm_str%>, <%lineNumberStart%>, <%columnNumberStart%>, <%lineNumberEnd%>, <%columnNumberEnd%>)\n'
334 end dumpInfo;
335
336 26751 template dumpAnnotation(Absyn.Annotation ann)
337 ::=
338 match ann
339 case ANNOTATION(elementArgs={}) then "annotation()"
340 case ANNOTATION(__) then
341 <<
342 annotation(
343 <%dumpElementArgList(elementArgs, ',<%\n%>')%>)
344 >>
345 end dumpAnnotation;
346
347 ✗ template dumpAnnotationOpt(Option<Absyn.Annotation> oann)
348 ::= match oann case SOME(ann) then dumpAnnotation(ann)
349 end dumpAnnotationOpt;
350
351 22070 template dumpAnnotationOptSpace(Option<Absyn.Annotation> oann)
352 ::= match oann case SOME(ann) then " " + dumpAnnotation(ann)
353 end dumpAnnotationOptSpace;
354
355 37014 template dumpComment(Absyn.Comment cmt)
356 ::=
357 match cmt
358 case COMMENT(__) then
359 dumpStringCommentOption(comment) + dumpAnnotationOptSpace(annotation_)
360 end dumpComment;
361
362 37014 template dumpCommentOpt(Option<Absyn.Comment> ocmt)
363 ::= match ocmt case SOME(cmt) then dumpComment(cmt)
364 end dumpCommentOpt;
365
366 85279 template dumpElementArgList(list<Absyn.ElementArg> elementArgs, Text separator)
367 ::=
368 shouldSeparateAfterElementArg(elementArgs) |> (earg,b) => (dumpElementArg(earg) + (if b then separator))
369 end dumpElementArgList;
370
371 134618 template dumpElementArg(Absyn.ElementArg earg)
372 ::=
373 match earg
374 case MODIFICATION(__) then
375 let each_str = dumpEach(eachPrefix)
376 let final_str = dumpFinal(finalPrefix)
377 let path_str = dumpPath(path)
378 let mod_str = match modification case SOME(mod) then dumpModification(mod)
379 let cmt_str = dumpStringCommentOption(comment)
380 '<%each_str%><%final_str%><%path_str%><%mod_str%><%cmt_str%>'
381 case REDECLARATION(__) then
382 let each_str = dumpEach(eachPrefix)
383 let final_str = dumpFinal(finalPrefix)
384 let redecl_str = dumpRedeclare(redeclareKeywords)
385 let repl_str = dumpReplaceable(redeclareKeywords)
386 let eredecl_str = '<%redecl_str%><%each_str%>'
387 let elem_str = dumpElementSpec(elementSpec, final_str, eredecl_str, repl_str, "", defaultDumpOptions)
388 let cc_str = match constrainClass case SOME(cc) then dumpConstrainClass(cc)
389 '<%elem_str%><%cc_str%>'
390 case ELEMENTARGCOMMENT(__) then (" " + comment ; absIndent=0)
391 end dumpElementArg;
392
393 788 template dumpEach(Absyn.Each each)
394 ::= match each case EACH() then "each "
395 end dumpEach;
396
397 5648 template dumpFinal(Boolean final)
398 ::= if final then "final "
399 end dumpFinal;
400
401 913 template dumpRedeclare(Absyn.RedeclareKeywords redecl)
402 ::=
403 match redecl
404 case REDECLARE() then "redeclare "
405 case REDECLARE_REPLACEABLE() then "redeclare "
406 end dumpRedeclare;
407
408 205 template dumpReplaceable(Absyn.RedeclareKeywords repl)
409 ::=
410 match repl
411 case REPLACEABLE() then "replaceable "
412 case REDECLARE_REPLACEABLE() then "replaceable "
413 end dumpReplaceable;
414
415 89 template dumpInnerOuter(Absyn.InnerOuter io)
416 ::=
417 match io
418 case INNER() then "inner "
419 case OUTER() then "outer "
420 case INNER_OUTER() then "inner outer "
421 end dumpInnerOuter;
422
423 154406 template dumpModification(Absyn.Modification mod)
424 ::=
425 match mod
426 case CLASSMOD(__) then
427 let arg_str = if elementArgLst then
428 '(<%dumpElementArgList(elementArgLst, ", ")%>)'
429 let eq_str = dumpEqMod(eqMod)
430 '<%arg_str%><%eq_str%>'
431 end dumpModification;
432
433 102823 template dumpEqMod(Absyn.EqMod eqmod)
434 ::= match eqmod case EQMOD(__) then '<%\ %>= <%dumpExp(exp)%>'
435 end dumpEqMod;
436
437 33057 template dumpElementSpec(Absyn.ElementSpec elem, String final, String redecl,
438 String repl, String io, DumpOptions options)
439 ::=
440 match elem
441 case CLASSDEF(__) then dumpClassElement(class_, final, redecl, repl, io, "", options)
442 case EXTENDS(__) then
443 let bc_str = dumpPath(path)
444 let args_str = dumpElementArgList(elementArg, ', ')
445 let mod_str = if args_str then '(<%args_str%>)'
446 let ann_str = dumpAnnotationOptSpace(annotationOpt)
447 'extends <%bc_str%><%mod_str%><%ann_str%>'
448 case COMPONENTS(__) then
449 let ty_str = dumpTypeSpec(typeSpec)
450 let attr_str = dumpElementAttr(attributes)
451 let dim_str = dumpElementAttrDim(attributes)
452 let comps_str = (components |> comp => dumpComponentItem(comp) ;separator=", ")
453 let prefix_str = '<%redecl%><%final%><%io%><%repl%>'
454 '<%prefix_str%><%attr_str%><%ty_str%><%dim_str%> <%comps_str%>'
455 case IMPORT(__) then
456 let imp_str = dumpImport(import_)
457 'import <%imp_str%><%dumpCommentOpt(comment)%>'
458 end dumpElementSpec;
459
460 34180 template dumpElementAttr(Absyn.ElementAttributes attr)
461 ::=
462 match attr
463 case ATTR(__) then
464 let flow_str = if flowPrefix then "flow "
465 let stream_str = if streamPrefix then "stream "
466 let par_str = dumpParallelism(parallelism)
467 let field_str = dumpIsField(isField)
468 let var_str = dumpVariability(variability)
469 let dir_str = dumpDirection(direction)
470 '<%flow_str%><%stream_str%><%par_str%><%field_str%><%var_str%><%dir_str%>'
471 end dumpElementAttr;
472
473 ✗ template dumpParallelism(Absyn.Parallelism par)
474 ::=
475 match par
476 case PARGLOBAL() then "parglobal "
477 case PARLOCAL() then "parlocal "
478 case NON_PARALLEL() then ""
479 end dumpParallelism;
480
481 ✗ template dumpIsField(Absyn.IsField isField)
482 ::=
483 match isField
484 case NONFIELD() then ""
485 case FIELD() then "field "
486 end dumpIsField;
487
488 7004 template dumpVariability(Absyn.Variability var)
489 ::=
490 match var
491 case VAR() then ""
492 case DISCRETE() then "discrete "
493 case PARAM() then "parameter "
494 case CONST() then "constant "
495 end dumpVariability;
496
497 4252 template dumpDirection(Absyn.Direction dir)
498 ::=
499 match dir
500 case BIDIR() then ""
501 case INPUT() then "input "
502 case OUTPUT() then "output "
503 case INPUT_OUTPUT() then "input output "
504 end dumpDirection;
505
506 33057 template dumpElementAttrDim(Absyn.ElementAttributes attr)
507 ::= match attr case ATTR(__) then dumpSubscripts(arrayDim)
508 end dumpElementAttrDim;
509
510 38 template dumpConstrainClass(Absyn.ConstrainClass cc)
511 ::=
512 match cc
513 case CONSTRAINCLASS(elementSpec = Absyn.EXTENDS(path = p, elementArg = el)) then
514 let path_str = dumpPath(p)
515 let el_str = if el then '(<%dumpElementArgList(el, ', ')%>)'
516 let cmt_str = dumpCommentOpt(comment)
517 ' constrainedby <%path_str%><%el_str%><%cmt_str%>'
518 end dumpConstrainClass;
519
520 33088 template dumpComponentItem(Absyn.ComponentItem comp)
521 ::=
522 match comp
523 case COMPONENTITEM(__) then
524 let comp_str = dumpComponent(component)
525 let cond_str = dumpComponentCondition(condition)
526 let cmt = dumpCommentOpt(comment)
527 '<%comp_str%><%cond_str%><%cmt%>'
528 end dumpComponentItem;
529
530 33088 template dumpComponent(Absyn.Component comp)
531 ::=
532 match comp
533 case COMPONENT(__) then
534 let dim_str = dumpSubscripts(arrayDim)
535 let mod_str = match modification case SOME(mod) then dumpModification(mod)
536 '<%name%><%dim_str%><%mod_str%>'
537 end dumpComponent;
538
539 594 template dumpComponentCondition(Option<Absyn.ComponentCondition> cond)
540 ::=
541 match cond
542 case SOME(cexp) then
543 let exp_str = dumpExp(cexp)
544 ' if <%exp_str%>'
545 end dumpComponentCondition;
546
547 757 template dumpImport(Absyn.Import imp)
548 ::=
549 match imp
550 case NAMED_IMPORT(__) then '<%name%> = <%dumpPath(path)%>'
551 case QUAL_IMPORT(__) then dumpPath(path)
552 case UNQUAL_IMPORT(__) then '<%dumpPath(path)%>.*'
553 case GROUP_IMPORT(__) then
554 let prefix_str = dumpPath(prefix)
555 let groups_str = (groups |> group => dumpGroupImport(group) ;separator=",")
556 '<%prefix_str%>.{<%groups_str%>}'
557 end dumpImport;
558
559 42 template dumpGroupImport(Absyn.GroupImport gimp)
560 ::=
561 match gimp
562 case GROUP_IMPORT_NAME(__) then name
563 case GROUP_IMPORT_RENAME(__) then '<%rename%> = <%name%>'
564 end dumpGroupImport;
565
566 15818 template dumpEquationItem(Absyn.EquationItem eq)
567 ::=
568 match eq
569 case EQUATIONITEM(__) then
570 let eq_str = dumpEquation(equation_)
571 let cmt_str = dumpCommentOpt(comment)
572 '<%eq_str%><%cmt_str%>;'
573 case EQUATIONITEMCOMMENT(__) then (System.trimWhitespace(comment) ; absIndent=0)
574 end dumpEquationItem;
575
576 666 template dumpEquationItems(list<Absyn.EquationItem> eql)
577 ::= (eql |> eq => dumpEquationItem(eq) ;separator="\n")
578 end dumpEquationItems;
579
580 9637 template dumpEquation(Absyn.Equation eq)
581 ::=
582 match eq
583 case EQ_IF(__) then
584 let if_str = dumpEquationBranch(ifExp, equationTrueItems, "if")
585 let elseif_str = (elseIfBranches |> (c, b) =>
586 dumpEquationBranch(c, b, "elseif") ;separator="\n")
587 let else_branch_str = dumpEquationItems(equationElseItems)
588 let else_str = if else_branch_str then
589 <<
590 else
591 <%else_branch_str%>
592 >>
593 <<
594 <%if_str%>
595 <%elseif_str%>
596 <%else_str%>
597 end if
598 >>
599 case EQ_EQUALS(__) then
600 let lhs = dumpLhsExp(leftSide)
601 let rhs = dumpExp(rightSide)
602 '<%lhs%> = <%rhs%>'
603 case EQ_PDE(__) then
604 let lhs = dumpLhsExp(leftSide)
605 let rhs = dumpExp(rightSide)
606 let domain_str = dumpCref(domain)
607 '<%lhs%> = <%rhs%> indomain <%domain_str%>'
608 case EQ_CONNECT(__) then
609 let c1_str = dumpCref(connector1)
610 let c2_str = dumpCref(connector2)
611 'connect(<%c1_str%>, <%c2_str%>)'
612 case EQ_FOR(__) then
613 let iter_str = dumpForIterators(iterators)
614 let body_str = dumpEquationItems(forEquations)
615 <<
616 for <%iter_str%> loop
617 <%body_str%>
618 end for
619 >>
620 case EQ_WHEN_E(__) then
621 let when_str = dumpEquationBranch(whenExp, whenEquations, "when")
622 let elsewhen_str = (elseWhenEquations |> (c, b) =>
623 dumpEquationBranch(c, b, "elsewhen") ;separator="\n")
624 <<
625 <%when_str%>
626 <%elsewhen_str%>
627 end when
628 >>
629 case EQ_NORETCALL(__) then
630 let name_str = dumpCref(functionName)
631 let args_str = dumpFunctionArgs(functionArgs)
632 '<%name_str%>(<%args_str%>)'
633 case EQ_FAILURE(__) then
634 let eq_str = dumpEquationItem(equ)
635 'failure(<%eq_str%>)'
636 end dumpEquation;
637
638 710 template dumpEquationBranch(Absyn.Exp cond, list<Absyn.EquationItem> body, String header)
639 ::=
640 let cond_str = dumpExp(cond)
641 let body_str = (body |> eq => dumpEquationItem(eq) ;separator="\n")
642 <<
643 <%header%> <%cond_str%> then
644 <%body_str%>
645 >>
646 end dumpEquationBranch;
647
648 1090 template dumpAlgorithmItems(list<Absyn.AlgorithmItem> algs)
649 ::= (algs |> alg => dumpAlgorithmItem(alg) ;separator="\n")
650 end dumpAlgorithmItems;
651
652 10020 template dumpAlgorithmItem(Absyn.AlgorithmItem alg)
653 ::=
654 match alg
655 case ALGORITHMITEM(__) then
656 let alg_str = dumpAlgorithm(algorithm_)
657 let cmt_str = dumpCommentOpt(comment)
658 '<%alg_str%><%cmt_str%>;'
659 case ALGORITHMITEMCOMMENT(__) then (System.trimWhitespace(comment) ; absIndent=0)
660 end dumpAlgorithmItem;
661
662 8429 template dumpAlgorithm(Absyn.Algorithm alg)
663 ::=
664 match alg
665 case ALG_ASSIGN(__) then
666 let lhs_str = dumpLhsExp(assignComponent)
667 let rhs_str = dumpExp(value)
668 '<%lhs_str%> := <%rhs_str%>'
669 case ALG_IF(__) then
670 let if_str = dumpAlgorithmBranch(ifExp, trueBranch, "if", "then")
671 let elseif_str = (elseIfAlgorithmBranch |> (c, b) =>
672 dumpAlgorithmBranch(c, b, "elseif", "then") ;separator="\n")
673 let else_branch_str = dumpAlgorithmItems(elseBranch)
674 let else_str = if else_branch_str then
675 <<
676 else
677 <%else_branch_str%>
678 >>
679 <<
680 <%if_str%>
681 <%elseif_str%>
682 <%else_str%>
683 end if
684 >>
685 case ALG_FOR(__) then
686 let iter_str = dumpForIterators(iterators)
687 let body_str = dumpAlgorithmItems(forBody)
688 <<
689 for <%iter_str%> loop
690 <%body_str%>
691 end for
692 >>
693 case ALG_PARFOR(__) then
694 let iter_str = dumpForIterators(iterators)
695 let body_str = dumpAlgorithmItems(parforBody)
696 <<
697 parfor <%iter_str%> loop
698 <%body_str%>
699 end parfor
700 >>
701 case ALG_WHILE(__) then
702 let while_str = dumpAlgorithmBranch(boolExpr, whileBody, "while", "loop")
703 <<
704 <%while_str%>
705 end while
706 >>
707 case ALG_WHEN_A(__) then
708 let when_str = dumpAlgorithmBranch(boolExpr, whenBody, "when", "then")
709 let elsewhen_str = (elseWhenAlgorithmBranch |> (c, b) =>
710 dumpAlgorithmBranch(c, b, "elsewhen", "then") ;separator="\n")
711 <<
712 <%when_str%>
713 <%elsewhen_str%>
714 end when
715 >>
716 case ALG_NORETCALL(__) then
717 let name_str = dumpCref(functionCall)
718 let args_str = dumpFunctionArgs(functionArgs)
719 '<%name_str%>(<%args_str%>)'
720 case ALG_RETURN(__) then "return"
721 case ALG_BREAK(__) then "break"
722 case ALG_FAILURE(__) then
723 let arg_str = if equ then dumpAlgorithmItems(equ) else "..."
724 'failure(<%arg_str%>)'
725 case ALG_TRY(__) then
726 let arg1 = dumpAlgorithmItems(body)
727 let arg2 = dumpAlgorithmItems(elseBody)
728 <<
729 try
730 <%arg1%>
731 else
732 <%arg2%>
733 end try;
734 >>
735 case ALG_CONTINUE(__) then "continue"
736 end dumpAlgorithm;
737
738 1226 template dumpAlgorithmBranch(Absyn.Exp cond, list<Absyn.AlgorithmItem> body,
739 String header, String exec_str)
740 ::=
741 let cond_str = dumpExp(cond)
742 let body_str = (body |> eq => dumpAlgorithmItem(eq) ;separator="\n")
743 <<
744 <%header%> <%cond_str%> <%exec_str%>
745 <%body_str%>
746 >>
747 end dumpAlgorithmBranch;
748
749 622754 template dumpPath(Absyn.Path path)
750 ::=
751 match path
752 case FULLYQUALIFIED(__) then
753 '.<%dumpPath(path)%>'
754 case QUALIFIED(__) then
755 if (Flags.getConfigBool(Flags.MODELICA_OUTPUT)) then
756 '<%name%>__<%dumpPath(path)%>'
757 else
758 '<%name%>.<%dumpPath(path)%>'
759 case IDENT(__) then
760 '<%name%>'
761 else
762 errorMsg("SCodeDump.dumpPath: Unknown path.")
763 end dumpPath;
764
765 203009 template dumpPathNoQual(Absyn.Path path)
766 ::=
767 match path
768 case FULLYQUALIFIED(__) then
769 dumpPath(path)
770 else
771 dumpPath(path)
772 end dumpPathNoQual;
773
774 26004 template dumpStringCommentOption(Option<String> cmt)
775 ::= match cmt case SOME(str) then '<%\ %>"<%str%>"'
776 end dumpStringCommentOption;
777
778 36157 template dumpTypeSpec(Absyn.TypeSpec typeSpec)
779 ::=
780 match typeSpec
781 case TPATH(__) then
782 let path_str = dumpPath(path)
783 let arraydim_str = dumpArrayDimOpt(arrayDim)
784 '<%path_str%><%arraydim_str%>'
785 case TCOMPLEX(__) then
786 let path_str = dumpPath(path)
787 let ty_str = (typeSpecs |> ty => dumpTypeSpec(ty) ;separator=", ")
788 let arraydim_str = dumpArrayDimOpt(arrayDim)
789 '<%path_str%><<%ty_str%>><%arraydim_str%>'
790 end dumpTypeSpec;
791
792 8 template dumpArrayDimOpt(Option<Absyn.ArrayDim> arraydim)
793 ::= match arraydim case SOME(ad) then dumpSubscripts(ad)
794 end dumpArrayDimOpt;
795
796 14487 template dumpSubscripts(list<Subscript> subscripts)
797 ::=
798 if subscripts then
799 let sub_str = (subscripts |> s => dumpSubscript(s) ;separator=", ")
800 '[<%sub_str%>]'
801 end dumpSubscripts;
802
803 15869 template dumpSubscript(Absyn.Subscript subscript)
804 ::=
805 match subscript
806 case NOSUB(__) then ':'
807 case SUBSCRIPT(__) then dumpExp(subscript)
808 end dumpSubscript;
809
810 264320 template dumpExp(Absyn.Exp exp)
811 ::=
812 match exp
813 case INTEGER(__) then value
814 case REAL(__) then value
815 case CREF(__) then dumpCref(componentRef)
816 case STRING(__) then ('"<%value; absIndent=0%>"')
817 case BOOL(__) then value
818 case e as BINARY(__) then
819 let lhs_str = dumpOperand(exp1, e, true)
820 let rhs_str = dumpOperand(exp2, e, false)
821 let op_str = dumpOperator(op)
822 '<%lhs_str%><%op_str%><%rhs_str%>'
823 case e as UNARY(__) then
824 let exp_str = dumpOperand(exp, e, false)
825 let op_str = dumpOperator(op)
826 '<%op_str%><%exp_str%>'
827 case e as LBINARY(__) then
828 let lhs_str = dumpOperand(exp1, e, true)
829 let rhs_str = dumpOperand(exp2, e, false)
830 let op_str = dumpOperator(op)
831 '<%lhs_str%><%op_str%><%rhs_str%>'
832 case e as LUNARY(__) then
833 let exp_str = dumpOperand(exp, e, false)
834 let op_str = dumpOperator(op)
835 '<%op_str%> <%exp_str%>'
836 case e as RELATION(__) then
837 let lhs_str = dumpOperand(exp1, e, true)
838 let rhs_str = dumpOperand(exp2, e, false)
839 let op_str = dumpOperator(op)
840 '<%lhs_str%><%op_str%><%rhs_str%>'
841 case IFEXP(__) then dumpIfExp(exp)
842 case CALL(function_=Absyn.CREF_IDENT(name="$array")) then
843 let args_str = dumpFunctionArgs(functionArgs)
844 '{<%args_str%>}'
845 case CALL(__) then
846 let func_str = dumpCref(function_)
847 let args_str = dumpFunctionArgs(functionArgs)
848 let tvs_str = if typeVars then '<<%(typeVars |> v => dumpPath(v) ;separator=", ")%>>'
849 '<%func_str%><%tvs_str%>(<%args_str%>)'
850 case PARTEVALFUNCTION(__) then
851 let func_str = dumpCref(function_)
852 let args_str = dumpFunctionArgs(functionArgs)
853 'function <%func_str%>(<%args_str%>)'
854 case ARRAY(__) then
855 let array_str = (arrayExp |> e => dumpExp(e) ;separator=", ")
856 '{<%array_str%>}'
857 case MATRIX(__) then
858 let matrix_str = (matrix |> row =>
859 (row |> e => dumpExp(e) ;separator=", ") ;separator="; ")
860 '[<%matrix_str%>]'
861 case e as RANGE(step = SOME(step)) then
862 let start_str = dumpOperand(start, e, false)
863 let step_str = dumpOperand(step, e, false)
864 let stop_str = dumpOperand(stop, e, false)
865 '<%start_str%>:<%step_str%>:<%stop_str%>'
866 case e as RANGE(step = NONE()) then
867 let start_str = dumpOperand(start, e, false)
868 let stop_str = dumpOperand(stop, e, false)
869 '<%start_str%>:<%stop_str%>'
870 case TUPLE(__) then
871 let tuple_str = (expressions |> e => dumpExp(e); separator=", " ;empty)
872 '(<%tuple_str%>)'
873 case END(__) then 'end'
874 case CODE(__) then '$Code(<%dumpCodeNode(code)%>)'
875 case AS(__) then
876 let exp_str = dumpExp(exp)
877 '<%id%> as <%exp_str%>'
878 case CONS(__) then
879 let head_str = dumpExp(head)
880 let rest_str = dumpExp(rest)
881 '<%head_str%> :: <%rest_str%>'
882 case MATCHEXP(__) then dumpMatchExp(exp)
883 case LIST(__) then
884 let list_str = (exps |> e => dumpExp(e) ;separator=", ")
885 '{<%list_str%>}'
886 case DOT(__) then
887 '(<%dumpExp(exp)%>).<%dumpExp(index)%>'
888 case EXPRESSIONCOMMENT(__) then
889 ((commentsBefore |> cmt => cmt ; absIndent=0) + dumpExp(exp) + (commentsAfter |> cmt => cmt ; absIndent=0))
890 case SUBSCRIPTED_EXP(__) then
891 '(<%dumpExp(exp)%>)[<%dumpSubscripts(subscripts)%>]'
892 case BREAK(__) then 'break'
893 case UNITFUL_LITERAL(__) then dumpExp(value) + "'" + unit + "'"
894 case _ then '/* AbsynDumpTpl.dumpExp: UNHANDLED Abyn.Exp */'
895 end dumpExp;
896
897 14029 template dumpLhsExp(Absyn.Exp lhs)
898 ::=
899 match lhs
900 case IFEXP(__) then '(<%dumpExp(lhs)%>)'
901 else dumpExp(lhs)
902 end dumpLhsExp;
903
904 195885 template dumpOperand(Absyn.Exp operand, Absyn.Exp operation, Boolean lhs)
905 ::=
906 let op_str = dumpExp(operand)
907 /* if shouldParenthesize(operand, operation, lhs) then
908 '(<%op_str%>)'
909 else */
910 op_str
911 end dumpOperand;
912
913 1808 template dumpIfExp(Absyn.Exp if_exp)
914 ::=
915 match if_exp
916 case IFEXP(__) then
917 let cond_str = dumpExp(ifExp)
918 let true_branch_str = dumpExp(trueBranch)
919 let else_branch_str = dumpExp(elseBranch)
920 let else_if_str = dumpElseIfExp(elseIfBranch)
921 'if <%cond_str%> then <%true_branch_str%><%else_if_str%> else <%else_branch_str%>'
922 end dumpIfExp;
923
924 1808 template dumpElseIfExp(list<tuple<Absyn.Exp, Absyn.Exp>> else_if)
925 ::=
926 else_if |> eib as (cond, branch) =>
927 let cond_str = dumpExp(cond)
928 let branch_str = dumpExp(branch)
929 ' elseif <%cond_str%> then <%branch_str%>' ;separator="\n"
930 end dumpElseIfExp;
931
932 22 template dumpCodeNode(Absyn.CodeNode code)
933 ::=
934 match code
935 case C_TYPENAME(__) then dumpPath(path)
936 case C_VARIABLENAME(__) then dumpCref(componentRef)
937 case C_CONSTRAINTSECTION(__) then
938 let initial_str = if boolean then "initial " else ""
939 let eql_str = dumpEquationItems(equationItemLst)
940 <<
941 <%initial_str%>constraint
942 <%eql_str%>
943 >>
944 case C_EQUATIONSECTION(__) then
945 let initial_str = if boolean then "initial " else ""
946 let eql_str = dumpEquationItems(equationItemLst)
947 <<
948 <%initial_str%>equation
949 <%eql_str%>
950 >>
951 case C_ALGORITHMSECTION(__) then
952 let initial_str = if boolean then "initial " else ""
953 let algs_str = dumpAlgorithmItems(algorithmItemLst)
954 <<
955 <%initial_str%>algorithm
956 <%algs_str%>
957 >>
958 case C_ELEMENT(__) then dumpElement(element, Dump.defaultDumpOptions)
959 case C_EXPRESSION(__) then dumpExp(exp)
960 case C_MODIFICATION(__) then dumpModification(modification)
961 end dumpCodeNode;
962
963 ✗ template dumpMatchExp(Absyn.Exp match_exp)
964 ::=
965 match match_exp
966 case MATCHEXP(__) then
967 let ty_str = dumpMatchType(matchTy)
968 let input_str = dumpExp(inputExp)
969 let locals_str = dumpMatchLocals(localDecls)
970 let cases_str = (cases |> c => dumpMatchCase(c) ;separator="\n\n")
971 let cmt_str = dumpStringCommentOption(comment)
972 <<
973 <%ty_str%> <%input_str%>
974 <%locals_str%>
975 <%cases_str%><%cmt_str%>
976 end <%ty_str%>
977 >>
978 end dumpMatchExp;
979
980 ✗ template dumpMatchType(Absyn.MatchType match_type)
981 ::=
982 match match_type
983 case MATCH() then "match"
984 case MATCHCONTINUE() then "matchcontinue"
985 end dumpMatchType;
986
987 ✗ template dumpMatchLocals(list<ElementItem> locals)
988 ::= if locals then
989 <<
990 local
991 <%(locals |> decl => dumpElementItem(decl, defaultDumpOptions) ;separator="\n")%>
992
993 >>
994 end dumpMatchLocals;
995
996 ✗ template dumpMatchEquations(ClassPart cp)
997 ::=
998 match cp
999 case EQUATIONS(contents={}) then ""
1000 case EQUATIONS(contents=eql) then
1001 <<
1002
1003 equation
1004 <%(eql |> eq => dumpEquationItem(eq) ;separator="\n")%>
1005 >>
1006 case ALGORITHMS(contents={}) then ""
1007 case ALGORITHMS(contents=algs) then
1008 <<
1009
1010 algorithm
1011 <%(algs |> alg => dumpAlgorithmItem(alg) ;separator="\n")%>
1012 >>
1013 end dumpMatchEquations;
1014
1015 ✗ template dumpMatchCase(Absyn.Case c)
1016 ::=
1017 match c
1018 case CASE(__) then
1019 let pattern_str = dumpExp(pattern)
1020 let guard_str = match patternGuard case SOME(g) then 'guard <%dumpExp(g)%> '
1021 let eql_str = dumpMatchEquations(classPart)
1022 let result_str = dumpExp(result)
1023 let then_str = if eql_str then
1024 <<
1025
1026 then
1027 <%result_str%>
1028 >>
1029 else 'then <%result_str%>'
1030 let cmt_str = dumpStringCommentOption(comment)
1031 <<
1032 case <%pattern_str%> <%guard_str%><%cmt_str%><%eql_str%><%then_str%>;
1033 >>
1034 case ELSE(__) then
1035 let eql_str = dumpMatchEquations(classPart)
1036 let result_str = dumpExp(result)
1037 let then_str = if eql_str then
1038 <<
1039
1040 then
1041 <%result_str%>
1042 >>
1043 else 'then <%result_str%>'
1044 let cmt_str = dumpStringCommentOption(comment)
1045 <<
1046 else <%cmt_str%><%eql_str%><%then_str%>;
1047 >>
1048 end dumpMatchCase;
1049
1050 105619 template dumpOperator(Absyn.Operator op)
1051 ::=
1052 match op
1053 case ADD(__) then ' + '
1054 case SUB(__) then ' - '
1055 case MUL(__) then '*'
1056 case DIV(__) then '/'
1057 case POW(__) then '^'
1058 case UPLUS(__) then '+'
1059 case UMINUS(__) then '-'
1060 case ADD_EW(__) then ' .+ '
1061 case SUB_EW(__) then ' .- '
1062 case MUL_EW(__) then '.*'
1063 case DIV_EW(__) then './'
1064 case POW_EW(__) then '.^'
1065 case UPLUS_EW(__) then ' .+ '
1066 case UMINUS_EW(__) then ' .- '
1067 case AND(__) then ' and '
1068 case OR(__) then ' or '
1069 case NOT(__) then 'not'
1070 case LESS(__) then ' < '
1071 case LESSEQ(__) then ' <= '
1072 case GREATER(__) then ' > '
1073 case GREATEREQ(__) then ' >= '
1074 case EQUAL(__) then ' == '
1075 case NEQUAL(__) then ' <> '
1076 end dumpOperator;
1077
1078 148260 template dumpCref(Absyn.ComponentRef cref)
1079 ::=
1080 match cref
1081 case CREF_QUAL(__) then
1082 '<%name%><%dumpSubscripts(subscripts)%>.<%dumpCref(componentRef)%>'
1083 case CREF_IDENT(__)
1084 then '<%name%><%dumpSubscripts(subscripts)%>'
1085 case CREF_FULLYQUALIFIED(__) then '.<%dumpCref(componentRef)%>'
1086 case WILD(__) then if Config.acceptMetaModelicaGrammar() then "_" else ""
1087 case ALLWILD(__) then '__'
1088 end dumpCref;
1089
1090 26050 template dumpFunctionArgs(Absyn.FunctionArgs args)
1091 ::=
1092 match args
1093 case FUNCTIONARGS(__) then
1094 let args_str = (args |> arg => dumpExp(arg) ;separator=", ")
1095 let namedargs_str = (argNames |> narg => dumpNamedArg(narg) ;separator=", ")
1096 let separator = if args_str then if argNames then ', '
1097 '<%args_str%><%separator%><%namedargs_str%>'
1098 case FOR_ITER_FARG(__) then
1099 let exp_str = dumpExp(exp)
1100 let iter_str = (iterators |> i => dumpForIterator(i) ;separator=", ")
1101 '<%exp_str%> <%match iterType case THREAD(__) then "threaded "%>for <%iter_str%>'
1102 end dumpFunctionArgs;
1103
1104 32595 template dumpNamedArg(Absyn.NamedArg narg)
1105 ::=
1106 match narg
1107 case NAMEDARG(__) then
1108 '<%argName%> = <%dumpExp(argValue)%>'
1109 end dumpNamedArg;
1110
1111 427 template dumpForIterators(Absyn.ForIterators iters)
1112 ::= (iters |> i => dumpForIterator(i) ;separator=", ")
1113 end dumpForIterators;
1114
1115 635 template dumpForIterator(Absyn.ForIterator iterator)
1116 ::=
1117 match iterator
1118 case ITERATOR(__) then
1119 let range_str = match range case SOME(r) then ' in <%dumpExp(r)%>'
1120 let guard_str = match guardExp case SOME(g) then ' guard <%dumpExp(g)%>'
1121 '<%name%><%guard_str%><%range_str%>'
1122 end dumpForIterator;
1123
1124 ✗ template errorMsg(String errMessage)
1125 ::=
1126 let() = Tpl.addTemplateError(errMessage)
1127 <<
1128 <%errMessage%>
1129 >>
1130 end errorMsg;
1131
1132 annotation(__OpenModelica_Interface="frontend_dump");
1133 end AbsynDumpTpl;
1134