Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 8.4% 39 / 0 / 463
Functions: -% 0 / 1 / 1
Branches: 31.6% 12 / 0 / 38

OMCompiler/Compiler/FrontEnd/ExpressionDump.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 ExpressionDump
37 " file: ExpressionDump.mo
38 package: ExpressionDump
39 description: ExpressionDump
40
41
42 This file contains the module ExpressionDump, which contains functions
43 to dump and print DAE.Expression."
44
45 // public imports
46 public import Absyn;
47 public import AbsynUtil;
48 public import DAE;
49 public import ExpressionBasics;
50 public import Graphviz;
51
52 // protected imports
53 protected import ComponentReference;
54 protected import ComponentReferenceBasics;
55 protected import Config;
56 protected import DAEDump;
57 protected import Dump;
58 protected import Error;
59 protected import Expression;
60 public import ExpressionDumpTpl;
61 protected import List;
62 protected import Print;
63 protected import System;
64 protected import Tpl;
65 protected import Types;
66 protected import Util;
67
68 /*
69 * - Printing expressions
70 * This module provides some functions to print data to the standard
71 * output. This is used for error messages, and for debugging the
72 * semantic description.
73 */
74
75 public function subscriptString
76 "Returns a string representation of a subscript."
77 input DAE.Subscript subscript;
78 output String str;
79 algorithm
80 str := match subscript
81 local
82 Integer i;
83 String res;
84 Absyn.Path enum_lit;
85 case DAE.INDEX(exp = DAE.ICONST(integer = i))
86 algorithm
87 4 res := intString(i);
88 then
89 res;
90 case DAE.INDEX(exp = DAE.ENUM_LITERAL(name = enum_lit))
91 algorithm
92 ✗ res := AbsynUtil.pathString(enum_lit);
93 then
94 res;
95 end match;
96 end subscriptString;
97
98 public function binopSymbol "
99 function: binopSymbol
100 Return a string representation of the Operator."
101 input DAE.Operator inOperator;
102 output String outString;
103 algorithm
104
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3575 times.
3575 outString := if Config.typeinfo()
105 then binopSymbol2(inOperator)
106 else binopSymbol1(inOperator);
107 end binopSymbol;
108
109 public function binopSymbol1
110 "Helper function to binopSymbol"
111 input DAE.Operator inOperator;
112 output String outString;
113 algorithm
114 outString := match inOperator
115 case DAE.ADD() then " + ";
116 case DAE.SUB() then " - ";
117 case DAE.MUL() then " * ";
118 case DAE.DIV() then " / ";
119 case DAE.POW() then " ^ ";
120 case DAE.ADD_ARR() then " + ";
121 case DAE.SUB_ARR() then " - ";
122 case DAE.MUL_ARR() then " * ";
123 case DAE.DIV_ARR() then " / ";
124 case DAE.POW_ARR() then " ^ ";
125 case DAE.POW_ARR2() then " ^ ";
126 case DAE.MUL_ARRAY_SCALAR() then " * ";
127 case DAE.ADD_ARRAY_SCALAR() then " + ";
128 case DAE.SUB_SCALAR_ARRAY() then " - ";
129 case DAE.POW_SCALAR_ARRAY() then " ^ ";
130 case DAE.POW_ARRAY_SCALAR() then " ^ ";
131 case DAE.MUL_SCALAR_PRODUCT() then " * ";
132 case DAE.MUL_MATRIX_PRODUCT() then " * ";
133 case DAE.DIV_SCALAR_ARRAY() then " / ";
134 case DAE.DIV_ARRAY_SCALAR() then " / ";
135 else " <UNKNOWN_SYMBOL> ";
136 end match;
137 end binopSymbol1;
138
139 public function debugBinopSymbol
140 "Helper function to binopSymbol"
141 input DAE.Operator inOperator;
142 output String outString;
143 algorithm
144 outString := match inOperator
145 case DAE.ADD() then " + ";
146 case DAE.SUB() then " - ";
147 case DAE.MUL() then " * ";
148 case DAE.DIV() then " / ";
149 case DAE.POW() then " ^ ";
150 case DAE.EQUAL() then " = ";
151 case DAE.ADD_ARR() then " +ARR ";
152 case DAE.SUB_ARR() then " -ARR ";
153 case DAE.MUL_ARR() then " *ARR ";
154 case DAE.DIV_ARR() then " /ARR ";
155 case DAE.POW_ARR() then " ^ARR ";
156 case DAE.POW_ARR2() then " ^ARR2 ";
157 case DAE.MUL_ARRAY_SCALAR() then " ARR*S ";
158 case DAE.ADD_ARRAY_SCALAR() then " ARR+S ";
159 case DAE.SUB_SCALAR_ARRAY() then " - ";
160 case DAE.POW_SCALAR_ARRAY() then " S^ARR ";
161 case DAE.POW_ARRAY_SCALAR() then " ARR^S ";
162 case DAE.MUL_SCALAR_PRODUCT() then " Dot ";
163 case DAE.MUL_MATRIX_PRODUCT() then " MatrixProd ";
164 case DAE.DIV_SCALAR_ARRAY() then " S/ARR ";
165 case DAE.DIV_ARRAY_SCALAR() then " ARR/S ";
166 end match;
167 end debugBinopSymbol;
168
169 protected function binopSymbol2
170 "Helper function to binopSymbol."
171 input DAE.Operator inOperator;
172 output String outString;
173 algorithm
174 outString := match inOperator
175 local
176 String ts,s;
177 DAE.Type t;
178
179 case DAE.ADD(ty = t)
180 algorithm
181 ✗ ts := TypesDump.unparseType(t);
182 ✗ s := stringAppendList({" +<", ts, "> "});
183 then
184 s;
185
186 case DAE.SUB(ty = t)
187 algorithm
188 ✗ ts := TypesDump.unparseType(t);
189 ✗ s := stringAppendList({" -<", ts, "> "});
190 then
191 s;
192
193 case DAE.MUL(ty = t)
194 algorithm
195 ✗ ts := TypesDump.unparseType(t);
196 ✗ s := stringAppendList({" *<", ts, "> "});
197 then
198 s;
199
200 case DAE.DIV(ty = t)
201 algorithm
202 ✗ ts := TypesDump.unparseType(t);
203 ✗ s := stringAppendList({" /<", ts, "> "});
204 then
205 s;
206
207 case DAE.POW() then " ^ ";
208 case DAE.ADD_ARR(ty = t)
209 algorithm
210 ✗ ts := TypesDump.unparseType(t);
211 ✗ s := stringAppendList({" +<ADD_ARR><", ts, "> "});
212 then
213 s;
214 case DAE.SUB_ARR(ty = t)
215 algorithm
216 ✗ ts := TypesDump.unparseType(t);
217 ✗ s := stringAppendList({" -<SUB_ARR><", ts, "> "});
218 then
219 s;
220 case DAE.MUL_ARR() then " *<MUL_ARRAY> ";
221 case DAE.DIV_ARR(ty = t)
222 algorithm
223 ✗ ts := TypesDump.unparseType(t);
224 ✗ s := stringAppendList({" /<DIV_ARR><", ts, "> "});
225 then
226 s;
227 case DAE.POW_ARR() then " ^<POW_ARR> ";
228 case DAE.POW_ARR2() then " ^<POW_ARR2> ";
229 case DAE.MUL_ARRAY_SCALAR() then " *<MUL_ARRAY_SCALAR> ";
230 case DAE.ADD_ARRAY_SCALAR() then " +<ADD_ARRAY_SCALAR> ";
231 case DAE.SUB_SCALAR_ARRAY() then " -<SUB_SCALAR_ARRAY> ";
232 case DAE.POW_SCALAR_ARRAY() then " ^<POW_SCALAR_ARRAY> ";
233 case DAE.POW_ARRAY_SCALAR() then " ^<POW_ARRAY_SCALAR> ";
234 case DAE.MUL_SCALAR_PRODUCT() then " *<MUL_SCALAR_PRODUCT> ";
235 case DAE.MUL_MATRIX_PRODUCT() then " *<MUL_MATRIX_PRODUCT> ";
236 case DAE.DIV_SCALAR_ARRAY() then " /<DIV_SCALAR_ARRAY> ";
237 case DAE.DIV_ARRAY_SCALAR() then " /<DIV_ARRAY_SCALAR> ";
238 end match;
239 end binopSymbol2;
240
241 public function unaryopSymbol
242 "Return string representation of unary operators."
243 input DAE.Operator inOperator;
244 output String outString;
245 algorithm
246 outString:=
247 match inOperator
248
1/2
✓ Branch 1 taken 560 times.
✗ Branch 2 not taken.
560 case DAE.UMINUS() then if Config.typeinfo() then "-<UMINUS>" else "-";
249 ✗ case DAE.UMINUS_ARR() then if Config.typeinfo() then "-<UMINUS_ARR>" else "-";
250 end match;
251 end unaryopSymbol;
252
253 public function lbinopSymbol
254 "Return string representation of logical binary operator."
255 input DAE.Operator inOperator;
256 output String outString;
257 algorithm
258 outString:=
259 match inOperator
260 case DAE.AND(_) then " and ";
261 case DAE.OR(_) then " or ";
262 end match;
263 end lbinopSymbol;
264
265 public function lunaryopSymbol
266 "Return string representation of logical unary operator."
267 input DAE.Operator inOperator;
268 output String outString;
269 algorithm
270 outString := match inOperator
271 case DAE.NOT(_) then "not ";
272 end match;
273 end lunaryopSymbol;
274
275 public function relopSymbol
276 "Return string representation of function operator."
277 input DAE.Operator inOperator;
278 output String outString;
279 algorithm
280 outString:=
281 match inOperator
282 case DAE.LESS() then " < ";
283 case DAE.LESSEQ() then " <= ";
284 case DAE.GREATER() then " > ";
285 case DAE.GREATEREQ() then " >= ";
286 case DAE.EQUAL() then " == ";
287 case DAE.NEQUAL() then " <> ";
288 end match;
289 end relopSymbol;
290
291 public function printList
292 "Print a list of values given a print
293 function and a separator string."
294 input list<Type_a> inTypeALst;
295 input FuncTypeType_aTo inFuncTypeTypeATo;
296 input String inString;
297 replaceable type Type_a subtypeof Any;
298 partial function FuncTypeType_aTo
299 input Type_a inTypeA;
300 end FuncTypeType_aTo;
301 algorithm
302 ():=
303 matchcontinue (inTypeALst,inFuncTypeTypeATo,inString)
304 local
305 Type_a h;
306 FuncTypeType_aTo r;
307 list<Type_a> t;
308 String sep;
309 case ({},_,_) then ();
310 case ({h},r,_)
311 algorithm
312 ✗ r(h);
313 then
314 ();
315 case ((h :: t),r,sep)
316 algorithm
317 ✗ r(h);
318 ✗ Print.printBuf(sep);
319 ✗ printList(t, r, sep);
320 then
321 ();
322 end matchcontinue;
323 end printList;
324
325 protected function printRow
326 "Print a list of expressions to the Print buffer."
327 input list<DAE.Exp> es_1;
328 algorithm
329 ✗ printList(es_1, printExp, ",");
330 end printRow;
331
332 public function debugPrintSubscriptStr "
333 Print a Subscript into a String."
334 input DAE.Subscript inSubscript;
335 output String outString;
336 algorithm
337 outString := match inSubscript
338 local
339 String s;
340 DAE.Exp e1;
341 case DAE.WHOLEDIM() then ":";
342 case DAE.INDEX(exp = e1)
343 algorithm
344 ✗ s := dumpExpStr(e1,0);
345 ✗ s := System.stringReplace(s, "\n", "");
346 then
347 s;
348 case DAE.SLICE(exp = e1)
349 algorithm
350 ✗ s := dumpExpStr(e1,0);
351 ✗ s := System.stringReplace(s, "\n", "");
352 then
353 s;
354 case DAE.WHOLE_NONEXP(exp = e1)
355 algorithm
356 ✗ s := dumpExpStr(e1,0);
357 ✗ s := System.stringReplace(s, "\n", "");
358 ✗ then
359 "1:"+s;
360 end match;
361 end debugPrintSubscriptStr;
362
363 public function printSubscriptLstStr
364 "Print a list of Subscripts into a String."
365 input list<DAE.Subscript> inSubscriptLst;
366 output String outString;
367 algorithm
368 ✗ outString := stringDelimitList(List.map(inSubscriptLst,ExpressionBasics.printSubscriptStr)," , ");
369 end printSubscriptLstStr;
370
371 public function printExpListStr
372 " prints a list of expressions with commas between expressions."
373 input list<DAE.Exp> expl;
374 output String res;
375 algorithm
376 37 res := stringDelimitList(List.map(expl,ExpressionBasics.printExpStr),", ");
377 end printExpListStr;
378
379 // stefan
380 public function printExpListStrNoSpace
381 "same as printExpListStr, but the string will not have any spaces or commas between expressions"
382 input list<DAE.Exp> expl;
383 output String res;
384 algorithm
385 ✗ res := stringAppendList(List.map(expl,ExpressionBasics.printExpStr));
386 end printExpListStrNoSpace;
387
388 public function printOptExpStr "
389 Returns a string if SOME otherwise ''"
390 input Option<DAE.Exp> oexp;
391 output String str;
392 algorithm
393 str := match oexp
394 local DAE.Exp e;
395 133 case SOME(e) then ExpressionBasics.printExpStr(e);
396 else "";
397 end match;
398 end printOptExpStr;
399
400 public function printCrefsFromExpStr
401 input DAE.Exp e;
402 output String s;
403 algorithm
404 ✗ s := Tpl.tplString2(ExpressionDumpTpl.dumpExpCrefs, e, "");
405 end printCrefsFromExpStr;
406
407 public function printExp2Str
408 "Helper function to printExpStr."
409 input DAE.Exp inExp;
410 input String stringDelimiter;
411 input Option<tuple<printComponentRefStrFunc,Type_a>> opcreffunc "tuple of function that prints component references and an extra parameter passed through to the function";
412 input Option<printCallFunc> opcallfunc "function that prints function calls";
413 output String outString;
414 replaceable type Type_a subtypeof Any;
415 partial function printComponentRefStrFunc
416 input DAE.ComponentRef inComponentRef;
417 input Type_a Param;
418 output String outString;
419 end printComponentRefStrFunc;
420 partial function printCallFunc
421 input DAE.Exp inExp;
422 input String stringDelimiter;
423 input Option<tuple<printComponentRefStrFunc,Type_a>> opcreffunc "tuple of function that prints component references and an extra parameter passed through to the function";
424 output String outString;
425 partial function printComponentRefStrFunc
426 input DAE.ComponentRef inComponentRef;
427 input Type_a Param;
428 output String outString;
429 end printComponentRefStrFunc;
430 end printCallFunc;
431 algorithm
432 outString := matchcontinue (inExp, opcreffunc, opcallfunc)
433 local
434 String s,s_1,s_2,sym,s1,s2,s3,s4,res,fs,argstr,s_4,str,crstr,dimstr,expstr,iterstr,s1_1,s2_1,cs,ts,cs_1,ts_1,fs_1,s3_1;
435 Integer i,pe1,p1,p2,pc,pt,pf,p,pstop,pstart,pstep;
436 Real r;
437 DAE.ComponentRef c,name;
438 DAE.Type tp;
439 DAE.Exp e1,e2,e,start,stop,step,cr,dim,exp,cond,tb,fb;
440 DAE.Operator op;
441 Absyn.Path fcn,lit;
442 list<DAE.Exp> args,es;
443 printComponentRefStrFunc pcreffunc;
444 Type_a creffuncparam;
445 printCallFunc pcallfunc;
446 Boolean b;
447 list<DAE.Exp> aexpl;
448 list<list<DAE.Exp>> lstes;
449 DAE.MatchType matchTy;
450 list<DAE.MatchCase> cases;
451 DAE.Pattern pat;
452 Absyn.CodeNode code;
453 DAE.ReductionIterators riters;
454 String scope, tyStr;
455 list<DAE.Subscript> subs;
456
457 case (DAE.EMPTY(scope = scope, name = name, tyStr = tyStr), _, _)
458 ✗ then "<EMPTY(scope: " + scope + ", name: " + ComponentReferenceBasics.printComponentRefStr(name) + ", ty: " + tyStr + ")>";
459
460 case (DAE.ICONST(integer = i), _, _)
461 algorithm
462 ✗ s := intString(i);
463 then
464 s;
465
466 case (DAE.RCONST(real = r), _, _)
467 algorithm
468 137 s := realString(r);
469 then
470 s;
471
472 case (DAE.SCONST(string = s), _, _)
473 algorithm
474 ✗ s := System.escapedString(s,false);
475 ✗ s := stringAppendList({stringDelimiter, s, stringDelimiter});
476 then
477 s;
478
479 ✗ case (DAE.BCONST(bool = b), _, _) then boolString(b);
480
481 case (DAE.CREF(componentRef = c), SOME((pcreffunc,creffuncparam)), _)
482 algorithm
483 ✗ s := pcreffunc(c,creffuncparam);
484 then
485 s;
486
487 case (DAE.CREF(componentRef = c), _, _)
488 algorithm
489 1641 s := ComponentReferenceBasics.printComponentRefStr(c);
490
5/6
✓ Branch 2 taken 163 times.
✓ Branch 3 taken 1478 times.
✓ Branch 6 taken 55 times.
✓ Branch 7 taken 108 times.
✓ Branch 10 taken 55 times.
✗ Branch 11 not taken.
1641 if listMember("dataReconciliation", Flags.getConfigStringList(Flags.PRE_OPT_MODULES_ADD)) or listMember("dataReconciliationStateEstimation", Flags.getConfigStringList(Flags.PRE_OPT_MODULES_ADD)) or listMember("dataReconciliationBoundaryConditions", Flags.getConfigStringList(Flags.PRE_OPT_MODULES_ADD)) then
491 1641 s := System.stringReplace(s, ".", "_"); // replace cref's to modelica output format for dumping to reconciled_dataReconciliation.mo
492 end if;
493 then
494 s;
495
496 case (DAE.ENUM_LITERAL(name = lit), _, _)
497 algorithm
498 ✗ s := AbsynUtil.pathString(lit);
499 then
500 s;
501
502 case (e as DAE.BINARY(e1,op,e2), _, _)
503 algorithm
504 480 sym := binopSymbol(op);
505 480 s1 := printExp2Str(e1, stringDelimiter, opcreffunc, opcallfunc);
506 480 s2 := printExp2Str(e2, stringDelimiter, opcreffunc, opcallfunc);
507 480 p := expPriority(e);
508 480 p1 := expPriority(e1);
509 480 p2 := expPriority(e2);
510 480 s1_1 := parenthesize(s1, p1, p,false);
511 480 s2_1 := parenthesize(s2, p2, p,true);
512 480 s := stringAppendList({s1_1, sym, s2_1});
513 then
514 s;
515
516 case ((e as DAE.UNARY(op,e1)), _, _)
517 algorithm
518 14 sym := unaryopSymbol(op);
519 14 s := printExp2Str(e1, stringDelimiter, opcreffunc, opcallfunc);
520 14 p := expPriority(e);
521 14 p1 := expPriority(e1);
522 14 s_1 := parenthesize(s, p1, p,true);
523 14 s_2 := stringAppend(sym, s_1);
524 then
525 s_2;
526
527 case ((e as DAE.LBINARY(e1,op,e2)), _, _)
528 algorithm
529 ✗ sym := lbinopSymbol(op);
530 ✗ s1 := printExp2Str(e1, stringDelimiter, opcreffunc, opcallfunc);
531 ✗ s2 := printExp2Str(e2, stringDelimiter, opcreffunc, opcallfunc);
532 ✗ p := expPriority(e);
533 ✗ p1 := expPriority(e1);
534 ✗ p2 := expPriority(e2);
535 ✗ s1_1 := parenthesize(s1, p1, p,false);
536 ✗ s2_1 := parenthesize(s2, p2, p,true);
537 ✗ s := stringAppendList({s1_1, sym, s2_1});
538 then
539 s;
540
541 case ((e as DAE.LUNARY(op,e1)), _, _)
542 algorithm
543 ✗ sym := lunaryopSymbol(op);
544 ✗ s := printExp2Str(e1, stringDelimiter, opcreffunc, opcallfunc);
545 ✗ p := expPriority(e);
546 ✗ p1 := expPriority(e1);
547 ✗ s_1 := parenthesize(s, p1, p,false);
548 ✗ s_2 := stringAppend(sym, s_1);
549 then
550 s_2;
551
552 case ((e as DAE.RELATION(exp1=e1,operator=op,exp2=e2)), _, _)
553 algorithm
554 ✗ sym := relopSymbol(op);
555 ✗ s1 := printExp2Str(e1, stringDelimiter, opcreffunc, opcallfunc);
556 ✗ s2 := printExp2Str(e2, stringDelimiter, opcreffunc, opcallfunc);
557 ✗ p := expPriority(e);
558 ✗ p1 := expPriority(e1);
559 ✗ p2 := expPriority(e2);
560 ✗ s1_1 := parenthesize(s1, p1, p,false);
561 ✗ s2_1 := parenthesize(s2, p2, p,true);
562 ✗ s := stringAppendList({s1_1, sym, s2_1});
563 then
564 s;
565
566 case ((e as DAE.IFEXP(cond,tb,fb)), _, _)
567 algorithm
568 ✗ cs := printExp2Str(cond, stringDelimiter, opcreffunc, opcallfunc);
569 ✗ ts := printExp2Str(tb, stringDelimiter, opcreffunc, opcallfunc);
570 ✗ fs := printExp2Str(fb, stringDelimiter, opcreffunc, opcallfunc);
571 ✗ p := expPriority(e);
572 ✗ pc := expPriority(cond);
573 ✗ pt := expPriority(tb);
574 ✗ pf := expPriority(fb);
575 ✗ cs_1 := parenthesize(cs, pc, p,false);
576 ✗ ts_1 := parenthesize(ts, pt, p,false);
577 ✗ fs_1 := parenthesize(fs, pf, p,false);
578 ✗ str := stringAppendList({"if ",cs_1," then ",ts_1," else ",fs_1});
579 then
580 str;
581
582 case (e as DAE.CALL(), _, SOME(pcallfunc))
583 algorithm
584 ✗ s_2 := pcallfunc(e,stringDelimiter,opcreffunc);
585 then
586 s_2;
587
588 case (DAE.CALL(path = fcn,expLst = args), _, _)
589 algorithm
590 51 fs := AbsynUtil.pathString(AbsynUtil.makeNotFullyQualified(fcn));
591 51 argstr := stringDelimitList(
592 List.map3(args, printExp2Str, stringDelimiter, opcreffunc, opcallfunc), ",");
593 51 s := stringAppendList({fs, "(", argstr, ")"});
594 then
595 s;
596
597 case (DAE.PARTEVALFUNCTION(path = fcn, expList = args), _, _)
598 algorithm
599 ✗ fs := AbsynUtil.pathString(AbsynUtil.makeNotFullyQualified(fcn));
600 ✗ argstr := stringDelimitList(
601 List.map3(args, printExp2Str, stringDelimiter, opcreffunc, opcallfunc), ",");
602 ✗ s := stringAppendList({"function ", fs, "(", argstr, ")"});
603 then
604 s;
605
606 case (DAE.ARRAY(array = es), _, _)
607 algorithm
608 // s3 = TypesDump.unparseType(tp); // adrpo: not used!
609 ✗ s := stringDelimitList(
610 List.map3(es, printExp2Str, stringDelimiter, opcreffunc, opcallfunc), ",");
611 ✗ s := stringAppendList({"{", s, "}"});
612 then
613 s;
614
615 case (DAE.TUPLE(PR = es), _, _)
616 algorithm
617 2 s := stringDelimitList(
618 List.map3(es, printExp2Str, stringDelimiter, opcreffunc, opcallfunc), ",");
619 2 s := stringAppendList({"(", s, ")"});
620 then
621 s;
622
623 case (DAE.MATRIX(matrix = lstes), _, _)
624 algorithm
625 // s3 = TypesDump.unparseType(tp); // adrpo: not used!
626 ✗ s := stringDelimitList(List.map1(lstes, printRowStr, stringDelimiter), "},{");
627 ✗ s := stringAppendList({"{{",s,"}}"});
628 then
629 s;
630
631 case (e as DAE.RANGE(_,start,NONE(),stop), _, _)
632 algorithm
633 ✗ s1 := printExp2Str(start, stringDelimiter, opcreffunc, opcallfunc);
634 ✗ s3 := printExp2Str(stop, stringDelimiter, opcreffunc, opcallfunc);
635 ✗ p := expPriority(e);
636 ✗ pstart := expPriority(start);
637 ✗ pstop := expPriority(stop);
638 ✗ s1_1 := parenthesize(s1, pstart, p,false);
639 ✗ s3_1 := parenthesize(s3, pstop, p,false);
640 ✗ s := stringAppendList({s1_1, ":", s3_1});
641 then
642 s;
643
644 case ((e as DAE.RANGE(_,start,SOME(step),stop)), _, _)
645 algorithm
646 ✗ s1 := printExp2Str(start, stringDelimiter, opcreffunc, opcallfunc);
647 ✗ s2 := printExp2Str(step, stringDelimiter, opcreffunc, opcallfunc);
648 ✗ s3 := printExp2Str(stop, stringDelimiter, opcreffunc, opcallfunc);
649 ✗ p := expPriority(e);
650 ✗ pstart := expPriority(start);
651 ✗ pstop := expPriority(stop);
652 ✗ pstep := expPriority(step);
653 ✗ s1_1 := parenthesize(s1, pstart, p,false);
654 ✗ s3_1 := parenthesize(s3, pstop, p,false);
655 ✗ s2_1 := parenthesize(s2, pstep, p,false);
656 ✗ s := stringAppendList({s1_1,":",s2_1,":",s3_1});
657 then
658 s;
659
660 case (DAE.CAST(ty = tp,exp = e), _, _)
661 algorithm
662 ✗ str := TypesDump.unparseType(tp);
663 ✗ s := printExp2Str(e, stringDelimiter, opcreffunc, opcallfunc);
664 ✗ res := stringAppendList({"DAE.CAST(",str,", ",s,")"});
665 then
666 res;
667
668 case (e as DAE.ASUB(exp = e1,sub = subs), _, _)
669 algorithm
670 ✗ aexpl := list(Expression.getSubscriptExp(sub) for sub in subs);
671 ✗ p := expPriority(e);
672 ✗ pe1 := expPriority(e1);
673 ✗ s1 := printExp2Str(e1, stringDelimiter, opcreffunc, opcallfunc);
674 ✗ s1_1 := parenthesize(s1, pe1, p,false);
675 ✗ s4 := stringDelimitList(
676 List.map3(aexpl,printExp2Str, stringDelimiter, opcreffunc, opcallfunc),",");
677 ✗ s_4 := s1_1+ "["+ s4 + "]";
678 then
679 s_4;
680
681 case (DAE.SIZE(exp = cr,sz = SOME(dim)), _, _)
682 algorithm
683 ✗ crstr := printExp2Str(cr, stringDelimiter, opcreffunc, opcallfunc);
684 ✗ dimstr := printExp2Str(dim, stringDelimiter, opcreffunc, opcallfunc);
685 ✗ str := stringAppendList({"size(",crstr,",",dimstr,")"});
686 then
687 str;
688
689 case (DAE.SIZE(exp = cr,sz = NONE()), _, _)
690 algorithm
691 ✗ crstr := printExp2Str(cr, stringDelimiter, opcreffunc, opcallfunc);
692 ✗ str := stringAppendList({"size(",crstr,")"});
693 then
694 str;
695
696 case (DAE.REDUCTION(reductionInfo=DAE.REDUCTIONINFO(path = fcn),expr = exp,iterators = riters), _, _)
697 algorithm
698 ✗ fs := AbsynUtil.pathStringNoQual(fcn);
699 ✗ expstr := printExp2Str(exp, stringDelimiter, opcreffunc, opcallfunc);
700 ✗ iterstr := stringDelimitList(List.map(riters, reductionIteratorStr),",");
701 ✗ str := stringAppendList({"<reduction>",fs,"(",expstr," for ",iterstr,")"});
702 then
703 str;
704
705 // MetaModelica tuple
706 case (DAE.META_TUPLE(es), _, _)
707 algorithm
708 ✗ s := "Tuple" + printExp2Str(DAE.TUPLE(es), stringDelimiter, opcreffunc, opcallfunc);
709 then
710 s;
711
712 // MetaModelica list
713 case (DAE.LIST(valList=es), _, _)
714 algorithm
715 ✗ s := stringDelimitList(List.map3(es,printExp2Str, stringDelimiter, opcreffunc, opcallfunc),",");
716 ✗ s := stringAppendList({"List(", s, ")"});
717 then
718 s;
719
720 // MetaModelica list cons
721 case (DAE.CONS(car=e1,cdr=e2), _, _)
722 algorithm
723 ✗ s1 := printExp2Str(e1, stringDelimiter, opcreffunc, opcallfunc);
724 ✗ s2 := printExp2Str(e2, stringDelimiter, opcreffunc, opcallfunc);
725 ✗ s_2 := stringAppendList({"listCons(", s1, ",", s2, ")"});
726 then
727 s_2;
728
729 // MetaModelica Option
730 case (DAE.META_OPTION(NONE()), _, _) then "NONE()";
731 case (DAE.META_OPTION(SOME(e1)), _, _)
732 algorithm
733 ✗ s1 := printExp2Str(e1, stringDelimiter, opcreffunc, opcallfunc);
734 ✗ s_1 := stringAppendList({"SOME(",s1,")"});
735 then
736 s_1;
737
738 case (DAE.BOX(e1), _, _)
739 algorithm
740 ✗ s1 := printExp2Str(e1, stringDelimiter, opcreffunc, opcallfunc);
741 ✗ s_1 := stringAppendList({"#(",s1,")"});
742 then
743 s_1;
744
745 case (DAE.UNBOX(e1,_), _, _)
746 algorithm
747 ✗ s1 := printExp2Str(e1, stringDelimiter, opcreffunc, opcallfunc);
748 ✗ s_1 := stringAppendList({"unbox(",s1,")"});
749 then
750 s_1;
751
752 // MetaModelica Uniontype Constructor
753 case (DAE.METARECORDCALL(path = fcn, args=args), _, _)
754 algorithm
755 ✗ fs := AbsynUtil.pathString(fcn);
756 ✗ argstr := stringDelimitList(
757 List.map3(args,printExp2Str, stringDelimiter, opcreffunc, opcallfunc),",");
758 ✗ s := stringAppendList({fs, "(", argstr, ")"});
759 then
760 s;
761
762 case (DAE.MATCHEXPRESSION(matchType=matchTy,inputs=es,cases=cases), _, _)
763 algorithm
764 ✗ s1 := printMatchType(matchTy);
765 ✗ s2 := printExp2Str(DAE.TUPLE(es), stringDelimiter, opcreffunc, opcallfunc);
766 ✗ s3 := stringAppendList(List.map(cases,printCase2Str));
767 ✗ s := stringAppendList({s1,s2,"\n",s3," end ",s1});
768 then s;
769
770 case (DAE.SHARED_LITERAL(exp=e), _, _)
771 ✗ then printExp2Str(e, stringDelimiter, opcreffunc, opcallfunc);
772
773 case (DAE.PATTERN(pattern=pat), _, _)
774 ✗ then patternStr(pat);
775
776 ✗ case (DAE.CODE(code=code), _, _) then "$Code(" + Dump.printCodeStr(code) + ")";
777
778 ✗ else printExpTypeStr(inExp);
779
780 end matchcontinue;
781 end printExp2Str;
782
783 protected function printExpTypeStr
784 "Prints out the name of the expression uniontype to a string."
785 input DAE.Exp inExp;
786 output String outString;
787 algorithm
788 outString := match inExp
789 case DAE.ICONST(_) then "ICONST";
790 case DAE.RCONST(_) then "RCONST";
791 case DAE.SCONST(_) then "SCONST";
792 case DAE.BCONST(_) then "BCONST";
793 case DAE.ENUM_LITERAL() then "ENUM_LITERAL";
794 case DAE.CREF() then "CREF";
795 case DAE.BINARY() then "BINARY";
796 case DAE.UNARY() then "UNARY";
797 case DAE.LBINARY() then "LBINARY";
798 case DAE.LUNARY() then "LUNARY";
799 case DAE.RELATION() then "RELATION";
800 case DAE.IFEXP() then "IFEXP";
801 case DAE.CALL() then "CALL";
802 case DAE.PARTEVALFUNCTION() then "PARTEVALFUNCTION";
803 case DAE.ARRAY() then "ARRAY";
804 case DAE.MATRIX() then "MATRIX";
805 case DAE.RANGE() then "RANGE";
806 case DAE.TUPLE() then "TUPLE";
807 case DAE.CAST() then "CAST";
808 case DAE.ASUB() then "ASUB";
809 case DAE.TSUB() then "TSUB";
810 case DAE.SIZE() then "SIZE";
811 case DAE.CODE() then "CODE";
812 case DAE.EMPTY() then "EMPTY";
813 case DAE.REDUCTION() then "REDUCTION";
814 case DAE.LIST() then "LIST";
815 case DAE.CONS() then "CAR";
816 case DAE.META_TUPLE() then "META_TUPLE";
817 case DAE.META_OPTION() then "META_OPTION";
818 case DAE.METARECORDCALL() then "METARECORDCALL";
819 case DAE.MATCHEXPRESSION() then "MATCHEXPRESSION";
820 case DAE.BOX() then "BOX";
821 case DAE.UNBOX() then "UNBOX";
822 case DAE.SHARED_LITERAL() then "SHARED_LITERAL";
823 case DAE.PATTERN() then "PATTERN";
824 else "#UNKNOWN EXPRESSION#";
825 end match;
826 end printExpTypeStr;
827
828 protected function reductionIteratorStr
829 input DAE.ReductionIterator riter;
830 output String str;
831 algorithm
832 str := match riter
833 local
834 String id;
835 DAE.Exp exp,gexp;
836 case DAE.REDUCTIONITER(id=id,exp=exp,guardExp=NONE())
837 algorithm
838 ✗ str := id + " in " + ExpressionBasics.printExpStr(exp);
839 then str;
840 case DAE.REDUCTIONITER(id=id,exp=exp,guardExp=SOME(gexp))
841 algorithm
842 ✗ str := id + " guard " + ExpressionBasics.printExpStr(gexp) + " in " + ExpressionBasics.printExpStr(exp);
843 then str;
844 end match;
845 end reductionIteratorStr;
846
847 protected function printMatchType
848 input DAE.MatchType ty;
849 output String str;
850 algorithm
851 str := match ty
852 case DAE.MATCHCONTINUE() then "matchcontinue";
853 case DAE.MATCH(NONE()) then "match";
854 case DAE.MATCH(SOME(_)) then "match /* switch */";
855 end match;
856 end printMatchType;
857
858 protected function printCase2Str
859 "Prints a matchcase as string"
860 input DAE.MatchCase matchCase;
861 output String str;
862 algorithm
863 str := match matchCase
864 local
865 list<DAE.Pattern> patterns;
866 list<DAE.Statement> body;
867 DAE.Exp result;
868 String resultStr,patternsStr,bodyStr;
869 case DAE.CASE(patterns=patterns, body={}, result=SOME(result))
870 algorithm
871 ✗ patternsStr := patternStr(DAE.PAT_META_TUPLE(patterns));
872 ✗ resultStr := ExpressionBasics.printExpStr(result);
873 ✗ then stringAppendList({" case ",patternsStr," then ",resultStr,";\n"});
874 case DAE.CASE(patterns=patterns, body={}, result=NONE())
875 algorithm
876 ✗ patternsStr := patternStr(DAE.PAT_META_TUPLE(patterns));
877 ✗ then stringAppendList({" case ",patternsStr," then fail();\n"});
878 case DAE.CASE(patterns=patterns, body=body, result=SOME(result))
879 algorithm
880 ✗ patternsStr := patternStr(DAE.PAT_META_TUPLE(patterns));
881 ✗ resultStr := ExpressionBasics.printExpStr(result);
882 ✗ bodyStr := stringAppendList(List.map1(body, DAEDump.ppStmtStr, 8));
883 ✗ then stringAppendList({" case ",patternsStr,"\n algorithm\n",bodyStr," then ",resultStr,";\n"});
884 case DAE.CASE(patterns=patterns, body=body, result=NONE())
885 algorithm
886 ✗ patternsStr := patternStr(DAE.PAT_META_TUPLE(patterns));
887 ✗ bodyStr := stringAppendList(List.map1(body, DAEDump.ppStmtStr, 8));
888 ✗ then stringAppendList({" case ",patternsStr,"\n algorithm\n",bodyStr," then fail();\n"});
889 end match;
890 end printCase2Str;
891
892 public function expPriority
893 " Returns a priority number for an expression.
894 This function is used to output parenthesis
895 when needed, e.g., 3(1+2) should output 3(1+2)
896 and not 31+2."
897 input DAE.Exp inExp;
898 output Integer outInteger;
899 algorithm
900 outInteger := match inExp
901 case DAE.ICONST(_) then 0;
902 case DAE.RCONST(_) then 0;
903 case DAE.SCONST(_) then 0;
904 case DAE.BCONST(_) then 0;
905 case DAE.ENUM_LITERAL() then 0;
906 case DAE.CREF(_,_) then 0;
907 case DAE.ASUB(_,_) then 0;
908 case DAE.CAST(_,_) then 0;
909 case DAE.CALL() then 0;
910 case DAE.PARTEVALFUNCTION() then 0;
911 case DAE.ARRAY() then 0;
912 case DAE.MATRIX() then 0;
913 case DAE.BINARY(operator = DAE.POW(_)) then 3;
914 case DAE.BINARY(operator = DAE.POW_ARR(_)) then 3;
915 case DAE.BINARY(operator = DAE.POW_ARR2(_)) then 3;
916 case DAE.BINARY(operator = DAE.POW_SCALAR_ARRAY(_)) then 3;
917 case DAE.BINARY(operator = DAE.POW_ARRAY_SCALAR(_)) then 3;
918 case DAE.BINARY(operator = DAE.DIV(_)) then 5;
919 case DAE.BINARY(operator = DAE.DIV_ARR(_)) then 5;
920 case DAE.BINARY(operator = DAE.DIV_SCALAR_ARRAY(_)) then 5;
921 case DAE.BINARY(operator = DAE.DIV_ARRAY_SCALAR(_)) then 5;
922 case DAE.BINARY(operator = DAE.MUL(_)) then 7;
923 case DAE.BINARY(operator = DAE.MUL_ARR(_)) then 7;
924 case DAE.BINARY(operator = DAE.MUL_ARRAY_SCALAR(_)) then 7;
925 case DAE.BINARY(operator = DAE.MUL_SCALAR_PRODUCT(_)) then 7;
926 case DAE.BINARY(operator = DAE.MUL_MATRIX_PRODUCT(_)) then 7;
927 case DAE.UNARY(operator = DAE.UMINUS(_)) then 8;
928 case DAE.UNARY(operator = DAE.UMINUS_ARR(_)) then 8;
929 case DAE.BINARY(operator = DAE.ADD(_)) then 9;
930 case DAE.BINARY(operator = DAE.ADD_ARR(_)) then 9;
931 case DAE.BINARY(operator = DAE.ADD_ARRAY_SCALAR(_)) then 9;
932 case DAE.BINARY(operator = DAE.SUB(_)) then 9;
933 case DAE.BINARY(operator = DAE.SUB_ARR(_)) then 9;
934 case DAE.BINARY(operator = DAE.SUB_SCALAR_ARRAY(_)) then 9;
935 case DAE.RELATION(operator = DAE.LESS(_)) then 11;
936 case DAE.RELATION(operator = DAE.LESSEQ(_)) then 11;
937 case DAE.RELATION(operator = DAE.GREATER(_)) then 11;
938 case DAE.RELATION(operator = DAE.GREATEREQ(_)) then 11;
939 case DAE.RELATION(operator = DAE.EQUAL(_)) then 11;
940 case DAE.RELATION(operator = DAE.NEQUAL(_)) then 11;
941 case DAE.LUNARY(operator = DAE.NOT(_)) then 13;
942 case DAE.LBINARY(operator = DAE.AND(_)) then 15;
943 case DAE.LBINARY(operator = DAE.OR(_)) then 17;
944 case DAE.RANGE() then 19;
945 case DAE.IFEXP() then 21;
946 case DAE.TUPLE(_) then 23; /* Not valid in inner expressions, only included here for completeness */
947 else 25;
948 end match;
949 end expPriority;
950
951 public function printRowStr
952 "Prints a list of expressions to a string."
953 input list<DAE.Exp> es_1;
954 input String stringDelimiter;
955 output String s;
956 algorithm
957 ✗ s := stringDelimitList(List.map3(es_1, printExp2Str, stringDelimiter, NONE(), NONE()), ",");
958 end printRowStr;
959
960 public function dumpExpGraphviz
961 "Creates a Graphviz Node from an Expression."
962 input DAE.Exp inExp;
963 output Graphviz.Node outNode;
964 algorithm
965 outNode := matchcontinue inExp
966 local
967 String s,sym,fs,tystr,istr;
968 Integer i;
969 DAE.ComponentRef c;
970 Graphviz.Node lt,rt,ct,tt,ft,t1,t2,t3,crt,dimt,expt,itert;
971 DAE.Exp e1,e2,e,t,f,start,stop,step,cr,dim,exp,iterexp,cond;
972 DAE.Operator op;
973 list<Graphviz.Node> argnodes,nodes;
974 Absyn.Path fcn;
975 list<DAE.Exp> args,es;
976 DAE.Type ty;
977 Real r;
978 Boolean b;
979 list<list<DAE.Exp>> lstes;
980
981 case DAE.ICONST(integer = i)
982 algorithm
983 ✗ s := intString(i);
984 ✗ then
985 Graphviz.LNODE("ICONST",{s},{},{});
986
987 case DAE.RCONST(real = r)
988 algorithm
989 ✗ s := realString(r);
990 ✗ then
991 Graphviz.LNODE("RCONST",{s},{},{});
992
993 case DAE.SCONST(string = s)
994 algorithm
995 ✗ s := System.escapedString(s,true);
996 ✗ s := stringAppendList({"\"", s, "\""});
997 ✗ then
998 Graphviz.LNODE("SCONST",{s},{},{});
999
1000 case DAE.BCONST(bool = b)
1001 algorithm
1002 ✗ s := boolString(b);
1003 ✗ then
1004 Graphviz.LNODE("BCONST",{s},{},{});
1005
1006 case DAE.CREF(componentRef = c)
1007 algorithm
1008 ✗ s := ComponentReferenceBasics.printComponentRefStr(c);
1009 ✗ then
1010 Graphviz.LNODE("CREF",{s},{},{});
1011
1012 case DAE.BINARY(exp1 = e1,operator = op,exp2 = e2)
1013 algorithm
1014 ✗ sym := binopSymbol(op);
1015 ✗ lt := dumpExpGraphviz(e1);
1016 ✗ rt := dumpExpGraphviz(e2);
1017 ✗ then
1018 Graphviz.LNODE("BINARY",{sym},{},{lt,rt});
1019
1020 case DAE.UNARY(operator = op,exp = e)
1021 algorithm
1022 ✗ sym := unaryopSymbol(op);
1023 ✗ ct := dumpExpGraphviz(e);
1024 ✗ then
1025 Graphviz.LNODE("UNARY",{sym},{},{ct});
1026
1027 case DAE.LBINARY(exp1 = e1,operator = op,exp2 = e2)
1028 algorithm
1029 ✗ sym := lbinopSymbol(op);
1030 ✗ lt := dumpExpGraphviz(e1);
1031 ✗ rt := dumpExpGraphviz(e2);
1032 ✗ then
1033 Graphviz.LNODE("LBINARY",{sym},{},{lt,rt});
1034
1035 case DAE.LUNARY(operator = op,exp = e)
1036 algorithm
1037 ✗ sym := lunaryopSymbol(op);
1038 ✗ ct := dumpExpGraphviz(e);
1039 ✗ then
1040 Graphviz.LNODE("LUNARY",{sym},{},{ct});
1041
1042 case DAE.RELATION(exp1 = e1,operator = op,exp2 = e2)
1043 algorithm
1044 ✗ sym := relopSymbol(op);
1045 ✗ lt := dumpExpGraphviz(e1);
1046 ✗ rt := dumpExpGraphviz(e2);
1047 ✗ then
1048 Graphviz.LNODE("RELATION",{sym},{},{lt,rt});
1049
1050 case DAE.IFEXP(expCond = cond,expThen = t,expElse = f)
1051 algorithm
1052 ✗ ct := dumpExpGraphviz(cond);
1053 ✗ tt := dumpExpGraphviz(t);
1054 ✗ ft := dumpExpGraphviz(f);
1055 ✗ then
1056 Graphviz.NODE("IFEXP",{},{ct,tt,ft});
1057
1058 case DAE.CALL(path = fcn,expLst = args)
1059 algorithm
1060 ✗ fs := AbsynUtil.pathString(fcn);
1061 ✗ argnodes := List.map(args, dumpExpGraphviz);
1062 ✗ then
1063 Graphviz.LNODE("CALL",{fs},{},argnodes);
1064
1065 case DAE.PARTEVALFUNCTION(expList = args)
1066 algorithm
1067 ✗ argnodes := List.map(args, dumpExpGraphviz);
1068 ✗ then
1069 Graphviz.NODE("PARTEVALFUNCTION",{},argnodes);
1070
1071 case DAE.ARRAY(array = es)
1072 algorithm
1073 ✗ nodes := List.map(es, dumpExpGraphviz);
1074 ✗ then
1075 Graphviz.NODE("ARRAY",{},nodes);
1076
1077 case DAE.TUPLE(PR = es)
1078 algorithm
1079 ✗ nodes := List.map(es, dumpExpGraphviz);
1080 ✗ then
1081 Graphviz.NODE("TUPLE",{},nodes);
1082
1083 case DAE.MATRIX(matrix = lstes)
1084 algorithm
1085 ✗ s := stringDelimitList(List.map1(lstes, printRowStr, "\""), "},{");
1086 ✗ s := stringAppendList({"{{", s, "}}"});
1087 ✗ then
1088 Graphviz.LNODE("MATRIX",{s},{},{});
1089
1090 case DAE.RANGE(start = start,step = NONE(),stop = stop)
1091 algorithm
1092 ✗ t1 := dumpExpGraphviz(start);
1093 t2 := Graphviz.NODE(":",{},{});
1094 ✗ t3 := dumpExpGraphviz(stop);
1095 ✗ then
1096 Graphviz.NODE("RANGE",{},{t1,t2,t3});
1097
1098 case DAE.RANGE(start = start,step = SOME(step),stop = stop)
1099 algorithm
1100 ✗ t1 := dumpExpGraphviz(start);
1101 ✗ t2 := dumpExpGraphviz(step);
1102 ✗ t3 := dumpExpGraphviz(stop);
1103 ✗ then
1104 Graphviz.NODE("RANGE",{},{t1,t2,t3});
1105
1106 case DAE.CAST(ty = ty,exp = e)
1107 algorithm
1108 ✗ tystr := TypesDump.unparseType(ty);
1109 ✗ ct := dumpExpGraphviz(e);
1110 ✗ then
1111 Graphviz.LNODE("CAST",{tystr},{},{ct});
1112
1113 case DAE.ASUB(exp = e,sub = (DAE.INDEX((DAE.ICONST(i)))::{}))
1114 algorithm
1115 ✗ ct := dumpExpGraphviz(e);
1116 ✗ istr := intString(i);
1117 ✗ s := stringAppendList({"[",istr,"]"});
1118 ✗ then
1119 Graphviz.LNODE("ASUB",{s},{},{ct});
1120
1121 case DAE.SIZE(exp = cr,sz = SOME(dim))
1122 algorithm
1123 ✗ crt := dumpExpGraphviz(cr);
1124 ✗ dimt := dumpExpGraphviz(dim);
1125 ✗ then
1126 Graphviz.NODE("SIZE",{},{crt,dimt});
1127
1128 case DAE.SIZE(exp = cr,sz = NONE())
1129 algorithm
1130 ✗ crt := dumpExpGraphviz(cr);
1131 ✗ then
1132 Graphviz.NODE("SIZE",{},{crt});
1133
1134 case DAE.REDUCTION(reductionInfo=DAE.REDUCTIONINFO(path = fcn),expr = exp,iterators = {DAE.REDUCTIONITER(exp=iterexp)})
1135 algorithm
1136 ✗ fs := AbsynUtil.pathString(fcn);
1137 ✗ expt := dumpExpGraphviz(exp);
1138 ✗ itert := dumpExpGraphviz(iterexp);
1139 ✗ then
1140 Graphviz.LNODE("REDUCTION",{fs},{},{expt,itert});
1141
1142 case _ then Graphviz.NODE("#UNKNOWN EXPRESSION# ----eeestr ",{},{});
1143 end matchcontinue;
1144 end dumpExpGraphviz;
1145
1146
1147 public function dumpExpStr
1148 "Dumps expression to a string."
1149 input DAE.Exp inExp;
1150 input Integer inInteger;
1151 output String outString;
1152 algorithm
1153 outString := matchcontinue (inExp,inInteger)
1154 local
1155 String gen_str,res_str,s,sym,lt,rt,ct,tt,ft,fs,argnodes_1,nodes_1,t1,t2,t3,istr,crt,dimt,expt,itert,tpStr,str;
1156 Integer level,x,new_level1,new_level2,new_level3,i;
1157 DAE.ComponentRef c;
1158 DAE.Exp e1,e2,e,t,f,start,stop,step,cr,dim,exp,iterexp,cond;
1159 DAE.Operator op;
1160 DAE.ClockKind clk;
1161 list<String> argnodes,nodes;
1162 Absyn.Path fcn;
1163 list<DAE.Exp> args,es;
1164 DAE.Type tp,ty;
1165 Real r;
1166 list<list<DAE.Exp>> lstes;
1167 Boolean b;
1168
1169 case (DAE.ICONST(integer = x),level)
1170 algorithm
1171 ✗ gen_str := genStringNTime(" |", level);
1172 ✗ s := intString(x);
1173 ✗ res_str := stringAppendList({gen_str,"ICONST ",s,"\n"});
1174 then
1175 res_str;
1176
1177 case (DAE.RCONST(real = r),level)
1178 algorithm
1179 ✗ gen_str := genStringNTime(" |", level);
1180 ✗ s := realString(r);
1181 ✗ res_str := stringAppendList({gen_str,"RCONST ",s,"\n"});
1182 then
1183 res_str;
1184
1185 case (DAE.SCONST(string = s),level)
1186 algorithm
1187 ✗ gen_str := genStringNTime(" |", level);
1188 ✗ s := System.escapedString(s,true);
1189 ✗ res_str := stringAppendList({gen_str,"SCONST ","\"", s,"\"\n"});
1190 then
1191 res_str;
1192
1193 case (DAE.BCONST(bool = false),level)
1194 algorithm
1195 ✗ gen_str := genStringNTime(" |", level);
1196 ✗ res_str := stringAppendList({gen_str,"BCONST ","false","\n"});
1197 then
1198 res_str;
1199
1200 case (DAE.BCONST(bool = true),level)
1201 algorithm
1202 ✗ gen_str := genStringNTime(" |", level);
1203 ✗ res_str := stringAppendList({gen_str,"BCONST ","true","\n"});
1204 then
1205 res_str;
1206
1207 // BTH TODO
1208 case (DAE.CLKCONST(clk = clk),level)
1209 algorithm
1210 ✗ gen_str := genStringNTime(" |", level);
1211 ✗ s := clockKindString(clk);
1212 ✗ res_str := stringAppendList({gen_str,"CLKCONST ",s,"\n"});
1213 then
1214 res_str;
1215
1216 case (DAE.ENUM_LITERAL(name = fcn, index = i), level)
1217 algorithm
1218 ✗ gen_str := genStringNTime(" |", level);
1219 ✗ s := AbsynUtil.pathString(fcn);
1220 ✗ istr := intString(i);
1221 ✗ res_str := stringAppendList({gen_str, "ENUM_LITERAL ", s, " [", istr, "]", "\n"});
1222 then
1223 res_str;
1224
1225 case (DAE.CREF(componentRef = c,ty=ty),level)
1226 algorithm
1227 ✗ gen_str := genStringNTime(" |", level);
1228 ✗ s := ComponentReferenceBasics.printComponentRefStr/*ComponentReference.debugPrintComponentRefTypeStr*/(c);
1229 ✗ tpStr:= TypesDump.unparseType(ty);
1230 ✗ res_str := stringAppendList({gen_str,"CREF ",s," CREFTYPE:",tpStr,"\n"});
1231 then
1232 res_str;
1233
1234 case (exp as DAE.BINARY(exp1 = e1,operator = op,exp2 = e2),level)
1235 algorithm
1236 ✗ gen_str := genStringNTime(" |", level);
1237 ✗ new_level1 := level + 1;
1238 new_level2 := level + 1;
1239 ✗ sym := debugBinopSymbol(op);
1240 ✗ tp := Expression.typeof(exp);
1241 ✗ str := TypesDump.unparseType(tp);
1242 ✗ lt := dumpExpStr(e1, new_level1);
1243 ✗ rt := dumpExpStr(e2, new_level2);
1244 ✗ res_str := stringAppendList({gen_str,"BINARY ",sym," ",str,"\n",lt,rt,""});
1245 then
1246 res_str;
1247
1248 case (DAE.UNARY(operator = op,exp = e),level)
1249 algorithm
1250 ✗ gen_str := genStringNTime(" |", level);
1251 ✗ new_level1 := level + 1;
1252 ✗ sym := unaryopSymbol(op);
1253 ✗ ct := dumpExpStr(e, new_level1);
1254 ✗ str := "expType:"+TypesDump.unparseType(Expression.typeof(e))+" optype:"+TypesDump.unparseType(Expression.typeofOp(op));
1255 ✗ res_str := stringAppendList({gen_str,"UNARY ",sym," ",str,"\n",ct,""});
1256 then
1257 res_str;
1258
1259 case (DAE.LBINARY(exp1 = e1,operator = op,exp2 = e2),level)
1260 algorithm
1261 ✗ gen_str := genStringNTime(" |", level);
1262 ✗ new_level1 := level + 1;
1263 new_level2 := level + 1;
1264 ✗ sym := lbinopSymbol(op);
1265 ✗ lt := dumpExpStr(e1, new_level1);
1266 ✗ rt := dumpExpStr(e2, new_level2);
1267 ✗ res_str := stringAppendList({gen_str,"LBINARY ",sym,"\n",lt,rt,""});
1268 then
1269 res_str;
1270
1271 case (DAE.LUNARY(operator = op,exp = e),level)
1272 algorithm
1273 ✗ gen_str := genStringNTime(" |", level);
1274 ✗ new_level1 := level + 1;
1275 ✗ sym := lunaryopSymbol(op);
1276 ✗ ct := dumpExpStr(e, new_level1);
1277 ✗ res_str := stringAppendList({gen_str,"LUNARY ",sym,"\n",ct,""});
1278 then
1279 res_str;
1280
1281 case (DAE.RELATION(exp1 = e1,operator = op,exp2 = e2),level)
1282 algorithm
1283 ✗ gen_str := genStringNTime(" |", level);
1284 ✗ new_level1 := level + 1;
1285 new_level2 := level + 1;
1286 ✗ sym := relopSymbol(op);
1287 ✗ lt := dumpExpStr(e1, new_level1);
1288 ✗ rt := dumpExpStr(e2, new_level2);
1289 ✗ res_str := stringAppendList({gen_str,"RELATION ",sym,"\n",lt,rt,""});
1290 then
1291 res_str;
1292
1293 case (DAE.IFEXP(expCond = cond,expThen = t,expElse = f),level)
1294 algorithm
1295 ✗ gen_str := genStringNTime(" |", level);
1296 ✗ new_level1 := level + 1;
1297 new_level2 := level + 1;
1298 new_level3 := level + 1;
1299 ✗ ct := dumpExpStr(cond, new_level1);
1300 ✗ tt := dumpExpStr(t, new_level2);
1301 ✗ ft := dumpExpStr(f, new_level3);
1302 ✗ res_str := stringAppendList({gen_str,"IFEXP ","\n",ct,tt,ft,""});
1303 then
1304 res_str;
1305
1306 case (DAE.CALL(path = fcn,expLst = args),level)
1307 algorithm
1308 ✗ gen_str := genStringNTime(" |", level);
1309 ✗ fs := AbsynUtil.pathString(fcn);
1310 ✗ new_level1 := level + 1;
1311 ✗ argnodes := List.map1(args, dumpExpStr, new_level1);
1312 ✗ argnodes_1 := stringAppendList(argnodes);
1313 ✗ res_str := stringAppendList({gen_str,"CALL ",fs,"\n",argnodes_1,""});
1314 then
1315 res_str;
1316
1317 case (DAE.PARTEVALFUNCTION(path = fcn,expList = args),level)
1318 algorithm
1319 ✗ gen_str := genStringNTime(" |", level);
1320 ✗ fs := AbsynUtil.pathString(fcn);
1321 ✗ new_level1 := level + 1;
1322 ✗ argnodes := List.map1(args, dumpExpStr, new_level1);
1323 ✗ argnodes_1 := stringAppendList(argnodes);
1324 ✗ res_str := stringAppendList({gen_str,"CALL ",fs,"\n",argnodes_1,""});
1325 then
1326 res_str;
1327
1328 case (DAE.ARRAY(array = es,scalar=b,ty=tp),level)
1329 algorithm
1330 ✗ gen_str := genStringNTime(" |", level);
1331 ✗ new_level1 := level + 1;
1332 ✗ nodes := List.map1(es, dumpExpStr, new_level1);
1333 ✗ nodes_1 := stringAppendList(nodes);
1334 ✗ s := boolString(b);
1335 ✗ tpStr := TypesDump.unparseType(tp);
1336 ✗ res_str := stringAppendList({gen_str,"ARRAY scalar:",s," tp: ",tpStr,"\n",nodes_1});
1337 then
1338 res_str;
1339
1340 case (DAE.TUPLE(PR = es),level)
1341 algorithm
1342 ✗ gen_str := genStringNTime(" |", level);
1343 ✗ new_level1 := level + 1;
1344 ✗ nodes := List.map1(es, dumpExpStr, new_level1);
1345 ✗ nodes_1 := stringAppendList(nodes);
1346 ✗ res_str := stringAppendList({gen_str,"TUPLE ",nodes_1,"\n"});
1347 then
1348 res_str;
1349
1350 case (DAE.MATRIX(matrix = lstes),level)
1351 algorithm
1352 ✗ gen_str := genStringNTime(" |", level);
1353 ✗ s := stringDelimitList(List.map1(lstes, printRowStr, "\""), "},{");
1354 ✗ res_str := stringAppendList({gen_str,"MATRIX ","\n","{{",s,"}}","\n"});
1355 then
1356 res_str;
1357
1358 case (DAE.RANGE(start = start,step = NONE(),stop = stop),level)
1359 algorithm
1360 ✗ gen_str := genStringNTime(" |", level);
1361 ✗ new_level1 := level + 1;
1362 new_level2 := level + 1;
1363 ✗ t1 := dumpExpStr(start, new_level1);
1364 t2 := ":";
1365 ✗ t3 := dumpExpStr(stop, new_level2);
1366 ✗ res_str := stringAppendList({gen_str,"RANGE ","\n",t1,t2,t3,""});
1367 then
1368 res_str;
1369
1370 case (DAE.RANGE(start = start,step = SOME(step),stop = stop),level)
1371 algorithm
1372 ✗ gen_str := genStringNTime(" |", level);
1373 ✗ new_level1 := level + 1;
1374 new_level2 := level + 1;
1375 new_level3 := level + 1;
1376 ✗ t1 := dumpExpStr(start, new_level1);
1377 ✗ t2 := dumpExpStr(step, new_level2);
1378 ✗ t3 := dumpExpStr(stop, new_level3);
1379 ✗ res_str := stringAppendList({gen_str,"RANGE ","\n",t1,t2,t3,""});
1380 then
1381 res_str;
1382
1383 case (DAE.CAST(exp = e),level)
1384 algorithm
1385 ✗ gen_str := genStringNTime(" |", level);
1386 ✗ new_level1 := level + 1;
1387 ✗ ct := dumpExpStr(e, new_level1);
1388 ✗ res_str := stringAppendList({gen_str,"CAST ","\n",ct,""});
1389 then
1390 res_str;
1391
1392 case (DAE.ASUB(exp = e,sub = ((DAE.INDEX(DAE.ICONST(i)))::{})),level)
1393 algorithm
1394 ✗ gen_str := genStringNTime(" |", level);
1395 ✗ new_level1 := level + 1;
1396 ✗ ct := dumpExpStr(e, new_level1);
1397 ✗ istr := intString(i);
1398 ✗ s := stringAppendList({"[",istr,"]"});
1399 ✗ res_str := stringAppendList({gen_str,"ASUB ",s,"\n",ct,""});
1400 then
1401 res_str;
1402
1403 case (DAE.ASUB(exp = e),level)
1404 algorithm
1405 ✗ gen_str := genStringNTime(" |", level);
1406 ✗ new_level1 := level + 1;
1407 ✗ ct := dumpExpStr(e, new_level1);
1408 ✗ res_str := stringAppendList({gen_str,"ASUB ","\n",ct,""});
1409 then
1410 res_str;
1411
1412 case (DAE.SIZE(exp = cr,sz = SOME(dim)),level)
1413 algorithm
1414 ✗ gen_str := genStringNTime(" |", level);
1415 ✗ new_level1 := level + 1;
1416 new_level2 := level + 1;
1417 ✗ crt := dumpExpStr(cr, new_level1);
1418 ✗ dimt := dumpExpStr(dim, new_level2);
1419 ✗ res_str := stringAppendList({gen_str,"SIZE ","\n",crt,dimt,""});
1420 then
1421 res_str;
1422
1423 case (DAE.SIZE(exp = cr,sz = NONE()),level)
1424 algorithm
1425 ✗ gen_str := genStringNTime(" |", level);
1426 ✗ new_level1 := level + 1;
1427 ✗ crt := dumpExpStr(cr, new_level1);
1428 ✗ res_str := stringAppendList({gen_str,"SIZE ","\n",crt,""});
1429 then
1430 res_str;
1431
1432 case (DAE.REDUCTION(reductionInfo=DAE.REDUCTIONINFO(),expr = exp,iterators={DAE.REDUCTIONITER(exp=iterexp)}),level)
1433 algorithm
1434 ✗ gen_str := genStringNTime(" |", level);
1435 ✗ new_level1 := level + 1;
1436 new_level2 := level + 1;
1437 ✗ expt := dumpExpStr(exp, new_level1);
1438 ✗ itert := dumpExpStr(iterexp, new_level2);
1439 ✗ res_str := stringAppendList({gen_str,"REDUCTION ","\n",expt,itert,""});
1440 then
1441 res_str;
1442
1443 case (DAE.RECORD(path=fcn, exps=args),level)
1444 algorithm
1445 ✗ gen_str := genStringNTime(" |", level);
1446 ✗ fs := AbsynUtil.pathString(fcn);
1447 ✗ new_level1 := level + 1;
1448 ✗ argnodes := List.map1(args, dumpExpStr, new_level1);
1449 ✗ argnodes_1 := stringAppendList(argnodes);
1450 ✗ res_str := stringAppendList({gen_str,"RECORD ",fs,"\n",argnodes_1,""});
1451 then
1452 res_str;
1453
1454 case (DAE.RSUB(exp=e, ix=i, fieldName=fs, ty=tp),level)
1455 algorithm
1456 ✗ gen_str := genStringNTime(" |", level);
1457 ✗ new_level1 := level + 1;
1458 ✗ ct := dumpExpStr(e, new_level1);
1459 ✗ istr := intString(i);
1460 ✗ s := stringAppendList({"[",istr,"]"});
1461 ✗ tpStr := TypesDump.unparseType(tp);
1462 ✗ res_str := stringAppendList({gen_str,"RSUB ",s," fieldName: ",fs," tp: ",tpStr,"\n",ct,""});
1463 then
1464 res_str;
1465
1466 case (DAE.BOX(exp=e),level)
1467 algorithm
1468 ✗ gen_str := genStringNTime(" |", level);
1469 ✗ new_level1 := level + 1;
1470 ✗ ct := dumpExpStr(e, new_level1);
1471 ✗ res_str := stringAppendList({gen_str,"BOX ","\n",ct,""});
1472 then
1473 res_str;
1474
1475 case (DAE.UNBOX(exp=e),level)
1476 algorithm
1477 ✗ gen_str := genStringNTime(" |", level);
1478 ✗ new_level1 := level + 1;
1479 ✗ ct := dumpExpStr(e, new_level1);
1480 ✗ res_str := stringAppendList({gen_str,"UNBOX ","\n",ct,""});
1481 then
1482 res_str;
1483
1484 case (_,level)
1485 algorithm
1486 ✗ gen_str := genStringNTime(" |", level);
1487 ✗ res_str := stringAppendList({gen_str," UNKNOWN EXPRESSION (" + printExpTypeStr(inExp) + ")","\n"});
1488 then
1489 res_str;
1490 end matchcontinue;
1491 end dumpExpStr;
1492
1493 protected function genStringNTime
1494 "function:getStringNTime
1495 Appends the string to itself n times."
1496 input String inString;
1497 input Integer inInteger;
1498 output String outString;
1499 algorithm
1500 outString := match (inString,inInteger)
1501 local
1502 String str,new_str,res_str;
1503 Integer new_level,level;
1504
1505 case (_,0) then ""; /* n */
1506
1507 case (str,level)
1508 algorithm
1509 ✗ new_level := level + (-1);
1510 ✗ new_str := genStringNTime(str, new_level);
1511 ✗ res_str := stringAppend(str, new_str);
1512 then
1513 res_str;
1514 end match;
1515 end genStringNTime;
1516
1517 public function dumpExp
1518 input DAE.Exp exp;
1519 protected String str;
1520 algorithm
1521 ✗ str := dumpExpStr(exp,0);
1522 ✗ print(str);
1523 ✗ print("--------------------\n");
1524 end dumpExp;
1525
1526 protected function printExpIfDiff ""
1527 input DAE.Exp e1,e2;
1528 output String s;
1529 algorithm
1530 ✗ s := if ExpressionBasics.expEqual(e1,e2)
1531 then ""
1532 else ExpressionBasics.printExpStr(e1) + " =!= " + ExpressionBasics.printExpStr(e2) + "\n";
1533 end printExpIfDiff;
1534
1535 public function printArraySizes "Function: printArraySizes"
1536 input list<Option <Integer>> inLst;
1537 output String out;
1538 algorithm
1539 out := match inLst
1540 local
1541 Integer x;
1542 list<Option<Integer>> lst;
1543 String s,s2;
1544
1545 case {} then "";
1546
1547 case SOME(x) :: lst
1548 algorithm
1549 ✗ s := printArraySizes(lst);
1550 ✗ s2 := intString(x);
1551 ✗ s := stringAppendList({s2, s});
1552 then s;
1553
1554 case _ :: lst
1555 algorithm
1556 ✗ s := printArraySizes(lst);
1557 then s;
1558 end match;
1559 end printArraySizes;
1560
1561 public function typeOfString
1562 "Retrieves the Type of the Expression as a String"
1563 input DAE.Exp inExp;
1564 output String str;
1565 protected
1566 DAE.Type ty;
1567 algorithm
1568 ✗ ty := Expression.typeof(inExp);
1569 ✗ str := TypesDump.unparseType(ty);
1570 end typeOfString;
1571
1572 public function debugPrintComponentRefExp "
1573 This function takes an DAE.Exp and tries to print ComponentReferences.
1574 Uses debugPrint.ComponentRefTypeStr, which gives type information to stdout.
1575 NOTE Only used for debugging.
1576 "
1577 input DAE.Exp inExp;
1578 output String str;
1579 algorithm str := matchcontinue inExp
1580 local
1581 DAE.ComponentRef cr;
1582 String s1;
1583 list<DAE.Exp> expl;
1584 ✗ case DAE.CREF(cr,_) then ComponentReference.debugPrintComponentRefTypeStr(cr);
1585 case DAE.ARRAY(_,_,expl)
1586 algorithm
1587 ✗ s1 := "{" + stringAppendList(List.map(expl,debugPrintComponentRefExp)) + "}";
1588 then
1589 s1;
1590 ✗ else ExpressionBasics.printExpStr(inExp); // when not cref, print expression anyways since it is used for some debugging.
1591 end matchcontinue;
1592 end debugPrintComponentRefExp;
1593
1594 public function dimensionIntString
1595 "Returns a integer string representation of an array dimension."
1596 input DAE.Dimension dim;
1597 output String str;
1598 algorithm
1599 str := match dim
1600 local
1601 String s;
1602 Integer x, size;
1603 DAE.Exp e;
1604 case DAE.DIM_UNKNOWN() then ":";
1605 case DAE.DIM_ENUM(size =size)
1606 3642 then intString(size);
1607 case DAE.DIM_BOOLEAN() then "1";
1608 case DAE.DIM_INTEGER(integer = x)
1609 271246 then intString(x);
1610 case DAE.DIM_EXP(exp = e)
1611 algorithm
1612 ✗ s := ExpressionBasics.printExpStr(e);
1613 then s;
1614 end match;
1615 end dimensionIntString;
1616
1617 public function dumpExpWithTitle
1618 input String title;
1619 input DAE.Exp exp;
1620 protected String str;
1621 algorithm
1622 ✗ str := dumpExpStr(exp,0);
1623 ✗ print(title);
1624 ✗ print(str);
1625 ✗ print("\n");
1626 end dumpExpWithTitle;
1627
1628 public function printSubscript
1629 "Print a Subscript."
1630 input DAE.Subscript inSubscript;
1631 algorithm
1632 () := match inSubscript
1633 local DAE.Exp e1;
1634 case DAE.WHOLEDIM()
1635 algorithm
1636 ✗ Print.printBuf(":");
1637 then
1638 ();
1639 case DAE.INDEX(exp = e1)
1640 algorithm
1641 ✗ printExp(e1);
1642 then
1643 ();
1644 case DAE.SLICE(exp = e1)
1645 algorithm
1646 ✗ printExp(e1);
1647 then
1648 ();
1649 case DAE.WHOLE_NONEXP(exp = e1)
1650 algorithm
1651 ✗ Print.printBuf("1:");
1652 ✗ printExp(e1);
1653 then
1654 ();
1655 end match;
1656 end printSubscript;
1657
1658 public function printExp
1659 "This function prints a complete expression."
1660 input DAE.Exp e;
1661 algorithm
1662 58 Tpl.tplPrint2(ExpressionDumpTpl.dumpExp, e, "\"");
1663 end printExp;
1664
1665 public function parenthesize
1666 "Adds parentheisis to a string if expression
1667 and parent expression priorities requires it."
1668 input String inString1;
1669 input Integer inInteger2;
1670 input Integer inInteger3;
1671 input Boolean rightOpParenthesis "true for right hand side operators";
1672 output String outString;
1673 algorithm
1674 outString := match (inString1,inInteger2,inInteger3,rightOpParenthesis)
1675 local
1676 String str_1,str;
1677 Integer pparent,pexpr;
1678
1679 // expr, prio. parent expr, prio. expr
1680 case (str,pparent,pexpr,_) guard (pparent > pexpr)
1681 algorithm
1682 1452 str_1 := stringAppendList({"(",str,")"});
1683 then str_1;
1684
1685 // If priorites are equal and str is from right hand side, parenthesize to make left associative
1686 case (str,pparent,pexpr,true) guard (pparent == pexpr)
1687 algorithm
1688 417 str_1 := stringAppendList({"(",str,")"});
1689 then
1690 str_1;
1691 case (str,_,_,_) then str;
1692 end match;
1693 end parenthesize;
1694
1695 public function clockKindString "
1696 Author: BTH
1697 Return textual representation of a ClockKind."
1698 input DAE.ClockKind inClockKind;
1699 output String outString;
1700 algorithm
1701 outString := match inClockKind
1702 local
1703 DAE.Exp c, intervalCounter, interval, condition, resolution, startInterval, solverMethod;
1704
1705 case DAE.INFERRED_CLOCK()
1706 then "Clock()";
1707
1708 case DAE.RATIONAL_CLOCK(intervalCounter=intervalCounter, resolution=resolution)
1709 ✗ then "Clock(" + dumpExpStr(intervalCounter,0) + ", " + dumpExpStr(resolution,0) + ")";
1710
1711 case DAE.REAL_CLOCK(interval=interval)
1712 ✗ then "Clock(" + dumpExpStr(interval,0) + ")";
1713
1714 case DAE.EVENT_CLOCK(condition=condition, startInterval=startInterval)
1715 ✗ then "Clock(" + dumpExpStr(condition,0) + ", " + dumpExpStr(startInterval,0) + ")";
1716
1717 case DAE.SOLVER_CLOCK(c=c, solverMethod=solverMethod)
1718 ✗ then "Clock(" + dumpExpStr(c,0) + ", " + dumpExpStr(solverMethod,0) + ")";
1719 end match;
1720 end clockKindString;
1721
1722
1723 public function constraintDTtoString "
1724 author: ptaeuber
1725 Converts DAE.CONSTRAINT_DT to string."
1726 input DAE.Constraint con;
1727 output String str;
1728 protected
1729 DAE.Exp c;
1730 Boolean localCon;
1731 algorithm
1732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 DAE.CONSTRAINT_DT(constraint = c, localCon = localCon) := con;
1733 16 str := ExpressionBasics.printExpStr(c);
1734
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
16 str := if localCon then str + " (local)" else str + " (global)";
1735 end constraintDTtoString;
1736
1737
1738 public function constraintDTlistToString "
1739 author: ptaeuber
1740 Converts list of DAE.CONSTRAINT_DT to string."
1741 input list<DAE.Constraint> cons;
1742 input String delim;
1743 output String str="";
1744 protected
1745 DAE.Constraint con;
1746 algorithm
1747
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 16 times.
32 for con in cons loop
1748 16 str := str + delim + constraintDTtoString(con);
1749 end for;
1750 end constraintDTlistToString;
1751
1752 public function patternStr "Pattern to String unparsing"
1753 input DAE.Pattern pattern;
1754 output String str;
1755 algorithm
1756 str := match pattern
1757 local
1758 list<DAE.Pattern> pats;
1759 list<String> fields,patsStr;
1760 DAE.Exp exp;
1761 DAE.Pattern pat,head,tail;
1762 String id;
1763 list<tuple<DAE.Pattern,String,DAE.Type>> namedpats;
1764 Absyn.Path name;
1765 case DAE.PAT_WILD() then "_";
1766 case DAE.PAT_AS(id=id,pat=DAE.PAT_WILD()) then id;
1767 case DAE.PAT_AS_FUNC_PTR(id,DAE.PAT_WILD()) then id;
1768 case DAE.PAT_SOME(pat)
1769 algorithm
1770 ✗ str := patternStr(pat);
1771 ✗ then "SOME(" + str + ")";
1772 case DAE.PAT_META_TUPLE(pats)
1773 algorithm
1774 ✗ str := stringDelimitList(List.map(pats,patternStr),",");
1775 ✗ then "(" + str + ")";
1776
1777 case DAE.PAT_CALL_TUPLE(pats)
1778 algorithm
1779 ✗ str := stringDelimitList(List.map(pats,patternStr),",");
1780 ✗ then "(" + str + ")";
1781
1782 case DAE.PAT_CALL(name=name, patterns=pats)
1783 algorithm
1784 ✗ id := AbsynUtil.pathString(name);
1785 ✗ str := stringDelimitList(List.map(pats,patternStr),",");
1786 ✗ then stringAppendList({id,"(",str,")"});
1787
1788 case DAE.PAT_CALL_NAMED(name=name, patterns=namedpats)
1789 algorithm
1790 ✗ id := AbsynUtil.pathString(name);
1791 ✗ fields := List.map(namedpats, Util.tuple32);
1792 ✗ patsStr := List.map1r(List.mapMap(namedpats, Util.tuple31, patternStr), stringAppend, "=");
1793 ✗ str := stringDelimitList(List.threadMap(fields, patsStr, stringAppend), ",");
1794 ✗ then stringAppendList({id,"(",str,")"});
1795
1796 ✗ case DAE.PAT_CONS(head,tail) then patternStr(head) + "::" + patternStr(tail);
1797
1798 ✗ case DAE.PAT_CONSTANT(exp=exp) then ExpressionBasics.printExpStr(exp);
1799 // case DAE.PAT_CONSTANT(SOME(et),exp) then "(" + TypesDump.unparseType(et) + ")" + ExpressionBasics.printExpStr(exp);
1800 ✗ case DAE.PAT_AS(id=id,pat=pat) then id + " as " + patternStr(pat);
1801 ✗ case DAE.PAT_AS_FUNC_PTR(id, pat) then id + " as " + patternStr(pat);
1802 else
1803 algorithm
1804 ✗ Error.addMessage(Error.INTERNAL_ERROR, {"ExpressionDump.patternStr not implemented correctly"});
1805 then "*PATTERN*";
1806 end match;
1807 end patternStr;
1808
1809 annotation(__OpenModelica_Interface="frontend_base");
1810 end ExpressionDump;
1811