Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: runtime/vm/ast.h

Issue 23960003: Disentangle AstNode::Name and AstNode::ShortName. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporated review comments. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/ast.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_AST_H_ 5 #ifndef VM_AST_H_
6 #define VM_AST_H_ 6 #define VM_AST_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/allocation.h" 9 #include "vm/allocation.h"
10 #include "vm/growable_array.h" 10 #include "vm/growable_array.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 NODE_LIST(DEFINE_VISITOR_FUNCTION) 78 NODE_LIST(DEFINE_VISITOR_FUNCTION)
79 #undef DEFINE_VISITOR_FUNCTION 79 #undef DEFINE_VISITOR_FUNCTION
80 80
81 private: 81 private:
82 DISALLOW_COPY_AND_ASSIGN(AstNodeVisitor); 82 DISALLOW_COPY_AND_ASSIGN(AstNodeVisitor);
83 }; 83 };
84 84
85 85
86 #define DECLARE_COMMON_NODE_FUNCTIONS(type) \ 86 #define DECLARE_COMMON_NODE_FUNCTIONS(type) \
87 virtual void Visit(AstNodeVisitor* visitor); \ 87 virtual void Visit(AstNodeVisitor* visitor); \
88 virtual const char* ShortName() const; \ 88 virtual const char* PrettyName() const; \
89 virtual bool Is##type() const { return true; } \ 89 virtual bool Is##type() const { return true; } \
90 virtual type* As##type() { return this; } 90 virtual type* As##type() { return this; }
91 91
92 92
93 class AstNode : public ZoneAllocated { 93 class AstNode : public ZoneAllocated {
94 public: 94 public:
95 explicit AstNode(intptr_t token_pos) 95 explicit AstNode(intptr_t token_pos)
96 : token_pos_(token_pos) { 96 : token_pos_(token_pos) {
97 ASSERT(token_pos_ >= 0); 97 ASSERT(token_pos_ >= 0);
98 } 98 }
99 99
100 intptr_t token_pos() const { return token_pos_; } 100 intptr_t token_pos() const { return token_pos_; }
101 101
102 #define AST_TYPE_CHECK(type, name) \ 102 #define AST_TYPE_CHECK(type, name) \
103 virtual bool Is##type() const { return false; } \ 103 virtual bool Is##type() const { return false; } \
104 virtual type* As##type() { return NULL; } 104 virtual type* As##type() { return NULL; }
105 NODE_LIST(AST_TYPE_CHECK) 105 NODE_LIST(AST_TYPE_CHECK)
106 #undef AST_TYPE_CHECK 106 #undef AST_TYPE_CHECK
107 107
108 virtual void Visit(AstNodeVisitor* visitor) = 0; 108 virtual void Visit(AstNodeVisitor* visitor) = 0;
109 virtual void VisitChildren(AstNodeVisitor* visitor) const = 0; 109 virtual void VisitChildren(AstNodeVisitor* visitor) const = 0;
110 virtual const char* ShortName() const = 0; 110 virtual const char* PrettyName() const = 0;
111
112 // 'ShortName' is predefined for each AstNode and is the default
113 // implementation of "Name()". Each AST node can override the function
114 // "Name" to do more complex name composition.
115 virtual const char* Name() const {
116 return ShortName();
117 }
118 111
119 // Convert the node into an assignment node using the rhs which is passed in, 112 // Convert the node into an assignment node using the rhs which is passed in,
120 // this is typically used for converting nodes like LoadLocalNode, 113 // this is typically used for converting nodes like LoadLocalNode,
121 // LoadStaticFieldNode, InstanceGetterNode etc. which were created during 114 // LoadStaticFieldNode, InstanceGetterNode etc. which were created during
122 // parsing as the assignment context was not known yet at that time. 115 // parsing as the assignment context was not known yet at that time.
123 virtual AstNode* MakeAssignmentNode(AstNode* rhs) { 116 virtual AstNode* MakeAssignmentNode(AstNode* rhs) {
124 return NULL; // By default all nodes are not assignable. 117 return NULL; // By default all nodes are not assignable.
125 } 118 }
126 119
127 // Return NULL if 'unary_op_kind' can't be applied. 120 // Return NULL if 'unary_op_kind' can't be applied.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 public: 344 public:
352 TypeNode(intptr_t token_pos, const AbstractType& type) 345 TypeNode(intptr_t token_pos, const AbstractType& type)
353 : AstNode(token_pos), type_(type) { 346 : AstNode(token_pos), type_(type) {
354 ASSERT(type_.IsZoneHandle()); 347 ASSERT(type_.IsZoneHandle());
355 ASSERT(!type_.IsNull()); 348 ASSERT(!type_.IsNull());
356 ASSERT(type_.IsFinalized()); 349 ASSERT(type_.IsFinalized());
357 } 350 }
358 351
359 const AbstractType& type() const { return type_; } 352 const AbstractType& type() const { return type_; }
360 353
361 virtual const char* Name() const; 354 const char* TypeName() const;
362 355
363 virtual const Instance* EvalConstExpr() const { 356 virtual const Instance* EvalConstExpr() const {
364 // TODO(regis): What if the type is malbounded? 357 // TODO(regis): What if the type is malbounded?
365 if (!type_.IsInstantiated() || type_.IsMalformed()) { 358 if (!type_.IsInstantiated() || type_.IsMalformed()) {
366 return NULL; 359 return NULL;
367 } 360 }
368 return &type(); 361 return &type();
369 } 362 }
370 363
371 virtual void VisitChildren(AstNodeVisitor* visitor) const { } 364 virtual void VisitChildren(AstNodeVisitor* visitor) const { }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 533
541 Token::Kind kind() const { return kind_; } 534 Token::Kind kind() const { return kind_; }
542 AstNode* left() const { return left_; } 535 AstNode* left() const { return left_; }
543 AstNode* right() const { return right_; } 536 AstNode* right() const { return right_; }
544 537
545 virtual void VisitChildren(AstNodeVisitor* visitor) const { 538 virtual void VisitChildren(AstNodeVisitor* visitor) const {
546 left()->Visit(visitor); 539 left()->Visit(visitor);
547 right()->Visit(visitor); 540 right()->Visit(visitor);
548 } 541 }
549 542
550 virtual const char* Name() const; 543 const char* TokenName() const;
551 virtual bool IsPotentiallyConst() const; 544 virtual bool IsPotentiallyConst() const;
552 virtual const Instance* EvalConstExpr() const; 545 virtual const Instance* EvalConstExpr() const;
553 546
554 DECLARE_COMMON_NODE_FUNCTIONS(ComparisonNode); 547 DECLARE_COMMON_NODE_FUNCTIONS(ComparisonNode);
555 548
556 private: 549 private:
557 const Token::Kind kind_; 550 const Token::Kind kind_;
558 AstNode* left_; 551 AstNode* left_;
559 AstNode* right_; 552 AstNode* right_;
560 553
(...skipping 23 matching lines...) Expand all
584 virtual int64_t mask32() const { 577 virtual int64_t mask32() const {
585 UNREACHABLE(); 578 UNREACHABLE();
586 return 0; 579 return 0;
587 } 580 }
588 581
589 virtual void VisitChildren(AstNodeVisitor* visitor) const { 582 virtual void VisitChildren(AstNodeVisitor* visitor) const {
590 left()->Visit(visitor); 583 left()->Visit(visitor);
591 right()->Visit(visitor); 584 right()->Visit(visitor);
592 } 585 }
593 586
594 virtual const char* Name() const; 587 const char* TokenName() const;
595 virtual bool IsPotentiallyConst() const; 588 virtual bool IsPotentiallyConst() const;
596 virtual const Instance* EvalConstExpr() const; 589 virtual const Instance* EvalConstExpr() const;
597 590
598 DECLARE_COMMON_NODE_FUNCTIONS(BinaryOpNode); 591 DECLARE_COMMON_NODE_FUNCTIONS(BinaryOpNode);
599 592
600 private: 593 private:
601 const Token::Kind kind_; 594 const Token::Kind kind_;
602 AstNode* left_; 595 AstNode* left_;
603 AstNode* right_; 596 AstNode* right_;
604 597
(...skipping 15 matching lines...) Expand all
620 ASSERT((kind_value != Token::kAND) && (kind_value != Token::kOR)); 613 ASSERT((kind_value != Token::kAND) && (kind_value != Token::kOR));
621 } 614 }
622 615
623 // The optional 32-bit mask must be a an unsigned 32-bit value. 616 // The optional 32-bit mask must be a an unsigned 32-bit value.
624 virtual bool has_mask32() const { return true; } 617 virtual bool has_mask32() const { return true; }
625 virtual int64_t mask32() const { 618 virtual int64_t mask32() const {
626 ASSERT(has_mask32()); 619 ASSERT(has_mask32());
627 return mask32_; 620 return mask32_;
628 } 621 }
629 622
630 virtual const char* Name() const; 623 const char* TokenName() const;
631 DECLARE_COMMON_NODE_FUNCTIONS(BinaryOpWithMask32Node); 624 DECLARE_COMMON_NODE_FUNCTIONS(BinaryOpWithMask32Node);
632 625
633 private: 626 private:
634 // Optional unsigned 32 bit mask applied on result. No mask: -1. 627 // Optional unsigned 32 bit mask applied on result. No mask: -1.
635 const int64_t mask32_; 628 const int64_t mask32_;
636 629
637 DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryOpWithMask32Node); 630 DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryOpWithMask32Node);
638 }; 631 };
639 632
640 633
(...skipping 12 matching lines...) Expand all
653 ASSERT(IsKindValid()); 646 ASSERT(IsKindValid());
654 } 647 }
655 648
656 Token::Kind kind() const { return kind_; } 649 Token::Kind kind() const { return kind_; }
657 AstNode* operand() const { return operand_; } 650 AstNode* operand() const { return operand_; }
658 651
659 virtual void VisitChildren(AstNodeVisitor* visitor) const { 652 virtual void VisitChildren(AstNodeVisitor* visitor) const {
660 operand()->Visit(visitor); 653 operand()->Visit(visitor);
661 } 654 }
662 655
663 virtual const char* Name() const; 656 const char* TokenName() const;
664 virtual bool IsPotentiallyConst() const; 657 virtual bool IsPotentiallyConst() const;
665 virtual const Instance* EvalConstExpr() const; 658 virtual const Instance* EvalConstExpr() const;
666 659
667 DECLARE_COMMON_NODE_FUNCTIONS(UnaryOpNode); 660 DECLARE_COMMON_NODE_FUNCTIONS(UnaryOpNode);
668 661
669 private: 662 private:
670 const Token::Kind kind_; 663 const Token::Kind kind_;
671 AstNode* operand_; 664 AstNode* operand_;
672 665
673 bool IsKindValid() const; 666 bool IsKindValid() const;
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 intptr_t inlined_finally_list_length() const { 964 intptr_t inlined_finally_list_length() const {
972 return inlined_finally_list_.length(); 965 return inlined_finally_list_.length();
973 } 966 }
974 InlinedFinallyNode* InlinedFinallyNodeAt(intptr_t index) const { 967 InlinedFinallyNode* InlinedFinallyNodeAt(intptr_t index) const {
975 return inlined_finally_list_[index]; 968 return inlined_finally_list_[index];
976 } 969 }
977 void AddInlinedFinallyNode(InlinedFinallyNode* finally_node) { 970 void AddInlinedFinallyNode(InlinedFinallyNode* finally_node) {
978 inlined_finally_list_.Add(finally_node); 971 inlined_finally_list_.Add(finally_node);
979 } 972 }
980 973
981 virtual const char* Name() const; 974 const char* TokenName() const;
982 975
983 virtual void VisitChildren(AstNodeVisitor* visitor) const { } 976 virtual void VisitChildren(AstNodeVisitor* visitor) const { }
984 977
985 DECLARE_COMMON_NODE_FUNCTIONS(JumpNode); 978 DECLARE_COMMON_NODE_FUNCTIONS(JumpNode);
986 979
987 private: 980 private:
988 Token::Kind kind_; 981 Token::Kind kind_;
989 SourceLabel* label_; 982 SourceLabel* label_;
990 GrowableArray<InlinedFinallyNode*> inlined_finally_list_; 983 GrowableArray<InlinedFinallyNode*> inlined_finally_list_;
991 DISALLOW_IMPLICIT_CONSTRUCTORS(JumpNode); 984 DISALLOW_IMPLICIT_CONSTRUCTORS(JumpNode);
992 }; 985 };
993 986
994 987
995 class LoadLocalNode : public AstNode { 988 class LoadLocalNode : public AstNode {
996 public: 989 public:
997 LoadLocalNode(intptr_t token_pos, const LocalVariable* local) 990 LoadLocalNode(intptr_t token_pos, const LocalVariable* local)
998 : AstNode(token_pos), local_(*local) { 991 : AstNode(token_pos), local_(*local) {
999 ASSERT(local != NULL); 992 ASSERT(local != NULL);
1000 } 993 }
1001 994
1002 const LocalVariable& local() const { return local_; } 995 const LocalVariable& local() const { return local_; }
1003 996
1004 virtual void VisitChildren(AstNodeVisitor* visitor) const { } 997 virtual void VisitChildren(AstNodeVisitor* visitor) const { }
1005 998
1006 virtual const char* Name() const;
1007 virtual const Instance* EvalConstExpr() const; 999 virtual const Instance* EvalConstExpr() const;
1008 virtual bool IsPotentiallyConst() const; 1000 virtual bool IsPotentiallyConst() const;
1009 virtual AstNode* MakeAssignmentNode(AstNode* rhs); 1001 virtual AstNode* MakeAssignmentNode(AstNode* rhs);
1010 1002
1011 DECLARE_COMMON_NODE_FUNCTIONS(LoadLocalNode); 1003 DECLARE_COMMON_NODE_FUNCTIONS(LoadLocalNode);
1012 1004
1013 private: 1005 private:
1014 const LocalVariable& local_; 1006 const LocalVariable& local_;
1015 1007
1016 DISALLOW_IMPLICIT_CONSTRUCTORS(LoadLocalNode); 1008 DISALLOW_IMPLICIT_CONSTRUCTORS(LoadLocalNode);
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 const intptr_t try_index_; 1748 const intptr_t try_index_;
1757 1749
1758 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); 1750 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode);
1759 }; 1751 };
1760 1752
1761 } // namespace dart 1753 } // namespace dart
1762 1754
1763 #undef DECLARE_COMMON_NODE_FUNCTIONS 1755 #undef DECLARE_COMMON_NODE_FUNCTIONS
1764 1756
1765 #endif // VM_AST_H_ 1757 #endif // VM_AST_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698