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

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay 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 3bb195cb was dae881f, checked in by Thierry Delisle <tdelisle@…>, 9 years ago

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

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