| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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* ShortName() 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 static const int kNoId = -1; | |
| 96 | |
| 97 explicit AstNode(intptr_t token_pos) | 95 explicit AstNode(intptr_t token_pos) |
| 98 : token_pos_(token_pos), | 96 : token_pos_(token_pos), |
| 99 id_(GetNextId()), | |
| 100 ic_data_(ICData::ZoneHandle()), | 97 ic_data_(ICData::ZoneHandle()), |
| 101 info_(NULL) { | 98 info_(NULL) { |
| 102 ASSERT(token_pos >= 0); | 99 ASSERT(token_pos >= 0); |
| 103 } | 100 } |
| 104 | 101 |
| 105 intptr_t token_pos() const { return token_pos_; } | 102 intptr_t token_pos() const { return token_pos_; } |
| 106 | 103 |
| 107 | 104 |
| 108 const ICData& ic_data() const { return ic_data_; } | 105 const ICData& ic_data() const { return ic_data_; } |
| 109 void set_ic_data(const ICData& value) { | 106 void set_ic_data(const ICData& value) { |
| 110 ic_data_ = value.raw(); | 107 ic_data_ = value.raw(); |
| 111 } | 108 } |
| 112 | 109 |
| 113 intptr_t id() const { return id_; } | |
| 114 | |
| 115 void set_info(CodeGenInfo* info) { info_ = info; } | 110 void set_info(CodeGenInfo* info) { info_ = info; } |
| 116 CodeGenInfo* info() const { return info_; } | 111 CodeGenInfo* info() const { return info_; } |
| 117 | 112 |
| 118 #define AST_TYPE_CHECK(type, name) \ | 113 #define AST_TYPE_CHECK(type, name) \ |
| 119 virtual bool Is##type() const { return false; } \ | 114 virtual bool Is##type() const { return false; } \ |
| 120 virtual type* As##type() { return NULL; } | 115 virtual type* As##type() { return NULL; } |
| 121 NODE_LIST(AST_TYPE_CHECK) | 116 NODE_LIST(AST_TYPE_CHECK) |
| 122 #undef AST_TYPE_CHECK | 117 #undef AST_TYPE_CHECK |
| 123 | 118 |
| 124 virtual void Visit(AstNodeVisitor* visitor) = 0; | 119 virtual void Visit(AstNodeVisitor* visitor) = 0; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 150 // constant. Otherwise, the return value is an approximation of the | 145 // constant. Otherwise, the return value is an approximation of the |
| 151 // actual value of the const expression. The type of the returned value | 146 // actual value of the const expression. The type of the returned value |
| 152 // corresponds to the type of the const expression and is either | 147 // corresponds to the type of the const expression and is either |
| 153 // Number, Integer, String, Bool, or anything else (not a subtype of | 148 // Number, Integer, String, Bool, or anything else (not a subtype of |
| 154 // the former). | 149 // the former). |
| 155 virtual const Instance* EvalConstExpr() const { return NULL; } | 150 virtual const Instance* EvalConstExpr() const { return NULL; } |
| 156 | 151 |
| 157 protected: | 152 protected: |
| 158 friend class ParsedFunction; | 153 friend class ParsedFunction; |
| 159 | 154 |
| 160 static intptr_t GetNextId() { | |
| 161 Isolate* isolate = Isolate::Current(); | |
| 162 intptr_t tmp = isolate->ast_node_id(); | |
| 163 isolate->set_ast_node_id(tmp + 1); | |
| 164 return tmp; | |
| 165 } | |
| 166 | |
| 167 private: | 155 private: |
| 168 const intptr_t token_pos_; | 156 const intptr_t token_pos_; |
| 169 // Unique id per function compiled, used to match AST node to a PC. | |
| 170 const intptr_t id_; | |
| 171 // IC data collected for this node. | 157 // IC data collected for this node. |
| 172 ICData& ic_data_; | 158 ICData& ic_data_; |
| 173 // Used by optimizing compiler. | 159 // Used by optimizing compiler. |
| 174 CodeGenInfo* info_; | 160 CodeGenInfo* info_; |
| 175 DISALLOW_COPY_AND_ASSIGN(AstNode); | 161 DISALLOW_COPY_AND_ASSIGN(AstNode); |
| 176 }; | 162 }; |
| 177 | 163 |
| 178 | 164 |
| 179 class SequenceNode : public AstNode { | 165 class SequenceNode : public AstNode { |
| 180 public: | 166 public: |
| 181 SequenceNode(intptr_t token_pos, LocalScope* scope) | 167 SequenceNode(intptr_t token_pos, LocalScope* scope) |
| 182 : AstNode(token_pos), | 168 : AstNode(token_pos), |
| 183 scope_(scope), | 169 scope_(scope), |
| 184 nodes_(4), | 170 nodes_(4), |
| 185 label_(NULL), | 171 label_(NULL) { |
| 186 first_parameter_id_(AstNode::kNoId), | |
| 187 last_parameter_id_(AstNode::kNoId) { | |
| 188 } | 172 } |
| 189 | 173 |
| 190 LocalScope* scope() const { return scope_; } | 174 LocalScope* scope() const { return scope_; } |
| 191 | 175 |
| 192 SourceLabel* label() const { return label_; } | 176 SourceLabel* label() const { return label_; } |
| 193 void set_label(SourceLabel* value) { label_ = value; } | 177 void set_label(SourceLabel* value) { label_ = value; } |
| 194 | 178 |
| 195 void VisitChildren(AstNodeVisitor* visitor) const; | 179 void VisitChildren(AstNodeVisitor* visitor) const; |
| 196 | 180 |
| 197 void Add(AstNode* node) { nodes_.Add(node); } | 181 void Add(AstNode* node) { nodes_.Add(node); } |
| 198 intptr_t length() const { return nodes_.length(); } | 182 intptr_t length() const { return nodes_.length(); } |
| 199 AstNode* NodeAt(intptr_t index) const { return nodes_[index]; } | 183 AstNode* NodeAt(intptr_t index) const { return nodes_[index]; } |
| 200 | 184 |
| 201 void set_first_parameter_id(intptr_t value) { first_parameter_id_ = value; } | |
| 202 void set_last_parameter_id(intptr_t value) { last_parameter_id_ = value; } | |
| 203 intptr_t ParameterIdAt(intptr_t param_pos) const { | |
| 204 ASSERT(first_parameter_id_ != AstNode::kNoId); | |
| 205 ASSERT(last_parameter_id_ != AstNode::kNoId); | |
| 206 ASSERT(param_pos <= (last_parameter_id_ - first_parameter_id_)); | |
| 207 return first_parameter_id_ + param_pos; | |
| 208 } | |
| 209 | |
| 210 DECLARE_COMMON_NODE_FUNCTIONS(SequenceNode); | 185 DECLARE_COMMON_NODE_FUNCTIONS(SequenceNode); |
| 211 | 186 |
| 212 // Collects all nodes accessible from this sequence node into array 'nodes'. | 187 // Collects all nodes accessible from this sequence node into array 'nodes'. |
| 213 void CollectAllNodes(GrowableArray<AstNode*>* nodes); | 188 void CollectAllNodes(GrowableArray<AstNode*>* nodes); |
| 214 | 189 |
| 215 private: | 190 private: |
| 216 LocalScope* scope_; | 191 LocalScope* scope_; |
| 217 GrowableArray<AstNode*> nodes_; | 192 GrowableArray<AstNode*> nodes_; |
| 218 SourceLabel* label_; | 193 SourceLabel* label_; |
| 219 intptr_t first_parameter_id_; | |
| 220 intptr_t last_parameter_id_; | |
| 221 | 194 |
| 222 DISALLOW_COPY_AND_ASSIGN(SequenceNode); | 195 DISALLOW_COPY_AND_ASSIGN(SequenceNode); |
| 223 }; | 196 }; |
| 224 | 197 |
| 225 | 198 |
| 226 class CloneContextNode : public AstNode { | 199 class CloneContextNode : public AstNode { |
| 227 public: | 200 public: |
| 228 explicit CloneContextNode(intptr_t token_pos) | 201 explicit CloneContextNode(intptr_t token_pos) |
| 229 : AstNode(token_pos) { | 202 : AstNode(token_pos) { |
| 230 } | 203 } |
| (...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1659 const LocalVariable& context_var_; | 1632 const LocalVariable& context_var_; |
| 1660 | 1633 |
| 1661 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); | 1634 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); |
| 1662 }; | 1635 }; |
| 1663 | 1636 |
| 1664 } // namespace dart | 1637 } // namespace dart |
| 1665 | 1638 |
| 1666 #undef DECLARE_COMMON_NODE_FUNCTIONS | 1639 #undef DECLARE_COMMON_NODE_FUNCTIONS |
| 1667 | 1640 |
| 1668 #endif // VM_AST_H_ | 1641 #endif // VM_AST_H_ |
| OLD | NEW |