source: src/Parser/ParseNode.h@ 03da511

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

more refactoring of parser code

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