/
Absyn.mo
1119 lines (919 loc) · 32.4 KB
/
Absyn.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 Absyn
"
file: mo
package: Absyn
description: Abstract syntax
This file defines the abstract syntax for Modelica in MetaModelica Compiler (MMC). It
contains uniontypes for constructing the abstract syntax tree
(AST).
* Abstract Syntax Tree (Close to Modelica)
- Complete Modelica 2.2, 3.1, 3.2, MetaModelica
- Including annotations and comments
* Primary AST for e.g. the Interactive module
- Model editor related representations (must use annotations)
mo\'s constructors are primarily used by (Parser/Modelica.g).
When the AST has been built, it is normally used by SCodeUtil.mo in order to
build the SCode (See SCodeUtil.mo). It is also possile to send the AST do
the unparser (Dump.mo) in order to print it.
For details regarding the abstract syntax tree, check out the grammar in
the Modelica language specification.
The following are the types and uniontypes that are used for the AST:"
public
type Ident = String "An identifier, for example a variable name" ;
public uniontype ForIterator
"For Iterator - these are used in:
* for loops where the expression part can be NONE() and then the range
is taken from an array variable that the iterator is used to index,
see 3.3.3.2 Several Iterators from Modelica Specification.
* in array iterators where the expression should always be SOME(Exp),
see 3.4.4.2 Array constructor with iterators from Specification
* the guard is a MetaModelica extension; it's a Boolean expression that
filters out items in the range."
record ITERATOR
String name;
Option<Exp> guardExp;
Option<Exp> range;
end ITERATOR;
end ForIterator;
public type ForIterators = list<ForIterator>
"For Iterators -
these are used in:
* for loops where the expression part can be NONE() and then the range
is taken from an array variable that the iterator is used to index,
see 3.3.3.2 Several Iterators from Modelica Specification.
* in array iterators where the expression should always be SOME(Exp),
see 3.4.4.2 Array constructor with iterators from Specification";
public
uniontype Program
"- Programs, the top level construct
A program is simply a list of class definitions declared at top
level in the source file, combined with a within statement that
indicates the hieractical position of the program."
record PROGRAM "PROGRAM, the top level construct"
list<Class> classes "List of classes" ;
Within within_ "Within clause" ;
end PROGRAM;
end Program;
public
uniontype Within "Within Clauses"
record WITHIN "the within clause"
Path path "the path for within";
end WITHIN;
record TOP end TOP;
end Within;
type Info = SourceInfo;
public
uniontype Class
"A class definition consists of a name, a flag to indicate
if this class is declared as partial, the declared class restriction,
and the body of the declaration."
record CLASS
Ident name;
Boolean partialPrefix "true if partial" ;
Boolean finalPrefix "true if final" ;
Boolean encapsulatedPrefix "true if encapsulated" ;
Restriction restriction "Restriction" ;
ClassDef body;
Info info "Information: FileName is the class is defined in +
isReadOnly bool + start line no + start column no +
end line no + end column no";
end CLASS;
end Class;
public
uniontype ClassDef
"The ClassDef type contains thClasse definition part of a class declaration.
The definition is either explicit, with a list of parts
(public, protected, equation, and algorithm), or it is a definition
derived from another class or an enumeration type.
For a derived type, the type contains the name of the derived class
and an optional array dimension and a list of modifications.
"
record PARTS
list<String> typeVars "class A<B,C> ... has type variables B,C";
list<NamedArg> classAttrs "optimization Op (objective=...) end Op. A list arguments attributing a
class declaration. Currently used only for Optimica extensions";
list<ClassPart> classParts;
list<Annotation> ann "Modelica2 allowed multiple class-annotations";
Option<String> comment;
end PARTS;
record DERIVED
TypeSpec typeSpec "typeSpec specification includes array dimensions" ;
ElementAttributes attributes;
list<ElementArg> arguments;
Option<Comment> comment;
end DERIVED;
record ENUMERATION
EnumDef enumLiterals;
Option<Comment> comment;
end ENUMERATION;
record OVERLOAD
list<Path> functionNames;
Option<Comment> comment;
end OVERLOAD;
record CLASS_EXTENDS
Ident baseClassName "name of class to extend" ;
list<ElementArg> modifications "modifications to be applied to the base class";
Option<String> comment "comment";
list<ClassPart> parts "class parts";
list<Annotation> ann;
end CLASS_EXTENDS;
record PDER
Path functionName;
list<Ident> vars "derived variables" ;
Option<Comment> comment "comment";
end PDER;
end ClassDef;
public
type ArrayDim = list<Subscript> "Component attributes are
properties of components which are applied by type prefixes.
As an example, declaring a component as `input Real x;\' will
give the attributes `ATTR({},false,VAR,INPUT)\'.
Components in Modelica can be scalar or arrays with one or more
dimensions. This type is used to indicate the dimensionality
of a component or a type definition.
- Array dimensions" ;
public
uniontype TypeSpec "ModExtension: new MetaModelica type specification!"
record TPATH
Path path;
Option<ArrayDim> arrayDim;
end TPATH;
record TCOMPLEX
Path path;
list<TypeSpec> typeSpecs;
Option<ArrayDim> arrayDim;
end TCOMPLEX;
end TypeSpec;
public
uniontype EnumDef
"The definition of an enumeration is either a list of literals
or a colon, \':\', which defines a supertype of all enumerations"
record ENUMLITERALS
list<EnumLiteral> enumLiterals;
end ENUMLITERALS;
record ENUM_COLON end ENUM_COLON;
end EnumDef;
public
uniontype EnumLiteral "EnumLiteral, which is a name in an enumeration and an optional
Comment."
record ENUMLITERAL
Ident literal;
Option<Comment> comment;
end ENUMLITERAL;
end EnumLiteral;
public
uniontype ClassPart "A class definition contains several parts. There are public and
protected component declarations, type definitions and `extends\'
clauses, collectively called elements. There are also equation
sections and algorithm sections. The EXTERNAL part is used only by functions
which can be declared as external C or FORTRAN functions."
record PUBLIC
list<ElementItem> contents ;
end PUBLIC;
record PROTECTED
list<ElementItem> contents;
end PROTECTED;
record CONSTRAINTS
list<Exp> contents;
end CONSTRAINTS;
record EQUATIONS
list<EquationItem> contents;
end EQUATIONS;
record INITIALEQUATIONS
list<EquationItem> contents;
end INITIALEQUATIONS;
record ALGORITHMS
list<AlgorithmItem> contents;
end ALGORITHMS;
record INITIALALGORITHMS
list<AlgorithmItem> contents;
end INITIALALGORITHMS;
record EXTERNAL
ExternalDecl externalDecl "externalDecl" ;
Option<Annotation> annotation_ "annotation" ;
end EXTERNAL;
end ClassPart;
public
uniontype ElementItem "An element item is either an element or an annotation"
record ELEMENTITEM
Element element;
end ELEMENTITEM;
record LEXER_COMMENT
String comment;
end LEXER_COMMENT;
end ElementItem;
public
uniontype Element "Elements
The basic element type in Modelica"
record ELEMENT
Boolean finalPrefix;
Option<RedeclareKeywords> redeclareKeywords "replaceable, redeclare" ;
InnerOuter innerOuter "inner/outer" ;
ElementSpec specification "Actual element specification" ;
Info info "File name the class is defined in + line no + column no" ;
Option<ConstrainClass> constrainClass "only valid for classdef and component" ;
end ELEMENT;
record DEFINEUNIT
Ident name;
list<NamedArg> args;
Info info;
end DEFINEUNIT;
record TEXT
Option<Ident> optName "optName : optional name of text, e.g. model with syntax error.
We need the name to be able to browse it..." ;
String string;
Info info;
end TEXT;
end Element;
public
uniontype ConstrainClass "Constraining type, must be extends"
record CONSTRAINCLASS
ElementSpec elementSpec "must be extends" ;
Option<Comment> comment "comment" ;
end CONSTRAINCLASS;
end ConstrainClass;
public
uniontype ElementSpec "An element is something that occurs in a public or protected
section in a class definition. There is one constructor in the
`ElementSpec\' type for each possible element type. There are
class definitions (`CLASSDEF\'), `extends\' clauses (`EXTENDS\')
and component declarations (`COMPONENTS\').
As an example, if the element `extends TwoPin;\' appears
in the source, it is represented in the AST as
`EXTENDS(IDENT(\"TwoPin\"),{})\'.
"
record CLASSDEF
Boolean replaceable_ "replaceable" ;
Class class_ "class" ;
end CLASSDEF;
record EXTENDS
Path path "path" ;
list<ElementArg> elementArg "elementArg" ;
Option<Annotation> annotationOpt "optional annotation";
end EXTENDS;
record IMPORT
Import import_ "import" ;
Option<Comment> comment "comment" ;
Info info;
end IMPORT;
record COMPONENTS
ElementAttributes attributes "attributes" ;
TypeSpec typeSpec "typeSpec" ;
list<ComponentItem> components "components" ;
end COMPONENTS;
end ElementSpec;
public
uniontype InnerOuter
"One of the keyword inner and outer CAN be given to reference an
inner or outer element. Thus there are three disjoint possibilities."
record INNER "an inner prefix" end INNER;
record OUTER "an outer prefix" end OUTER;
record INNER_OUTER "an inner outer prefix" end INNER_OUTER;
record NOT_INNER_OUTER "no inner outer prefix" end NOT_INNER_OUTER;
end InnerOuter;
public
uniontype Import "Import statements, different kinds"
// A named import is a import statement to a variable ex;
// NAMED_IMPORT("SI",QUALIFIED("Modelica",IDENT("SIunits")));
record NAMED_IMPORT
Ident name "name" ;
Path path "path" ;
end NAMED_IMPORT;
record QUAL_IMPORT
Path path "path" ;
end QUAL_IMPORT;
record UNQUAL_IMPORT
Path path "path" ;
end UNQUAL_IMPORT;
record GROUP_IMPORT
Path prefix;
list<GroupImport> groups;
end GROUP_IMPORT;
end Import;
public
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;
public
type ComponentCondition = Exp "A componentItem can have a condition that must be fulfilled if
the component should be instantiated.
" ;
public
uniontype ComponentItem "Collection of component and an optional comment"
record COMPONENTITEM
Component component "component" ;
Option<ComponentCondition> condition "condition" ;
Option<Comment> comment "comment" ;
end COMPONENTITEM;
end ComponentItem;
public
uniontype Component "Some kind of Modelica entity (object or variable)"
record COMPONENT
Ident name "name" ;
ArrayDim arrayDim "Array dimensions, if any" ;
Option<Modification> modification "Optional modification" ;
end COMPONENT;
end Component;
public
uniontype EquationItem "Several component declarations can be grouped together in one
`ElementSpec\' by writing them on the same line in the source.
This type contains the information specific to one component."
record EQUATIONITEM
Equation equation_ "equation" ;
Option<Comment> comment "comment" ;
Info info "line number" ;
end EQUATIONITEM;
record EQUATIONITEMCOMMENT
String comment;
end EQUATIONITEMCOMMENT;
end EquationItem;
public
uniontype AlgorithmItem "Info specific for an algorithm item."
record ALGORITHMITEM
Algorithm algorithm_ "algorithm" ;
Option<Comment> comment "comment" ;
Info info "line number" ;
end ALGORITHMITEM;
record ALGORITHMITEMCOMMENT "A comment from the lexer"
String comment;
end ALGORITHMITEMCOMMENT;
end AlgorithmItem;
public
uniontype Equation "Information on one (kind) of equation, different constructors for different
kinds of equations"
record EQ_IF
Exp ifExp "Conditional expression" ;
list<EquationItem> equationTrueItems "true branch" ;
list<tuple<Exp, list<EquationItem>>> elseIfBranches "elseIfBranches" ;
list<EquationItem> equationElseItems "equationElseItems Standard 2-side eqn" ;
end EQ_IF;
record EQ_EQUALS
Exp leftSide "leftSide" ;
Exp rightSide "rightSide Connect stmt" ;
end EQ_EQUALS;
record EQ_PDE
Exp leftSide "leftSide" ;
Exp rightSide "rightSide Connect stmt" ;
ComponentRef domain "domain for PDEs" ;
end EQ_PDE;
record EQ_CONNECT
ComponentRef connector1 "connector1" ;
ComponentRef connector2 "connector2" ;
end EQ_CONNECT;
record EQ_FOR
ForIterators iterators;
list<EquationItem> forEquations "forEquations" ;
end EQ_FOR;
record EQ_WHEN_E
Exp whenExp "whenExp" ;
list<EquationItem> whenEquations "whenEquations" ;
list<tuple<Exp, list<EquationItem>>> elseWhenEquations "elseWhenEquations" ;
end EQ_WHEN_E;
record EQ_NORETCALL
ComponentRef functionName "functionName" ;
FunctionArgs functionArgs "functionArgs; fcalls without return value" ;
end EQ_NORETCALL;
record EQ_FAILURE
EquationItem equ;
end EQ_FAILURE;
end Equation;
public
uniontype Algorithm "The Algorithm type describes one algorithm statement in an
algorithm section. It does not describe a whole algorithm. The
reason this type is named like this is that the name of the
grammar rule for algorithm statements is `algorithm\'."
record ALG_ASSIGN
Exp assignComponent "assignComponent" ;
Exp value "value" ;
end ALG_ASSIGN;
record ALG_IF
Exp ifExp "ifExp" ;
list<AlgorithmItem> trueBranch "trueBranch" ;
list<tuple<Exp, list<AlgorithmItem>>> elseIfAlgorithmBranch "elseIfAlgorithmBranch" ;
list<AlgorithmItem> elseBranch "elseBranch" ;
end ALG_IF;
record ALG_FOR
ForIterators iterators;
list<AlgorithmItem> forBody "forBody" ;
end ALG_FOR;
record ALG_PARFOR
ForIterators iterators;
list<AlgorithmItem> parforBody "parallel for loop Body" ;
end ALG_PARFOR;
record ALG_WHILE
Exp boolExpr "boolExpr" ;
list<AlgorithmItem> whileBody "whileBody" ;
end ALG_WHILE;
record ALG_WHEN_A
Exp boolExpr "boolExpr" ;
list<AlgorithmItem> whenBody "whenBody" ;
list<tuple<Exp, list<AlgorithmItem>>> elseWhenAlgorithmBranch "elseWhenAlgorithmBranch" ;
end ALG_WHEN_A;
record ALG_NORETCALL
ComponentRef functionCall "functionCall" ;
FunctionArgs functionArgs "functionArgs; general fcalls without return value" ;
end ALG_NORETCALL;
record ALG_RETURN
end ALG_RETURN;
record ALG_BREAK
end ALG_BREAK;
// MetaModelica extensions
record ALG_FAILURE
list<AlgorithmItem> equ;
end ALG_FAILURE;
record ALG_TRY
list<AlgorithmItem> body;
list<AlgorithmItem> elseBody;
end ALG_TRY;
record ALG_CONTINUE
end ALG_CONTINUE;
end Algorithm;
public
uniontype Modification "Modifications are described by the `Modification\' type. There
are two forms of modifications: redeclarations and component
modifications.
- Modifications"
record CLASSMOD
list<ElementArg> elementArgLst;
EqMod eqMod;
end CLASSMOD;
end Modification;
public
uniontype EqMod
record NOMOD
end NOMOD;
record EQMOD
Exp exp;
Info info;
end EQMOD;
end EqMod;
public
uniontype ElementArg "Wrapper for things that modify elements, modifications and redeclarations"
record MODIFICATION
Boolean finalPrefix "final prefix";
Each eachPrefix "each";
Path path;
Option<Modification> modification "modification";
Option<String> comment "comment";
Info info;
end MODIFICATION;
record REDECLARATION
Boolean finalPrefix "final prefix";
RedeclareKeywords redeclareKeywords "redeclare or replaceable ";
Each eachPrefix "each prefix";
ElementSpec elementSpec "elementSpec";
Option<ConstrainClass> constrainClass "class definition or declaration";
Info info "needed because ElementSpec does not contain this info; Element does";
end REDECLARATION;
end ElementArg;
public
uniontype RedeclareKeywords "The keywords redeclare and replacable can be given in three different kombinations, each one by themself or the both combined."
record REDECLARE end REDECLARE;
record REPLACEABLE end REPLACEABLE;
record REDECLARE_REPLACEABLE end REDECLARE_REPLACEABLE;
end RedeclareKeywords;
public
uniontype Each "The each keyword can be present in both MODIFICATION\'s and REDECLARATION\'s.
- Each attribute"
record EACH end EACH;
record NON_EACH end NON_EACH;
end Each;
public
uniontype ElementAttributes "Element attributes"
record ATTR
Boolean flowPrefix "flow";
Boolean streamPrefix "stream";
Parallelism parallelism "for OpenCL/CUDA parglobal, parlocal ...";
Variability variability "parameter, constant etc.";
Direction direction "input/output";
IsField isField "non-field / field";
ArrayDim arrayDim "array dimensions";
end ATTR;
end ElementAttributes;
public
uniontype IsField "Is field"
record NONFIELD "variable is not a field" end NONFIELD;
record FIELD "variable is a field" end FIELD;
end IsField;
public
uniontype Parallelism "Parallelism"
record PARGLOBAL "Global variables for CUDA and OpenCL" end PARGLOBAL;
record PARLOCAL "Shared for CUDA and local for OpenCL" end PARLOCAL;
record NON_PARALLEL "Non parallel/Normal variables" end NON_PARALLEL;
end Parallelism;
public
uniontype FlowStream
record FLOW end FLOW;
record STREAM end STREAM;
record NOT_FLOW_STREAM end NOT_FLOW_STREAM;
end FlowStream;
public
uniontype Variability "Variability"
record VAR end VAR;
record DISCRETE end DISCRETE;
record PARAM end PARAM;
record CONST end CONST;
end Variability;
public
uniontype Direction "Direction"
record INPUT "direction is input"
end INPUT;
record OUTPUT "direction is output"
end OUTPUT;
record BIDIR "direction is not specified, neither input nor output"
end BIDIR;
record INPUT_OUTPUT "direction is both input and output (OM extension; syntactic sugar for functions)"
end INPUT_OUTPUT;
end Direction;
public
uniontype Exp "The Exp uniontype is the container of a Modelica expression.
- Expressions"
record INTEGER
Integer value;
end INTEGER;
record REAL
String value "String representation of a Real, in order to unparse without changing the user's display preference";
end REAL;
record CREF
ComponentRef componentRef;
end CREF;
record STRING
String value;
end STRING;
record BOOL
Boolean value;
end BOOL;
record BINARY "Binary operations, e.g. a*b"
Exp exp1;
Operator op;
Exp exp2;
end BINARY;
record UNARY "Unary operations, e.g. -(x), +(x)"
Operator op "op" ;
Exp exp "exp - any arithmetic expression" ;
end UNARY;
record LBINARY
Exp exp1 "exp1" ;
Operator op "op" ;
Exp exp2 ;
end LBINARY;
record LUNARY "Logical unary operations: not"
Operator op "op" ;
Exp exp "exp - any logical or relation expression" ;
end LUNARY;
record RELATION
Exp exp1 "exp1" ;
Operator op "op" ;
Exp exp2 ;
end RELATION;
record IFEXP "If expressions"
Exp ifExp "ifExp" ;
Exp trueBranch "trueBranch" ;
Exp elseBranch "elseBranch" ;
list<tuple<Exp, Exp>> elseIfBranch "elseIfBranch Function calls" ;
end IFEXP;
record CALL
ComponentRef function_ "function" ;
FunctionArgs functionArgs ;
end CALL;
// stefan
record PARTEVALFUNCTION "Partially evaluated function"
ComponentRef function_ "function" ;
FunctionArgs functionArgs ;
end PARTEVALFUNCTION;
record ARRAY "Array construction using {, }, or array"
list<Exp> arrayExp ;
end ARRAY;
record MATRIX "Matrix construction using {, } "
list<list<Exp>> matrix ;
end MATRIX;
record RANGE "Range expressions, e.g. 1:10 or 1:0.5:10"
Exp start "start" ;
Option<Exp> step "step" ;
Exp stop "stop";
end RANGE;
record TUPLE " Tuples used in function calls returning several values"
list<Exp> expressions "comma-separated expressions" ;
end TUPLE;
record END "array access operator for last element, e.g. a{end}:=1;"
end END;
record CODE "Modelica AST Code constructors - OpenModelica extension"
CodeNode code;
end CODE;
// MetaModelica expressions follow below!
record AS "as operator"
Ident id " only an id " ;
Exp exp " expression to bind to the id ";
end AS;
record CONS "list cons or :: operator"
Exp head " head of the list ";
Exp rest " rest of the list ";
end CONS;
record MATCHEXP "matchcontinue expression"
MatchType matchTy " match or matchcontinue ";
Exp inputExp " match expression of ";
list<ElementItem> localDecls " local declarations ";
list<Case> cases " case list + else in the end ";
Option<String> comment " match expr comment_optional ";
end MATCHEXP;
// The following are only used internally in the compiler
record LIST "Part of MetaModelica extension"
list<Exp> exps;
end LIST;
record DOT "exp.index"
Exp exp;
Exp index;
end DOT;
end Exp;
uniontype Case "case in match or matchcontinue"
record CASE
Exp pattern " patterns to be matched ";
Option<Exp> patternGuard;
Info patternInfo "file information of the pattern";
list<ElementItem> localDecls " local decls ";
ClassPart classPart " equation or algorithm section ";
Exp result " result ";
Info resultInfo "file information of the result-exp";
Option<String> comment " comment after case like: case pattern string_comment ";
Info info "file information of the whole case";
end CASE;
record ELSE "else in match or matchcontinue"
list<ElementItem> localDecls " local decls ";
ClassPart classPart " equation or algorithm section ";
Exp result " result ";
Info resultInfo "file information of the result-exp";
Option<String> comment " comment after case like: case pattern string_comment ";
Info info "file information of the whole case";
end ELSE;
end Case;
uniontype MatchType
record MATCH end MATCH;
record MATCHCONTINUE end MATCHCONTINUE;
end MatchType;
uniontype CodeNode "The Code uniontype is used for Meta-programming. It originates from the $Code quoting mechanism. See paper in Modelica2003 conference"
record C_TYPENAME "Cannot be parsed; used by Static for API calls"
Path path;
end C_TYPENAME;
record C_VARIABLENAME "Cannot be parsed; used by Static for API calls"
ComponentRef componentRef;
end C_VARIABLENAME;
record C_CONSTRAINTSECTION
Boolean boolean;
list<EquationItem> equationItemLst;
end C_CONSTRAINTSECTION;
record C_EQUATIONSECTION
Boolean boolean;
list<EquationItem> equationItemLst;
end C_EQUATIONSECTION;
record C_ALGORITHMSECTION
Boolean boolean;
list<AlgorithmItem> algorithmItemLst;
end C_ALGORITHMSECTION;
record C_ELEMENT
Element element;
end C_ELEMENT;
record C_EXPRESSION
Exp exp;
end C_EXPRESSION;
record C_MODIFICATION
Modification modification;
end C_MODIFICATION;
end CodeNode;
uniontype FunctionArgs "The FunctionArgs uniontype consists of a list of positional arguments
followed by a list of named arguments (Modelica v2.0)"
record FUNCTIONARGS
list<Exp> args "args" ;
list<NamedArg> argNames "argNames" ;
end FUNCTIONARGS;
record FOR_ITER_FARG
Exp exp "iterator expression";
ReductionIterType iterType;
ForIterators iterators;
end FOR_ITER_FARG;
end FunctionArgs;
constant FunctionArgs emptyFunctionArgs = FUNCTIONARGS({},{});
uniontype ReductionIterType
record COMBINE "Reductions are by default calculated as all combinations of the iterators"
end COMBINE;
record THREAD "With this option, all iterators must have the same length"
end THREAD;
end ReductionIterType;
uniontype NamedArg "The NamedArg uniontype consist of an Identifier for the argument and an expression
giving the value of the argument"
record NAMEDARG
Ident argName "argName" ;
Exp argValue "argValue" ;
end NAMEDARG;
end NamedArg;
uniontype Operator "Expression operators"
/* arithmetic operators */
record ADD "addition" end ADD;
record SUB "subtraction" end SUB;
record MUL "multiplication" end MUL;
record DIV "division" end DIV;
record POW "power" end POW;
record UPLUS "unary plus" end UPLUS;
record UMINUS "unary minus" end UMINUS;
/* element-wise arithmetic operators */
record ADD_EW "element-wise addition" end ADD_EW;
record SUB_EW "element-wise subtraction" end SUB_EW;
record MUL_EW "element-wise multiplication" end MUL_EW;
record DIV_EW "element-wise division" end DIV_EW;
record POW_EW "element-wise power" end POW_EW;
record UPLUS_EW "element-wise unary minus" end UPLUS_EW;
record UMINUS_EW "element-wise unary plus" end UMINUS_EW;
/* logical operators */
record AND "logical and" end AND;
record OR "logical or" end OR;
record NOT "logical not" end NOT;
/* relational operators */
record LESS "less than" end LESS;
record LESSEQ "less than or equal" end LESSEQ;
record GREATER "greater than" end GREATER;
record GREATEREQ "greater than or equal" end GREATEREQ;
record EQUAL "relational equal" end EQUAL;
record NEQUAL "relational not equal" end NEQUAL;
end Operator;
uniontype Subscript "The Subscript uniontype is used both in array declarations and
component references. This might seem strange, but it is
inherited from the grammar. The NOSUB constructor means that
the dimension size is undefined when used in a declaration, and
when it is used in a component reference it means a slice of the
whole dimension.
- Subscripts"
record NOSUB "unknown array dimension" end NOSUB;
record SUBSCRIPT "dimension as an expression"
Exp subscript "subscript";
end SUBSCRIPT;
end Subscript;
uniontype ComponentRef "A component reference is the fully or partially qualified name of
a component. It is represented as a list of
identifier--subscript pairs.
- Component references and paths"
record CREF_FULLYQUALIFIED
ComponentRef componentRef;
end CREF_FULLYQUALIFIED;
record CREF_QUAL
Ident name "name" ;
list<Subscript> subscripts "subscripts" ;
ComponentRef componentRef "componentRef" ;
end CREF_QUAL;
record CREF_IDENT
Ident name "name" ;
list<Subscript> subscripts "subscripts" ;
end CREF_IDENT;
record WILD end WILD;
record ALLWILD end ALLWILD;
end ComponentRef;
uniontype Path "The type `Path\', on the other hand,
is used to store references to class names, or names inside
class definitions."
record QUALIFIED
Ident name "name" ;
Path path "path" ;
end QUALIFIED;
record IDENT
Ident name "name" ;
end IDENT;
record FULLYQUALIFIED "Used during instantiation for names that are fully qualified,
i.e. the names are looked up from top scope directly like for instance Modelica.SIunits.Voltage
Note: Not created during parsing, only during instantation to speedup/simplify lookup.