-
Notifications
You must be signed in to change notification settings - Fork 299
/
Dump.mo
4923 lines (4620 loc) · 150 KB
/
Dump.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 Dump
" file: Dump.mo
package: Dump
description: debug printing
RCS: $Id$
Printing routines for debugging of the AST. These functions do
nothing but print the data structures to the standard output.
The main entrypoint for this module is the function Dump.dump
which takes an entire program as an argument, and prints it all
in Modelica source form. The other interface functions can be
used to print smaller portions of a program."
// public imports
public import Absyn;
// protected imports
protected import AbsynDumpTpl;
protected import Config;
protected import Error;
protected import List;
protected import Print;
protected import Tpl;
protected import Util;
public function dumpExpStr
input Absyn.Exp exp;
output String str;
algorithm
Print.clearBuf();
printExp(exp);
str := Print.getString();
end dumpExpStr;
public function dumpExp
input Absyn.Exp exp;
protected String str;
algorithm
Print.clearBuf();
printExp(exp);
str := Print.getString();
print(str);
print("--------------------\n");
end dumpExp;
public function dump
"Prints a program, i.e. the whole AST, to the Print buffer."
input Absyn.Program inProgram;
algorithm
_ := match (inProgram)
local
list<Absyn.Class> cs;
Absyn.Within w;
case Absyn.PROGRAM(classes = cs,within_ = w)
equation
Print.printBuf("Absyn.PROGRAM([\n");
printList(cs, printClass, ", ");
Print.printBuf("],");
dumpWithin(w);
Print.printBuf(")\n");
then
();
end match;
end dump;
public function unparseStr
"Prettyprints the Program, i.e. the whole AST, to a string."
input Absyn.Program inProgram;
input Boolean markup "
Used by MathCore, and dependencies to other modules requires this to also be in OpenModelica.
Contact peter.aronsson@mathcore.com for an explanation.
Note: This will be used for a different purpose in OpenModelica once we redesign Dump to use templates
... by sending in DumpOptions (for example to add markup, etc)
";
output String outString;
algorithm
outString := Tpl.tplString(AbsynDumpTpl.dump, inProgram);
end unparseStr;
public function unparseClassList
"Prettyprints a list of classes"
input list<Absyn.Class> inClasses;
output String outString;
algorithm
outString := Tpl.tplString(AbsynDumpTpl.dump,
Absyn.PROGRAM(inClasses, Absyn.TOP(), Absyn.TIMESTAMP(0.0, 0.0)));
end unparseClassList;
public function unparseClassStr
"Prettyprints a Class."
input Absyn.Class inClass;
output String outString;
algorithm
outString := Tpl.tplString(AbsynDumpTpl.dumpClass, inClass);
end unparseClassStr;
public function unparseWithin
"Prettyprints a within statement."
input Absyn.Within inWithin;
output String outString;
algorithm
outString := Tpl.tplString(AbsynDumpTpl.dumpWithin, inWithin);
end unparseWithin;
protected function dumpWithin
"Dumps within to the Print buffer."
input Absyn.Within inWithin;
algorithm
_ := match (inWithin)
local Absyn.Path p;
case (Absyn.TOP())
equation
Print.printBuf("Absyn.TOP");
then
();
case (Absyn.WITHIN(path = p))
equation
Print.printBuf("Absyn.WITHIN(");
dumpPath(p);
Print.printBuf("\n");
then
();
end match;
end dumpWithin;
public function unparseClassAttributesStr
"Prettyprints Class attributes."
input Absyn.Class inClass;
output String outString;
algorithm
outString := match (inClass)
local
String s1,s2,s2_1,s3,str,n;
Boolean p,f,e;
Absyn.Restriction r;
case Absyn.CLASS(partialPrefix = p,finalPrefix = f,encapsulatedPrefix = e,restriction = r)
equation
s1 = selectString(p, "partial ", "");
s2 = selectString(f, "final ", "");
s2_1 = selectString(e, "encapsulated ", "");
s3 = unparseRestrictionStr(r);
str = stringAppendList({s2_1,s1,s2,s3});
then
str;
end match;
end unparseClassAttributesStr;
public function unparseCommentOption
"Prettyprints a Comment."
input Option<Absyn.Comment> inComment;
output String outString;
algorithm
outString := Tpl.tplString(AbsynDumpTpl.dumpCommentOpt, inComment);
end unparseCommentOption;
protected function dumpCommentOption
"Prints a Comment to the Print buffer."
input Option<Absyn.Comment> inAbsynCommentOption;
algorithm
_ := match (inAbsynCommentOption)
local
String str,cmt;
Option<Absyn.Annotation> annopt;
case (NONE())
equation
Print.printBuf("NONE()");
then
();
case (SOME(Absyn.COMMENT(annopt,SOME(cmt))))
equation
Print.printBuf("SOME(Absyn.COMMENT(");
dumpAnnotationOption(annopt);
str = stringAppendList({"SOME(\"",cmt,"\")))"});
Print.printBuf(str);
then
();
case (SOME(Absyn.COMMENT(annopt,NONE())))
equation
Print.printBuf("SOME(Absyn.COMMENT(");
dumpAnnotationOption(annopt);
Print.printBuf(",NONE()))");
then
();
end match;
end dumpCommentOption;
protected function dumpAnnotationOption
"Dumps an annotation option to the Print buffer."
input Option<Absyn.Annotation> inAbsynAnnotationOption;
algorithm
_ := match (inAbsynAnnotationOption)
local list<Absyn.ElementArg> mod;
case (NONE())
equation
Print.printBuf("NONE()");
then
();
case (SOME(Absyn.ANNOTATION(mod)))
equation
Print.printBuf("SOME(Absyn.ANNOTATION(");
printMod1(mod);
Print.printBuf("))");
then
();
end match;
end dumpAnnotationOption;
protected function printEnumliterals
"Prints enumeration literals, each consisting of an
identifier and an optional comment to the Print buffer."
input list<Absyn.EnumLiteral> lst;
algorithm
Print.printBuf("[");
printEnumliterals2(lst);
Print.printBuf("]");
end printEnumliterals;
protected function printEnumliterals2
"Helper function to printEnumliterals"
input list<Absyn.EnumLiteral> inAbsynEnumLiteralLst;
algorithm
_ := matchcontinue (inAbsynEnumLiteralLst)
local
String str,str2;
Option<Absyn.Comment> optcmt,optcmt2;
Absyn.EnumLiteral a;
list<Absyn.EnumLiteral> b;
case ({}) then ();
case ((Absyn.ENUMLITERAL(literal = str,comment = optcmt) :: (a :: b)))
equation
Print.printBuf("Absyn.ENUMLITERAL(\"");
Print.printBuf(str);
Print.printBuf("\",");
dumpCommentOption(optcmt);
Print.printBuf("), ");
printEnumliterals2((a :: b));
then
();
case ({Absyn.ENUMLITERAL(literal = str,comment = optcmt),Absyn.ENUMLITERAL(literal = str2,comment = optcmt2)})
equation
Print.printBuf("Absyn.ENUMLITERAL(\"");
Print.printBuf(str);
Print.printBuf("\",");
dumpCommentOption(optcmt);
Print.printBuf("), Absyn.ENUMLITERAL(\"");
Print.printBuf(str2);
Print.printBuf("\",");
dumpCommentOption(optcmt2);
Print.printBuf(")");
then
();
end matchcontinue;
end printEnumliterals2;
public function unparseRestrictionStr
"Prettyprints the class restriction."
input Absyn.Restriction inRestriction;
output String outString;
algorithm
outString := Tpl.tplString(AbsynDumpTpl.dumpRestriction, inRestriction);
end unparseRestrictionStr;
public function printInfo
"author: adrpo, 2006-02-05
Dumps an Info to the Print buffer."
input Absyn.Info inInfo;
algorithm
_ := match (inInfo)
local
String s1,s2,s3,s4,filename;
Boolean isReadOnly;
Integer sline,scol,eline,ecol;
case (Absyn.INFO(fileName = filename,isReadOnly = isReadOnly,
lineNumberStart = sline,columnNumberStart = scol,
lineNumberEnd = eline,columnNumberEnd = ecol))
equation
Print.printBuf("Absyn.INFO(\"");
Print.printBuf(filename);
Print.printBuf("\", ");
printBool(isReadOnly);
Print.printBuf(", ");
s1 = intString(sline);
Print.printBuf(s1);
Print.printBuf(", ");
s2 = intString(scol);
Print.printBuf(s2);
Print.printBuf(", ");
s3 = intString(eline);
Print.printBuf(s3);
Print.printBuf(", ");
s4 = intString(ecol);
Print.printBuf(s4);
Print.printBuf(")");
then
();
end match;
end printInfo;
public function unparseInfoStr
"author: adrpo, 2006-02-05
Translates Info to a string representation"
input Absyn.Info inInfo;
output String outString;
algorithm
outString:=
match (inInfo)
local
String s1,s2,s3,s4,s5,str,filename;
Boolean isReadOnly;
Integer sline,scol,eline,ecol;
case (Absyn.INFO(fileName = filename,isReadOnly = isReadOnly,
lineNumberStart = sline,columnNumberStart = scol,
lineNumberEnd = eline,columnNumberEnd = ecol))
equation
s1 = selectString(isReadOnly, "readonly", "writable");
s2 = intString(sline);
s3 = intString(scol);
s4 = intString(eline);
s5 = intString(ecol);
str = stringAppendList({"Absyn.INFO(\"",filename,"\", ",s1,", ",s2,", ",s3,", ",s4,", ",s5,")\n"});
then
str;
end match;
end unparseInfoStr;
protected function printClass
"Dumps a Class to the Print buffer.
changed by adrpo, 2006-02-05 to use printInfo."
input Absyn.Class inClass;
algorithm
_ := match (inClass)
local
String n;
Boolean p,f,e;
Absyn.Restriction r;
Absyn.ClassDef cdef;
Absyn.Info info;
case (Absyn.CLASS(name = n,partialPrefix = p,finalPrefix = f,encapsulatedPrefix = e,restriction = r,body = cdef,info = info))
equation
Print.printBuf("Absyn.CLASS(\""); Print.printBuf(n);
Print.printBuf("\", "); printBool(p);
Print.printBuf(", "); printBool(f);
Print.printBuf(", "); printBool(e);
Print.printBuf(", "); printClassRestriction(r);
Print.printBuf(", "); printClassdef(cdef);
Print.printBuf(", "); printInfo(info);
Print.printBuf(")\n");
then
();
end match;
end printClass;
protected function printClassdef
"Prints a ClassDef to the Print buffer."
input Absyn.ClassDef inClassDef;
algorithm
_ := match (inClassDef)
local
list<Absyn.ClassPart> parts;
Option<String> commentStr;
Option<Absyn.Comment> comment;
String s,baseClassName;
Absyn.TypeSpec tspec;
Absyn.ElementAttributes attr;
list<Absyn.ElementArg> earg,modifications;
list<Absyn.EnumLiteral> enumlst;
case (Absyn.PARTS(classParts = parts,comment = commentStr))
equation
Print.printBuf("Absyn.PARTS([");
printListDebug("print_classdef", parts, printClassPart, ", ");
Print.printBuf("], ");
printStringCommentOption(commentStr);
Print.printBuf(")");
then
();
case (Absyn.CLASS_EXTENDS(baseClassName = baseClassName,
modifications = modifications,
parts = parts,
comment = commentStr))
equation
Print.printBuf("Absyn.CLASS_EXTENDS([");
Print.printBuf(baseClassName); Print.printBuf(",[");
printList(modifications, printElementArg, ",");
Print.printBuf("], ");
printStringCommentOption(commentStr);
Print.printBuf(", ");
Print.printBuf("Absyn.PARTS([");
printListDebug("print_classdef", parts, printClassPart, ", ");
Print.printBuf("]))");
then
();
case (Absyn.DERIVED(typeSpec = tspec,attributes = attr,arguments = earg,comment = comment))
equation
Print.printBuf("Absyn.DERIVED(");
s = unparseTypeSpec(tspec);
Print.printBuf(s);
Print.printBuf(", ");
printElementattr(attr);
Print.printBuf(",[");
printList(earg, printElementArg, ",");
Print.printBuf("], ");
s = unparseCommentOption(comment);
Print.printBuf(s);
Print.printBuf(")");
then
();
case (Absyn.ENUMERATION(enumLiterals = Absyn.ENUMLITERALS(enumLiterals = enumlst),comment = comment))
equation
Print.printBuf("Absyn.ENUMERATION(");
printEnumliterals(enumlst);
Print.printBuf(", ");
dumpCommentOption(comment);
Print.printBuf(")");
then
();
case (Absyn.ENUMERATION(enumLiterals = Absyn.ENUM_COLON(),comment = comment))
equation
Print.printBuf("Absyn.ENUMERATION( :, ");
dumpCommentOption(comment);
Print.printBuf(")");
then
();
case (Absyn.OVERLOAD(functionNames = _))
equation
Print.printBuf("Absyn.OVERLOAD( fill in )");
then
();
end match;
end printClassdef;
protected function printClassRestriction
"Prints the class restriction to the Print buffer."
input Absyn.Restriction inRestriction;
algorithm
_ := matchcontinue (inRestriction)
case Absyn.R_CLASS() equation Print.printBuf("Absyn.R_CLASS"); then ();
case Absyn.R_OPTIMIZATION() equation Print.printBuf("Absyn.R_OPTIMIZATION"); then ();
case Absyn.R_MODEL() equation Print.printBuf("Absyn.R_MODEL"); then ();
case Absyn.R_RECORD() equation Print.printBuf("Absyn.R_RECORD"); then ();
case Absyn.R_BLOCK() equation Print.printBuf("Absyn.R_BLOCK"); then ();
case Absyn.R_CONNECTOR() equation Print.printBuf("Absyn.R_CONNECTOR"); then ();
case Absyn.R_EXP_CONNECTOR() equation Print.printBuf("Absyn.R_EXP_CONNECTOR"); then ();
case Absyn.R_TYPE() equation Print.printBuf("Absyn.R_TYPE"); then ();
case Absyn.R_PACKAGE() equation Print.printBuf("Absyn.R_PACKAGE"); then ();
case Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION(Absyn.IMPURE()))
equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION(Absyn.IMPURE))"); then ();
case Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION(Absyn.PURE()))
equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION(Absyn.PURE))"); then ();
case Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION(Absyn.NO_PURITY()))
equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_NORMAL_FUNCTION(Absyn.NO_PURITY))"); then ();
case Absyn.R_FUNCTION(Absyn.FR_OPERATOR_FUNCTION()) equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_OPERATOR_FUNCTION)"); then ();
case Absyn.R_FUNCTION(Absyn.FR_PARALLEL_FUNCTION()) equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_PARALLEL_FUNCTION)"); then ();
case Absyn.R_FUNCTION(Absyn.FR_KERNEL_FUNCTION()) equation Print.printBuf("Absyn.R_FUNCTION(Absyn.FR_KERNEL_FUNCTION)"); then ();
case Absyn.R_OPERATOR() equation Print.printBuf("Absyn.R_OPERATOR"); then ();
case Absyn.R_OPERATOR_RECORD() equation Print.printBuf("Absyn.R_OPERATOR_RECORD"); then ();
case Absyn.R_ENUMERATION() equation Print.printBuf("Absyn.R_ENUMERATION"); then ();
case Absyn.R_PREDEFINED_INTEGER() equation Print.printBuf("Absyn.R_PREDEFINED_INTEGER"); then ();
case Absyn.R_PREDEFINED_REAL() equation Print.printBuf("Absyn.R_PREDEFINED_REAL"); then ();
case Absyn.R_PREDEFINED_STRING() equation Print.printBuf("Absyn.R_PREDEFINED_STRING"); then ();
case Absyn.R_PREDEFINED_BOOLEAN() equation Print.printBuf("Absyn.R_PREDEFINED_BOOLEAN"); then ();
// BTH
case Absyn.R_PREDEFINED_CLOCK() equation Print.printBuf("Absyn.R_PREDEFINED_CLOCK"); then ();
case Absyn.R_PREDEFINED_ENUMERATION() equation Print.printBuf("Absyn.R_PREDEFINED_ENUMERATION"); then ();
case Absyn.R_UNIONTYPE() equation Print.printBuf("Absyn.R_UNIONTYPE"); then ();
case _ equation Print.printBuf("/* UNKNOWN RESTRICTION! FIXME! */"); then ();
end matchcontinue;
end printClassRestriction;
protected function printClassModification
"Prints a class modification to a print buffer."
input list<Absyn.ElementArg> inAbsynElementArgLst;
algorithm
_ := matchcontinue (inAbsynElementArgLst)
local list<Absyn.ElementArg> l;
case ({}) then ();
case (l)
equation
Print.printBuf("(");
printListDebug("print_class_modification", l, printElementArg, ",");
Print.printBuf(")");
then
();
end matchcontinue;
end printClassModification;
protected function printElementArg
"Prints an ElementArg to the Print buffer."
input Absyn.ElementArg inElementArg;
algorithm
_ := match (inElementArg)
local
Boolean f;
Absyn.Each each_;
Option<Absyn.Modification> optm;
Option<String> optcmt;
Absyn.RedeclareKeywords keywords;
Absyn.ElementSpec spec;
Absyn.Path p;
case (Absyn.MODIFICATION(finalPrefix = f,eachPrefix = each_,path = p,modification = optm,comment = optcmt))
equation
Print.printBuf("Absyn.MODIFICATION(");
printBool(f);
Print.printBuf(", ");
dumpEach(each_);
Print.printBuf(", ");
printPath(p);
Print.printBuf(", ");
printOptModification(optm);
Print.printBuf(", ");
printStringCommentOption(optcmt);
Print.printBuf(")");
then
();
case (Absyn.REDECLARATION(finalPrefix = f,redeclareKeywords = _,eachPrefix = _,elementSpec = spec))
equation
Print.printBuf("Absyn.REDECLARATION(");
printBool(f);
printElementspec(spec);
Print.printBuf(",_)");
then
();
end match;
end printElementArg;
public function unparseEachStr
"Prettyprints the each keyword."
input Absyn.Each inEach;
output String outString;
algorithm
outString := match (inEach)
case (Absyn.EACH()) then "each ";
case (Absyn.NON_EACH()) then "";
end match;
end unparseEachStr;
protected function dumpEach
"Print the each keyword to the Print buffer"
input Absyn.Each inEach;
algorithm
_ := match (inEach)
case (Absyn.EACH()) equation Print.printBuf("Absyn.EACH"); then ();
case (Absyn.NON_EACH()) equation Print.printBuf("Absyn.NON_EACH"); then ();
end match;
end dumpEach;
protected function printClassPart
"Prints the ClassPart to the Print buffer."
input Absyn.ClassPart inClassPart;
algorithm
_ := match (inClassPart)
local
list<Absyn.ElementItem> el;
list<Absyn.EquationItem> eqs;
// list<Absyn.ConstraintItem> constr;
list<Absyn.AlgorithmItem> algs;
list<Absyn.Exp> exps;
Absyn.ExternalDecl edecl;
case (Absyn.PUBLIC(contents = el))
equation
Print.printBuf("Absyn.PUBLIC(");
printElementitems(el);
Print.printBuf(")");
then
();
case (Absyn.PROTECTED(contents = el))
equation
Print.printBuf("Absyn.PROTECTED(");
printElementitems(el);
Print.printBuf(")");
then
();
case (Absyn.EQUATIONS(contents = eqs))
equation
Print.printBuf("Absyn.EQUATIONS([");
printList(eqs, printEquationitem, ", ");
Print.printBuf("])");
then
();
case (Absyn.CONSTRAINTS(contents = exps))
equation
Print.printBuf("Absyn.CONSTRAINTS([");
printList(exps, printExp, "; ");
Print.printBuf("])");
then
();
case (Absyn.INITIALEQUATIONS(contents = eqs))
equation
Print.printBuf("Absyn.INITIALEQUATIONS([");
printList(eqs, printEquationitem, ", ");
Print.printBuf("])");
then
();
case (Absyn.ALGORITHMS(contents = algs))
equation
Print.printBuf("Absyn.ALGORITHMS(");
printList(algs, printAlgorithmitem, ", ");
Print.printBuf(")");
then
();
case (Absyn.INITIALALGORITHMS(contents = algs))
equation
Print.printBuf("Absyn.INITIALALGORITHMS([");
printList(algs, printAlgorithmitem, ", ");
Print.printBuf("])");
then
();
case (Absyn.EXTERNAL(externalDecl = edecl))
equation
Print.printBuf("Absyn.EXTERNAL(");
printExternalDecl(edecl);
Print.printBuf(")");
then
();
end match;
end printClassPart;
protected function printExternalDecl
"Prints an external declaration to the Print buffer."
input Absyn.ExternalDecl inExternalDecl;
algorithm
_ := match (inExternalDecl)
local
String idstr,crefstr,expstr,str,lang;
Option<String> id;
Option<Absyn.ComponentRef> cref;
list<Absyn.Exp> exps;
case Absyn.EXTERNALDECL(funcName = id,lang = NONE(),output_ = cref,args = exps)
equation
idstr = Util.getOptionOrDefault(id, "");
crefstr = getOptionStr(cref, printComponentRefStr);
expstr = printListStr(exps, printExpStr, ",");
str = stringAppendList({idstr,", ",crefstr,", (",expstr,")"});
Print.printBuf(str);
then
();
case Absyn.EXTERNALDECL(funcName = id,lang = SOME(lang),output_ = cref,args = exps)
equation
idstr = Util.getOptionOrDefault(id, "");
crefstr = getOptionStr(cref, printComponentRefStr);
expstr = printListStr(exps, printExpStr, ",");
str = stringAppendList({idstr,", \"",lang,"\", ",crefstr,", (",expstr,")"});
Print.printBuf(str);
then
();
end match;
end printExternalDecl;
protected function printElementitems
"Print a list of ElementItems to the Print buffer."
input list<Absyn.ElementItem> elts;
algorithm
Print.printBuf("[");
printElementitems2(elts);
Print.printBuf("]");
end printElementitems;
protected function printElementitems2
"Helper function to printElementitems"
input list<Absyn.ElementItem> inAbsynElementItemLst;
algorithm
_ := matchcontinue (inAbsynElementItemLst)
local
Absyn.Element e;
Absyn.Annotation a;
list<Absyn.ElementItem> els;
case {} then ();
case {Absyn.ELEMENTITEM(element = e)}
equation
Print.printBuf("Absyn.ELEMENTITEM(");
printElement(e);
Print.printBuf(")");
then
();
case (Absyn.ELEMENTITEM(element = e) :: els)
equation
Print.printBuf("Absyn.ELEMENTITEM(");
printElement(e);
Print.printBuf("), ");
printElementitems2(els);
then
();
case _
equation
Print.printBuf("Error Dump.printElementitems2\n");
then
();
end matchcontinue;
end printElementitems2;
protected function printAnnotation
"Prints an annotation to the Print buffer."
input Absyn.Annotation inAnnotation;
algorithm
_ := match (inAnnotation)
local list<Absyn.ElementArg> mod;
case (Absyn.ANNOTATION(elementArgs = mod))
equation
Print.printBuf("ANNOTATION(");
printModification(Absyn.CLASSMOD(mod,Absyn.NOMOD()));
Print.printBuf(")");
then
();
end match;
end printAnnotation;
public function unparseElementArgStr "Prettyprints an Absyn.ElementArg"
input Absyn.ElementArg inElementArg;
output String outString;
algorithm
outString := Tpl.tplString(AbsynDumpTpl.dumpElementArg,inElementArg);
end unparseElementArgStr;
public function unparseElementItemStr
"Prettyprints and ElementItem."
input Absyn.ElementItem inElementItem;
output String outString;
algorithm
outString := Tpl.tplString(AbsynDumpTpl.dumpElementItem, inElementItem);
end unparseElementItemStr;
public function unparseAnnotation
"Prettyprint an annotation."
input Absyn.Annotation inAnnotation;
output String outString;
algorithm
outString := Tpl.tplString(AbsynDumpTpl.dumpAnnotation, inAnnotation);
end unparseAnnotation;
public function unparseAnnotationOption
"Prettyprint an annotation."
input Option<Absyn.Annotation> inAbsynAnnotation;
output String outString;
algorithm
outString := match (inAbsynAnnotation)
local
Absyn.Annotation ann;
case SOME(ann) then unparseAnnotation(ann);
else "";
end match;
end unparseAnnotationOption;
protected function printElement "
Prints an Element to the Print buffer.
changed by adrpo, 2006-02-06 to use print_info and dump Absyn.TEXT also
"
input Absyn.Element inElement;
algorithm
_:=
match (inElement)
local
Boolean finalPrefix;
Option<Absyn.RedeclareKeywords> repl;
Absyn.InnerOuter inout;
String name,text;
Absyn.ElementSpec spec;
Absyn.Info info;
case (Absyn.ELEMENT(finalPrefix = finalPrefix,redeclareKeywords = _,innerOuter = inout,
specification = spec,info = info,constrainClass = NONE()))
equation
Print.printBuf("Absyn.ELEMENT(");
printBool(finalPrefix);
Print.printBuf(", _");
Print.printBuf(", ");
printInnerouter(inout);
Print.printBuf(", ");
printElementspec(spec);
Print.printBuf(", ");
printInfo(info);
Print.printBuf("),NONE())");
then
();
case (Absyn.ELEMENT(finalPrefix = finalPrefix,redeclareKeywords = _,innerOuter = inout,
specification = spec,info = info,constrainClass = SOME(_)))
equation
Print.printBuf("Absyn.ELEMENT(");
printBool(finalPrefix);
Print.printBuf(", _");
Print.printBuf(", ");
printInnerouter(inout);
Print.printBuf(",");
printElementspec(spec);
Print.printBuf(", ");
printInfo(info);
Print.printBuf(", SOME(...))");
then
();
case (Absyn.TEXT(optName = SOME(name),string = text,info = info))
equation
Print.printBuf("Absyn.TEXT(");
Print.printBuf("SOME(\"");
Print.printBuf(name);
Print.printBuf("\"), \"");
Print.printBuf(text);
Print.printBuf("\", ");
printInfo(info);
Print.printBuf(")");
then
();
case (Absyn.TEXT(optName = NONE(),string = text,info = info))
equation
Print.printBuf("Absyn.TEXT(");
Print.printBuf("NONE, \"");
Print.printBuf(text);
Print.printBuf("\", ");
printInfo(info);
Print.printBuf(")");
then
();
end match;
end printElement;
protected function printInnerouter
"Prints the inner or outer keyword to the Print buffer."
input Absyn.InnerOuter inInnerOuter;
algorithm
_:=
match (inInnerOuter)
case (Absyn.INNER())
equation
Print.printBuf("Absyn.INNER");
then
();
case (Absyn.OUTER())
equation
Print.printBuf("Absyn.OUTER");
then
();
case (Absyn.INNER_OUTER())
equation
Print.printBuf("Absyn.INNER_OUTER ");
then
();
case (Absyn.NOT_INNER_OUTER())
equation
Print.printBuf("Absyn.NOT_INNER_OUTER ");
then
();
end match;
end printInnerouter;
public function unparseInnerouterStr "
Prettyprints the inner or outer keyword to a string.
"
input Absyn.InnerOuter inInnerOuter;
output String outString;
algorithm
outString:=
match (inInnerOuter)
case (Absyn.INNER()) then "inner ";
case (Absyn.OUTER()) then "outer ";
case (Absyn.INNER_OUTER()) then "inner outer ";
case (Absyn.NOT_INNER_OUTER()) then "";
end match;
end unparseInnerouterStr;
public function printElementspec
"Prints the ElementSpec to the Print buffer."
input Absyn.ElementSpec inElementSpec;
algorithm
_:=
matchcontinue (inElementSpec)
local
Boolean repl;
Absyn.Class cl;
Absyn.Path p;
list<Absyn.ElementArg> l;
String s;
Absyn.ElementAttributes attr;
Absyn.TypeSpec t;
list<Absyn.ComponentItem> cs;
Absyn.Import i;
Absyn.Annotation ann;
case (Absyn.CLASSDEF(replaceable_ = repl,class_ = cl))
equation
Print.printBuf("Absyn.CLASSDEF(");
printBool(repl);
Print.printBuf(", ");
printClass(cl);
Print.printBuf(")");
then
();
case (Absyn.EXTENDS(path = p,elementArg = l,annotationOpt=SOME(ann)))
equation
Print.printBuf("Absyn.EXTENDS(");
dumpPath(p);
Print.printBuf(", [");
printListDebug("print_elementspec", l, printElementArg, ",");
printAnnotation(ann);
Print.printBuf("])");
then
();
case (Absyn.EXTENDS(path = p,elementArg = l,annotationOpt=NONE()))
equation
Print.printBuf("Absyn.EXTENDS(");
dumpPath(p);
Print.printBuf(", [");
printListDebug("print_elementspec", l, printElementArg, ",");
Print.printBuf("])");
then
();
case (Absyn.COMPONENTS(attributes = attr,typeSpec = t,components = cs))
equation
Print.printBuf("Absyn.COMPONENTS(");
printElementattr(attr);
Print.printBuf(",");
s = unparseTypeSpec(t);
Print.printBuf(s);
Print.printBuf(",[");
printListDebug("print_elementspec", cs, printComponentitem, ",");
Print.printBuf("])");
then
();
case (Absyn.IMPORT(import_ = i))
equation
Print.printBuf("Absyn.IMPORT(");
printImport(i);
Print.printBuf(")");
then
();
else
equation
Print.printBuf(" ##ERROR## ");
then
();
end matchcontinue;
end printElementspec;
public function printImport
"Prints an Import to the Print buffer."
input Absyn.Import inImport;
algorithm
_ := match (inImport)
local
String i;
Absyn.Path p;
list<Absyn.GroupImport> groups;
case (Absyn.NAMED_IMPORT(name = i,path = p))
equation
Print.printBuf(i);
Print.printBuf(" = ");
printPath(p);
then
();
case (Absyn.QUAL_IMPORT(path = p))
equation
printPath(p);
then
();
case (Absyn.UNQUAL_IMPORT(path = p))
equation
printPath(p);
Print.printBuf(".*");
then