/
SCodeTV.mo
796 lines (666 loc) · 16.4 KB
/
SCodeTV.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
interface package SCodeTV
package builtin
function boolNot
input Boolean inBoolean;
output Boolean outNegatedBoolean;
end boolNot;
function intLt
input Integer x;
input Integer y;
output Boolean outResult;
end intLt;
end builtin;
package Absyn
type Ident = String;
uniontype ForIterator
record ITERATOR
String name;
Option<Exp> guardExp;
Option<Exp> range;
end ITERATOR;
end ForIterator;
type ForIterators = list<ForIterator>;
uniontype Exp
record INTEGER
Integer value;
end INTEGER;
record REAL
Real value;
end REAL;
record CREF
ComponentRef componentRef;
end CREF;
record STRING
String value;
end STRING;
record BOOL
Boolean value;
end BOOL;
record BINARY
Exp exp1;
Operator op;
Exp exp2;
end BINARY;
record UNARY
Operator op;
Exp exp;
end UNARY;
record LBINARY
Exp exp1;
Operator op;
Exp exp2;
end LBINARY;
record LUNARY
Operator op;
Exp exp;
end LUNARY;
record RELATION
Exp exp1;
Operator op;
Exp exp2;
end RELATION;
record IFEXP
Exp ifExp;
Exp trueBranch;
Exp elseBranch;
list<tuple<Exp, Exp>> elseIfBranch;
end IFEXP;
record CALL
ComponentRef function_;
FunctionArgs functionArgs ;
end CALL;
record PARTEVALFUNCTION
ComponentRef function_;
FunctionArgs functionArgs ;
end PARTEVALFUNCTION;
record ARRAY
list<Exp> arrayExp ;
end ARRAY;
record MATRIX
list<list<Exp>> matrix ;
end MATRIX;
record RANGE
Exp start;
Option<Exp> step;
Exp stop;
end RANGE;
record TUPLE
list<Exp> expressions;
end TUPLE;
record END
end END;
record CODE
CodeNode code;
end CODE;
record AS
Ident id;
Exp exp;
end AS;
record CONS
Exp head;
Exp rest;
end CONS;
record MATCHEXP
MatchType matchTy;
Exp inputExp;
list<ElementItem> localDecls;
list<Case> cases;
Option<String> comment;
end MATCHEXP;
record LIST
list<Exp> exps;
end LIST;
end Exp;
uniontype Case
record CASE
Exp pattern;
Info patternInfo;
list<ElementItem> localDecls;
list<EquationItem> equations;
Exp result;
Info resultInfo;
Option<String> comment;
Info info;
end CASE;
record ELSE
list<ElementItem> localDecls;
list<EquationItem> equations;
Exp result;
Info resultInfo;
Option<String> comment;
Info info;
end ELSE;
end Case;
uniontype MatchType
record MATCH end MATCH;
record MATCHCONTINUE end MATCHCONTINUE;
end MatchType;
uniontype Import
record NAMED_IMPORT
Ident name;
Path path;
end NAMED_IMPORT;
record QUAL_IMPORT
Path path;
end QUAL_IMPORT;
record UNQUAL_IMPORT
Path path;
end UNQUAL_IMPORT;
record GROUP_IMPORT
Path prefix;
list<GroupImport> groups;
end GROUP_IMPORT;
end Import;
uniontype GroupImport
record GROUP_IMPORT_NAME
String name;
end GROUP_IMPORT_NAME;
record GROUP_IMPORT_RENAME
String rename;
String name;
end GROUP_IMPORT_RENAME;
end GroupImport;
uniontype Operator
record ADD end ADD;
record SUB end SUB;
record MUL end MUL;
record DIV end DIV;
record POW end POW;
record UPLUS end UPLUS;
record UMINUS end UMINUS;
record ADD_EW end ADD_EW;
record SUB_EW end SUB_EW;
record MUL_EW end MUL_EW;
record DIV_EW end DIV_EW;
record POW_EW end POW_EW;
record UPLUS_EW end UPLUS_EW;
record UMINUS_EW end UMINUS_EW;
record AND end AND;
record OR end OR;
record NOT end NOT;
record LESS end LESS;
record LESSEQ end LESSEQ;
record GREATER end GREATER;
record GREATEREQ end GREATEREQ;
record EQUAL end EQUAL;
record NEQUAL end NEQUAL;
end Operator;
uniontype Subscript
record NOSUB end NOSUB;
record SUBSCRIPT
Exp subscript;
end SUBSCRIPT;
end Subscript;
type ArrayDim = list<Subscript>;
uniontype ComponentRef
record CREF_FULLYQUALIFIED
ComponentRef componentRef;
end CREF_FULLYQUALIFIED;
record CREF_QUAL
Ident name;
list<Subscript> subscripts;
ComponentRef componentRef;
end CREF_QUAL;
record CREF_IDENT
Ident name;
list<Subscript> subscripts;
end CREF_IDENT;
record WILD end WILD;
record ALLWILD end ALLWILD;
record CREF_INVALID
ComponentRef componentRef;
end CREF_INVALID;
end ComponentRef;
uniontype Path
record QUALIFIED
Ident name;
Path path;
end QUALIFIED;
record IDENT
Ident name;
end IDENT;
record FULLYQUALIFIED
Path path;
end FULLYQUALIFIED;
end Path;
uniontype FunctionArgs
record FUNCTIONARGS
list<Exp> args;
list<NamedArg> argNames;
end FUNCTIONARGS;
record FOR_ITER_FARG
Exp exp;
ForIterators iterators;
end FOR_ITER_FARG;
end FunctionArgs;
uniontype NamedArg
record NAMEDARG
Ident argName;
Exp argValue;
end NAMEDARG;
end NamedArg;
uniontype InnerOuter
record INNER end INNER;
record OUTER end OUTER;
record INNER_OUTER end INNER_OUTER;
record NOT_INNER_OUTER end NOT_INNER_OUTER;
end InnerOuter;
uniontype Direction
record INPUT end INPUT;
record OUTPUT end OUTPUT;
record BIDIR end BIDIR;
end Direction;
uniontype TypeSpec
record TPATH
Path path;
Option<ArrayDim> arrayDim;
end TPATH;
record TCOMPLEX
Path path;
list<TypeSpec> typeSpecs;
Option<ArrayDim> arrayDim;
end TCOMPLEX;
end TypeSpec;
end Absyn;
package Dump
function expPriority
input Absyn.Exp inExp;
output Integer outInteger;
end expPriority;
end Dump;
package SCode
type Ident = Absyn.Ident;
type Path = Absyn.Path;
type Subscript = Absyn.Subscript;
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
Boolean isExpandable;
end R_CONNECTOR;
record R_OPERATOR end R_OPERATOR;
record R_OPERATOR_FUNCTION end R_OPERATOR_FUNCTION;
record R_OPERATOR_RECORD end R_OPERATOR_RECORD;
record R_TYPE end R_TYPE;
record R_PACKAGE end R_PACKAGE;
record R_FUNCTION
FunctionRestriction functionRestriction;
end R_FUNCTION;
record R_EXT_FUNCTION end R_EXT_FUNCTION;
record R_ENUMERATION end R_ENUMERATION;
record R_PREDEFINED_INTEGER end R_PREDEFINED_INTEGER;
record R_PREDEFINED_REAL end R_PREDEFINED_REAL;
record R_PREDEFINED_STRING end R_PREDEFINED_STRING;
record R_PREDEFINED_BOOLEAN end R_PREDEFINED_BOOLEAN;
record R_PREDEFINED_ENUMERATION end R_PREDEFINED_ENUMERATION;
record R_METARECORD
Absyn.Path name;
Integer index;
end R_METARECORD;
record R_UNIONTYPE
end R_UNIONTYPE;
end Restriction;
uniontype FunctionRestriction
record FR_NORMAL_FUNCTION "a normal function" end FR_NORMAL_FUNCTION;
record FR_OPERATOR_FUNCTION "an operator function" end FR_OPERATOR_FUNCTION;
record FR_EXTERNAL_FUNCTION "an operator function" end FR_EXTERNAL_FUNCTION;
record FR_RECORD_CONSTRUCTOR "record constructor" end FR_RECORD_CONSTRUCTOR;
end FunctionRestriction;
uniontype Mod
record MOD
Final finalPrefix;
Each eachPrefix;
list<SubMod> subModLst;
Option<tuple<Absyn.Exp,Boolean>> binding;
end MOD;
record REDECL
Final finalPrefix;
Each eachPrefix;
Element element;
end REDECL;
record NOMOD end NOMOD;
end Mod;
uniontype SubMod
record NAMEMOD
Ident ident;
Mod A;
end NAMEMOD;
record IDXMOD
list<Subscript> subscriptLst;
Mod an;
end IDXMOD;
end SubMod;
type Program = list<Element>;
uniontype Enum
record ENUM
Ident literal;
Option<Comment> comment;
end ENUM;
end Enum;
uniontype ClassDef
record PARTS
list<Element> elementLst;
list<Equation> normalEquationLst;
list<Equation> initialEquationLst;
list<AlgorithmSection> normalAlgorithmLst;
list<AlgorithmSection> initialAlgorithmLst;
Option<ExternalDecl> externalDecl;
list<Annotation> annotationLst;
Option<Comment> comment;
end PARTS;
record CLASS_EXTENDS
Ident baseClassName;
Mod modifications;
ClassDef composition;
end CLASS_EXTENDS;
record DERIVED
Absyn.TypeSpec typeSpec;
Mod modifications;
Attributes attributes;
Option<Comment> comment;
end DERIVED;
record ENUMERATION
list<Enum> enumLst;
Option<Comment> comment;
end ENUMERATION;
record OVERLOAD
list<Absyn.Path> pathLst;
Option<Comment> comment;
end OVERLOAD;
record PDER
Absyn.Path functionPath;
list<Ident> derivedVariables;
Option<Comment> comment;
end PDER;
end ClassDef;
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;
uniontype Annotation
record ANNOTATION
Mod modification;
end ANNOTATION;
end Annotation;
uniontype ExternalDecl
record EXTERNALDECL
Option<Ident> funcName;
Option<String> lang;
Option<Absyn.ComponentRef> output_;
list<Absyn.Exp> args;
Option<Annotation> annotation_ ;
end EXTERNALDECL;
end ExternalDecl;
uniontype Equation
record EQUATION
EEquation eEquation;
end EQUATION;
end Equation;
uniontype EEquation
record EQ_IF
list<Absyn.Exp> condition;
list<list<EEquation>> thenBranch;
list<EEquation> elseBranch;
Option<Comment> comment;
Absyn.Info info;
end EQ_IF;
record EQ_EQUALS
Absyn.Exp expLeft;
Absyn.Exp expRight;
Option<Comment> comment;
Absyn.Info info;
end EQ_EQUALS;
record EQ_CONNECT
Absyn.ComponentRef crefLeft;
Absyn.ComponentRef crefRight;
Option<Comment> comment;
Absyn.Info info;
end EQ_CONNECT;
record EQ_FOR
Ident index;
Option<Absyn.Exp> range;
list<EEquation> eEquationLst;
Option<Comment> comment;
Absyn.Info info;
end EQ_FOR;
record EQ_WHEN
Absyn.Exp condition;
list<EEquation> eEquationLst;
list<tuple<Absyn.Exp, list<EEquation>>> elseBranches;
Option<Comment> comment;
Absyn.Info info;
end EQ_WHEN;
record EQ_ASSERT
Absyn.Exp condition;
Absyn.Exp message;
Option<Comment> comment;
Absyn.Info info;
end EQ_ASSERT;
record EQ_TERMINATE
Absyn.Exp message;
Option<Comment> comment;
Absyn.Info info;
end EQ_TERMINATE;
record EQ_REINIT
Absyn.ComponentRef cref;
Absyn.Exp expReinit;
Option<Comment> comment;
Absyn.Info info;
end EQ_REINIT;
record EQ_NORETCALL
Absyn.ComponentRef functionName;
Absyn.FunctionArgs functionArgs;
Option<Comment> comment;
Absyn.Info info;
end EQ_NORETCALL;
end EEquation;
uniontype AlgorithmSection
record ALGORITHM
list<Statement> statements;
end ALGORITHM;
end AlgorithmSection;
uniontype Statement
record ALG_ASSIGN
Absyn.Exp assignComponent;
Absyn.Exp 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
String index;
Option<Absyn.Exp> range;
list<Statement> forBody;
Option<Comment> comment;
Absyn.Info info;
end ALG_FOR;
record ALG_WHILE
Absyn.Exp boolExpr;
list<Statement> 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.Exp exp;
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;
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_FAILURE
list<Statement> stmts;
Option<Comment> comment;
Absyn.Info info;
end ALG_FAILURE;
end Statement;
uniontype Visibility
record PUBLIC end PUBLIC;
record PROTECTED end PROTECTED;
end Visibility;
uniontype Redeclare
record REDECLARE end REDECLARE;
record NOT_REDECLARE end NOT_REDECLARE;
end Redeclare;
uniontype ConstrainClass
record CONSTRAINCLASS
Absyn.Path constrainingClass;
Mod modifier;
Option<Comment> comment;
end CONSTRAINCLASS;
end ConstrainClass;
uniontype Replaceable
record REPLACEABLE
Option<ConstrainClass> cc;
end REPLACEABLE;
record NOT_REPLACEABLE end NOT_REPLACEABLE;
end Replaceable;
uniontype Final
record FINAL end FINAL;
record NOT_FINAL end NOT_FINAL;
end Final;
uniontype Each
record EACH end EACH;
record NOT_EACH end NOT_EACH;
end Each;
uniontype Encapsulated
record ENCAPSULATED end ENCAPSULATED;
record NOT_ENCAPSULATED end NOT_ENCAPSULATED;
end Encapsulated;
uniontype Partial
record PARTIAL end PARTIAL;
record NOT_PARTIAL end NOT_PARTIAL;
end Partial;
uniontype Stream
record STREAM end STREAM;
record NOT_STREAM end NOT_STREAM;
end Stream;
uniontype Flow
record FLOW end FLOW;
record NOT_FLOW end NOT_FLOW;
end Flow;
uniontype Prefixes
record PREFIXES
Visibility visibility;
Redeclare redeclarePrefix;
Final finalPrefix;
Absyn.InnerOuter innerOuter;
Replaceable replaceablePrefix;
end PREFIXES;
end Prefixes;
uniontype Element
record IMPORT
Absyn.Import imp;
Visibility visibility;
Absyn.Info info;
end IMPORT;
record EXTENDS
Path baseClassPath;
Visibility visibility;
Mod modifications;
Option<Annotation> ann;
Absyn.Info info;
end EXTENDS;
record CLASS
Ident name;
Prefixes prefixes;
Encapsulated encapsulatedPrefix;
Partial partialPrefix;
Restriction restriction;
ClassDef classDef;
Absyn.Info info;
end CLASS;
record COMPONENT
Ident name;
Prefixes prefixes;
Attributes attributes;
Absyn.TypeSpec typeSpec;
Mod modifications;
Option<Comment> comment;
Option<Absyn.Exp> condition;
Absyn.Info info;
end COMPONENT;
record DEFINEUNIT
Ident name;
Visibility visibility;
Option<String> exp;
Option<Real> weight;
end DEFINEUNIT;
end Element;
uniontype Attributes
record ATTR
Absyn.ArrayDim arrayDims;
Flow flowPrefix;
Parallelism parallelism;
Stream streamPrefix;
Variability variability;
Absyn.Direction direction;
end ATTR;
end Attributes;
uniontype Parallelism
record PARGLOBAL end PARGLOBAL;
record PARLOCAL end PARLOCAL;
record NON_PARALLEL end NON_PARALLEL;
end Parallelism;
uniontype Variability
record VAR end VAR;
record DISCRETE end DISCRETE;
record PARAM end PARAM;
record CONST end CONST;
end Variability;
uniontype Initial
record INITIAL end INITIAL;
record NON_INITIAL end NON_INITIAL;
end Initial;
end SCode;
package Tpl
function addTemplateError
input String inErrMsg;
end addTemplateError;
end Tpl;
package Config
function showAnnotations
output Boolean show;
end showAnnotations;
end Config;
end SCodeTV;