source: src/Parser/ParseNode.h@ 5b40f30

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 5b40f30 was d63eeb0, checked in by Rob Schluntz <rschlunt@…>, 10 years ago

Merge branch 'master' into ctor

Conflicts:

src/CodeGen/CodeGenerator.cc
src/GenPoly/Box.cc
src/Makefile.in
src/Parser/ParseNode.h
src/Parser/parser.cc
src/Parser/parser.yy
src/SymTab/Validate.cc
src/SynTree/Initializer.h
src/SynTree/ObjectDecl.cc
src/SynTree/Visitor.h
src/main.cc

  • Property mode set to 100644
File size: 18.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
[d63eeb0]12// Last Modified On : Tue Feb 09 13:23:34 2016
13// Update Count : 185
[b87a5ed]14//
15
[51b73452]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"
[51b73452]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();
[51b73452]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; }
[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
[b87a5ed]55 virtual void print( std::ostream &, int indent = 0 ) const;
56 virtual void printList( std::ostream &, int indent = 0 ) const;
[51b73452]57
[b87a5ed]58 ParseNode &operator,( ParseNode &);
[bdd516a]59 protected:
[e869d663]60 std::string name;
[b87a5ed]61 ParseNode *next;
62 static int indent_by;
[51b73452]63};
64
[bdd516a]65ParseNode *mkList( ParseNode & );
[51b73452]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
[51b73452]73
[b87a5ed]74 virtual ExpressionNode *clone() const = 0;
[51b73452]75
[b87a5ed]76 virtual CommaExprNode *add_to_list( ExpressionNode * );
[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 );
[51b73452]81
[b87a5ed]82 virtual void print( std::ostream &, int indent = 0) const = 0;
83 virtual void printOneLine( std::ostream &, int indent = 0) const = 0;
[51b73452]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;
[51b73452]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();
[51b73452]96
[b87a5ed]97 virtual NullExprNode *clone() const;
[51b73452]98
[b87a5ed]99 virtual void print( std::ostream &, int indent = 0) const;
100 virtual void printOneLine( std::ostream &, int indent = 0) const;
[51b73452]101
[b87a5ed]102 virtual Expression *build() const;
[51b73452]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 * );
[7ee14bb7]110 ConstantNode( const ConstantNode &other ) : 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;
[51b73452]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 );
[51b73452]133
[b87a5ed]134 virtual Expression *build() const ;
[51b73452]135
[b87a5ed]136 virtual VarRefNode *clone() const { return new VarRefNode( *this ); }
[51b73452]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;
[51b73452]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 );
[51b73452]162
[b87a5ed]163 DeclarationNode *get_decl() const { return decl; }
[51b73452]164
[b87a5ed]165 virtual Expression *build() const ;
[51b73452]166
[b87a5ed]167 virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); }
[51b73452]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;
[51b73452]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 };
[51b73452]189
[b87a5ed]190 OperatorNode( Type t );
191 OperatorNode( const OperatorNode &other );
192 virtual ~OperatorNode();
[51b73452]193
[b87a5ed]194 virtual OperatorNode *clone() const { return new OperatorNode( *this ); }
[51b73452]195
[59db689]196 Type get_type() const;
197 const char *get_typename() const;
[51b73452]198
[b87a5ed]199 virtual void print( std::ostream &, int indent = 0) const;
200 virtual void printOneLine( std::ostream &, int indent = 0) const;
[51b73452]201
[b87a5ed]202 virtual Expression *build() const { return 0; }
[bdd516a]203 private:
[b87a5ed]204 Type type;
[51b73452]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;
[51b73452]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
[51b73452]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 ); }
[51b73452]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;
[51b73452]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 ); }
[51b73452]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;
[51b73452]319
[bdd516a]320 private:
[b87a5ed]321 StatementNode *body;
[51b73452]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 };
332 enum Aggregate { Struct, Union, Context };
[b87a5ed]333 enum TypeClass { Type, Dtype, Ftype };
334
[974906e2]335 static const char *storageName[];
[b87a5ed]336 static const char *qualifierName[];
337 static const char *basicTypeName[];
338 static const char *modifierName[];
[68cd1ce]339 static const char *aggregateName[];
[b87a5ed]340 static const char *typeClassName[];
341
[7f5566b]342 static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle = false );
[b87a5ed]343 static DeclarationNode *newQualifier( Qualifier );
344 static DeclarationNode *newStorageClass( StorageClass );
345 static DeclarationNode *newBasicType( BasicType );
346 static DeclarationNode *newModifier( Modifier );
347 static DeclarationNode *newForall( DeclarationNode *);
348 static DeclarationNode *newFromTypedef( std::string *);
[2871210]349 static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields );
[b87a5ed]350 static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants );
351 static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant );
352 static DeclarationNode *newName( std::string *);
[59db689]353 static DeclarationNode *newFromTypeGen( std::string *, ExpressionNode *params );
[b87a5ed]354 static DeclarationNode *newTypeParam( TypeClass, std::string *);
355 static DeclarationNode *newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts );
356 static DeclarationNode *newContextUse( std::string *name, ExpressionNode *params );
357 static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams );
358 static DeclarationNode *newPointer( DeclarationNode *qualifiers );
359 static DeclarationNode *newArray( ExpressionNode *size, DeclarationNode *qualifiers, bool isStatic );
360 static DeclarationNode *newVarArray( DeclarationNode *qualifiers );
361 static DeclarationNode *newBitfield( ExpressionNode *size );
362 static DeclarationNode *newTuple( DeclarationNode *members );
363 static DeclarationNode *newTypeof( ExpressionNode *expr );
[59db689]364 static DeclarationNode *newAttr( std::string *, ExpressionNode *expr );
365 static DeclarationNode *newAttr( std::string *, DeclarationNode *type );
[b87a5ed]366
367 DeclarationNode *addQualifiers( DeclarationNode *);
368 DeclarationNode *copyStorageClasses( DeclarationNode *);
369 DeclarationNode *addType( DeclarationNode *);
370 DeclarationNode *addTypedef();
371 DeclarationNode *addAssertions( DeclarationNode *);
372 DeclarationNode *addName( std::string *);
373 DeclarationNode *addBitfield( ExpressionNode *size );
374 DeclarationNode *addVarArgs();
375 DeclarationNode *addFunctionBody( StatementNode *body );
376 DeclarationNode *addOldDeclList( DeclarationNode *list );
377 DeclarationNode *addPointer( DeclarationNode *qualifiers );
378 DeclarationNode *addArray( DeclarationNode *array );
379 DeclarationNode *addNewPointer( DeclarationNode *pointer );
380 DeclarationNode *addNewArray( DeclarationNode *array );
381 DeclarationNode *addParamList( DeclarationNode *list );
382 DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions
383 DeclarationNode *addInitializer( InitializerNode *init );
384
385 DeclarationNode *cloneType( std::string *newName );
386 DeclarationNode *cloneType( DeclarationNode *existing );
387 DeclarationNode *cloneType( int ) { return cloneType( ( std::string *)0 ); }
388 DeclarationNode *cloneBaseType( std::string *newName );
389 DeclarationNode *cloneBaseType( DeclarationNode *newdecl );
390
[de62360d]391 DeclarationNode *appendList( DeclarationNode * );
[b87a5ed]392
393 DeclarationNode *clone() const;
394 void print( std::ostream &, int indent = 0 ) const;
395 void printList( std::ostream &, int indent = 0 ) const;
396
397 Declaration *build() const;
398 ::Type *buildType() const;
399
400 bool get_hasEllipsis() const;
[5f2f2d7]401 const std::string &get_name() const { return name; }
[b87a5ed]402 LinkageSpec::Type get_linkage() const { return linkage; }
403 DeclarationNode *extractAggregate() const;
404
405 DeclarationNode();
406 ~DeclarationNode();
[bdd516a]407 private:
[68cd1ce]408 StorageClass buildStorageClass() const;
[de62360d]409 bool buildFuncSpecifier( StorageClass key ) const;
[b87a5ed]410
411 TypeData *type;
412 std::string name;
413 std::list< StorageClass > storageClasses;
[1db21619]414 std::list< std::string > attributes;
[b87a5ed]415 ExpressionNode *bitfieldWidth;
416 InitializerNode *initializer;
417 bool hasEllipsis;
418 LinkageSpec::Type linkage;
419
420 static UniqueName anonymous;
[1db21619]421}; // DeclarationNode
[51b73452]422
423class StatementNode : public ParseNode {
[bdd516a]424 public:
[974906e2]425 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru,
[b87a5ed]426 While, Do, For,
427 Goto, Continue, Break, Return, Throw,
428 Try, Catch, Finally, Asm,
429 Decl
430 };
[51b73452]431
[59db689]432 StatementNode();
[7f5566b]433 StatementNode( const std::string *name );
434 StatementNode( Type t, ExpressionNode *control = 0, StatementNode *block = 0 );
435 StatementNode( Type t, std::string *target );
[b87a5ed]436 StatementNode( DeclarationNode *decl );
[51b73452]437
[59db689]438 ~StatementNode();
[51b73452]439
[59db689]440 static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false );
[51b73452]441
[1db21619]442 StatementNode *set_block( StatementNode *b ) { block = b; return this; }
443 StatementNode *get_block() const { return block; }
444
445 void set_control( ExpressionNode *c ) { control = c; }
446 ExpressionNode *get_control() const { return control; }
[51b73452]447
[1db21619]448 StatementNode::Type get_type() const { return type; }
[51b73452]449
[59db689]450 StatementNode *add_label( const std::string * );
[1db21619]451 const std::list<std::string> &get_labels() const { return labels; }
[51b73452]452
[b87a5ed]453 void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; }
454 void setCatchRest( bool newVal ) { isCatchRest = newVal; }
[51b73452]455
[b87a5ed]456 std::string get_target() const;
[51b73452]457
[b87a5ed]458 StatementNode *add_controlexp( ExpressionNode * );
459 StatementNode *append_block( StatementNode * );
460 StatementNode *append_last_case( StatementNode * );
[51b73452]461
[b87a5ed]462 void print( std::ostream &, int indent = 0) const;
463 virtual StatementNode *clone() const;
464 virtual Statement *build() const;
[bdd516a]465 private:
[b87a5ed]466 static const char *StType[];
467 Type type;
468 ExpressionNode *control;
469 StatementNode *block;
[1db21619]470 std::list<std::string> labels;
[b87a5ed]471 std::string *target; // target label for jump statements
472 DeclarationNode *decl;
473 bool isCatchRest;
[1db21619]474}; // StatementNode
[51b73452]475
476class CompoundStmtNode : public StatementNode {
[bdd516a]477 public:
[59db689]478 CompoundStmtNode();
479 CompoundStmtNode( const std::string * );
[b87a5ed]480 CompoundStmtNode( StatementNode * );
481 ~CompoundStmtNode();
[51b73452]482
[b87a5ed]483 void add_statement( StatementNode * );
[51b73452]484
[b87a5ed]485 void print( std::ostream &, int indent = 0 ) const;
486 virtual Statement *build() const;
[bdd516a]487 private:
[b87a5ed]488 StatementNode *first, *last;
[51b73452]489};
490
[7f5566b]491class AsmStmtNode : public StatementNode {
492 public:
493 AsmStmtNode( Type, bool voltile, ConstantNode *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ConstantNode *clobber = 0, LabelNode *gotolabels = 0 );
494 ~AsmStmtNode();
495
496 void print( std::ostream &, int indent = 0 ) const;
497 Statement *build() const;
498 private:
499 bool voltile;
500 ConstantNode *instruction;
501 ExpressionNode *output, *input;
502 ConstantNode *clobber;
503 std::list<std::string> gotolabels;
504};
505
[51b73452]506class NullStmtNode : public CompoundStmtNode {
[bdd516a]507 public:
[b87a5ed]508 Statement *build() const;
[7f5566b]509 void print( std::ostream &, int indent = 0 ) const;
[51b73452]510};
511
512class InitializerNode : public ParseNode {
[bdd516a]513 public:
[b87a5ed]514 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 );
515 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 );
516 ~InitializerNode();
[51b73452]517
[b87a5ed]518 ExpressionNode *get_expression() const { return expr; }
[51b73452]519
[b87a5ed]520 InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; }
521 ExpressionNode *get_designators() const { return designator; }
[51b73452]522
[974906e2]523 InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }
524 bool get_maybeConstructed() const { return maybeConstructed; }
525
[b87a5ed]526 InitializerNode *next_init() const { return kids; }
[51b73452]527
[b87a5ed]528 void print( std::ostream &, int indent = 0 ) const;
529 void printOneLine( std::ostream & ) const;
[51b73452]530
[b87a5ed]531 virtual Initializer *build() const;
[bdd516a]532 private:
[b87a5ed]533 ExpressionNode *expr;
534 bool aggregate;
535 ExpressionNode *designator; // may be list
536 InitializerNode *kids;
[974906e2]537 bool maybeConstructed;
[51b73452]538};
539
540template< typename SynTreeType, typename NodeType >
[b87a5ed]541void buildList( const NodeType *firstNode, std::list< SynTreeType *> &outputList ) {
542 SemanticError errors;
543 std::back_insert_iterator< std::list< SynTreeType *> > out( outputList );
544 const NodeType *cur = firstNode;
545
546 while ( cur ) {
547 try {
548 SynTreeType *result = dynamic_cast< SynTreeType *>( cur->build() );
549 if ( result ) {
550 *out++ = result;
551 } else {
552 } // if
553 } catch( SemanticError &e ) {
554 errors.append( e );
555 } // try
556 cur = dynamic_cast< NodeType *>( cur->get_link() );
557 } // while
[a32b204]558 if ( ! errors.isEmpty() ) {
[b87a5ed]559 throw errors;
560 } // if
[51b73452]561}
562
563// in DeclarationNode.cc
[59db689]564void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList );
[bdd516a]565void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType *> &outputList );
[59db689]566void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList );
[51b73452]567
568// in ExpressionNode.cc
569ExpressionNode *flattenCommas( ExpressionNode *list );
570ExpressionNode *tupleContents( ExpressionNode *tuple );
571
[bdd516a]572#endif // PARSENODE_H
[51b73452]573
574// Local Variables: //
[b87a5ed]575// tab-width: 4 //
576// mode: c++ //
577// compile-command: "make install" //
[51b73452]578// End: //
Note: See TracBrowser for help on using the repository browser.