source: src/Parser/ParseNode.h @ 51e076e

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 51e076e was 51e076e, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

more refactoring of parser code

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