source: src/Parser/ParseNode.h @ 3dcd347a

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since 3dcd347a was 70a06f6, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Merge branch 'master' into ctor

Conflicts:

src/CodeGen/CodeGenerator.cc
src/GenPoly/Box.cc
src/Parser/DeclarationNode.cc
src/Parser/ParseNode.h
src/Parser/parser.cc
src/Parser/parser.yy
src/SymTab/AddVisit.h
src/SymTab/Validate.cc
src/SynTree/Expression.cc
src/SynTree/Expression.h
src/SynTree/Mutator.cc
src/SynTree/Mutator.h
src/SynTree/SynTree.h
src/SynTree/Visitor.cc
src/SynTree/Visitor.h
src/libcfa/iostream.c

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