| OLD | NEW |
| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 V(CatchClauseNode, "catch clause block") \ | 58 V(CatchClauseNode, "catch clause block") \ |
| 59 V(TryCatchNode, "try catch block") \ | 59 V(TryCatchNode, "try catch block") \ |
| 60 V(ThrowNode, "throw") \ | 60 V(ThrowNode, "throw") \ |
| 61 V(InlinedFinallyNode, "inlined finally") \ | 61 V(InlinedFinallyNode, "inlined finally") \ |
| 62 | 62 |
| 63 | 63 |
| 64 #define DEFINE_FORWARD_DECLARATION(type, name) class type; | 64 #define DEFINE_FORWARD_DECLARATION(type, name) class type; |
| 65 NODE_LIST(DEFINE_FORWARD_DECLARATION) | 65 NODE_LIST(DEFINE_FORWARD_DECLARATION) |
| 66 #undef DEFINE_FORWARD_DECLARATION | 66 #undef DEFINE_FORWARD_DECLARATION |
| 67 | 67 |
| 68 // Forward declarations. | |
| 69 class CodeGenInfo; | |
| 70 | 68 |
| 71 // Abstract class to implement an AST node visitor. An example is AstPrinter. | 69 // Abstract class to implement an AST node visitor. An example is AstPrinter. |
| 72 class AstNodeVisitor : public ValueObject { | 70 class AstNodeVisitor : public ValueObject { |
| 73 public: | 71 public: |
| 74 AstNodeVisitor() {} | 72 AstNodeVisitor() {} |
| 75 virtual ~AstNodeVisitor() {} | 73 virtual ~AstNodeVisitor() {} |
| 76 | 74 |
| 77 #define DEFINE_VISITOR_FUNCTION(type, name) \ | 75 #define DEFINE_VISITOR_FUNCTION(type, name) \ |
| 78 virtual void Visit##type(type* node) { } | 76 virtual void Visit##type(type* node) { } |
| 79 NODE_LIST(DEFINE_VISITOR_FUNCTION) | 77 NODE_LIST(DEFINE_VISITOR_FUNCTION) |
| 80 #undef DEFINE_VISITOR_FUNCTION | 78 #undef DEFINE_VISITOR_FUNCTION |
| 81 | 79 |
| 82 private: | 80 private: |
| 83 DISALLOW_COPY_AND_ASSIGN(AstNodeVisitor); | 81 DISALLOW_COPY_AND_ASSIGN(AstNodeVisitor); |
| 84 }; | 82 }; |
| 85 | 83 |
| 86 | 84 |
| 87 #define DECLARE_COMMON_NODE_FUNCTIONS(type) \ | 85 #define DECLARE_COMMON_NODE_FUNCTIONS(type) \ |
| 88 virtual void Visit(AstNodeVisitor* visitor); \ | 86 virtual void Visit(AstNodeVisitor* visitor); \ |
| 89 virtual const char* ShortName() const; \ | 87 virtual const char* ShortName() const; \ |
| 90 virtual bool Is##type() const { return true; } \ | 88 virtual bool Is##type() const { return true; } \ |
| 91 virtual type* As##type() { return this; } | 89 virtual type* As##type() { return this; } |
| 92 | 90 |
| 93 | 91 |
| 94 class AstNode : public ZoneAllocated { | 92 class AstNode : public ZoneAllocated { |
| 95 public: | 93 public: |
| 96 explicit AstNode(intptr_t token_pos) | 94 explicit AstNode(intptr_t token_pos) |
| 97 : token_pos_(token_pos), | 95 : token_pos_(token_pos), |
| 98 ic_data_(ICData::ZoneHandle()), | 96 ic_data_(ICData::ZoneHandle()) { |
| 99 info_(NULL) { | |
| 100 ASSERT(token_pos_ >= 0); | 97 ASSERT(token_pos_ >= 0); |
| 101 } | 98 } |
| 102 | 99 |
| 103 intptr_t token_pos() const { return token_pos_; } | 100 intptr_t token_pos() const { return token_pos_; } |
| 104 | 101 |
| 105 | |
| 106 const ICData& ic_data() const { return ic_data_; } | 102 const ICData& ic_data() const { return ic_data_; } |
| 107 void set_ic_data(const ICData& value) { | 103 void set_ic_data(const ICData& value) { |
| 108 ic_data_ = value.raw(); | 104 ic_data_ = value.raw(); |
| 109 } | 105 } |
| 110 | 106 |
| 111 void set_info(CodeGenInfo* info) { info_ = info; } | |
| 112 CodeGenInfo* info() const { return info_; } | |
| 113 | |
| 114 #define AST_TYPE_CHECK(type, name) \ | 107 #define AST_TYPE_CHECK(type, name) \ |
| 115 virtual bool Is##type() const { return false; } \ | 108 virtual bool Is##type() const { return false; } \ |
| 116 virtual type* As##type() { return NULL; } | 109 virtual type* As##type() { return NULL; } |
| 117 NODE_LIST(AST_TYPE_CHECK) | 110 NODE_LIST(AST_TYPE_CHECK) |
| 118 #undef AST_TYPE_CHECK | 111 #undef AST_TYPE_CHECK |
| 119 | 112 |
| 120 virtual void Visit(AstNodeVisitor* visitor) = 0; | 113 virtual void Visit(AstNodeVisitor* visitor) = 0; |
| 121 virtual void VisitChildren(AstNodeVisitor* visitor) const = 0; | 114 virtual void VisitChildren(AstNodeVisitor* visitor) const = 0; |
| 122 virtual const char* ShortName() const = 0; | 115 virtual const char* ShortName() const = 0; |
| 123 | 116 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 150 // the former). | 143 // the former). |
| 151 virtual const Instance* EvalConstExpr() const { return NULL; } | 144 virtual const Instance* EvalConstExpr() const { return NULL; } |
| 152 | 145 |
| 153 protected: | 146 protected: |
| 154 friend class ParsedFunction; | 147 friend class ParsedFunction; |
| 155 | 148 |
| 156 private: | 149 private: |
| 157 const intptr_t token_pos_; | 150 const intptr_t token_pos_; |
| 158 // IC data collected for this node. | 151 // IC data collected for this node. |
| 159 ICData& ic_data_; | 152 ICData& ic_data_; |
| 160 // Used by optimizing compiler. | |
| 161 CodeGenInfo* info_; | |
| 162 DISALLOW_COPY_AND_ASSIGN(AstNode); | 153 DISALLOW_COPY_AND_ASSIGN(AstNode); |
| 163 }; | 154 }; |
| 164 | 155 |
| 165 | 156 |
| 166 class SequenceNode : public AstNode { | 157 class SequenceNode : public AstNode { |
| 167 public: | 158 public: |
| 168 SequenceNode(intptr_t token_pos, LocalScope* scope) | 159 SequenceNode(intptr_t token_pos, LocalScope* scope) |
| 169 : AstNode(token_pos), | 160 : AstNode(token_pos), |
| 170 scope_(scope), | 161 scope_(scope), |
| 171 nodes_(4), | 162 nodes_(4), |
| (...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1707 const LocalVariable& context_var_; | 1698 const LocalVariable& context_var_; |
| 1708 | 1699 |
| 1709 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); | 1700 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); |
| 1710 }; | 1701 }; |
| 1711 | 1702 |
| 1712 } // namespace dart | 1703 } // namespace dart |
| 1713 | 1704 |
| 1714 #undef DECLARE_COMMON_NODE_FUNCTIONS | 1705 #undef DECLARE_COMMON_NODE_FUNCTIONS |
| 1715 | 1706 |
| 1716 #endif // VM_AST_H_ | 1707 #endif // VM_AST_H_ |
| OLD | NEW |