Changeset 04cdd9b for src/Parser/ParseNode.h
- Timestamp:
- Aug 19, 2016, 2:42:04 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, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- e85a8631
- Parents:
- 03da511 (diff), ac71a86 (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
r03da511 r04cdd9b 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 7 09:37:16201613 // Update Count : 33312 // Last Modified On : Thu Aug 18 23:48:37 2016 13 // Update Count : 542 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 31 32 32 class StatementNode; 33 33 class CompoundStmtNode; 34 34 class DeclarationNode; 35 class ExpressionNode; 35 36 class InitializerNode; 36 37 37 // Builder 38 //############################################################################## 39 38 40 class ParseNode { 39 41 public: 40 ParseNode(); 41 ParseNode( const std::string * ); 42 ParseNode( const std::string & ); // for copy constructing subclasses 43 virtual ~ParseNode(); 44 45 ParseNode *get_link() const { return next; } 46 ParseNode *get_last(); 47 ParseNode *set_link( ParseNode * ); 48 void set_next( ParseNode *newlink ) { next = newlink; } 49 50 virtual ParseNode *clone() const { return 0; }; 42 ParseNode() {}; 43 ParseNode( const std::string *name ) : name( *name ) { assert( false ); delete name; } 44 ParseNode( const std::string &name ) : name( name ) { assert( false ); } 45 virtual ~ParseNode() { delete next; }; 46 virtual ParseNode *clone() const = 0; 47 48 ParseNode *get_next() const { return next; } 49 ParseNode *set_next( ParseNode *newlink ) { next = newlink; return this; } 50 ParseNode *get_last() { 51 ParseNode *current; 52 for ( current = this; current->get_next() != 0; current = current->get_next() ); 53 return current; 54 } 55 ParseNode *set_last( ParseNode *newlast ) { 56 if ( newlast != 0 ) get_last()->set_next( newlast ); 57 return this; 58 } 51 59 52 60 const std::string &get_name() const { return name; } 53 61 void set_name( const std::string &newValue ) { name = newValue; } 54 62 55 virtual void print( std::ostream &os, int indent = 0 ) const; 56 virtual void printList( std::ostream &os, int indent = 0 ) const; 57 58 ParseNode &operator,( ParseNode &); 59 protected: 63 virtual void print( std::ostream &os, int indent = 0 ) const {} 64 virtual void printList( std::ostream &os, int indent = 0 ) const {} 65 private: 66 static int indent_by; 67 68 ParseNode *next = nullptr; 60 69 std::string name; 61 static int indent_by; 62 ParseNode *next; 63 }; 64 65 ParseNode *mkList( ParseNode & ); 66 67 //############################################################################## 68 69 class ExpressionNode : public ParseNode { 70 }; // ParseNode 71 72 //############################################################################## 73 74 class InitializerNode : public ParseNode { 70 75 public: 71 ExpressionNode(); 72 ExpressionNode( const std::string * ); 76 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 ); 77 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); 78 ~InitializerNode(); 79 virtual InitializerNode *clone() const { assert( false ); return nullptr; } 80 81 ExpressionNode *get_expression() const { return expr; } 82 83 InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } 84 ExpressionNode *get_designators() const { return designator; } 85 86 InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; } 87 bool get_maybeConstructed() const { return maybeConstructed; } 88 89 InitializerNode *next_init() const { return kids; } 90 91 void print( std::ostream &os, int indent = 0 ) const; 92 void printOneLine( std::ostream & ) const; 93 94 virtual Initializer *build() const; 95 private: 96 ExpressionNode *expr; 97 bool aggregate; 98 ExpressionNode *designator; // may be list 99 InitializerNode *kids; 100 bool maybeConstructed; 101 }; 102 103 //############################################################################## 104 105 class ExpressionNode final : public ParseNode { 106 public: 107 ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {} 108 ExpressionNode( Expression * expr, const std::string *name ) : ParseNode( name ), expr( expr ) {} 73 109 ExpressionNode( const ExpressionNode &other ); 74 virtual ~ExpressionNode() { delete argName; } 75 76 virtual ExpressionNode *clone() const = 0; 77 78 ExpressionNode *get_argName() const { return argName; } 79 ExpressionNode *set_argName( const std::string *aName ); 80 ExpressionNode *set_argName( ExpressionNode *aDesignator ); 110 virtual ~ExpressionNode() {} 111 virtual ExpressionNode *clone() const { assert( false ); return nullptr; } 112 81 113 bool get_extension() const { return extension; } 82 114 ExpressionNode *set_extension( bool exten ) { extension = exten; return this; } 83 115 84 virtual void print( std::ostream &os, int indent = 0) const = 0; 85 virtual void printOneLine( std::ostream &os, int indent = 0) const = 0; 86 87 virtual Expression *build() const = 0; 88 protected: 89 void printDesignation ( std::ostream &os, int indent = 0) const; 116 void print( std::ostream &os, int indent = 0 ) const {} 117 void printOneLine( std::ostream &os, int indent = 0 ) const {} 118 119 template<typename T> 120 bool isExpressionType() const { 121 return nullptr != dynamic_cast<T>(expr.get()); 122 } 123 124 Expression *build() const { return const_cast<ExpressionNode*>(this)->expr.release(); } 90 125 private: 91 ExpressionNode *argName = 0;92 126 bool extension = false; 127 std::unique_ptr<Expression> expr; 93 128 }; 94 129 95 130 template< typename T > 96 struct maybeBuild_t< Expression, T> {131 struct maybeBuild_t< Expression, T > { 97 132 static inline Expression * doit( const T *orig ) { 98 133 if ( orig ) { … … 101 136 return p; 102 137 } else { 103 return 0;138 return nullptr; 104 139 } // if 105 140 } 106 };107 108 //##############################################################################109 110 // NullExprNode is used in tuples as a place-holder where a tuple component is omitted e.g., [ 2, , 3 ]111 class NullExprNode : public ExpressionNode {112 public:113 NullExprNode();114 115 virtual NullExprNode *clone() const;116 117 virtual void print( std::ostream &os, int indent = 0) const;118 virtual void printOneLine( std::ostream &os, int indent = 0) const;119 120 virtual Expression *build() const;121 };122 123 //##############################################################################124 125 class ConstantNode : public ExpressionNode {126 public:127 ConstantNode( ConstantExpr *expr ) : expr( expr ) {}128 ConstantNode( const ConstantNode &other ) : expr( other.expr->clone() ) {}129 virtual ~ConstantNode() {}130 131 virtual ConstantNode *clone() const { assert( false ); return new ConstantNode( *this ); }132 133 ConstantExpr *get_expr() const { return expr; }134 135 virtual void print( std::ostream &os, int indent = 0 ) const {}136 virtual void printOneLine( std::ostream &os, int indent = 0 ) const {}137 138 Expression *build() const { return expr; }139 private:140 ConstantExpr *expr;141 };142 143 ConstantNode *build_constantInteger( std::string &str );144 ConstantNode *build_constantFloat( std::string &str );145 ConstantNode *build_constantChar( std::string &str );146 ConstantNode *build_constantStr( std::string &str );147 148 //##############################################################################149 150 class VarRefNode : public ExpressionNode {151 public:152 VarRefNode( const std::string *, bool isLabel = false );153 VarRefNode( const VarRefNode &other );154 155 virtual Expression *build() const ;156 157 virtual VarRefNode *clone() const { return new VarRefNode( *this ); }158 159 virtual void print( std::ostream &os, int indent = 0 ) const;160 virtual void printOneLine( std::ostream &os, int indent = 0 ) const;161 private:162 bool isLabel;163 };164 165 //##############################################################################166 167 class DesignatorNode : public ExpressionNode {168 public:169 DesignatorNode( ExpressionNode *expr, bool isArrayIndex = false );170 DesignatorNode( const DesignatorNode &other );171 172 virtual Expression *build() const ;173 virtual DesignatorNode *clone() const { return new DesignatorNode( *this ); }174 175 virtual void print( std::ostream &os, int indent = 0 ) const;176 virtual void printOneLine( std::ostream &os, int indent = 0 ) const;177 private:178 bool isArrayIndex;179 };180 181 //##############################################################################182 183 class TypeValueNode : public ExpressionNode {184 public:185 TypeValueNode( DeclarationNode * );186 TypeValueNode( const TypeValueNode &other );187 188 DeclarationNode *get_decl() const { return decl; }189 190 virtual Expression *build() const ;191 192 virtual TypeValueNode *clone() const { return new TypeValueNode( *this ); }193 194 virtual void print( std::ostream &os, int indent = 0) const;195 virtual void printOneLine( std::ostream &os, int indent = 0) const;196 private:197 DeclarationNode *decl;198 };199 200 //##############################################################################201 202 class CompositeExprNode : public ExpressionNode {203 public:204 CompositeExprNode( Expression *expr ) : expr( expr ) {}205 CompositeExprNode( const CompositeExprNode &other ) : expr( other.expr->clone() ) {}206 virtual ~CompositeExprNode() {}207 208 CompositeExprNode *clone() const { assert( false ); return new CompositeExprNode( *this ); }209 210 Expression *build() const { return expr; }211 212 void print( std::ostream &os, int indent = 0 ) const {}213 void printOneLine( std::ostream &os, int indent = 0 ) const {}214 private:215 Expression *expr;216 141 }; 217 142 … … 227 152 }; 228 153 229 Expression *build_cast( TypeValueNode * arg, ExpressionNode *expr_node ); 230 Expression *build_fieldSel( ExpressionNode *expr_node, VarRefNode *member ); 231 Expression *build_pfieldSel( ExpressionNode *expr_node, VarRefNode *member ); 154 struct LabelNode { 155 std::list< Label > labels; 156 }; 157 158 Expression *build_constantInteger( const std::string &str ); 159 Expression *build_constantFloat( const std::string &str ); 160 Expression *build_constantChar( const std::string &str ); 161 ConstantExpr *build_constantStr( const std::string &str ); 162 163 NameExpr *build_varref( const std::string *name, bool labelp = false ); 164 Expression *build_typevalue( DeclarationNode *decl ); 165 166 Expression *build_cast( DeclarationNode * decl_node, ExpressionNode *expr_node ); 167 Expression *build_fieldSel( ExpressionNode *expr_node, NameExpr *member ); 168 Expression *build_pfieldSel( ExpressionNode *expr_node, NameExpr *member ); 232 169 Expression *build_addressOf( ExpressionNode *expr_node ); 233 Expression *build_sizeOf( ExpressionNode *expr_node ); 234 Expression *build_alignOf( ExpressionNode *expr_node ); 235 Expression *build_offsetOf( TypeValueNode * arg, VarRefNode *member ); 170 Expression *build_sizeOfexpr( ExpressionNode *expr_node ); 171 Expression *build_sizeOftype( DeclarationNode *decl_node ); 172 Expression *build_alignOfexpr( ExpressionNode *expr_node ); 173 Expression *build_alignOftype( DeclarationNode *decl_node ); 174 Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ); 236 175 Expression *build_and( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); 237 176 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ); … … 242 181 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ); 243 182 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ); 244 Expression *build_attr( VarRefNode *var, ExpressionNode * expr = 0 ); 245 Expression *build_tuple( ExpressionNode * expr = 0 ); 246 Expression *build_func( ExpressionNode * function, ExpressionNode * expr ); 183 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ); 184 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ); 185 Expression *build_tuple( ExpressionNode * expr_node = 0 ); 186 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ); 247 187 Expression *build_range( ExpressionNode * low, ExpressionNode *high ); 248 249 //############################################################################## 250 251 class AsmExprNode : public ExpressionNode { 252 public: 253 AsmExprNode(); 254 AsmExprNode( ExpressionNode *inout, ConstantNode *constraint, ExpressionNode *operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} 255 virtual ~AsmExprNode() { delete inout; delete constraint; delete operand; } 256 257 virtual AsmExprNode *clone() const { return new AsmExprNode( *this ); } 258 virtual Expression *build() const; 259 260 virtual void print( std::ostream &os, int indent = 0) const; 261 virtual void printOneLine( std::ostream &os, int indent = 0) const; 262 263 ExpressionNode *get_inout() const { return inout; }; 264 void set_inout( ExpressionNode *newValue ) { inout = newValue; } 265 266 ConstantNode *get_constraint() const { return constraint; }; 267 void set_constraint( ConstantNode *newValue ) { constraint = newValue; } 268 269 ExpressionNode *get_operand() const { return operand; }; 270 void set_operand( ExpressionNode *newValue ) { operand = newValue; } 271 private: 272 ExpressionNode *inout; 273 ConstantNode *constraint; 274 ExpressionNode *operand; 275 }; 276 277 //############################################################################## 278 279 class 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 &os, int indent = 0) const; 285 virtual void printOneLine( std::ostream &os, int indent = 0) const; 286 287 const std::list< Label > &get_labels() const { return labels; }; 288 void append_label( std::string *label ) { labels.push_back( *label ); delete label; } 289 private: 290 std::list< Label > labels; 291 }; 292 293 //############################################################################## 294 295 class ForCtlExprNode : public ExpressionNode { 296 public: 297 ForCtlExprNode( ParseNode *, ExpressionNode *, ExpressionNode * ) throw ( SemanticError ); 298 ForCtlExprNode( const ForCtlExprNode &other ); 299 ~ForCtlExprNode(); 300 301 StatementNode *get_init() const { return init; } 302 ExpressionNode *get_condition() const { return condition; } 303 ExpressionNode *get_change() const { return change; } 304 305 virtual ForCtlExprNode *clone() const { return new ForCtlExprNode( *this ); } 306 virtual Expression *build() const; 307 308 virtual void print( std::ostream &os, int indent = 0 ) const; 309 virtual void printOneLine( std::ostream &os, int indent = 0 ) const; 310 private: 311 StatementNode *init; 312 ExpressionNode *condition; 313 ExpressionNode *change; 314 }; 315 316 //############################################################################## 317 318 class ValofExprNode : public ExpressionNode { 319 public: 320 ValofExprNode(); 321 ValofExprNode( StatementNode *s = 0 ); 322 ValofExprNode( const ValofExprNode &other ); 323 ~ValofExprNode(); 324 325 virtual ValofExprNode *clone() const { return new ValofExprNode( *this ); } 326 327 StatementNode *get_body() const { return body; } 328 void print( std::ostream &os, int indent = 0 ) const; 329 void printOneLine( std::ostream &os, int indent = 0 ) const; 330 Expression *build() const; 331 332 private: 333 StatementNode *body; 334 }; 188 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ); 189 Expression *build_valexpr( StatementNode *s ); 190 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ); 335 191 336 192 //############################################################################## … … 382 238 static DeclarationNode *newBuiltinType( BuiltinType ); 383 239 240 DeclarationNode(); 241 ~DeclarationNode(); 242 DeclarationNode *clone() const; 243 384 244 DeclarationNode *addQualifiers( DeclarationNode *); 385 245 DeclarationNode *copyStorageClasses( DeclarationNode *); … … 397 257 DeclarationNode *addNewArray( DeclarationNode *array ); 398 258 DeclarationNode *addParamList( DeclarationNode *list ); 399 DeclarationNode *addIdList( DeclarationNode *list ); 259 DeclarationNode *addIdList( DeclarationNode *list ); // old-style functions 400 260 DeclarationNode *addInitializer( InitializerNode *init ); 401 261 … … 406 266 DeclarationNode *cloneBaseType( DeclarationNode *newdecl ); 407 267 408 DeclarationNode *appendList( DeclarationNode * ); 409 410 DeclarationNode *clone() const; 268 DeclarationNode *appendList( DeclarationNode *node ) { 269 return (DeclarationNode *)set_last( node ); 270 } 271 411 272 void print( std::ostream &os, int indent = 0 ) const; 412 273 void printList( std::ostream &os, int indent = 0 ) const; … … 417 278 bool get_hasEllipsis() const; 418 279 const std::string &get_name() const { return name; } 419 LinkageSpec:: Typeget_linkage() const { return linkage; }280 LinkageSpec::Spec get_linkage() const { return linkage; } 420 281 DeclarationNode *extractAggregate() const; 421 282 ExpressionNode *get_enumeratorValue() const { return enumeratorValue; } … … 423 284 bool get_extension() const { return extension; } 424 285 DeclarationNode *set_extension( bool exten ) { extension = exten; return this; } 425 426 DeclarationNode();427 ~DeclarationNode();428 286 private: 429 StorageClass buildStorageClass() const;430 bool buildFuncSpecifier( StorageClass key ) const;287 // StorageClass buildStorageClass() const; 288 // bool buildFuncSpecifier( StorageClass key ) const; 431 289 432 290 TypeData *type; 433 291 std::string name; 434 std::list< StorageClass > storageClasses; 292 // std::list< StorageClass > storageClasses; 293 StorageClass storageClass; 294 bool isInline, isNoreturn; 435 295 std::list< std::string > attributes; 436 296 ExpressionNode *bitfieldWidth; … … 438 298 InitializerNode *initializer; 439 299 bool hasEllipsis; 440 LinkageSpec:: Typelinkage;300 LinkageSpec::Spec linkage; 441 301 bool extension = false; 302 std::string error; 442 303 443 304 static UniqueName anonymous; 444 305 }; // DeclarationNode 445 306 446 //############################################################################## 447 448 class StatementNode : public ParseNode { 307 Type *buildType( TypeData *type ); 308 309 //############################################################################## 310 311 class StatementNode final : public ParseNode { 449 312 public: 450 enum Type { Exp, If, Switch, Case, Default, Choose, Fallthru, 451 While, Do, For, 452 Goto, Continue, Break, Return, Throw, 453 Try, Catch, Finally, Asm, 454 Decl 455 }; 456 457 StatementNode(); 458 StatementNode( const std::string *name ); 459 StatementNode( Type t, ExpressionNode *control = 0, StatementNode *block = 0 ); 460 StatementNode( Type t, std::string *target ); 313 StatementNode() { stmt = nullptr; } 314 StatementNode( Statement *stmt ) : stmt( stmt ) {} 461 315 StatementNode( DeclarationNode *decl ); 462 463 ~StatementNode(); 464 465 static StatementNode *newCatchStmt( DeclarationNode *d = 0, StatementNode *s = 0, bool catchRestP = false ); 466 467 StatementNode *set_block( StatementNode *b ) { block = b; return this; } 468 StatementNode *get_block() const { return block; } 469 470 void set_control( ExpressionNode *c ) { control = c; } 471 ExpressionNode *get_control() const { return control; } 472 473 StatementNode::Type get_type() const { return type; } 474 475 StatementNode *add_label( const std::string * ); 476 const std::list<std::string> &get_labels() const { return labels; } 477 478 void addDeclaration( DeclarationNode *newDecl ) { decl = newDecl; } 479 void setCatchRest( bool newVal ) { isCatchRest = newVal; } 480 481 std::string get_target() const; 482 483 // StatementNode *add_controlexp( ExpressionNode * ); 484 StatementNode *append_block( StatementNode * ); 485 StatementNode *append_last_case( StatementNode * ); 486 487 void print( std::ostream &os, int indent = 0) const; 488 virtual StatementNode *clone() const; 489 virtual Statement *build() const; 316 virtual ~StatementNode() {} 317 318 virtual StatementNode *clone() const final { assert( false ); return nullptr; } 319 Statement *build() const { return const_cast<StatementNode*>(this)->stmt.release(); } 320 321 virtual StatementNode *add_label( const std::string * name ) { 322 stmt->get_labels().emplace_back( *name ); 323 delete name; 324 return this; 325 } 326 327 virtual StatementNode *append_last_case( StatementNode * ); 328 329 virtual void print( std::ostream &os, int indent = 0 ) {} 330 virtual void printList( std::ostream &os, int indent = 0 ) {} 490 331 private: 491 static const char *StType[]; 492 Type type; 493 ExpressionNode *control; 494 StatementNode *block; 495 std::list<std::string> labels; 496 std::string *target; // target label for jump statements 497 DeclarationNode *decl; 498 bool isCatchRest; 332 std::unique_ptr<Statement> stmt; 499 333 }; // StatementNode 500 334 501 //############################################################################## 502 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 &os, int indent = 0 ) const; 513 virtual Statement *build() const; 514 private: 515 StatementNode *first, *last; 516 }; 517 518 //############################################################################## 519 520 class AsmStmtNode : public StatementNode { 521 public: 522 AsmStmtNode( Type, bool voltile, ConstantNode *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ConstantNode *clobber = 0, LabelNode *gotolabels = 0 ); 523 ~AsmStmtNode(); 524 525 void print( std::ostream &os, int indent = 0 ) const; 526 Statement *build() const; 527 private: 528 bool voltile; 529 ConstantNode *instruction; 530 ExpressionNode *output, *input; 531 ConstantNode *clobber; 532 std::list< Label > gotolabels; 533 }; 534 535 //############################################################################## 536 537 class InitializerNode : public ParseNode { 538 public: 539 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode *des = 0 ); 540 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode *des = 0 ); 541 ~InitializerNode(); 542 543 ExpressionNode *get_expression() const { return expr; } 544 545 InitializerNode *set_designators( ExpressionNode *des ) { designator = des; return this; } 546 ExpressionNode *get_designators() const { return designator; } 547 548 InitializerNode *set_maybeConstructed( bool value ) { maybeConstructed = value; return this; } 549 bool get_maybeConstructed() const { return maybeConstructed; } 550 551 InitializerNode *next_init() const { return kids; } 552 553 void print( std::ostream &os, int indent = 0 ) const; 554 void printOneLine( std::ostream & ) const; 555 556 virtual Initializer *build() const; 557 private: 558 ExpressionNode *expr; 559 bool aggregate; 560 ExpressionNode *designator; // may be list 561 InitializerNode *kids; 562 bool maybeConstructed; 563 }; 564 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 &os, int indent = 0 ) const; 582 void printOneLine( std::ostream &os, int indent = 0 ) const; 583 584 virtual Expression *build() const; 585 private: 586 DeclarationNode *type; 587 InitializerNode *kids; 588 }; 335 Statement *build_expr( ExpressionNode *ctl ); 336 337 struct ForCtl { 338 ForCtl( ExpressionNode *expr, ExpressionNode *condition, ExpressionNode *change ) : 339 init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {} 340 ForCtl( DeclarationNode *decl, ExpressionNode *condition, ExpressionNode *change ) : 341 init( new StatementNode( decl ) ), condition( condition ), change( change ) {} 342 343 StatementNode *init; 344 ExpressionNode *condition; 345 ExpressionNode *change; 346 }; 347 348 Statement *build_if( ExpressionNode *ctl, StatementNode *then_stmt, StatementNode *else_stmt ); 349 Statement *build_switch( ExpressionNode *ctl, StatementNode *stmt ); 350 Statement *build_case( ExpressionNode *ctl ); 351 Statement *build_default(); 352 Statement *build_while( ExpressionNode *ctl, StatementNode *stmt, bool kind = false ); 353 Statement *build_for( ForCtl *forctl, StatementNode *stmt ); 354 Statement *build_branch( std::string identifier, BranchStmt::Type kind ); 355 Statement *build_computedgoto( ExpressionNode *ctl ); 356 Statement *build_return( ExpressionNode *ctl ); 357 Statement *build_throw( ExpressionNode *ctl ); 358 Statement *build_try( StatementNode *try_stmt, StatementNode *catch_stmt, StatementNode *finally_stmt ); 359 Statement *build_catch( DeclarationNode *decl, StatementNode *stmt, bool catchAny = false ); 360 Statement *build_finally( StatementNode *stmt ); 361 Statement *build_compound( StatementNode *first ); 362 Statement *build_asmstmt( bool voltile, ConstantExpr *instruction, ExpressionNode *output = 0, ExpressionNode *input = 0, ExpressionNode *clobber = 0, LabelNode *gotolabels = 0 ); 363 364 //############################################################################## 589 365 590 366 template< typename SynTreeType, typename NodeType > 591 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) {367 void buildList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) { 592 368 SemanticError errors; 593 std::back_insert_iterator< std::list< SynTreeType * > > out( outputList );369 std::back_insert_iterator< std::list< SynTreeType * > > out( outputList ); 594 370 const NodeType *cur = firstNode; 595 371 596 372 while ( cur ) { 597 373 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 ) );374 // SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::result_of< decltype(&NodeType::build)(NodeType)>::type >( cur ) ); 375 SynTreeType *result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) ); 600 376 if ( result ) { 601 377 *out++ = result; … … 605 381 errors.append( e ); 606 382 } // try 607 cur = dynamic_cast< NodeType * >( cur->get_link() );383 cur = dynamic_cast< NodeType * >( cur->get_next() ); 608 384 } // while 609 385 if ( ! errors.isEmpty() ) { … … 614 390 // in DeclarationNode.cc 615 391 void buildList( const DeclarationNode *firstNode, std::list< Declaration * > &outputList ); 616 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList );392 void buildList( const DeclarationNode *firstNode, std::list< DeclarationWithType * > &outputList ); 617 393 void buildTypeList( const DeclarationNode *firstNode, std::list< Type * > &outputList ); 394 395 template< typename SynTreeType, typename NodeType > 396 void buildMoveList( const NodeType *firstNode, std::list< SynTreeType * > &outputList ) { 397 buildList(firstNode, outputList); 398 delete firstNode; 399 } 400 618 401 619 402 #endif // PARSENODE_H
Note:
See TracChangeset
for help on using the changeset viewer.