1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // ParseNode.h -- |
---|
8 | // |
---|
9 | // Author : Rodolfo G. Esteves |
---|
10 | // Created On : Sat May 16 13:28:16 2015 |
---|
11 | // Last Modified By : Rob Schluntz |
---|
12 | // Last Modified On : Thu Apr 14 15:37:52 2016 |
---|
13 | // Update Count : 205 |
---|
14 | // |
---|
15 | |
---|
16 | #ifndef PARSENODE_H |
---|
17 | #define PARSENODE_H |
---|
18 | |
---|
19 | #include <string> |
---|
20 | #include <list> |
---|
21 | #include <iterator> |
---|
22 | |
---|
23 | #include "Common/utility.h" |
---|
24 | #include "Parser/LinkageSpec.h" |
---|
25 | #include "SynTree/Type.h" |
---|
26 | //#include "SynTree/Declaration.h" |
---|
27 | #include "Common/UniqueName.h" |
---|
28 | |
---|
29 | class ExpressionNode; |
---|
30 | class CompositeExprNode; |
---|
31 | class CommaExprNode; |
---|
32 | class StatementNode; |
---|
33 | class CompoundStmtNode; |
---|
34 | class DeclarationNode; |
---|
35 | class InitializerNode; |
---|
36 | |
---|
37 | // Builder |
---|
38 | class ParseNode { |
---|
39 | public: |
---|
40 | ParseNode(); |
---|
41 | ParseNode( const std::string * ); |
---|
42 | ParseNode( const std::string & ); // for copy constructing subclasses |
---|
43 | virtual ~ParseNode(); |
---|
44 | |
---|
45 | ParseNode *get_link() const; |
---|
46 | ParseNode *get_last(); |
---|
47 | ParseNode *set_link( ParseNode * ); |
---|
48 | void set_next( ParseNode *newlink ) { next = newlink; } |
---|
49 | |
---|
50 | virtual ParseNode *clone() const { return 0; }; |
---|
51 | |
---|
52 | const std::string &get_name() const { return name; } |
---|
53 | void set_name( const std::string &newValue ) { name = newValue; } |
---|
54 | |
---|
55 | virtual void print( std::ostream &, int indent = 0 ) const; |
---|
56 | virtual void printList( std::ostream &, int indent = 0 ) const; |
---|
57 | |
---|
58 | ParseNode &operator,( ParseNode &); |
---|
59 | protected: |
---|
60 | std::string name; |
---|
61 | ParseNode *next; |
---|
62 | static int indent_by; |
---|
63 | }; |
---|
64 | |
---|
65 | ParseNode *mkList( ParseNode & ); |
---|
66 | |
---|
67 | class ExpressionNode : public ParseNode { |
---|
68 | public: |
---|
69 | ExpressionNode(); |
---|
70 | ExpressionNode( const std::string * ); |
---|
71 | ExpressionNode( const ExpressionNode &other ); |
---|
72 | virtual ~ExpressionNode() { delete argName; } // cannot delete argName because it might be referenced elsewhere |
---|
73 | |
---|
74 | virtual ExpressionNode *clone() const = 0; |
---|
75 | |
---|
76 | virtual CommaExprNode *add_to_list( ExpressionNode * ); |
---|
77 | |
---|
78 | ExpressionNode *get_argName() const { return argName; } |
---|
79 | ExpressionNode *set_argName( const std::string *aName ); |
---|
80 | ExpressionNode *set_argName( ExpressionNode *aDesignator ); |
---|
81 | |
---|
82 | virtual void print( std::ostream &, int indent = 0) const = 0; |
---|
83 | virtual void printOneLine( std::ostream &, int indent = 0) const = 0; |
---|
84 | |
---|
85 | virtual Expression *build() const = 0; |
---|
86 | protected: |
---|
87 | void printDesignation ( std::ostream &, int indent = 0) const; |
---|
88 | private: |
---|
89 | ExpressionNode *argName; |
---|
90 | }; |
---|
91 | |
---|
92 | // NullExprNode is used in tuples as a place-holder where a tuple component is omitted e.g., [ 2, , 3 ] |
---|
93 | class NullExprNode : public ExpressionNode { |
---|
94 | public: |
---|
95 | NullExprNode(); |
---|
96 | |
---|
97 | virtual NullExprNode *clone() const; |
---|
98 | |
---|
99 | virtual void print( std::ostream &, int indent = 0) const; |
---|
100 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
101 | |
---|
102 | virtual Expression *build() const; |
---|
103 | }; |
---|
104 | |
---|
105 | class ConstantNode : public ExpressionNode { |
---|
106 | public: |
---|
107 | enum Type { Integer, Float, Character, String }; |
---|
108 | |
---|
109 | ConstantNode( Type, std::string * ); |
---|
110 | ConstantNode( const ConstantNode &other ) : type( other.type ), btype( other.btype), value( *new std::string( other.value ) ) {}; |
---|
111 | ~ConstantNode() { delete &value; } |
---|
112 | |
---|
113 | virtual ConstantNode *clone() const { return new ConstantNode( *this ); } |
---|
114 | Type get_type( void ) const { return type; } |
---|
115 | virtual void print( std::ostream &, int indent = 0) const; |
---|
116 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
117 | |
---|
118 | const std::string &get_value() const { return value; } |
---|
119 | ConstantNode *appendstr( const std::string *newValue ); |
---|
120 | |
---|
121 | Expression *build() const; |
---|
122 | private: |
---|
123 | Type type; |
---|
124 | BasicType::Kind btype; |
---|
125 | std::string &value; |
---|
126 | }; |
---|
127 | |
---|
128 | class VarRefNode : public ExpressionNode { |
---|
129 | public: |
---|
130 | VarRefNode(); |
---|
131 | VarRefNode( const std::string *, bool isLabel = false ); |
---|
132 | VarRefNode( const VarRefNode &other ); |
---|
133 | |
---|
134 | virtual Expression *build() const ; |
---|
135 | |
---|
136 | virtual VarRefNode *clone() const { return new VarRefNode( *this ); } |
---|
137 | |
---|
138 | virtual void print( std::ostream &, int indent = 0 ) const; |
---|
139 | virtual void printOneLine( std::ostream &, int indent = 0 ) const; |
---|
140 | private: |
---|
141 | bool isLabel; |
---|
142 | }; |
---|
143 | |
---|
144 | class DesignatorNode : public ExpressionNode { |
---|
145 | public: |
---|
146 | DesignatorNode( ExpressionNode *expr, bool isArrayIndex = false ); |
---|
147 | DesignatorNode( const DesignatorNode &other ); |
---|
148 | |
---|
149 | virtual Expression *build() const ; |
---|
150 | virtual DesignatorNode *clone() const { return new DesignatorNode( *this ); } |
---|
151 | |
---|
152 | virtual void print( std::ostream &, int indent = 0 ) const; |
---|
153 | virtual void printOneLine( std::ostream &, int indent = 0 ) const; |
---|
154 | private: |
---|
155 | bool isArrayIndex; |
---|
156 | }; |
---|
157 | |
---|
158 | class TypeValueNode : public ExpressionNode { |
---|
159 | public: |
---|
160 | TypeValueNode( DeclarationNode * ); |
---|
161 | TypeValueNode( const TypeValueNode &other ); |
---|
162 | |
---|
163 | DeclarationNode *get_decl() const { return decl; } |
---|
164 | |
---|
165 | virtual Expression *build() const ; |
---|
166 | |
---|
167 | virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); } |
---|
168 | |
---|
169 | virtual void print( std::ostream &, int indent = 0) const; |
---|
170 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
171 | private: |
---|
172 | DeclarationNode *decl; |
---|
173 | }; |
---|
174 | |
---|
175 | class OperatorNode : public ExpressionNode { |
---|
176 | public: |
---|
177 | enum Type { TupleC, Comma, TupleFieldSel, // n-adic |
---|
178 | // triadic |
---|
179 | Cond, NCond, |
---|
180 | // diadic |
---|
181 | SizeOf, AlignOf, OffsetOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And, |
---|
182 | BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, |
---|
183 | Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn, |
---|
184 | Index, FieldSel, PFieldSel, Range, |
---|
185 | // monadic |
---|
186 | UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress, |
---|
187 | Ctor, Dtor, |
---|
188 | }; |
---|
189 | |
---|
190 | OperatorNode( Type t ); |
---|
191 | OperatorNode( const OperatorNode &other ); |
---|
192 | virtual ~OperatorNode(); |
---|
193 | |
---|
194 | virtual OperatorNode *clone() const { return new OperatorNode( *this ); } |
---|
195 | |
---|
196 | Type get_type() const; |
---|
197 | const char *get_typename() const; |
---|
198 | |
---|
199 | virtual void print( std::ostream &, int indent = 0) const; |
---|
200 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
201 | |
---|
202 | virtual Expression *build() const { return 0; } |
---|
203 | private: |
---|
204 | Type type; |
---|
205 | }; |
---|
206 | |
---|
207 | class CompositeExprNode : public ExpressionNode { |
---|
208 | public: |
---|
209 | CompositeExprNode(); |
---|
210 | CompositeExprNode( const std::string * ); |
---|
211 | CompositeExprNode( ExpressionNode *f, ExpressionNode *args = 0 ); |
---|
212 | CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2 ); |
---|
213 | CompositeExprNode( const CompositeExprNode &other ); |
---|
214 | virtual ~CompositeExprNode(); |
---|
215 | |
---|
216 | virtual CompositeExprNode *clone() const { return new CompositeExprNode( *this ); } |
---|
217 | virtual Expression *build() const; |
---|
218 | |
---|
219 | virtual void print( std::ostream &, int indent = 0) const; |
---|
220 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
221 | |
---|
222 | void set_function( ExpressionNode * ); |
---|
223 | void set_args( ExpressionNode * ); |
---|
224 | |
---|
225 | void add_arg( ExpressionNode * ); |
---|
226 | |
---|
227 | ExpressionNode *get_function() const; |
---|
228 | ExpressionNode *get_args() const; |
---|
229 | private: |
---|
230 | ExpressionNode *function; |
---|
231 | ExpressionNode *arguments; |
---|
232 | }; |
---|
233 | |
---|
234 | class AsmExprNode : public ExpressionNode { |
---|
235 | public: |
---|
236 | AsmExprNode(); |
---|
237 | AsmExprNode( ExpressionNode *inout, ConstantNode *constraint, ExpressionNode *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} |
---|
238 | virtual ~AsmExprNode() { delete inout; delete constraint; delete operand; } |
---|
239 | |
---|
240 | virtual AsmExprNode *clone() const { return new AsmExprNode( *this ); } |
---|
241 | virtual Expression *build() const; |
---|
242 | |
---|
243 | virtual void print( std::ostream &, int indent = 0) const; |
---|
244 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
245 | |
---|
246 | ExpressionNode *get_inout() const { return inout; }; |
---|
247 | void set_inout( ExpressionNode *newValue ) { inout = newValue; } |
---|
248 | |
---|
249 | ConstantNode *get_constraint() const { return constraint; }; |
---|
250 | void set_constraint( ConstantNode *newValue ) { constraint = newValue; } |
---|
251 | |
---|
252 | ExpressionNode *get_operand() const { return operand; }; |
---|
253 | void set_operand( ExpressionNode *newValue ) { operand = newValue; } |
---|
254 | private: |
---|
255 | ExpressionNode *inout; |
---|
256 | ConstantNode *constraint; |
---|
257 | ExpressionNode *operand; |
---|
258 | }; |
---|
259 | |
---|
260 | class LabelNode : public ExpressionNode { |
---|
261 | public: |
---|
262 | virtual Expression *build() const { return NULL; } |
---|
263 | virtual LabelNode *clone() const { return new LabelNode( *this ); } |
---|
264 | |
---|
265 | virtual void print( std::ostream &, int indent = 0) const; |
---|
266 | virtual void printOneLine( std::ostream &, int indent = 0) const; |
---|
267 | |
---|
268 | const std::list< std::string > &get_labels() const { return labels; }; |
---|
269 | void append_label( std::string *label ) { labels.push_back( *label ); delete label; } |
---|
270 | private: |
---|
271 | std::list< std::string > labels; |
---|
272 | }; |
---|
273 | |
---|
274 | class CommaExprNode : public CompositeExprNode { |
---|
275 | public: |
---|
276 | CommaExprNode(); |
---|
277 | CommaExprNode( ExpressionNode * ); |
---|
278 | CommaExprNode( ExpressionNode *, ExpressionNode * ); |
---|
279 | CommaExprNode( const CommaExprNode &other ); |
---|
280 | |
---|
281 | virtual CommaExprNode *add_to_list( ExpressionNode * ); |
---|
282 | virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); } |
---|
283 | }; |
---|
284 | |
---|
285 | class ForCtlExprNode : public ExpressionNode { |
---|
286 | public: |
---|
287 | ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError ); |
---|
288 | ForCtlExprNode( const ForCtlExprNode &other ); |
---|
289 | ~ForCtlExprNode(); |
---|
290 | |
---|
291 | StatementNode *get_init() const { return init; } |
---|
292 | ExpressionNode *get_condition() const { return condition; } |
---|
293 | ExpressionNode *get_change() const { return change; } |
---|
294 | |
---|
295 | virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); } |
---|
296 | virtual Expression *build() const; |
---|
297 | |
---|
298 | virtual void print( std::ostream &, int indent = 0 ) const; |
---|
299 | virtual void printOneLine( std::ostream &, int indent = 0 ) const; |
---|
300 | private: |
---|
301 | StatementNode *init; |
---|
302 | ExpressionNode *condition; |
---|
303 | ExpressionNode *change; |
---|
304 | }; |
---|
305 | |
---|
306 | class ValofExprNode : public ExpressionNode { |
---|
307 | public: |
---|
308 | ValofExprNode(); |
---|
309 | ValofExprNode( StatementNode *s = 0 ); |
---|
310 | ValofExprNode( const ValofExprNode &other ); |
---|
311 | ~ValofExprNode(); |
---|
312 | |
---|
313 | virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); } |
---|
314 | |
---|
315 | StatementNode *get_body() const { return body; } |
---|
316 | void print( std::ostream &, int indent = 0 ) const; |
---|
317 | void printOneLine( std::ostream &, int indent = 0 ) const; |
---|
318 | Expression *build() const; |
---|
319 | |
---|
320 | private: |
---|
321 | StatementNode *body; |
---|
322 | }; |
---|
323 | |
---|
324 | class TypeData; |
---|
325 | |
---|
326 | class DeclarationNode : public ParseNode { |
---|
327 | public: |
---|
328 | enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic }; |
---|
329 | enum StorageClass { Extern, Static, Auto, Register, Inline, Fortran, Noreturn, Threadlocal, NoStorageClass, }; |
---|
330 | enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary }; |
---|
331 | enum Modifier { Signed, Unsigned, Short, Long }; |
---|
332 | enum Aggregate { Struct, Union, Trait }; |
---|
333 | enum TypeClass { Type, Dtype, Ftype }; |
---|
334 | enum BuiltinType { Valist }; |
---|
335 | |
---|
336 | static const char *storageName[]; |
---|
337 | static const char *qualifierName[]; |
---|
338 | static const char *basicTypeName[]; |
---|
339 | static const char *modifierName[]; |
---|
340 | static const char *aggregateName[]; |
---|
341 | static const char *typeClassName[]; |
---|
342 | static const char *builtinTypeName[]; |
---|
343 | |
---|
344 | static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle = false ); |
---|
345 | static DeclarationNode *newQualifier( Qualifier ); |
---|
346 | static DeclarationNode *newStorageClass( StorageClass ); |
---|
347 | static DeclarationNode *newBasicType( BasicType ); |
---|
348 | static DeclarationNode *newModifier( Modifier ); |
---|
349 | static DeclarationNode *newForall( DeclarationNode *); |
---|
350 | static DeclarationNode *newFromTypedef( std::string *); |
---|
351 | static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ); |
---|
352 | static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants ); |
---|
353 | static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant ); |
---|
354 | static DeclarationNode *newName( std::string *); |
---|
355 | static DeclarationNode *newFromTypeGen( std::string *, ExpressionNode *params ); |
---|
356 | static DeclarationNode *newTypeParam( TypeClass, std::string *); |
---|
357 | static DeclarationNode *newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts ); |
---|
358 | static DeclarationNode *newTraitUse( std::string *name, ExpressionNode *params ); |
---|
359 | static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams ); |
---|
360 | static DeclarationNode *newPointer( DeclarationNode *qualifiers ); |
---|
361 | static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic ); |
---|
362 | static DeclarationNode *newVarArray( DeclarationNode *qualifiers ); |
---|
363 | static DeclarationNode *newBitfield( ExpressionNode *size ); |
---|
364 | static DeclarationNode *newTuple( DeclarationNode *members ); |
---|
365 | static DeclarationNode *newTypeof( ExpressionNode *expr ); |
---|
366 | static DeclarationNode *newAttr( std::string *, ExpressionNode *expr ); |
---|
367 | static DeclarationNode *newAttr( std::string *, DeclarationNode *type ); |
---|
368 | static DeclarationNode *newBuiltinType( BuiltinType ); |
---|
369 | |
---|
370 | DeclarationNode *addQualifiers( DeclarationNode *); |
---|
371 | DeclarationNode *copyStorageClasses( DeclarationNode *); |
---|
372 | DeclarationNode *addType( DeclarationNode *); |
---|
373 | DeclarationNode *addTypedef(); |
---|
374 | DeclarationNode *addAssertions( DeclarationNode *); |
---|
375 | DeclarationNode *addName( std::string *); |
---|
376 | DeclarationNode *addBitfield( ExpressionNode *size ); |
---|
377 | DeclarationNode *addVarArgs(); |
---|
378 | DeclarationNode *addFunctionBody( StatementNode *body ); |
---|
379 | DeclarationNode *addOldDeclList( DeclarationNode *list ); |
---|
380 | DeclarationNode *addPointer( DeclarationNode *qualifiers ); |
---|
381 | DeclarationNode *addArray( DeclarationNode *array ); |
---|
382 | DeclarationNode *addNewPointer( DeclarationNode *pointer ); |
---|
383 | DeclarationNode *addNewArray( DeclarationNode *array ); |
---|
384 | DeclarationNode *addParamList( DeclarationNode *list ); |
---|
385 | DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions |
---|
386 | DeclarationNode *addInitializer( InitializerNode *init ); |
---|
387 | |
---|
388 | DeclarationNode *cloneType( std::string *newName ); |
---|
389 | DeclarationNode *cloneType( DeclarationNode *existing ); |
---|
390 | DeclarationNode *cloneType( int ) { return cloneType( ( std::string *)0 ); } |
---|
391 | DeclarationNode *cloneBaseType( std::string *newName ); |
---|
392 | DeclarationNode *cloneBaseType( DeclarationNode *newdecl ); |
---|
393 | |
---|
394 | DeclarationNode *appendList( DeclarationNode * ); |
---|
395 | |
---|
396 | DeclarationNode *clone() const; |
---|
397 | void print( std::ostream &, int indent = 0 ) const; |
---|
398 | void printList( std::ostream &, int indent = 0 ) const; |
---|
399 | |
---|
400 | Declaration *build() const; |
---|
401 | ::Type *buildType() const; |
---|
402 | |
---|
403 | bool get_hasEllipsis() const; |
---|
404 | const std::string &get_name() const { return name; } |
---|
405 | LinkageSpec::Type get_linkage() const { return linkage; } |
---|
406 | DeclarationNode *extractAggregate() const; |
---|
407 | ExpressionNode *get_enumeratorValue() const { return enumeratorValue; } |
---|
408 | |
---|
409 | DeclarationNode(); |
---|
410 | ~DeclarationNode(); |
---|
411 | private: |
---|
412 | StorageClass buildStorageClass() const; |
---|
413 | bool buildFuncSpecifier( StorageClass key ) const; |
---|
414 | |
---|
415 | TypeData *type; |
---|
416 | std::string name; |
---|
417 | std::list< StorageClass > storageClasses; |
---|
418 | std::list< std::string > attributes; |
---|
419 | ExpressionNode *bitfieldWidth; |
---|
420 | ExpressionNode *enumeratorValue; |
---|
421 | InitializerNode *initializer; |
---|
422 | bool hasEllipsis; |
---|
423 | LinkageSpec::Type linkage; |
---|
424 | |
---|
425 | static UniqueName anonymous; |
---|
426 | }; // DeclarationNode |
---|
427 | |
---|
428 | class StatementNode : public ParseNode { |
---|
429 | public: |
---|
430 | enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, |
---|
431 | While, Do, For, |
---|
432 | Goto, Continue, Break, Return, Throw, |
---|
433 | Try, Catch, Finally, Asm, |
---|
434 | Decl |
---|
435 | }; |
---|
436 | |
---|
437 | StatementNode(); |
---|
438 | StatementNode( const std::string *name ); |
---|
439 | StatementNode( Type t, ExpressionNode *control = 0, StatementNode *block = 0 ); |
---|
440 | StatementNode( Type t, std::string *target ); |
---|
441 | StatementNode( DeclarationNode *decl ); |
---|
442 | |
---|
443 | ~StatementNode(); |
---|
444 | |
---|
445 | static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false ); |
---|
446 | |
---|
447 | StatementNode *set_block( StatementNode *b ) { block = b; return this; } |
---|
448 | StatementNode *get_block() const { return block; } |
---|
449 | |
---|
450 | void set_control( ExpressionNode *c ) { control = c; } |
---|
451 | ExpressionNode *get_control() const { return control; } |
---|
452 | |
---|
453 | StatementNode::Type get_type() const { return type; } |
---|
454 | |
---|
455 | StatementNode *add_label( const std::string * ); |
---|
456 | const std::list<std::string> &get_labels() const { return labels; } |
---|
457 | |
---|
458 | void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; } |
---|
459 | void setCatchRest( bool newVal ) { isCatchRest = newVal; } |
---|
460 | |
---|
461 | std::string get_target() const; |
---|
462 | |
---|
463 | StatementNode *add_controlexp( ExpressionNode * ); |
---|
464 | StatementNode *append_block( StatementNode * ); |
---|
465 | StatementNode *append_last_case( StatementNode * ); |
---|
466 | |
---|
467 | void print( std::ostream &, int indent = 0) const; |
---|
468 | virtual StatementNode *clone() const; |
---|
469 | virtual Statement *build() const; |
---|
470 | private: |
---|
471 | static const char *StType[]; |
---|
472 | Type type; |
---|
473 | ExpressionNode *control; |
---|
474 | StatementNode *block; |
---|
475 | std::list<std::string> labels; |
---|
476 | std::string *target; // target label for jump statements |
---|
477 | DeclarationNode *decl; |
---|
478 | bool isCatchRest; |
---|
479 | }; // StatementNode |
---|
480 | |
---|
481 | class CompoundStmtNode : public StatementNode { |
---|
482 | public: |
---|
483 | CompoundStmtNode(); |
---|
484 | CompoundStmtNode( const std::string * ); |
---|
485 | CompoundStmtNode( StatementNode * ); |
---|
486 | ~CompoundStmtNode(); |
---|
487 | |
---|
488 | void add_statement( StatementNode * ); |
---|
489 | |
---|
490 | void print( std::ostream &, int indent = 0 ) const; |
---|
491 | virtual Statement *build() const; |
---|
492 | private: |
---|
493 | StatementNode *first, *last; |
---|
494 | }; |
---|
495 | |
---|
496 | class AsmStmtNode : public StatementNode { |
---|
497 | public: |
---|
498 | AsmStmtNode( Type, bool voltile, ConstantNode *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ConstantNode *clobber = 0, LabelNode *gotolabels = 0 ); |
---|
499 | ~AsmStmtNode(); |
---|
500 | |
---|
501 | void print( std::ostream &, int indent = 0 ) const; |
---|
502 | Statement *build() const; |
---|
503 | private: |
---|
504 | bool voltile; |
---|
505 | ConstantNode *instruction; |
---|
506 | ExpressionNode *output, *input; |
---|
507 | ConstantNode *clobber; |
---|
508 | std::list<std::string> gotolabels; |
---|
509 | }; |
---|
510 | |
---|
511 | class NullStmtNode : public CompoundStmtNode { |
---|
512 | public: |
---|
513 | Statement *build() const; |
---|
514 | void print( std::ostream &, int indent = 0 ) const; |
---|
515 | }; |
---|
516 | |
---|
517 | class InitializerNode : public ParseNode { |
---|
518 | public: |
---|
519 | InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 ); |
---|
520 | InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); |
---|
521 | ~InitializerNode(); |
---|
522 | |
---|
523 | ExpressionNode *get_expression() const { return expr; } |
---|
524 | |
---|
525 | InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } |
---|
526 | ExpressionNode *get_designators() const { return designator; } |
---|
527 | |
---|
528 | InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; } |
---|
529 | bool get_maybeConstructed() const { return maybeConstructed; } |
---|
530 | |
---|
531 | InitializerNode *next_init() const { return kids; } |
---|
532 | |
---|
533 | void print( std::ostream &, int indent = 0 ) const; |
---|
534 | void printOneLine( std::ostream & ) const; |
---|
535 | |
---|
536 | virtual Initializer *build() const; |
---|
537 | private: |
---|
538 | ExpressionNode *expr; |
---|
539 | bool aggregate; |
---|
540 | ExpressionNode *designator; // may be list |
---|
541 | InitializerNode *kids; |
---|
542 | bool maybeConstructed; |
---|
543 | }; |
---|
544 | |
---|
545 | class CompoundLiteralNode : public ExpressionNode { |
---|
546 | public: |
---|
547 | CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids ); |
---|
548 | CompoundLiteralNode( const CompoundLiteralNode &type ); |
---|
549 | ~CompoundLiteralNode(); |
---|
550 | |
---|
551 | virtual CompoundLiteralNode *clone() const; |
---|
552 | |
---|
553 | DeclarationNode *get_type() const { return type; } |
---|
554 | CompoundLiteralNode *set_type( DeclarationNode *t ) { type = t; return this; } |
---|
555 | |
---|
556 | InitializerNode *get_initializer() const { return kids; } |
---|
557 | CompoundLiteralNode *set_initializer( InitializerNode *k ) { kids = k; return this; } |
---|
558 | |
---|
559 | void print( std::ostream &, int indent = 0 ) const; |
---|
560 | void printOneLine( std::ostream &, int indent = 0 ) const; |
---|
561 | |
---|
562 | virtual Expression *build() const; |
---|
563 | private: |
---|
564 | DeclarationNode *type; |
---|
565 | InitializerNode *kids; |
---|
566 | }; |
---|
567 | |
---|
568 | template< typename SynTreeType, typename NodeType > |
---|
569 | void buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) { |
---|
570 | SemanticError errors; |
---|
571 | std::back_insert_iterator< std::list< SynTreeType *> > out( outputList ); |
---|
572 | const NodeType *cur = firstNode; |
---|
573 | |
---|
574 | while ( cur ) { |
---|
575 | try { |
---|
576 | SynTreeType *result = dynamic_cast< SynTreeType *>( cur->build() ); |
---|
577 | if ( result ) { |
---|
578 | *out++ = result; |
---|
579 | } else { |
---|
580 | } // if |
---|
581 | } catch( SemanticError &e ) { |
---|
582 | errors.append( e ); |
---|
583 | } // try |
---|
584 | cur = dynamic_cast< NodeType *>( cur->get_link() ); |
---|
585 | } // while |
---|
586 | if ( ! errors.isEmpty() ) { |
---|
587 | throw errors; |
---|
588 | } // if |
---|
589 | } |
---|
590 | |
---|
591 | // in DeclarationNode.cc |
---|
592 | void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ); |
---|
593 | void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList ); |
---|
594 | void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ); |
---|
595 | |
---|
596 | // in ExpressionNode.cc |
---|
597 | ExpressionNode *flattenCommas( ExpressionNode *list ); |
---|
598 | ExpressionNode *tupleContents( ExpressionNode *tuple ); |
---|
599 | |
---|
600 | #endif // PARSENODE_H |
---|
601 | |
---|
602 | // Local Variables: // |
---|
603 | // tab-width: 4 // |
---|
604 | // mode: c++ // |
---|
605 | // compile-command: "make install" // |
---|
606 | // End: // |
---|