/
SCode.mo
2789 lines (2573 loc) · 87.3 KB
/
SCode.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-CurrentYear, Linköping University,
* 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
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköping University, 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.
*
*/
package SCode
" file: SCode.mo
package: SCode
description: SCode intermediate form
RCS: $Id$
This module contains data structures to describe a Modelica
model in a more convenient (canonical) way than the Absyn module does.
Also local functions for printing and query of SCode are defined.
See also SCodeUtil.mo for translation functions
from Absyn representation to SCode representation.
The SCode representation is used as input to the Inst module"
public import Absyn;
public type Ident = Absyn.Ident "Some definitions are borrowed from `Absyn\'";
public type Path = Absyn.Path;
public type Subscript = Absyn.Subscript;
public
uniontype Restriction
record R_CLASS end R_CLASS;
record R_OPTIMIZATION end R_OPTIMIZATION;
record R_MODEL end R_MODEL;
record R_RECORD end R_RECORD;
record R_BLOCK end R_BLOCK;
record R_CONNECTOR "a connector"
Boolean isExpandable "is expandable?";
end R_CONNECTOR;
record R_OPERATOR "an operator definition"
Boolean isFunction "is this operator a function?";
end R_OPERATOR;
record R_TYPE end R_TYPE;
record R_PACKAGE end R_PACKAGE;
record R_FUNCTION end R_FUNCTION;
record R_EXT_FUNCTION "Added c.t. Absyn" end R_EXT_FUNCTION;
record R_ENUMERATION end R_ENUMERATION;
// predefined internal types
record R_PREDEFINED_INTEGER "predefined IntegerType" end R_PREDEFINED_INTEGER;
record R_PREDEFINED_REAL "predefined RealType" end R_PREDEFINED_REAL;
record R_PREDEFINED_STRING "predefined StringType" end R_PREDEFINED_STRING;
record R_PREDEFINED_BOOLEAN "predefined BooleanType" end R_PREDEFINED_BOOLEAN;
record R_PREDEFINED_ENUMERATION "predefined EnumType" end R_PREDEFINED_ENUMERATION;
// MetaModelica extensions
record R_METARECORD "Metamodelica extension"
Absyn.Path name; //Name of the uniontype
Integer index; //Index in the uniontype
end R_METARECORD; /* added by x07simbj */
record R_UNIONTYPE "Metamodelica extension"
end R_UNIONTYPE; /* added by simbj */
end Restriction;
public
uniontype Mod "- Modifications"
record MOD
Boolean finalPrefix "final" ;
Absyn.Each eachPrefix;
list<SubMod> subModLst;
Option<tuple<Absyn.Exp,Boolean>> absynExpOption "The binding expression of a modification
has an expression and a Boolean delayElaboration which is true if elaboration(type checking)
should be delayed. This can for instance be used when having A a(x = a.y) where a.y can not be
type checked -before- a is instantiated, which is the current design in instantiation process.";
end MOD;
record REDECL
Boolean finalPrefix "final" ;
list<Element> elementLst "elements" ;
end REDECL;
record NOMOD end NOMOD;
end Mod;
public
uniontype SubMod "Modifications are represented in an more structured way than in
the `Absyn\' module. Modifications using qualified names
(such as in `x.y = z\') are normalized (to `x(y = z)\'). And a
special case when arrays are subscripted in a modification.
"
record NAMEMOD
Ident ident;
Mod A "A named component" ;
end NAMEMOD;
record IDXMOD
list<Subscript> subscriptLst;
Mod an "An array element" ;
end IDXMOD;
end SubMod;
public
type Program = list<Class> "- Programs
As in the AST, a program is simply a list of class definitions." ;
public
uniontype Class "- Classes"
record CLASS "the simplified SCode class"
Ident name "the name of the class" ;
Boolean partialPrefix "the partial prefix" ;
Boolean encapsulatedPrefix "the encapsulated prefix" ;
Restriction restriction "the restriction of the class" ;
ClassDef classDef "the class specification" ;
Absyn.Info info "the class information";
end CLASS;
end Class;
public
uniontype Enum "Enum, which is a name in an enumeration and an optional Comment."
record ENUM
Ident literal;
Option<Comment> comment;
end ENUM;
end Enum;
public
uniontype ClassDef
"The major difference between these types and their Absyn
counterparts is that the PARTS constructor contains separate
lists for elements, equations and algorithms.
SCode.PARTS contains elements of a class definition. For instance,
model A
extends B;
C c;
end A;
Here PARTS contains two elements ('extends B' and 'C c')
SCode.DERIVED is used for short class definitions, i.e:
class A = B(modifiers);
SCode.CLASS_EXTENDS is used for extended class definition, i.e:
class extends A (modifier)
new elements;
end A;"
record PARTS "a class made of parts"
list<Element> elementLst "the list of elements";
list<Equation> normalEquationLst "the list of equations";
list<Equation> initialEquationLst "the list of initial equations";
list<AlgorithmSection> normalAlgorithmLst "the list of algorithms";
list<AlgorithmSection> initialAlgorithmLst "the list of initial algorithms";
Option<Absyn.ExternalDecl> externalDecl "used by external functions" ;
list<Annotation> annotationLst "the list of annotations found in between class elements, equations and algorithms";
Option<Comment> comment "the class comment";
end PARTS;
record CLASS_EXTENDS "an extended class definition plus the additional parts"
Ident baseClassName "the name of the base class we have to extend";
Mod modifications "the modifications that need to be applied to the base class";
list<Element> elementLst "the list of elements";
list<Equation> normalEquationLst "the list of equations";
list<Equation> initialEquationLst "the list of initial equations";
list<AlgorithmSection> normalAlgorithmLst "the list of algorithms";
list<AlgorithmSection> initialAlgorithmLst "the list of initial algorithms";
list<Annotation> annotationLst "the list of annotations found in between class elements, equations and algorithms";
Option<Comment> comment "the class comment";
end CLASS_EXTENDS;
record DERIVED "a derived class"
Absyn.TypeSpec typeSpec "typeSpec: type specification" ;
Mod modifications;
Absyn.ElementAttributes attributes;
Option<Comment> comment "the translated comment from the Absyn";
end DERIVED;
record ENUMERATION "an enumeration"
list<Enum> enumLst "if the list is empty it means :, the supertype of all enumerations";
Option<Comment> comment "the translated comment from the Absyn";
end ENUMERATION;
record OVERLOAD "an overloaded function"
list<Absyn.Path> pathLst;
Option<Comment> comment "the translated comment from the Absyn";
end OVERLOAD;
record PDER "the partial derivative"
Absyn.Path functionPath "function name" ;
list<Ident> derivedVariables "derived variables" ;
Option<Comment> comment "the Absyn comment";
end PDER;
end ClassDef;
// stefan
public
uniontype Comment
record COMMENT
Option<Annotation> annotation_;
Option<String> comment;
end COMMENT;
record CLASS_COMMENT
list<Annotation> annotations;
Option<Comment> comment;
end CLASS_COMMENT;
end Comment;
// stefan
public
uniontype Annotation
record ANNOTATION
Mod modification;
end ANNOTATION;
end Annotation;
public
uniontype Equation "- Equations"
record EQUATION "an equation"
EEquation eEquation "an equation";
end EQUATION;
end Equation;
public
uniontype EEquation
"These represent equations and are almost identical to their Absyn versions.
In EQ_IF the elseif branches are represented as normal else branches with
a single if statement in them."
record EQ_IF
list<Absyn.Exp> condition "conditional" ;
list<list<EEquation>> thenBranch "the true (then) branch" ;
list<EEquation> elseBranch "the false (else) branch" ;
Option<Comment> comment;
Absyn.Info info;
end EQ_IF;
record EQ_EQUALS "the equality equation"
Absyn.Exp expLeft "the expression on the left side of the operator";
Absyn.Exp expRight "the expression on the right side of the operator";
Option<Comment> comment;
Absyn.Info info;
end EQ_EQUALS;
record EQ_CONNECT "the connect equation"
Absyn.ComponentRef crefLeft "the connector/component reference on the left side";
Absyn.ComponentRef crefRight "the connector/component reference on the right side";
Option<Comment> comment;
Absyn.Info info;
end EQ_CONNECT;
record EQ_FOR "the for equation"
Ident index "the index name";
Absyn.Exp range "the range of the index";
list<EEquation> eEquationLst "the equation list";
Option<Comment> comment;
Absyn.Info info;
end EQ_FOR;
record EQ_WHEN "the when equation"
Absyn.Exp condition "the when condition";
list<EEquation> eEquationLst "the equation list";
list<tuple<Absyn.Exp, list<EEquation>>> tplAbsynExpEEquationLstLst "the elsewhen expression and equation list";
Option<Comment> comment;
Absyn.Info info;
end EQ_WHEN;
record EQ_ASSERT "the assert equation"
Absyn.Exp condition "the assert condition";
Absyn.Exp message "the assert message";
Option<Comment> comment;
Absyn.Info info;
end EQ_ASSERT;
record EQ_TERMINATE "the terminate equation"
Absyn.Exp message "the terminate message";
Option<Comment> comment;
Absyn.Info info;
end EQ_TERMINATE;
record EQ_REINIT "a reinit equation"
Absyn.ComponentRef cref "the variable to initialize";
Absyn.Exp expReinit "the new value" ;
Option<Comment> comment;
Absyn.Info info;
end EQ_REINIT;
record EQ_NORETCALL "function calls without return value"
Absyn.ComponentRef functionName "the function nanme";
Absyn.FunctionArgs functionArgs "the function arguments";
Option<Comment> comment;
Absyn.Info info;
end EQ_NORETCALL;
end EEquation;
public uniontype AlgorithmSection "- Algorithms
The Absyn module uses the terminology from the
grammar, where algorithm means an algorithmic
statement. But here, an Algorithm means a whole
algorithm section."
record ALGORITHM "the algorithm section"
list<Statement> statements "the algorithm statements" ;
end ALGORITHM;
end AlgorithmSection;
public uniontype Statement "The Statement type describes one algorithm statement in an algorithm section."
record ALG_ASSIGN
Absyn.Exp assignComponent "assignComponent" ;
Absyn.Exp value "value" ;
Option<Comment> comment;
Absyn.Info info;
end ALG_ASSIGN;
record ALG_IF
Absyn.Exp boolExpr;
list<Statement> trueBranch;
list<tuple<Absyn.Exp, list<Statement>>> elseIfBranch;
list<Statement> elseBranch;
Option<Comment> comment;
Absyn.Info info;
end ALG_IF;
record ALG_FOR
Absyn.ForIterators iterators;
list<Statement> forBody "forBody" ;
Option<Comment> comment;
Absyn.Info info;
end ALG_FOR;
record ALG_WHILE
Absyn.Exp boolExpr "boolExpr" ;
list<Statement> whileBody "whileBody" ;
Option<Comment> comment;
Absyn.Info info;
end ALG_WHILE;
record ALG_WHEN_A
list<tuple<Absyn.Exp, list<Statement>>> branches;
Option<Comment> comment;
Absyn.Info info;
end ALG_WHEN_A;
record ALG_NORETCALL
Absyn.ComponentRef functionCall "functionCall" ;
Absyn.FunctionArgs functionArgs "functionArgs; general fcalls without return value" ;
Option<Comment> comment;
Absyn.Info info;
end ALG_NORETCALL;
record ALG_RETURN
Option<Comment> comment;
Absyn.Info info;
end ALG_RETURN;
record ALG_BREAK
Option<Comment> comment;
Absyn.Info info;
end ALG_BREAK;
// Part of MetaModelica extension. KS
record ALG_TRY
list<Statement> tryBody;
Option<Comment> comment;
Absyn.Info info;
end ALG_TRY;
record ALG_CATCH
list<Statement> catchBody;
Option<Comment> comment;
Absyn.Info info;
end ALG_CATCH;
record ALG_THROW
Option<Comment> comment;
Absyn.Info info;
end ALG_THROW;
record ALG_MATCHCASES
Absyn.MatchType matchType;
list<Absyn.Exp> inputExps;
list<Absyn.Exp> switchCases;
Option<Comment> comment;
Absyn.Info info;
end ALG_MATCHCASES;
record ALG_GOTO
String labelName;
Option<Comment> comment;
Absyn.Info info;
end ALG_GOTO;
record ALG_LABEL
String labelName;
Option<Comment> comment;
Absyn.Info info;
end ALG_LABEL;
record ALG_FAILURE
list<Statement> stmts;
Option<Comment> comment;
Absyn.Info info;
end ALG_FAILURE;
//-------------------------------
end Statement;
public
uniontype Element "- Elements
There are four types of elements in a declaration, represented by the constructors:
EXTENDS (for extends clauses),
CLASSDEF (for local class definitions)
COMPONENT (for local variables). and
IMPORT (for import clauses)
The baseclass name is initially NONE() in the translation,
and if an element is inherited from a base class it is
filled in during the instantiation process."
record EXTENDS "the extends element"
Path baseClassPath "the extends path";
Mod modifications "the modifications applied to the base class";
Option<Annotation> annotation_;
end EXTENDS;
record CLASSDEF "a local class definition"
Ident name "the name of the local class" ;
Boolean finalPrefix "final prefix" ;
Boolean replaceablePrefix "replaceable prefix" ;
Class classDef "the class definition" ;
Option<Absyn.ConstrainClass> cc;
end CLASSDEF;
record IMPORT "an import element"
Absyn.Import imp "the import definition";
end IMPORT;
record COMPONENT "a component"
Ident component "the component name" ;
Absyn.InnerOuter innerOuter "the inner/outer/innerouter prefix";
Boolean finalPrefix "the final prefix" ;
Boolean replaceablePrefix "the replaceable prefix" ;
Boolean protectedPrefix "the protected prefix" ;
Attributes attributes "the component attributes";
Absyn.TypeSpec typeSpec "the type specification" ;
Mod modifications "the modifications to be applied to the component";
Option<Comment> comment "this if for extraction of comments and annotations from Absyn";
Option<Absyn.Exp> condition "the conditional declaration of a component";
Option<Absyn.Info> info "this is for line and column numbers, also file name.";
Option<Absyn.ConstrainClass> cc "The constraining class for the component";
end COMPONENT;
record DEFINEUNIT "a unit defintion has a name and the two optional parameters exp, and weight"
Ident name;
Option<String> exp;
Option<Real> weight;
end DEFINEUNIT;
end Element;
public
uniontype Attributes "- Attributes"
record ATTR "the attributes of the component"
Absyn.ArrayDim arrayDims "the array dimensions of the component";
Boolean flowPrefix "the flow prefix" ;
Boolean streamPrefix "the stream prefix" ;
Accessibility accesibility "the accesibility of the component: RW (read/write), RO (read only), WO (write only)" ;
Variability variability " the variability: parameter, discrete, variable, constant" ;
Absyn.Direction direction "the direction: input, output or bidirectional" ;
end ATTR;
end Attributes;
public
uniontype Variability "the variability of a component"
record VAR "a variable" end VAR;
record DISCRETE "a discrete variable" end DISCRETE;
record PARAM "a parameter" end PARAM;
record CONST "a constant" end CONST;
end Variability;
public
uniontype Accessibility "These are attributes that apply to a declared component."
record RW "read/write" end RW;
record RO "read-only" end RO;
record WO "write-only (not used)" end WO;
end Accessibility;
public /* adrpo: previously present in Inst.mo */
uniontype Initial "the initial attribute of an algorithm or equation
Intial is used as argument to instantiation-function for
specifying if equations or algorithms are initial or not."
record INITIAL "an initial equation or algorithm" end INITIAL;
record NON_INITIAL "a normal equation or algorithm" end NON_INITIAL;
end Initial;
// .......... functionality .........
protected import Util;
protected import Dump;
protected import ModUtil;
protected import Print;
protected import Error;
protected function elseWhenEquationStr
"@author: adrpo
Return the elsewhen parts as a string."
input list<tuple<Absyn.Exp, list<EEquation>>> tplAbsynExpEEquationLstLst;
output String str;
algorithm
str := matchcontinue(tplAbsynExpEEquationLstLst)
local
Absyn.Exp exp;
list<EEquation> eqn_lst;
list<tuple<Absyn.Exp, list<EEquation>>> rest;
String s1, s2, s3, res;
list<String> str_lst;
case ({}) then "";
case ((exp,eqn_lst)::rest)
equation
s1 = Dump.printExpStr(exp);
str_lst = Util.listMap(eqn_lst, equationStr);
s2 = Util.stringDelimitList(str_lst, "\n");
s3 = elseWhenEquationStr(tplAbsynExpEEquationLstLst);
res = stringAppendList({"\nelsewhen ",s1," then\n",s2,"\n", s3});
then
res;
end matchcontinue;
end elseWhenEquationStr;
public function equationStr
"function: equationStr
author: PA
Return the equation as a string."
input EEquation inEEquation;
output String outString;
algorithm
outString := matchcontinue (inEEquation)
local
String s1,s2,s3,s4,res,id;
list<String> tb_strs,fb_strs,str_lst;
Absyn.Exp e1,e2,exp;
list<Absyn.Exp> ifexp;
list<EEquation> ttb,fb,eqn_lst;
list<list<EEquation>> tb;
Absyn.ComponentRef cr1,cr2,cr;
Absyn.FunctionArgs fargs;
list<tuple<Absyn.Exp, list<EEquation>>> tplAbsynExpEEquationLstLst;
case (EQ_IF(condition = e1::ifexp,thenBranch = ttb::tb,elseBranch = fb))
equation
s1 = Dump.printExpStr(e1);
tb_strs = Util.listMap(ttb, equationStr);
fb_strs = Util.listMap(fb, equationStr);
s2 = Util.stringDelimitList(tb_strs, "\n");
s3 = Util.stringDelimitList(fb_strs, "\n");
s4 = elseIfEquationStr(ifexp,tb);
res = stringAppendList({"if ",s1," then ",s2,s4,"else ",s3,"end if;"});
then
res;
case (EQ_EQUALS(expLeft = e1,expRight = e2))
equation
s1 = Dump.printExpStr(e1);
s2 = Dump.printExpStr(e2);
res = stringAppendList({s1," = ",s2,";"});
then
res;
case (EQ_CONNECT(crefLeft = cr1,crefRight = cr2))
equation
s1 = Dump.printComponentRefStr(cr1);
s2 = Dump.printComponentRefStr(cr2);
res = stringAppendList({"connect(",s1,", ",s2,");"});
then
res;
case (EQ_FOR(index = id,range = exp,eEquationLst = eqn_lst))
equation
s1 = Dump.printExpStr(exp);
str_lst = Util.listMap(eqn_lst, equationStr);
s2 = Util.stringDelimitList(str_lst, "\n");
res = stringAppendList({"for ",id," in ",s1," loop\n",s2,"\nend for;"});
then
res;
case (EQ_WHEN(condition=exp, eEquationLst=eqn_lst, tplAbsynExpEEquationLstLst=tplAbsynExpEEquationLstLst))
equation
s1 = Dump.printExpStr(exp);
str_lst = Util.listMap(eqn_lst, equationStr);
s2 = Util.stringDelimitList(str_lst, "\n");
s3 = elseWhenEquationStr(tplAbsynExpEEquationLstLst);
res = stringAppendList({"when ",s1," then\n",s2,s3,"\nend when;"});
then
res;
case (EQ_ASSERT(condition = e1,message = e2))
equation
s1 = Dump.printExpStr(e1);
s2 = Dump.printExpStr(e2);
res = stringAppendList({"assert(",s1,", ",s2,");"});
then
res;
case (EQ_REINIT(cref = cr,expReinit = e1))
equation
s1 = Dump.printComponentRefStr(cr);
s2 = Dump.printExpStr(e1);
res = stringAppendList({"reinit(",s1,", ",s2,");"});
then
res;
case(EQ_NORETCALL(functionName = cr, functionArgs = fargs))
equation
s1 = Dump.printComponentRefStr(cr);
s2 = Dump.printFunctionArgsStr(fargs);
res = s1 +& "(" +& s2 +& ");";
then res;
end matchcontinue;
end equationStr;
protected function prettyPrintOptModifier "
Author BZ, 2008-07
Pretty print SCode.Mod
"
input Option<Absyn.Modification> oam;
input String comp;
output String str;
algorithm str := matchcontinue(oam,comp)
local
Absyn.Modification m;
case(NONE(),_) then "";
case(SOME(m),comp)
equation
str = prettyPrintModifier(m,comp);
then
str;
end matchcontinue;
end prettyPrintOptModifier;
protected function prettyPrintModifier "
Author BZ, 2008-07
Helper function for prettyPrintOptModifier
"
input Absyn.Modification oam;
input String comp;
output String str;
algorithm str := matchcontinue(oam,comp)
local
Absyn.Modification m;
Absyn.Exp exp;
list<Absyn.ElementArg> laea;
Absyn.ElementArg aea;
case(Absyn.CLASSMOD(_,SOME(exp)),comp)
equation
str = comp +& " = " +&Dump.printExpStr(exp);
then
str;
case(Absyn.CLASSMOD((laea as aea::{}),NONE()),comp)
equation
str = comp +& "(" +&prettyPrintElementModifier(aea) +&")";
then
str;
case(Absyn.CLASSMOD((laea as _::{}),NONE()),comp)
equation
str = comp +& "({" +& Util.stringDelimitList(Util.listMap(laea,prettyPrintElementModifier),", ") +& "})";
then
str;
end matchcontinue;
end prettyPrintModifier;
protected function prettyPrintElementModifier "
Author BZ, 2008-07
Helper function for prettyPrintOptModifier
TODO: implement type of new redeclare component
"
input Absyn.ElementArg aea;
output String str;
algorithm str := matchcontinue(aea)
local
Option<Absyn.Modification> oam;
String compName;
Absyn.ElementSpec spec;
Absyn.ComponentRef cr;
case(Absyn.MODIFICATION(modification = oam,componentRef=cr))
equation
compName = Absyn.printComponentRefStr(cr);
then prettyPrintOptModifier(oam,compName);
case(Absyn.REDECLARATION(elementSpec=spec))
equation
compName = Absyn.elementSpecName(spec);
then
"Redeclaration of (" +& compName +& ")";
end matchcontinue;
end prettyPrintElementModifier;
public function stripSubmod
"function: stripSubmod
author: PA
Removes all submodifiers from the Mod."
input Mod inMod;
output Mod outMod;
algorithm
outMod := matchcontinue (inMod)
local
Boolean f;
Absyn.Each each_;
list<SubMod> subs;
Option<tuple<Absyn.Exp,Boolean>> e;
Mod m;
case (MOD(finalPrefix = f,eachPrefix = each_,subModLst = subs,absynExpOption = e)) then MOD(f,each_,{},e);
case (m) then m;
end matchcontinue;
end stripSubmod;
public function getElementNamed
"function: getElementNamed
Return the Element with the name given as first argument from the Class."
input Ident inIdent;
input Class inClass;
output Element outElement;
algorithm
outElement := matchcontinue (inIdent,inClass)
local
Element elt;
String id;
list<Element> elts;
case (id,CLASS(classDef = PARTS(elementLst = elts)))
equation
elt = getElementNamedFromElts(id, elts);
then
elt;
/* adrpo: handle also the case model extends X then X; */
case (id,CLASS(classDef = CLASS_EXTENDS(elementLst = elts)))
equation
elt = getElementNamedFromElts(id, elts);
then
elt;
end matchcontinue;
end getElementNamed;
protected function getElementNamedFromElts
"function: getElementNamedFromElts
Helper function to getElementNamed."
input Ident inIdent;
input list<Element> inElementLst;
output Element outElement;
algorithm
outElement := matchcontinue (inIdent,inElementLst)
local
Element elt,comp,cdef;
String id2,id1;
list<Element> xs;
case (id2,((comp as COMPONENT(component = id1)) :: _))
equation
true = stringEq(id1, id2);
then
comp;
case (id2,(COMPONENT(component = id1) :: xs))
equation
false = stringEq(id1, id2);
elt = getElementNamedFromElts(id2, xs);
then
elt;
case (id2,(CLASSDEF(name = id1) :: xs))
equation
false = stringEq(id1, id2);
elt = getElementNamedFromElts(id2, xs);
then
elt;
case (id2,(EXTENDS(baseClassPath = _) :: xs))
equation
elt = getElementNamedFromElts(id2, xs);
then
elt;
case (id2,((cdef as CLASSDEF(name = id1)) :: _))
equation
true = stringEq(id1, id2);
then
cdef;
// Try next.
case (id2, _:: xs)
equation
elt = getElementNamedFromElts(id2, xs);
then
elt;
end matchcontinue;
end getElementNamedFromElts;
public function printMod
"function: printMod
This function prints a modification.
The code is excluded from the report for brevity."
input Mod m;
String s;
algorithm
s := printModStr(m);
Print.printBuf(s);
end printMod;
public function printModStr
"function: printModStr
Prints Mod to a string."
input Mod inMod;
output String outString;
algorithm
outString:=
matchcontinue (inMod)
local
String finalPrefixstr,str,res,each_str,subs_str,ass_str;
list<String> strs;
Boolean b,finalPrefix;
list<Element> elist;
Absyn.Each each_;
list<SubMod> subs;
Option<tuple<Absyn.Exp,Boolean>> ass;
case (NOMOD()) then "";
case REDECL(finalPrefix = b,elementLst = elist)
equation
Print.printBuf("redeclare(");
finalPrefixstr = Util.if_(b, "final", "");
strs = Util.listMap(elist, printElementStr);
str = Util.stringDelimitList(strs, ",");
res = stringAppendList({"redeclare(",finalPrefixstr,str,")"});
then
res;
case MOD(finalPrefix = finalPrefix,eachPrefix = each_,subModLst = subs,absynExpOption = ass)
equation
finalPrefixstr = Util.if_(finalPrefix, "final", "");
each_str = Dump.unparseEachStr(each_);
subs_str = printSubs1Str(subs);
ass_str = printEqmodStr(ass);
res = stringAppendList({finalPrefixstr,each_str,subs_str,ass_str});
then
res;
case _
equation
Print.printBuf("#-- Inst.printModStr failed\n");
then
fail();
end matchcontinue;
end printModStr;
public function restrString
"function: restrString
Prints Restriction to a string."
input Restriction inRestriction;
output String outString;
algorithm
outString:=
matchcontinue (inRestriction)
case R_CLASS() then "CLASS";
case R_OPTIMIZATION() then "OPTIMIZATION";
case R_MODEL() then "MODEL";
case R_RECORD() then "RECORD";
case R_BLOCK() then "BLOCK";
case R_CONNECTOR(false) then "CONNECTOR";
case R_CONNECTOR(true) then "EXPANDABLE_CONNECTOR";
case R_OPERATOR(false) then "OPERATOR";
case R_OPERATOR(true) then "OPERATOR_FUNCTION";
case R_TYPE() then "TYPE";
case R_PACKAGE() then "PACKAGE";
case R_FUNCTION() then "FUNCTION";
case R_EXT_FUNCTION() then "EXTFUNCTION";
case R_ENUMERATION() then "ENUMERATION";
case R_METARECORD(_,_) then "METARECORD";
case R_UNIONTYPE() then "UNIONTYPE";
// predefined types
case R_PREDEFINED_INTEGER() then "PREDEFINED_INT";
case R_PREDEFINED_REAL() then "PREDEFINED_REAL";
case R_PREDEFINED_STRING() then "PREDEFINED_STRING";
case R_PREDEFINED_BOOLEAN() then "PREDEFINED_BOOL";
case R_PREDEFINED_ENUMERATION() then "PREDEFINED_ENUM";
end matchcontinue;
end restrString;
public function printRestr
"function: printRestr
Prints Restriction to the Print buffer."
input Restriction restr;
String str;
algorithm
str := restrString(restr);
Print.printBuf(str);
end printRestr;
protected function printFinal
"function: printFinal
Prints \"final\" to the Print buffer."
input Boolean inBoolean;
algorithm
_ := matchcontinue (inBoolean)
case false then ();
case true
equation
Print.printBuf(" final ");
then
();
end matchcontinue;
end printFinal;
protected function printSubsStr
"function: printSubsStr
Prints a SubMod list to a string."
input list<SubMod> inSubModLst;
output String outString;
algorithm
outString := matchcontinue (inSubModLst)
local
String s,res,n,mod_str,str,sub_str;
Mod mod;
list<SubMod> subs;
list<Subscript> ss;
case {} then "";
case {NAMEMOD(ident = n,A = mod)}
equation
s = printModStr(mod);
res = n +& " " +& s;
then
res;
case (NAMEMOD(ident = n,A = mod) :: subs)
equation
mod_str = printModStr(mod);
str = printSubsStr(subs);
res = stringAppendList({n, " ", mod_str, ", ", str});
then
res;
case {IDXMOD(subscriptLst = ss,an = mod)}
equation
str = Dump.printSubscriptsStr(ss);
mod_str = printModStr(mod);
res = stringAppend(str, mod_str);
then
res;
case (IDXMOD(subscriptLst = ss,an = mod) :: subs)
equation
str = Dump.printSubscriptsStr(ss);
mod_str = printModStr(mod);
sub_str = printSubsStr(subs);
res = stringAppendList({str,mod_str,", ",sub_str});
then
res;
end matchcontinue;
end printSubsStr;
public function printSubs1Str
"function: printSubs1Str
Helper function to printSubsStr."
input list<SubMod> inSubModLst;
output String outString;
algorithm
outString:=
matchcontinue (inSubModLst)
local
String s,res;
list<SubMod> l;
case {} then "";
case l
equation
s = printSubsStr(l);
res = stringAppendList({"(",s,")"});
then
res;
end matchcontinue;
end printSubs1Str;
protected function printEqmodStr
"function: printEqmodStr
Helper function to printModStr."
input Option<tuple<Absyn.Exp,Boolean>> inAbsynExpOption;