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