Changeset 7527e63 for src/Parser/ParseNode.h
- Timestamp:
- Aug 16, 2016, 3:20:06 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 1f6d4624
- Parents:
- 950f7a7 (diff), 7880579 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
r950f7a7 r7527e63 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 12 20:50:21201613 // Update Count : 26112 // Last Modified On : Tue Aug 16 08:37:47 2016 13 // Update Count : 527 14 14 // 15 15 … … 22 22 #include <memory> 23 23 24 #include "Common/utility.h"25 24 #include "Parser/LinkageSpec.h" 26 25 #include "SynTree/Type.h" 27 26 #include "SynTree/Expression.h" 28 //#include "SynTree/Declaration.h" 27 #include "SynTree/Statement.h" 28 #include "SynTree/Label.h" 29 #include "Common/utility.h" 29 30 #include "Common/UniqueName.h" 30 #include "SynTree/Label.h" 31 32 class ExpressionNode; 33 class CompositeExprNode; 34 class CommaExprNode; 31 35 32 class StatementNode; 36 33 class CompoundStmtNode; 37 34 class DeclarationNode; 35 class ExpressionNode; 38 36 class InitializerNode; 39 37 40 // Builder 38 //############################################################################## 39 41 40 class ParseNode { 42 41 public: … … 45 44 ParseNode( const std::string & ); // for copy constructing subclasses 46 45 virtual ~ParseNode(); 47 48 ParseNode *get_link() const { return next; } 46 virtual ParseNode *clone() const { assert( false ); return nullptr; }; 47 48 ParseNode *get_next() const { return next; } 49 ParseNode *set_next( ParseNode *newlink ) { next = newlink; return this; } 49 50 ParseNode *get_last(); 50 ParseNode *set_link( ParseNode * ); 51 void set_next( ParseNode *newlink ) { next = newlink; } 52 53 virtual ParseNode *clone() const { return 0; }; 51 ParseNode *set_last( ParseNode * ); 54 52 55 53 const std::string &get_name() const { return name; } 56 54 void set_name( const std::string &newValue ) { name = newValue; } 57 55 58 virtual void print( std::ostream &, int indent = 0 ) const; 59 virtual void printList( std::ostream &, int indent = 0 ) const; 60 61 ParseNode &operator,( ParseNode &); 62 protected: 56 virtual void print( std::ostream &os, int indent = 0 ) const {} 57 virtual void printList( std::ostream &os, int indent = 0 ) const; 58 private: 59 static int indent_by; 60 61 ParseNode *next; 63 62 std::string name; 64 static int indent_by; 65 ParseNode *next; 66 }; 67 68 ParseNode *mkList( ParseNode & ); 63 }; // ParseNode 64 65 //############################################################################## 66 67 class InitializerNode : public ParseNode { 68 public: 69 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 ); 70 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); 71 ~InitializerNode(); 72 73 ExpressionNode *get_expression() const { return expr; } 74 75 InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } 76 ExpressionNode *get_designators() const { return designator; } 77 78 InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; } 79 bool get_maybeConstructed() const { return maybeConstructed; } 80 81 InitializerNode *next_init() const { return kids; } 82 83 void print( std::ostream &os, int indent = 0 ) const; 84 void printOneLine( std::ostream & ) const; 85 86 virtual Initializer *build() const; 87 private: 88 ExpressionNode *expr; 89 bool aggregate; 90 ExpressionNode *designator; // may be list 91 InitializerNode *kids; 92 bool maybeConstructed; 93 }; 94 95 //############################################################################## 69 96 70 97 class ExpressionNode : public ParseNode { 71 98 public: 72 ExpressionNode( );73 ExpressionNode( const std::string * );99 ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {} 100 ExpressionNode( Expression * expr, const std::string *name ) : ParseNode( name ), expr( expr ) {} 74 101 ExpressionNode( const ExpressionNode &other ); 75 virtual ~ExpressionNode() { delete argName; } // cannot delete argName because it might be referenced elsewhere 76 77 virtual ExpressionNode *clone() const = 0; 78 79 virtual CommaExprNode *add_to_list( ExpressionNode * ); 80 81 ExpressionNode *get_argName() const { return argName; } 82 ExpressionNode *set_argName( const std::string *aName ); 83 ExpressionNode *set_argName( ExpressionNode *aDesignator ); 102 virtual ~ExpressionNode() {} 103 104 virtual ExpressionNode *clone() const { assert( false ); return nullptr; } 105 84 106 bool get_extension() const { return extension; } 85 107 ExpressionNode *set_extension( bool exten ) { extension = exten; return this; } 86 108 87 virtual void print( std::ostream &, int indent = 0) const = 0; 88 virtual void printOneLine( std::ostream &, int indent = 0) const = 0; 89 90 virtual Expression *build() const = 0; 91 protected: 92 void printDesignation ( std::ostream &, int indent = 0) const; 93 private: 94 ExpressionNode *argName = 0; 109 virtual void print( std::ostream &os, int indent = 0 ) const {} 110 virtual void printOneLine( std::ostream &os, int indent = 0 ) const {} 111 112 virtual Expression *build() const { return expr; } 113 private: 95 114 bool extension = false; 115 Expression *expr; 96 116 }; 97 117 98 118 template< typename T > 99 struct maybeBuild_t< Expression, T> {119 struct maybeBuild_t< Expression, T > { 100 120 static inline Expression * doit( const T *orig ) { 101 121 if ( orig ) { … … 104 124 return p; 105 125 } else { 106 return 0;126 return nullptr; 107 127 } // if 108 128 } 109 129 }; 110 130 111 // NullExprNode is used in tuples as a place-holder where a tuple component is omitted e.g., [ 2, , 3 ] 112 class NullExprNode : public ExpressionNode { 113 public: 114 NullExprNode(); 115 116 virtual NullExprNode *clone() const; 117 118 virtual void print( std::ostream &, int indent = 0) const; 119 virtual void printOneLine( std::ostream &, int indent = 0) const; 120 121 virtual Expression *build() const; 122 }; 123 124 class ConstantNode : public ExpressionNode { 125 public: 126 enum Type { Integer, Float, Character, String }; 127 128 ConstantNode( ConstantExpr * ); 129 ConstantNode( const ConstantNode &other ) : expr( other.expr->clone() ) {}; 130 ~ConstantNode() { delete expr; } 131 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; 135 136 ConstantNode *appendstr( const std::string *newValue ); 137 138 Expression *build() const; 139 private: 140 ConstantExpr *expr; 141 }; 142 143 ConstantNode *makeConstant( ConstantNode::Type, std::string * ); 144 ConstantNode *makeConstantStr( ConstantNode::Type type, std::string *str ); 145 146 class VarRefNode : public ExpressionNode { 147 public: 148 VarRefNode(); 149 VarRefNode( const std::string *, bool isLabel = false ); 150 VarRefNode( const VarRefNode &other ); 151 152 virtual Expression *build() const ; 153 154 virtual VarRefNode *clone() const { return new VarRefNode( *this ); } 155 156 virtual void print( std::ostream &, int indent = 0 ) const; 157 virtual void printOneLine( std::ostream &, int indent = 0 ) const; 158 private: 159 bool isLabel; 160 }; 161 162 class DesignatorNode : public ExpressionNode { 163 public: 164 DesignatorNode( ExpressionNode *expr, bool isArrayIndex = false ); 165 DesignatorNode( const DesignatorNode &other ); 166 167 virtual Expression *build() const ; 168 virtual DesignatorNode *clone() const { return new DesignatorNode( *this ); } 169 170 virtual void print( std::ostream &, int indent = 0 ) const; 171 virtual void printOneLine( std::ostream &, int indent = 0 ) const; 172 private: 173 bool isArrayIndex; 174 }; 175 176 class TypeValueNode : public ExpressionNode { 177 public: 178 TypeValueNode( DeclarationNode * ); 179 TypeValueNode( const TypeValueNode &other ); 180 181 DeclarationNode *get_decl() const { return decl; } 182 183 virtual Expression *build() const ; 184 185 virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); } 186 187 virtual void print( std::ostream &, int indent = 0) const; 188 virtual void printOneLine( std::ostream &, int indent = 0) const; 189 private: 190 DeclarationNode *decl; 191 }; 192 193 class OperatorNode : public ExpressionNode { 194 public: 195 enum Type { TupleC, Comma, TupleFieldSel, // n-adic 196 // triadic 197 Cond, NCond, 198 // diadic 199 SizeOf, AlignOf, OffsetOf, Attr, Plus, Minus, Mul, Div, Mod, Or, And, 200 BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, 201 Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn, 202 Index, FieldSel, PFieldSel, Range, 203 // monadic 204 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress, 205 Ctor, Dtor, 206 }; 207 208 OperatorNode( Type t ); 209 OperatorNode( const OperatorNode &other ); 210 virtual ~OperatorNode(); 211 212 virtual OperatorNode *clone() const { return new OperatorNode( *this ); } 213 214 Type get_type() const; 215 const char *get_typename() const; 216 217 virtual void print( std::ostream &, int indent = 0) const; 218 virtual void printOneLine( std::ostream &, int indent = 0) const; 219 220 virtual Expression *build() const { return 0; } 221 private: 222 Type type; 223 }; 224 225 class CompositeExprNode : public ExpressionNode { 226 public: 227 CompositeExprNode(); 228 CompositeExprNode( const std::string * ); 229 CompositeExprNode( ExpressionNode *f, ExpressionNode *args = 0 ); 230 CompositeExprNode( ExpressionNode *f, ExpressionNode *arg1, ExpressionNode *arg2 ); 231 CompositeExprNode( const CompositeExprNode &other ); 232 virtual ~CompositeExprNode(); 233 234 virtual CompositeExprNode *clone() const { return new CompositeExprNode( *this ); } 235 virtual Expression *build() const; 236 237 virtual void print( std::ostream &, int indent = 0) const; 238 virtual void printOneLine( std::ostream &, int indent = 0) const; 239 240 void set_function( ExpressionNode * ); 241 void set_args( ExpressionNode * ); 242 243 void add_arg( ExpressionNode * ); 244 245 ExpressionNode *get_function() const; 246 ExpressionNode *get_args() const; 247 private: 248 ExpressionNode *function; 249 ExpressionNode *arguments; 250 }; 251 252 class AsmExprNode : public ExpressionNode { 253 public: 254 AsmExprNode(); 255 AsmExprNode( ExpressionNode *inout, ConstantNode *constraint, ExpressionNode *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} 256 virtual ~AsmExprNode() { delete inout; delete constraint; delete operand; } 257 258 virtual AsmExprNode *clone() const { return new AsmExprNode( *this ); } 259 virtual Expression *build() const; 260 261 virtual void print( std::ostream &, int indent = 0) const; 262 virtual void printOneLine( std::ostream &, int indent = 0) const; 263 264 ExpressionNode *get_inout() const { return inout; }; 265 void set_inout( ExpressionNode *newValue ) { inout = newValue; } 266 267 ConstantNode *get_constraint() const { return constraint; }; 268 void set_constraint( ConstantNode *newValue ) { constraint = newValue; } 269 270 ExpressionNode *get_operand() const { return operand; }; 271 void set_operand( ExpressionNode *newValue ) { operand = newValue; } 272 private: 273 ExpressionNode *inout; 274 ConstantNode *constraint; 275 ExpressionNode *operand; 276 }; 277 278 class LabelNode : public ExpressionNode { 279 public: 280 virtual Expression *build() const { return NULL; } 281 virtual LabelNode *clone() const { return new LabelNode( *this ); } 282 283 virtual void print( std::ostream &, int indent = 0) const; 284 virtual void printOneLine( std::ostream &, int indent = 0) const; 285 286 const std::list< Label > &get_labels() const { return labels; }; 287 void append_label( std::string *label ) { labels.push_back( *label ); delete label; } 288 private: 131 enum class OperKinds { 132 // diadic 133 SizeOf, AlignOf, OffsetOf, Plus, Minus, Mul, Div, Mod, Or, And, 134 BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, 135 Assign, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn, 136 Index, Range, 137 // monadic 138 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, LabelAddress, 139 Ctor, Dtor, 140 }; 141 142 struct LabelNode { 289 143 std::list< Label > labels; 290 144 }; 291 145 292 class CommaExprNode : public CompositeExprNode { 293 public: 294 CommaExprNode(); 295 CommaExprNode( ExpressionNode * ); 296 CommaExprNode( ExpressionNode *, ExpressionNode * ); 297 CommaExprNode( const CommaExprNode &other ); 298 299 virtual CommaExprNode *add_to_list( ExpressionNode * ); 300 virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); } 301 }; 302 303 class ForCtlExprNode : public ExpressionNode { 304 public: 305 ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError ); 306 ForCtlExprNode( const ForCtlExprNode &other ); 307 ~ForCtlExprNode(); 308 309 StatementNode *get_init() const { return init; } 310 ExpressionNode *get_condition() const { return condition; } 311 ExpressionNode *get_change() const { return change; } 312 313 virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); } 314 virtual Expression *build() const; 315 316 virtual void print( std::ostream &, int indent = 0 ) const; 317 virtual void printOneLine( std::ostream &, int indent = 0 ) const; 318 private: 319 StatementNode *init; 320 ExpressionNode *condition; 321 ExpressionNode *change; 322 }; 323 324 class ValofExprNode : public ExpressionNode { 325 public: 326 ValofExprNode(); 327 ValofExprNode( StatementNode *s = 0 ); 328 ValofExprNode( const ValofExprNode &other ); 329 ~ValofExprNode(); 330 331 virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); } 332 333 StatementNode *get_body() const { return body; } 334 void print( std::ostream &, int indent = 0 ) const; 335 void printOneLine( std::ostream &, int indent = 0 ) const; 336 Expression *build() const; 337 338 private: 339 StatementNode *body; 340 }; 146 Expression *build_constantInteger( std::string &str ); 147 Expression *build_constantFloat( std::string &str ); 148 Expression *build_constantChar( std::string &str ); 149 ConstantExpr *build_constantStr( std::string &str ); 150 151 NameExpr *build_varref( const std::string *name, bool labelp = false ); 152 Expression *build_typevalue( DeclarationNode *decl ); 153 154 Expression *build_cast( DeclarationNode * decl_node, ExpressionNode *expr_node ); 155 Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member ); 156 Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member ); 157 Expression *build_addressOf( ExpressionNode *expr_node ); 158 Expression *build_sizeOfexpr( ExpressionNode *expr_node ); 159 Expression *build_sizeOftype( DeclarationNode *decl_node ); 160 Expression *build_alignOfexpr( ExpressionNode *expr_node ); 161 Expression *build_alignOftype( DeclarationNode *decl_node ); 162 Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ); 163 Expression *build_and( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); 164 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ); 165 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ); 166 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ); 167 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); 168 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); 169 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ); 170 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); 171 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ); 172 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ); 173 Expression *build_tuple( ExpressionNode * expr_node = 0 ); 174 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ); 175 Expression *build_range( ExpressionNode * low, ExpressionNode *high ); 176 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ); 177 Expression *build_valexpr( StatementNode *s ); 178 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ); 179 180 //############################################################################## 341 181 342 182 class TypeData; … … 386 226 static DeclarationNode *newBuiltinType( BuiltinType ); 387 227 228 DeclarationNode(); 229 ~DeclarationNode(); 230 DeclarationNode *clone() const; 231 388 232 DeclarationNode *addQualifiers( DeclarationNode *); 389 233 DeclarationNode *copyStorageClasses( DeclarationNode *); … … 401 245 DeclarationNode *addNewArray( DeclarationNode *array ); 402 246 DeclarationNode *addParamList( DeclarationNode *list ); 403 DeclarationNode *addIdList( DeclarationNode *list ); 247 DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions 404 248 DeclarationNode *addInitializer( InitializerNode *init ); 405 249 … … 412 256 DeclarationNode *appendList( DeclarationNode * ); 413 257 414 DeclarationNode *clone() const; 415 void print( std::ostream &, int indent = 0 ) const; 416 void printList( std::ostream &, int indent = 0 ) const; 258 void print( std::ostream &os, int indent = 0 ) const; 259 void printList( std::ostream &os, int indent = 0 ) const; 417 260 418 261 Declaration *build() const; … … 427 270 bool get_extension() const { return extension; } 428 271 DeclarationNode *set_extension( bool exten ) { extension = exten; return this; } 429 430 DeclarationNode();431 ~DeclarationNode();432 272 private: 433 273 StorageClass buildStorageClass() const; … … 448 288 }; // DeclarationNode 449 289 290 Type *buildType( TypeData *type ); 291 292 //############################################################################## 293 450 294 class StatementNode : public ParseNode { 451 295 public: 452 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, 453 While, Do, For, 454 Goto, Continue, Break, Return, Throw, 455 Try, Catch, Finally, Asm, 456 Decl 457 }; 458 459 StatementNode(); 460 StatementNode( const std::string *name ); 461 StatementNode( Type t, ExpressionNode *control = 0, StatementNode *block = 0 ); 462 StatementNode( Type t, std::string *target ); 296 StatementNode() { stmt = nullptr; } 297 StatementNode( Statement *stmt ) : stmt( stmt ) {} 463 298 StatementNode( DeclarationNode *decl ); 464 465 ~StatementNode(); 466 467 static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false ); 468 469 StatementNode *set_block( StatementNode *b ) { block = b; return this; } 470 StatementNode *get_block() const { return block; } 471 472 void set_control( ExpressionNode *c ) { control = c; } 473 ExpressionNode *get_control() const { return control; } 474 475 StatementNode::Type get_type() const { return type; } 476 477 StatementNode *add_label( const std::string * ); 478 const std::list<std::string> &get_labels() const { return labels; } 479 480 void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; } 481 void setCatchRest( bool newVal ) { isCatchRest = newVal; } 482 483 std::string get_target() const; 484 485 StatementNode *add_controlexp( ExpressionNode * ); 486 StatementNode *append_block( StatementNode * ); 487 StatementNode *append_last_case( StatementNode * ); 488 489 void print( std::ostream &, int indent = 0) const; 490 virtual StatementNode *clone() const; 491 virtual Statement *build() const; 492 private: 493 static const char *StType[]; 494 Type type; 495 ExpressionNode *control; 496 StatementNode *block; 497 std::list<std::string> labels; 498 std::string *target; // target label for jump statements 499 DeclarationNode *decl; 500 bool isCatchRest; 299 virtual ~StatementNode() {} 300 301 virtual StatementNode *clone() const { assert( false ); return nullptr; } 302 virtual Statement *build() const { return stmt; } 303 304 virtual StatementNode *add_label( const std::string * name ) { 305 stmt->get_labels().emplace_back( *name ); 306 return this; 307 } 308 309 virtual StatementNode *append_last_case( StatementNode * ); 310 311 virtual void print( std::ostream &os, int indent = 0 ) {} 312 virtual void printList( std::ostream &os, int indent = 0 ) {} 313 private: 314 Statement *stmt; 501 315 }; // StatementNode 502 316 503 class CompoundStmtNode : public StatementNode { 504 public: 505 CompoundStmtNode(); 506 CompoundStmtNode( const std::string * ); 507 CompoundStmtNode( StatementNode * ); 508 ~CompoundStmtNode(); 509 510 void add_statement( StatementNode * ); 511 512 void print( std::ostream &, int indent = 0 ) const; 513 virtual Statement *build() const; 514 private: 515 StatementNode *first, *last; 516 }; 517 518 class AsmStmtNode : public StatementNode { 519 public: 520 AsmStmtNode( Type, bool voltile, ConstantNode *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ConstantNode *clobber = 0, LabelNode *gotolabels = 0 ); 521 ~AsmStmtNode(); 522 523 void print( std::ostream &, int indent = 0 ) const; 524 Statement *build() const; 525 private: 526 bool voltile; 527 ConstantNode *instruction; 528 ExpressionNode *output, *input; 529 ConstantNode *clobber; 530 std::list< Label > gotolabels; 531 }; 532 533 class NullStmtNode : public CompoundStmtNode { 534 public: 535 Statement *build() const; 536 void print( std::ostream &, int indent = 0 ) const; 537 }; 538 539 class InitializerNode : public ParseNode { 540 public: 541 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 ); 542 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); 543 ~InitializerNode(); 544 545 ExpressionNode *get_expression() const { return expr; } 546 547 InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } 548 ExpressionNode *get_designators() const { return designator; } 549 550 InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; } 551 bool get_maybeConstructed() const { return maybeConstructed; } 552 553 InitializerNode *next_init() const { return kids; } 554 555 void print( std::ostream &, int indent = 0 ) const; 556 void printOneLine( std::ostream & ) const; 557 558 virtual Initializer *build() const; 559 private: 560 ExpressionNode *expr; 561 bool aggregate; 562 ExpressionNode *designator; // may be list 563 InitializerNode *kids; 564 bool maybeConstructed; 565 }; 566 567 class 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 581 void print( std::ostream &, int indent = 0 ) const; 582 void printOneLine( std::ostream &, int indent = 0 ) const; 583 584 virtual Expression *build() const; 585 private: 586 DeclarationNode *type; 587 InitializerNode *kids; 588 }; 317 Statement *build_expr( ExpressionNode *ctl ); 318 319 struct ForCtl { 320 ForCtl( ExpressionNode *expr, ExpressionNode *condition, ExpressionNode *change ) : 321 init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {} 322 ForCtl( DeclarationNode *decl, ExpressionNode *condition, ExpressionNode *change ) : 323 init( new StatementNode( decl ) ), condition( condition ), change( change ) {} 324 325 StatementNode *init; 326 ExpressionNode *condition; 327 ExpressionNode *change; 328 }; 329 330 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ); 331 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ); 332 Statement *build_case( ExpressionNode *ctl ); 333 Statement *build_default(); 334 Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind = false ); 335 Statement *build_for( ForCtl *forctl, StatementNode *stmt ); 336 Statement *build_branch( std::string identifier, BranchStmt::Type kind ); 337 Statement *build_computedgoto( ExpressionNode *ctl ); 338 Statement *build_return( ExpressionNode *ctl ); 339 Statement *build_throw( ExpressionNode *ctl ); 340 Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ); 341 Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny = false ); 342 Statement *build_finally( StatementNode *stmt ); 343 Statement *build_compound( StatementNode *first ); 344 Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ExpressionNode *clobber = 0, LabelNode *gotolabels = 0 ); 345 346 //############################################################################## 589 347 590 348 template< typename SynTreeType, typename NodeType > 591 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {349 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) { 592 350 SemanticError errors; 593 std::back_insert_iterator< std::list< SynTreeType * > > out( outputList );351 std::back_insert_iterator< std::list< SynTreeType * > > out( outputList ); 594 352 const NodeType *cur = firstNode; 595 353 596 354 while ( cur ) { 597 355 try { 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 ) );356 // SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) ); 357 SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) ); 600 358 if ( result ) { 601 359 *out++ = result; … … 605 363 errors.append( e ); 606 364 } // try 607 cur = dynamic_cast< NodeType * >( cur->get_link() );365 cur = dynamic_cast< NodeType * >( cur->get_next() ); 608 366 } // while 609 367 if ( ! errors.isEmpty() ) { … … 614 372 // in DeclarationNode.cc 615 373 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ); 616 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList );374 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ); 617 375 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ); 618 619 // in ExpressionNode.cc620 ExpressionNode *flattenCommas( ExpressionNode *list );621 ExpressionNode *tupleContents( ExpressionNode *tuple );622 376 623 377 #endif // PARSENODE_H
Note:
See TracChangeset
for help on using the changeset viewer.