Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 21.9% 245 / 0 / 1118
Functions: -% 0 / 1 / 1
Branches: 13.3% 12 / 0 / 90

OMCompiler/Compiler/FrontEnd/DAEDump.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 DAEDump
37 " file: DAEDump.mo
38 package: DAEDump
39 description: DAEDump output
40
41
42 This module implements functions to print the DAE AST."
43
44 // public imports
45 public import DAE;
46 public import Graphviz;
47 public import IOStream;
48 public import SCode;
49
50 // protected imports
51 protected import ComponentReference;
52 protected import ComponentReferenceBasics;
53 protected import Config;
54 protected import DAEUtil;
55 protected import DAEDumpTypes;
56 protected import DAEDumpTypes.*;
57 protected import ElementSource;
58 protected import Error;
59 protected import Print;
60 protected import Util;
61 protected import Expression;
62 protected import ExpressionBasics;
63 protected import ExpressionDump;
64 protected import Absyn;
65 protected import AbsynUtil;
66 protected import Dump;
67 protected import ValuesDump;
68 protected import Values;
69 protected import Types;
70 protected import ClassInf;
71 protected import SCodeDump;
72 import SCodeUtil;
73 protected import List;
74 protected import Flags;
75 protected import DAEDumpTpl;
76 protected import Tpl;
77
78 public function dump "This function prints the DAE in the standard output format to the Print buffer.
79 For printing to the stdout use print(dumpStr(dae)) instead."
80 input DAE.DAElist dae;
81 input AvlTreePathFunction.Tree functionTree;
82 algorithm
83 () := match dae
84 local
85 list<DAE.Element> daelist;
86
87 case DAE.DAE(daelist)
88 algorithm
89 ✗ List.map_0(sortFunctions(DAEUtil.getFunctionList(functionTree)),dumpFunction);
90 ✗ List.map_0(daelist, dumpExtObjectClass);
91 ✗ List.map_0(daelist, dumpCompElement);
92 then
93 ();
94 end match;
95 end dump;
96
97 public function dumpFunctionNamesStr "return all function names in a string (comma separated)"
98 input AvlTreePathFunction.Tree funcs;
99 output String str;
100 algorithm
101 ✗ str := stringDelimitList(List.map(sortFunctions(DAEUtil.getFunctionList(funcs)),functionNameStr),",");
102 end dumpFunctionNamesStr;
103
104 public function functionNameStr
105 "return the name of a function, if element is not function return empty string"
106 input DAE.Function inElement;
107 output String res;
108 algorithm
109 res := matchcontinue inElement
110 local
111 Absyn.Path fpath;
112
113 case DAE.FUNCTION(path = fpath)
114 algorithm
115 1919 res := AbsynUtil.pathStringNoQual(fpath);
116 then res;
117 case DAE.RECORD_CONSTRUCTOR(path = fpath)
118 algorithm
119 589 res := AbsynUtil.pathStringNoQual(fpath);
120 then res;
121 else "";
122 end matchcontinue;
123 end functionNameStr;
124
125 protected function sortFunctions "sorts the functions and record constructors in alphabetical order"
126 input list<DAE.Function> funcs;
127 output list<DAE.Function> sortedFuncs;
128 algorithm
129 1026 sortedFuncs := List.sort(funcs,funcGreaterThan);
130 end sortFunctions;
131
132 protected function funcGreaterThan "sorting function for two DAE.Element that are functions or record constuctors"
133 input DAE.Function func1;
134 input DAE.Function func2;
135 output Boolean res;
136 algorithm
137 res := match func2
138 case _ algorithm
139 1254 res := stringCompare(functionNameStr(func1),functionNameStr(func2)) > 0;
140 then res;
141 else true;
142 end match;
143 end funcGreaterThan;
144
145 public function dumpOperatorString "
146 Author bz printOperator
147 Dump operator to a string."
148 input DAE.Operator op;
149 output String str;
150 algorithm
151 str := match op
152 local
153 Absyn.Path p;
154 case DAE.ADD() then " ADD ";
155 case DAE.SUB() then " SUB ";
156 case DAE.MUL() then " MUL ";
157 case DAE.DIV() then " DIV ";
158 case DAE.POW() then " POW ";
159 case DAE.UMINUS() then " UMINUS ";
160 case DAE.UMINUS_ARR() then " UMINUS_ARR ";
161 case DAE.ADD_ARR() then " ADD_ARR ";
162 case DAE.SUB_ARR() then " SUB_ARR ";
163 case DAE.MUL_ARR() then " MUL_ARR ";
164 case DAE.DIV_ARR() then " DIV_ARR ";
165 case DAE.MUL_ARRAY_SCALAR() then " MUL_ARRAY_SCALAR ";
166 case DAE.ADD_ARRAY_SCALAR() then " ADD_ARRAY_SCALAR ";
167 case DAE.SUB_SCALAR_ARRAY() then " SUB_SCALAR_ARRAY ";
168 case DAE.MUL_SCALAR_PRODUCT() then " MUL_SCALAR_PRODUCT ";
169 case DAE.MUL_MATRIX_PRODUCT() then " MUL_MATRIX_PRODUCT ";
170 case DAE.DIV_ARRAY_SCALAR() then " DIV_ARRAY_SCALAR ";
171 case DAE.DIV_SCALAR_ARRAY() then " DIV_SCALAR_ARRAY ";
172 case DAE.POW_ARRAY_SCALAR() then " POW_ARRAY_SCALAR ";
173 case DAE.POW_SCALAR_ARRAY() then " POW_SCALAR_ARRAY ";
174 case DAE.POW_ARR() then " POW_ARR ";
175 case DAE.POW_ARR2() then " POW_ARR2 ";
176 case DAE.OR(_) then " OR ";
177 case DAE.AND(_) then " AND ";
178 case DAE.NOT(_) then " NOT ";
179 case DAE.LESSEQ() then " LESSEQ ";
180 case DAE.GREATER() then " GREATER ";
181 case DAE.GREATEREQ() then " GREATEREQ ";
182 case DAE.LESS() then " LESS ";
183 case DAE.EQUAL() then " EQUAL ";
184 case DAE.NEQUAL() then " NEQUAL ";
185 ✗ case DAE.USERDEFINED(p) then " Userdefined:" + AbsynUtil.pathString(p) + " ";
186 else " --UNDEFINED-- ";
187 end match;
188 end dumpOperatorString;
189
190 public function dumpOperatorSymbol "
191 Author bz printOperator
192 Dump operator to a string."
193 input DAE.Operator op;
194 output String str;
195 algorithm
196 str := match op
197 local
198 Absyn.Path p;
199 case DAE.ADD(_) then " + ";
200 case DAE.SUB(_) then " - ";
201 case DAE.MUL(_) then " .* ";
202 case DAE.DIV(_) then " / ";
203 case DAE.POW(_) then " ^ ";
204 case DAE.UMINUS(_) then " - ";
205 case DAE.UMINUS_ARR(_) then " - ";
206 case DAE.ADD_ARR(_) then " + ";
207 case DAE.SUB_ARR(_) then " - ";
208 case DAE.MUL_ARR(_) then " .* ";
209 case DAE.DIV_ARR(_) then " ./ ";
210 case DAE.MUL_ARRAY_SCALAR(_) then " * ";
211 case DAE.ADD_ARRAY_SCALAR(_) then " .+ ";
212 case DAE.SUB_SCALAR_ARRAY(_) then " .- ";
213 case DAE.MUL_SCALAR_PRODUCT(_) then " * ";
214 case DAE.MUL_MATRIX_PRODUCT(_) then " * ";
215 case DAE.DIV_ARRAY_SCALAR(_) then " / ";
216 case DAE.DIV_SCALAR_ARRAY(_) then " ./ ";
217 case DAE.POW_ARRAY_SCALAR(_) then " .^ ";
218 case DAE.POW_SCALAR_ARRAY(_) then " .^ ";
219 case DAE.POW_ARR(_) then " ^ ";
220 case DAE.POW_ARR2(_) then " .^ ";
221 case DAE.OR(_) then " or ";
222 case DAE.AND(_) then " and ";
223 case DAE.NOT(_) then " not ";
224 case DAE.LESSEQ(_) then " <= ";
225 case DAE.GREATER(_) then " > ";
226 case DAE.GREATEREQ(_) then " >= ";
227 case DAE.LESS(_) then " < ";
228 case DAE.EQUAL(_) then " == ";
229 case DAE.NEQUAL(_) then " <> ";
230 ✗ case DAE.USERDEFINED(p) then " Userdefined:" + AbsynUtil.pathString(p) + " ";
231 else " --UNDEFINED-- ";
232 end match;
233 end dumpOperatorSymbol;
234
235 protected function dumpStartValue "Dumps the StartValue for a variable."
236 input DAE.StartValue inStartValue;
237 algorithm
238 () := matchcontinue inStartValue
239 local
240 DAE.Exp e;
241 case SOME(e)
242 algorithm
243 ✗ Print.printBuf("(start=");
244 ✗ ExpressionDump.printExp(e);
245 ✗ Print.printBuf(")");
246 then
247 ();
248 else ();
249 end matchcontinue;
250 end dumpStartValue;
251
252 public function dumpStartValueStr "Dumps the start value for a variable to a string."
253 input DAE.StartValue inStartValue;
254 output String outString;
255 algorithm
256 outString := matchcontinue inStartValue
257 local
258 String s,res;
259 DAE.Exp e;
260 case SOME(e)
261 algorithm
262 ✗ s := ExpressionBasics.printExpStr(e);
263 ✗ res := stringAppendList({"(start=",s,")"});
264 then
265 res;
266 else "";
267 end matchcontinue;
268 end dumpStartValueStr;
269
270 public function dumpExtDeclStr "Dumps the external declaration to a string."
271 input DAE.ExternalDecl inExternalDecl;
272 output String outString;
273 algorithm
274 outString := match inExternalDecl
275 local
276 String extargsstr,rettystr,str,id,lang;
277 list<DAE.ExtArg> extargs;
278 DAE.ExtArg retty;
279 case DAE.EXTERNALDECL(name = id,args = extargs,returnArg = retty,language = lang)
280 algorithm
281 ✗ extargsstr := List.toStringCustom(extargs, dumpExtArgStr, "", "", ", ", "");
282 ✗ rettystr := dumpExtArgStr(retty);
283 ✗ rettystr := if stringEq(rettystr, "") then rettystr else (rettystr + " = ");
284 ✗ str := stringAppendList({"external \"", lang, "\" ", rettystr, id,"(",extargsstr,");"});
285 then
286 str;
287 end match;
288 end dumpExtDeclStr;
289
290 public function dumpExtArgStr "Helper function to dumpExtDeclStr"
291 input DAE.ExtArg inExtArg;
292 output String outString;
293 algorithm
294 outString := match inExtArg
295 local
296 String crstr,str,dimstr;
297 DAE.ComponentRef cr;
298 DAE.Exp exp,dim;
299
300 case DAE.NOEXTARG() then "";
301 case DAE.EXTARG(componentRef = cr)
302 algorithm
303 ✗ crstr := ComponentReferenceBasics.printComponentRefStr(cr);
304 then
305 crstr;
306 case DAE.EXTARGEXP(exp = exp)
307 algorithm
308 ✗ crstr := ExpressionBasics.printExpStr(exp);
309 then
310 crstr;
311 case DAE.EXTARGSIZE(componentRef = cr,exp = dim)
312 algorithm
313 ✗ crstr := ComponentReferenceBasics.printComponentRefStr(cr);
314 ✗ dimstr := ExpressionBasics.printExpStr(dim);
315 ✗ str := stringAppendList({"size(",crstr,", ",dimstr,")"});
316 then
317 str;
318 end match;
319 end dumpExtArgStr;
320
321 protected function dumpCompElement "Dumps Component elements."
322 input DAE.Element inElement;
323 algorithm
324 () := matchcontinue inElement
325 local
326 String n;
327 list<DAE.Element> l;
328 Option<SCode.Comment> c;
329 case DAE.COMP(ident = n,dAElist = l, comment = c)
330 algorithm
331 ✗ Print.printBuf("class ");
332 ✗ Print.printBuf(n);
333 ✗ dumpCommentOption(c);
334 ✗ Print.printBuf("\n");
335 ✗ dumpElements(l);
336 ✗ Print.printBuf("end ");
337 ✗ Print.printBuf(n);
338 ✗ Print.printBuf(";\n");
339 then
340 ();
341 else (); /* LS: for non-COMPS, which are only FUNCTIONS at the moment */
342 end matchcontinue;
343 end dumpCompElement;
344
345 public function dumpElements "Dump elements."
346 input list<DAE.Element> l;
347 algorithm
348 ✗ dumpVars(l, false);
349 ✗ List.map_0(l, dumpExtObjectClass);
350 ✗ Print.printBuf("initial equation\n");
351 ✗ List.map_0(l, dumpInitialEquation);
352 ✗ Print.printBuf("equation\n");
353 ✗ List.map_0(l, dumpEquation);
354 ✗ List.map_0(l, dumpInitialAlgorithm);
355 ✗ List.map_0(l, dumpAlgorithm);
356 ✗ List.map_0(l, dumpCompElement);
357 end dumpElements;
358
359 public function dumpFunctionElements "Dump function elements."
360 input list<DAE.Element> l;
361 algorithm
362 18 dumpVars(l, true);
363 18 List.map_0(l, dumpAlgorithm);
364 end dumpFunctionElements;
365
366 protected function dumpVars "Dump variables to Print buffer."
367 input list<DAE.Element> lst;
368 input Boolean printTypeDimension "use true here when printing components in functions as these are not vectorized! Otherwise, use false";
369 protected
370 String str;
371 IOStream.IOStream myStream;
372 algorithm
373 18 myStream := IOStream.create("", IOStream.LIST());
374 18 myStream := dumpVarsStream(lst, printTypeDimension, myStream);
375 18 str := IOStream.string(myStream);
376 18 Print.printBuf(str);
377 end dumpVars;
378
379 protected function dumpKind "Dump VarKind."
380 input DAE.VarKind inVarKind;
381 algorithm
382 () := match inVarKind
383 case DAE.CONST()
384 algorithm
385 ✗ Print.printBuf(" constant ");
386 then
387 ();
388 case DAE.PARAM()
389 algorithm
390 ✗ Print.printBuf(" parameter ");
391 then
392 ();
393 case DAE.DISCRETE()
394 algorithm
395 ✗ Print.printBuf(" discrete ");
396 then
397 ();
398 case DAE.VARIABLE()
399 algorithm
400 ✗ Print.printBuf(" ");
401 then
402 ();
403 end match;
404 end dumpKind;
405
406 public function dumpKindStr "Dump VarKind to a string."
407 input DAE.VarKind inVarKind;
408 output String outString;
409 algorithm
410 outString := match inVarKind
411 case DAE.CONST() then "constant ";
412 case DAE.PARAM() then "parameter ";
413 case DAE.DISCRETE() then "discrete ";
414 case DAE.VARIABLE() then "";
415 end match;
416 end dumpKindStr;
417
418 protected function dumpDirection "Dump VarDirection."
419 input DAE.VarDirection inVarDirection;
420 algorithm
421 () := match inVarDirection
422 case DAE.INPUT()
423 algorithm
424 ✗ Print.printBuf(" input ");
425 then
426 ();
427 case DAE.OUTPUT()
428 algorithm
429 ✗ Print.printBuf(" output ");
430 then
431 ();
432 case DAE.BIDIR()
433 algorithm
434 ✗ Print.printBuf(" ");
435 then
436 ();
437 end match;
438 end dumpDirection;
439
440 protected function dumpParallelism "Dump VarParallelism."
441 input DAE.VarParallelism inVarParallelism;
442 algorithm
443 () := match inVarParallelism
444 case DAE.NON_PARALLEL()
445 algorithm
446 ✗ Print.printBuf(" ");
447 then
448 ();
449 case DAE.PARGLOBAL()
450 algorithm
451 ✗ Print.printBuf(" parglobal ");
452 then
453 ();
454 case DAE.PARLOCAL()
455 algorithm
456 ✗ Print.printBuf(" parlocal ");
457 then
458 ();
459 end match;
460 end dumpParallelism;
461
462 public function dumpDirectionStr "Dump VarDirection to a string"
463 input DAE.VarDirection inVarDirection;
464 output String outString;
465 algorithm
466 outString := match inVarDirection
467 case DAE.INPUT() then "input ";
468 case DAE.OUTPUT() then "output ";
469 case DAE.BIDIR() then "";
470 end match;
471 end dumpDirectionStr;
472
473 protected function dumpStateSelectStr "Dump StateSelect to a string."
474 input DAE.StateSelect inStateSelect;
475 output String outString;
476 algorithm
477 outString := match inStateSelect
478 case DAE.NEVER() then "StateSelect.never";
479 case DAE.AVOID() then "StateSelect.avoid";
480 case DAE.PREFER() then "StateSelect.prefer";
481 case DAE.ALWAYS() then "StateSelect.always";
482 case DAE.DEFAULT() then "StateSelect.default";
483 end match;
484 end dumpStateSelectStr;
485
486 protected function dumpUncertaintyStr
487 "
488 Author: Daniel Hedberg 2011-01
489
490 Dump Uncertainty to a string.
491 "
492 input DAE.Uncertainty uncertainty;
493 output String out;
494 algorithm
495 out := match uncertainty
496 case DAE.GIVEN() then "Uncertainty.given";
497 case DAE.SOUGHT() then "Uncertainty.sought";
498 case DAE.REFINE() then "Uncertainty.refine";
499 case DAE.PROPAGATE() then "Uncertainty.propagate";
500 end match;
501 end dumpUncertaintyStr;
502
503 protected function dumpDistributionStr
504 "
505 Author: Peter Aronsson 2012
506
507 Dump Distribution to a string.
508 "
509 input DAE.Distribution distribution;
510 output String out;
511 algorithm
512 out := match distribution
513 local
514 DAE.Exp name;
515 DAE.Exp params;
516 DAE.Exp paramNames;
517 String name_str,params_str, paramNames_str;
518
519 case DAE.DISTRIBUTION(name = name, params = params,paramNames=paramNames) algorithm
520 ✗ name_str := ExpressionBasics.printExpStr(name);
521 ✗ params_str := ExpressionBasics.printExpStr(params);
522 ✗ paramNames_str := ExpressionBasics.printExpStr(paramNames);
523 ✗ then
524 "Distribution(name = " + name_str + ", params = " + params_str + ", paramNames= " + paramNames_str + ")";
525 end match;
526 end dumpDistributionStr;
527
528 public function dumpVariableAttributes "Dump VariableAttributes option."
529 input Option<DAE.VariableAttributes> attr;
530 protected
531 String res;
532 algorithm
533 ✗ res := dumpVariableAttributesStr(attr);
534 ✗ Print.printBuf(res);
535 end dumpVariableAttributes;
536
537 public function dumpVariableAttributesStr "Dump VariableAttributes option to a string."
538 input Option<DAE.VariableAttributes> inVariableAttributesOption;
539 output String outString;
540 algorithm
541 outString := matchcontinue inVariableAttributesOption
542 local
543 String quantity,unit_str,displayUnit_str,stateSel_str,min_str,max_str,nominal_str,initial_str,fixed_str,uncertainty_str,dist_str,res_1,res,startOriginStr;
544 Option<DAE.Exp> quant,unit,displayUnit,min,max,initialExp,nominal,fixed;
545 Option<DAE.StartOrigin> startOrigin;
546 Option<DAE.StateSelect> stateSel;
547 Option<DAE.Uncertainty> uncertainty;
548 Option<DAE.Distribution> dist;
549
550 case SOME(DAE.VAR_ATTR_REAL(quant,unit,displayUnit,min,max,initialExp,fixed,nominal,stateSel,uncertainty,dist,_,_,_,startOrigin))
551 algorithm
552 19 quantity := getOptionWithConcatStr(quant, ExpressionBasics.printExpStr, "quantity = ");
553 19 unit_str := getOptionWithConcatStr(unit, ExpressionBasics.printExpStr, "unit = ");
554 19 displayUnit_str := getOptionWithConcatStr(displayUnit, ExpressionBasics.printExpStr, "displayUnit = ");
555 19 stateSel_str := getOptionWithConcatStr(stateSel, dumpStateSelectStr , "stateSelect = ");
556 19 min_str := getOptionWithConcatStr(min, ExpressionBasics.printExpStr, "min = ");
557 19 max_str := getOptionWithConcatStr(max, ExpressionBasics.printExpStr, "max = ");
558 19 nominal_str := getOptionWithConcatStr(nominal, ExpressionBasics.printExpStr, "nominal = ");
559 19 initial_str := getOptionWithConcatStr(initialExp, ExpressionBasics.printExpStr, "start = ");
560 19 fixed_str := getOptionWithConcatStr(fixed, ExpressionBasics.printExpStr, "fixed = ");
561 19 uncertainty_str := getOptionWithConcatStr(uncertainty, dumpUncertaintyStr, "uncertainty = ");
562 19 dist_str := getOptionWithConcatStr(dist, dumpDistributionStr , "distribution = ");
563
564 19 startOriginStr := getStartOrigin(startOrigin);
565
566 19 res_1 := Util.stringDelimitListNonEmptyElts(
567 {quantity,unit_str,displayUnit_str,min_str,max_str,
568 initial_str,fixed_str,nominal_str,stateSel_str,uncertainty_str,dist_str,startOriginStr}, ", ");
569
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
38 res := if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
570 then
571 res;
572
573 case SOME(DAE.VAR_ATTR_INT(quant,min,max,initialExp,fixed,uncertainty,dist,_,_,_,startOrigin))
574 algorithm
575 ✗ quantity := getOptionWithConcatStr(quant, ExpressionBasics.printExpStr, "quantity = ");
576 ✗ min_str := getOptionWithConcatStr(min, ExpressionBasics.printExpStr, "min = ");
577 ✗ max_str := getOptionWithConcatStr(max, ExpressionBasics.printExpStr, "max = ");
578 ✗ initial_str := getOptionWithConcatStr(initialExp, ExpressionBasics.printExpStr, "start = ");
579 ✗ fixed_str := getOptionWithConcatStr(fixed, ExpressionBasics.printExpStr, "fixed = ");
580 ✗ uncertainty_str := getOptionWithConcatStr(uncertainty, dumpUncertaintyStr, "uncertainty = ");
581 ✗ dist_str := getOptionWithConcatStr(dist, dumpDistributionStr , "distribution = ");
582
583 ✗ startOriginStr := getStartOrigin(startOrigin);
584
585 ✗ res_1 := Util.stringDelimitListNonEmptyElts({quantity,min_str,max_str,initial_str,fixed_str,uncertainty_str,dist_str,startOriginStr}, ", ");
586 ✗ res := if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
587 then
588 res;
589
590 case SOME(DAE.VAR_ATTR_BOOL(quant,initialExp,fixed,_,_,_,startOrigin))
591 algorithm
592 ✗ quantity := getOptionWithConcatStr(quant, ExpressionBasics.printExpStr, "quantity = ");
593 ✗ initial_str := getOptionWithConcatStr(initialExp, ExpressionBasics.printExpStr, "start = ");
594 ✗ fixed_str := getOptionWithConcatStr(fixed, ExpressionBasics.printExpStr, "fixed = ");
595
596 ✗ startOriginStr := getStartOrigin(startOrigin);
597
598 ✗ res_1 := Util.stringDelimitListNonEmptyElts({quantity,initial_str,fixed_str,startOriginStr}, ", ");
599 ✗ res := if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
600 then
601 res;
602
603 case SOME(DAE.VAR_ATTR_STRING(quant,initialExp,fixed,_,_,_,startOrigin))
604 algorithm
605 ✗ quantity := getOptionWithConcatStr(quant, ExpressionBasics.printExpStr, "quantity = ");
606 ✗ initial_str := getOptionWithConcatStr(initialExp, ExpressionBasics.printExpStr, "start = ");
607 ✗ fixed_str := getOptionWithConcatStr(fixed, ExpressionBasics.printExpStr, "fixed = ");
608
609 ✗ startOriginStr := getStartOrigin(startOrigin);
610
611 ✗ res_1 := Util.stringDelimitListNonEmptyElts({quantity,initial_str,fixed_str,startOriginStr}, ", ");
612 ✗ res := if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
613 then
614 res;
615
616 case SOME(DAE.VAR_ATTR_ENUMERATION(quant,min,max,initialExp,fixed,_,_,_,startOrigin))
617 algorithm
618 ✗ quantity := getOptionWithConcatStr(quant, ExpressionBasics.printExpStr, "quantity = ");
619 ✗ min_str := getOptionWithConcatStr(min, ExpressionBasics.printExpStr, "min = ");
620 ✗ max_str := getOptionWithConcatStr(max, ExpressionBasics.printExpStr, "max = ");
621 ✗ initial_str := getOptionWithConcatStr(initialExp, ExpressionBasics.printExpStr, "start = ");
622 ✗ fixed_str := getOptionWithConcatStr(fixed, ExpressionBasics.printExpStr, "fixed = ");
623
624 ✗ startOriginStr := getStartOrigin(startOrigin);
625
626 ✗ res_1 := Util.stringDelimitListNonEmptyElts({quantity,min_str,max_str,initial_str,fixed_str,startOriginStr}, ", ");
627 ✗ res := if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
628 then
629 res;
630
631 case NONE() then "";
632
633 else "(unknown VariableAttributes)";
634 end matchcontinue;
635 end dumpVariableAttributesStr;
636
637 protected function getStartOrigin
638 input Option<DAE.StartOrigin> inStartOrigin;
639 output String outStartOrigin;
640 algorithm
641 outStartOrigin := match inStartOrigin
642 local
643 DAE.StartOrigin so;
644
645 case SOME(so) guard Flags.isSet(Flags.SHOW_START_ORIGIN)
646 ✗ then "startOrigin = " + startOriginStr(so);
647
648 else "";
649 end match;
650 end getStartOrigin;
651
652 public function startOriginStr
653 input DAE.StartOrigin so;
654 output String str;
655 algorithm
656 str := match so
657 case DAE.StartOrigin.UNDEFINED_ORIGIN() then "undefined";
658 case DAE.StartOrigin.TYPE_ORIGIN() then "type";
659 case DAE.StartOrigin.BINDING_ORIGIN() then "binding";
660 case DAE.StartOrigin.CONFIDENCE()
661 ✗ then "confidence(" + intString(so.actual) + ", " + intString(so.raw) + ")";
662 case DAE.StartOrigin.TYPE_CONFIDENCE()
663 ✗ then "typeConfidence(" + intString(so.level) + ")";
664 end match;
665 end startOriginStr;
666
667 protected function dumpVarVisibilityStr "Prints 'protected' to a string for protected variables"
668 input DAE.VarVisibility prot;
669 output String str;
670 algorithm
671 str := match prot
672 case DAE.PUBLIC() then "";
673 case DAE.PROTECTED() then "protected ";
674 end match;
675 end dumpVarVisibilityStr;
676
677 public function dumpVarParallelismStr "Dump VarParallelism to a string"
678 input DAE.VarParallelism inVarParallelism;
679 output String outString;
680 algorithm
681 outString := match inVarParallelism
682 case DAE.NON_PARALLEL() then "";
683 case DAE.PARGLOBAL() then "parglobal ";
684 case DAE.PARLOCAL() then "parlocal ";
685 end match;
686 end dumpVarParallelismStr;
687
688 protected function dumpCommentOption "Dump Comment option."
689 input Option<SCode.Comment> comment;
690 protected
691 String str;
692 algorithm
693 ✗ str := dumpCommentAnnotationStr(comment);
694 ✗ Print.printBuf(str);
695 end dumpCommentOption;
696
697 protected function dumpEquation "Dump equation."
698 input DAE.Element inElement;
699 algorithm
700 () := matchcontinue inElement
701 local
702 DAE.Exp e1,e2,e;
703 DAE.ComponentRef c,cr1,cr2;
704 DAE.ElementSource src;
705 String sourceStr;
706
707 case DAE.EQUATION(exp = e1, scalar = e2, source = src)
708 algorithm
709 ✗ Print.printBuf(" ");
710 ✗ ExpressionDump.printExp(e1);
711 ✗ Print.printBuf(" = ");
712 ✗ ExpressionDump.printExp(e2);
713 ✗ sourceStr := getSourceInformationStr(src);
714 ✗ Print.printBuf(sourceStr);
715 ✗ Print.printBuf(";\n");
716 then
717 ();
718
719 case DAE.EQUEQUATION(cr1=cr1, cr2=cr2, source = src)
720 algorithm
721 ✗ Print.printBuf(" ");
722 ✗ ComponentReference.printComponentRef(cr1);
723 ✗ Print.printBuf(" = ");
724 ✗ ComponentReference.printComponentRef(cr2);
725 ✗ sourceStr := getSourceInformationStr(src);
726 ✗ Print.printBuf(sourceStr);
727 ✗ Print.printBuf(";\n");
728 then
729 ();
730
731 case DAE.ARRAY_EQUATION(exp = e1, array= e2, source = src)
732 algorithm
733 ✗ Print.printBuf(" ");
734 ✗ ExpressionDump.printExp(e1);
735 ✗ Print.printBuf(" = ");
736 ✗ ExpressionDump.printExp(e2);
737 ✗ sourceStr := getSourceInformationStr(src);
738 ✗ Print.printBuf(sourceStr);
739 ✗ Print.printBuf(";\n");
740 then
741 ();
742
743 case DAE.COMPLEX_EQUATION(lhs = e1, rhs= e2, source = src)
744 algorithm
745 ✗ Print.printBuf(" ");
746 ✗ ExpressionDump.printExp(e1);
747 ✗ Print.printBuf(" = ");
748 ✗ ExpressionDump.printExp(e2);
749 ✗ sourceStr := getSourceInformationStr(src);
750 ✗ Print.printBuf(sourceStr);
751 ✗ Print.printBuf(";\n");
752 then
753 ();
754
755 case DAE.DEFINE(componentRef = c, exp = e, source = src)
756 algorithm
757 ✗ Print.printBuf(" ");
758 ✗ ComponentReference.printComponentRef(c);
759 ✗ Print.printBuf(" ::= ");
760 ✗ ExpressionDump.printExp(e);
761 ✗ sourceStr := getSourceInformationStr(src);
762 ✗ Print.printBuf(sourceStr);
763 ✗ Print.printBuf(";\n");
764 then
765 ();
766
767 case DAE.ASSERT(condition=e1, message=e2, source = src)
768 algorithm
769 ✗ Print.printBuf("assert(");
770 ✗ ExpressionDump.printExp(e1);
771 ✗ Print.printBuf(",");
772 ✗ ExpressionDump.printExp(e2);
773 ✗ Print.printBuf(") ");
774 ✗ sourceStr := getSourceInformationStr(src);
775 ✗ Print.printBuf(sourceStr);
776 ✗ Print.printBuf(";\n");
777 then
778 ();
779
780 case DAE.NORETCALL(exp = e1, source = src)
781 algorithm
782 ✗ ExpressionDump.printExp(e1);
783 ✗ sourceStr := getSourceInformationStr(src);
784 ✗ Print.printBuf(sourceStr);
785 ✗ Print.printBuf(";\n");
786 then
787 ();
788
789 case _
790 algorithm
791 ✗ Print.printBuf("/* FIXME: UNHANDLED_EQUATION in DAEDump.dumpEquation */;\n");
792 then
793 ();
794
795 end matchcontinue;
796 end dumpEquation;
797
798 protected function dumpInitialEquation "Dump initial equation."
799 input DAE.Element inElement;
800 algorithm
801 () := matchcontinue inElement
802 local
803 DAE.Exp e1,e2,e;
804 DAE.ComponentRef c;
805 list<DAE.Element> xs1,xs2;
806 list<list<DAE.Element>> trueBranches;
807 list<DAE.Exp> conds;
808 String s,s1,s2,sourceStr;
809 IOStream.IOStream str;
810 DAE.ElementSource src;
811 list<SCode.Comment> cmt;
812
813 case DAE.INITIALEQUATION(exp1 = e1,exp2 = e2)
814 algorithm
815 ✗ Print.printBuf(" ");
816 ✗ ExpressionDump.printExp(e1);
817 ✗ Print.printBuf(" = ");
818 ✗ ExpressionDump.printExp(e2);
819 ✗ Print.printBuf(";\n");
820 then
821 ();
822
823 case DAE.INITIALDEFINE(componentRef = c,exp = e)
824 algorithm
825 ✗ Print.printBuf(" ");
826 ✗ ComponentReference.printComponentRef(c);
827 ✗ Print.printBuf(" ::= ");
828 ✗ ExpressionDump.printExp(e);
829 ✗ Print.printBuf(";\n");
830 then
831 ();
832
833 case DAE.INITIAL_ARRAY_EQUATION(exp = e1, array = e2)
834 algorithm
835 ✗ Print.printBuf(" ");
836 ✗ ExpressionDump.printExp(e1);
837 ✗ Print.printBuf(" = ");
838 ✗ ExpressionDump.printExp(e2);
839 ✗ Print.printBuf(";\n");
840 then
841 ();
842
843 case DAE.INITIAL_COMPLEX_EQUATION(lhs = e1,rhs = e2)
844 algorithm
845 ✗ Print.printBuf(" ");
846 ✗ ExpressionDump.printExp(e1);
847 ✗ Print.printBuf(" = ");
848 ✗ ExpressionDump.printExp(e2);
849 ✗ Print.printBuf(";\n");
850 then
851 ();
852
853 case DAE.INITIAL_IF_EQUATION(condition1 = (e::conds),equations2 = (xs1::trueBranches),equations3 = xs2)
854 algorithm
855 ✗ Print.printBuf(" if ");
856 ✗ ExpressionDump.printExp(e);
857 ✗ Print.printBuf(" then\n");
858 ✗ List.map_0(xs1,dumpInitialEquation);
859 ✗ str := dumpIfEquationsStream(conds, trueBranches, IOStream.emptyStreamOfTypeList);
860 ✗ s := IOStream.string(str);
861 ✗ Print.printBuf(s);
862 ✗ Print.printBuf(" else\n");
863 ✗ List.map_0(xs2,dumpInitialEquation);
864 ✗ Print.printBuf("end if;\n");
865 then
866 ();
867
868 case DAE.INITIAL_ASSERT(condition=e1,message = e2,source = src)
869 algorithm
870 ✗ cmt := ElementSource.getComments(src);
871 ✗ sourceStr := cmtListToString(cmt);
872 ✗ s1 := ExpressionBasics.printExpStr(e1);
873 ✗ s2 := ExpressionBasics.printExpStr(e2);
874 ✗ s := stringAppendList({" assert(",s1, ",",s2,") ", sourceStr, ";\n"});
875 ✗ Print.printBuf(s);
876 then
877 ();
878
879 case DAE.INITIAL_TERMINATE(message=e1,source = src)
880 algorithm
881 ✗ cmt := ElementSource.getComments(src);
882 ✗ sourceStr := cmtListToString(cmt);
883 ✗ s1 := ExpressionBasics.printExpStr(e1);
884 ✗ s := stringAppendList({" terminate(",s1,") ", sourceStr, ";\n"});
885 ✗ Print.printBuf(s);
886 then
887 ();
888
889 case DAE.INITIAL_NORETCALL(exp = e1)
890 algorithm
891 ✗ ExpressionDump.printExp(e1);
892 ✗ Print.printBuf(";\n");
893 then
894 ();
895
896 else ();
897 end matchcontinue;
898 end dumpInitialEquation;
899
900 public function dumpEquationStr "Dump equation to a string."
901 input DAE.Element inElement;
902 output String outString;
903 algorithm
904 outString := matchcontinue inElement
905 local
906 String s1,s2,s3,s4,s5,str,sourceStr;
907 DAE.Exp e1,e2,e;
908 DAE.ComponentRef c,cr1,cr2;
909 DAE.ElementSource src;
910 list<SCode.Comment> cmt;
911
912 case DAE.EQUATION(exp = e1,scalar = e2,source = src)
913 algorithm
914 40 cmt := ElementSource.getComments(src);
915 40 sourceStr := cmtListToString(cmt);
916 40 s1 := ExpressionBasics.printExpStr(e1);
917 40 s2 := ExpressionBasics.printExpStr(e2);
918 40 str := stringAppendList({" ", s1, " = ", s2, sourceStr, ";\n"});
919 then
920 str;
921
922 case DAE.EQUEQUATION(cr1=cr1,cr2=cr2,source = src)
923 algorithm
924 ✗ cmt := ElementSource.getComments(src);
925 ✗ sourceStr := cmtListToString(cmt);
926 ✗ s1 := ComponentReferenceBasics.printComponentRefStr(cr1);
927 ✗ s2 := ComponentReferenceBasics.printComponentRefStr(cr2);
928 ✗ str := stringAppendList({" ", s1, " = ", s2, sourceStr, ";\n"});
929 then
930 str;
931
932 case DAE.ARRAY_EQUATION(exp=e1,array=e2,source = src)
933 algorithm
934 ✗ cmt := ElementSource.getComments(src);
935 ✗ sourceStr := cmtListToString(cmt);
936 ✗ s1 := ExpressionBasics.printExpStr(e1);
937 ✗ s2 := ExpressionBasics.printExpStr(e2);
938 ✗ str := " " + s1 + " = " + s2 + sourceStr + ";\n";
939 then
940 str;
941
942 case DAE.COMPLEX_EQUATION(lhs=e1,rhs=e2,source = src)
943 algorithm
944 ✗ cmt := ElementSource.getComments(src);
945 ✗ sourceStr := cmtListToString(cmt);
946 ✗ s1 := ExpressionBasics.printExpStr(e1);
947 ✗ s2 := ExpressionBasics.printExpStr(e2);
948 ✗ str := " " + s1 + " = " + s2 + sourceStr + ";\n";
949 then
950 str;
951
952 case DAE.DEFINE(componentRef = c,exp = e,source = src)
953 algorithm
954 ✗ cmt := ElementSource.getComments(src);
955 ✗ sourceStr := cmtListToString(cmt);
956 ✗ s1 := ComponentReferenceBasics.printComponentRefStr(c);
957 ✗ s2 := stringAppend(" ", s1);
958 ✗ s3 := stringAppend(" ::= ", s2);
959 ✗ s4 := ExpressionBasics.printExpStr(e);
960 ✗ s5 := stringAppend(s3, s4);
961 ✗ str := stringAppend(s5, sourceStr + ";\n");
962 then
963 str;
964
965 case DAE.ASSERT(condition=e1,message = e2,source = src)
966 algorithm
967 ✗ cmt := ElementSource.getComments(src);
968 ✗ sourceStr := cmtListToString(cmt);
969 ✗ s1 := ExpressionBasics.printExpStr(e1);
970 ✗ s2 := ExpressionBasics.printExpStr(e2);
971 ✗ str := stringAppendList({" assert(",s1, ",",s2,") ", sourceStr, ";\n"});
972 then
973 str;
974
975 case DAE.TERMINATE(message=e1,source = src)
976 algorithm
977 ✗ cmt := ElementSource.getComments(src);
978 ✗ sourceStr := cmtListToString(cmt);
979 ✗ s1 := ExpressionBasics.printExpStr(e1);
980 ✗ str := stringAppendList({" terminate(",s1,") ", sourceStr, ";\n"});
981 then
982 str;
983
984 case DAE.NORETCALL(exp=e1,source = src)
985 algorithm
986 ✗ cmt := ElementSource.getComments(src);
987 ✗ sourceStr := cmtListToString(cmt);
988 ✗ s1 := ExpressionBasics.printExpStr(e1);
989 ✗ str := stringAppendList({" ", s1, sourceStr, ";\n"});
990 then
991 str;
992 // adrpo: TODO! FIXME! should we say UNKNOWN equation here? we don't handle all cases!
993 else "#UNKNOWN_EQUATION#";
994 end matchcontinue;
995 end dumpEquationStr;
996
997 public function dumpAlgorithm "Dump algorithm."
998 input DAE.Element inElement;
999 algorithm
1000 () := matchcontinue inElement
1001 local list<DAE.Statement> stmts;
1002 case DAE.ALGORITHM(algorithm_ = DAE.ALGORITHM_STMTS(statementLst = stmts))
1003 algorithm
1004 18 Print.printBuf("algorithm\n");
1005 18 Dump.printList(stmts, ppStatement, "");
1006 then
1007 ();
1008 else ();
1009 end matchcontinue;
1010 end dumpAlgorithm;
1011
1012 protected function dumpInitialAlgorithm "Dump initial algorithm."
1013 input DAE.Element inElement;
1014 algorithm
1015 () := matchcontinue inElement
1016 local list<DAE.Statement> stmts;
1017 case DAE.INITIALALGORITHM(algorithm_ = DAE.ALGORITHM_STMTS(statementLst = stmts))
1018 algorithm
1019 ✗ Print.printBuf("initial algorithm\n");
1020 ✗ Dump.printList(stmts, ppStatement, "");
1021 then
1022 ();
1023 else ();
1024 end matchcontinue;
1025 end dumpInitialAlgorithm;
1026
1027 protected function dumpExtObjectClass
1028 "Dump External Object class"
1029 input DAE.Element inElement;
1030 algorithm
1031 () := matchcontinue inElement
1032 local
1033 String fstr;
1034 Absyn.Path fpath;
1035 case DAE.EXTOBJECTCLASS(path = fpath)
1036 algorithm
1037 ✗ Print.printBuf("class ");
1038 ✗ fstr := AbsynUtil.pathString(fpath);
1039 ✗ Print.printBuf(fstr);
1040 ✗ Print.printBuf("\n extends ExternalObject;\n");
1041 ✗ Print.printBuf("end ");
1042 ✗ Print.printBuf(fstr);
1043 ✗ Print.printBuf(";\n");
1044 then
1045 ();
1046 else ();
1047 end matchcontinue;
1048 end dumpExtObjectClass;
1049
1050 public function derivativeCondStr "
1051 Author BZ
1052 Function for printing conditions"
1053 input DAE.derivativeCond dc;
1054 output String str;
1055 algorithm
1056 str := match dc
1057 local DAE.Exp e;
1058
1059 case DAE.NO_DERIVATIVE(e)
1060 algorithm
1061 ✗ str := "noDerivative(" + ExpressionBasics.printExpStr(e) + ")";
1062 then
1063 str;
1064
1065 case DAE.ZERO_DERIVATIVE() then "zeroDerivative";
1066 end match;
1067 end derivativeCondStr;
1068
1069 protected function dumpFunction
1070 "Dump function"
1071 input DAE.Function inElement;
1072 algorithm
1073 () := matchcontinue inElement
1074 local
1075 String fstr, ext_decl_str, parallelism_str, impureStr, typeStr;
1076 Absyn.Path fpath;
1077 list<DAE.Element> daeElts;
1078 DAE.Type t;
1079 Option<SCode.Comment> c;
1080 DAE.ExternalDecl ext_decl;
1081 Boolean isImpure;
1082
1083 case DAE.FUNCTION(path = fpath, functions = (DAE.FUNCTION_DEF(body = daeElts)::_),
1084 type_ = t,isImpure = isImpure,comment = c)
1085 algorithm
1086 18 typeStr := TypesDump.printTypeStr(t);
1087 18 Print.printBuf(typeStr);
1088 18 parallelism_str := dumpParallelismStr(t);
1089 18 Print.printBuf(parallelism_str);
1090
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 impureStr := if isImpure then "impure " else "";
1091 18 Print.printBuf(impureStr);
1092 18 Print.printBuf("function ");
1093 18 fstr := AbsynUtil.pathStringNoQual(fpath);
1094 18 Print.printBuf(fstr);
1095 18 Print.printBuf(dumpCommentStr(c));
1096 18 Print.printBuf("\n");
1097 18 dumpFunctionElements(daeElts);
1098 18 Print.printBuf(dumpClassAnnotationStr(c));
1099 18 Print.printBuf("end ");
1100 18 Print.printBuf(fstr);
1101 18 Print.printBuf(";\n\n");
1102 then
1103 ();
1104
1105 case DAE.FUNCTION(functions = (DAE.FUNCTION_EXT(externalDecl = DAE.EXTERNALDECL(language="builtin"))::_))
1106 then
1107 ();
1108
1109 case DAE.FUNCTION(path = fpath, functions = (DAE.FUNCTION_EXT(body = daeElts, externalDecl = ext_decl)::_),
1110 isImpure = isImpure, comment = c)
1111 algorithm
1112 ✗ impureStr := if isImpure then "impure " else "";
1113 ✗ Print.printBuf(impureStr);
1114 ✗ Print.printBuf("function ");
1115 ✗ fstr := AbsynUtil.pathStringNoQual(fpath);
1116 ✗ Print.printBuf(fstr);
1117 ✗ Print.printBuf(dumpCommentStr(c));
1118 ✗ Print.printBuf("\n");
1119 ✗ dumpFunctionElements(daeElts);
1120 ✗ ext_decl_str := dumpExtDeclStr(ext_decl);
1121 ✗ Print.printBuf("\n " + ext_decl_str + "\n");
1122 ✗ Print.printBuf(dumpClassAnnotationStr(c));
1123 ✗ Print.printBuf("end ");
1124 ✗ Print.printBuf(fstr);
1125 ✗ Print.printBuf(";\n\n");
1126 then
1127 ();
1128
1129 case DAE.RECORD_CONSTRUCTOR(path = fpath,type_=t)
1130 algorithm
1131
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 false := Flags.isSet(Flags.DISABLE_RECORD_CONSTRUCTOR_OUTPUT);
1132
1133
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
1 if Flags.isSet(Flags.PRINT_RECORD_TYPES) then
1134 ✗ Print.printBuf(TypesDump.unparseType(t));
1135 ✗ Print.printBuf("\n");
1136 else
1137 1 Print.printBuf("function ");
1138 1 fstr := AbsynUtil.pathStringNoQual(fpath);
1139 1 Print.printBuf(fstr);
1140 1 Print.printBuf(" \"Automatically generated record constructor for "+fstr+"\"\n");
1141 1 Print.printBuf(printRecordConstructorInputsStr(t));
1142 1 Print.printBuf(" output "+AbsynUtil.pathLastIdent(fpath)+ " res;\n");
1143 1 Print.printBuf("end ");
1144 1 Print.printBuf(fstr);
1145 1 Print.printBuf(";\n\n");
1146 end if;
1147 then
1148 ();
1149
1150 else ();
1151 end matchcontinue;
1152 end dumpFunction;
1153
1154 protected function dumpParallelismStr
1155 input DAE.Type inType;
1156 output String outString;
1157 algorithm
1158 outString := match inType
1159 case DAE.T_FUNCTION(_, _, DAE.FUNCTION_ATTRIBUTES(functionParallelism=DAE.FP_NON_PARALLEL()), _) then "";
1160 case DAE.T_FUNCTION(_, _, DAE.FUNCTION_ATTRIBUTES(functionParallelism=DAE.FP_PARALLEL_FUNCTION()), _) then "parallel ";
1161 case DAE.T_FUNCTION(_, _, DAE.FUNCTION_ATTRIBUTES(functionParallelism=DAE.FP_KERNEL_FUNCTION()), _) then "kernel ";
1162 else "#dumpParallelismStr failed#";
1163 end match;
1164 end dumpParallelismStr;
1165
1166 public function dumpInlineTypeStr
1167 input DAE.InlineType inlineType;
1168 output String str;
1169 algorithm
1170 str := match inlineType
1171 case DAE.NO_INLINE() then "\"Inline never\"";
1172 case DAE.AFTER_INDEX_RED_INLINE() then " \"Inline after index reduction\"";
1173 case DAE.NORM_INLINE() then " \"Inline before index reduction\"";
1174 case DAE.DEFAULT_INLINE() then "\"Inline if necessary\"";
1175 case DAE.EARLY_INLINE() then "\"Inline earier than normal inline\"";
1176 case DAE.BUILTIN_EARLY_INLINE() then "\"Inline even if inlining is disabled\"";
1177 else "\"unknown\"";
1178 end match;
1179 end dumpInlineTypeStr;
1180
1181 public function dumpInlineTypeBackendStr
1182 input DAE.InlineType inlineType;
1183 output String str;
1184 algorithm
1185 str := match inlineType
1186 case DAE.NO_INLINE() then "NONE";
1187 case DAE.AFTER_INDEX_RED_INLINE() then "AFTER_INDEX_RED";
1188 case DAE.NORM_INLINE() then "NORMAL";
1189 case DAE.DEFAULT_INLINE() then "DEFAULT";
1190 case DAE.EARLY_INLINE() then "EARLY";
1191 case DAE.BUILTIN_EARLY_INLINE() then "BUILTIN_EARLY";
1192 else "UNKNOWN";
1193 end match;
1194 end dumpInlineTypeBackendStr;
1195
1196
1197 protected function printRecordConstructorInputsStr
1198 "Helper function to dumpFunction. Prints the inputs of a record constructor."
1199 input DAE.Type itp;
1200 output String str;
1201 algorithm
1202 str := match itp
1203 local
1204 list<String> var_strl;
1205 list<DAE.Var> vars;
1206 DAE.Type tp;
1207
1208 case DAE.T_COMPLEX(varLst = vars)
1209 algorithm
1210 1 var_strl := List.map(vars, printRecordConstructorInputStr);
1211 1 then
1212 stringAppendList(var_strl);
1213
1214 1 case DAE.T_FUNCTION(funcResultType = tp) then printRecordConstructorInputsStr(tp);
1215
1216 end match;
1217 end printRecordConstructorInputsStr;
1218
1219 protected function printRecordConstructorInputStr
1220 input DAE.Var inVar;
1221 output String outString;
1222 protected
1223 String name, attr_str, binding_str, ty_str, ty_vars_str;
1224 DAE.Attributes attr;
1225 DAE.Type ty;
1226 DAE.Binding binding;
1227 algorithm
1228 2 DAE.TYPES_VAR(name = name, attributes = attr, ty = ty, binding = binding) := inVar;
1229 2 attr_str := printRecordConstructorInputAttrStr(attr);
1230 2 binding_str := printRecordConstructorBinding(binding);
1231 2 (ty_str, ty_vars_str) := printTypeStr(ty);
1232 4 outString := stringAppendList({" ", attr_str, ty_str, " ", name, ty_vars_str, binding_str, ";\n"});
1233 end printRecordConstructorInputStr;
1234
1235 protected function printRecordConstructorInputAttrStr
1236 input DAE.Attributes inAttributes;
1237 output String outString;
1238 algorithm
1239 outString := match inAttributes
1240 // protected vars are not input!, see Modelica Spec 3.2, Section 12.6, Record Constructor Functions, page 140
1241 case DAE.ATTR(visibility = SCode.PROTECTED()) then "protected ";
1242 // constants are not input! see Modelica Spec 3.2, Section 12.6, Record Constructor Functions, page 140
1243 case DAE.ATTR(variability = SCode.CONST()) then "constant ";
1244 else "input ";
1245 end match;
1246 end printRecordConstructorInputAttrStr;
1247
1248 protected function printRecordConstructorBinding "prints the binding of a record constructor input"
1249 input DAE.Binding binding;
1250 output String str;
1251 algorithm
1252 str := match binding
1253 local DAE.Exp e; Values.Value v;
1254 case DAE.UNBOUND() then "";
1255 case DAE.EQBOUND(exp=e, source=DAE.BINDING_FROM_DEFAULT_VALUE()) algorithm
1256 ✗ str := " = "+ExpressionBasics.printExpStr(e);
1257 then str;
1258 case DAE.EQBOUND(exp=e, source=DAE.BINDING_FROM_RECORD_SUBMODS()) algorithm
1259 ✗ str := " = "+ExpressionBasics.printExpStr(e);
1260 then str;
1261 case DAE.VALBOUND(valBound=v, source=DAE.BINDING_FROM_DEFAULT_VALUE()) algorithm
1262 ✗ str := " = " + ValuesDump.valString(v);
1263 then str;
1264 end match;
1265 end printRecordConstructorBinding;
1266
1267 protected function ppStatement
1268 "Prettyprint an algorithm statement"
1269 input DAE.Statement alg;
1270 algorithm
1271 20 ppStmt(alg, 2);
1272 end ppStatement;
1273
1274 public function ppStatementStr
1275 "Prettyprint an algorithm statement to a string."
1276 input DAE.Statement alg;
1277 output String str;
1278 algorithm
1279 37632 str := ppStmtStr(alg, 2);
1280 end ppStatementStr;
1281
1282 protected function ppStmt
1283 "Helper function to ppStatement."
1284 input DAE.Statement inStatement;
1285 input Integer inInteger;
1286 algorithm
1287 () := matchcontinue (inStatement,inInteger)
1288 local
1289 DAE.Exp e,cond,msg,e1,e2;
1290 Integer i,i_1;
1291 String s1,s2,s3,str,id,name;
1292 list<String> es;
1293 list<DAE.Exp> expl;
1294 list<DAE.Statement> then_,stmts;
1295 DAE.Statement stmt;
1296 DAE.Type ty;
1297 DAE.Else else_;
1298 DAE.ElementSource source;
1299
1300 case (DAE.STMT_ASSIGN(exp1 = e2,exp = e,source = source),i)
1301 algorithm
1302 10 indent(i);
1303 10 ExpressionDump.printExp(e2);
1304 10 Print.printBuf(" := ");
1305 10 ExpressionDump.printExp(e);
1306
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if Config.typeinfo() then
1307 ✗ Print.printBuf(" /* " + Error.infoStr(ElementSource.getElementSourceFileInfo(source)) + " */");
1308 end if;
1309 10 Print.printBuf(";\n");
1310 then
1311 ();
1312
1313 case (DAE.STMT_ASSIGN_ARR(lhs = e2,exp = e),i)
1314 algorithm
1315 17 indent(i);
1316 17 ExpressionDump.printExp(e2);
1317 17 Print.printBuf(" := ");
1318 17 ExpressionDump.printExp(e);
1319 17 Print.printBuf(";\n");
1320 then
1321 ();
1322
1323 case (DAE.STMT_TUPLE_ASSIGN(expExpLst = expl,exp = e),i)
1324 algorithm
1325 ✗ s1 := indentStr(i);
1326 ✗ s2 := ExpressionBasics.printExpStr(e);
1327 ✗ es := List.map(expl, ExpressionBasics.printExpStr);
1328 ✗ s3 := stringDelimitList(es, ", ");
1329 ✗ str := stringAppendList({s1,"(",s3,") := ",s2,";\n"});
1330 ✗ Print.printBuf(str);
1331 then
1332 ();
1333
1334 case (DAE.STMT_IF(exp = e,statementLst = then_,else_ = else_),i)
1335 algorithm
1336 4 indent(i);
1337 4 Print.printBuf("if ");
1338 4 ExpressionDump.printExp(e);
1339 4 Print.printBuf(" then\n");
1340 4 i_1 := i + 2;
1341 4 ppStmtList(then_, i_1);
1342 4 ppElse(else_, i);
1343 4 indent(i);
1344 4 Print.printBuf("end if;\n");
1345 then
1346 ();
1347
1348 case (DAE.STMT_FOR(iter = id,range = e,statementLst = stmts),i)
1349 algorithm
1350 ✗ indent(i);
1351 ✗ Print.printBuf("for ");
1352 ✗ Print.printBuf(id);
1353 ✗ Print.printBuf(" in ");
1354 ✗ ExpressionDump.printExp(e);
1355 ✗ Print.printBuf(" loop\n");
1356 ✗ i_1 := i + 2;
1357 ✗ ppStmtList(stmts, i_1);
1358 ✗ indent(i);
1359 ✗ Print.printBuf("end for;\n");
1360 then
1361 ();
1362
1363 case (DAE.STMT_PARFOR(iter = id,range = e,statementLst = stmts),i)
1364 algorithm
1365 ✗ indent(i);
1366 ✗ Print.printBuf("parfor ");
1367 ✗ Print.printBuf(id);
1368 ✗ Print.printBuf(" in ");
1369 ✗ ExpressionDump.printExp(e);
1370 ✗ Print.printBuf(" loop\n");
1371 ✗ i_1 := i + 2;
1372 ✗ ppStmtList(stmts, i_1);
1373 ✗ indent(i);
1374 ✗ Print.printBuf("end parfor;\n");
1375 then
1376 ();
1377
1378 case (DAE.STMT_WHILE(exp = e,statementLst = stmts),i)
1379 algorithm
1380 ✗ indent(i);
1381 ✗ Print.printBuf("while ");
1382 ✗ ExpressionDump.printExp(e);
1383 ✗ Print.printBuf(" loop\n");
1384 ✗ i_1 := i + 2;
1385 ✗ ppStmtList(stmts, i_1);
1386 ✗ indent(i);
1387 ✗ Print.printBuf("end while;\n");
1388 then
1389 ();
1390
1391 case (DAE.STMT_NORETCALL(exp = e1),i)
1392 algorithm
1393 ✗ indent(i);
1394 () := match e1
1395 case DAE.CALL(attr=DAE.CALL_ATTR(tailCall=DAE.TAIL()))
1396 algorithm
1397 ✗ Print.printBuf("return ");
1398 then ();
1399 else ();
1400 end match;
1401 ✗ ExpressionDump.printExp(e1);
1402 ✗ Print.printBuf(";\n");
1403 then
1404 ();
1405
1406 case (stmt as DAE.STMT_WHEN(),i)
1407 algorithm
1408 ✗ indent(i);
1409 ✗ Print.printBuf(ppWhenStmtStr(stmt,1));
1410 then
1411 ();
1412
1413 case (DAE.STMT_ASSERT(cond = cond,msg = msg),i)
1414 algorithm
1415 ✗ indent(i);
1416 ✗ Print.printBuf("assert(");
1417 ✗ ExpressionDump.printExp(cond);
1418 ✗ Print.printBuf(", ");
1419 ✗ ExpressionDump.printExp(msg);
1420 ✗ Print.printBuf(");\n");
1421 then
1422 ();
1423
1424 case (DAE.STMT_RETURN(),i)
1425 algorithm
1426 ✗ indent(i);
1427 ✗ Print.printBuf("return;\n");
1428 then
1429 ();
1430
1431 case (DAE.STMT_BREAK(),i)
1432 algorithm
1433 ✗ indent(i);
1434 ✗ Print.printBuf("break;\n");
1435 then
1436 ();
1437
1438 case (DAE.STMT_REINIT(var = e1, value = e2),i)
1439 algorithm
1440 ✗ indent(i);
1441 ✗ Print.printBuf("reinit(");
1442 ✗ ExpressionDump.printExp(e1);
1443 ✗ Print.printBuf(",");
1444 ✗ ExpressionDump.printExp(e2);
1445 ✗ Print.printBuf(");\n");
1446 then
1447 ();
1448
1449 case (DAE.STMT_FAILURE(body = stmts),i)
1450 algorithm
1451 ✗ indent(i);
1452 ✗ Print.printBuf("begin failure\n");
1453 ✗ ppStmtList(stmts, i+2);
1454 ✗ Print.printBuf("end try;\n");
1455 then
1456 ();
1457
1458 case (DAE.STMT_ARRAY_INIT(name = name, ty = ty),i)
1459 algorithm
1460 ✗ indent(i);
1461 ✗ Print.printBuf("/* ");
1462 ✗ Print.printBuf(name);
1463 ✗ Print.printBuf(" := array_alloc(");
1464 ✗ Print.printBuf(TypesDump.unparseType(ty));
1465 ✗ Print.printBuf(") */;\n");
1466 then
1467 ();
1468
1469 case (_,i)
1470 algorithm
1471 ✗ indent(i);
1472 ✗ Print.printBuf("**ALGORITHM**;\n");
1473 then
1474 ();
1475 end matchcontinue;
1476 end ppStmt;
1477
1478
1479 protected function ppWhenStmtStr
1480 input DAE.Statement inStatement;
1481 input Integer inInteger;
1482 output String outString;
1483 algorithm
1484 outString := match (inStatement,inInteger)
1485 local
1486 String s3,s4,s5,s6,str,s7,s8,s9,s10;
1487 DAE.Exp e;
1488 Integer i,i_1;
1489 list<DAE.Statement> stmts;
1490 DAE.Statement stmt;
1491 case (DAE.STMT_WHEN(exp = e,statementLst = stmts, elseWhen=NONE()),i)
1492 algorithm
1493 280 s3 := stringAppend("when ",ExpressionBasics.printExpStr(e));
1494 280 s5 := stringAppend(s3, " then\n");
1495 280 i_1 := i + 2;
1496 280 s6 := ppStmtListStr(stmts, i_1);
1497 280 s7 := stringAppend(s5, s6);
1498 280 s8 := indentStr(i);
1499 280 s9 := stringAppend(s7, s8);
1500 280 str := stringAppend(s9, "end when;\n");
1501 then
1502 str;
1503 case (DAE.STMT_WHEN(exp = e,statementLst = stmts, elseWhen=SOME(stmt)),i)
1504 algorithm
1505 104 s3 := ExpressionBasics.printExpStr(e);
1506 104 s4 := stringAppend("when ", s3);
1507 104 s5 := stringAppend(s4, " then\n");
1508 104 i_1 := i + 2;
1509 104 s6 := ppStmtListStr(stmts, i_1);
1510 104 s7 := stringAppend(s5, s6);
1511 104 s8 := ppWhenStmtStr(stmt,i);
1512 104 s9 := stringAppend(indentStr(i),"else");
1513 104 s10:= stringAppend(s7,s9);
1514 104 str := stringAppend(s10, s8);
1515 then
1516 str;
1517 end match;
1518 end ppWhenStmtStr;
1519
1520 public function ppStmtStr
1521 "Helper function to ppStatementStr"
1522 input DAE.Statement inStatement;
1523 input Integer inInteger;
1524 output String outString;
1525 algorithm
1526 outString := matchcontinue (inStatement,inInteger)
1527 local
1528 String s1,s2,s3,s4,s5,s6,str,s7,s8,s9,s10,s11,id,cond_str,msg_str,e1_str,e2_str;
1529 DAE.Exp e,cond,msg,e1,e2;
1530 Integer i,i_1;
1531 list<String> es;
1532 list<DAE.Exp> expl;
1533 list<DAE.Statement> then_,stmts;
1534 DAE.Statement stmt;
1535 DAE.Else else_;
1536
1537 case (DAE.STMT_ASSIGN(exp1 = e2,exp = e),i)
1538 algorithm
1539 10089 s1 := indentStr(i);
1540 10089 s2 := ExpressionBasics.printExpStr(e2);
1541 10089 s3 := ExpressionBasics.printExpStr(e);
1542 10089 str := stringAppendList({s1,s2," := ",s3,";\n"});
1543 then
1544 str;
1545
1546 case (DAE.STMT_ASSIGN_ARR(lhs=e2,exp = e),i)
1547 algorithm
1548 285 s1 := indentStr(i);
1549 285 s2 := ExpressionBasics.printExpStr(e2);
1550 285 s3 := ExpressionBasics.printExpStr(e);
1551 285 str := stringAppendList({s1,s2," := ",s3,";\n"});
1552 then
1553 str;
1554
1555 case (DAE.STMT_TUPLE_ASSIGN(expExpLst = expl,exp = e),i)
1556 algorithm
1557 1041 s1 := indentStr(i);
1558 1041 s2 := ExpressionBasics.printExpStr(e);
1559 1041 es := List.map(expl, ExpressionBasics.printExpStr);
1560 1041 s3 := stringDelimitList(es, ", ");
1561 1041 str := stringAppendList({s1,"(",s3,") := ",s2,";\n"});
1562 then
1563 str;
1564
1565 case (DAE.STMT_IF(exp = e,statementLst = then_,else_ = else_),i)
1566 algorithm
1567 898 s1 := indentStr(i);
1568 898 s2 := stringAppend(s1, "if ");
1569 898 s3 := ExpressionBasics.printExpStr(e);
1570 898 s4 := stringAppend(s2, s3);
1571 898 s5 := stringAppend(s4, " then\n");
1572 898 i_1 := i + 2;
1573 898 s6 := ppStmtListStr(then_, i_1);
1574 898 s7 := stringAppend(s5, s6);
1575 898 s8 := ppElseStr(else_, i);
1576 898 s9 := stringAppend(s7, s8);
1577 898 s10 := indentStr(i);
1578 898 s11 := stringAppend(s9, s10);
1579 898 str := stringAppend(s11, "end if;\n");
1580 then
1581 str;
1582
1583 case (DAE.STMT_FOR(iter = id,range = e,statementLst = stmts),i)
1584 algorithm
1585 558 s1 := indentStr(i);
1586 558 s3 := ExpressionBasics.printExpStr(e);
1587 558 i_1 := i + 2;
1588 558 s4 := ppStmtListStr(stmts, i_1);
1589 558 s5 := indentStr(i);
1590 558 str := stringAppendList({s1,"for ",id," in ",s3," loop\n",s4,s5,"end for;\n"});
1591 then
1592 str;
1593
1594 case (DAE.STMT_PARFOR(iter = id,range = e,statementLst = stmts),i)
1595 algorithm
1596 ✗ s1 := indentStr(i);
1597 ✗ s3 := ExpressionBasics.printExpStr(e);
1598 ✗ i_1 := i + 2;
1599 ✗ s4 := ppStmtListStr(stmts, i_1);
1600 ✗ s5 := indentStr(i);
1601 ✗ str := stringAppendList({s1,"parfor ",id," in ",s3," loop\n",s4,s5,"end for;\n"});
1602 then
1603 str;
1604
1605 case (DAE.STMT_WHILE(exp = e,statementLst = stmts),i)
1606 algorithm
1607 16 s1 := indentStr(i);
1608 16 s2 := stringAppend(s1, "while ");
1609 16 s3 := ExpressionBasics.printExpStr(e);
1610 16 s4 := stringAppend(s2, s3);
1611 16 s5 := stringAppend(s4, " loop\n");
1612 16 i_1 := i + 2;
1613 16 s6 := ppStmtListStr(stmts, i_1);
1614 16 s7 := stringAppend(s5, s6);
1615 16 s8 := indentStr(i);
1616 16 s9 := stringAppend(s7, s8);
1617 16 str := stringAppend(s9, "end while;\n");
1618 then
1619 str;
1620
1621 case (stmt as DAE.STMT_WHEN(),i)
1622 algorithm
1623 280 s1 := indentStr(i);
1624 280 s2 := ppWhenStmtStr(stmt,i);
1625 280 str := stringAppend(s1,s2);
1626 then
1627 str;
1628
1629 case (DAE.STMT_ASSERT(cond = cond,msg = msg),i)
1630 algorithm
1631 65840 s1 := indentStr(i);
1632 65840 cond_str := ExpressionBasics.printExpStr(cond);
1633 65840 msg_str := ExpressionBasics.printExpStr(msg);
1634 65840 str := stringAppendList({s1,"assert(",cond_str,", ",msg_str,");\n"});
1635 then
1636 str;
1637
1638 case (DAE.STMT_TERMINATE(msg = msg),i)
1639 algorithm
1640 6 s1 := indentStr(i);
1641 6 msg_str := ExpressionBasics.printExpStr(msg);
1642 6 str := stringAppendList({s1,"terminate(",msg_str,");\n"});
1643 then
1644 str;
1645
1646 case (DAE.STMT_NORETCALL(exp = e),i)
1647 algorithm
1648 262 s1 := indentStr(i);
1649 s2 := match e
1650 case DAE.CALL(attr=DAE.CALL_ATTR(tailCall=DAE.TAIL())) then "return ";
1651 else "";
1652 end match;
1653 262 s3 := ExpressionBasics.printExpStr(e);
1654 262 str := stringAppendList({s1,s2,s3,";\n"});
1655 then
1656 str;
1657
1658 case (DAE.STMT_RETURN(),i)
1659 algorithm
1660 ✗ s1 := indentStr(i);
1661 ✗ str := stringAppend(s1, "return;\n");
1662 then
1663 str;
1664
1665 case (DAE.STMT_BREAK(),i)
1666 algorithm
1667 56 s1 := indentStr(i);
1668 56 str := stringAppend(s1, "break;\n");
1669 then
1670 str;
1671
1672 case (DAE.STMT_REINIT(var = e1, value = e2),i)
1673 algorithm
1674 48 s1 := indentStr(i);
1675 48 e1_str := ExpressionBasics.printExpStr(e1);
1676 48 e2_str := ExpressionBasics.printExpStr(e2);
1677 48 str := stringAppendList({s1,"reinit(",e1_str,", ",e2_str,");\n"});
1678 then str;
1679
1680 case (DAE.STMT_FAILURE(body=stmts),i)
1681 algorithm
1682 ✗ s1 := indentStr(i);
1683 ✗ s2 := ppStmtListStr(stmts, i+2);
1684 ✗ str := stringAppendList({s1,"failure(\n",s2,s1,");\n"});
1685 then str;
1686
1687 case (DAE.STMT_ARRAY_INIT(name=s2),i)
1688 algorithm
1689 ✗ s1 := indentStr(i);
1690 ✗ str := stringAppendList({s1,"arrayInit(\n",s2,s1,");\n"});
1691 then str;
1692
1693 case (_,i)
1694 algorithm
1695 ✗ s1 := indentStr(i);
1696 ✗ str := stringAppend(s1, "**ALGORITHM COULD NOT BE GENERATED(DAE.mo)**;\n");
1697 then
1698 str;
1699 end matchcontinue;
1700 end ppStmtStr;
1701
1702 protected function ppStmtList "
1703 Helper function to pp_stmt
1704 "
1705 input list<DAE.Statement> inAlgorithmStatementLst;
1706 input Integer inInteger;
1707 algorithm
1708 ():=
1709 match (inAlgorithmStatementLst,inInteger)
1710 local
1711 DAE.Statement stmt;
1712 list<DAE.Statement> stmts;
1713 Integer i;
1714 case ({},_) then ();
1715 case ((stmt :: stmts),i)
1716 algorithm
1717 11 ppStmt(stmt, i);
1718 11 ppStmtList(stmts, i);
1719 then
1720 ();
1721 end match;
1722 end ppStmtList;
1723
1724 public function ppStmtListStr "
1725 Helper function to pp_stmt_str
1726 "
1727 input list<DAE.Statement> inAlgorithmStatementLst;
1728 input Integer inInteger=0;
1729 output String outString;
1730 algorithm
1731 outString:=
1732 match (inAlgorithmStatementLst,inInteger)
1733 local
1734 String s1,s2,str;
1735 DAE.Statement stmt;
1736 list<DAE.Statement> stmts;
1737 Integer i;
1738 case ({},_) then "";
1739 case ((stmt :: stmts),i)
1740 algorithm
1741 2819 s1 := ppStmtStr(stmt, i);
1742 2819 s2 := ppStmtListStr(stmts, i);
1743 2819 str := stringAppend(s1, s2);
1744 then
1745 str;
1746 end match;
1747 end ppStmtListStr;
1748
1749 protected function ppElse "
1750 Helper function to pp_stmt
1751 "
1752 input DAE.Else inElse;
1753 input Integer inInteger;
1754 algorithm
1755 ():=
1756 match (inElse,inInteger)
1757 local
1758 Integer i_1,i;
1759 DAE.Exp e;
1760 list<DAE.Statement> then_,stmts;
1761 DAE.Else else_;
1762 case (DAE.NOELSE(),_) then ();
1763 case (DAE.ELSEIF(exp = e,statementLst = then_,else_ = else_),i)
1764 algorithm
1765 ✗ indent(i);
1766 ✗ Print.printBuf("elseif ");
1767 ✗ ExpressionDump.printExp(e);
1768 ✗ Print.printBuf(" then\n");
1769 ✗ i_1 := i + 2;
1770 ✗ ppStmtList(then_, i_1);
1771 ✗ ppElse(else_, i);
1772 then
1773 ();
1774 case (DAE.ELSE(statementLst = stmts),i)
1775 algorithm
1776 3 indent(i);
1777 3 Print.printBuf("else\n");
1778 3 i_1 := i + 2;
1779 3 ppStmtList(stmts, i_1);
1780 then
1781 ();
1782 end match;
1783 end ppElse;
1784
1785 protected function ppElseStr "
1786 Helper function to ppElseStr
1787 "
1788 input DAE.Else inElse;
1789 input Integer inInteger;
1790 output String outString;
1791 algorithm
1792 outString:=
1793 match (inElse,inInteger)
1794 local
1795 String s1,s2,s3,s4,s5,s6,s7,s8,str;
1796 Integer i_1,i;
1797 DAE.Exp e;
1798 list<DAE.Statement> then_,stmts;
1799 DAE.Else else_;
1800 case (DAE.NOELSE(),_) then "";
1801 case (DAE.ELSEIF(exp = e,statementLst = then_,else_ = else_),i)
1802 algorithm
1803 298 s1 := indentStr(i);
1804 298 s2 := stringAppend(s1, "elseif ");
1805 298 s3 := ExpressionBasics.printExpStr(e);
1806 298 s4 := stringAppend(s2, s3);
1807 298 s5 := stringAppend(s4, " then\n");
1808 298 i_1 := i + 2;
1809 298 s6 := ppStmtListStr(then_, i_1);
1810 298 s7 := stringAppend(s5, s6);
1811 298 s8 := ppElseStr(else_, i);
1812 298 str := stringAppend(s7, s8);
1813 then
1814 str;
1815 case (DAE.ELSE(statementLst = stmts),i)
1816 algorithm
1817 166 s1 := indentStr(i);
1818 166 s2 := stringAppend(s1, "else\n");
1819 166 i_1 := i + 2;
1820 166 s3 := ppStmtListStr(stmts, i_1);
1821 166 str := stringAppend(s2, s3);
1822 then
1823 str;
1824 end match;
1825 end ppElseStr;
1826
1827 protected function indent "
1828 Print an indentation, given an indent level.
1829 "
1830 input Integer inInteger;
1831 algorithm
1832 ():=
1833 match inInteger
1834 local Integer i_1,i;
1835 case 0 then ();
1836 case i
1837 algorithm
1838 122 Print.printBuf(" ");
1839 122 i_1 := i - 1;
1840 122 indent(i_1);
1841 then
1842 ();
1843 end match;
1844 end indent;
1845
1846 protected function indentStr "
1847 Print an indentation to a string, given an indent level.
1848 "
1849 input Integer inInteger;
1850 output String outString;
1851 algorithm
1852 outString:=
1853 match inInteger
1854 local
1855 Integer i_1,i;
1856 String s1,str;
1857 case 0 then "";
1858 case i
1859 algorithm
1860 176638 i_1 := i - 1;
1861 176638 s1 := indentStr(i_1);
1862 176638 str := stringAppend(" ", s1);
1863 then
1864 str;
1865 end match;
1866 end indentStr;
1867
1868 public function dumpDebug "
1869
1870 Dump the data structures in a
1871 paranthesised way
1872
1873 "
1874 input DAE.DAElist inDAElist;
1875 algorithm
1876 ():=
1877 match inDAElist
1878 local list<DAE.Element> elist;
1879 case DAE.DAE(elementLst = elist)
1880 algorithm
1881 ✗ Print.printBuf("DAE(");
1882 ✗ dumpDebugElist(elist);
1883 ✗ Print.printBuf(")");
1884 then
1885 ();
1886 end match;
1887 end dumpDebug;
1888
1889 protected function dumpDebugElist "
1890 Helper function to dump_debug.
1891 "
1892 input list<DAE.Element> inElementLst;
1893 algorithm
1894 ():=
1895 match inElementLst
1896 local
1897 DAE.Element first;
1898 list<DAE.Element> rest;
1899 case {} then ();
1900 case first :: rest
1901 algorithm
1902 ✗ dumpDebugElement(first);
1903 ✗ Print.printBuf("\n");
1904 ✗ dumpDebugElist(rest);
1905 then
1906 ();
1907 end match;
1908 end dumpDebugElist;
1909
1910 public function dumpDebugDAE ""
1911 input DAE.DAElist dae;
1912 output String str;
1913 algorithm
1914 str := match dae
1915 local
1916 list<DAE.Element> elems;
1917 case DAE.DAE(elementLst=elems)
1918 algorithm
1919 ✗ Print.clearBuf();
1920 ✗ dumpDebugElist(elems);
1921 ✗ str := Print.getString();
1922 then
1923 str;
1924 end match;
1925 end dumpDebugDAE;
1926
1927 public function dumpDebugElement "
1928 Dump element using parenthesis.
1929 "
1930 input DAE.Element inElement;
1931 algorithm
1932 ():=
1933 matchcontinue inElement
1934 local
1935 String comment_str,tmp_str,n;
1936 DAE.ComponentRef cr,cr1,cr2;
1937 DAE.VarKind vk;
1938 Option<DAE.VariableAttributes> dae_var_attr;
1939 Option<SCode.Comment> comment;
1940 DAE.Exp e,exp,e1,e2;
1941 list<DAE.Element> l;
1942 case DAE.VAR(componentRef = cr,
1943 kind = vk,
1944 binding = NONE(),
1945 variableAttributesOption = dae_var_attr,
1946 comment = comment)
1947 algorithm
1948 ✗ Print.printBuf("VAR(");
1949 ✗ ComponentReference.printComponentRef(cr);
1950 ✗ Print.printBuf(", ");
1951 ✗ dumpKind(vk);
1952 ✗ comment_str := dumpCommentAnnotationStr(comment);
1953 ✗ Print.printBuf(" comment:");
1954 ✗ Print.printBuf(comment_str);
1955 ✗ tmp_str := dumpVariableAttributesStr(dae_var_attr);
1956 ✗ Print.printBuf(tmp_str);
1957 ✗ Print.printBuf(")");
1958 then
1959 ();
1960 case DAE.VAR(componentRef = cr,
1961 kind = vk,
1962 binding = SOME(e),
1963 variableAttributesOption = dae_var_attr,
1964 comment = comment)
1965 algorithm
1966 ✗ Print.printBuf("VAR(");
1967 ✗ ComponentReference.printComponentRef(cr);
1968 ✗ Print.printBuf(", ");
1969 ✗ dumpKind(vk);
1970 ✗ Print.printBuf(", binding: ");
1971 ✗ ExpressionDump.printExp(e);
1972 ✗ comment_str := dumpCommentAnnotationStr(comment);
1973 ✗ Print.printBuf(" comment:");
1974 ✗ Print.printBuf(comment_str);
1975 ✗ tmp_str := dumpVariableAttributesStr(dae_var_attr);
1976 ✗ Print.printBuf(tmp_str);
1977 ✗ Print.printBuf(")");
1978 then
1979 ();
1980 case DAE.DEFINE(componentRef = cr,exp = exp)
1981 algorithm
1982 ✗ Print.printBuf("DEFINE(");
1983 ✗ ComponentReference.printComponentRef(cr);
1984 ✗ Print.printBuf(", ");
1985 ✗ ExpressionDump.printExp(exp);
1986 ✗ Print.printBuf(")");
1987 then
1988 ();
1989 case DAE.INITIALDEFINE(componentRef = cr,exp = exp)
1990 algorithm
1991 ✗ Print.printBuf("INITIALDEFINE(");
1992 ✗ ComponentReference.printComponentRef(cr);
1993 ✗ Print.printBuf(", ");
1994 ✗ ExpressionDump.printExp(exp);
1995 ✗ Print.printBuf(")");
1996 then
1997 ();
1998 case DAE.EQUATION(exp = e1,scalar = e2)
1999 algorithm
2000 ✗ Print.printBuf("EQUATION(");
2001 ✗ ExpressionDump.printExp(e1);
2002 ✗ Print.printBuf(",");
2003 ✗ ExpressionDump.printExp(e2);
2004 ✗ Print.printBuf(")");
2005 then
2006 ();
2007
2008 case DAE.EQUEQUATION(cr1=cr1,cr2=cr2)
2009 algorithm
2010 ✗ Print.printBuf("EQUATION(");
2011 ✗ ComponentReference.printComponentRef(cr1);
2012 ✗ Print.printBuf(",");
2013 ✗ ComponentReference.printComponentRef(cr2);
2014 ✗ Print.printBuf(")");
2015 then
2016 ();
2017 case DAE.INITIALEQUATION(exp1 = e1,exp2 = e2)
2018 algorithm
2019 ✗ Print.printBuf("INITIALEQUATION(");
2020 ✗ ExpressionDump.printExp(e1);
2021 ✗ Print.printBuf(",");
2022 ✗ ExpressionDump.printExp(e2);
2023 ✗ Print.printBuf(")");
2024 then
2025 ();
2026 case DAE.ALGORITHM()
2027 algorithm
2028 ✗ Print.printBuf("ALGORITHM()");
2029 then
2030 ();
2031 case DAE.INITIALALGORITHM()
2032 algorithm
2033 ✗ Print.printBuf("INITIALALGORITHM()");
2034 then
2035 ();
2036 case DAE.COMP(ident = n,dAElist = l)
2037 algorithm
2038 ✗ Print.printBuf("COMP(");
2039 ✗ Print.printBuf(n);
2040 ✗ Print.printBuf(",");
2041 ✗ dumpDebugElist(l);
2042 ✗ Print.printBuf(")");
2043 then
2044 ();
2045 case DAE.ARRAY_EQUATION(exp = e1,array = e2)
2046 algorithm
2047 ✗ Print.printBuf("ARRAY_EQUATION(");
2048 ✗ ExpressionDump.printExp(e1);
2049 ✗ Print.printBuf(",");
2050 ✗ ExpressionDump.printExp(e2);
2051 ✗ Print.printBuf(")");
2052 then
2053 ();
2054 case DAE.INITIAL_ARRAY_EQUATION(exp = e1,array = e2)
2055 algorithm
2056 ✗ Print.printBuf("INITIAL_ARRAY_EQUATION(");
2057 ✗ ExpressionDump.printExp(e1);
2058 ✗ Print.printBuf(",");
2059 ✗ ExpressionDump.printExp(e2);
2060 ✗ Print.printBuf(")");
2061 then
2062 ();
2063 case DAE.COMPLEX_EQUATION(lhs = e1,rhs = e2)
2064 algorithm
2065 ✗ Print.printBuf("COMPLEX_EQUATION(");
2066 ✗ ExpressionDump.printExp(e1);
2067 ✗ Print.printBuf(",");
2068 ✗ ExpressionDump.printExp(e2);
2069 ✗ Print.printBuf(")");
2070 then
2071 ();
2072 case DAE.INITIAL_COMPLEX_EQUATION(lhs = e1,rhs = e2)
2073 algorithm
2074 ✗ Print.printBuf("INITIAL_COMPLEX_EQUATION(");
2075 ✗ ExpressionDump.printExp(e1);
2076 ✗ Print.printBuf(",");
2077 ✗ ExpressionDump.printExp(e2);
2078 ✗ Print.printBuf(")");
2079 then
2080 ();
2081 case DAE.IF_EQUATION()
2082 algorithm
2083 ✗ Print.printBuf("IF_EQUATION()");
2084 then
2085 ();
2086 case DAE.INITIAL_IF_EQUATION()
2087 algorithm
2088 ✗ Print.printBuf("INITIAL_IF_EQUATION()");
2089 then
2090 ();
2091 case DAE.WHEN_EQUATION()
2092 algorithm
2093 ✗ Print.printBuf("WHEN_EQUATION()");
2094 then
2095 ();
2096 case DAE.EXTOBJECTCLASS()
2097 algorithm
2098 ✗ Print.printBuf("EXTOBJECTCLASS()");
2099 then
2100 ();
2101 case DAE.ASSERT(condition = e1,message = e2)
2102 algorithm
2103 ✗ Print.printBuf("ASSERT(");
2104 ✗ ExpressionDump.printExp(e1);
2105 ✗ Print.printBuf(",");
2106 ✗ ExpressionDump.printExp(e2);
2107 ✗ Print.printBuf(")");
2108 then
2109 ();
2110 case DAE.INITIAL_ASSERT(condition = e1,message = e2)
2111 algorithm
2112 ✗ Print.printBuf("INITIAL_ASSERT(");
2113 ✗ ExpressionDump.printExp(e1);
2114 ✗ Print.printBuf(",");
2115 ✗ ExpressionDump.printExp(e2);
2116 ✗ Print.printBuf(")");
2117 then
2118 ();
2119 case DAE.TERMINATE(message = e1)
2120 algorithm
2121 ✗ Print.printBuf("TERMINATE(");
2122 ✗ ExpressionDump.printExp(e1);
2123 ✗ Print.printBuf(")");
2124 then
2125 ();
2126 case DAE.INITIAL_TERMINATE(message = e1)
2127 algorithm
2128 ✗ Print.printBuf("INITIAL_TERMINATE(");
2129 ✗ ExpressionDump.printExp(e1);
2130 ✗ Print.printBuf(")");
2131 then
2132 ();
2133 case DAE.REINIT()
2134 algorithm
2135 ✗ Print.printBuf("REINIT()");
2136 then
2137 ();
2138 case DAE.NORETCALL()
2139 algorithm
2140 ✗ Print.printBuf("NORETCALL()");
2141 then
2142 ();
2143 case DAE.SM_COMP(componentRef = cr,dAElist = l)
2144 algorithm
2145 ✗ Print.printBuf("SM_COMP(");
2146 ✗ ComponentReference.printComponentRef(cr);
2147 ✗ Print.printBuf(",");
2148 ✗ dumpDebugElist(l);
2149 ✗ Print.printBuf(")");
2150 then
2151 ();
2152 case DAE.FLAT_SM(ident = n,dAElist = l)
2153 algorithm
2154 ✗ Print.printBuf("FLAT_SM(");
2155 ✗ Print.printBuf(n);
2156 ✗ Print.printBuf(",");
2157 ✗ dumpDebugElist(l);
2158 ✗ Print.printBuf(")");
2159 then
2160 ();
2161 case _
2162 algorithm
2163 ✗ Print.printBuf("UNKNOWN ");
2164 then
2165 ();
2166 end matchcontinue;
2167 end dumpDebugElement;
2168
2169 public function dumpFlow "
2170 Author BZ 2008-07, dump flow properties to string."
2171 input DAE.ConnectorType var;
2172 output String flowString;
2173 algorithm
2174 flowString := match var
2175 case DAE.FLOW() then "flow";
2176 case DAE.POTENTIAL() then "effort";
2177 case DAE.NON_CONNECTOR() then "non_connector";
2178 end match;
2179 end dumpFlow;
2180
2181 public function dumpConnectorType
2182 input DAE.ConnectorType inConnectorType;
2183 output String outString;
2184 algorithm
2185 outString := match inConnectorType
2186 case DAE.FLOW() then "flow";
2187 case DAE.STREAM() then "stream";
2188 else "";
2189 end match;
2190 end dumpConnectorType;
2191
2192 public function dumpGraphviz "
2193 Graphviz functions to visualize
2194 the dae
2195 "
2196 input DAE.DAElist dae;
2197 protected
2198 Graphviz.Node r;
2199 algorithm
2200 ✗ r := buildGraphviz(dae);
2201 ✗ Graphviz.dump(r);
2202 end dumpGraphviz;
2203
2204 protected function buildGraphviz "
2205 Builds the graphviz node from a dae list.
2206 "
2207 input DAE.DAElist inDAElist;
2208 output Graphviz.Node outNode;
2209 algorithm
2210 outNode:=
2211 match inDAElist
2212 local
2213 list<DAE.Element> vars,nonvars,els;
2214 list<Graphviz.Node> nonvarnodes,varnodes,nodelist;
2215 case DAE.DAE(elementLst = els)
2216 algorithm
2217 ✗ vars := DAEUtil.getMatchingElements(els, DAEUtil.isVar);
2218 ✗ nonvars := DAEUtil.getMatchingElements(els, DAEUtil.isNotVar);
2219 ✗ nonvarnodes := buildGrList(nonvars);
2220 ✗ varnodes := buildGrVars(vars);
2221 ✗ nodelist := listAppend(nonvarnodes, varnodes);
2222 ✗ then
2223 Graphviz.NODE("DAE",{},nodelist);
2224 end match;
2225 end buildGraphviz;
2226
2227 protected function buildGrList "Helper function to build_graphviz.
2228 "
2229 input list<DAE.Element> inElementLst;
2230 output list<Graphviz.Node> outGraphvizNodeLst;
2231 algorithm
2232 outGraphvizNodeLst:=
2233 match inElementLst
2234 local
2235 Graphviz.Node node;
2236 list<Graphviz.Node> nodelist;
2237 DAE.Element el;
2238 list<DAE.Element> rest;
2239 case {} then {};
2240 case el :: rest
2241 algorithm
2242 ✗ node := buildGrElement(el);
2243 ✗ nodelist := buildGrList(rest);
2244 then
2245 (node :: nodelist);
2246 end match;
2247 end buildGrList;
2248
2249 protected function buildGrVars "Helper function to build_graphviz.
2250 "
2251 input list<DAE.Element> inElementLst;
2252 output list<Graphviz.Node> outGraphvizNodeLst;
2253 algorithm
2254 outGraphvizNodeLst := match inElementLst
2255 local
2256 list<String> strlist;
2257 list<DAE.Element> vars;
2258 case {} then {};
2259 case vars
2260 algorithm
2261 ✗ (strlist,_) := buildGrStrlist(vars, buildGrVarStr, 10);
2262 ✗ then
2263 {Graphviz.LNODE("VARS",strlist,{Graphviz.box},{})};
2264 end match;
2265 end buildGrVars;
2266
2267 public function buildGrStrlist "Helper function to build_graphviz.
2268 "
2269 input list<Type_a> inTypeALst;
2270 input FuncTypeType_aToString inFuncTypeTypeAToString;
2271 input Integer inInteger;
2272 output list<String> outStringLst;
2273 output list<Type_a> outTypeALst;
2274 replaceable type Type_a subtypeof Any;
2275 partial function FuncTypeType_aToString
2276 input Type_a inTypeA;
2277 output String outString;
2278 end FuncTypeType_aToString;
2279 algorithm
2280 (outStringLst,outTypeALst):=
2281 match (inTypeALst,inFuncTypeTypeAToString,inInteger)
2282 local
2283 list<Type_a> ignored,rest;
2284 FuncTypeType_aToString printer;
2285 Integer count,count_1;
2286 list<String> strlist;
2287 String str;
2288 Type_a var;
2289 case ({},_,_) then ({},{});
2290 case (ignored,_,count) guard count <= 0
2291 then
2292 ({"..."},ignored);
2293 case ((var :: rest),printer,count) guard count > 0
2294 algorithm
2295 ✗ count_1 := count - 1;
2296 ✗ (strlist,ignored) := buildGrStrlist(rest, printer, count_1);
2297 ✗ str := printer(var);
2298 ✗ then
2299 ((str :: strlist),ignored);
2300 end match;
2301 end buildGrStrlist;
2302
2303 protected function buildGrVarStr "Helper function to build_graphviz.
2304 "
2305 input DAE.Element inElement;
2306 output String outString;
2307 algorithm
2308 outString:=
2309 match inElement
2310 local
2311 String str,expstr,str_1,str_2;
2312 DAE.ComponentRef cr;
2313 DAE.Exp exp;
2314 case DAE.VAR(componentRef = cr,binding = NONE())
2315 algorithm
2316 ✗ str := ComponentReferenceBasics.printComponentRefStr(cr);
2317 then
2318 str;
2319 case DAE.VAR(componentRef = cr,binding = SOME(exp))
2320 algorithm
2321 ✗ str := ComponentReferenceBasics.printComponentRefStr(cr);
2322 ✗ expstr := printExpStrSpecial(exp);
2323 ✗ str_1 := stringAppend(str, " = ");
2324 ✗ str_2 := stringAppend(str_1, expstr);
2325 then
2326 str_2;
2327 end match;
2328 end buildGrVarStr;
2329
2330 protected function printExpStrSpecial "
2331 Prints an expression to a string suitable for graphviz.
2332 "
2333 input DAE.Exp inExp;
2334 output String outString;
2335 algorithm
2336 outString:=
2337 match inExp
2338 local
2339 String s_1,s_2,s,str;
2340 DAE.Exp exp;
2341 case DAE.SCONST(string = s)
2342 algorithm
2343 ✗ s_1 := stringAppend("\\\"", s);
2344 ✗ s_2 := stringAppend(s_1, "\\\"");
2345 then
2346 s_2;
2347 case exp
2348 algorithm
2349 ✗ str := ExpressionBasics.printExpStr(exp);
2350 then
2351 str;
2352 end match;
2353 end printExpStrSpecial;
2354
2355 protected function buildGrElement "
2356 Builds a Graphviz.Node from an element.
2357 "
2358 input DAE.Element inElement;
2359 output Graphviz.Node outNode;
2360 algorithm
2361 outNode := match inElement
2362 local
2363 String crstr,vkstr,expstr,expstr_1,e1str,e2str,n;
2364 DAE.ComponentRef cr,cr1,cr2;
2365 DAE.VarKind vk;
2366 DAE.Exp exp,e1,e2;
2367 list<Graphviz.Node> nodes;
2368 list<DAE.Element> elts;
2369 case DAE.VAR(componentRef = cr,kind = vk,binding = NONE())
2370 algorithm
2371 ✗ crstr := ComponentReferenceBasics.printComponentRefStr(cr);
2372 ✗ vkstr := dumpKindStr(vk);
2373 ✗ then
2374 Graphviz.LNODE("VAR",{crstr,vkstr},{},{});
2375 case DAE.VAR(componentRef = cr,kind = vk,binding = SOME(exp))
2376 algorithm
2377 ✗ crstr := ComponentReferenceBasics.printComponentRefStr(cr);
2378 ✗ vkstr := dumpKindStr(vk);
2379 ✗ expstr := printExpStrSpecial(exp);
2380 ✗ expstr_1 := stringAppend("= ", expstr);
2381 ✗ then
2382 Graphviz.LNODE("VAR",{crstr,vkstr,expstr_1},{},{});
2383 case DAE.DEFINE(componentRef = cr,exp = exp)
2384 algorithm
2385 ✗ crstr := ComponentReferenceBasics.printComponentRefStr(cr);
2386 ✗ expstr := printExpStrSpecial(exp);
2387 ✗ expstr_1 := stringAppend("= ", expstr);
2388 ✗ then
2389 Graphviz.LNODE("DEFINE",{crstr,expstr_1},{},{});
2390 case DAE.EQUATION(exp = e1,scalar = e2)
2391 algorithm
2392 ✗ e1str := printExpStrSpecial(e1);
2393 ✗ e2str := printExpStrSpecial(e2);
2394 ✗ then
2395 Graphviz.LNODE("EQUATION",{e1str,"=",e2str},{},{});
2396 case DAE.EQUEQUATION(cr1=cr1,cr2=cr2)
2397 algorithm
2398 ✗ e1str := printExpStrSpecial(Expression.crefExp(cr1));
2399 ✗ e2str := printExpStrSpecial(Expression.crefExp(cr2));
2400 ✗ then
2401 Graphviz.LNODE("EQUEQUATION",{e1str,"=",e2str},{},{});
2402 case DAE.ALGORITHM() then Graphviz.NODE("ALGORITHM",{},{});
2403 case DAE.INITIALDEFINE(componentRef = cr,exp = exp)
2404 algorithm
2405 ✗ crstr := ComponentReferenceBasics.printComponentRefStr(cr);
2406 ✗ expstr := printExpStrSpecial(exp);
2407 ✗ expstr_1 := stringAppend("= ", expstr);
2408 ✗ then
2409 Graphviz.LNODE("INITIALDEFINE",{crstr,expstr_1},{},{});
2410 case DAE.INITIALEQUATION(exp1 = e1,exp2 = e2)
2411 algorithm
2412 ✗ e1str := printExpStrSpecial(e1);
2413 ✗ e2str := printExpStrSpecial(e2);
2414 ✗ then
2415 Graphviz.LNODE("INITIALEQUATION",{e1str,"=",e2str},{},{});
2416 case DAE.INITIALALGORITHM() then Graphviz.NODE("INITIALALGORITHM",{},{});
2417 case DAE.COMP(ident = n,dAElist = elts)
2418 algorithm
2419 ✗ nodes := buildGrList(elts);
2420 ✗ then
2421 Graphviz.LNODE("COMP",{n},{},nodes);
2422 end match;
2423 end buildGrElement;
2424
2425 protected function unparseType "wrapper function for TypesDump.unparseType, so records and enumerations can be output properly"
2426 input DAE.Type tp;
2427 output String str;
2428 algorithm
2429 str := matchcontinue tp
2430 local
2431 String name, dim_str;
2432 Absyn.Path path;
2433 DAE.Type bc_tp, ty;
2434 list<DAE.Dimension> dims;
2435
2436 case DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(path))
2437 algorithm
2438 10 name := AbsynUtil.pathStringNoQual(path);
2439 then
2440 name;
2441
2442 case DAE.T_ARRAY(ty = ty)
2443 algorithm
2444
1/4
✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
42 DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(path)) :=
2445 Types.arrayElementType(ty);
2446 ✗ dims := TypesDump.getDimensions(tp);
2447 ✗ name := AbsynUtil.pathStringNoQual(path);
2448 ✗ dim_str := List.toStringCustom(dims, ExpressionBasics.dimensionString, "", "[",
2449 ", ", "]", false);
2450 ✗ then
2451 name + dim_str;
2452
2453 case DAE.T_SUBTYPE_BASIC(complexType = ty as DAE.T_SUBTYPE_BASIC())
2454 ✗ then unparseType(ty);
2455
2456 ✗ case DAE.T_SUBTYPE_BASIC(complexType = bc_tp) then TypesDump.unparseType(bc_tp);
2457 22428 else TypesDump.unparseType(tp);
2458 end matchcontinue;
2459 end unparseType;
2460
2461 public function unparseDimensions
2462 "prints dimensions to a string"
2463 input DAE.InstDims dims;
2464 input Boolean printTypeDimension "use true here when printing components in functions as these are not vectorized! Otherwise, use false";
2465 output String dimsStr;
2466 algorithm
2467 dimsStr := match(dims, printTypeDimension)
2468 local
2469 String str;
2470
2471 // false gives nothing
2472 case (_, false) then "";
2473
2474 // nothing gives nothing
2475 case ({}, true) then "";
2476 // dims give something
2477 case (_, true)
2478 algorithm
2479 38 str := "[" + stringDelimitList(List.map(dims, ExpressionBasics.dimensionString), ", ") + "]";
2480 then
2481 str;
2482 end match;
2483 end unparseDimensions;
2484
2485 public function dumpStr "This function prints the DAE to a string."
2486 input DAE.DAElist inDAElist;
2487 input AvlTreePathFunction.Tree functionTree;
2488 output String outString;
2489 protected
2490 list<DAE.Element> daelist;
2491 functionList funList;
2492 list<DAEDumpTypes.compWithSplitElements> fixedDae;
2493 algorithm
2494 1026 DAE.DAE(elementLst = daelist) := inDAElist;
2495 1026 funList := dumpFunctionList(functionTree);
2496 1026 fixedDae := List.map(daelist, DAEUtil.splitComponent);
2497 1026 outString := Tpl.tplString2(DAEDumpTpl.dumpDAE, fixedDae, funList);
2498 end dumpStr;
2499
2500 public function dumpElementsStr "This function prints the DAE to a string."
2501 input list<DAE.Element> els;
2502 output String outString;
2503 algorithm
2504 outString := match els
2505 local
2506 IOStream.IOStream myStream;
2507 String str;
2508
2509 case _
2510 algorithm
2511 ✗ myStream := IOStream.create("dae", IOStream.LIST());
2512 ✗ myStream := dumpElementsStream(els, myStream);
2513 ✗ str := IOStream.string(myStream);
2514 then
2515 str;
2516 end match;
2517 end dumpElementsStr;
2518
2519 public function dumpAlgorithmsStr "This function prints the algorithms to a string."
2520 input list<DAE.Element> algs;
2521 output String outString;
2522 algorithm
2523 outString := match algs
2524 local
2525 IOStream.IOStream myStream;
2526 String str;
2527
2528 case _
2529 algorithm
2530 19 myStream := IOStream.create("algs", IOStream.LIST());
2531 19 myStream := dumpAlgorithmsStream(algs, myStream);
2532 19 str := IOStream.string(myStream);
2533 then
2534 str;
2535 end match;
2536 end dumpAlgorithmsStr;
2537
2538
2539 public function dumpConstraintsStr "This function prints the constraints to a string."
2540 input list<DAE.Element> constrs;
2541 output String outString;
2542 algorithm
2543 outString := match constrs
2544 local
2545 IOStream.IOStream myStream;
2546 String str;
2547
2548 case _
2549 algorithm
2550 ✗ myStream := IOStream.create("constrs", IOStream.LIST());
2551 ✗ myStream := dumpConstraintStream(constrs, myStream);
2552 ✗ str := IOStream.string(myStream);
2553 then
2554 str;
2555 end match;
2556 end dumpConstraintsStr;
2557
2558 /************ IOStream based implementation ***************/
2559 /************ IOStream based implementation ***************/
2560 /************ IOStream based implementation ***************/
2561 /************ IOStream based implementation ***************/
2562
2563 public function dumpStream "This function prints the DAE to a stream."
2564 input DAE.DAElist dae;
2565 input AvlTreePathFunction.Tree functionTree;
2566 input IOStream.IOStream inStream;
2567 output IOStream.IOStream outStream;
2568 algorithm
2569 outStream := match (dae, inStream)
2570 local
2571 list<DAE.Element> daelist;
2572 list<DAE.Function> funcs;
2573 IOStream.IOStream str;
2574
2575 case (DAE.DAE(daelist), str)
2576 algorithm
2577 ✗ funcs := DAEUtil.getFunctionList(functionTree);
2578 ✗ funcs := sortFunctions(funcs);
2579 ✗ str := List.fold(funcs, dumpFunctionStream, str);
2580 ✗ str := IOStream.appendList(str, List.map(daelist, dumpExtObjClassStr));
2581 ✗ str := List.fold(daelist, dumpCompElementStream, str);
2582 then
2583 str;
2584 end match;
2585 end dumpStream;
2586
2587 public function dumpFunctionList " returns sorted functions and record constructors in alphabetical order
2588 (mainly important for template based DAE unparser)."
2589 input AvlTreePathFunction.Tree functionTree;
2590 output functionList funList;
2591 algorithm
2592 funList := match functionTree
2593 local
2594 list<DAE.Function> funcs;
2595
2596 case _
2597 algorithm
2598 1026 funcs := DAEUtil.getFunctionList(functionTree);
2599
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 1026 times.
✓ Branch 4 taken 1026 times.
✗ Branch 5 not taken.
2052 funcs := List.filter2OnTrue(funcs, isVisibleFunction,
2600 Flags.isSet(Flags.DISABLE_RECORD_CONSTRUCTOR_OUTPUT),
2601 Flags.isSet(Flags.INLINE_FUNCTIONS));
2602 1026 funcs := sortFunctions(funcs);
2603 1026 funList := FUNCTION_LIST(funcs);
2604 then
2605 (funList);
2606
2607 end match;
2608 end dumpFunctionList;
2609
2610 protected function isVisibleFunction
2611 "Returns true if the given function should be visible in the flattened output."
2612 input DAE.Function inFunc;
2613 input Boolean inHideRecordCons "Hides record constructors if true.";
2614 input Boolean inInliningEnabled "Hides early inlined functions if true.";
2615 output Boolean outIsVisible;
2616 algorithm
2617 outIsVisible := match(inFunc, inHideRecordCons, inInliningEnabled)
2618 local
2619 Option<SCode.Comment> cmt;
2620
2621 // Hide functions with 'external "builtin"'.
2622 case (DAE.FUNCTION(functions = DAE.FUNCTION_EXT(externalDecl =
2623 DAE.EXTERNALDECL(language = "builtin")) :: _), _, _) then false;
2624 // Hide functions in package OpenModelica.
2625 case (DAE.FUNCTION(path = Absyn.FULLYQUALIFIED(
2626 Absyn.QUALIFIED(name = "OpenModelica"))), _, _) then false;
2627 // Hide functions which should always be inlined.
2628 case (DAE.FUNCTION(inlineType = DAE.BUILTIN_EARLY_INLINE()), _, _) then false;
2629 // Hide functions which should be inlined unless inlining is disabled.
2630 case (DAE.FUNCTION(inlineType = DAE.EARLY_INLINE()), _, true) then false;
2631 // Hide functions with annotation __OpenModelica_builtin = true.
2632 case (DAE.FUNCTION(comment = cmt), _, _)
2633 493 then not SCodeUtil.optCommentHasBooleanNamedAnnotation(cmt, "__OpenModelica_builtin");
2634 // Hide record constructors if requested.
2635 case (DAE.RECORD_CONSTRUCTOR(), true, _) then false;
2636 else true;
2637 end match;
2638 end isVisibleFunction;
2639
2640 protected function dumpCompElementStream "Dumps components to a stream."
2641 input DAE.Element inElement;
2642 input IOStream.IOStream inStream;
2643 output IOStream.IOStream outStream;
2644 algorithm
2645 outStream := matchcontinue (inElement, inStream)
2646 local
2647 String n;
2648 list<DAE.Element> l;
2649 Option<SCode.Comment> c;
2650 IOStream.IOStream str;
2651
2652 case (DAE.COMP(ident = n,dAElist = l,comment = c), str)
2653 algorithm
2654 ✗ str := IOStream.append(str, "class ");
2655 ✗ str := IOStream.append(str, n);
2656 ✗ str := IOStream.append(str, dumpCommentStr(c));
2657 ✗ str := IOStream.append(str, "\n");
2658 ✗ str := dumpElementsStream(l, str);
2659 ✗ str := IOStream.append(str, dumpClassAnnotationStr(c));
2660 ✗ str := IOStream.append(str, "end ");
2661 ✗ str := IOStream.append(str, n);
2662 ✗ str := IOStream.append(str, ";\n");
2663 then
2664 str;
2665
2666 case (_, str) then str; /* LS: for non-COMPS, which are only FUNCTIONS at the moment */
2667 end matchcontinue;
2668 end dumpCompElementStream;
2669
2670 public function dumpElementsStream "Dump elements to a stream"
2671 input list<DAE.Element> l;
2672 input IOStream.IOStream inStream;
2673 output IOStream.IOStream outStream;
2674 algorithm
2675 outStream := match inStream
2676 local
2677 IOStream.IOStream str;
2678 list<DAE.Element> v,ie,ia,e,a,co;
2679 list<DAEDumpTypes.compWithSplitElements> sm;
2680 list<SCode.Comment> comments;
2681 Option<SCode.Annotation> ann;
2682
2683 case str
2684 algorithm
2685 // classify DAE
2686 ✗ (v,ie,ia,e,a,_,co,_,sm,comments) := DAEUtil.splitElements(l);
2687
2688 // dump components with split elements (e.g., state machines)
2689 ✗ str := dumpCompWithSplitElementsStream(sm, str);
2690
2691 // dump variables
2692 ✗ str := dumpVarsStream(v, false, str);
2693
2694 ✗ str := IOStream.append(str, if listEmpty(ie) then "" else "initial equation\n");
2695 ✗ str := dumpInitialEquationsStream(ie, str);
2696
2697 ✗ str := dumpInitialAlgorithmsStream(ia, str);
2698
2699 ✗ str := IOStream.append(str, if listEmpty(e) then "" else "equation\n");
2700 ✗ str := dumpEquationsStream(e, str);
2701
2702 ✗ str := dumpAlgorithmsStream(a, str);
2703
2704 ✗ str := IOStream.append(str, if listEmpty(co) then "" else "constraint\n");
2705 ✗ str := dumpConstraintStream(co, str);
2706
2707 ✗ str := IOStream.append(str, stringAppendList(list(match cmt
2708 case SCode.COMMENT(annotation_=ann as SOME(_))
2709 ✗ then SCodeDump.printCommentStr(SCode.COMMENT(ann,NONE()));
2710 else ""; end match for cmt in comments)));
2711 then
2712 str;
2713 end match;
2714 end dumpElementsStream;
2715
2716 public function dumpCompWithSplitElementsStream "Dump components with split elements (e.g., state machines) to a stream."
2717 input list<DAEDumpTypes.compWithSplitElements> inCompLst;
2718 input IOStream.IOStream inStream;
2719 output IOStream.IOStream outStream;
2720 algorithm
2721 outStream := match (inCompLst, inStream)
2722 local
2723 String name;
2724 splitElements spltElems;
2725 Option<SCode.Comment> comment;
2726 String cstr;
2727 IOStream.IOStream str;
2728 list<DAEDumpTypes.compWithSplitElements> xs;
2729 list<DAE.Element> v,ie,ia,e,a,co;
2730 list<DAEDumpTypes.compWithSplitElements> sm;
2731
2732 case ({}, str) then str;
2733
2734 case (COMP_WITH_SPLIT(name=name, spltElems=spltElems, comment=comment) :: xs, str)
2735 algorithm
2736 try
2737 ✗ SOME(SCode.COMMENT(comment=SOME(cstr))) := comment;
2738 ✗ cstr := " \"" + cstr + "\"";
2739 else
2740 cstr := "";
2741 end try;
2742 ✗ SPLIT_ELEMENTS(v,ie,ia,e,a,co,_,_,sm) := spltElems;
2743
2744 ✗ str := IOStream.append(str, name + cstr + "\n");
2745
2746 ✗ str := dumpCompWithSplitElementsStream(sm, str);
2747 ✗ str := dumpVarsStream(v, false, str);
2748 ✗ str := IOStream.append(str, if listEmpty(ie) then "" else "initial equation\n");
2749 ✗ str := dumpInitialEquationsStream(ie, str);
2750 ✗ str := dumpInitialAlgorithmsStream(ia, str);
2751 ✗ str := IOStream.append(str, if listEmpty(e) then "" else "equation\n");
2752 ✗ str := dumpEquationsStream(e, str);
2753 ✗ str := dumpAlgorithmsStream(a, str);
2754 ✗ str := IOStream.append(str, if listEmpty(co) then "" else "constraint\n");
2755 ✗ str := dumpConstraintStream(co, str);
2756
2757 ✗ str := IOStream.append(str, "end " + name + cstr + ";\n");
2758 ✗ str := dumpCompWithSplitElementsStream(xs, str);
2759 then
2760 str;
2761 end match;
2762 end dumpCompWithSplitElementsStream;
2763
2764 public function dumpAlgorithmsStream "Dump algorithms to a stream."
2765 input list<DAE.Element> inElementLst;
2766 input IOStream.IOStream inStream;
2767 output IOStream.IOStream outStream;
2768 algorithm
2769 outStream := matchcontinue (inElementLst, inStream)
2770 local
2771 IOStream.IOStream str;
2772 list<DAE.Statement> stmts;
2773 list<DAE.Element> xs;
2774
2775 case ({}, str) then str;
2776
2777 case (DAE.ALGORITHM(algorithm_ = DAE.ALGORITHM_STMTS(statementLst = stmts)) :: xs, str)
2778 algorithm
2779 19 str := IOStream.append(str, "algorithm\n");
2780 19 str := IOStream.appendList(str, List.map(stmts, ppStatementStr));
2781 19 str := dumpAlgorithmsStream(xs, str);
2782 then
2783 str;
2784
2785 case (_ :: xs, str)
2786 algorithm
2787 ✗ str := dumpAlgorithmsStream(xs, str);
2788 then
2789 str;
2790 end matchcontinue;
2791 end dumpAlgorithmsStream;
2792
2793 protected function dumpInitialAlgorithmsStream "Dump initialalgorithms to a stream."
2794 input list<DAE.Element> inElementLst;
2795 input IOStream.IOStream inStream;
2796 output IOStream.IOStream outStream;
2797 algorithm
2798 outStream := matchcontinue (inElementLst, inStream)
2799 local
2800 IOStream.IOStream str;
2801 list<DAE.Statement> stmts;
2802 list<DAE.Element> xs;
2803
2804 case ({}, str) then str;
2805
2806 case (DAE.INITIALALGORITHM(algorithm_ = DAE.ALGORITHM_STMTS(statementLst = stmts)) :: xs, str)
2807 algorithm
2808 ✗ str := IOStream.append(str, "initial algorithm\n");
2809 ✗ str := IOStream.appendList(str, List.map(stmts, ppStatementStr));
2810 ✗ str := dumpInitialAlgorithmsStream(xs, str);
2811 then
2812 str;
2813
2814 case (_ :: xs, str)
2815 algorithm
2816 ✗ str := dumpInitialAlgorithmsStream(xs, str);
2817 then
2818 str;
2819 end matchcontinue;
2820 end dumpInitialAlgorithmsStream;
2821
2822 protected function dumpEquationsStream "Dump equations to a stream."
2823 input list<DAE.Element> inElementLst;
2824 input IOStream.IOStream inStream;
2825 output IOStream.IOStream outStream;
2826 algorithm
2827 outStream := match (inElementLst, inStream)
2828 local
2829 String s1,s2,s3,s,sourceStr;
2830 DAE.Exp e1,e2,e;
2831 list<DAE.Exp> conds;
2832 list<DAE.Element> xs,xs1,xs2;
2833 list<list<DAE.Element>> tb;
2834 DAE.ComponentRef c,cr,cr1,cr2;
2835 IOStream.IOStream str;
2836 DAE.Element el;
2837 DAE.Dimensions dims;
2838 DAE.ElementSource src;
2839
2840 case ({}, str) then str;
2841
2842 case ((DAE.EQUATION(exp = e1, scalar = e2, source = src) :: xs), str)
2843 algorithm
2844 ✗ sourceStr := getSourceInformationStr(src);
2845 ✗ s1 := ExpressionBasics.printExpStr(e1);
2846 ✗ s2 := ExpressionBasics.printExpStr(e2);
2847 ✗ str := IOStream.appendList(str, {" ", s1, " = ", s2, sourceStr, ";\n"});
2848 ✗ str := dumpEquationsStream(xs, str);
2849 then
2850 str;
2851
2852 case ((DAE.EQUEQUATION(cr1=cr1, cr2=cr2, source = src) :: xs), str)
2853 algorithm
2854 ✗ sourceStr := getSourceInformationStr(src);
2855 ✗ str := IOStream.append(str, " " +
2856 ComponentReferenceBasics.printComponentRefStr(cr1) +
2857 " = " +
2858 ComponentReferenceBasics.printComponentRefStr(cr2) +
2859 sourceStr +
2860 ";\n");
2861 ✗ str := dumpEquationsStream(xs, str);
2862 then
2863 str;
2864
2865 case ((DAE.ARRAY_EQUATION(dimension = dims, exp = e1, array = e2, source = src) :: xs), str)
2866 algorithm
2867 ✗ sourceStr := getSourceInformationStr(src);
2868 ✗ s1 := ExpressionBasics.printExpStr(e1);
2869 ✗ s2 := ExpressionBasics.printExpStr(e2);
2870 ✗ s3 := if Config.typeinfo() then TypesDump.printDimensionsStr(dims) else "";
2871 ✗ s3 := if Config.typeinfo() then " /* array equation [" + s3 + "] */" else "";
2872 ✗ str := IOStream.appendList(str, {" ", s1, " = ", s2, s3, sourceStr, ";\n"});
2873 ✗ str := dumpEquationsStream(xs, str);
2874 then
2875 str;
2876
2877 case ((DAE.COMPLEX_EQUATION(lhs = e1, rhs= e2, source = src) :: xs), str)
2878 algorithm
2879 ✗ sourceStr := getSourceInformationStr(src);
2880 ✗ s1 := ExpressionBasics.printExpStr(e1);
2881 ✗ s2 := ExpressionBasics.printExpStr(e2);
2882 ✗ str := IOStream.appendList(str, {" ", s1, " = ", s2, sourceStr, ";\n"});
2883 ✗ str := dumpEquationsStream(xs, str);
2884 then
2885 str;
2886
2887 case ((DAE.DEFINE(componentRef = c, exp = e, source = src) :: xs), str)
2888 algorithm
2889 ✗ sourceStr := getSourceInformationStr(src);
2890 ✗ s1 := ComponentReferenceBasics.printComponentRefStr(c);
2891 ✗ s2 := ExpressionBasics.printExpStr(e);
2892 ✗ str := IOStream.appendList(str, {" ", s1, " = ", s2, sourceStr, ";\n"});
2893 ✗ str := dumpEquationsStream(xs, str);
2894 then
2895 str;
2896
2897 case ((DAE.ASSERT(condition=e1, message = e2, level = DAE.ENUM_LITERAL(index=1), source = src) :: xs), str)
2898 algorithm
2899 ✗ sourceStr := getSourceInformationStr(src);
2900 ✗ s1 := ExpressionBasics.printExpStr(e1);
2901 ✗ s2 := ExpressionBasics.printExpStr(e2);
2902 ✗ str := IOStream.appendList(str, {" assert(",s1,",",s2,")", sourceStr, ";\n"});
2903 ✗ str := dumpEquationsStream(xs, str);
2904 then
2905 str;
2906
2907 case (DAE.TERMINATE(message=e1, source = src) :: xs, str)
2908 algorithm
2909 ✗ sourceStr := getSourceInformationStr(src);
2910 ✗ s1 := ExpressionBasics.printExpStr(e1);
2911 ✗ str := IOStream.appendList(str, {" terminate(",s1,")", sourceStr, ";\n"});
2912 ✗ str := dumpEquationsStream(xs, str);
2913 then
2914 str;
2915
2916 case (DAE.FOR_EQUATION(iter = s, range = e1, equations = xs1, source = src) :: xs, str)
2917 algorithm
2918 ✗ getSourceInformationStr(src);
2919 ✗ s1 := ExpressionBasics.printExpStr(e1);
2920 ✗ str := IOStream.appendList(str, {" for ", s, " in ", s1, " loop\n"});
2921 ✗ str := dumpEquationsStream(xs1, str);
2922 ✗ str := IOStream.appendList(str, {" end for;\n"});
2923 ✗ str := dumpEquationsStream(xs, str);
2924 then
2925 str;
2926
2927 case ((DAE.IF_EQUATION(condition1 = {},equations2 = {},equations3 = {}) :: _), str)
2928 then
2929 str;
2930
2931 case ((DAE.IF_EQUATION(condition1 = (e::conds),equations2 = (xs1::tb),equations3 = {}, source = src) :: xs), str)
2932 algorithm
2933 ✗ sourceStr := getSourceInformationStr(src);
2934 ✗ str := IOStream.append(str, " if ");
2935 ✗ str := IOStream.append(str, ExpressionBasics.printExpStr(e));
2936 ✗ str := IOStream.append(str, " then\n");
2937 ✗ str := dumpEquationsStream(xs1, str);
2938 ✗ str := dumpIfEquationsStream(conds, tb, str);
2939 ✗ str := IOStream.append(str, " end if");
2940 ✗ str := IOStream.append(str, sourceStr + ";\n");
2941 ✗ str := dumpEquationsStream(xs, str);
2942 then
2943 str;
2944
2945 case ((DAE.IF_EQUATION(condition1 = (e::conds),equations2 = (xs1::tb),equations3 = xs2, source = src) :: xs), str)
2946 algorithm
2947 ✗ sourceStr := getSourceInformationStr(src);
2948 ✗ str := IOStream.append(str, " if ");
2949 ✗ str := IOStream.append(str, ExpressionBasics.printExpStr(e));
2950 ✗ str := IOStream.append(str, " then\n");
2951 ✗ str := dumpEquationsStream(xs1, str);
2952 ✗ str := dumpIfEquationsStream(conds, tb, str);
2953 ✗ str := IOStream.append(str, " else\n");
2954 ✗ str := dumpEquationsStream(xs2, str);
2955 ✗ str := IOStream.append(str, " end if" + sourceStr + ";\n");
2956 ✗ str := dumpEquationsStream(xs, str);
2957 then
2958 str;
2959
2960 case ((DAE.WHEN_EQUATION(condition = e,equations = xs1,elsewhen_ = SOME(el), source = src) :: xs), str)
2961 algorithm
2962 ✗ getSourceInformationStr(src);
2963 ✗ str := IOStream.append(str, "when ");
2964 ✗ str := IOStream.append(str, ExpressionBasics.printExpStr(e));
2965 ✗ str := IOStream.append(str, " then\n");
2966 ✗ str := dumpEquationsStream(xs1, str);
2967 ✗ str := IOStream.append(str, " else");
2968 ✗ str := dumpEquationsStream((el :: xs), str);
2969 then
2970 str;
2971
2972 case ((DAE.WHEN_EQUATION(condition = e,equations = xs1,elsewhen_ = NONE(), source = src) :: xs), str)
2973 algorithm
2974 ✗ sourceStr := getSourceInformationStr(src);
2975 ✗ str := IOStream.append(str, " when ");
2976 ✗ str := IOStream.append(str, ExpressionBasics.printExpStr(e));
2977 ✗ str := IOStream.append(str, " then\n");
2978 ✗ str := dumpEquationsStream(xs1, str);
2979 ✗ str := IOStream.append(str, " end when" + sourceStr + ";\n");
2980 ✗ str := dumpEquationsStream(xs, str);
2981 then
2982 str;
2983
2984 case ((DAE.REINIT(componentRef = cr, exp = e, source = src) :: xs), str)
2985 algorithm
2986 ✗ sourceStr := getSourceInformationStr(src);
2987 ✗ s := ComponentReferenceBasics.printComponentRefStr(cr);
2988 ✗ s1 := ExpressionBasics.printExpStr(e);
2989 ✗ str := IOStream.appendList(str, {" reinit(",s,",",s1,")",sourceStr,";\n"});
2990 ✗ str := dumpEquationsStream(xs, str);
2991 then
2992 str;
2993
2994 case ((DAE.NORETCALL(exp=e, source = src) :: xs), str)
2995 algorithm
2996 ✗ sourceStr := getSourceInformationStr(src);
2997 ✗ s1 := ExpressionBasics.printExpStr(e);
2998 ✗ str := IOStream.appendList(str, {" ",s1, sourceStr, ";\n"});
2999 ✗ str := dumpEquationsStream(xs, str);
3000 then
3001 str;
3002
3003 case ((_ :: xs), str)
3004 algorithm
3005 ✗ str := IOStream.append(str, " /* unhandled equation in DAEDump.dumpEquationsStream FIXME! */\n");
3006 ✗ str := dumpEquationsStream(xs, str);
3007 then
3008 str;
3009 end match;
3010 end dumpEquationsStream;
3011
3012 protected function dumpIfEquationsStream ""
3013 input list<DAE.Exp> iconds;
3014 input list<list<DAE.Element>> itbs;
3015 input IOStream.IOStream inStream;
3016 output IOStream.IOStream outStream;
3017 algorithm
3018 outStream := match(iconds,itbs,inStream)
3019 local
3020 DAE.Exp c;
3021 list<DAE.Element> tb;
3022 IOStream.IOStream str;
3023 list<DAE.Exp> conds;
3024 list<list<DAE.Element>> tbs;
3025
3026 case({},{},str) then str;
3027
3028 case(c::conds, tb::tbs, str)
3029 algorithm
3030 ✗ str := IOStream.append(str, " elseif ");
3031 ✗ str := IOStream.append(str, ExpressionBasics.printExpStr(c));
3032 ✗ str := IOStream.append(str, " then\n");
3033 ✗ str := dumpEquationsStream(tb, str);
3034 ✗ str := dumpIfEquationsStream(conds,tbs, str);
3035 then
3036 str;
3037 end match;
3038 end dumpIfEquationsStream;
3039
3040 protected function dumpInitialEquationsStream "Dump initial equations to a stream."
3041 input list<DAE.Element> inElementLst;
3042 input IOStream.IOStream inStream;
3043 output IOStream.IOStream outStream;
3044 algorithm
3045 outStream := matchcontinue (inElementLst, inStream)
3046 local
3047 String s1,s2,sourceStr;
3048 DAE.Exp e1,e2,e;
3049 list<DAE.Element> xs,xs1,xs2;
3050 list<list<DAE.Element>> trueBranches;
3051 DAE.ComponentRef c;
3052 IOStream.IOStream str;
3053 list<DAE.Exp> conds;
3054 DAE.ElementSource src;
3055
3056 case ({}, str) then str;
3057
3058 case ((DAE.INITIALEQUATION(exp1 = e1,exp2 = e2) :: xs), str)
3059 algorithm
3060 ✗ s1 := ExpressionBasics.printExpStr(e1);
3061 ✗ s2 := ExpressionBasics.printExpStr(e2);
3062 ✗ str := IOStream.appendList(str, {" ", s1, " = ", s2, ";\n"});
3063 ✗ str := dumpInitialEquationsStream(xs, str);
3064 then
3065 str;
3066
3067 case ((DAE.INITIAL_ARRAY_EQUATION(exp = e1, array = e2) :: xs), str)
3068 algorithm
3069 ✗ s1 := ExpressionBasics.printExpStr(e1);
3070 ✗ s2 := ExpressionBasics.printExpStr(e2);
3071 ✗ str := IOStream.appendList(str, {" ", s1, " = ", s2, ";\n"});
3072 ✗ str := dumpInitialEquationsStream(xs, str);
3073 then
3074 str;
3075
3076 case ((DAE.INITIAL_COMPLEX_EQUATION(lhs = e1,rhs = e2) :: xs), str)
3077 algorithm
3078 ✗ s1 := ExpressionBasics.printExpStr(e1);
3079 ✗ s2 := ExpressionBasics.printExpStr(e2);
3080 ✗ str := IOStream.appendList(str, {" ", s1, " = ", s2, ";\n"});
3081 ✗ str := dumpInitialEquationsStream(xs, str);
3082 then
3083 str;
3084
3085 case ((DAE.INITIALDEFINE(componentRef = c,exp = e) :: xs), str)
3086 algorithm
3087 ✗ s1 := ComponentReferenceBasics.printComponentRefStr(c);
3088 ✗ s2 := ExpressionBasics.printExpStr(e);
3089 ✗ str := IOStream.appendList(str, {" ", s1, " = ", s2, ";\n"});
3090 ✗ str := dumpInitialEquationsStream(xs, str);
3091 then
3092 str;
3093
3094 case (DAE.INITIAL_FOR_EQUATION(iter = s2, range = e1, equations = xs1, source = src) :: xs, str)
3095 algorithm
3096 ✗ getSourceInformationStr(src);
3097 ✗ s1 := ExpressionBasics.printExpStr(e1);
3098 ✗ str := IOStream.appendList(str, {" for ", s2, " in ", s1, " loop\n"});
3099 ✗ str := dumpEquationsStream(xs1, str);
3100 ✗ str := IOStream.appendList(str, {" end for;\n"});
3101 ✗ str := dumpEquationsStream(xs, str);
3102 then
3103 str;
3104
3105 case ((DAE.INITIAL_IF_EQUATION(condition1 = (e::conds),equations2 = (xs1::trueBranches),equations3 = xs2) :: xs), str)
3106 algorithm
3107 ✗ str := IOStream.append(str, " if ");
3108 ✗ str := IOStream.append(str, ExpressionBasics.printExpStr(e));
3109 ✗ str := IOStream.append(str, " then\n");
3110 ✗ str := dumpInitialEquationsStream(xs1, str);
3111 ✗ str := dumpIfEquationsStream(conds, trueBranches, str);
3112 ✗ str := IOStream.append(str, " else\n");
3113 ✗ str := dumpInitialEquationsStream(xs2, str);
3114 ✗ str := IOStream.append(str, " end if;\n");
3115 ✗ str := dumpInitialEquationsStream(xs, str);
3116 then
3117 str;
3118
3119 case ((DAE.INITIAL_NORETCALL(exp=e) :: xs), str)
3120 algorithm
3121 ✗ s1 := ExpressionBasics.printExpStr(e);
3122 ✗ str := IOStream.appendList(str, {" ",s1, ";\n"});
3123 ✗ str := dumpInitialEquationsStream(xs, str);
3124 then
3125 str;
3126
3127 case ((DAE.INITIAL_ASSERT(condition=e1, message = e2, level = DAE.ENUM_LITERAL(index=1), source = src) :: xs), str)
3128 algorithm
3129 ✗ sourceStr := getSourceInformationStr(src);
3130 ✗ s1 := ExpressionBasics.printExpStr(e1);
3131 ✗ s2 := ExpressionBasics.printExpStr(e2);
3132 ✗ str := IOStream.appendList(str, {" assert(",s1,",",s2,")", sourceStr, ";\n"});
3133 ✗ str := dumpEquationsStream(xs, str);
3134 then
3135 str;
3136
3137 case (DAE.INITIAL_TERMINATE(message=e1, source = src) :: xs, str)
3138 algorithm
3139 ✗ sourceStr := getSourceInformationStr(src);
3140 ✗ s1 := ExpressionBasics.printExpStr(e1);
3141 ✗ str := IOStream.appendList(str, {" terminate(",s1,")", sourceStr, ";\n"});
3142 ✗ str := dumpEquationsStream(xs, str);
3143 then
3144 str;
3145
3146 case ((_ :: xs), str)
3147 algorithm
3148 ✗ str := dumpInitialEquationsStream(xs, str);
3149 then
3150 str;
3151 end matchcontinue;
3152 end dumpInitialEquationsStream;
3153
3154 public function dumpConstraintStream "Dump constraints to a stream."
3155 input list<DAE.Element> inElementLst;
3156 input IOStream.IOStream inStream;
3157 output IOStream.IOStream outStream;
3158 algorithm
3159 outStream := matchcontinue (inElementLst, inStream)
3160 local
3161 IOStream.IOStream str;
3162 list<DAE.Exp> exps;
3163 list<DAE.Element> xs;
3164
3165 case ({}, str) then str;
3166
3167 case (DAE.CONSTRAINT(constraints = DAE.CONSTRAINT_EXPS(constraintLst = exps)) :: xs, str)
3168 algorithm
3169 // initial indenttion.
3170 ✗ str := IOStream.append(str, " ");
3171
3172 ✗ str := IOStream.append(str, stringDelimitList(List.map(exps, ExpressionBasics.printExpStr),";\n " ));
3173 //add the delimiter to the last element too. also if there is just 1 element in the 'exps' list.
3174 ✗ str := IOStream.append(str, ";\n");
3175 ✗ str := dumpConstraintStream(xs, str);
3176 then
3177 str;
3178
3179 case (_ :: xs, str)
3180 algorithm
3181 ✗ str := dumpConstraintStream(xs, str);
3182 then
3183 str;
3184 end matchcontinue;
3185 end dumpConstraintStream;
3186
3187 public function dumpDAEElementsStr "
3188 Author BZ
3189 print a DAE.DAEList to a string"
3190 input DAE.DAElist d;
3191 output String str;
3192 algorithm
3193 str := match d
3194 local
3195 list<DAE.Element> l;
3196 IOStream.IOStream myStream;
3197
3198 case DAE.DAE(elementLst=l)
3199 algorithm
3200 ✗ myStream := IOStream.create("", IOStream.LIST());
3201 ✗ myStream := dumpElementsStream(l, myStream);
3202 ✗ str := IOStream.string(myStream);
3203 then str;
3204 end match;
3205 end dumpDAEElementsStr;
3206
3207 public function dumpVarsStream "Dump variables to a string."
3208 input list<DAE.Element> inElementLst;
3209 input Boolean printTypeDimension "use true here when printing components in functions as these are not vectorized! Otherwise, use false";
3210 input IOStream.IOStream inStream;
3211 output IOStream.IOStream outStream;
3212 algorithm
3213 outStream := match (inElementLst, inStream)
3214 local
3215 IOStream.IOStream str;
3216 DAE.Element first;
3217 list<DAE.Element> rest;
3218 // handle nothingness
3219 case ({}, _) then inStream;
3220 // the usual case
3221 case (first :: rest, str)
3222 algorithm
3223 79 str := dumpVarStream(first, printTypeDimension, str);
3224 79 str := dumpVarsStream(rest, printTypeDimension, str);
3225 then
3226 str;
3227 end match;
3228 end dumpVarsStream;
3229
3230 public function daeTypeStr
3231 input DAE.Type inType;
3232 output String outTypeStr;
3233 protected
3234 String typeAttrStr;
3235 algorithm
3236 22369 (outTypeStr, typeAttrStr) := printTypeStr(inType);
3237
2/4
✓ Branch 0 taken 22369 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 22369 times.
✗ Branch 4 not taken.
22369 if typeAttrStr <> "" then
3238 ✗ outTypeStr := outTypeStr + " " + typeAttrStr;
3239 end if;
3240 end daeTypeStr;
3241
3242 public function printTypeStr
3243 input DAE.Type inType;
3244 output String outTypeStr;
3245 output String outTypeAttrStr;
3246 protected
3247 DAE.Type ty;
3248 list<DAE.Var> ty_vars;
3249 algorithm
3250 22438 (ty, ty_vars) := TypesDump.stripTypeVars(inType);
3251 22438 outTypeStr := unparseType(ty);
3252 22438 outTypeAttrStr := List.toStringCustom(ty_vars, TypesDump.unparseVarAttr, "", "(", ", ", ")", false);
3253 end printTypeStr;
3254
3255 public function dumpCallAttr
3256 "dumps the DAE.CallAttributes"
3257 input DAE.CallAttributes ca;
3258 protected
3259 Boolean tpl,bi,impure_,isFunc;
3260 DAE.InlineType iType;
3261 DAE.Type ty;
3262 DAE.TailCall tailCall;
3263 String s1,s2;
3264 algorithm
3265 ✗ DAE.CALL_ATTR(ty=ty,tuple_=tpl,builtin=bi,isImpure=impure_,isFunctionPointerCall=isFunc,inlineType=iType,tailCall=tailCall) := ca;
3266 ✗ print("Call attributes: \n----------------------\n");
3267 ✗ (s1,s2) := printTypeStr(ty);
3268 ✗ print("DAE-type: "+s1+"\n");
3269 ✗ print("DAE-type attributes :"+s2+"\n");
3270 ✗ print("tuple_: "+boolString(tpl)+" builtin: "+boolString(bi)+" impure: "+boolString(impure_)+" isFunctionPointerCall: "+boolString(isFunc)+"\n\n");
3271 end dumpCallAttr;
3272
3273 public function dumpVarBindingStr
3274 input Option<DAE.Exp> inBinding;
3275 output String outString;
3276 algorithm
3277 outString := match inBinding
3278 local
3279 DAE.Exp exp;
3280 String bind_str;
3281
3282 case SOME(exp)
3283 algorithm
3284 12 bind_str := ExpressionBasics.printExpStr(exp);
3285 12 then
3286 " = " + bind_str;
3287
3288 else "";
3289 end match;
3290 end dumpVarBindingStr;
3291
3292 protected function dumpVarStream
3293 "Dump var to a stream."
3294 input DAE.Element inElement;
3295 input Boolean printTypeDimension "use true here when printing components in functions as these are not vectorized! Otherwise, use false";
3296 input IOStream.IOStream inStream;
3297 output IOStream.IOStream outStream;
3298 algorithm
3299 outStream := matchcontinue(inElement, inStream)
3300 local
3301 String final_str, kind_str, dir_str, ty_str, ty_vars_str, dim_str, name_str;
3302 String vis_str, par_str, cmt_str, attr_str, binding_str;
3303 DAE.ComponentRef id;
3304 DAE.VarKind kind;
3305 DAE.VarDirection dir;
3306 DAE.VarParallelism prl;
3307 DAE.VarVisibility vis;
3308 DAE.Type ty;
3309 Option<DAE.VariableAttributes> attr;
3310 Option<SCode.Comment> cmt;
3311 Option<DAE.Exp> binding;
3312 DAE.InstDims dims;
3313 IOStream.IOStream str;
3314
3315 case (DAE.VAR(componentRef = id,
3316 kind = kind,
3317 direction = dir,
3318 parallelism = prl,
3319 protection = vis,
3320 ty = ty,
3321 dims = dims,
3322 binding = binding,
3323 variableAttributesOption = attr,
3324 comment = cmt), str)
3325 algorithm
3326
1/2
✓ Branch 1 taken 61 times.
✗ Branch 2 not taken.
61 final_str := if DAEUtil.getFinalAttr(attr) then "final " else "";
3327 61 kind_str := dumpKindStr(kind);
3328 61 dir_str := dumpDirectionStr(dir);
3329 61 (ty_str, ty_vars_str) := printTypeStr(ty);
3330 61 dim_str := unparseDimensions(dims, printTypeDimension);
3331 61 name_str := ComponentReferenceBasics.printComponentRefStr(id);
3332 61 vis_str := dumpVarVisibilityStr(vis);
3333 61 par_str := dumpVarParallelismStr(prl);
3334 61 cmt_str := dumpCommentAnnotationStr(cmt);
3335 61 attr_str := dumpVariableAttributesStr(attr);
3336 61 binding_str := dumpVarBindingStr(binding);
3337 122 str := IOStream.appendList(str, {" ", vis_str, final_str, par_str,
3338 kind_str, dir_str, ty_str, dim_str, " ", name_str, ty_vars_str,
3339 attr_str, binding_str, cmt_str, ";\n"});
3340 then
3341 str;
3342
3343 else inStream;
3344
3345 end matchcontinue;
3346 end dumpVarStream;
3347
3348 public function dumpAlgorithmStream
3349 "Dump algorithm to a stream"
3350 input DAE.Element inElement;
3351 input IOStream.IOStream inStream;
3352 output IOStream.IOStream outStream;
3353 algorithm
3354 outStream := matchcontinue (inElement, inStream)
3355 local
3356 IOStream.IOStream str;
3357 list<DAE.Statement> stmts;
3358
3359 case (DAE.ALGORITHM(algorithm_ = DAE.ALGORITHM_STMTS(statementLst = stmts)), str)
3360 algorithm
3361 ✗ str := IOStream.append(str, "algorithm\n");
3362 ✗ str := List.fold(stmts, ppStatementStream, str);
3363 then
3364 str;
3365 case (_,str) then str;
3366 end matchcontinue;
3367 end dumpAlgorithmStream;
3368
3369 public function dumpInitialAlgorithmStream
3370 "Dump algorithm to a stream"
3371 input DAE.Element inElement;
3372 input IOStream.IOStream inStream;
3373 output IOStream.IOStream outStream;
3374 algorithm
3375 outStream := matchcontinue (inElement, inStream)
3376 local
3377 IOStream.IOStream str;
3378 list<DAE.Statement> stmts;
3379
3380 case (DAE.INITIALALGORITHM(algorithm_ = DAE.ALGORITHM_STMTS(statementLst = stmts)), str)
3381 algorithm
3382 ✗ str := IOStream.append(str, "initial algorithm\n");
3383 ✗ str := List.fold(stmts, ppStatementStream, str);
3384 then
3385 str;
3386 case (_,str) then str;
3387 end matchcontinue;
3388 end dumpInitialAlgorithmStream;
3389
3390 public function ppStatementStream
3391 "Prettyprint an algorithm statement to a string."
3392 input DAE.Statement alg;
3393 input IOStream.IOStream inStream;
3394 output IOStream.IOStream outStream;
3395 protected
3396 Integer hnd;
3397 algorithm
3398 ✗ hnd := Print.saveAndClearBuf();
3399 ✗ ppStatement(alg);
3400 ✗ outStream := IOStream.append(inStream, Print.getString());
3401 ✗ Print.restoreBuf(hnd);
3402 end ppStatementStream;
3403
3404 public function dumpFunctionTree
3405 input AvlTreePathFunction.Tree inFunctionTree;
3406 input String inHeading;
3407 algorithm
3408 ✗ print("\n" + inHeading + "\n========================================\n");
3409 ✗ for fnc in sortFunctions(DAEUtil.getFunctionList(inFunctionTree)) loop
3410 ✗ print(dumpFunctionStr(fnc));
3411 end for;
3412 end dumpFunctionTree;
3413
3414 public function dumpFunctionStr "Dump function to a string."
3415 input DAE.Function inElement;
3416 output String outString;
3417 algorithm
3418 outString := matchcontinue inElement
3419 local
3420 String s;
3421 Integer hnd;
3422
3423 case _
3424 algorithm
3425 19 hnd := Print.saveAndClearBuf();
3426 19 dumpFunction(inElement);
3427 19 s := Print.getString();
3428 19 Print.restoreBuf(hnd);
3429 then
3430 s;
3431
3432 else "";
3433 end matchcontinue;
3434 end dumpFunctionStr;
3435
3436 protected function dumpExtObjClassStr
3437 "Dump external object class to a string."
3438 input DAE.Element inElement;
3439 output String outString;
3440 algorithm
3441 outString := matchcontinue inElement
3442 local
3443 String s;
3444 Integer hnd;
3445
3446 case DAE.EXTOBJECTCLASS()
3447 algorithm
3448 ✗ hnd := Print.saveAndClearBuf();
3449 ✗ dumpExtObjectClass(inElement);
3450 ✗ s := Print.getString();
3451 ✗ Print.restoreBuf(hnd);
3452 then
3453 s;
3454
3455 else "";
3456 end matchcontinue;
3457 end dumpExtObjClassStr;
3458
3459 protected function dumpFunctionStream
3460 "Dump function to a stream"
3461 input DAE.Function inElement;
3462 input IOStream.IOStream inStream;
3463 output IOStream.IOStream outStream;
3464 algorithm
3465 outStream := matchcontinue (inElement, inStream)
3466 local
3467 String fstr, ext_decl_str, impureStr, ann_str;
3468 Absyn.Path fpath;
3469 list<DAE.Element> daeElts;
3470 DAE.Type t;
3471 DAE.Type tp;
3472 IOStream.IOStream str;
3473 Option<SCode.Comment> c;
3474 DAE.ExternalDecl ext_decl;
3475 Boolean isImpure;
3476
3477 case (DAE.FUNCTION(path = fpath, functions = (DAE.FUNCTION_DEF(body = daeElts)::_),
3478 type_ = t, isImpure = isImpure, comment = c), str)
3479 algorithm
3480 ✗ str := IOStream.append(str, dumpParallelismStr(t));
3481 ✗ fstr := AbsynUtil.pathStringNoQual(fpath);
3482 ✗ impureStr := if isImpure then "impure " else "";
3483 ✗ str := IOStream.append(str, impureStr);
3484 ✗ str := IOStream.append(str, "function ");
3485 ✗ str := IOStream.append(str, fstr);
3486 ✗ str := IOStream.append(str, dumpCommentStr(c));
3487 ✗ str := IOStream.append(str, "\n");
3488 ✗ str := dumpFunctionElementsStream(daeElts, str);
3489 ✗ str := IOStream.append(str, dumpClassAnnotationStr(c));
3490 ✗ str := IOStream.append(str, "end ");
3491 ✗ str := IOStream.append(str, fstr);
3492 ✗ str := IOStream.append(str, ";\n\n");
3493 then
3494 str;
3495
3496 case (DAE.FUNCTION(functions=(DAE.FUNCTION_EXT(externalDecl = DAE.EXTERNALDECL(language="builtin"))::_)), str)
3497 then
3498 str;
3499
3500 case (DAE.FUNCTION(path = fpath, functions = (DAE.FUNCTION_EXT(body = daeElts, externalDecl = ext_decl)::_),
3501 isImpure = isImpure, comment = c), str)
3502 algorithm
3503 ✗ fstr := AbsynUtil.pathStringNoQual(fpath);
3504 ✗ impureStr := if isImpure then "impure " else "";
3505 ✗ str := IOStream.append(str, impureStr);
3506 ✗ str := IOStream.append(str, "function ");
3507 ✗ str := IOStream.append(str, fstr);
3508 ✗ str := IOStream.append(str, dumpCommentStr(c));
3509 ✗ str := IOStream.append(str, "\n");
3510 ✗ str := dumpFunctionElementsStream(daeElts, str);
3511 ✗ ext_decl_str := dumpExtDeclStr(ext_decl);
3512 ✗ ann_str := dumpClassAnnotationStr(c);
3513 ✗ str := IOStream.appendList(str, {"\n ", ext_decl_str, "\n", ann_str, "end ", fstr, ";\n\n"});
3514 then
3515 str;
3516
3517 case (DAE.RECORD_CONSTRUCTOR(path = fpath,type_=tp), str)
3518 algorithm
3519 ✗ false := Flags.isSet(Flags.DISABLE_RECORD_CONSTRUCTOR_OUTPUT);
3520
3521 ✗ if Flags.isSet(Flags.PRINT_RECORD_TYPES) then
3522 ✗ str := IOStream.append(str, TypesDump.unparseType(tp));
3523 ✗ str := IOStream.append(str, "\n");
3524 else
3525 ✗ fstr := AbsynUtil.pathStringNoQual(fpath);
3526 ✗ str := IOStream.append(str, "function ");
3527 ✗ str := IOStream.append(str, fstr);
3528 ✗ str := IOStream.append(str, " \"Automatically generated record constructor for " + fstr + "\"\n");
3529 ✗ str := IOStream.append(str, printRecordConstructorInputsStr(tp));
3530 ✗ str := IOStream.append(str, " output "+AbsynUtil.pathLastIdent(fpath) + " res;\n");
3531 ✗ str := IOStream.append(str, "end ");
3532 ✗ str := IOStream.append(str, fstr);
3533 ✗ str := IOStream.append(str, ";\n\n");
3534 end if;
3535 then
3536 str;
3537
3538 case (_, str) then str;
3539 end matchcontinue;
3540 end dumpFunctionStream;
3541
3542 public function dumpFunctionElementsStream "Dump function elements to a stream."
3543 input list<DAE.Element> l;
3544 input IOStream.IOStream inStream;
3545 output IOStream.IOStream outStream;
3546 algorithm
3547 ✗ outStream := dumpVarsStream(l, true, inStream);
3548 ✗ outStream := List.fold(l, dumpAlgorithmStream, outStream);
3549 end dumpFunctionElementsStream;
3550
3551 public function unparseVarKind
3552 input DAE.VarKind inVarKind;
3553 output String outString;
3554 algorithm
3555 outString := match inVarKind
3556 case DAE.VARIABLE() then "";
3557 case DAE.PARAM() then "parameter";
3558 case DAE.CONST() then "const";
3559 case DAE.DISCRETE() then "discrete";
3560 end match;
3561 end unparseVarKind;
3562
3563 public function unparseVarDirection
3564 input DAE.VarDirection inVarDirection;
3565 output String outString;
3566 algorithm
3567 outString := match inVarDirection
3568 case DAE.BIDIR() then "";
3569 case DAE.INPUT() then "input";
3570 case DAE.OUTPUT() then "output";
3571 end match;
3572 end unparseVarDirection;
3573
3574 function unparseVarInnerOuter
3575 input DAE.VarInnerOuter io;
3576 output String str;
3577 algorithm
3578 str := match io
3579 case DAE.VarInnerOuter.INNER() then "inner";
3580 case DAE.VarInnerOuter.OUTER() then "outer";
3581 case DAE.VarInnerOuter.INNER_OUTER() then "inner outer";
3582 else "";
3583 end match;
3584 end unparseVarInnerOuter;
3585
3586 public function getSourceInformationStr
3587 "@author: adrpo
3588 display the source information as string"
3589 input DAE.ElementSource inSource;
3590 output String outStr;
3591 algorithm
3592 outStr := matchcontinue inSource
3593 local
3594 list<Absyn.Within> po;
3595 list<tuple<DAE.ComponentRef, DAE.ComponentRef>> ceol;
3596 list<SCode.Comment> cmt;
3597 String str;
3598
3599 case _
3600 algorithm
3601 ✗ false := Flags.isSet(Flags.SHOW_EQUATION_SOURCE);
3602 then
3603 "";
3604
3605 case DAE.SOURCE(_, po, _, ceol, _, _, cmt)
3606 algorithm
3607 ✗ str := cmtListToString(cmt);
3608 ✗ str := str + " /* models: {" + stringDelimitList(List.map(po, withinString), ", ") + "}" +
3609 " connects: {" + stringDelimitList(connectsStr(ceol), ", ") + "} */";
3610 then
3611 str;
3612 end matchcontinue;
3613 end getSourceInformationStr;
3614
3615 protected function connectsStr
3616 input list<tuple<DAE.ComponentRef, DAE.ComponentRef>> inLst;
3617 output list<String> outStr;
3618 algorithm
3619 outStr := matchcontinue inLst
3620 local
3621 list<tuple<DAE.ComponentRef, DAE.ComponentRef>> rest;
3622 list<String> slst;
3623 String str;
3624 DAE.ComponentRef c1, c2;
3625
3626 case {} then {};
3627
3628 case {(c1,c2)}
3629 algorithm
3630 ✗ str := ComponentReferenceBasics.printComponentRefStr(c1) + "," +
3631 ComponentReferenceBasics.printComponentRefStr(c2);
3632 ✗ str := "connect(" + str + ")";
3633 then
3634 {str};
3635
3636 case (c1,c2)::rest
3637 algorithm
3638 ✗ str := ComponentReferenceBasics.printComponentRefStr(c1) + "," +
3639 ComponentReferenceBasics.printComponentRefStr(c2);
3640 ✗ str := "connect(" + str + ")";
3641 ✗ slst := connectsStr(rest);
3642 then
3643 str::slst;
3644
3645 end matchcontinue;
3646 end connectsStr;
3647
3648 protected function withinString
3649 input Absyn.Within w;
3650 output String str;
3651 algorithm
3652 str := match w
3653 local
3654 Absyn.Path p1;
3655 case Absyn.TOP() then "TOP";
3656 ✗ case Absyn.WITHIN(p1) then AbsynUtil.pathString(p1);
3657 end match;
3658 end withinString;
3659
3660 public function cmtListToString
3661 input list<SCode.Comment> inCmtLst;
3662 output String outStr;
3663 algorithm
3664 outStr := match inCmtLst
3665 local
3666 SCode.Comment c;
3667 list<SCode.Comment> rest;
3668 String str;
3669
3670 case {} then "";
3671
3672 case {c}
3673 algorithm
3674 39 str := dumpCommentAnnotationStr(SOME(c));
3675 then
3676 str;
3677
3678 case c::rest
3679 algorithm
3680 ✗ str := dumpCommentAnnotationStr(SOME(c));
3681 ✗ str := str + " " + cmtListToString(rest);
3682 then
3683 str;
3684
3685 else "";
3686
3687 end match;
3688 end cmtListToString;
3689
3690 public function clockKindString
3691 input DAE.ClockKind cK;
3692 output String sOut;
3693 algorithm
3694 sOut := match cK
3695 local
3696 DAE.Exp e1,e2;
3697 case DAE.INFERRED_CLOCK()
3698 then "Inferred Clock";
3699 case DAE.RATIONAL_CLOCK(intervalCounter=e1, resolution=e2)
3700 ✗ then "Rational Clock("+ExpressionBasics.printExpStr(e1)+"; "+ExpressionBasics.printExpStr(e2)+")";
3701 case DAE.REAL_CLOCK(interval=e1)
3702 ✗ then "Real Clock("+ExpressionBasics.printExpStr(e1)+")";
3703 case DAE.EVENT_CLOCK(condition=e1, startInterval=e2)
3704 ✗ then "Event Clock("+ExpressionBasics.printExpStr(e1)+"; "+ExpressionBasics.printExpStr(e2)+")";
3705 case DAE.SOLVER_CLOCK(c=e1, solverMethod=e2)
3706 ✗ then "Solver Clock("+ExpressionBasics.printExpStr(e1)+"; "+ExpressionBasics.printExpStr(e2)+")";
3707 end match;
3708 end clockKindString;
3709
3710
3711 public function dumpDebugElementStr "Dump equation to a string.For debug purposes."
3712 input DAE.Element inElement;
3713 output String outString;
3714 algorithm
3715 outString := matchcontinue inElement
3716 local
3717 Absyn.Path path;
3718 String s1,s2,str,sourceStr;
3719 DAE.Exp e1,e2;
3720 DAE.ComponentRef c,cr1,cr2;
3721 list<DAE.Element> elst;
3722 Absyn.Path path;
3723 DAE.ElementSource src;
3724 list<SCode.Comment> cmt;
3725
3726 case DAE.VAR(componentRef = c)
3727 algorithm
3728 ✗ s1 := ComponentReferenceBasics.printComponentRefStr(c);
3729 ✗ str := stringAppendList({"VAR: ", s1,";\n"});
3730 then
3731 str;
3732
3733 case DAE.DEFINE(componentRef = c,source = src)
3734 algorithm
3735 ✗ cmt := ElementSource.getComments(src);
3736 ✗ sourceStr := cmtListToString(cmt);
3737 ✗ s1 := ComponentReferenceBasics.printComponentRefStr(c);
3738 ✗ str := stringAppend(s1, sourceStr + ";\n");
3739 then
3740 str;
3741
3742 case DAE.INITIALDEFINE(componentRef = c,source = src)
3743 algorithm
3744 ✗ cmt := ElementSource.getComments(src);
3745 ✗ sourceStr := cmtListToString(cmt);
3746 ✗ s1 := ComponentReferenceBasics.printComponentRefStr(c);
3747 ✗ str := stringAppend(s1, sourceStr + ";\n");
3748 then
3749 str;
3750
3751 case DAE.EQUATION(exp = e1,scalar = e2,source = src)
3752 algorithm
3753 ✗ cmt := ElementSource.getComments(src);
3754 ✗ sourceStr := cmtListToString(cmt);
3755 ✗ s1 := ExpressionBasics.printExpStr(e1);
3756 ✗ s2 := ExpressionBasics.printExpStr(e2);
3757 ✗ str := stringAppendList({" ", s1, " = ", s2, sourceStr, ";\n"});
3758 then
3759 str;
3760
3761 case DAE.EQUEQUATION(cr1=cr1,cr2=cr2,source = src)
3762 algorithm
3763 ✗ cmt := ElementSource.getComments(src);
3764 ✗ sourceStr := cmtListToString(cmt);
3765 ✗ s1 := ComponentReferenceBasics.printComponentRefStr(cr1);
3766 ✗ s2 := ComponentReferenceBasics.printComponentRefStr(cr2);
3767 ✗ str := stringAppendList({"EQUEQUATION ", s1, " = ", s2, sourceStr, ";\n"});
3768 then
3769 str;
3770
3771 case DAE.ARRAY_EQUATION(exp=e1,array=e2,source = src)
3772 algorithm
3773 ✗ cmt := ElementSource.getComments(src);
3774 ✗ sourceStr := cmtListToString(cmt);
3775 ✗ s1 := ExpressionBasics.printExpStr(e1);
3776 ✗ s2 := ExpressionBasics.printExpStr(e2);
3777 ✗ str := "ARRAY_EQUATION " + s1 + " = " + s2 + sourceStr + ";\n";
3778 then
3779 str;
3780
3781 case DAE.INITIAL_ARRAY_EQUATION(exp=e1,array=e2,source = src)
3782 algorithm
3783 ✗ cmt := ElementSource.getComments(src);
3784 ✗ sourceStr := cmtListToString(cmt);
3785 ✗ s1 := ExpressionBasics.printExpStr(e1);
3786 ✗ s2 := ExpressionBasics.printExpStr(e2);
3787 ✗ str := "INITIAL_ARRAY_EQUATION " + s1 + " = " + s2 + sourceStr + ";\n";
3788 then
3789 str;
3790
3791 case DAE.COMPLEX_EQUATION(lhs=e1,rhs=e2,source = src)
3792 algorithm
3793 ✗ cmt := ElementSource.getComments(src);
3794 ✗ sourceStr := cmtListToString(cmt);
3795 ✗ s1 := ExpressionBasics.printExpStr(e1);
3796 ✗ s2 := ExpressionBasics.printExpStr(e2);
3797 ✗ str := "COMPLEX_EQUATION " + s1 + " = " + s2 + sourceStr + ";\n";
3798 then
3799 str;
3800
3801 case DAE.INITIAL_COMPLEX_EQUATION(lhs=e1,rhs=e2,source = src)
3802 algorithm
3803 ✗ cmt := ElementSource.getComments(src);
3804 ✗ sourceStr := cmtListToString(cmt);
3805 ✗ s1 := ExpressionBasics.printExpStr(e1);
3806 ✗ s2 := ExpressionBasics.printExpStr(e2);
3807 ✗ str := "INITIAL_COMPLEX_EQUATION " + s1 + " = " + s2 + sourceStr + ";\n";
3808 then
3809 str;
3810
3811 case DAE.WHEN_EQUATION(condition = e1,source = src)
3812 algorithm
3813 ✗ cmt := ElementSource.getComments(src);
3814 ✗ sourceStr := cmtListToString(cmt);
3815 ✗ s1 := ExpressionBasics.printExpStr(e1);
3816 ✗ str := stringAppendList({"WHEN_EQUATION: ", s1, sourceStr, ";\n"});
3817 then
3818 str;
3819
3820 case DAE.IF_EQUATION(source = src)
3821 algorithm
3822 ✗ cmt := ElementSource.getComments(src);
3823 ✗ sourceStr := cmtListToString(cmt);
3824 ✗ str := stringAppendList({"IF_EQUATION: ", sourceStr, ";\n"});
3825 then
3826 str;
3827
3828 case DAE.INITIAL_IF_EQUATION(source = src)
3829 algorithm
3830 ✗ cmt := ElementSource.getComments(src);
3831 ✗ sourceStr := cmtListToString(cmt);
3832 ✗ str := stringAppendList({"INITIAL_IF_EQUATION: ", sourceStr, ";\n"});
3833 then
3834 str;
3835
3836 case DAE.INITIALEQUATION(exp1 = e1,exp2 = e2,source = src)
3837 algorithm
3838 ✗ cmt := ElementSource.getComments(src);
3839 ✗ sourceStr := cmtListToString(cmt);
3840 ✗ s1 := ExpressionBasics.printExpStr(e1);
3841 ✗ s2 := ExpressionBasics.printExpStr(e2);
3842 ✗ str := stringAppendList({"INITIALEQUATION ", s1, " = ", s2, sourceStr, ";\n"});
3843 then
3844 str;
3845
3846 case DAE.ALGORITHM(source = src)
3847 algorithm
3848 ✗ cmt := ElementSource.getComments(src);
3849 ✗ sourceStr := cmtListToString(cmt);
3850 ✗ str := stringAppendList({"ALGO ", sourceStr, ";\n"});
3851 then
3852 str;
3853
3854 case DAE.INITIALALGORITHM(source = src)
3855 algorithm
3856 ✗ cmt := ElementSource.getComments(src);
3857 ✗ sourceStr := cmtListToString(cmt);
3858 ✗ str := stringAppendList({"INITIALALGORITHM ", sourceStr, ";\n"});
3859 then
3860 str;
3861
3862 case DAE.COMP(source = src, dAElist = elst)
3863 algorithm
3864 ✗ cmt := ElementSource.getComments(src);
3865 ✗ sourceStr := cmtListToString(cmt);
3866 ✗ s1 := stringDelimitList(List.map(elst,DAEDump.dumpDebugElementStr),"\n");
3867 ✗ str := stringAppendList({"COMP ",s1, sourceStr, ";\n"});
3868 then
3869 str;
3870
3871 case DAE.EXTOBJECTCLASS(path = path, source = src)
3872 algorithm
3873 ✗ cmt := ElementSource.getComments(src);
3874 ✗ sourceStr := cmtListToString(cmt);
3875 ✗ s1 := AbsynUtil.pathString(path);
3876 ✗ str := stringAppendList({"EXTOBJ ",s1," ", sourceStr, ";\n"});
3877 then
3878 str;
3879
3880 case DAE.ASSERT(condition=e1,message = e2,source = src)
3881 algorithm
3882 ✗ cmt := ElementSource.getComments(src);
3883 ✗ sourceStr := cmtListToString(cmt);
3884 ✗ s1 := ExpressionBasics.printExpStr(e1);
3885 ✗ s2 := ExpressionBasics.printExpStr(e2);
3886 ✗ str := stringAppendList({" assert(",s1, ",",s2,") ", sourceStr, ";\n"});
3887 then
3888 str;
3889
3890 case DAE.INITIAL_ASSERT(condition=e1,message = e2,source = src)
3891 algorithm
3892 ✗ cmt := ElementSource.getComments(src);
3893 ✗ sourceStr := cmtListToString(cmt);
3894 ✗ s1 := ExpressionBasics.printExpStr(e1);
3895 ✗ s2 := ExpressionBasics.printExpStr(e2);
3896 ✗ str := stringAppendList({" /* initial */ assert(",s1, ",",s2,") ", sourceStr, ";\n"});
3897 then
3898 str;
3899
3900 case DAE.TERMINATE(message=e1,source = src)
3901 algorithm
3902 ✗ cmt := ElementSource.getComments(src);
3903 ✗ sourceStr := cmtListToString(cmt);
3904 ✗ s1 := ExpressionBasics.printExpStr(e1);
3905 ✗ str := stringAppendList({" terminate(",s1,") ", sourceStr, ";\n"});
3906 then
3907 str;
3908
3909 case DAE.INITIAL_TERMINATE(message=e1,source = src)
3910 algorithm
3911 ✗ cmt := ElementSource.getComments(src);
3912 ✗ sourceStr := cmtListToString(cmt);
3913 ✗ s1 := ExpressionBasics.printExpStr(e1);
3914 ✗ str := stringAppendList({" /* initial */ terminate(",s1,") ", sourceStr, ";\n"});
3915 then
3916 str;
3917
3918 case DAE.REINIT(source = src)
3919 algorithm
3920 ✗ cmt := ElementSource.getComments(src);
3921 ✗ sourceStr := cmtListToString(cmt);
3922 ✗ str := stringAppendList({" reinit(",") ", sourceStr, ";\n"});
3923 then
3924 str;
3925
3926 case DAE.NORETCALL(exp=e1,source = src)
3927 algorithm
3928 ✗ cmt := ElementSource.getComments(src);
3929 ✗ sourceStr := cmtListToString(cmt);
3930 ✗ s1 := ExpressionBasics.printExpStr(e1);
3931 ✗ str := stringAppendList({" ", s1, sourceStr, ";\n"});
3932 then
3933 str;
3934 else "#UNKNOWN_EQUATION#";
3935 end matchcontinue;
3936 end dumpDebugElementStr;
3937
3938 protected function getOptionWithConcatStr "
3939 Get option string value using a function translating the value to a string
3940 and concatenate with an additional suffix string.
3941 "
3942 input Option<Type_a> inTypeAOption;
3943 input FuncTypeType_aToString inFuncTypeTypeAToString;
3944 input String inString;
3945 output String outString;
3946 replaceable type Type_a subtypeof Any;
3947 partial function FuncTypeType_aToString
3948 input Type_a inTypeA;
3949 output String outString;
3950 end FuncTypeType_aToString;
3951 algorithm
3952 outString:=
3953 match (inTypeAOption,inFuncTypeTypeAToString,inString)
3954 local
3955 String str,str_1,default_str;
3956 Type_a a;
3957 FuncTypeType_aToString r;
3958 case (SOME(a),r,default_str) /* suffix */
3959 algorithm
3960
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
30 str := r(a);
3961 30 str_1 := stringAppend(default_str, str);
3962 then
3963 str_1;
3964 case (NONE(),_,_) then "";
3965 end match;
3966 end getOptionWithConcatStr;
3967
3968
3969 annotation(__OpenModelica_Interface="frontend_base");
3970 end DAEDump;
3971