source: src/Parser/ParseNode.h @ c967ef9

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since c967ef9 was 4e05d27, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

update parser constant-code

  • Property mode set to 100644
File size: 20.8 KB
RevLine 
[b87a5ed]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//
[974906e2]7// ParseNode.h --
[b87a5ed]8//
9// Author           : Rodolfo G. Esteves
10// Created On       : Sat May 16 13:28:16 2015
[e04ef3a]11// Last Modified By : Peter A. Buhr
[4e05d27]12// Last Modified On : Sun Jul 24 02:17:00 2016
13// Update Count     : 269
[b87a5ed]14//
15
[51b7345]16#ifndef PARSENODE_H
17#define PARSENODE_H
18
19#include <string>
20#include <list>
21#include <iterator>
[e04ef3a]22#include <memory>
[51b7345]23
[d3b7937]24#include "Common/utility.h"
[68cd1ce]25#include "Parser/LinkageSpec.h"
[59db689]26#include "SynTree/Type.h"
[e04ef3a]27#include "SynTree/Expression.h"
[68cd1ce]28//#include "SynTree/Declaration.h"
[d3b7937]29#include "Common/UniqueName.h"
[0f8e4ac]30#include "SynTree/Label.h"
[51b7345]31
32class ExpressionNode;
33class CompositeExprNode;
34class CommaExprNode;
35class StatementNode;
36class CompoundStmtNode;
37class DeclarationNode;
38class InitializerNode;
39
40// Builder
41class ParseNode {
[bdd516a]42  public:
[59db689]43        ParseNode();
44        ParseNode( const std::string * );
[8e9cbb2]45        ParseNode( const std::string & );                                       // for copy constructing subclasses
[59db689]46        virtual ~ParseNode();
[51b7345]47
[8e9cbb2]48        ParseNode *get_link() const { return next; }
[59db689]49        ParseNode *get_last();
[b87a5ed]50        ParseNode *set_link( ParseNode * );
51        void set_next( ParseNode *newlink ) { next = newlink; }
[51b7345]52
[b87a5ed]53        virtual ParseNode *clone() const { return 0; };
[51b7345]54
[e869d663]55        const std::string &get_name() const { return name; }
56        void set_name( const std::string &newValue ) { name = newValue; }
57
[b87a5ed]58        virtual void print( std::ostream &, int indent = 0 ) const;
59        virtual void printList( std::ostream &, int indent = 0 ) const;
[51b7345]60
[b87a5ed]61        ParseNode &operator,( ParseNode &);
[bdd516a]62  protected:
[e869d663]63        std::string name;
[b87a5ed]64        static int indent_by;
[8e9cbb2]65        ParseNode *next;
[51b7345]66};
67
[bdd516a]68ParseNode *mkList( ParseNode & );
[51b7345]69
70class ExpressionNode : public ParseNode {
[bdd516a]71  public:
[b87a5ed]72        ExpressionNode();
[59db689]73        ExpressionNode( const std::string * );
[b87a5ed]74        ExpressionNode( const ExpressionNode &other );
[7f5566b]75        virtual ~ExpressionNode() { delete argName; } // cannot delete argName because it might be referenced elsewhere
[51b7345]76
[b87a5ed]77        virtual ExpressionNode *clone() const = 0;
[51b7345]78
[b87a5ed]79        virtual CommaExprNode *add_to_list( ExpressionNode * );
[51b7345]80
[b87a5ed]81        ExpressionNode *get_argName() const { return argName; }
[7f5566b]82        ExpressionNode *set_argName( const std::string *aName );
83        ExpressionNode *set_argName( ExpressionNode *aDesignator );
[e04ef3a]84        bool get_extension() const { return extension; }
85        ExpressionNode *set_extension( bool exten ) { extension = exten; return this; }
[51b7345]86
[b87a5ed]87        virtual void print( std::ostream &, int indent = 0) const = 0;
88        virtual void printOneLine( std::ostream &, int indent = 0) const = 0;
[51b7345]89
[b87a5ed]90        virtual Expression *build() const = 0;
[bdd516a]91  protected:
[b87a5ed]92        void printDesignation ( std::ostream &, int indent = 0) const;
[bdd516a]93  private:
[e04ef3a]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        }
[51b7345]109};
110
[bdd516a]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:
[b87a5ed]114        NullExprNode();
[51b7345]115
[b87a5ed]116        virtual NullExprNode *clone() const;
[51b7345]117
[b87a5ed]118        virtual void print( std::ostream &, int indent = 0) const;
119        virtual void printOneLine( std::ostream &, int indent = 0) const;
[51b7345]120
[b87a5ed]121        virtual Expression *build() const;
[51b7345]122};
123
124class ConstantNode : public ExpressionNode {
[bdd516a]125  public:
[cd623a4]126        enum Type { Integer, Float, Character, String };
[bdd516a]127
[ca35c51]128        ConstantNode( ConstantExpr * );
129        ConstantNode( const ConstantNode &other ) : expr( other.expr->clone() ) {};
130        ~ConstantNode() { delete expr; }
[bdd516a]131
[b87a5ed]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;
[bdd516a]135
[59db689]136        ConstantNode *appendstr( const std::string *newValue );
[bdd516a]137
[b87a5ed]138        Expression *build() const;
[bdd516a]139  private:
[ca35c51]140        ConstantExpr *expr;
[51b7345]141};
142
[4e05d27]143ConstantNode *makeConstantInteger( std::string & );
144ConstantNode *makeConstantFloat( std::string & );
145ConstantNode *makeConstantChar( std::string & );
146ConstantNode *makeConstantStr( std::string & );
[ca35c51]147
[51b7345]148class VarRefNode : public ExpressionNode {
[bdd516a]149  public:
[b87a5ed]150        VarRefNode();
[59db689]151        VarRefNode( const std::string *, bool isLabel = false );
[b87a5ed]152        VarRefNode( const VarRefNode &other );
[51b7345]153
[b87a5ed]154        virtual Expression *build() const ;
[51b7345]155
[b87a5ed]156        virtual VarRefNode *clone() const { return new VarRefNode( *this ); }
[51b7345]157
[59db689]158        virtual void print( std::ostream &, int indent = 0 ) const;
159        virtual void printOneLine( std::ostream &, int indent = 0 ) const;
[bdd516a]160  private:
[b87a5ed]161        bool isLabel;
[51b7345]162};
163
[51b1202]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
[bdd516a]178class TypeValueNode : public ExpressionNode {
179  public:
[b87a5ed]180        TypeValueNode( DeclarationNode * );
181        TypeValueNode( const TypeValueNode &other );
[51b7345]182
[b87a5ed]183        DeclarationNode *get_decl() const { return decl; }
[51b7345]184
[b87a5ed]185        virtual Expression *build() const ;
[51b7345]186
[b87a5ed]187        virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); }
[51b7345]188
[b87a5ed]189        virtual void print( std::ostream &, int indent = 0) const;
190        virtual void printOneLine( std::ostream &, int indent = 0) const;
[bdd516a]191  private:
[b87a5ed]192        DeclarationNode *decl;
[51b7345]193};
194
195class OperatorNode : public ExpressionNode {
[bdd516a]196  public:
[5721a6d]197        enum Type { TupleC, Comma, TupleFieldSel, // n-adic
198                                // triadic
[974906e2]199                                Cond, NCond,
[5721a6d]200                                // diadic
[e04ef3a]201                                SizeOf, AlignOf, OffsetOf, Attr, Plus, Minus, Mul, Div, Mod, Or, And,
[974906e2]202                                BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
[5721a6d]203                                Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn,
204                                Index, FieldSel, PFieldSel, Range,
205                                // monadic
[2794fff]206                                UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress,
207                                Ctor, Dtor,
[b87a5ed]208        };
[51b7345]209
[b87a5ed]210        OperatorNode( Type t );
211        OperatorNode( const OperatorNode &other );
212        virtual ~OperatorNode();
[51b7345]213
[b87a5ed]214        virtual OperatorNode *clone() const { return new OperatorNode( *this ); }
[51b7345]215
[59db689]216        Type get_type() const;
217        const char *get_typename() const;
[51b7345]218
[b87a5ed]219        virtual void print( std::ostream &, int indent = 0) const;
220        virtual void printOneLine( std::ostream &, int indent = 0) const;
[51b7345]221
[b87a5ed]222        virtual Expression *build() const { return 0; }
[bdd516a]223  private:
[b87a5ed]224        Type type;
[51b7345]225};
226
227class CompositeExprNode : public ExpressionNode {
[bdd516a]228  public:
[59db689]229        CompositeExprNode();
230        CompositeExprNode( const std::string * );
[b87a5ed]231        CompositeExprNode( ExpressionNode *f, ExpressionNode *args = 0 );
232        CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2 );
233        CompositeExprNode( const CompositeExprNode &other );
234        virtual ~CompositeExprNode();
[bdd516a]235
[b87a5ed]236        virtual CompositeExprNode *clone() const { return new CompositeExprNode( *this ); }
237        virtual Expression *build() const;
[bdd516a]238
[b87a5ed]239        virtual void print( std::ostream &, int indent = 0) const;
240        virtual void printOneLine( std::ostream &, int indent = 0) const;
[bdd516a]241
[b87a5ed]242        void set_function( ExpressionNode * );
243        void set_args( ExpressionNode * );
[bdd516a]244
[b87a5ed]245        void add_arg( ExpressionNode * );
[bdd516a]246
[b87a5ed]247        ExpressionNode *get_function() const;
248        ExpressionNode *get_args() const;
[bdd516a]249  private:
[b87a5ed]250        ExpressionNode *function;
251        ExpressionNode *arguments;
[51b7345]252};
253
[7f5566b]254class 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
280class 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
[0f8e4ac]288        const std::list< Label > &get_labels() const { return labels; };
[7f5566b]289        void append_label( std::string *label ) { labels.push_back( *label ); delete label; }
290  private:
[0f8e4ac]291        std::list< Label > labels;
[7f5566b]292};
293
[51b7345]294class CommaExprNode : public CompositeExprNode {
[bdd516a]295  public:
[b87a5ed]296        CommaExprNode();
297        CommaExprNode( ExpressionNode * );
298        CommaExprNode( ExpressionNode *, ExpressionNode * );
299        CommaExprNode( const CommaExprNode &other );
[bdd516a]300
[b87a5ed]301        virtual CommaExprNode *add_to_list( ExpressionNode * );
302        virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); }
[51b7345]303};
304
305class ForCtlExprNode : public ExpressionNode {
[bdd516a]306  public:
[b87a5ed]307        ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError );
308        ForCtlExprNode( const ForCtlExprNode &other );
309        ~ForCtlExprNode();
[bdd516a]310
[b87a5ed]311        StatementNode *get_init() const { return init; }
312        ExpressionNode *get_condition() const { return condition; }
313        ExpressionNode *get_change() const { return change; }
[bdd516a]314
[b87a5ed]315        virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); }
316        virtual Expression *build() const;
[bdd516a]317
[b87a5ed]318        virtual void print( std::ostream &, int indent = 0 ) const;
319        virtual void printOneLine( std::ostream &, int indent = 0 ) const;
[bdd516a]320  private:
[b87a5ed]321        StatementNode *init;
322        ExpressionNode *condition;
323        ExpressionNode *change;
[51b7345]324};
325
326class ValofExprNode : public ExpressionNode {
[bdd516a]327  public:
[b87a5ed]328        ValofExprNode();
329        ValofExprNode( StatementNode *s = 0 );
330        ValofExprNode( const ValofExprNode &other );
331        ~ValofExprNode();
[974906e2]332
[b87a5ed]333        virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); }
[51b7345]334
[b87a5ed]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;
[51b7345]339
[bdd516a]340  private:
[b87a5ed]341        StatementNode *body;
[51b7345]342};
343
344class TypeData;
345
[bdd516a]346class DeclarationNode : public ParseNode {
347  public:
[1db21619]348        enum Qualifier { Const, Restrict, Volatile, Lvalue, Atomic };
[68cd1ce]349        enum StorageClass { Extern, Static, Auto, Register, Inline, Fortran, Noreturn, Threadlocal, NoStorageClass, };
[b87a5ed]350        enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary };
[68cd1ce]351        enum Modifier  { Signed, Unsigned, Short, Long };
[4040425]352        enum Aggregate { Struct, Union, Trait };
[b87a5ed]353        enum TypeClass { Type, Dtype, Ftype };
[90c3b1c]354        enum BuiltinType { Valist };
[b87a5ed]355
[974906e2]356        static const char *storageName[];
[b87a5ed]357        static const char *qualifierName[];
358        static const char *basicTypeName[];
359        static const char *modifierName[];
[68cd1ce]360        static const char *aggregateName[];
[b87a5ed]361        static const char *typeClassName[];
[90c3b1c]362        static const char *builtinTypeName[];
[b87a5ed]363
[7f5566b]364        static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle = false );
[b87a5ed]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 *);
[5d125e4]371        static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields, bool body );
[b87a5ed]372        static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants );
373        static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant );
374        static DeclarationNode *newName( std::string *);
[59db689]375        static DeclarationNode *newFromTypeGen( std::string *, ExpressionNode *params );
[b87a5ed]376        static DeclarationNode *newTypeParam( TypeClass, std::string *);
[4040425]377        static DeclarationNode *newTrait( std::string *name, DeclarationNode *params, DeclarationNode *asserts );
378        static DeclarationNode *newTraitUse( std::string *name, ExpressionNode *params );
[b87a5ed]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 );
[59db689]386        static DeclarationNode *newAttr( std::string *, ExpressionNode *expr );
387        static DeclarationNode *newAttr( std::string *, DeclarationNode *type );
[90c3b1c]388        static DeclarationNode *newBuiltinType( BuiltinType );
[b87a5ed]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
[de62360d]414        DeclarationNode *appendList( DeclarationNode * );
[b87a5ed]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;
[5f2f2d7]424        const std::string &get_name() const { return name; }
[b87a5ed]425        LinkageSpec::Type get_linkage() const { return linkage; }
426        DeclarationNode *extractAggregate() const;
[90c3b1c]427        ExpressionNode *get_enumeratorValue() const { return enumeratorValue; }
[b87a5ed]428
[7305915]429        bool get_extension() const { return extension; }
430        DeclarationNode *set_extension( bool exten ) { extension = exten; return this; }
431
[b87a5ed]432        DeclarationNode();
433        ~DeclarationNode();
[bdd516a]434  private:
[68cd1ce]435        StorageClass buildStorageClass() const;
[de62360d]436        bool buildFuncSpecifier( StorageClass key ) const;
[b87a5ed]437
438        TypeData *type;
439        std::string name;
440        std::list< StorageClass > storageClasses;
[1db21619]441        std::list< std::string > attributes;
[b87a5ed]442        ExpressionNode *bitfieldWidth;
[90c3b1c]443        ExpressionNode *enumeratorValue;
[b87a5ed]444        InitializerNode *initializer;
445        bool hasEllipsis;
446        LinkageSpec::Type linkage;
[7305915]447        bool extension = false;
[b87a5ed]448
449        static UniqueName anonymous;
[1db21619]450}; // DeclarationNode
[51b7345]451
452class StatementNode : public ParseNode {
[bdd516a]453  public:
[974906e2]454        enum Type { Exp,   If,        Switch,  Case,    Default,  Choose,   Fallthru,
[b87a5ed]455                                While, Do,        For,
456                                Goto,  Continue,  Break,   Return,  Throw,
457                                Try,   Catch,     Finally, Asm,
458                                Decl
459        };
[51b7345]460
[59db689]461        StatementNode();
[7f5566b]462        StatementNode( const std::string *name );
463        StatementNode( Type t, ExpressionNode *control = 0, StatementNode *block = 0 );
464        StatementNode( Type t, std::string *target );
[b87a5ed]465        StatementNode( DeclarationNode *decl );
[51b7345]466
[59db689]467        ~StatementNode();
[51b7345]468
[59db689]469        static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
[51b7345]470
[1db21619]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; }
[51b7345]476
[1db21619]477        StatementNode::Type get_type() const { return type; }
[51b7345]478
[59db689]479        StatementNode *add_label( const std::string * );
[1db21619]480        const std::list<std::string> &get_labels() const { return labels; }
[51b7345]481
[b87a5ed]482        void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; }
483        void setCatchRest( bool newVal ) { isCatchRest = newVal; }
[51b7345]484
[b87a5ed]485        std::string get_target() const;
[51b7345]486
[b87a5ed]487        StatementNode *add_controlexp( ExpressionNode * );
488        StatementNode *append_block( StatementNode * );
489        StatementNode *append_last_case( StatementNode * );
[51b7345]490
[b87a5ed]491        void print( std::ostream &, int indent = 0) const;
492        virtual StatementNode *clone() const;
493        virtual Statement *build() const;
[bdd516a]494  private:
[b87a5ed]495        static const char *StType[];
496        Type type;
497        ExpressionNode *control;
498        StatementNode *block;
[1db21619]499        std::list<std::string> labels;
[b87a5ed]500        std::string *target;                            // target label for jump statements
501        DeclarationNode *decl;
502        bool isCatchRest;
[1db21619]503}; // StatementNode
[51b7345]504
505class CompoundStmtNode : public StatementNode {
[bdd516a]506  public:
[59db689]507        CompoundStmtNode();
508        CompoundStmtNode( const std::string * );
[b87a5ed]509        CompoundStmtNode( StatementNode * );
510        ~CompoundStmtNode();
[51b7345]511
[b87a5ed]512        void add_statement( StatementNode * );
[51b7345]513
[b87a5ed]514        void print( std::ostream &, int indent = 0 ) const;
515        virtual Statement *build() const;
[bdd516a]516  private:
[b87a5ed]517        StatementNode *first, *last;
[51b7345]518};
519
[7f5566b]520class 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;
[0f8e4ac]532        std::list< Label > gotolabels;
[7f5566b]533};
534
[51b7345]535class NullStmtNode : public CompoundStmtNode {
[bdd516a]536  public:
[b87a5ed]537        Statement *build() const;
[7f5566b]538        void print( std::ostream &, int indent = 0 ) const;
[51b7345]539};
540
541class InitializerNode : public ParseNode {
[bdd516a]542  public:
[b87a5ed]543        InitializerNode( ExpressionNode *, bool aggrp = false,  ExpressionNode *des = 0 );
544        InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 );
545        ~InitializerNode();
[51b7345]546
[b87a5ed]547        ExpressionNode *get_expression() const { return expr; }
[51b7345]548
[b87a5ed]549        InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; }
550        ExpressionNode *get_designators() const { return designator; }
[51b7345]551
[974906e2]552        InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }
553        bool get_maybeConstructed() const { return maybeConstructed; }
554
[b87a5ed]555        InitializerNode *next_init() const { return kids; }
[51b7345]556
[b87a5ed]557        void print( std::ostream &, int indent = 0 ) const;
558        void printOneLine( std::ostream & ) const;
[51b7345]559
[b87a5ed]560        virtual Initializer *build() const;
[bdd516a]561  private:
[b87a5ed]562        ExpressionNode *expr;
563        bool aggregate;
564        ExpressionNode *designator; // may be list
565        InitializerNode *kids;
[974906e2]566        bool maybeConstructed;
[51b7345]567};
568
[630a82a]569class 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
[51b7345]592template< typename SynTreeType, typename NodeType >
[b87a5ed]593void 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 {
[e04ef3a]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 ) );
[b87a5ed]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
[a32b204]611        if ( ! errors.isEmpty() ) {
[b87a5ed]612                throw errors;
613        } // if
[51b7345]614}
615
616// in DeclarationNode.cc
[59db689]617void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList );
[bdd516a]618void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList );
[59db689]619void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList );
[51b7345]620
621// in ExpressionNode.cc
622ExpressionNode *flattenCommas( ExpressionNode *list );
623ExpressionNode *tupleContents( ExpressionNode *tuple );
624
[bdd516a]625#endif // PARSENODE_H
[51b7345]626
627// Local Variables: //
[b87a5ed]628// tab-width: 4 //
629// mode: c++ //
630// compile-command: "make install" //
[51b7345]631// End: //
Note: See TracBrowser for help on using the repository browser.