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

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

Issue 14942010: Eliminate temporary locals for some expressions (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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') | runtime/vm/parser.cc » ('J')
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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* temp(intptr_t i) const { return vars_[i]; }
Kevin Millikin (Google) 2013/05/30 11:30:55 It's inconsistent to have two different ways to lo
Florian Schneider 2013/05/30 11:46:57 Done.
302 const GrowableArray<AstNode*>& initializers() const {
303 return initializers_;
304 }
305
306 LocalVariable* AddInitializer(AstNode* node);
307
308 intptr_t num_temps() const {
309 return vars_.length();
310 }
311
312 AstNode* body() const { return body_; }
313 void set_body(AstNode* node) { body_ = node; }
314
315 void VisitChildren(AstNodeVisitor* visitor) const;
316
317 DECLARE_COMMON_NODE_FUNCTIONS(LetNode);
318
319 private:
320 GrowableArray<LocalVariable*> vars_;
321 GrowableArray<AstNode*> initializers_;
322 AstNode* body_;
323
324 DISALLOW_COPY_AND_ASSIGN(LetNode);
325 };
326
327
296 class ArrayNode : public AstNode { 328 class ArrayNode : public AstNode {
297 public: 329 public:
298 ArrayNode(intptr_t token_pos, 330 ArrayNode(intptr_t token_pos, const AbstractType& type)
299 const AbstractType& type,
300 const LocalVariable& temp)
301 : AstNode(token_pos), 331 : AstNode(token_pos),
302 type_(type), 332 type_(type),
303 temp_local_(temp),
304 elements_() { 333 elements_() {
305 CheckFields(); 334 CheckFields();
306 } 335 }
307 ArrayNode(intptr_t token_pos, 336 ArrayNode(intptr_t token_pos,
308 const AbstractType& type, 337 const AbstractType& type,
309 const LocalVariable& temp,
310 const GrowableArray<AstNode*>& elements) 338 const GrowableArray<AstNode*>& elements)
311 : AstNode(token_pos), 339 : AstNode(token_pos),
312 type_(type), 340 type_(type),
313 temp_local_(temp),
314 elements_(elements.length()) { 341 elements_(elements.length()) {
315 CheckFields(); 342 CheckFields();
316 for (intptr_t i = 0; i < elements.length(); i++) { 343 for (intptr_t i = 0; i < elements.length(); i++) {
317 elements_.Add(elements[i]); 344 elements_.Add(elements[i]);
318 } 345 }
319 } 346 }
320 347
321 void VisitChildren(AstNodeVisitor* visitor) const; 348 void VisitChildren(AstNodeVisitor* visitor) const;
322 349
323 intptr_t length() const { return elements_.length(); } 350 intptr_t length() const { return elements_.length(); }
324 351
325 AstNode* ElementAt(intptr_t index) const { return elements_[index]; } 352 AstNode* ElementAt(intptr_t index) const { return elements_[index]; }
326 void SetElementAt(intptr_t index, AstNode* value) { 353 void SetElementAt(intptr_t index, AstNode* value) {
327 elements_[index] = value; 354 elements_[index] = value;
328 } 355 }
329 void AddElement(AstNode* expr) { elements_.Add(expr); } 356 void AddElement(AstNode* expr) { elements_.Add(expr); }
330 357
331 const AbstractType& type() const { return type_; } 358 const AbstractType& type() const { return type_; }
332 359
333 const LocalVariable& temp_local() const { return temp_local_; }
334
335 DECLARE_COMMON_NODE_FUNCTIONS(ArrayNode); 360 DECLARE_COMMON_NODE_FUNCTIONS(ArrayNode);
336 361
337 private: 362 private:
338 const AbstractType& type_; 363 const AbstractType& type_;
339 const LocalVariable& temp_local_; // Store allocated array while filling it.
340 GrowableArray<AstNode*> elements_; 364 GrowableArray<AstNode*> elements_;
341 365
342 void CheckFields() { 366 void CheckFields() {
343 ASSERT(type_.IsZoneHandle()); 367 ASSERT(type_.IsZoneHandle());
344 ASSERT(!type_.IsNull()); 368 ASSERT(!type_.IsNull());
345 ASSERT(type_.IsFinalized()); 369 ASSERT(type_.IsFinalized());
346 // Type may be uninstantiated when creating a generic list literal. 370 // Type may be uninstantiated when creating a generic list literal.
347 ASSERT((type_.arguments() == AbstractTypeArguments::null()) || 371 ASSERT((type_.arguments() == AbstractTypeArguments::null()) ||
348 ((AbstractTypeArguments::Handle(type_.arguments()).Length() == 1))); 372 ((AbstractTypeArguments::Handle(type_.arguments()).Length() == 1)));
349 } 373 }
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1500 // the instantiator is the receiver of this function. In order to instantiate T 1524 // 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 1525 // 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 1526 // 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 1527 // the receiver at an offset in the receiver specified by the provided
1504 // instantiator_class. 1528 // instantiator_class.
1505 // 1529 //
1506 // If the caller to the constructor or to the factory is a factory, then the 1530 // 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 1531 // 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 1532 // type argument vector. This case is identified by a null and unneeded
1509 // instantiator_class. 1533 // 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 { 1534 class ConstructorCallNode : public AstNode {
1514 public: 1535 public:
1515 ConstructorCallNode(intptr_t token_pos, 1536 ConstructorCallNode(intptr_t token_pos,
1516 const AbstractTypeArguments& type_arguments, 1537 const AbstractTypeArguments& type_arguments,
1517 const Function& constructor, 1538 const Function& constructor,
1518 ArgumentListNode* arguments, 1539 ArgumentListNode* arguments)
1519 const LocalVariable* allocated_object_var)
1520 : AstNode(token_pos), 1540 : AstNode(token_pos),
1521 type_arguments_(type_arguments), 1541 type_arguments_(type_arguments),
1522 constructor_(constructor), 1542 constructor_(constructor),
1523 arguments_(arguments), 1543 arguments_(arguments) {
1524 allocated_object_var_(*allocated_object_var) {
1525 ASSERT(type_arguments_.IsZoneHandle()); 1544 ASSERT(type_arguments_.IsZoneHandle());
1526 ASSERT(constructor_.IsZoneHandle()); 1545 ASSERT(constructor_.IsZoneHandle());
1527 ASSERT(arguments_ != NULL); 1546 ASSERT(arguments_ != NULL);
1528 ASSERT(allocated_object_var != NULL);
1529 } 1547 }
1530 1548
1531 const AbstractTypeArguments& type_arguments() const { 1549 const AbstractTypeArguments& type_arguments() const {
1532 return type_arguments_; 1550 return type_arguments_;
1533 } 1551 }
1534 const Function& constructor() const { return constructor_; } 1552 const Function& constructor() const { return constructor_; }
1535 ArgumentListNode* arguments() const { return arguments_; } 1553 ArgumentListNode* arguments() const { return arguments_; }
1536 const LocalVariable& allocated_object_var() const {
1537 return allocated_object_var_;
1538 }
1539 1554
1540 virtual void VisitChildren(AstNodeVisitor* visitor) const { 1555 virtual void VisitChildren(AstNodeVisitor* visitor) const {
1541 arguments()->Visit(visitor); 1556 arguments()->Visit(visitor);
1542 } 1557 }
1543 1558
1544 DECLARE_COMMON_NODE_FUNCTIONS(ConstructorCallNode); 1559 DECLARE_COMMON_NODE_FUNCTIONS(ConstructorCallNode);
1545 1560
1546 private: 1561 private:
1547 const AbstractTypeArguments& type_arguments_; 1562 const AbstractTypeArguments& type_arguments_;
1548 const Function& constructor_; 1563 const Function& constructor_;
1549 ArgumentListNode* arguments_; 1564 ArgumentListNode* arguments_;
1550 const LocalVariable& allocated_object_var_;
1551 1565
1552 DISALLOW_IMPLICIT_CONSTRUCTORS(ConstructorCallNode); 1566 DISALLOW_IMPLICIT_CONSTRUCTORS(ConstructorCallNode);
1553 }; 1567 };
1554 1568
1555 1569
1556 // The body of a Dart function marked as 'native' consists of this node. 1570 // The body of a Dart function marked as 'native' consists of this node.
1557 class NativeBodyNode : public AstNode { 1571 class NativeBodyNode : public AstNode {
1558 public: 1572 public:
1559 NativeBodyNode(intptr_t token_pos, 1573 NativeBodyNode(intptr_t token_pos,
1560 const Function& function, 1574 const Function& function,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 const LocalVariable& context_var_; 1758 const LocalVariable& context_var_;
1745 1759
1746 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); 1760 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode);
1747 }; 1761 };
1748 1762
1749 } // namespace dart 1763 } // namespace dart
1750 1764
1751 #undef DECLARE_COMMON_NODE_FUNCTIONS 1765 #undef DECLARE_COMMON_NODE_FUNCTIONS
1752 1766
1753 #endif // VM_AST_H_ 1767 #endif // VM_AST_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/ast.cc » ('j') | runtime/vm/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698