/
DAEDump.mo
4053 lines (3697 loc) · 123 KB
/
DAEDump.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package DAEDump
" file: DAEDump.mo
package: DAEDump
description: DAEDump output
This module implements functions to print the DAE AST."
// public imports
public import DAE;
public import Graphviz;
public import IOStream;
public import SCode;
// protected imports
protected import ComponentReference;
protected import Config;
protected import DAEUtil;
protected import ElementSource;
protected import Error;
protected import Print;
protected import Util;
protected import Expression;
protected import ExpressionDump;
protected import Absyn;
protected import AbsynUtil;
protected import Dump;
protected import ValuesUtil;
protected import Values;
protected import Types;
protected import ClassInf;
protected import SCodeDump;
import SCodeUtil;
protected import List;
protected import Flags;
protected import DAEDumpTpl;
protected import Tpl;
protected import System;
public uniontype splitElements
record SPLIT_ELEMENTS
list<DAE.Element> v;
list<DAE.Element> ie;
list<DAE.Element> ia;
list<DAE.Element> e;
list<DAE.Element> a;
list<DAE.Element> co;
list<DAE.Element> o;
list<DAE.Element> ca;
list<compWithSplitElements> sm;
end SPLIT_ELEMENTS;
end splitElements;
public uniontype compWithSplitElements
record COMP_WITH_SPLIT
String name;
splitElements spltElems;
Option<SCode.Comment> comment;
end COMP_WITH_SPLIT;
end compWithSplitElements;
public uniontype functionList
record FUNCTION_LIST
list<DAE.Function> funcs;
end FUNCTION_LIST;
end functionList;
public function dump "This function prints the DAE in the standard output format to the Print buffer.
For printing to the stdout use print(dumpStr(dae)) instead."
input DAE.DAElist dae;
input DAE.FunctionTree functionTree;
algorithm
_ := match (dae,functionTree)
local
list<DAE.Element> daelist;
case (DAE.DAE(daelist),_)
equation
List.map_0(sortFunctions(DAEUtil.getFunctionList(functionTree)),dumpFunction);
List.map_0(daelist, dumpExtObjectClass);
List.map_0(daelist, dumpCompElement);
then
();
end match;
end dump;
public function dumpFunctionNamesStr "return all function names in a string (comma separated)"
input DAE.FunctionTree funcs;
output String str;
algorithm
str := stringDelimitList(List.map(sortFunctions(DAEUtil.getFunctionList(funcs)),functionNameStr),",");
end dumpFunctionNamesStr;
public function functionNameStr
"return the name of a function, if element is not function return empty string"
input DAE.Function inElement;
output String res;
algorithm
res := matchcontinue (inElement)
local
Absyn.Path fpath;
case DAE.FUNCTION(path = fpath)
equation
res = AbsynUtil.pathStringNoQual(fpath);
then res;
case DAE.RECORD_CONSTRUCTOR(path = fpath)
equation
res = AbsynUtil.pathStringNoQual(fpath);
then res;
else "";
end matchcontinue;
end functionNameStr;
protected function sortFunctions "sorts the functions and record constructors in alphabetical order"
input list<DAE.Function> funcs;
output list<DAE.Function> sortedFuncs;
algorithm
sortedFuncs := List.sort(funcs,funcGreaterThan);
end sortFunctions;
protected function funcGreaterThan "sorting function for two DAE.Element that are functions or record constuctors"
input DAE.Function func1;
input DAE.Function func2;
output Boolean res;
algorithm
res := matchcontinue(func1,func2)
case(_,_) equation
res = stringCompare(functionNameStr(func1),functionNameStr(func2)) > 0;
then res;
else true;
end matchcontinue;
end funcGreaterThan;
public function dumpOperatorString "
Author bz printOperator
Dump operator to a string."
input DAE.Operator op;
output String str;
algorithm
str := match(op)
local
Absyn.Path p;
DAE.Type ty;
case(DAE.ADD()) then " ADD ";
case(DAE.SUB()) then " SUB ";
case(DAE.MUL()) then " MUL ";
case(DAE.DIV()) then " DIV ";
case(DAE.POW()) then " POW ";
case(DAE.UMINUS()) then " UMINUS ";
case(DAE.UMINUS_ARR()) then " UMINUS_ARR ";
case(DAE.ADD_ARR()) then " ADD_ARR ";
case(DAE.SUB_ARR()) then " SUB_ARR ";
case(DAE.MUL_ARR()) then " MUL_ARR ";
case(DAE.DIV_ARR()) then " DIV_ARR ";
case(DAE.MUL_ARRAY_SCALAR()) then " MUL_ARRAY_SCALAR ";
case(DAE.ADD_ARRAY_SCALAR()) then " ADD_ARRAY_SCALAR ";
case(DAE.SUB_SCALAR_ARRAY()) then " SUB_SCALAR_ARRAY ";
case(DAE.MUL_SCALAR_PRODUCT()) then " MUL_SCALAR_PRODUCT ";
case(DAE.MUL_MATRIX_PRODUCT()) then " MUL_MATRIX_PRODUCT ";
case(DAE.DIV_ARRAY_SCALAR()) then " DIV_ARRAY_SCALAR ";
case(DAE.DIV_SCALAR_ARRAY()) then " DIV_SCALAR_ARRAY ";
case(DAE.POW_ARRAY_SCALAR()) then " POW_ARRAY_SCALAR ";
case(DAE.POW_SCALAR_ARRAY()) then " POW_SCALAR_ARRAY ";
case(DAE.POW_ARR()) then " POW_ARR ";
case(DAE.POW_ARR2()) then " POW_ARR2 ";
case(DAE.OR(_)) then " OR ";
case(DAE.AND(_)) then " AND ";
case(DAE.NOT(_)) then " NOT ";
case(DAE.LESSEQ()) then " LESSEQ ";
case(DAE.GREATER()) then " GREATER ";
case(DAE.GREATEREQ()) then " GREATEREQ ";
case(DAE.LESS()) then " LESS ";
case(DAE.EQUAL()) then " EQUAL ";
case(DAE.NEQUAL()) then " NEQUAL ";
case(DAE.USERDEFINED(p)) then " Userdefined:" + AbsynUtil.pathString(p) + " ";
else " --UNDEFINED-- ";
end match;
end dumpOperatorString;
public function dumpOperatorSymbol "
Author bz printOperator
Dump operator to a string."
input DAE.Operator op;
output String str;
algorithm
str := match(op)
local
Absyn.Path p;
case(DAE.ADD(_)) then " + ";
case(DAE.SUB(_)) then " - ";
case(DAE.MUL(_)) then " .* ";
case(DAE.DIV(_)) then " / ";
case(DAE.POW(_)) then " ^ ";
case(DAE.UMINUS(_)) then " - ";
case(DAE.UMINUS_ARR(_)) then " - ";
case(DAE.ADD_ARR(_)) then " + ";
case(DAE.SUB_ARR(_)) then " - ";
case(DAE.MUL_ARR(_)) then " .* ";
case(DAE.DIV_ARR(_)) then " ./ ";
case(DAE.MUL_ARRAY_SCALAR(_)) then " * ";
case(DAE.ADD_ARRAY_SCALAR(_)) then " .+ ";
case(DAE.SUB_SCALAR_ARRAY(_)) then " .- ";
case(DAE.MUL_SCALAR_PRODUCT(_)) then " * ";
case(DAE.MUL_MATRIX_PRODUCT(_)) then " * ";
case(DAE.DIV_ARRAY_SCALAR(_)) then " / ";
case(DAE.DIV_SCALAR_ARRAY(_)) then " ./ ";
case(DAE.POW_ARRAY_SCALAR(_)) then " .^ ";
case(DAE.POW_SCALAR_ARRAY(_)) then " .^ ";
case(DAE.POW_ARR(_)) then " ^ ";
case(DAE.POW_ARR2(_)) then " .^ ";
case(DAE.OR(_)) then " or ";
case(DAE.AND(_)) then " and ";
case(DAE.NOT(_)) then " not ";
case(DAE.LESSEQ(_)) then " <= ";
case(DAE.GREATER(_)) then " > ";
case(DAE.GREATEREQ(_)) then " >= ";
case(DAE.LESS(_)) then " < ";
case(DAE.EQUAL(_)) then " == ";
case(DAE.NEQUAL(_)) then " <> ";
case(DAE.USERDEFINED(p)) then " Userdefined:" + AbsynUtil.pathString(p) + " ";
else " --UNDEFINED-- ";
end match;
end dumpOperatorSymbol;
protected function dumpStartValue "Dumps the StartValue for a variable."
input DAE.StartValue inStartValue;
algorithm
_ := matchcontinue (inStartValue)
local
DAE.Exp e;
case (SOME(e))
equation
Print.printBuf("(start=");
ExpressionDump.printExp(e);
Print.printBuf(")");
then
();
else ();
end matchcontinue;
end dumpStartValue;
public function dumpStartValueStr "Dumps the start value for a variable to a string."
input DAE.StartValue inStartValue;
output String outString;
algorithm
outString := matchcontinue (inStartValue)
local
String s,res;
DAE.Exp e;
case (SOME(e))
equation
s = ExpressionDump.printExpStr(e);
res = stringAppendList({"(start=",s,")"});
then
res;
else "";
end matchcontinue;
end dumpStartValueStr;
public function dumpExtDeclStr "Dumps the external declaration to a string."
input DAE.ExternalDecl inExternalDecl;
output String outString;
algorithm
outString := match (inExternalDecl)
local
String extargsstr,rettystr,str,id,lang;
list<DAE.ExtArg> extargs;
DAE.ExtArg retty;
case DAE.EXTERNALDECL(name = id,args = extargs,returnArg = retty,language = lang)
equation
extargsstr = Dump.getStringList(extargs, dumpExtArgStr, ", ");
rettystr = dumpExtArgStr(retty);
rettystr = if stringEq(rettystr, "") then rettystr else (rettystr + " = ");
str = stringAppendList({"external \"", lang, "\" ", rettystr, id,"(",extargsstr,");"});
then
str;
end match;
end dumpExtDeclStr;
public function dumpExtArgStr "Helper function to dumpExtDeclStr"
input DAE.ExtArg inExtArg;
output String outString;
algorithm
outString := match (inExtArg)
local
String crstr,str,dimstr;
DAE.ComponentRef cr;
SCode.ConnectorType ct;
SCode.Variability var;
Absyn.Direction dir;
DAE.Type ty;
DAE.Exp exp,dim;
DAE.Attributes attr;
case DAE.NOEXTARG() then "";
case DAE.EXTARG(componentRef = cr)
equation
crstr = ComponentReference.printComponentRefStr(cr);
then
crstr;
case DAE.EXTARGEXP(exp = exp)
equation
crstr = ExpressionDump.printExpStr(exp);
then
crstr;
case DAE.EXTARGSIZE(componentRef = cr,exp = dim)
equation
crstr = ComponentReference.printComponentRefStr(cr);
dimstr = ExpressionDump.printExpStr(dim);
str = stringAppendList({"size(",crstr,", ",dimstr,")"});
then
str;
end match;
end dumpExtArgStr;
protected function dumpCompElement "Dumps Component elements."
input DAE.Element inElement;
algorithm
_ := matchcontinue (inElement)
local
String n;
list<DAE.Element> l;
Option<SCode.Comment> c;
case DAE.COMP(ident = n,dAElist = l, comment = c)
equation
Print.printBuf("class ");
Print.printBuf(n);
dumpCommentOption(c);
Print.printBuf("\n");
dumpElements(l);
Print.printBuf("end ");
Print.printBuf(n);
Print.printBuf(";\n");
then
();
else (); /* LS: for non-COMPS, which are only FUNCTIONS at the moment */
end matchcontinue;
end dumpCompElement;
public function dumpElements "Dump elements."
input list<DAE.Element> l;
algorithm
dumpVars(l, false);
List.map_0(l, dumpExtObjectClass);
Print.printBuf("initial equation\n");
List.map_0(l, dumpInitialEquation);
Print.printBuf("equation\n");
List.map_0(l, dumpEquation);
List.map_0(l, dumpInitialAlgorithm);
List.map_0(l, dumpAlgorithm);
List.map_0(l, dumpCompElement);
end dumpElements;
public function dumpFunctionElements "Dump function elements."
input list<DAE.Element> l;
algorithm
dumpVars(l, true);
List.map_0(l, dumpAlgorithm);
end dumpFunctionElements;
protected function dumpVars "Dump variables to Print buffer."
input list<DAE.Element> lst;
input Boolean printTypeDimension "use true here when printing components in functions as these are not vectorized! Otherwise, use false";
protected
String str;
IOStream.IOStream myStream;
algorithm
myStream := IOStream.create("", IOStream.LIST());
myStream := dumpVarsStream(lst, printTypeDimension, myStream);
str := IOStream.string(myStream);
Print.printBuf(str);
end dumpVars;
protected function dumpKind "Dump VarKind."
input DAE.VarKind inVarKind;
algorithm
_ := match (inVarKind)
case DAE.CONST()
equation
Print.printBuf(" constant ");
then
();
case DAE.PARAM()
equation
Print.printBuf(" parameter ");
then
();
case DAE.DISCRETE()
equation
Print.printBuf(" discrete ");
then
();
case DAE.VARIABLE()
equation
Print.printBuf(" ");
then
();
end match;
end dumpKind;
public function dumpKindStr "Dump VarKind to a string."
input DAE.VarKind inVarKind;
output String outString;
algorithm
outString := match (inVarKind)
case DAE.CONST() then "constant ";
case DAE.PARAM() then "parameter ";
case DAE.DISCRETE() then "discrete ";
case DAE.VARIABLE() then "";
end match;
end dumpKindStr;
protected function dumpDirection "Dump VarDirection."
input DAE.VarDirection inVarDirection;
algorithm
_ := match (inVarDirection)
case DAE.INPUT()
equation
Print.printBuf(" input ");
then
();
case DAE.OUTPUT()
equation
Print.printBuf(" output ");
then
();
case DAE.BIDIR()
equation
Print.printBuf(" ");
then
();
end match;
end dumpDirection;
protected function dumpParallelism "Dump VarParallelism."
input DAE.VarParallelism inVarParallelism;
algorithm
_ := match (inVarParallelism)
case DAE.NON_PARALLEL()
equation
Print.printBuf(" ");
then
();
case DAE.PARGLOBAL()
equation
Print.printBuf(" parglobal ");
then
();
case DAE.PARLOCAL()
equation
Print.printBuf(" parlocal ");
then
();
end match;
end dumpParallelism;
public function dumpDirectionStr "Dump VarDirection to a string"
input DAE.VarDirection inVarDirection;
output String outString;
algorithm
outString := match (inVarDirection)
case DAE.INPUT() then "input ";
case DAE.OUTPUT() then "output ";
case DAE.BIDIR() then "";
end match;
end dumpDirectionStr;
protected function dumpStateSelectStr "Dump StateSelect to a string."
input DAE.StateSelect inStateSelect;
output String outString;
algorithm
outString := match (inStateSelect)
case DAE.NEVER() then "StateSelect.never";
case DAE.AVOID() then "StateSelect.avoid";
case DAE.PREFER() then "StateSelect.prefer";
case DAE.ALWAYS() then "StateSelect.always";
case DAE.DEFAULT() then "StateSelect.default";
end match;
end dumpStateSelectStr;
protected function dumpUncertaintyStr
"
Author: Daniel Hedberg 2011-01
Dump Uncertainty to a string.
"
input DAE.Uncertainty uncertainty;
output String out;
algorithm
out := match (uncertainty)
case DAE.GIVEN() then "Uncertainty.given";
case DAE.SOUGHT() then "Uncertainty.sought";
case DAE.REFINE() then "Uncertainty.refine";
end match;
end dumpUncertaintyStr;
protected function dumpDistributionStr
"
Author: Peter Aronsson 2012
Dump Distribution to a string.
"
input DAE.Distribution distribution;
output String out;
algorithm
out := match (distribution)
local
DAE.Exp name;
DAE.Exp params;
DAE.Exp paramNames;
String name_str,params_str, paramNames_str;
case DAE.DISTRIBUTION(name = name, params = params,paramNames=paramNames) equation
name_str = ExpressionDump.printExpStr(name);
params_str = ExpressionDump.printExpStr(params);
paramNames_str = ExpressionDump.printExpStr(paramNames);
then
"Distribution(name = " + name_str + ", params = " + params_str + ", paramNames= " + paramNames_str + ")";
end match;
end dumpDistributionStr;
public function dumpVariableAttributes "Dump VariableAttributes option."
input Option<DAE.VariableAttributes> attr;
protected
String res;
algorithm
res := dumpVariableAttributesStr(attr);
Print.printBuf(res);
end dumpVariableAttributes;
public function dumpVariableAttributesStr "Dump VariableAttributes option to a string."
input Option<DAE.VariableAttributes> inVariableAttributesOption;
output String outString;
algorithm
outString := matchcontinue (inVariableAttributesOption)
local
String quantity,unit_str,displayUnit_str,stateSel_str,min_str,max_str,nominal_str,initial_str,fixed_str,uncertainty_str,dist_str,res_1,res1,res,startOriginStr;
Option<DAE.Exp> quant,unit,displayUnit,min,max,initialExp,nominal,fixed,startOrigin;
Option<DAE.StateSelect> stateSel;
Option<DAE.Uncertainty> uncertainty;
Option<DAE.Distribution> dist;
case (SOME(DAE.VAR_ATTR_REAL(quant,unit,displayUnit,min,max,initialExp,fixed,nominal,stateSel,uncertainty,dist,_,_,_,startOrigin)))
equation
quantity = Dump.getOptionWithConcatStr(quant, ExpressionDump.printExpStr, "quantity = ");
unit_str = Dump.getOptionWithConcatStr(unit, ExpressionDump.printExpStr, "unit = ");
displayUnit_str = Dump.getOptionWithConcatStr(displayUnit, ExpressionDump.printExpStr, "displayUnit = ");
stateSel_str = Dump.getOptionWithConcatStr(stateSel, dumpStateSelectStr , "stateSelect = ");
min_str = Dump.getOptionWithConcatStr(min, ExpressionDump.printExpStr, "min = ");
max_str = Dump.getOptionWithConcatStr(max, ExpressionDump.printExpStr, "max = ");
nominal_str = Dump.getOptionWithConcatStr(nominal, ExpressionDump.printExpStr, "nominal = ");
initial_str = Dump.getOptionWithConcatStr(initialExp, ExpressionDump.printExpStr, "start = ");
fixed_str = Dump.getOptionWithConcatStr(fixed, ExpressionDump.printExpStr, "fixed = ");
uncertainty_str = Dump.getOptionWithConcatStr(uncertainty, dumpUncertaintyStr, "uncertainty = ");
dist_str = Dump.getOptionWithConcatStr(dist, dumpDistributionStr , "distribution = ");
startOriginStr = getStartOrigin(startOrigin);
res_1 = Util.stringDelimitListNonEmptyElts(
{quantity,unit_str,displayUnit_str,min_str,max_str,
initial_str,fixed_str,nominal_str,stateSel_str,uncertainty_str,dist_str,startOriginStr}, ", ");
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
then
res;
case (SOME(DAE.VAR_ATTR_INT(quant,min,max,initialExp,fixed,uncertainty,dist,_,_,_,startOrigin)))
equation
quantity = Dump.getOptionWithConcatStr(quant, ExpressionDump.printExpStr, "quantity = ");
min_str = Dump.getOptionWithConcatStr(min, ExpressionDump.printExpStr, "min = ");
max_str = Dump.getOptionWithConcatStr(max, ExpressionDump.printExpStr, "max = ");
initial_str = Dump.getOptionWithConcatStr(initialExp, ExpressionDump.printExpStr, "start = ");
fixed_str = Dump.getOptionWithConcatStr(fixed, ExpressionDump.printExpStr, "fixed = ");
uncertainty_str = Dump.getOptionWithConcatStr(uncertainty, dumpUncertaintyStr, "uncertainty = ");
dist_str = Dump.getOptionWithConcatStr(dist, dumpDistributionStr , "distribution = ");
startOriginStr = getStartOrigin(startOrigin);
res_1 = Util.stringDelimitListNonEmptyElts({quantity,min_str,max_str,initial_str,fixed_str,uncertainty_str,dist_str,startOriginStr}, ", ");
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
then
res;
case (SOME(DAE.VAR_ATTR_BOOL(quant,initialExp,fixed,_,_,_,startOrigin)))
equation
quantity = Dump.getOptionWithConcatStr(quant, ExpressionDump.printExpStr, "quantity = ");
initial_str = Dump.getOptionWithConcatStr(initialExp, ExpressionDump.printExpStr, "start = ");
fixed_str = Dump.getOptionWithConcatStr(fixed, ExpressionDump.printExpStr, "fixed = ");
startOriginStr = getStartOrigin(startOrigin);
res_1 = Util.stringDelimitListNonEmptyElts({quantity,initial_str,fixed_str,startOriginStr}, ", ");
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
then
res;
case (SOME(DAE.VAR_ATTR_STRING(quant,initialExp,fixed,_,_,_,startOrigin)))
equation
quantity = Dump.getOptionWithConcatStr(quant, ExpressionDump.printExpStr, "quantity = ");
initial_str = Dump.getOptionWithConcatStr(initialExp, ExpressionDump.printExpStr, "start = ");
fixed_str = Dump.getOptionWithConcatStr(fixed, ExpressionDump.printExpStr, "fixed = ");
startOriginStr = getStartOrigin(startOrigin);
res_1 = Util.stringDelimitListNonEmptyElts({quantity,initial_str,fixed_str,startOriginStr}, ", ");
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
then
res;
case (SOME(DAE.VAR_ATTR_ENUMERATION(quant,min,max,initialExp,fixed,_,_,_,startOrigin)))
equation
quantity = Dump.getOptionWithConcatStr(quant, ExpressionDump.printExpStr, "quantity = ");
min_str = Dump.getOptionWithConcatStr(min, ExpressionDump.printExpStr, "min = ");
max_str = Dump.getOptionWithConcatStr(max, ExpressionDump.printExpStr, "max = ");
initial_str = Dump.getOptionWithConcatStr(initialExp, ExpressionDump.printExpStr, "start = ");
fixed_str = Dump.getOptionWithConcatStr(fixed, ExpressionDump.printExpStr, "fixed = ");
startOriginStr = getStartOrigin(startOrigin);
res_1 = Util.stringDelimitListNonEmptyElts({quantity,min_str,max_str,initial_str,fixed_str,startOriginStr}, ", ");
res = if stringEmpty(res_1) then "" else stringAppendList({"(",res_1,")"});
then
res;
case (NONE()) then "";
else "(unknown VariableAttributes)";
end matchcontinue;
end dumpVariableAttributesStr;
protected function getStartOrigin
input Option<DAE.Exp> inStartOrigin;
output String outStartOrigin;
algorithm
outStartOrigin := match(inStartOrigin)
local
String str;
case (NONE()) then "";
case (_)
equation
if (Flags.isSet(Flags.SHOW_START_ORIGIN))
then
str = Dump.getOptionWithConcatStr(inStartOrigin, ExpressionDump.printExpStr , "startOrigin = ");
else
str = "";
end if;
then
str;
end match;
end getStartOrigin;
protected function dumpVarVisibilityStr "Prints 'protected' to a string for protected variables"
input DAE.VarVisibility prot;
output String str;
algorithm
str := match(prot)
case DAE.PUBLIC() then "";
case DAE.PROTECTED() then "protected ";
end match;
end dumpVarVisibilityStr;
public function dumpVarParallelismStr "Dump VarParallelism to a string"
input DAE.VarParallelism inVarParallelism;
output String outString;
algorithm
outString := match (inVarParallelism)
case DAE.NON_PARALLEL() then "";
case DAE.PARGLOBAL() then "parglobal ";
case DAE.PARLOCAL() then "parlocal ";
end match;
end dumpVarParallelismStr;
protected function dumpCommentStr
"Dumps a comment to a string."
input Option<SCode.Comment> inComment;
output String outString;
algorithm
outString := match(inComment)
local
String cmt;
case SOME(SCode.COMMENT(comment = SOME(cmt)))
equation
cmt = System.escapedString(cmt,false);
then stringAppendList({" \"", cmt, "\""});
else "";
end match;
end dumpCommentStr;
protected function dumpClassAnnotationStr
input Option<SCode.Comment> inComment;
output String outString;
algorithm
outString := dumpAnnotationStr(inComment, " ", ";\n");
end dumpClassAnnotationStr;
protected function dumpCompAnnotationStr
input Option<SCode.Comment> inComment;
output String outString;
algorithm
outString := dumpAnnotationStr(inComment, " ", "");
end dumpCompAnnotationStr;
protected function dumpAnnotationStr
input Option<SCode.Comment> inComment;
input String inPrefix;
input String inSuffix;
output String outString;
algorithm
outString := matchcontinue(inComment, inPrefix, inSuffix)
local
String ann;
SCode.Mod ann_mod;
case (SOME(SCode.COMMENT(annotation_ = SOME(SCode.ANNOTATION(ann_mod)))), _, _)
algorithm
if Config.showAnnotations() then
ann := inPrefix + "annotation" + SCodeDump.printModStr(ann_mod, SCodeDump.defaultOptions) + inSuffix;
elseif Config.showStructuralAnnotations() then
ann_mod := filterStructuralMods(ann_mod);
if not SCodeUtil.isEmptyMod(ann_mod) then
ann := inPrefix + "annotation" + SCodeDump.printModStr(ann_mod, SCodeDump.defaultOptions) + inSuffix;
end if;
else
ann := "";
end if;
then
ann;
else "";
end matchcontinue;
end dumpAnnotationStr;
public function filterStructuralMods
input output SCode.Mod mod;
algorithm
mod := SCodeUtil.filterSubMods(mod, filterStructuralMod);
end filterStructuralMods;
public function filterStructuralMod
input SCode.SubMod mod;
output Boolean keep;
algorithm
keep := match mod.ident
case "Evaluate" then true;
case "Inline" then true;
case "LateInline" then true;
case "derivative" then true;
case "inverse" then true;
case "smoothOrder" then true;
case "InlineAfterIndexReduction" then true;
case "GenerateEvents" then true;
else false;
end match;
end filterStructuralMod;
public function dumpCommentAnnotationStr
input Option<SCode.Comment> inComment;
output String outString;
algorithm
outString := match(inComment)
case NONE() then "";
else dumpCommentStr(inComment) + dumpCompAnnotationStr(inComment);
end match;
end dumpCommentAnnotationStr;
protected function dumpCommentOption "Dump Comment option."
input Option<SCode.Comment> comment;
protected
String str;
algorithm
str := dumpCommentAnnotationStr(comment);
Print.printBuf(str);
end dumpCommentOption;
protected function dumpEquation "Dump equation."
input DAE.Element inElement;
algorithm
_ := matchcontinue (inElement)
local
DAE.Exp e1,e2,e;
DAE.ComponentRef c,cr1,cr2;
Absyn.Path functionName;
list<DAE.Exp> functionArgs;
DAE.ElementSource src;
String sourceStr;
case (DAE.EQUATION(exp = e1, scalar = e2, source = src))
equation
Print.printBuf(" ");
ExpressionDump.printExp(e1);
Print.printBuf(" = ");
ExpressionDump.printExp(e2);
sourceStr = getSourceInformationStr(src);
Print.printBuf(sourceStr);
Print.printBuf(";\n");
then
();
case (DAE.EQUEQUATION(cr1=cr1, cr2=cr2, source = src))
equation
Print.printBuf(" ");
ComponentReference.printComponentRef(cr1);
Print.printBuf(" = ");
ComponentReference.printComponentRef(cr2);
sourceStr = getSourceInformationStr(src);
Print.printBuf(sourceStr);
Print.printBuf(";\n");
then
();
case (DAE.ARRAY_EQUATION(exp = e1, array= e2, source = src))
equation
Print.printBuf(" ");
ExpressionDump.printExp(e1);
Print.printBuf(" = ");
ExpressionDump.printExp(e2);
sourceStr = getSourceInformationStr(src);
Print.printBuf(sourceStr);
Print.printBuf(";\n");
then
();
case (DAE.COMPLEX_EQUATION(lhs = e1, rhs= e2, source = src))
equation
Print.printBuf(" ");
ExpressionDump.printExp(e1);
Print.printBuf(" = ");
ExpressionDump.printExp(e2);
sourceStr = getSourceInformationStr(src);
Print.printBuf(sourceStr);
Print.printBuf(";\n");
then
();
case (DAE.DEFINE(componentRef = c, exp = e, source = src))
equation
Print.printBuf(" ");
ComponentReference.printComponentRef(c);
Print.printBuf(" ::= ");
ExpressionDump.printExp(e);
sourceStr = getSourceInformationStr(src);
Print.printBuf(sourceStr);
Print.printBuf(";\n");
then
();
case (DAE.ASSERT(condition=e1, message=e2, source = src))
equation
Print.printBuf("assert(");
ExpressionDump.printExp(e1);
Print.printBuf(",");
ExpressionDump.printExp(e2);
Print.printBuf(") ");
sourceStr = getSourceInformationStr(src);
Print.printBuf(sourceStr);
Print.printBuf(";\n");
then
();
case (DAE.NORETCALL(exp = e1, source = src))
equation
ExpressionDump.printExp(e1);
sourceStr = getSourceInformationStr(src);
Print.printBuf(sourceStr);
Print.printBuf(";\n");
then
();
case _
equation
Print.printBuf("/* FIXME: UNHANDLED_EQUATION in DAEDump.dumpEquation */;\n");
then
();
end matchcontinue;
end dumpEquation;
protected function dumpInitialEquation "Dump initial equation."
input DAE.Element inElement;
algorithm
_ := matchcontinue (inElement)
local
DAE.Exp e1,e2,e;
DAE.ComponentRef c;
list<DAE.Element> xs1,xs2;
list<list<DAE.Element>> trueBranches;
list<DAE.Exp> conds;
String s,s1,s2,sourceStr;
IOStream.IOStream str;
DAE.ElementSource src;
list<SCode.Comment> cmt;
case (DAE.INITIALEQUATION(exp1 = e1,exp2 = e2))
equation
Print.printBuf(" ");
ExpressionDump.printExp(e1);
Print.printBuf(" = ");
ExpressionDump.printExp(e2);
Print.printBuf(";\n");
then
();
case (DAE.INITIALDEFINE(componentRef = c,exp = e))
equation
Print.printBuf(" ");
ComponentReference.printComponentRef(c);
Print.printBuf(" ::= ");
ExpressionDump.printExp(e);
Print.printBuf(";\n");
then
();
case (DAE.INITIAL_ARRAY_EQUATION(exp = e1, array = e2))
equation
Print.printBuf(" ");
ExpressionDump.printExp(e1);
Print.printBuf(" = ");
ExpressionDump.printExp(e2);
Print.printBuf(";\n");
then
();
case (DAE.INITIAL_COMPLEX_EQUATION(lhs = e1,rhs = e2))
equation
Print.printBuf(" ");
ExpressionDump.printExp(e1);
Print.printBuf(" = ");
ExpressionDump.printExp(e2);
Print.printBuf(";\n");
then
();
case (DAE.INITIAL_IF_EQUATION(condition1 = (e::conds),equations2 = (xs1::trueBranches),equations3 = xs2))
equation
Print.printBuf(" if ");
ExpressionDump.printExp(e);
Print.printBuf(" then\n");
List.map_0(xs1,dumpInitialEquation);
str = dumpIfEquationsStream(conds, trueBranches, IOStream.emptyStreamOfTypeList);
s = IOStream.string(str);
Print.printBuf(s);
Print.printBuf(" else\n");
List.map_0(xs2,dumpInitialEquation);
Print.printBuf("end if;\n");
then
();
case (DAE.INITIAL_ASSERT(condition=e1,message = e2,source = src))
equation
cmt = ElementSource.getCommentsFromSource(src);
sourceStr = cmtListToString(cmt);
s1 = ExpressionDump.printExpStr(e1);
s2 = ExpressionDump.printExpStr(e2);
s = stringAppendList({" assert(",s1, ",",s2,") ", sourceStr, ";\n"});
Print.printBuf(s);
then
();
case (DAE.INITIAL_TERMINATE(message=e1,source = src))
equation