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

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: cleaned up 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/ast.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 LetNode(intptr_t token_pos, intptr_t num_temps);
300
301 LocalVariable* temp(intptr_t i) const { return vars_[i]; }
302 const GrowableArray<AstNode*>& temp_expressions() const {
Kevin Millikin (Google) 2013/05/29 11:28:23 'temp_expression' sounds like the expression is te
Florian Schneider 2013/05/30 09:29:31 Done.
303 return temp_expressions_;
304 }
305 void SetTempExpression(intptr_t i, AstNode* node) {
hausner 2013/05/28 17:00:47 We typically use the ending -At for setters that a
Florian Schneider 2013/05/30 09:29:31 Redesigned to add expressions instead of prealloca
306 temp_expressions_[i] = node;
307 }
308
309 intptr_t num_temps() const {
310 return vars_.length();
311 }
312
313 AstNode* body() const { return body_; }
314 void set_body(AstNode* node) { body_ = node; }
315
316 void VisitChildren(AstNodeVisitor* visitor) const;
317
318 DECLARE_COMMON_NODE_FUNCTIONS(LetNode);
319
320 private:
321 GrowableArray<LocalVariable*> vars_;
322 GrowableArray<AstNode*> temp_expressions_;
323 AstNode* body_;
Kevin Millikin (Google) 2013/05/29 11:28:23 I think you should: (1) allow a list of AstNode* i
Florian Schneider 2013/05/30 09:29:31 Yes, I'll do that as a separate CL and added a TOD
324
325 DISALLOW_COPY_AND_ASSIGN(LetNode);
326 };
327
328
296 class ArrayNode : public AstNode { 329 class ArrayNode : public AstNode {
297 public: 330 public:
298 ArrayNode(intptr_t token_pos, 331 ArrayNode(intptr_t token_pos, const AbstractType& type)
299 const AbstractType& type,
300 const LocalVariable& temp)
301 : AstNode(token_pos), 332 : AstNode(token_pos),
302 type_(type), 333 type_(type),
303 temp_local_(temp),
304 elements_() { 334 elements_() {
305 CheckFields(); 335 CheckFields();
306 } 336 }
307 ArrayNode(intptr_t token_pos, 337 ArrayNode(intptr_t token_pos,
308 const AbstractType& type, 338 const AbstractType& type,
309 const LocalVariable& temp,
310 const GrowableArray<AstNode*>& elements) 339 const GrowableArray<AstNode*>& elements)
311 : AstNode(token_pos), 340 : AstNode(token_pos),
312 type_(type), 341 type_(type),
313 temp_local_(temp),
314 elements_(elements.length()) { 342 elements_(elements.length()) {
315 CheckFields(); 343 CheckFields();
316 for (intptr_t i = 0; i < elements.length(); i++) { 344 for (intptr_t i = 0; i < elements.length(); i++) {
317 elements_.Add(elements[i]); 345 elements_.Add(elements[i]);
318 } 346 }
319 } 347 }
320 348
321 void VisitChildren(AstNodeVisitor* visitor) const; 349 void VisitChildren(AstNodeVisitor* visitor) const;
322 350
323 intptr_t length() const { return elements_.length(); } 351 intptr_t length() const { return elements_.length(); }
324 352
325 AstNode* ElementAt(intptr_t index) const { return elements_[index]; } 353 AstNode* ElementAt(intptr_t index) const { return elements_[index]; }
326 void SetElementAt(intptr_t index, AstNode* value) { 354 void SetElementAt(intptr_t index, AstNode* value) {
327 elements_[index] = value; 355 elements_[index] = value;
328 } 356 }
329 void AddElement(AstNode* expr) { elements_.Add(expr); } 357 void AddElement(AstNode* expr) { elements_.Add(expr); }
330 358
331 const AbstractType& type() const { return type_; } 359 const AbstractType& type() const { return type_; }
332 360
333 const LocalVariable& temp_local() const { return temp_local_; }
334
335 DECLARE_COMMON_NODE_FUNCTIONS(ArrayNode); 361 DECLARE_COMMON_NODE_FUNCTIONS(ArrayNode);
336 362
337 private: 363 private:
338 const AbstractType& type_; 364 const AbstractType& type_;
339 const LocalVariable& temp_local_; // Store allocated array while filling it.
340 GrowableArray<AstNode*> elements_; 365 GrowableArray<AstNode*> elements_;
341 366
342 void CheckFields() { 367 void CheckFields() {
343 ASSERT(type_.IsZoneHandle()); 368 ASSERT(type_.IsZoneHandle());
344 ASSERT(!type_.IsNull()); 369 ASSERT(!type_.IsNull());
345 ASSERT(type_.IsFinalized()); 370 ASSERT(type_.IsFinalized());
346 // Type may be uninstantiated when creating a generic list literal. 371 // Type may be uninstantiated when creating a generic list literal.
347 ASSERT((type_.arguments() == AbstractTypeArguments::null()) || 372 ASSERT((type_.arguments() == AbstractTypeArguments::null()) ||
348 ((AbstractTypeArguments::Handle(type_.arguments()).Length() == 1))); 373 ((AbstractTypeArguments::Handle(type_.arguments()).Length() == 1)));
349 } 374 }
(...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 1525 // 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 1526 // 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 1527 // 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 1528 // the receiver at an offset in the receiver specified by the provided
1504 // instantiator_class. 1529 // instantiator_class.
1505 // 1530 //
1506 // If the caller to the constructor or to the factory is a factory, then the 1531 // 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 1532 // 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 1533 // type argument vector. This case is identified by a null and unneeded
1509 // instantiator_class. 1534 // 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 { 1535 class ConstructorCallNode : public AstNode {
1514 public: 1536 public:
1515 ConstructorCallNode(intptr_t token_pos, 1537 ConstructorCallNode(intptr_t token_pos,
1516 const AbstractTypeArguments& type_arguments, 1538 const AbstractTypeArguments& type_arguments,
1517 const Function& constructor, 1539 const Function& constructor,
1518 ArgumentListNode* arguments, 1540 ArgumentListNode* arguments)
1519 const LocalVariable* allocated_object_var)
1520 : AstNode(token_pos), 1541 : AstNode(token_pos),
1521 type_arguments_(type_arguments), 1542 type_arguments_(type_arguments),
1522 constructor_(constructor), 1543 constructor_(constructor),
1523 arguments_(arguments), 1544 arguments_(arguments) {
1524 allocated_object_var_(*allocated_object_var) {
1525 ASSERT(type_arguments_.IsZoneHandle()); 1545 ASSERT(type_arguments_.IsZoneHandle());
1526 ASSERT(constructor_.IsZoneHandle()); 1546 ASSERT(constructor_.IsZoneHandle());
1527 ASSERT(arguments_ != NULL); 1547 ASSERT(arguments_ != NULL);
1528 ASSERT(allocated_object_var != NULL);
1529 } 1548 }
1530 1549
1531 const AbstractTypeArguments& type_arguments() const { 1550 const AbstractTypeArguments& type_arguments() const {
1532 return type_arguments_; 1551 return type_arguments_;
1533 } 1552 }
1534 const Function& constructor() const { return constructor_; } 1553 const Function& constructor() const { return constructor_; }
1535 ArgumentListNode* arguments() const { return arguments_; } 1554 ArgumentListNode* arguments() const { return arguments_; }
1536 const LocalVariable& allocated_object_var() const {
1537 return allocated_object_var_;
1538 }
1539 1555
1540 virtual void VisitChildren(AstNodeVisitor* visitor) const { 1556 virtual void VisitChildren(AstNodeVisitor* visitor) const {
1541 arguments()->Visit(visitor); 1557 arguments()->Visit(visitor);
1542 } 1558 }
1543 1559
1544 DECLARE_COMMON_NODE_FUNCTIONS(ConstructorCallNode); 1560 DECLARE_COMMON_NODE_FUNCTIONS(ConstructorCallNode);
1545 1561
1546 private: 1562 private:
1547 const AbstractTypeArguments& type_arguments_; 1563 const AbstractTypeArguments& type_arguments_;
1548 const Function& constructor_; 1564 const Function& constructor_;
1549 ArgumentListNode* arguments_; 1565 ArgumentListNode* arguments_;
1550 const LocalVariable& allocated_object_var_;
1551 1566
1552 DISALLOW_IMPLICIT_CONSTRUCTORS(ConstructorCallNode); 1567 DISALLOW_IMPLICIT_CONSTRUCTORS(ConstructorCallNode);
1553 }; 1568 };
1554 1569
1555 1570
1556 // The body of a Dart function marked as 'native' consists of this node. 1571 // The body of a Dart function marked as 'native' consists of this node.
1557 class NativeBodyNode : public AstNode { 1572 class NativeBodyNode : public AstNode {
1558 public: 1573 public:
1559 NativeBodyNode(intptr_t token_pos, 1574 NativeBodyNode(intptr_t token_pos,
1560 const Function& function, 1575 const Function& function,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 const LocalVariable& context_var_; 1759 const LocalVariable& context_var_;
1745 1760
1746 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); 1761 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode);
1747 }; 1762 };
1748 1763
1749 } // namespace dart 1764 } // namespace dart
1750 1765
1751 #undef DECLARE_COMMON_NODE_FUNCTIONS 1766 #undef DECLARE_COMMON_NODE_FUNCTIONS
1752 1767
1753 #endif // VM_AST_H_ 1768 #endif // VM_AST_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/ast.cc » ('j') | runtime/vm/ast.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698