source: src/Parser/ParseNode.h@ aaf1f4d

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

Merge branch 'master' of plg2:software/cfa/cfa-cc

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