source: src/Parser/ParseNode.h@ 9706554

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 9706554 was 9706554, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

even more refactoring of parser code

  • Property mode set to 100644
File size: 22.7 KB
Line 
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 : Fri Aug 5 11:42:50 2016
13// Update Count : 293
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
32class ExpressionNode;
33class CompositeExprNode;
34class CommaExprNode;
35class StatementNode;
36class CompoundStmtNode;
37class DeclarationNode;
38class InitializerNode;
39
40// Builder
41class 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
68ParseNode *mkList( ParseNode & );
69
70class 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
98template< typename T >
99struct 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 ]
112class 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
124class 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
143ConstantNode *makeConstantInteger( std::string & );
144ConstantNode *makeConstantFloat( std::string & );
145ConstantNode *makeConstantChar( std::string & );
146ConstantNode *makeConstantStr( std::string & );
147
148class 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
164class 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
178class 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
195class 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
227Expression *build_cast( TypeValueNode * arg, ExpressionNode *expr_node );
228Expression *build_fieldSel( ExpressionNode *expr_node, VarRefNode *member );
229Expression *build_pfieldSel( ExpressionNode *expr_node, VarRefNode *member );
230Expression *build_addressOf( ExpressionNode *expr_node );
231Expression *build_sizeOf( ExpressionNode *expr_node );
232Expression *build_alignOf( ExpressionNode *expr_node );
233Expression *build_offsetOf( TypeValueNode * arg, VarRefNode *member );
234Expression *build_and( ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
235Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind );
236Expression *build_unary_val( OperatorNode::Type op, ExpressionNode *expr_node );
237Expression *build_unary_ptr( OperatorNode::Type op, ExpressionNode *expr_node );
238Expression *build_binary_val( OperatorNode::Type op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
239Expression *build_binary_ptr( OperatorNode::Type op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
240Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 );
241Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 );
242Expression *build_attr( VarRefNode *var, ExpressionNode * expr = 0 );
243Expression *build_tuple( ExpressionNode * expr = 0 );
244Expression *build_func( ExpressionNode * function, ExpressionNode * expr );
245
246class CompositeExprNode2 : public ExpressionNode {
247 public:
248 CompositeExprNode2( Expression *expr );
249 CompositeExprNode2( const CompositeExprNode2 &other );
250 virtual ~CompositeExprNode2();
251
252 virtual CompositeExprNode2 *clone() const { return new CompositeExprNode2( *this ); }
253 virtual Expression *build() const { return expr->clone(); }
254
255 virtual void print( std::ostream &, int indent = 0) const;
256 virtual void printOneLine( std::ostream &, int indent = 0) const;
257 private:
258 Expression *expr;
259};
260
261class CompositeExprNode : public ExpressionNode {
262 public:
263 CompositeExprNode();
264 CompositeExprNode( const std::string * );
265 CompositeExprNode( ExpressionNode *f, ExpressionNode *args = 0 );
266 CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2 );
267 CompositeExprNode( const CompositeExprNode &other );
268 virtual ~CompositeExprNode();
269
270 virtual CompositeExprNode *clone() const { return new CompositeExprNode( *this ); }
271 virtual Expression *build() const;
272
273 virtual void print( std::ostream &, int indent = 0) const;
274 virtual void printOneLine( std::ostream &, int indent = 0) const;
275
276 void set_function( ExpressionNode * );
277 void set_args( ExpressionNode * );
278
279 void add_arg( ExpressionNode * );
280
281 ExpressionNode *get_function() const;
282 ExpressionNode *get_args() const;
283 private:
284 ExpressionNode *function;
285 ExpressionNode *arguments;
286};
287
288class AsmExprNode : public ExpressionNode {
289 public:
290 AsmExprNode();
291 AsmExprNode( ExpressionNode *inout, ConstantNode *constraint, ExpressionNode *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
292 virtual ~AsmExprNode() { delete inout; delete constraint; delete operand; }
293
294 virtual AsmExprNode *clone() const { return new AsmExprNode( *this ); }
295 virtual Expression *build() const;
296
297 virtual void print( std::ostream &, int indent = 0) const;
298 virtual void printOneLine( std::ostream &, int indent = 0) const;
299
300 ExpressionNode *get_inout() const { return inout; };
301 void set_inout( ExpressionNode *newValue ) { inout = newValue; }
302
303 ConstantNode *get_constraint() const { return constraint; };
304 void set_constraint( ConstantNode *newValue ) { constraint = newValue; }
305
306 ExpressionNode *get_operand() const { return operand; };
307 void set_operand( ExpressionNode *newValue ) { operand = newValue; }
308 private:
309 ExpressionNode *inout;
310 ConstantNode *constraint;
311 ExpressionNode *operand;
312};
313
314class LabelNode : public ExpressionNode {
315 public:
316 virtual Expression *build() const { return NULL; }
317 virtual LabelNode *clone() const { return new LabelNode( *this ); }
318
319 virtual void print( std::ostream &, int indent = 0) const;
320 virtual void printOneLine( std::ostream &, int indent = 0) const;
321
322 const std::list< Label > &get_labels() const { return labels; };
323 void append_label( std::string *label ) { labels.push_back( *label ); delete label; }
324 private:
325 std::list< Label > labels;
326};
327
328class CommaExprNode : public CompositeExprNode {
329 public:
330 CommaExprNode();
331 CommaExprNode( ExpressionNode * );
332 CommaExprNode( ExpressionNode *, ExpressionNode * );
333 CommaExprNode( const CommaExprNode &other );
334
335 // virtual CommaExprNode *add_to_list( ExpressionNode * );
336 virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); }
337};
338
339class ForCtlExprNode : public ExpressionNode {
340 public:
341 ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError );
342 ForCtlExprNode( const ForCtlExprNode &other );
343 ~ForCtlExprNode();
344
345 StatementNode *get_init() const { return init; }
346 ExpressionNode *get_condition() const { return condition; }
347 ExpressionNode *get_change() const { return change; }
348
349 virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); }
350 virtual Expression *build() const;
351
352 virtual void print( std::ostream &, int indent = 0 ) const;
353 virtual void printOneLine( std::ostream &, int indent = 0 ) const;
354 private:
355 StatementNode *init;
356 ExpressionNode *condition;
357 ExpressionNode *change;
358};
359
360class ValofExprNode : public ExpressionNode {
361 public:
362 ValofExprNode();
363 ValofExprNode( StatementNode *s = 0 );
364 ValofExprNode( const ValofExprNode &other );
365 ~ValofExprNode();
366
367 virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); }
368
369 StatementNode *get_body() const { return body; }
370 void print( std::ostream &, int indent = 0 ) const;
371 void printOneLine( std::ostream &, int indent = 0 ) const;
372 Expression *build() const;
373
374 private:
375 StatementNode *body;
376};
377
378class TypeData;
379
380class DeclarationNode : public ParseNode {
381 public:
382 enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic };
383 enum StorageClass { Extern, Static, Auto, Register, Inline, Fortran, Noreturn, Threadlocal, NoStorageClass, };
384 enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary };
385 enum Modifier { Signed, Unsigned, Short, Long };
386 enum Aggregate { Struct, Union, Trait };
387 enum TypeClass { Type, Dtype, Ftype };
388 enum BuiltinType { Valist };
389
390 static const char *storageName[];
391 static const char *qualifierName[];
392 static const char *basicTypeName[];
393 static const char *modifierName[];
394 static const char *aggregateName[];
395 static const char *typeClassName[];
396 static const char *builtinTypeName[];
397
398 static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle = false );
399 static DeclarationNode *newQualifier( Qualifier );
400 static DeclarationNode *newStorageClass( StorageClass );
401 static DeclarationNode *newBasicType( BasicType );
402 static DeclarationNode *newModifier( Modifier );
403 static DeclarationNode *newForall( DeclarationNode *);
404 static DeclarationNode *newFromTypedef( std::string *);
405 static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body );
406 static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants );
407 static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant );
408 static DeclarationNode *newName( std::string *);
409 static DeclarationNode *newFromTypeGen( std::string *, ExpressionNode *params );
410 static DeclarationNode *newTypeParam( TypeClass, std::string *);
411 static DeclarationNode *newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts );
412 static DeclarationNode *newTraitUse( std::string *name, ExpressionNode *params );
413 static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams );
414 static DeclarationNode *newPointer( DeclarationNode *qualifiers );
415 static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic );
416 static DeclarationNode *newVarArray( DeclarationNode *qualifiers );
417 static DeclarationNode *newBitfield( ExpressionNode *size );
418 static DeclarationNode *newTuple( DeclarationNode *members );
419 static DeclarationNode *newTypeof( ExpressionNode *expr );
420 static DeclarationNode *newAttr( std::string *, ExpressionNode *expr );
421 static DeclarationNode *newAttr( std::string *, DeclarationNode *type );
422 static DeclarationNode *newBuiltinType( BuiltinType );
423
424 DeclarationNode *addQualifiers( DeclarationNode *);
425 DeclarationNode *copyStorageClasses( DeclarationNode *);
426 DeclarationNode *addType( DeclarationNode *);
427 DeclarationNode *addTypedef();
428 DeclarationNode *addAssertions( DeclarationNode *);
429 DeclarationNode *addName( std::string *);
430 DeclarationNode *addBitfield( ExpressionNode *size );
431 DeclarationNode *addVarArgs();
432 DeclarationNode *addFunctionBody( StatementNode *body );
433 DeclarationNode *addOldDeclList( DeclarationNode *list );
434 DeclarationNode *addPointer( DeclarationNode *qualifiers );
435 DeclarationNode *addArray( DeclarationNode *array );
436 DeclarationNode *addNewPointer( DeclarationNode *pointer );
437 DeclarationNode *addNewArray( DeclarationNode *array );
438 DeclarationNode *addParamList( DeclarationNode *list );
439 DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions
440 DeclarationNode *addInitializer( InitializerNode *init );
441
442 DeclarationNode *cloneType( std::string *newName );
443 DeclarationNode *cloneType( DeclarationNode *existing );
444 DeclarationNode *cloneType( int ) { return cloneType( ( std::string *)0 ); }
445 DeclarationNode *cloneBaseType( std::string *newName );
446 DeclarationNode *cloneBaseType( DeclarationNode *newdecl );
447
448 DeclarationNode *appendList( DeclarationNode * );
449
450 DeclarationNode *clone() const;
451 void print( std::ostream &, int indent = 0 ) const;
452 void printList( std::ostream &, int indent = 0 ) const;
453
454 Declaration *build() const;
455 ::Type *buildType() const;
456
457 bool get_hasEllipsis() const;
458 const std::string &get_name() const { return name; }
459 LinkageSpec::Type get_linkage() const { return linkage; }
460 DeclarationNode *extractAggregate() const;
461 ExpressionNode *get_enumeratorValue() const { return enumeratorValue; }
462
463 bool get_extension() const { return extension; }
464 DeclarationNode *set_extension( bool exten ) { extension = exten; return this; }
465
466 DeclarationNode();
467 ~DeclarationNode();
468 private:
469 StorageClass buildStorageClass() const;
470 bool buildFuncSpecifier( StorageClass key ) const;
471
472 TypeData *type;
473 std::string name;
474 std::list< StorageClass > storageClasses;
475 std::list< std::string > attributes;
476 ExpressionNode *bitfieldWidth;
477 ExpressionNode *enumeratorValue;
478 InitializerNode *initializer;
479 bool hasEllipsis;
480 LinkageSpec::Type linkage;
481 bool extension = false;
482
483 static UniqueName anonymous;
484}; // DeclarationNode
485
486class StatementNode : public ParseNode {
487 public:
488 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru,
489 While, Do, For,
490 Goto, Continue, Break, Return, Throw,
491 Try, Catch, Finally, Asm,
492 Decl
493 };
494
495 StatementNode();
496 StatementNode( const std::string *name );
497 StatementNode( Type t, ExpressionNode *control = 0, StatementNode *block = 0 );
498 StatementNode( Type t, std::string *target );
499 StatementNode( DeclarationNode *decl );
500
501 ~StatementNode();
502
503 static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
504
505 StatementNode *set_block( StatementNode *b ) { block = b; return this; }
506 StatementNode *get_block() const { return block; }
507
508 void set_control( ExpressionNode *c ) { control = c; }
509 ExpressionNode *get_control() const { return control; }
510
511 StatementNode::Type get_type() const { return type; }
512
513 StatementNode *add_label( const std::string * );
514 const std::list<std::string> &get_labels() const { return labels; }
515
516 void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; }
517 void setCatchRest( bool newVal ) { isCatchRest = newVal; }
518
519 std::string get_target() const;
520
521 // StatementNode *add_controlexp( ExpressionNode * );
522 StatementNode *append_block( StatementNode * );
523 StatementNode *append_last_case( StatementNode * );
524
525 void print( std::ostream &, int indent = 0) const;
526 virtual StatementNode *clone() const;
527 virtual Statement *build() const;
528 private:
529 static const char *StType[];
530 Type type;
531 ExpressionNode *control;
532 StatementNode *block;
533 std::list<std::string> labels;
534 std::string *target; // target label for jump statements
535 DeclarationNode *decl;
536 bool isCatchRest;
537}; // StatementNode
538
539class CompoundStmtNode : public StatementNode {
540 public:
541 CompoundStmtNode();
542 CompoundStmtNode( const std::string * );
543 CompoundStmtNode( StatementNode * );
544 ~CompoundStmtNode();
545
546 void add_statement( StatementNode * );
547
548 void print( std::ostream &, int indent = 0 ) const;
549 virtual Statement *build() const;
550 private:
551 StatementNode *first, *last;
552};
553
554class AsmStmtNode : public StatementNode {
555 public:
556 AsmStmtNode( Type, bool voltile, ConstantNode *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ConstantNode *clobber = 0, LabelNode *gotolabels = 0 );
557 ~AsmStmtNode();
558
559 void print( std::ostream &, int indent = 0 ) const;
560 Statement *build() const;
561 private:
562 bool voltile;
563 ConstantNode *instruction;
564 ExpressionNode *output, *input;
565 ConstantNode *clobber;
566 std::list< Label > gotolabels;
567};
568
569class NullStmtNode : public CompoundStmtNode {
570 public:
571 Statement *build() const;
572 void print( std::ostream &, int indent = 0 ) const;
573};
574
575class InitializerNode : public ParseNode {
576 public:
577 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 );
578 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 );
579 ~InitializerNode();
580
581 ExpressionNode *get_expression() const { return expr; }
582
583 InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; }
584 ExpressionNode *get_designators() const { return designator; }
585
586 InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }
587 bool get_maybeConstructed() const { return maybeConstructed; }
588
589 InitializerNode *next_init() const { return kids; }
590
591 void print( std::ostream &, int indent = 0 ) const;
592 void printOneLine( std::ostream & ) const;
593
594 virtual Initializer *build() const;
595 private:
596 ExpressionNode *expr;
597 bool aggregate;
598 ExpressionNode *designator; // may be list
599 InitializerNode *kids;
600 bool maybeConstructed;
601};
602
603class CompoundLiteralNode : public ExpressionNode {
604 public:
605 CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids );
606 CompoundLiteralNode( const CompoundLiteralNode &type );
607 ~CompoundLiteralNode();
608
609 virtual CompoundLiteralNode *clone() const;
610
611 DeclarationNode *get_type() const { return type; }
612 CompoundLiteralNode *set_type( DeclarationNode *t ) { type = t; return this; }
613
614 InitializerNode *get_initializer() const { return kids; }
615 CompoundLiteralNode *set_initializer( InitializerNode *k ) { kids = k; return this; }
616
617 void print( std::ostream &, int indent = 0 ) const;
618 void printOneLine( std::ostream &, int indent = 0 ) const;
619
620 virtual Expression *build() const;
621 private:
622 DeclarationNode *type;
623 InitializerNode *kids;
624};
625
626template< typename SynTreeType, typename NodeType >
627void buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) {
628 SemanticError errors;
629 std::back_insert_iterator< std::list< SynTreeType *> > out( outputList );
630 const NodeType *cur = firstNode;
631
632 while ( cur ) {
633 try {
634// SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::result_of<decltype(&NodeType::build)(NodeType)>::type>( cur ) );
635 SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::pointer_traits<decltype(cur->build())>::element_type>( cur ) );
636 if ( result ) {
637 *out++ = result;
638 } else {
639 } // if
640 } catch( SemanticError &e ) {
641 errors.append( e );
642 } // try
643 cur = dynamic_cast< NodeType *>( cur->get_link() );
644 } // while
645 if ( ! errors.isEmpty() ) {
646 throw errors;
647 } // if
648}
649
650// in DeclarationNode.cc
651void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList );
652void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList );
653void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList );
654
655// in ExpressionNode.cc
656ExpressionNode *flattenCommas( ExpressionNode *list );
657ExpressionNode *tupleContents( ExpressionNode *tuple );
658
659#endif // PARSENODE_H
660
661// Local Variables: //
662// tab-width: 4 //
663// mode: c++ //
664// compile-command: "make install" //
665// End: //
Note: See TracBrowser for help on using the repository browser.