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

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

Issue 226953002: Implement deferred constant support (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 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') | no next file with comments »
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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 433
434 class ClosureNode : public AstNode { 434 class ClosureNode : public AstNode {
435 public: 435 public:
436 ClosureNode(intptr_t token_pos, 436 ClosureNode(intptr_t token_pos,
437 const Function& function, 437 const Function& function,
438 AstNode* receiver, // Non-null for implicit instance closures. 438 AstNode* receiver, // Non-null for implicit instance closures.
439 LocalScope* scope) // Null for implicit closures. 439 LocalScope* scope) // Null for implicit closures.
440 : AstNode(token_pos), 440 : AstNode(token_pos),
441 function_(function), 441 function_(function),
442 receiver_(receiver), 442 receiver_(receiver),
443 scope_(scope) { 443 scope_(scope),
444 is_deferred_reference_(false) {
444 ASSERT(function_.IsZoneHandle()); 445 ASSERT(function_.IsZoneHandle());
445 ASSERT((function_.IsNonImplicitClosureFunction() && 446 ASSERT((function_.IsNonImplicitClosureFunction() &&
446 (receiver_ == NULL) && (scope_ != NULL)) || 447 (receiver_ == NULL) && (scope_ != NULL)) ||
447 (function_.IsImplicitInstanceClosureFunction() && 448 (function_.IsImplicitInstanceClosureFunction() &&
448 (receiver_ != NULL) && (scope_ == NULL)) || 449 (receiver_ != NULL) && (scope_ == NULL)) ||
449 (function_.IsImplicitStaticClosureFunction() && 450 (function_.IsImplicitStaticClosureFunction() &&
450 (receiver_ == NULL) && (scope_ == NULL))); 451 (receiver_ == NULL) && (scope_ == NULL)));
451 } 452 }
452 453
453 const Function& function() const { return function_; } 454 const Function& function() const { return function_; }
454 AstNode* receiver() const { return receiver_; } 455 AstNode* receiver() const { return receiver_; }
455 LocalScope* scope() const { return scope_; } 456 LocalScope* scope() const { return scope_; }
456 457
458 void set_is_deferred(bool value) { is_deferred_reference_ = value; }
459
457 virtual void VisitChildren(AstNodeVisitor* visitor) const { 460 virtual void VisitChildren(AstNodeVisitor* visitor) const {
458 if (receiver() != NULL) { 461 if (receiver() != NULL) {
459 receiver()->Visit(visitor); 462 receiver()->Visit(visitor);
460 } 463 }
461 } 464 }
462 465
463 virtual AstNode* MakeAssignmentNode(AstNode* rhs); 466 virtual AstNode* MakeAssignmentNode(AstNode* rhs);
464 virtual bool IsPotentiallyConst() const; 467 virtual bool IsPotentiallyConst() const;
465 virtual const Instance* EvalConstExpr() const; 468 virtual const Instance* EvalConstExpr() const;
466 469
467 DECLARE_COMMON_NODE_FUNCTIONS(ClosureNode); 470 DECLARE_COMMON_NODE_FUNCTIONS(ClosureNode);
468 471
469 private: 472 private:
470 const Function& function_; 473 const Function& function_;
471 AstNode* receiver_; 474 AstNode* receiver_;
472 LocalScope* scope_; 475 LocalScope* scope_;
476 bool is_deferred_reference_;
473 477
474 DISALLOW_IMPLICIT_CONSTRUCTORS(ClosureNode); 478 DISALLOW_IMPLICIT_CONSTRUCTORS(ClosureNode);
475 }; 479 };
476 480
477 481
478 // Primary nodes hold identifiers or values (library, class or function) 482 // Primary nodes hold identifiers or values (library, class or function)
479 // resolved from an identifier. Primary nodes should not ever make it to the 483 // resolved from an identifier. Primary nodes should not ever make it to the
480 // code generation phase as they will be transformed into the correct call or 484 // code generation phase as they will be transformed into the correct call or
481 // field access nodes. 485 // field access nodes.
482 class PrimaryNode : public AstNode { 486 class PrimaryNode : public AstNode {
483 public: 487 public:
484 PrimaryNode(intptr_t token_pos, const Object& primary) 488 PrimaryNode(intptr_t token_pos, const Object& primary)
485 : AstNode(token_pos), primary_(primary) { 489 : AstNode(token_pos),
490 primary_(primary),
491 is_deferred_reference_(false) {
486 ASSERT(primary_.IsNotTemporaryScopedHandle()); 492 ASSERT(primary_.IsNotTemporaryScopedHandle());
487 } 493 }
488 494
489 const Object& primary() const { return primary_; } 495 const Object& primary() const { return primary_; }
490 496
497 void set_is_deferred(bool value) { is_deferred_reference_ = value; }
498 bool is_deferred_reference() const { return is_deferred_reference_; }
499
491 bool IsSuper() const { 500 bool IsSuper() const {
492 return primary().IsString() && (primary().raw() == Symbols::Super().raw()); 501 return primary().IsString() && (primary().raw() == Symbols::Super().raw());
493 } 502 }
494 503
495 virtual void VisitChildren(AstNodeVisitor* visitor) const; 504 virtual void VisitChildren(AstNodeVisitor* visitor) const;
496 505
497 DECLARE_COMMON_NODE_FUNCTIONS(PrimaryNode); 506 DECLARE_COMMON_NODE_FUNCTIONS(PrimaryNode);
498 507
499 private: 508 private:
500 const Object& primary_; 509 const Object& primary_;
510 bool is_deferred_reference_;
501 511
502 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimaryNode); 512 DISALLOW_IMPLICIT_CONSTRUCTORS(PrimaryNode);
503 }; 513 };
504 514
505 515
506 class ReturnNode : public AstNode { 516 class ReturnNode : public AstNode {
507 public: 517 public:
508 // Return from a void function returns the null object. 518 // Return from a void function returns the null object.
509 explicit ReturnNode(intptr_t token_pos) 519 explicit ReturnNode(intptr_t token_pos)
510 : AstNode(token_pos), 520 : AstNode(token_pos),
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 DECLARE_COMMON_NODE_FUNCTIONS(BinaryOpWithMask32Node); 672 DECLARE_COMMON_NODE_FUNCTIONS(BinaryOpWithMask32Node);
663 673
664 private: 674 private:
665 // Optional unsigned 32 bit mask applied on result. No mask: -1. 675 // Optional unsigned 32 bit mask applied on result. No mask: -1.
666 const int64_t mask32_; 676 const int64_t mask32_;
667 677
668 DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryOpWithMask32Node); 678 DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryOpWithMask32Node);
669 }; 679 };
670 680
671 681
672
673 class UnaryOpNode : public AstNode { 682 class UnaryOpNode : public AstNode {
674 public: 683 public:
675 // Returns optimized version, e.g., for ('-' '1') ('-1') literal is returned. 684 // Returns optimized version, e.g., for ('-' '1') ('-1') literal is returned.
676 static AstNode* UnaryOpOrLiteral(intptr_t token_pos, 685 static AstNode* UnaryOpOrLiteral(intptr_t token_pos,
677 Token::Kind kind, 686 Token::Kind kind,
678 AstNode* operand); 687 AstNode* operand);
679 UnaryOpNode(intptr_t token_pos, 688 UnaryOpNode(intptr_t token_pos,
680 Token::Kind kind, 689 Token::Kind kind,
681 AstNode* operand) 690 AstNode* operand)
682 : AstNode(token_pos), kind_(kind), operand_(operand) { 691 : AstNode(token_pos), kind_(kind), operand_(operand) {
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 const Field& field_; 1141 const Field& field_;
1133 AstNode* value_; 1142 AstNode* value_;
1134 1143
1135 DISALLOW_IMPLICIT_CONSTRUCTORS(StoreInstanceFieldNode); 1144 DISALLOW_IMPLICIT_CONSTRUCTORS(StoreInstanceFieldNode);
1136 }; 1145 };
1137 1146
1138 1147
1139 class LoadStaticFieldNode : public AstNode { 1148 class LoadStaticFieldNode : public AstNode {
1140 public: 1149 public:
1141 LoadStaticFieldNode(intptr_t token_pos, const Field& field) 1150 LoadStaticFieldNode(intptr_t token_pos, const Field& field)
1142 : AstNode(token_pos), field_(field) { 1151 : AstNode(token_pos), field_(field), is_deferred_reference_(false) {
1143 ASSERT(field_.IsZoneHandle()); 1152 ASSERT(field_.IsZoneHandle());
1144 } 1153 }
1145 1154
1146 const Field& field() const { return field_; } 1155 const Field& field() const { return field_; }
1156 void set_is_deferred(bool value) { is_deferred_reference_ = value; }
1147 1157
1148 virtual void VisitChildren(AstNodeVisitor* visitor) const { } 1158 virtual void VisitChildren(AstNodeVisitor* visitor) const { }
1149 1159
1150 virtual AstNode* MakeAssignmentNode(AstNode* rhs); 1160 virtual AstNode* MakeAssignmentNode(AstNode* rhs);
1151 1161
1152 virtual bool IsPotentiallyConst() const { 1162 virtual bool IsPotentiallyConst() const {
1153 return field_.is_const(); 1163 return field_.is_const();
1154 } 1164 }
1155 1165
1156 virtual const Instance* EvalConstExpr() const { 1166 virtual const Instance* EvalConstExpr() const {
1157 ASSERT(field_.is_static()); 1167 ASSERT(field_.is_static());
1158 return field_.is_const() ? &Instance::ZoneHandle(field_.value()) : NULL; 1168 if (is_deferred_reference_) printf("DDDDD\n");
srdjan 2014/04/07 17:19:10 Why only four Ds?
hausner 2014/04/07 17:30:27 Eins zwei drei vier fünf... DDDDDone.
1169 return !is_deferred_reference_ && field_.is_const()
1170 ? &Instance::ZoneHandle(field_.value())
1171 : NULL;
1159 } 1172 }
1160 1173
1161 DECLARE_COMMON_NODE_FUNCTIONS(LoadStaticFieldNode); 1174 DECLARE_COMMON_NODE_FUNCTIONS(LoadStaticFieldNode);
1162 1175
1163 private: 1176 private:
1164 const Field& field_; 1177 const Field& field_;
1178 bool is_deferred_reference_;
1165 1179
1166 DISALLOW_IMPLICIT_CONSTRUCTORS(LoadStaticFieldNode); 1180 DISALLOW_IMPLICIT_CONSTRUCTORS(LoadStaticFieldNode);
1167 }; 1181 };
1168 1182
1169 1183
1170 class StoreStaticFieldNode : public AstNode { 1184 class StoreStaticFieldNode : public AstNode {
1171 public: 1185 public:
1172 StoreStaticFieldNode(intptr_t token_pos, const Field& field, AstNode* value) 1186 StoreStaticFieldNode(intptr_t token_pos, const Field& field, AstNode* value)
1173 : AstNode(token_pos), field_(field), value_(value) { 1187 : AstNode(token_pos), field_(field), value_(value) {
1174 ASSERT(field_.IsZoneHandle()); 1188 ASSERT(field_.IsZoneHandle());
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 public: 1392 public:
1379 StaticGetterNode(intptr_t token_pos, 1393 StaticGetterNode(intptr_t token_pos,
1380 AstNode* receiver, 1394 AstNode* receiver,
1381 bool is_super_getter, 1395 bool is_super_getter,
1382 const Class& cls, 1396 const Class& cls,
1383 const String& field_name) 1397 const String& field_name)
1384 : AstNode(token_pos), 1398 : AstNode(token_pos),
1385 receiver_(receiver), 1399 receiver_(receiver),
1386 cls_(cls), 1400 cls_(cls),
1387 field_name_(field_name), 1401 field_name_(field_name),
1388 is_super_getter_(is_super_getter) { 1402 is_super_getter_(is_super_getter),
1403 is_deferred_reference_(false) {
1389 ASSERT(cls_.IsZoneHandle()); 1404 ASSERT(cls_.IsZoneHandle());
1390 ASSERT(field_name_.IsZoneHandle()); 1405 ASSERT(field_name_.IsZoneHandle());
1391 ASSERT(field_name_.IsSymbol()); 1406 ASSERT(field_name_.IsSymbol());
1392 } 1407 }
1393 1408
1394 // The receiver is required 1409 // The receiver is required
1395 // 1) for a super getter (an instance method that is resolved at compile 1410 // 1) for a super getter (an instance method that is resolved at compile
1396 // time rather than at runtime). 1411 // time rather than at runtime).
1397 // 2) when transforming this StaticGetterNode issued in a non-static 1412 // 2) when transforming this StaticGetterNode issued in a non-static
1398 // context to an InstanceSetterNode. This may occurs when we find a 1413 // context to an InstanceSetterNode. This may occurs when we find a
1399 // static getter, but no field and no static setter are declared. 1414 // static getter, but no field and no static setter are declared.
1400 AstNode* receiver() const { return receiver_; } 1415 AstNode* receiver() const { return receiver_; }
1401 const Class& cls() const { return cls_; } 1416 const Class& cls() const { return cls_; }
1402 const String& field_name() const { return field_name_; } 1417 const String& field_name() const { return field_name_; }
1403 bool is_super_getter() const { return is_super_getter_; } 1418 bool is_super_getter() const { return is_super_getter_; }
1419 void set_is_deferred(bool value) { is_deferred_reference_ = value; }
1404 1420
1405 virtual void VisitChildren(AstNodeVisitor* visitor) const { } 1421 virtual void VisitChildren(AstNodeVisitor* visitor) const { }
1406 1422
1407 virtual AstNode* MakeAssignmentNode(AstNode* rhs); 1423 virtual AstNode* MakeAssignmentNode(AstNode* rhs);
1408 1424
1409 virtual bool IsPotentiallyConst() const; 1425 virtual bool IsPotentiallyConst() const;
1410 virtual const Instance* EvalConstExpr() const; 1426 virtual const Instance* EvalConstExpr() const;
1411 1427
1412 DECLARE_COMMON_NODE_FUNCTIONS(StaticGetterNode); 1428 DECLARE_COMMON_NODE_FUNCTIONS(StaticGetterNode);
1413 1429
1414 private: 1430 private:
1415 AstNode* receiver_; 1431 AstNode* receiver_;
1416 const Class& cls_; 1432 const Class& cls_;
1417 const String& field_name_; 1433 const String& field_name_;
1418 const bool is_super_getter_; 1434 const bool is_super_getter_;
1435 bool is_deferred_reference_;
1419 1436
1420 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticGetterNode); 1437 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticGetterNode);
1421 }; 1438 };
1422 1439
1423 1440
1424 class StaticSetterNode : public AstNode { 1441 class StaticSetterNode : public AstNode {
1425 public: 1442 public:
1426 StaticSetterNode(intptr_t token_pos, 1443 StaticSetterNode(intptr_t token_pos,
1427 AstNode* receiver, 1444 AstNode* receiver,
1428 const Class& cls, 1445 const Class& cls,
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 const intptr_t try_index_; 1803 const intptr_t try_index_;
1787 1804
1788 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode); 1805 DISALLOW_IMPLICIT_CONSTRUCTORS(InlinedFinallyNode);
1789 }; 1806 };
1790 1807
1791 } // namespace dart 1808 } // namespace dart
1792 1809
1793 #undef DECLARE_COMMON_NODE_FUNCTIONS 1810 #undef DECLARE_COMMON_NODE_FUNCTIONS
1794 1811
1795 #endif // VM_AST_H_ 1812 #endif // VM_AST_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698