Changes in src/Parser/ParseNode.h [658fafe4:e869d663]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
r658fafe4 re869d663 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // ParseNode.h -- 7 // ParseNode.h -- 8 8 // 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:28:16 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun Jul 24 02:17:00 201613 // Update Count : 26911 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Aug 12 13:27:11 2015 13 // Update Count : 172 14 14 // 15 15 … … 20 20 #include <list> 21 21 #include <iterator> 22 #include <memory> 23 24 #include "Common/utility.h" 22 23 #include "utility.h" 25 24 #include "Parser/LinkageSpec.h" 26 25 #include "SynTree/Type.h" 27 #include "SynTree/Expression.h"28 26 //#include "SynTree/Declaration.h" 29 #include "Common/UniqueName.h" 30 #include "SynTree/Label.h" 27 #include "UniqueName.h" 31 28 32 29 class ExpressionNode; … … 43 40 ParseNode(); 44 41 ParseNode( const std::string * ); 45 ParseNode( const std::string & ); 42 ParseNode( const std::string & ); // for copy constructing subclasses 46 43 virtual ~ParseNode(); 47 44 48 ParseNode *get_link() const { return next; }45 ParseNode *get_link() const; 49 46 ParseNode *get_last(); 50 47 ParseNode *set_link( ParseNode * ); … … 62 59 protected: 63 60 std::string name; 61 ParseNode *next; 64 62 static int indent_by; 65 ParseNode *next;66 63 }; 67 64 … … 77 74 virtual ExpressionNode *clone() const = 0; 78 75 79 //virtual CommaExprNode *add_to_list( ExpressionNode * );76 virtual CommaExprNode *add_to_list( ExpressionNode * ); 80 77 81 78 ExpressionNode *get_argName() const { return argName; } 82 79 ExpressionNode *set_argName( const std::string *aName ); 83 80 ExpressionNode *set_argName( ExpressionNode *aDesignator ); 84 bool get_extension() const { return extension; }85 ExpressionNode *set_extension( bool exten ) { extension = exten; return this; }86 81 87 82 virtual void print( std::ostream &, int indent = 0) const = 0; … … 92 87 void printDesignation ( std::ostream &, int indent = 0) const; 93 88 private: 94 ExpressionNode *argName = 0; 95 bool extension = false; 96 }; 97 98 template< typename T > 99 struct 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 } 89 ExpressionNode *argName; 109 90 }; 110 91 … … 126 107 enum Type { Integer, Float, Character, String }; 127 108 128 ConstantNode( ConstantExpr * ); 129 ConstantNode( const ConstantNode &other ) : expr( other.expr->clone() ) {}; 130 ~ConstantNode() { delete expr; } 109 ConstantNode( Type, std::string * ); 110 ~ConstantNode() { delete &value; } 131 111 132 112 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; 135 113 Type get_type( void ) const { return type; } 114 virtual void print( std::ostream &, int indent = 0) const; 115 virtual void printOneLine( std::ostream &, int indent = 0) const; 116 117 const std::string &get_value() const { return value; } 136 118 ConstantNode *appendstr( const std::string *newValue ); 137 119 138 120 Expression *build() const; 139 121 private: 140 ConstantExpr *expr; 141 }; 142 143 ConstantNode *makeConstantInteger( std::string & ); 144 ConstantNode *makeConstantFloat( std::string & ); 145 ConstantNode *makeConstantChar( std::string & ); 146 ConstantNode *makeConstantStr( std::string & ); 122 Type type; 123 BasicType::Kind btype; 124 std::string &value; 125 }; 147 126 148 127 class VarRefNode : public ExpressionNode { … … 195 174 class OperatorNode : public ExpressionNode { 196 175 public: 197 enum Type { TupleC, Comma, TupleFieldSel, // n-adic 198 // triadic 199 Cond, NCond, 200 // diadic 201 SizeOf, AlignOf, OffsetOf, Attr, Plus, Minus, Mul, Div, Mod, Or, And, 202 BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, 203 Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn, 204 Index, FieldSel, PFieldSel, Range, 205 // monadic 206 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress, 207 Ctor, Dtor, 176 enum Type { TupleC, Comma, TupleFieldSel, 177 Cond, NCond, 178 SizeOf, AlignOf, Attr, CompLit, Plus, Minus, Mul, Div, Mod, Or, And, 179 BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, 180 Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, 181 ERAssn, OrAssn, Index, FieldSel, PFieldSel, Range, 182 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress 208 183 }; 209 184 … … 223 198 private: 224 199 Type type; 200 static const char *OpName[]; 225 201 }; 226 202 … … 286 262 virtual void printOneLine( std::ostream &, int indent = 0) const; 287 263 288 const std::list< Label> &get_labels() const { return labels; };264 const std::list< std::string > &get_labels() const { return labels; }; 289 265 void append_label( std::string *label ) { labels.push_back( *label ); delete label; } 290 266 private: 291 std::list< Label > labels; 267 std::list< std::string > labels; 268 }; 269 270 class CommaExprNode : public CompositeExprNode { 271 public: 272 CommaExprNode(); 273 CommaExprNode( ExpressionNode * ); 274 CommaExprNode( ExpressionNode *, ExpressionNode * ); 275 CommaExprNode( const CommaExprNode &other ); 276 277 virtual CommaExprNode *add_to_list( ExpressionNode * ); 278 virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); } 292 279 }; 293 280 … … 319 306 ValofExprNode( const ValofExprNode &other ); 320 307 ~ValofExprNode(); 321 308 322 309 virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); } 323 310 … … 339 326 enum BasicType { Char, Int, Float, Double, Void, Bool, Complex, Imaginary }; 340 327 enum Modifier { Signed, Unsigned, Short, Long }; 341 enum Aggregate { Struct, Union, Trait };328 enum Aggregate { Struct, Union, Context }; 342 329 enum TypeClass { Type, Dtype, Ftype }; 343 enum BuiltinType { Valist }; 344 345 static const char *storageName[]; 330 331 static const char *storageName[]; 346 332 static const char *qualifierName[]; 347 333 static const char *basicTypeName[]; … … 349 335 static const char *aggregateName[]; 350 336 static const char *typeClassName[]; 351 static const char *builtinTypeName[];352 337 353 338 static DeclarationNode *newFunction( std::string *name, DeclarationNode *ret, DeclarationNode *param, StatementNode *body, bool newStyle = false ); … … 358 343 static DeclarationNode *newForall( DeclarationNode *); 359 344 static DeclarationNode *newFromTypedef( std::string *); 360 static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields , bool body);345 static DeclarationNode *newAggregate( Aggregate kind, const std::string *name, ExpressionNode *actuals, DeclarationNode *fields ); 361 346 static DeclarationNode *newEnum( std::string *name, DeclarationNode *constants ); 362 347 static DeclarationNode *newEnumConstant( std::string *name, ExpressionNode *constant ); … … 364 349 static DeclarationNode *newFromTypeGen( std::string *, ExpressionNode *params ); 365 350 static DeclarationNode *newTypeParam( TypeClass, std::string *); 366 static DeclarationNode *new Trait( std::string *name, DeclarationNode *params, DeclarationNode *asserts );367 static DeclarationNode *new TraitUse( std::string *name, ExpressionNode *params );351 static DeclarationNode *newContext( std::string *name, DeclarationNode *params, DeclarationNode *asserts ); 352 static DeclarationNode *newContextUse( std::string *name, ExpressionNode *params ); 368 353 static DeclarationNode *newTypeDecl( std::string *name, DeclarationNode *typeParams ); 369 354 static DeclarationNode *newPointer( DeclarationNode *qualifiers ); … … 375 360 static DeclarationNode *newAttr( std::string *, ExpressionNode *expr ); 376 361 static DeclarationNode *newAttr( std::string *, DeclarationNode *type ); 377 static DeclarationNode *newBuiltinType( BuiltinType );378 362 379 363 DeclarationNode *addQualifiers( DeclarationNode *); … … 414 398 LinkageSpec::Type get_linkage() const { return linkage; } 415 399 DeclarationNode *extractAggregate() const; 416 ExpressionNode *get_enumeratorValue() const { return enumeratorValue; }417 418 bool get_extension() const { return extension; }419 DeclarationNode *set_extension( bool exten ) { extension = exten; return this; }420 400 421 401 DeclarationNode(); … … 430 410 std::list< std::string > attributes; 431 411 ExpressionNode *bitfieldWidth; 432 ExpressionNode *enumeratorValue;433 412 InitializerNode *initializer; 434 413 bool hasEllipsis; 435 414 LinkageSpec::Type linkage; 436 bool extension = false;437 415 438 416 static UniqueName anonymous; … … 441 419 class StatementNode : public ParseNode { 442 420 public: 443 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, 421 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, 444 422 While, Do, For, 445 423 Goto, Continue, Break, Return, Throw, … … 474 452 std::string get_target() const; 475 453 476 //StatementNode *add_controlexp( ExpressionNode * );454 StatementNode *add_controlexp( ExpressionNode * ); 477 455 StatementNode *append_block( StatementNode * ); 478 456 StatementNode *append_last_case( StatementNode * ); … … 519 497 ExpressionNode *output, *input; 520 498 ConstantNode *clobber; 521 std::list< Label > gotolabels; 499 std::list<std::string> gotolabels; 500 }; 501 502 class NullStmtNode : public CompoundStmtNode { 503 public: 504 Statement *build() const; 505 void print( std::ostream &, int indent = 0 ) const; 522 506 }; 523 507 … … 533 517 ExpressionNode *get_designators() const { return designator; } 534 518 535 InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }536 bool get_maybeConstructed() const { return maybeConstructed; }537 538 519 InitializerNode *next_init() const { return kids; } 539 520 … … 546 527 bool aggregate; 547 528 ExpressionNode *designator; // may be list 548 InitializerNode *kids;549 bool maybeConstructed;550 };551 552 class CompoundLiteralNode : public ExpressionNode {553 public:554 CompoundLiteralNode( DeclarationNode *type, InitializerNode *kids );555 CompoundLiteralNode( const CompoundLiteralNode &type );556 ~CompoundLiteralNode();557 558 virtual CompoundLiteralNode *clone() const;559 560 DeclarationNode *get_type() const { return type; }561 CompoundLiteralNode *set_type( DeclarationNode *t ) { type = t; return this; }562 563 InitializerNode *get_initializer() const { return kids; }564 CompoundLiteralNode *set_initializer( InitializerNode *k ) { kids = k; return this; }565 566 void print( std::ostream &, int indent = 0 ) const;567 void printOneLine( std::ostream &, int indent = 0 ) const;568 569 virtual Expression *build() const;570 private:571 DeclarationNode *type;572 529 InitializerNode *kids; 573 530 }; … … 581 538 while ( cur ) { 582 539 try { 583 // SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::result_of<decltype(&NodeType::build)(NodeType)>::type>( cur ) ); 584 SynTreeType *result = dynamic_cast< SynTreeType *>( maybeBuild<typename std::pointer_traits<decltype(cur->build())>::element_type>( cur ) ); 540 SynTreeType *result = dynamic_cast< SynTreeType *>( cur->build() ); 585 541 if ( result ) { 586 542 *out++ = result;
Note:
See TracChangeset
for help on using the changeset viewer.