MicroModelicaCCompiler  4.5.3
ast_types.hpp
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  This file is part of QSS Solver.
4 
5  QSS Solver is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  QSS Solver is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QSS Solver. If not, see <http://www.gnu.org/licenses/>.
17 
18  ******************************************************************************/
19 
20 #ifndef AST_TYPES_H_
21 #define AST_TYPES_H_
22 
23 #include <iostream>
24 #include <list>
25 #include <set>
26 #include <string>
27 
28 #include "../util/macros.hpp"
29 
30 #define MAKE_SPACE \
31  for (int __i = 0; __i < block; __i++) ret << " ";
32 #define BEGIN_BLOCK block += 2;
33 #define END_BLOCK block -= 2;
34 #define current_element(it) (*it)
35 #define foreach(it, list) for (it = list->begin(); it != list->end(); it++)
36 #define foreachReverse(it, list) for (it = list->rbegin(); it != list->rend(); it++)
37 
38 extern int block;
39 class MCC_Parser;
40 
41 using namespace std;
42 
43 typedef std::set<string> PreSet_;
44 typedef PreSet_ *PreSet;
45 typedef bool AST_Boolean;
46 typedef string *AST_String;
47 typedef int AST_Integer;
48 typedef double AST_Real;
49 typedef string AST_Type;
50 typedef int AST_TypePrefix;
51 typedef int AST_ClassPrefix;
52 
53 DEFINE_TYPE(AST_Node);
54 DEFINE_TYPE(AST_Argument);
55 DEFINE_TYPE(AST_Argument_Modification);
56 DEFINE_TYPE(AST_Argument_Redeclaration);
57 DEFINE_TYPE(AST_Class);
58 DEFINE_TYPE(AST_Comment);
59 DEFINE_TYPE(AST_Element_Component);
60 DEFINE_TYPE(AST_Composition);
61 DEFINE_TYPE(AST_CompositionElement);
62 DEFINE_TYPE(AST_CompositionEqsAlgs);
63 DEFINE_TYPE(AST_Declaration);
64 DEFINE_TYPE(AST_Element);
65 DEFINE_TYPE(AST_Element_Component);
66 DEFINE_TYPE(AST_Element_ClassWrapper);
67 DEFINE_TYPE(AST_Equation);
68 DEFINE_TYPE(AST_Equation_Call);
69 DEFINE_TYPE(AST_Equation_Connect);
70 DEFINE_TYPE(AST_Equation_Else);
71 DEFINE_TYPE(AST_Equation_Equality);
72 DEFINE_TYPE(AST_Equation_For);
73 DEFINE_TYPE(AST_Equation_If);
74 DEFINE_TYPE(AST_Equation_When);
75 DEFINE_TYPE(AST_Expression);
76 DEFINE_TYPE(AST_Expression_BinOp);
77 DEFINE_TYPE(AST_Expression_Boolean);
78 DEFINE_TYPE(AST_Expression_BooleanNot);
79 DEFINE_TYPE(AST_Expression_Brace);
80 DEFINE_TYPE(AST_Expression_Call);
81 DEFINE_TYPE(AST_Expression_CallArgs);
82 DEFINE_TYPE(AST_Expression_Colon);
83 DEFINE_TYPE(AST_Expression_ComponentReference);
84 DEFINE_TYPE(AST_Expression_Derivative);
85 DEFINE_TYPE(AST_Expression_End);
86 DEFINE_TYPE(AST_Expression_If);
87 DEFINE_TYPE(AST_Expression_If_ElseIf);
88 DEFINE_TYPE(AST_Expression_Integer);
89 DEFINE_TYPE(AST_Expression_NamedArgument);
90 DEFINE_TYPE(AST_Expression_Null);
91 DEFINE_TYPE(AST_Expression_Output);
92 DEFINE_TYPE(AST_Expression_Range);
93 DEFINE_TYPE(AST_Expression_Real);
94 DEFINE_TYPE(AST_Expression_String);
95 DEFINE_TYPE(AST_Expression_UMinus);
96 DEFINE_TYPE(AST_Expression_ArrayIndex);
97 DEFINE_TYPE(AST_Expression_Bracket);
98 DEFINE_TYPE(AST_External_Function_Call);
99 DEFINE_TYPE(AST_Element_ExtendsClause);
100 DEFINE_TYPE(AST_Element_ImportClause);
101 DEFINE_TYPE(AST_ForIndex);
102 DEFINE_TYPE(AST_ImportClause);
103 DEFINE_TYPE(AST_Modification);
104 DEFINE_TYPE(AST_Modification_Assign);
105 DEFINE_TYPE(AST_Modification_Class);
106 DEFINE_TYPE(AST_Modification_Equal);
107 DEFINE_TYPE(AST_ShortClassExp);
108 DEFINE_TYPE(AST_Statement);
109 DEFINE_TYPE(AST_Statement_Break);
110 DEFINE_TYPE(AST_Statement_Else);
111 DEFINE_TYPE(AST_Statement_Return);
112 DEFINE_TYPE(AST_Statement_When);
113 DEFINE_TYPE(AST_Statement_While);
114 DEFINE_TYPE(AST_Statement_For);
115 DEFINE_TYPE(AST_Statement_If);
116 DEFINE_TYPE(AST_Statement_Assign);
117 DEFINE_TYPE(AST_Statement_OutputAssigment);
118 DEFINE_TYPE(AST_StoredDefinition);
119 
120 DEFINE_LIST(AST_Argument);
121 DEFINE_LIST(AST_Class);
122 DEFINE_LIST(AST_Element_Component);
123 DEFINE_LIST(AST_CompositionElement);
124 DEFINE_LIST(AST_Declaration);
125 DEFINE_LIST(AST_Element);
126 DEFINE_LIST(AST_Equation);
127 DEFINE_LIST(AST_Equation_Else);
128 DEFINE_LIST(AST_Expression);
129 DEFINE_LIST(AST_ExpressionList);
130 DEFINE_LIST(AST_Expression_ComponentReference);
131 DEFINE_LIST(AST_ForIndex);
132 DEFINE_LIST(AST_Statement);
133 DEFINE_LIST(AST_Statement_Else);
136 
137 enum BinOpType {
157 };
158 
160 
162 
187 };
188 
190 
192 
194  TP_INPUT = (1 << 1),
195  TP_OUTPUT = (1 << 2),
196  TP_DISCRETE = (1 << 3),
197  TP_PARAMETER = (1 << 4),
198  TP_FLOW = (1 << 5),
199  TP_STREAM = (1 << 6),
200  TP_CONSTANT = (1 << 7),
201  TP_FOR = (1 << 8),
202  TP_EQ = (1 << 9),
203  TP_LOCAL = (1 << 10)
204 };
205 
207 
211 
213  CP_PARTIAL = (1 << 1),
214  CP_CLASS = (1 << 2),
215  CP_MODEL = (1 << 3),
216  CP_BLOCK = (1 << 4),
217  CP_RECORD = (1 << 5),
218  CP_CONNECTOR = (1 << 6),
219  CP_TYPE = (1 << 7),
220  CP_OPERATOR = (1 << 8),
221  CP_EXPANDABLE = (1 << 9),
222  CP_PURE = (1 << 10),
223  CP_IMPURE = (1 << 11),
224  CP_PACKAGE = (1 << 12),
225  CP_FUNCTION = (1 << 13)
226 };
227 
228 template <typename T1>
229 T1 AST_ListElement(list<T1> *l, int n)
230 {
231  typename std::list<T1>::iterator it;
232  it = l->begin();
233  for (int j = 1; j < n; j++) {
234  it++;
235  }
236  return *it;
237 }
238 
239 template <typename T1>
240 list<T1> *AST_ListAppend(list<T1> *l, T1 e)
241 {
242  l->push_back(e);
243  return l;
244 }
245 
246 template <typename T1>
247 list<T1> *AST_ListPrepend(list<T1> *l, T1 e)
248 {
249  l->push_front(e);
250  return l;
251 }
252 
253 template <typename T1>
254 list<T1> *AST_ListRemove(list<T1> *l, T1 e)
255 {
256  l->remove(e);
257  return l;
258 }
259 
260 template <typename T1>
261 void AST_ListInsert(list<T1> *l1, typename std::list<T1>::iterator it, T1 e)
262 {
263  typename std::list<T1>::iterator insert_it = it;
264  if (insert_it != l1->end()) {
265  insert_it++;
266  }
267  l1->insert(insert_it, 1, e);
268 }
269 
270 template <typename T1>
271 T1 AST_ListFirst(list<T1> *l)
272 {
273  return l->front();
274 }
275 
276 template <typename T1>
277 list<T1> *AST_ListConcat(list<T1> *l1, list<T1> *l2)
278 {
279  l1->insert(l1->end(), l2->begin(), l2->end());
280  return l1;
281 }
282 
283 template <typename T1>
284 list<T1> *AST_ListCopy(list<T1> *l1)
285 {
286  list<T1> *ls = new list<T1>;
287  ls->assign(l1->begin(), l1->end());
288  return ls;
289 }
290 
291 template <typename T1>
292 int AST_Length(list<T1> *l1)
293 {
294  return l1->size();
295 }
296 
297 template <typename T1>
298 T1 AST_ListAt(list<T1> *l1, int i)
299 {
300  typename list<T1>::iterator it = l1->begin();
301  for (int c = 0; c < i; c++) {
302  it++;
303  }
304  if (it != l1->end()) {
305  return *it;
306  }
307  return T1();
308 }
309 
310 template <typename T1>
311 list<T1> *newAST_SimpleList(T1 t)
312 {
313  list<T1> *ls = new list<T1>;
314  ls->push_back(t);
315  return ls;
316 }
317 
318 template <typename T1>
319 void AST_ListPrint(list<T1> *l1, ostream &ret, string sec_name = "", string separator = " ", string opener = "", string closer = "",
320  bool block = false)
321 {
322  typename list<T1>::iterator it;
323  int size = l1->size(), i = 1;
324  if (size) {
325  ret << sec_name;
326  if (block) BEGIN_BLOCK;
327  ret << opener;
328  foreach (it, l1) {
329  ret << current_element(it);
330  ret << (i < size ? separator : "");
331  i++;
332  }
333  ret << closer;
334  if (block) END_BLOCK;
335  }
336 }
337 
338 #endif /* AST_TYPES_H_ */
PreSet
PreSet_ * PreSet
Definition: ast_types.hpp:44
block
int block
Definition: ast_builder.cpp:41
EXPINTEGER
@ EXPINTEGER
Definition: ast_types.hpp:180
EXPOUTPUT
@ EXPOUTPUT
Definition: ast_types.hpp:182
AST_Type
string AST_Type
Definition: ast_types.hpp:49
DEFINE_LIST
DEFINE_LIST(AST_Argument)
BINOPEXP
@ BINOPEXP
Definition: ast_types.hpp:154
EQWHEN
@ EQWHEN
Definition: ast_types.hpp:161
ModificationType
ModificationType
Definition: ast_types.hpp:189
MODASSIGN
@ MODASSIGN
Definition: ast_types.hpp:189
BINOPAND
@ BINOPAND
Definition: ast_types.hpp:139
EXPCOMPREF
@ EXPCOMPREF
Definition: ast_types.hpp:165
BINOPCOMPEQ
@ BINOPCOMPEQ
Definition: ast_types.hpp:145
DEFINE_TYPE
DEFINE_TYPE(AST_Node)
CP_BLOCK
@ CP_BLOCK
Definition: ast_types.hpp:216
AST_ListPrint
void AST_ListPrint(list< T1 > *l1, ostream &ret, string sec_name="", string separator=" ", string opener="", string closer="", bool block=false)
Definition: ast_types.hpp:319
AST_ListConcat
list< T1 > * AST_ListConcat(list< T1 > *l1, list< T1 > *l2)
Definition: ast_types.hpp:277
AST_ListPrepend
list< T1 > * AST_ListPrepend(list< T1 > *l, T1 e)
Definition: ast_types.hpp:247
END_BLOCK
#define END_BLOCK
Definition: ast_types.hpp:33
TP_EQ
@ TP_EQ
Definition: ast_types.hpp:202
EXPUMINUS
@ EXPUMINUS
Definition: ast_types.hpp:176
AST_Integer
int AST_Integer
Definition: ast_types.hpp:47
STWHILE
@ STWHILE
Definition: ast_types.hpp:191
EXPELSEIF
@ EXPELSEIF
Definition: ast_types.hpp:174
BINOPELEXP
@ BINOPELEXP
Definition: ast_types.hpp:155
ClassPrefix
ClassPrefix
Definition: ast_types.hpp:212
TP_FLOW
@ TP_FLOW
Definition: ast_types.hpp:198
EXPCALLARG
@ EXPCALLARG
Definition: ast_types.hpp:171
EQCONNECT
@ EQCONNECT
Definition: ast_types.hpp:161
AST_ListRemove
list< T1 > * AST_ListRemove(list< T1 > *l, T1 e)
Definition: ast_types.hpp:254
ELCLASS
@ ELCLASS
Definition: ast_types.hpp:159
EXPARRAYINDEX
@ EXPARRAYINDEX
Definition: ast_types.hpp:185
BINOPGREATER
@ BINOPGREATER
Definition: ast_types.hpp:142
ELNONE
@ ELNONE
Definition: ast_types.hpp:159
TP_LOCAL
@ TP_LOCAL
Definition: ast_types.hpp:203
AST_Real
double AST_Real
Definition: ast_types.hpp:48
EQIF
@ EQIF
Definition: ast_types.hpp:161
BINOPELMULT
@ BINOPELMULT
Definition: ast_types.hpp:153
TP_CONSTANT
@ TP_CONSTANT
Definition: ast_types.hpp:200
BINOPELADD
@ BINOPELADD
Definition: ast_types.hpp:147
ExpressionType
ExpressionType
Definition: ast_types.hpp:163
EXPIF
@ EXPIF
Definition: ast_types.hpp:170
BINOPLOWER
@ BINOPLOWER
Definition: ast_types.hpp:140
CP_IMPURE
@ CP_IMPURE
Definition: ast_types.hpp:223
EXPRANGE
@ EXPRANGE
Definition: ast_types.hpp:183
EQFOR
@ EQFOR
Definition: ast_types.hpp:161
AST_ListElement
T1 AST_ListElement(list< T1 > *l, int n)
Definition: ast_types.hpp:229
AST_String
string * AST_String
Definition: ast_types.hpp:46
BINOPMULT
@ BINOPMULT
Definition: ast_types.hpp:152
TypePrefix
TypePrefix
Definition: ast_types.hpp:193
STBREAK
@ STBREAK
Definition: ast_types.hpp:191
BEGIN_BLOCK
#define BEGIN_BLOCK
Definition: ast_types.hpp:32
EXTENDS
@ EXTENDS
Definition: ast_types.hpp:159
BINOPELDIV
@ BINOPELDIV
Definition: ast_types.hpp:151
AST_ClassPrefix
int AST_ClassPrefix
Definition: ast_types.hpp:51
STFOR
@ STFOR
Definition: ast_types.hpp:191
EXPDERIVATIVE
@ EXPDERIVATIVE
Definition: ast_types.hpp:167
TP_PARAMETER
@ TP_PARAMETER
Definition: ast_types.hpp:197
EXPBOOLEAN
@ EXPBOOLEAN
Definition: ast_types.hpp:177
ArgumentType
ArgumentType
Definition: ast_types.hpp:206
AST_ListCopy
list< T1 > * AST_ListCopy(list< T1 > *l1)
Definition: ast_types.hpp:284
BINOPSUB
@ BINOPSUB
Definition: ast_types.hpp:148
AST_ListInsert
void AST_ListInsert(list< T1 > *l1, typename std::list< T1 >::iterator it, T1 e)
Definition: ast_types.hpp:261
AST_Boolean
bool AST_Boolean
Definition: ast_types.hpp:45
BINOPNULL
@ BINOPNULL
Definition: ast_types.hpp:156
AST_Length
int AST_Length(list< T1 > *l1)
Definition: ast_types.hpp:292
AST_TypePrefix
int AST_TypePrefix
Definition: ast_types.hpp:50
TP_FOR
@ TP_FOR
Definition: ast_types.hpp:201
AST_ListAppend
list< T1 > * AST_ListAppend(list< T1 > *l, T1 e)
Definition: ast_types.hpp:240
BINOPOR
@ BINOPOR
Definition: ast_types.hpp:138
BINOPGREATEREQ
@ BINOPGREATEREQ
Definition: ast_types.hpp:143
AST_TypePrefixAdd
AST_TypePrefix AST_TypePrefixAdd(AST_TypePrefix, AST_TypePrefix)
Definition: ast_builder.cpp:263
STNONE
@ STNONE
Definition: ast_types.hpp:191
EXPCALL
@ EXPCALL
Definition: ast_types.hpp:173
EXPNULL
@ EXPNULL
Definition: ast_types.hpp:168
STASSIGN
@ STASSIGN
Definition: ast_types.hpp:191
STOUTASSING
@ STOUTASSING
Definition: ast_types.hpp:191
MODEQUAL
@ MODEQUAL
Definition: ast_types.hpp:189
AST_ListFirst
T1 AST_ListFirst(list< T1 > *l)
Definition: ast_types.hpp:271
CP_TYPE
@ CP_TYPE
Definition: ast_types.hpp:219
TP_OUTPUT
@ TP_OUTPUT
Definition: ast_types.hpp:195
AR_MODIFICATION
@ AR_MODIFICATION
Definition: ast_types.hpp:206
EQNONE
@ EQNONE
Definition: ast_types.hpp:161
BINOPDIV
@ BINOPDIV
Definition: ast_types.hpp:150
EQCALL
@ EQCALL
Definition: ast_types.hpp:161
STIF
@ STIF
Definition: ast_types.hpp:191
AR_REDECLARATION
@ AR_REDECLARATION
Definition: ast_types.hpp:206
EXPBOOLEANNOT
@ EXPBOOLEANNOT
Definition: ast_types.hpp:181
CP_PURE
@ CP_PURE
Definition: ast_types.hpp:222
ElementType
ElementType
Definition: ast_types.hpp:159
MODNONE
@ MODNONE
Definition: ast_types.hpp:189
newAST_SimpleList
list< T1 > * newAST_SimpleList(T1 t)
Definition: ast_types.hpp:311
AST_ListAt
T1 AST_ListAt(list< T1 > *l1, int i)
Definition: ast_types.hpp:298
EXPNONE
@ EXPNONE
Definition: ast_types.hpp:164
EXPBRACKET
@ EXPBRACKET
Definition: ast_types.hpp:186
TP_STREAM
@ TP_STREAM
Definition: ast_types.hpp:199
STRETURN
@ STRETURN
Definition: ast_types.hpp:191
StatementType
StatementType
Definition: ast_types.hpp:191
BINOPCOMPNE
@ BINOPCOMPNE
Definition: ast_types.hpp:144
CP_OPERATOR
@ CP_OPERATOR
Definition: ast_types.hpp:220
EXPNAMEDARGUMENT
@ EXPNAMEDARGUMENT
Definition: ast_types.hpp:184
CP_CONNECTOR
@ CP_CONNECTOR
Definition: ast_types.hpp:218
PreSet_
std::set< string > PreSet_
Definition: ast_types.hpp:43
MODCLASS
@ MODCLASS
Definition: ast_types.hpp:189
EXPBINOP
@ EXPBINOP
Definition: ast_types.hpp:166
CP_RECORD
@ CP_RECORD
Definition: ast_types.hpp:217
CP_PACKAGE
@ CP_PACKAGE
Definition: ast_types.hpp:224
TP_DISCRETE
@ TP_DISCRETE
Definition: ast_types.hpp:196
BINOPLOWEREQ
@ BINOPLOWEREQ
Definition: ast_types.hpp:141
CP_EXPANDABLE
@ CP_EXPANDABLE
Definition: ast_types.hpp:221
BINOPADD
@ BINOPADD
Definition: ast_types.hpp:146
EQEQUALITY
@ EQEQUALITY
Definition: ast_types.hpp:161
CP_PARTIAL
@ CP_PARTIAL
Definition: ast_types.hpp:213
CP_FUNCTION
@ CP_FUNCTION
Definition: ast_types.hpp:225
BINOPELSUB
@ BINOPELSUB
Definition: ast_types.hpp:149
EquationType
EquationType
Definition: ast_types.hpp:161
BinOpType
BinOpType
Definition: ast_types.hpp:137
STWHEN
@ STWHEN
Definition: ast_types.hpp:191
EXPCOLON
@ EXPCOLON
Definition: ast_types.hpp:175
EXPREAL
@ EXPREAL
Definition: ast_types.hpp:179
CP_CLASS
@ CP_CLASS
Definition: ast_types.hpp:214
newAST_TypePrefix
AST_TypePrefix newAST_TypePrefix()
Definition: ast_builder.cpp:259
EXPBRACE
@ EXPBRACE
Definition: ast_types.hpp:172
CP_MODEL
@ CP_MODEL
Definition: ast_types.hpp:215
COMPONENT
@ COMPONENT
Definition: ast_types.hpp:159
IMPORT
@ IMPORT
Definition: ast_types.hpp:159
current_element
#define current_element(it)
Definition: ast_types.hpp:34
EXPEND
@ EXPEND
Definition: ast_types.hpp:169
EXPSTRING
@ EXPSTRING
Definition: ast_types.hpp:178
TP_INPUT
@ TP_INPUT
Definition: ast_types.hpp:194