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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 V(PrimaryNode, "primary") \ | 48 V(PrimaryNode, "primary") \ |
49 V(LoadLocalNode, "load local") \ | 49 V(LoadLocalNode, "load local") \ |
50 V(StoreLocalNode, "store local") \ | 50 V(StoreLocalNode, "store local") \ |
51 V(LoadInstanceFieldNode, "load field") \ | 51 V(LoadInstanceFieldNode, "load field") \ |
52 V(StoreInstanceFieldNode, "store field") \ | 52 V(StoreInstanceFieldNode, "store field") \ |
53 V(LoadStaticFieldNode, "load static field") \ | 53 V(LoadStaticFieldNode, "load static field") \ |
54 V(StoreStaticFieldNode, "store static field") \ | 54 V(StoreStaticFieldNode, "store static field") \ |
55 V(LoadIndexedNode, "load indexed") \ | 55 V(LoadIndexedNode, "load indexed") \ |
56 V(StoreIndexedNode, "store indexed") \ | 56 V(StoreIndexedNode, "store indexed") \ |
57 V(SequenceNode, "seq") \ | 57 V(SequenceNode, "seq") \ |
| 58 V(LetNode, "let") \ |
58 V(CommaNode, "comma") \ | 59 V(CommaNode, "comma") \ |
59 V(CatchClauseNode, "catch clause block") \ | 60 V(CatchClauseNode, "catch clause block") \ |
60 V(TryCatchNode, "try catch block") \ | 61 V(TryCatchNode, "try catch block") \ |
61 V(ThrowNode, "throw") \ | 62 V(ThrowNode, "throw") \ |
62 V(InlinedFinallyNode, "inlined finally") \ | 63 V(InlinedFinallyNode, "inlined finally") \ |
63 | 64 |
64 | 65 |
65 #define DEFINE_FORWARD_DECLARATION(type, name) class type; | 66 #define DEFINE_FORWARD_DECLARATION(type, name) class type; |
66 NODE_LIST(DEFINE_FORWARD_DECLARATION) | 67 NODE_LIST(DEFINE_FORWARD_DECLARATION) |
67 #undef DEFINE_FORWARD_DECLARATION | 68 #undef DEFINE_FORWARD_DECLARATION |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 287 |
287 private: | 288 private: |
288 const intptr_t formal_parameter_index_; | 289 const intptr_t formal_parameter_index_; |
289 const String& formal_parameter_name_; | 290 const String& formal_parameter_name_; |
290 const LocalVariable& saved_arguments_descriptor_; | 291 const LocalVariable& saved_arguments_descriptor_; |
291 | 292 |
292 DISALLOW_COPY_AND_ASSIGN(ArgumentDefinitionTestNode); | 293 DISALLOW_COPY_AND_ASSIGN(ArgumentDefinitionTestNode); |
293 }; | 294 }; |
294 | 295 |
295 | 296 |
| 297 class LetNode : public AstNode { |
| 298 public: |
| 299 explicit LetNode(intptr_t token_pos); |
| 300 |
| 301 LocalVariable* TempAt(intptr_t i) const { return vars_[i]; } |
| 302 AstNode* InitializerAt(intptr_t i) const { return initializers_[i]; } |
| 303 |
| 304 LocalVariable* AddInitializer(AstNode* node); |
| 305 |
| 306 intptr_t num_temps() const { |
| 307 return vars_.length(); |
| 308 } |
| 309 |
| 310 AstNode* body() const { return body_; } |
| 311 void set_body(AstNode* node) { body_ = node; } |
| 312 |
| 313 void VisitChildren(AstNodeVisitor* visitor) const; |
| 314 |
| 315 DECLARE_COMMON_NODE_FUNCTIONS(LetNode); |
| 316 |
| 317 private: |
| 318 GrowableArray<LocalVariable*> vars_; |
| 319 GrowableArray<AstNode*> initializers_; |
| 320 AstNode* body_; |
| 321 |
| 322 DISALLOW_COPY_AND_ASSIGN(LetNode); |
| 323 }; |
| 324 |
| 325 |
296 class ArrayNode : public AstNode { | 326 class ArrayNode : public AstNode { |
297 public: | 327 public: |
298 ArrayNode(intptr_t token_pos, | 328 ArrayNode(intptr_t token_pos, const AbstractType& type) |
299 const AbstractType& type, | |
300 const LocalVariable& temp) | |
301 : AstNode(token_pos), | 329 : AstNode(token_pos), |
302 type_(type), | 330 type_(type), |
303 temp_local_(temp), | |
304 elements_() { | 331 elements_() { |
305 CheckFields(); | 332 CheckFields(); |
306 } | 333 } |
307 ArrayNode(intptr_t token_pos, | 334 ArrayNode(intptr_t token_pos, |
308 const AbstractType& type, | 335 const AbstractType& type, |
309 const LocalVariable& temp, | |
310 const GrowableArray<AstNode*>& elements) | 336 const GrowableArray<AstNode*>& elements) |
311 : AstNode(token_pos), | 337 : AstNode(token_pos), |
312 type_(type), | 338 type_(type), |
313 temp_local_(temp), | |
314 elements_(elements.length()) { | 339 elements_(elements.length()) { |
315 CheckFields(); | 340 CheckFields(); |
316 for (intptr_t i = 0; i < elements.length(); i++) { | 341 for (intptr_t i = 0; i < elements.length(); i++) { |
317 elements_.Add(elements[i]); | 342 elements_.Add(elements[i]); |
318 } | 343 } |
319 } | 344 } |
320 | 345 |
321 void VisitChildren(AstNodeVisitor* visitor) const; | 346 void VisitChildren(AstNodeVisitor* visitor) const; |
322 | 347 |
323 intptr_t length() const { return elements_.length(); } | 348 intptr_t length() const { return elements_.length(); } |
324 | 349 |
325 AstNode* ElementAt(intptr_t index) const { return elements_[index]; } | 350 AstNode* ElementAt(intptr_t index) const { return elements_[index]; } |
326 void SetElementAt(intptr_t index, AstNode* value) { | 351 void SetElementAt(intptr_t index, AstNode* value) { |
327 elements_[index] = value; | 352 elements_[index] = value; |
328 } | 353 } |
329 void AddElement(AstNode* expr) { elements_.Add(expr); } | 354 void AddElement(AstNode* expr) { elements_.Add(expr); } |
330 | 355 |
331 const AbstractType& type() const { return type_; } | 356 const AbstractType& type() const { return type_; } |
332 | 357 |
333 const LocalVariable& temp_local() const { return temp_local_; } | |
334 | |
335 DECLARE_COMMON_NODE_FUNCTIONS(ArrayNode); | 358 DECLARE_COMMON_NODE_FUNCTIONS(ArrayNode); |
336 | 359 |
337 private: | 360 private: |
338 const AbstractType& type_; | 361 const AbstractType& type_; |
339 const LocalVariable& temp_local_; // Store allocated array while filling it. | |
340 GrowableArray<AstNode*> elements_; | 362 GrowableArray<AstNode*> elements_; |
341 | 363 |
342 void CheckFields() { | 364 void CheckFields() { |
343 ASSERT(type_.IsZoneHandle()); | 365 ASSERT(type_.IsZoneHandle()); |
344 ASSERT(!type_.IsNull()); | 366 ASSERT(!type_.IsNull()); |
345 ASSERT(type_.IsFinalized()); | 367 ASSERT(type_.IsFinalized()); |
346 // Type may be uninstantiated when creating a generic list literal. | 368 // Type may be uninstantiated when creating a generic list literal. |
347 ASSERT((type_.arguments() == AbstractTypeArguments::null()) || | 369 ASSERT((type_.arguments() == AbstractTypeArguments::null()) || |
348 ((AbstractTypeArguments::Handle(type_.arguments()).Length() == 1))); | 370 ((AbstractTypeArguments::Handle(type_.arguments()).Length() == 1))); |
349 } | 371 } |
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 // the instantiator is the receiver of this function. In order to instantiate T | 1522 // the instantiator is the receiver of this function. In order to instantiate T |
1501 // in the example above (which could for example be the first type parameter of | 1523 // in the example above (which could for example be the first type parameter of |
1502 // the class of the caller), the code at run time extracts the type arguments of | 1524 // the class of the caller), the code at run time extracts the type arguments of |
1503 // the receiver at an offset in the receiver specified by the provided | 1525 // the receiver at an offset in the receiver specified by the provided |
1504 // instantiator_class. | 1526 // instantiator_class. |
1505 // | 1527 // |
1506 // If the caller to the constructor or to the factory is a factory, then the | 1528 // If the caller to the constructor or to the factory is a factory, then the |
1507 // instantiator is the first parameter of this factory, which is already a | 1529 // instantiator is the first parameter of this factory, which is already a |
1508 // type argument vector. This case is identified by a null and unneeded | 1530 // type argument vector. This case is identified by a null and unneeded |
1509 // instantiator_class. | 1531 // instantiator_class. |
1510 // | |
1511 // A temporary local is needed to hold the allocated value while the | |
1512 // constructor is being called. | |
1513 class ConstructorCallNode : public AstNode { | 1532 class ConstructorCallNode : public AstNode { |
1514 public: | 1533 public: |
1515 ConstructorCallNode(intptr_t token_pos, | 1534 ConstructorCallNode(intptr_t token_pos, |
1516 const AbstractTypeArguments& type_arguments, | 1535 const AbstractTypeArguments& type_arguments, |
1517 const Function& constructor, | 1536 const Function& constructor, |
1518 ArgumentListNode* arguments, | 1537 ArgumentListNode* arguments) |
1519 const LocalVariable* allocated_object_var) | |
1520 : AstNode(token_pos), | 1538 : AstNode(token_pos), |
1521 type_arguments_(type_arguments), | 1539 type_arguments_(type_arguments), |
1522 constructor_(constructor), | 1540 constructor_(constructor), |
1523 arguments_(arguments), | 1541 arguments_(arguments) { |
1524 allocated_object_var_(*allocated_object_var) { | |
1525 ASSERT(type_arguments_.IsZoneHandle()); | 1542 ASSERT(type_arguments_.IsZoneHandle()); |
1526 ASSERT(constructor_.IsZoneHandle()); | 1543 ASSERT(constructor_.IsZoneHandle()); |
1527 ASSERT(arguments_ != NULL); | 1544 ASSERT(arguments_ != NULL); |
1528 ASSERT(allocated_object_var != NULL); | |
1529 } | 1545 } |
1530 | 1546 |
1531 const AbstractTypeArguments& type_arguments() const { | 1547 const AbstractTypeArguments& type_arguments() const { |
1532 return type_arguments_; | 1548 return type_arguments_; |
1533 } | 1549 } |
1534 const Function& constructor() const { return constructor_; } | 1550 const Function& constructor() const { return constructor_; } |
1535 ArgumentListNode* arguments() const { return arguments_; } | 1551 ArgumentListNode* arguments() const { return arguments_; } |
1536 const LocalVariable& allocated_object_var() const { | |
1537 return allocated_object_var_; | |
1538 } | |
1539 | 1552 |
1540 virtual void VisitChildren(AstNodeVisitor* visitor) const { | 1553 virtual void VisitChildren(AstNodeVisitor* visitor) const { |
1541 arguments()->Visit(visitor); | 1554 arguments()->Visit(visitor); |
1542 } | 1555 } |
1543 | 1556 |
1544 DECLARE_COMMON_NODE_FUNCTIONS(ConstructorCallNode); | 1557 DECLARE_COMMON_NODE_FUNCTIONS(ConstructorCallNode); |
1545 | 1558 |
1546 private: | 1559 private: |
1547 const AbstractTypeArguments& type_arguments_; | 1560 const AbstractTypeArguments& type_arguments_; |
1548 const Function& constructor_; | 1561 const Function& constructor_; |
1549 ArgumentListNode* arguments_; | 1562 ArgumentListNode* arguments_; |
1550 const LocalVariable& allocated_object_var_; | |
1551 | 1563 |
1552 DISALLOW_IMPLICIT_CONSTRUCTORS(ConstructorCallNode); | 1564 DISALLOW_IMPLICIT_CONSTRUCTORS(ConstructorCallNode); |
1553 }; | 1565 }; |
1554 | 1566 |
1555 | 1567 |
1556 // The body of a Dart function marked as 'native' consists of this node. | 1568 // The body of a Dart function marked as 'native' consists of this node. |
1557 class NativeBodyNode : public AstNode { | 1569 class NativeBodyNode : public AstNode { |
1558 public: | 1570 public: |
1559 NativeBodyNode(intptr_t token_pos, | 1571 NativeBodyNode(intptr_t token_pos, |
1560 const Function& function, | 1572 const Function& function, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1744 const LocalVariable& context_var_; | 1756 const LocalVariable& context_var_; |
1745 | 1757 |
1746 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); | 1758 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); |
1747 }; | 1759 }; |
1748 | 1760 |
1749 } // namespace dart | 1761 } // namespace dart |
1750 | 1762 |
1751 #undef DECLARE_COMMON_NODE_FUNCTIONS | 1763 #undef DECLARE_COMMON_NODE_FUNCTIONS |
1752 | 1764 |
1753 #endif // VM_AST_H_ | 1765 #endif // VM_AST_H_ |
OLD | NEW |