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

Side by Side Diff: src/ast.h

Issue 314603004: Parser: Delay internalizing strings and values. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: More code review (rossberg@). Created 6 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 | « include/v8.h ('k') | src/ast.cc » ('j') | src/ast-value-factory.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_AST_H_ 5 #ifndef V8_AST_H_
6 #define V8_AST_H_ 6 #define V8_AST_H_
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/assembler.h" 10 #include "src/assembler.h"
11 #include "src/ast-value-factory.h"
11 #include "src/factory.h" 12 #include "src/factory.h"
12 #include "src/feedback-slots.h" 13 #include "src/feedback-slots.h"
13 #include "src/isolate.h" 14 #include "src/isolate.h"
14 #include "src/jsregexp.h" 15 #include "src/jsregexp.h"
15 #include "src/list-inl.h" 16 #include "src/list-inl.h"
16 #include "src/runtime.h" 17 #include "src/runtime.h"
17 #include "src/small-pointer-list.h" 18 #include "src/small-pointer-list.h"
18 #include "src/smart-pointers.h" 19 #include "src/smart-pointers.h"
19 #include "src/token.h" 20 #include "src/token.h"
20 #include "src/types.h" 21 #include "src/types.h"
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 // TODO(rossberg): this should move to its own AST node eventually. 361 // TODO(rossberg): this should move to its own AST node eventually.
361 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle); 362 virtual void RecordToBooleanTypeFeedback(TypeFeedbackOracle* oracle);
362 byte to_boolean_types() const { return to_boolean_types_; } 363 byte to_boolean_types() const { return to_boolean_types_; }
363 364
364 BailoutId id() const { return id_; } 365 BailoutId id() const { return id_; }
365 TypeFeedbackId test_id() const { return test_id_; } 366 TypeFeedbackId test_id() const { return test_id_; }
366 367
367 protected: 368 protected:
368 Expression(Zone* zone, int pos) 369 Expression(Zone* zone, int pos)
369 : AstNode(pos), 370 : AstNode(pos),
371 zone_(zone),
370 bounds_(Bounds::Unbounded(zone)), 372 bounds_(Bounds::Unbounded(zone)),
371 id_(GetNextId(zone)), 373 id_(GetNextId(zone)),
372 test_id_(GetNextId(zone)) {} 374 test_id_(GetNextId(zone)) {}
373 void set_to_boolean_types(byte types) { to_boolean_types_ = types; } 375 void set_to_boolean_types(byte types) { to_boolean_types_ = types; }
374 376
377 Zone* zone_;
378
375 private: 379 private:
376 Bounds bounds_; 380 Bounds bounds_;
377 byte to_boolean_types_; 381 byte to_boolean_types_;
378 382
379 const BailoutId id_; 383 const BailoutId id_;
380 const TypeFeedbackId test_id_; 384 const TypeFeedbackId test_id_;
381 }; 385 };
382 386
383 387
384 class BreakableStatement : public Statement { 388 class BreakableStatement : public Statement {
385 public: 389 public:
386 enum BreakableType { 390 enum BreakableType {
387 TARGET_FOR_ANONYMOUS, 391 TARGET_FOR_ANONYMOUS,
388 TARGET_FOR_NAMED_ONLY 392 TARGET_FOR_NAMED_ONLY
389 }; 393 };
390 394
391 // The labels associated with this statement. May be NULL; 395 // The labels associated with this statement. May be NULL;
392 // if it is != NULL, guaranteed to contain at least one entry. 396 // if it is != NULL, guaranteed to contain at least one entry.
393 ZoneStringList* labels() const { return labels_; } 397 ZoneList<const AstString*>* labels() const { return labels_; }
394 398
395 // Type testing & conversion. 399 // Type testing & conversion.
396 virtual BreakableStatement* AsBreakableStatement() V8_FINAL V8_OVERRIDE { 400 virtual BreakableStatement* AsBreakableStatement() V8_FINAL V8_OVERRIDE {
397 return this; 401 return this;
398 } 402 }
399 403
400 // Code generation 404 // Code generation
401 Label* break_target() { return &break_target_; } 405 Label* break_target() { return &break_target_; }
402 406
403 // Testers. 407 // Testers.
404 bool is_target_for_anonymous() const { 408 bool is_target_for_anonymous() const {
405 return breakable_type_ == TARGET_FOR_ANONYMOUS; 409 return breakable_type_ == TARGET_FOR_ANONYMOUS;
406 } 410 }
407 411
408 BailoutId EntryId() const { return entry_id_; } 412 BailoutId EntryId() const { return entry_id_; }
409 BailoutId ExitId() const { return exit_id_; } 413 BailoutId ExitId() const { return exit_id_; }
410 414
411 protected: 415 protected:
412 BreakableStatement( 416 BreakableStatement(
413 Zone* zone, ZoneStringList* labels, 417 Zone* zone, ZoneList<const AstString*>* labels,
414 BreakableType breakable_type, int position) 418 BreakableType breakable_type, int position)
415 : Statement(zone, position), 419 : Statement(zone, position),
416 labels_(labels), 420 labels_(labels),
417 breakable_type_(breakable_type), 421 breakable_type_(breakable_type),
418 entry_id_(GetNextId(zone)), 422 entry_id_(GetNextId(zone)),
419 exit_id_(GetNextId(zone)) { 423 exit_id_(GetNextId(zone)) {
420 ASSERT(labels == NULL || labels->length() > 0); 424 ASSERT(labels == NULL || labels->length() > 0);
421 } 425 }
422 426
423 427
424 private: 428 private:
425 ZoneStringList* labels_; 429 ZoneList<const AstString*>* labels_;
426 BreakableType breakable_type_; 430 BreakableType breakable_type_;
427 Label break_target_; 431 Label break_target_;
428 const BailoutId entry_id_; 432 const BailoutId entry_id_;
429 const BailoutId exit_id_; 433 const BailoutId exit_id_;
430 }; 434 };
431 435
432 436
433 class Block V8_FINAL : public BreakableStatement { 437 class Block V8_FINAL : public BreakableStatement {
434 public: 438 public:
435 DECLARE_NODE_TYPE(Block) 439 DECLARE_NODE_TYPE(Block)
(...skipping 10 matching lines...) Expand all
446 virtual bool IsJump() const V8_OVERRIDE { 450 virtual bool IsJump() const V8_OVERRIDE {
447 return !statements_.is_empty() && statements_.last()->IsJump() 451 return !statements_.is_empty() && statements_.last()->IsJump()
448 && labels() == NULL; // Good enough as an approximation... 452 && labels() == NULL; // Good enough as an approximation...
449 } 453 }
450 454
451 Scope* scope() const { return scope_; } 455 Scope* scope() const { return scope_; }
452 void set_scope(Scope* scope) { scope_ = scope; } 456 void set_scope(Scope* scope) { scope_ = scope; }
453 457
454 protected: 458 protected:
455 Block(Zone* zone, 459 Block(Zone* zone,
456 ZoneStringList* labels, 460 ZoneList<const AstString*>* labels,
457 int capacity, 461 int capacity,
458 bool is_initializer_block, 462 bool is_initializer_block,
459 int pos) 463 int pos)
460 : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos), 464 : BreakableStatement(zone, labels, TARGET_FOR_NAMED_ONLY, pos),
461 statements_(capacity, zone), 465 statements_(capacity, zone),
462 is_initializer_block_(is_initializer_block), 466 is_initializer_block_(is_initializer_block),
463 decls_id_(GetNextId(zone)), 467 decls_id_(GetNextId(zone)),
464 scope_(NULL) { 468 scope_(NULL) {
465 } 469 }
466 470
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 private: 659 private:
656 VariableProxy* proxy_; 660 VariableProxy* proxy_;
657 }; 661 };
658 662
659 663
660 class ModulePath V8_FINAL : public Module { 664 class ModulePath V8_FINAL : public Module {
661 public: 665 public:
662 DECLARE_NODE_TYPE(ModulePath) 666 DECLARE_NODE_TYPE(ModulePath)
663 667
664 Module* module() const { return module_; } 668 Module* module() const { return module_; }
665 Handle<String> name() const { return name_; } 669 Handle<String> name() const { return name_->string(); }
666 670
667 protected: 671 protected:
668 ModulePath(Zone* zone, Module* module, Handle<String> name, int pos) 672 ModulePath(Zone* zone, Module* module, const AstString* name, int pos)
669 : Module(zone, pos), 673 : Module(zone, pos), module_(module), name_(name) {}
670 module_(module),
671 name_(name) {
672 }
673 674
674 private: 675 private:
675 Module* module_; 676 Module* module_;
676 Handle<String> name_; 677 const AstString* name_;
677 }; 678 };
678 679
679 680
680 class ModuleUrl V8_FINAL : public Module { 681 class ModuleUrl V8_FINAL : public Module {
681 public: 682 public:
682 DECLARE_NODE_TYPE(ModuleUrl) 683 DECLARE_NODE_TYPE(ModuleUrl)
683 684
684 Handle<String> url() const { return url_; } 685 Handle<String> url() const { return url_; }
685 686
686 protected: 687 protected:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 Statement* body() const { return body_; } 724 Statement* body() const { return body_; }
724 725
725 BailoutId OsrEntryId() const { return osr_entry_id_; } 726 BailoutId OsrEntryId() const { return osr_entry_id_; }
726 virtual BailoutId ContinueId() const = 0; 727 virtual BailoutId ContinueId() const = 0;
727 virtual BailoutId StackCheckId() const = 0; 728 virtual BailoutId StackCheckId() const = 0;
728 729
729 // Code generation 730 // Code generation
730 Label* continue_target() { return &continue_target_; } 731 Label* continue_target() { return &continue_target_; }
731 732
732 protected: 733 protected:
733 IterationStatement(Zone* zone, ZoneStringList* labels, int pos) 734 IterationStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
734 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos), 735 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
735 body_(NULL), 736 body_(NULL),
736 osr_entry_id_(GetNextId(zone)) { 737 osr_entry_id_(GetNextId(zone)) {
737 } 738 }
738 739
739 void Initialize(Statement* body) { 740 void Initialize(Statement* body) {
740 body_ = body; 741 body_ = body;
741 } 742 }
742 743
743 private: 744 private:
(...skipping 13 matching lines...) Expand all
757 cond_ = cond; 758 cond_ = cond;
758 } 759 }
759 760
760 Expression* cond() const { return cond_; } 761 Expression* cond() const { return cond_; }
761 762
762 virtual BailoutId ContinueId() const V8_OVERRIDE { return continue_id_; } 763 virtual BailoutId ContinueId() const V8_OVERRIDE { return continue_id_; }
763 virtual BailoutId StackCheckId() const V8_OVERRIDE { return back_edge_id_; } 764 virtual BailoutId StackCheckId() const V8_OVERRIDE { return back_edge_id_; }
764 BailoutId BackEdgeId() const { return back_edge_id_; } 765 BailoutId BackEdgeId() const { return back_edge_id_; }
765 766
766 protected: 767 protected:
767 DoWhileStatement(Zone* zone, ZoneStringList* labels, int pos) 768 DoWhileStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
768 : IterationStatement(zone, labels, pos), 769 : IterationStatement(zone, labels, pos),
769 cond_(NULL), 770 cond_(NULL),
770 continue_id_(GetNextId(zone)), 771 continue_id_(GetNextId(zone)),
771 back_edge_id_(GetNextId(zone)) { 772 back_edge_id_(GetNextId(zone)) {
772 } 773 }
773 774
774 private: 775 private:
775 Expression* cond_; 776 Expression* cond_;
776 777
777 const BailoutId continue_id_; 778 const BailoutId continue_id_;
(...skipping 16 matching lines...) Expand all
794 } 795 }
795 void set_may_have_function_literal(bool value) { 796 void set_may_have_function_literal(bool value) {
796 may_have_function_literal_ = value; 797 may_have_function_literal_ = value;
797 } 798 }
798 799
799 virtual BailoutId ContinueId() const V8_OVERRIDE { return EntryId(); } 800 virtual BailoutId ContinueId() const V8_OVERRIDE { return EntryId(); }
800 virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; } 801 virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; }
801 BailoutId BodyId() const { return body_id_; } 802 BailoutId BodyId() const { return body_id_; }
802 803
803 protected: 804 protected:
804 WhileStatement(Zone* zone, ZoneStringList* labels, int pos) 805 WhileStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
805 : IterationStatement(zone, labels, pos), 806 : IterationStatement(zone, labels, pos),
806 cond_(NULL), 807 cond_(NULL),
807 may_have_function_literal_(true), 808 may_have_function_literal_(true),
808 body_id_(GetNextId(zone)) { 809 body_id_(GetNextId(zone)) {
809 } 810 }
810 811
811 private: 812 private:
812 Expression* cond_; 813 Expression* cond_;
813 814
814 // True if there is a function literal subexpression in the condition. 815 // True if there is a function literal subexpression in the condition.
(...skipping 30 matching lines...) Expand all
845 846
846 virtual BailoutId ContinueId() const V8_OVERRIDE { return continue_id_; } 847 virtual BailoutId ContinueId() const V8_OVERRIDE { return continue_id_; }
847 virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; } 848 virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; }
848 BailoutId BodyId() const { return body_id_; } 849 BailoutId BodyId() const { return body_id_; }
849 850
850 bool is_fast_smi_loop() { return loop_variable_ != NULL; } 851 bool is_fast_smi_loop() { return loop_variable_ != NULL; }
851 Variable* loop_variable() { return loop_variable_; } 852 Variable* loop_variable() { return loop_variable_; }
852 void set_loop_variable(Variable* var) { loop_variable_ = var; } 853 void set_loop_variable(Variable* var) { loop_variable_ = var; }
853 854
854 protected: 855 protected:
855 ForStatement(Zone* zone, ZoneStringList* labels, int pos) 856 ForStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
856 : IterationStatement(zone, labels, pos), 857 : IterationStatement(zone, labels, pos),
857 init_(NULL), 858 init_(NULL),
858 cond_(NULL), 859 cond_(NULL),
859 next_(NULL), 860 next_(NULL),
860 may_have_function_literal_(true), 861 may_have_function_literal_(true),
861 loop_variable_(NULL), 862 loop_variable_(NULL),
862 continue_id_(GetNextId(zone)), 863 continue_id_(GetNextId(zone)),
863 body_id_(GetNextId(zone)) { 864 body_id_(GetNextId(zone)) {
864 } 865 }
865 866
(...skipping 21 matching lines...) Expand all
887 void Initialize(Expression* each, Expression* subject, Statement* body) { 888 void Initialize(Expression* each, Expression* subject, Statement* body) {
888 IterationStatement::Initialize(body); 889 IterationStatement::Initialize(body);
889 each_ = each; 890 each_ = each;
890 subject_ = subject; 891 subject_ = subject;
891 } 892 }
892 893
893 Expression* each() const { return each_; } 894 Expression* each() const { return each_; }
894 Expression* subject() const { return subject_; } 895 Expression* subject() const { return subject_; }
895 896
896 protected: 897 protected:
897 ForEachStatement(Zone* zone, ZoneStringList* labels, int pos) 898 ForEachStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
898 : IterationStatement(zone, labels, pos), 899 : IterationStatement(zone, labels, pos), each_(NULL), subject_(NULL) {}
899 each_(NULL),
900 subject_(NULL) {
901 }
902 900
903 private: 901 private:
904 Expression* each_; 902 Expression* each_;
905 Expression* subject_; 903 Expression* subject_;
906 }; 904 };
907 905
908 906
909 class ForInStatement V8_FINAL : public ForEachStatement, 907 class ForInStatement V8_FINAL : public ForEachStatement,
910 public FeedbackSlotInterface { 908 public FeedbackSlotInterface {
911 public: 909 public:
(...skipping 15 matching lines...) Expand all
927 enum ForInType { FAST_FOR_IN, SLOW_FOR_IN }; 925 enum ForInType { FAST_FOR_IN, SLOW_FOR_IN };
928 ForInType for_in_type() const { return for_in_type_; } 926 ForInType for_in_type() const { return for_in_type_; }
929 void set_for_in_type(ForInType type) { for_in_type_ = type; } 927 void set_for_in_type(ForInType type) { for_in_type_ = type; }
930 928
931 BailoutId BodyId() const { return body_id_; } 929 BailoutId BodyId() const { return body_id_; }
932 BailoutId PrepareId() const { return prepare_id_; } 930 BailoutId PrepareId() const { return prepare_id_; }
933 virtual BailoutId ContinueId() const V8_OVERRIDE { return EntryId(); } 931 virtual BailoutId ContinueId() const V8_OVERRIDE { return EntryId(); }
934 virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; } 932 virtual BailoutId StackCheckId() const V8_OVERRIDE { return body_id_; }
935 933
936 protected: 934 protected:
937 ForInStatement(Zone* zone, ZoneStringList* labels, int pos) 935 ForInStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
938 : ForEachStatement(zone, labels, pos), 936 : ForEachStatement(zone, labels, pos),
939 for_in_type_(SLOW_FOR_IN), 937 for_in_type_(SLOW_FOR_IN),
940 for_in_feedback_slot_(kInvalidFeedbackSlot), 938 for_in_feedback_slot_(kInvalidFeedbackSlot),
941 body_id_(GetNextId(zone)), 939 body_id_(GetNextId(zone)),
942 prepare_id_(GetNextId(zone)) { 940 prepare_id_(GetNextId(zone)) {
943 } 941 }
944 942
945 ForInType for_in_type_; 943 ForInType for_in_type_;
946 int for_in_feedback_slot_; 944 int for_in_feedback_slot_;
947 const BailoutId body_id_; 945 const BailoutId body_id_;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 Expression* assign_each() const { 988 Expression* assign_each() const {
991 return assign_each_; 989 return assign_each_;
992 } 990 }
993 991
994 virtual BailoutId ContinueId() const V8_OVERRIDE { return EntryId(); } 992 virtual BailoutId ContinueId() const V8_OVERRIDE { return EntryId(); }
995 virtual BailoutId StackCheckId() const V8_OVERRIDE { return BackEdgeId(); } 993 virtual BailoutId StackCheckId() const V8_OVERRIDE { return BackEdgeId(); }
996 994
997 BailoutId BackEdgeId() const { return back_edge_id_; } 995 BailoutId BackEdgeId() const { return back_edge_id_; }
998 996
999 protected: 997 protected:
1000 ForOfStatement(Zone* zone, ZoneStringList* labels, int pos) 998 ForOfStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
1001 : ForEachStatement(zone, labels, pos), 999 : ForEachStatement(zone, labels, pos),
1002 assign_iterator_(NULL), 1000 assign_iterator_(NULL),
1003 next_result_(NULL), 1001 next_result_(NULL),
1004 result_done_(NULL), 1002 result_done_(NULL),
1005 assign_each_(NULL), 1003 assign_each_(NULL),
1006 back_edge_id_(GetNextId(zone)) { 1004 back_edge_id_(GetNextId(zone)) {
1007 } 1005 }
1008 1006
1009 Expression* assign_iterator_; 1007 Expression* assign_iterator_;
1010 Expression* next_result_; 1008 Expression* next_result_;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 1148
1151 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { 1149 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) {
1152 tag_ = tag; 1150 tag_ = tag;
1153 cases_ = cases; 1151 cases_ = cases;
1154 } 1152 }
1155 1153
1156 Expression* tag() const { return tag_; } 1154 Expression* tag() const { return tag_; }
1157 ZoneList<CaseClause*>* cases() const { return cases_; } 1155 ZoneList<CaseClause*>* cases() const { return cases_; }
1158 1156
1159 protected: 1157 protected:
1160 SwitchStatement(Zone* zone, ZoneStringList* labels, int pos) 1158 SwitchStatement(Zone* zone, ZoneList<const AstString*>* labels, int pos)
1161 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos), 1159 : BreakableStatement(zone, labels, TARGET_FOR_ANONYMOUS, pos),
1162 tag_(NULL), 1160 tag_(NULL),
1163 cases_(NULL) { } 1161 cases_(NULL) { }
1164 1162
1165 private: 1163 private:
1166 Expression* tag_; 1164 Expression* tag_;
1167 ZoneList<CaseClause*>* cases_; 1165 ZoneList<CaseClause*>* cases_;
1168 }; 1166 };
1169 1167
1170 1168
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 protected: 1328 protected:
1331 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {} 1329 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {}
1332 }; 1330 };
1333 1331
1334 1332
1335 class Literal V8_FINAL : public Expression { 1333 class Literal V8_FINAL : public Expression {
1336 public: 1334 public:
1337 DECLARE_NODE_TYPE(Literal) 1335 DECLARE_NODE_TYPE(Literal)
1338 1336
1339 virtual bool IsPropertyName() const V8_OVERRIDE { 1337 virtual bool IsPropertyName() const V8_OVERRIDE {
1340 if (value_->IsInternalizedString()) { 1338 return value_->IsPropertyName();
1341 uint32_t ignored;
1342 return !String::cast(*value_)->AsArrayIndex(&ignored);
1343 }
1344 return false;
1345 } 1339 }
1346 1340
1347 Handle<String> AsPropertyName() { 1341 Handle<String> AsPropertyName() {
1348 ASSERT(IsPropertyName()); 1342 ASSERT(IsPropertyName());
1349 return Handle<String>::cast(value_); 1343 return Handle<String>::cast(value());
1344 }
1345
1346 const AstString* AsRawPropertyName() {
1347 ASSERT(IsPropertyName());
1348 return value_->AsString();
1350 } 1349 }
1351 1350
1352 virtual bool ToBooleanIsTrue() const V8_OVERRIDE { 1351 virtual bool ToBooleanIsTrue() const V8_OVERRIDE {
1353 return value_->BooleanValue(); 1352 return value()->BooleanValue();
1354 } 1353 }
1355 virtual bool ToBooleanIsFalse() const V8_OVERRIDE { 1354 virtual bool ToBooleanIsFalse() const V8_OVERRIDE {
1356 return !value_->BooleanValue(); 1355 return !value()->BooleanValue();
1357 } 1356 }
1358 1357
1359 Handle<Object> value() const { return value_; } 1358 Handle<Object> value() const { return value_->value(); }
1359 const AstValue* raw_value() const { return value_; }
1360 1360
1361 // Support for using Literal as a HashMap key. NOTE: Currently, this works 1361 // Support for using Literal as a HashMap key. NOTE: Currently, this works
1362 // only for string and number literals! 1362 // only for string and number literals!
1363 uint32_t Hash() { return ToString()->Hash(); } 1363 uint32_t Hash() { return ToString()->Hash(); }
1364 1364
1365 static bool Match(void* literal1, void* literal2) { 1365 static bool Match(void* literal1, void* literal2) {
1366 Handle<String> s1 = static_cast<Literal*>(literal1)->ToString(); 1366 Handle<String> s1 = static_cast<Literal*>(literal1)->ToString();
1367 Handle<String> s2 = static_cast<Literal*>(literal2)->ToString(); 1367 Handle<String> s2 = static_cast<Literal*>(literal2)->ToString();
1368 return String::Equals(s1, s2); 1368 return String::Equals(s1, s2);
1369 } 1369 }
1370 1370
1371 TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); } 1371 TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); }
1372 1372
1373 protected: 1373 protected:
1374 Literal(Zone* zone, Handle<Object> value, int position) 1374 Literal(Zone* zone, const AstValue* value, int position)
1375 : Expression(zone, position), 1375 : Expression(zone, position),
1376 value_(value), 1376 value_(value),
1377 isolate_(zone->isolate()) { } 1377 isolate_(zone->isolate()) { }
1378 1378
1379 private: 1379 private:
1380 Handle<String> ToString(); 1380 Handle<String> ToString();
1381 1381
1382 Handle<Object> value_; 1382 const AstValue* value_;
1383 // TODO(dcarney): remove. this is only needed for Match and Hash. 1383 // TODO(dcarney): remove. this is only needed for Match and Hash.
1384 Isolate* isolate_; 1384 Isolate* isolate_;
1385 }; 1385 };
1386 1386
1387 1387
1388 // Base class for literals that needs space in the corresponding JSFunction. 1388 // Base class for literals that needs space in the corresponding JSFunction.
1389 class MaterializedLiteral : public Expression { 1389 class MaterializedLiteral : public Expression {
1390 public: 1390 public:
1391 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } 1391 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; }
1392 1392
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 class ObjectLiteralProperty V8_FINAL : public ZoneObject { 1443 class ObjectLiteralProperty V8_FINAL : public ZoneObject {
1444 public: 1444 public:
1445 enum Kind { 1445 enum Kind {
1446 CONSTANT, // Property with constant value (compile time). 1446 CONSTANT, // Property with constant value (compile time).
1447 COMPUTED, // Property with computed value (execution time). 1447 COMPUTED, // Property with computed value (execution time).
1448 MATERIALIZED_LITERAL, // Property value is a materialized literal. 1448 MATERIALIZED_LITERAL, // Property value is a materialized literal.
1449 GETTER, SETTER, // Property is an accessor function. 1449 GETTER, SETTER, // Property is an accessor function.
1450 PROTOTYPE // Property is __proto__. 1450 PROTOTYPE // Property is __proto__.
1451 }; 1451 };
1452 1452
1453 ObjectLiteralProperty(Zone* zone, Literal* key, Expression* value); 1453 ObjectLiteralProperty(Zone* zone, AstValueFactory* ast_value_factory,
1454 Literal* key, Expression* value);
1454 1455
1455 Literal* key() { return key_; } 1456 Literal* key() { return key_; }
1456 Expression* value() { return value_; } 1457 Expression* value() { return value_; }
1457 Kind kind() { return kind_; } 1458 Kind kind() { return kind_; }
1458 1459
1459 // Type feedback information. 1460 // Type feedback information.
1460 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1461 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1461 bool IsMonomorphic() { return !receiver_type_.is_null(); } 1462 bool IsMonomorphic() { return !receiver_type_.is_null(); }
1462 Handle<Map> GetReceiverType() { return receiver_type_; } 1463 Handle<Map> GetReceiverType() { return receiver_type_; }
1463 1464
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 bool may_store_doubles_; 1543 bool may_store_doubles_;
1543 bool has_function_; 1544 bool has_function_;
1544 }; 1545 };
1545 1546
1546 1547
1547 // Node for capturing a regexp literal. 1548 // Node for capturing a regexp literal.
1548 class RegExpLiteral V8_FINAL : public MaterializedLiteral { 1549 class RegExpLiteral V8_FINAL : public MaterializedLiteral {
1549 public: 1550 public:
1550 DECLARE_NODE_TYPE(RegExpLiteral) 1551 DECLARE_NODE_TYPE(RegExpLiteral)
1551 1552
1552 Handle<String> pattern() const { return pattern_; } 1553 Handle<String> pattern() const { return pattern_->string(); }
1553 Handle<String> flags() const { return flags_; } 1554 Handle<String> flags() const { return flags_->string(); }
1554 1555
1555 protected: 1556 protected:
1556 RegExpLiteral(Zone* zone, 1557 RegExpLiteral(Zone* zone,
1557 Handle<String> pattern, 1558 const AstString* pattern,
1558 Handle<String> flags, 1559 const AstString* flags,
1559 int literal_index, 1560 int literal_index,
1560 int pos) 1561 int pos)
1561 : MaterializedLiteral(zone, literal_index, pos), 1562 : MaterializedLiteral(zone, literal_index, pos),
1562 pattern_(pattern), 1563 pattern_(pattern),
1563 flags_(flags) { 1564 flags_(flags) {
1564 set_depth(1); 1565 set_depth(1);
1565 } 1566 }
1566 1567
1567 private: 1568 private:
1568 Handle<String> pattern_; 1569 const AstString* pattern_;
1569 Handle<String> flags_; 1570 const AstString* flags_;
1570 }; 1571 };
1571 1572
1572 1573
1573 // An array literal has a literals object that is used 1574 // An array literal has a literals object that is used
1574 // for minimizing the work when constructing it at runtime. 1575 // for minimizing the work when constructing it at runtime.
1575 class ArrayLiteral V8_FINAL : public MaterializedLiteral { 1576 class ArrayLiteral V8_FINAL : public MaterializedLiteral {
1576 public: 1577 public:
1577 DECLARE_NODE_TYPE(ArrayLiteral) 1578 DECLARE_NODE_TYPE(ArrayLiteral)
1578 1579
1579 Handle<FixedArray> constant_elements() const { return constant_elements_; } 1580 Handle<FixedArray> constant_elements() const { return constant_elements_; }
(...skipping 30 matching lines...) Expand all
1610 1611
1611 1612
1612 class VariableProxy V8_FINAL : public Expression { 1613 class VariableProxy V8_FINAL : public Expression {
1613 public: 1614 public:
1614 DECLARE_NODE_TYPE(VariableProxy) 1615 DECLARE_NODE_TYPE(VariableProxy)
1615 1616
1616 virtual bool IsValidReferenceExpression() const V8_OVERRIDE { 1617 virtual bool IsValidReferenceExpression() const V8_OVERRIDE {
1617 return var_ == NULL ? true : var_->IsValidReference(); 1618 return var_ == NULL ? true : var_->IsValidReference();
1618 } 1619 }
1619 1620
1620 bool IsVariable(Handle<String> n) const {
1621 return !is_this() && name().is_identical_to(n);
1622 }
1623
1624 bool IsArguments() const { return var_ != NULL && var_->is_arguments(); } 1621 bool IsArguments() const { return var_ != NULL && var_->is_arguments(); }
1625 1622
1626 bool IsLValue() const { return is_lvalue_; } 1623 bool IsLValue() const { return is_lvalue_; }
1627 1624
1628 Handle<String> name() const { return name_; } 1625 Handle<String> name() const { return name_->string(); }
1626 const AstString* raw_name() const { return name_; }
1629 Variable* var() const { return var_; } 1627 Variable* var() const { return var_; }
1630 bool is_this() const { return is_this_; } 1628 bool is_this() const { return is_this_; }
1631 Interface* interface() const { return interface_; } 1629 Interface* interface() const { return interface_; }
1632 1630
1633 1631
1634 void MarkAsTrivial() { is_trivial_ = true; } 1632 void MarkAsTrivial() { is_trivial_ = true; }
1635 void MarkAsLValue() { is_lvalue_ = true; } 1633 void MarkAsLValue() { is_lvalue_ = true; }
1636 1634
1637 // Bind this proxy to the variable var. Interfaces must match. 1635 // Bind this proxy to the variable var. Interfaces must match.
1638 void BindTo(Variable* var); 1636 void BindTo(Variable* var);
1639 1637
1640 protected: 1638 protected:
1641 VariableProxy(Zone* zone, Variable* var, int position); 1639 VariableProxy(Zone* zone, Variable* var, int position);
1642 1640
1643 VariableProxy(Zone* zone, 1641 VariableProxy(Zone* zone,
1644 Handle<String> name, 1642 const AstString* name,
1645 bool is_this, 1643 bool is_this,
1646 Interface* interface, 1644 Interface* interface,
1647 int position); 1645 int position);
1648 1646
1649 Handle<String> name_; 1647 const AstString* name_;
1650 Variable* var_; // resolved variable, or NULL 1648 Variable* var_; // resolved variable, or NULL
1651 bool is_this_; 1649 bool is_this_;
1652 bool is_trivial_; 1650 bool is_trivial_;
1653 // True if this variable proxy is being used in an assignment 1651 // True if this variable proxy is being used in an assignment
1654 // or with a increment/decrement operator. 1652 // or with a increment/decrement operator.
1655 bool is_lvalue_; 1653 bool is_lvalue_;
1656 Interface* interface_; 1654 Interface* interface_;
1657 }; 1655 };
1658 1656
1659 1657
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 1883
1886 1884
1887 // The CallRuntime class does not represent any official JavaScript 1885 // The CallRuntime class does not represent any official JavaScript
1888 // language construct. Instead it is used to call a C or JS function 1886 // language construct. Instead it is used to call a C or JS function
1889 // with a set of arguments. This is used from the builtins that are 1887 // with a set of arguments. This is used from the builtins that are
1890 // implemented in JavaScript (see "v8natives.js"). 1888 // implemented in JavaScript (see "v8natives.js").
1891 class CallRuntime V8_FINAL : public Expression { 1889 class CallRuntime V8_FINAL : public Expression {
1892 public: 1890 public:
1893 DECLARE_NODE_TYPE(CallRuntime) 1891 DECLARE_NODE_TYPE(CallRuntime)
1894 1892
1895 Handle<String> name() const { return name_; } 1893 Handle<String> name() const { return raw_name_->string(); }
1894 const AstString* raw_name() const { return raw_name_; }
1896 const Runtime::Function* function() const { return function_; } 1895 const Runtime::Function* function() const { return function_; }
1897 ZoneList<Expression*>* arguments() const { return arguments_; } 1896 ZoneList<Expression*>* arguments() const { return arguments_; }
1898 bool is_jsruntime() const { return function_ == NULL; } 1897 bool is_jsruntime() const { return function_ == NULL; }
1899 1898
1900 TypeFeedbackId CallRuntimeFeedbackId() const { return reuse(id()); } 1899 TypeFeedbackId CallRuntimeFeedbackId() const { return reuse(id()); }
1901 1900
1902 protected: 1901 protected:
1903 CallRuntime(Zone* zone, 1902 CallRuntime(Zone* zone,
1904 Handle<String> name, 1903 const AstString* name,
1905 const Runtime::Function* function, 1904 const Runtime::Function* function,
1906 ZoneList<Expression*>* arguments, 1905 ZoneList<Expression*>* arguments,
1907 int pos) 1906 int pos)
1908 : Expression(zone, pos), 1907 : Expression(zone, pos),
1909 name_(name), 1908 raw_name_(name),
1910 function_(function), 1909 function_(function),
1911 arguments_(arguments) { } 1910 arguments_(arguments) { }
1912 1911
1913 private: 1912 private:
1914 Handle<String> name_; 1913 const AstString* raw_name_;
1915 const Runtime::Function* function_; 1914 const Runtime::Function* function_;
1916 ZoneList<Expression*>* arguments_; 1915 ZoneList<Expression*>* arguments_;
1917 }; 1916 };
1918 1917
1919 1918
1920 class UnaryOperation V8_FINAL : public Expression { 1919 class UnaryOperation V8_FINAL : public Expression {
1921 public: 1920 public:
1922 DECLARE_NODE_TYPE(UnaryOperation) 1921 DECLARE_NODE_TYPE(UnaryOperation)
1923 1922
1924 Token::Value op() const { return op_; } 1923 Token::Value op() const { return op_; }
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
2292 kNotParenthesized 2291 kNotParenthesized
2293 }; 2292 };
2294 2293
2295 enum IsGeneratorFlag { 2294 enum IsGeneratorFlag {
2296 kIsGenerator, 2295 kIsGenerator,
2297 kNotGenerator 2296 kNotGenerator
2298 }; 2297 };
2299 2298
2300 DECLARE_NODE_TYPE(FunctionLiteral) 2299 DECLARE_NODE_TYPE(FunctionLiteral)
2301 2300
2302 Handle<String> name() const { return name_; } 2301 Handle<String> name() const { return raw_name_->string(); }
2302 const AstString* raw_name() const { return raw_name_; }
2303 Scope* scope() const { return scope_; } 2303 Scope* scope() const { return scope_; }
2304 ZoneList<Statement*>* body() const { return body_; } 2304 ZoneList<Statement*>* body() const { return body_; }
2305 void set_function_token_position(int pos) { function_token_position_ = pos; } 2305 void set_function_token_position(int pos) { function_token_position_ = pos; }
2306 int function_token_position() const { return function_token_position_; } 2306 int function_token_position() const { return function_token_position_; }
2307 int start_position() const; 2307 int start_position() const;
2308 int end_position() const; 2308 int end_position() const;
2309 int SourceSize() const { return end_position() - start_position(); } 2309 int SourceSize() const { return end_position() - start_position(); }
2310 bool is_expression() const { return IsExpression::decode(bitfield_); } 2310 bool is_expression() const { return IsExpression::decode(bitfield_); }
2311 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); } 2311 bool is_anonymous() const { return IsAnonymous::decode(bitfield_); }
2312 StrictMode strict_mode() const; 2312 StrictMode strict_mode() const;
2313 2313
2314 int materialized_literal_count() { return materialized_literal_count_; } 2314 int materialized_literal_count() { return materialized_literal_count_; }
2315 int expected_property_count() { return expected_property_count_; } 2315 int expected_property_count() { return expected_property_count_; }
2316 int handler_count() { return handler_count_; } 2316 int handler_count() { return handler_count_; }
2317 int parameter_count() { return parameter_count_; } 2317 int parameter_count() { return parameter_count_; }
2318 2318
2319 bool AllowsLazyCompilation(); 2319 bool AllowsLazyCompilation();
2320 bool AllowsLazyCompilationWithoutContext(); 2320 bool AllowsLazyCompilationWithoutContext();
2321 2321
2322 void InitializeSharedInfo(Handle<Code> code); 2322 void InitializeSharedInfo(Handle<Code> code);
2323 2323
2324 Handle<String> debug_name() const { 2324 Handle<String> debug_name() const {
2325 if (name_->length() > 0) return name_; 2325 if (raw_name_ != NULL && !raw_name_->IsEmpty()) {
2326 return raw_name_->string();
2327 }
2326 return inferred_name(); 2328 return inferred_name();
2327 } 2329 }
2328 2330
2329 Handle<String> inferred_name() const { return inferred_name_; } 2331 Handle<String> inferred_name() const {
2332 if (!inferred_name_.is_null()) {
2333 ASSERT(raw_inferred_name_ == NULL);
2334 return inferred_name_;
2335 }
2336 if (raw_inferred_name_ != NULL) {
2337 return raw_inferred_name_->string();
2338 }
2339 UNREACHABLE();
2340 return Handle<String>();
2341 }
2342
2343 // Only one of {set_inferred_name, set_raw_inferred_name} should be called.
2330 void set_inferred_name(Handle<String> inferred_name) { 2344 void set_inferred_name(Handle<String> inferred_name) {
2331 inferred_name_ = inferred_name; 2345 inferred_name_ = inferred_name;
2346 ASSERT(raw_inferred_name_== NULL || raw_inferred_name_->IsEmpty());
2347 raw_inferred_name_ = NULL;
2348 }
2349
2350 void set_raw_inferred_name(const AstString* raw_inferred_name) {
2351 raw_inferred_name_ = raw_inferred_name;
2352 ASSERT(inferred_name_.is_null());
2353 inferred_name_ = Handle<String>();
2332 } 2354 }
2333 2355
2334 // shared_info may be null if it's not cached in full code. 2356 // shared_info may be null if it's not cached in full code.
2335 Handle<SharedFunctionInfo> shared_info() { return shared_info_; } 2357 Handle<SharedFunctionInfo> shared_info() { return shared_info_; }
2336 2358
2337 bool pretenure() { return Pretenure::decode(bitfield_); } 2359 bool pretenure() { return Pretenure::decode(bitfield_); }
2338 void set_pretenure() { bitfield_ |= Pretenure::encode(true); } 2360 void set_pretenure() { bitfield_ |= Pretenure::encode(true); }
2339 2361
2340 bool has_duplicate_parameters() { 2362 bool has_duplicate_parameters() {
2341 return HasDuplicateParameters::decode(bitfield_); 2363 return HasDuplicateParameters::decode(bitfield_);
(...skipping 26 matching lines...) Expand all
2368 return ast_properties_.feedback_slots(); 2390 return ast_properties_.feedback_slots();
2369 } 2391 }
2370 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } 2392 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
2371 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } 2393 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
2372 void set_dont_optimize_reason(BailoutReason reason) { 2394 void set_dont_optimize_reason(BailoutReason reason) {
2373 dont_optimize_reason_ = reason; 2395 dont_optimize_reason_ = reason;
2374 } 2396 }
2375 2397
2376 protected: 2398 protected:
2377 FunctionLiteral(Zone* zone, 2399 FunctionLiteral(Zone* zone,
2378 Handle<String> name, 2400 const AstString* name,
2401 AstValueFactory* ast_value_factory,
2379 Scope* scope, 2402 Scope* scope,
2380 ZoneList<Statement*>* body, 2403 ZoneList<Statement*>* body,
2381 int materialized_literal_count, 2404 int materialized_literal_count,
2382 int expected_property_count, 2405 int expected_property_count,
2383 int handler_count, 2406 int handler_count,
2384 int parameter_count, 2407 int parameter_count,
2385 FunctionType function_type, 2408 FunctionType function_type,
2386 ParameterFlag has_duplicate_parameters, 2409 ParameterFlag has_duplicate_parameters,
2387 IsFunctionFlag is_function, 2410 IsFunctionFlag is_function,
2388 IsParenthesizedFlag is_parenthesized, 2411 IsParenthesizedFlag is_parenthesized,
2389 IsGeneratorFlag is_generator, 2412 IsGeneratorFlag is_generator,
2390 int position) 2413 int position)
2391 : Expression(zone, position), 2414 : Expression(zone, position),
2392 name_(name), 2415 raw_name_(name),
2393 scope_(scope), 2416 scope_(scope),
2394 body_(body), 2417 body_(body),
2395 inferred_name_(zone->isolate()->factory()->empty_string()), 2418 raw_inferred_name_(ast_value_factory->empty_string()),
2396 dont_optimize_reason_(kNoReason), 2419 dont_optimize_reason_(kNoReason),
2397 materialized_literal_count_(materialized_literal_count), 2420 materialized_literal_count_(materialized_literal_count),
2398 expected_property_count_(expected_property_count), 2421 expected_property_count_(expected_property_count),
2399 handler_count_(handler_count), 2422 handler_count_(handler_count),
2400 parameter_count_(parameter_count), 2423 parameter_count_(parameter_count),
2401 function_token_position_(RelocInfo::kNoPosition) { 2424 function_token_position_(RelocInfo::kNoPosition) {
2402 bitfield_ = 2425 bitfield_ =
2403 IsExpression::encode(function_type != DECLARATION) | 2426 IsExpression::encode(function_type != DECLARATION) |
2404 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | 2427 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) |
2405 Pretenure::encode(false) | 2428 Pretenure::encode(false) |
2406 HasDuplicateParameters::encode(has_duplicate_parameters) | 2429 HasDuplicateParameters::encode(has_duplicate_parameters) |
2407 IsFunction::encode(is_function) | 2430 IsFunction::encode(is_function) |
2408 IsParenthesized::encode(is_parenthesized) | 2431 IsParenthesized::encode(is_parenthesized) |
2409 IsGenerator::encode(is_generator); 2432 IsGenerator::encode(is_generator);
2410 } 2433 }
2411 2434
2412 private: 2435 private:
2436 const AstString* raw_name_;
2413 Handle<String> name_; 2437 Handle<String> name_;
2414 Handle<SharedFunctionInfo> shared_info_; 2438 Handle<SharedFunctionInfo> shared_info_;
2415 Scope* scope_; 2439 Scope* scope_;
2416 ZoneList<Statement*>* body_; 2440 ZoneList<Statement*>* body_;
2441 const AstString* raw_inferred_name_;
2417 Handle<String> inferred_name_; 2442 Handle<String> inferred_name_;
2418 AstProperties ast_properties_; 2443 AstProperties ast_properties_;
2419 BailoutReason dont_optimize_reason_; 2444 BailoutReason dont_optimize_reason_;
2420 2445
2421 int materialized_literal_count_; 2446 int materialized_literal_count_;
2422 int expected_property_count_; 2447 int expected_property_count_;
2423 int handler_count_; 2448 int handler_count_;
2424 int parameter_count_; 2449 int parameter_count_;
2425 int function_token_position_; 2450 int function_token_position_;
2426 2451
2427 unsigned bitfield_; 2452 unsigned bitfield_;
2428 class IsExpression: public BitField<bool, 0, 1> {}; 2453 class IsExpression: public BitField<bool, 0, 1> {};
2429 class IsAnonymous: public BitField<bool, 1, 1> {}; 2454 class IsAnonymous: public BitField<bool, 1, 1> {};
2430 class Pretenure: public BitField<bool, 2, 1> {}; 2455 class Pretenure: public BitField<bool, 2, 1> {};
2431 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {}; 2456 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {};
2432 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {}; 2457 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {};
2433 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {}; 2458 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {};
2434 class IsGenerator: public BitField<IsGeneratorFlag, 6, 1> {}; 2459 class IsGenerator: public BitField<IsGeneratorFlag, 6, 1> {};
2435 }; 2460 };
2436 2461
2437 2462
2438 class NativeFunctionLiteral V8_FINAL : public Expression { 2463 class NativeFunctionLiteral V8_FINAL : public Expression {
2439 public: 2464 public:
2440 DECLARE_NODE_TYPE(NativeFunctionLiteral) 2465 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2441 2466
2442 Handle<String> name() const { return name_; } 2467 Handle<String> name() const { return name_->string(); }
2443 v8::Extension* extension() const { return extension_; } 2468 v8::Extension* extension() const { return extension_; }
2444 2469
2445 protected: 2470 protected:
2446 NativeFunctionLiteral( 2471 NativeFunctionLiteral(Zone* zone, const AstString* name,
2447 Zone* zone, Handle<String> name, v8::Extension* extension, int pos) 2472 v8::Extension* extension, int pos)
2448 : Expression(zone, pos), name_(name), extension_(extension) {} 2473 : Expression(zone, pos), name_(name), extension_(extension) {}
2449 2474
2450 private: 2475 private:
2451 Handle<String> name_; 2476 const AstString* name_;
2452 v8::Extension* extension_; 2477 v8::Extension* extension_;
2453 }; 2478 };
2454 2479
2455 2480
2456 class ThisFunction V8_FINAL : public Expression { 2481 class ThisFunction V8_FINAL : public Expression {
2457 public: 2482 public:
2458 DECLARE_NODE_TYPE(ThisFunction) 2483 DECLARE_NODE_TYPE(ThisFunction)
2459 2484
2460 protected: 2485 protected:
2461 explicit ThisFunction(Zone* zone, int pos): Expression(zone, pos) {} 2486 explicit ThisFunction(Zone* zone, int pos): Expression(zone, pos) {}
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
2933 }; 2958 };
2934 2959
2935 2960
2936 2961
2937 // ---------------------------------------------------------------------------- 2962 // ----------------------------------------------------------------------------
2938 // AstNode factory 2963 // AstNode factory
2939 2964
2940 template<class Visitor> 2965 template<class Visitor>
2941 class AstNodeFactory V8_FINAL BASE_EMBEDDED { 2966 class AstNodeFactory V8_FINAL BASE_EMBEDDED {
2942 public: 2967 public:
2943 explicit AstNodeFactory(Zone* zone) : zone_(zone) { } 2968 explicit AstNodeFactory(Zone* zone, AstValueFactory* ast_value_factory)
2969 : zone_(zone), ast_value_factory_(ast_value_factory) {}
2944 2970
2945 Visitor* visitor() { return &visitor_; } 2971 Visitor* visitor() { return &visitor_; }
2946 2972
2947 #define VISIT_AND_RETURN(NodeType, node) \ 2973 #define VISIT_AND_RETURN(NodeType, node) \
2948 visitor_.Visit##NodeType((node)); \ 2974 visitor_.Visit##NodeType((node)); \
2949 return node; 2975 return node;
2950 2976
2951 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, 2977 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
2952 VariableMode mode, 2978 VariableMode mode,
2953 Scope* scope, 2979 Scope* scope,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2997 ModuleLiteral* module = 3023 ModuleLiteral* module =
2998 new(zone_) ModuleLiteral(zone_, body, interface, pos); 3024 new(zone_) ModuleLiteral(zone_, body, interface, pos);
2999 VISIT_AND_RETURN(ModuleLiteral, module) 3025 VISIT_AND_RETURN(ModuleLiteral, module)
3000 } 3026 }
3001 3027
3002 ModuleVariable* NewModuleVariable(VariableProxy* proxy, int pos) { 3028 ModuleVariable* NewModuleVariable(VariableProxy* proxy, int pos) {
3003 ModuleVariable* module = new(zone_) ModuleVariable(zone_, proxy, pos); 3029 ModuleVariable* module = new(zone_) ModuleVariable(zone_, proxy, pos);
3004 VISIT_AND_RETURN(ModuleVariable, module) 3030 VISIT_AND_RETURN(ModuleVariable, module)
3005 } 3031 }
3006 3032
3007 ModulePath* NewModulePath(Module* origin, Handle<String> name, int pos) { 3033 ModulePath* NewModulePath(Module* origin, const AstString* name, int pos) {
3008 ModulePath* module = new(zone_) ModulePath(zone_, origin, name, pos); 3034 ModulePath* module = new (zone_) ModulePath(zone_, origin, name, pos);
3009 VISIT_AND_RETURN(ModulePath, module) 3035 VISIT_AND_RETURN(ModulePath, module)
3010 } 3036 }
3011 3037
3012 ModuleUrl* NewModuleUrl(Handle<String> url, int pos) { 3038 ModuleUrl* NewModuleUrl(Handle<String> url, int pos) {
3013 ModuleUrl* module = new(zone_) ModuleUrl(zone_, url, pos); 3039 ModuleUrl* module = new(zone_) ModuleUrl(zone_, url, pos);
3014 VISIT_AND_RETURN(ModuleUrl, module) 3040 VISIT_AND_RETURN(ModuleUrl, module)
3015 } 3041 }
3016 3042
3017 Block* NewBlock(ZoneStringList* labels, 3043 Block* NewBlock(ZoneList<const AstString*>* labels,
3018 int capacity, 3044 int capacity,
3019 bool is_initializer_block, 3045 bool is_initializer_block,
3020 int pos) { 3046 int pos) {
3021 Block* block = new(zone_) Block( 3047 Block* block = new(zone_) Block(
3022 zone_, labels, capacity, is_initializer_block, pos); 3048 zone_, labels, capacity, is_initializer_block, pos);
3023 VISIT_AND_RETURN(Block, block) 3049 VISIT_AND_RETURN(Block, block)
3024 } 3050 }
3025 3051
3026 #define STATEMENT_WITH_LABELS(NodeType) \ 3052 #define STATEMENT_WITH_LABELS(NodeType) \
3027 NodeType* New##NodeType(ZoneStringList* labels, int pos) { \ 3053 NodeType* New##NodeType(ZoneList<const AstString*>* labels, int pos) { \
3028 NodeType* stmt = new(zone_) NodeType(zone_, labels, pos); \ 3054 NodeType* stmt = new(zone_) NodeType(zone_, labels, pos); \
3029 VISIT_AND_RETURN(NodeType, stmt); \ 3055 VISIT_AND_RETURN(NodeType, stmt); \
3030 } 3056 }
3031 STATEMENT_WITH_LABELS(DoWhileStatement) 3057 STATEMENT_WITH_LABELS(DoWhileStatement)
3032 STATEMENT_WITH_LABELS(WhileStatement) 3058 STATEMENT_WITH_LABELS(WhileStatement)
3033 STATEMENT_WITH_LABELS(ForStatement) 3059 STATEMENT_WITH_LABELS(ForStatement)
3034 STATEMENT_WITH_LABELS(SwitchStatement) 3060 STATEMENT_WITH_LABELS(SwitchStatement)
3035 #undef STATEMENT_WITH_LABELS 3061 #undef STATEMENT_WITH_LABELS
3036 3062
3037 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, 3063 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
3038 ZoneStringList* labels, 3064 ZoneList<const AstString*>* labels,
3039 int pos) { 3065 int pos) {
3040 switch (visit_mode) { 3066 switch (visit_mode) {
3041 case ForEachStatement::ENUMERATE: { 3067 case ForEachStatement::ENUMERATE: {
3042 ForInStatement* stmt = new(zone_) ForInStatement(zone_, labels, pos); 3068 ForInStatement* stmt = new(zone_) ForInStatement(zone_, labels, pos);
3043 VISIT_AND_RETURN(ForInStatement, stmt); 3069 VISIT_AND_RETURN(ForInStatement, stmt);
3044 } 3070 }
3045 case ForEachStatement::ITERATE: { 3071 case ForEachStatement::ITERATE: {
3046 ForOfStatement* stmt = new(zone_) ForOfStatement(zone_, labels, pos); 3072 ForOfStatement* stmt = new(zone_) ForOfStatement(zone_, labels, pos);
3047 VISIT_AND_RETURN(ForOfStatement, stmt); 3073 VISIT_AND_RETURN(ForOfStatement, stmt);
3048 } 3074 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
3125 return new(zone_) EmptyStatement(zone_, pos); 3151 return new(zone_) EmptyStatement(zone_, pos);
3126 } 3152 }
3127 3153
3128 CaseClause* NewCaseClause( 3154 CaseClause* NewCaseClause(
3129 Expression* label, ZoneList<Statement*>* statements, int pos) { 3155 Expression* label, ZoneList<Statement*>* statements, int pos) {
3130 CaseClause* clause = 3156 CaseClause* clause =
3131 new(zone_) CaseClause(zone_, label, statements, pos); 3157 new(zone_) CaseClause(zone_, label, statements, pos);
3132 VISIT_AND_RETURN(CaseClause, clause) 3158 VISIT_AND_RETURN(CaseClause, clause)
3133 } 3159 }
3134 3160
3135 Literal* NewLiteral(Handle<Object> handle, int pos) { 3161 Literal* NewStringLiteral(const AstString* string, int pos) {
3136 Literal* lit = new(zone_) Literal(zone_, handle, pos); 3162 Literal* lit =
3163 new (zone_) Literal(zone_, ast_value_factory_->NewString(string), pos);
3137 VISIT_AND_RETURN(Literal, lit) 3164 VISIT_AND_RETURN(Literal, lit)
3138 } 3165 }
3139 3166
3140 Literal* NewNumberLiteral(double number, int pos) { 3167 Literal* NewNumberLiteral(double number, int pos) {
3141 return NewLiteral( 3168 Literal* lit = new (zone_)
3142 zone_->isolate()->factory()->NewNumber(number, TENURED), pos); 3169 Literal(zone_, ast_value_factory_->NewNumber(number), pos);
3170 VISIT_AND_RETURN(Literal, lit)
3171 }
3172
3173 Literal* NewSmiLiteral(int number, int pos) {
3174 Literal* lit =
3175 new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
3176 VISIT_AND_RETURN(Literal, lit)
3177 }
3178
3179 Literal* NewBooleanLiteral(bool b, int pos) {
3180 Literal* lit =
3181 new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
3182 VISIT_AND_RETURN(Literal, lit)
3183 }
3184
3185 Literal* NewStringListLiteral(ZoneList<const AstString*>* strings, int pos) {
3186 Literal* lit = new (zone_)
3187 Literal(zone_, ast_value_factory_->NewStringList(strings), pos);
3188 VISIT_AND_RETURN(Literal, lit)
3189 }
3190
3191 Literal* NewNullLiteral(int pos) {
3192 Literal* lit =
3193 new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
3194 VISIT_AND_RETURN(Literal, lit)
3195 }
3196
3197 Literal* NewUndefinedLiteral(int pos) {
3198 Literal* lit =
3199 new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
3200 VISIT_AND_RETURN(Literal, lit)
3201 }
3202
3203 Literal* NewTheHoleLiteral(int pos) {
3204 Literal* lit =
3205 new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
3206 VISIT_AND_RETURN(Literal, lit)
3143 } 3207 }
3144 3208
3145 ObjectLiteral* NewObjectLiteral( 3209 ObjectLiteral* NewObjectLiteral(
3146 ZoneList<ObjectLiteral::Property*>* properties, 3210 ZoneList<ObjectLiteral::Property*>* properties,
3147 int literal_index, 3211 int literal_index,
3148 int boilerplate_properties, 3212 int boilerplate_properties,
3149 bool has_function, 3213 bool has_function,
3150 int pos) { 3214 int pos) {
3151 ObjectLiteral* lit = new(zone_) ObjectLiteral( 3215 ObjectLiteral* lit = new(zone_) ObjectLiteral(
3152 zone_, properties, literal_index, boilerplate_properties, 3216 zone_, properties, literal_index, boilerplate_properties,
3153 has_function, pos); 3217 has_function, pos);
3154 VISIT_AND_RETURN(ObjectLiteral, lit) 3218 VISIT_AND_RETURN(ObjectLiteral, lit)
3155 } 3219 }
3156 3220
3157 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key, 3221 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key,
3158 Expression* value) { 3222 Expression* value) {
3159 return new(zone_) ObjectLiteral::Property(zone_, key, value); 3223 return new (zone_)
3224 ObjectLiteral::Property(zone_, ast_value_factory_, key, value);
3160 } 3225 }
3161 3226
3162 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter, 3227 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter,
3163 FunctionLiteral* value, 3228 FunctionLiteral* value,
3164 int pos) { 3229 int pos) {
3165 ObjectLiteral::Property* prop = 3230 ObjectLiteral::Property* prop =
3166 new(zone_) ObjectLiteral::Property(zone_, is_getter, value); 3231 new(zone_) ObjectLiteral::Property(zone_, is_getter, value);
3167 prop->set_key(NewLiteral(value->name(), pos)); 3232 prop->set_key(NewStringLiteral(value->raw_name(), pos));
3168 return prop; // Not an AST node, will not be visited. 3233 return prop; // Not an AST node, will not be visited.
3169 } 3234 }
3170 3235
3171 RegExpLiteral* NewRegExpLiteral(Handle<String> pattern, 3236 RegExpLiteral* NewRegExpLiteral(const AstString* pattern,
3172 Handle<String> flags, 3237 const AstString* flags,
3173 int literal_index, 3238 int literal_index,
3174 int pos) { 3239 int pos) {
3175 RegExpLiteral* lit = 3240 RegExpLiteral* lit =
3176 new(zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos); 3241 new(zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos);
3177 VISIT_AND_RETURN(RegExpLiteral, lit); 3242 VISIT_AND_RETURN(RegExpLiteral, lit);
3178 } 3243 }
3179 3244
3180 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, 3245 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3181 int literal_index, 3246 int literal_index,
3182 int pos) { 3247 int pos) {
3183 ArrayLiteral* lit = new(zone_) ArrayLiteral( 3248 ArrayLiteral* lit = new(zone_) ArrayLiteral(
3184 zone_, values, literal_index, pos); 3249 zone_, values, literal_index, pos);
3185 VISIT_AND_RETURN(ArrayLiteral, lit) 3250 VISIT_AND_RETURN(ArrayLiteral, lit)
3186 } 3251 }
3187 3252
3188 VariableProxy* NewVariableProxy(Variable* var, 3253 VariableProxy* NewVariableProxy(Variable* var,
3189 int pos = RelocInfo::kNoPosition) { 3254 int pos = RelocInfo::kNoPosition) {
3190 VariableProxy* proxy = new(zone_) VariableProxy(zone_, var, pos); 3255 VariableProxy* proxy = new(zone_) VariableProxy(zone_, var, pos);
3191 VISIT_AND_RETURN(VariableProxy, proxy) 3256 VISIT_AND_RETURN(VariableProxy, proxy)
3192 } 3257 }
3193 3258
3194 VariableProxy* NewVariableProxy(Handle<String> name, 3259 VariableProxy* NewVariableProxy(const AstString* name,
3195 bool is_this, 3260 bool is_this,
3196 Interface* interface = Interface::NewValue(), 3261 Interface* interface = Interface::NewValue(),
3197 int position = RelocInfo::kNoPosition) { 3262 int position = RelocInfo::kNoPosition) {
3198 VariableProxy* proxy = 3263 VariableProxy* proxy =
3199 new(zone_) VariableProxy(zone_, name, is_this, interface, position); 3264 new(zone_) VariableProxy(zone_, name, is_this, interface, position);
3200 VISIT_AND_RETURN(VariableProxy, proxy) 3265 VISIT_AND_RETURN(VariableProxy, proxy)
3201 } 3266 }
3202 3267
3203 Property* NewProperty(Expression* obj, Expression* key, int pos) { 3268 Property* NewProperty(Expression* obj, Expression* key, int pos) {
3204 Property* prop = new(zone_) Property(zone_, obj, key, pos); 3269 Property* prop = new(zone_) Property(zone_, obj, key, pos);
3205 VISIT_AND_RETURN(Property, prop) 3270 VISIT_AND_RETURN(Property, prop)
3206 } 3271 }
3207 3272
3208 Call* NewCall(Expression* expression, 3273 Call* NewCall(Expression* expression,
3209 ZoneList<Expression*>* arguments, 3274 ZoneList<Expression*>* arguments,
3210 int pos) { 3275 int pos) {
3211 Call* call = new(zone_) Call(zone_, expression, arguments, pos); 3276 Call* call = new(zone_) Call(zone_, expression, arguments, pos);
3212 VISIT_AND_RETURN(Call, call) 3277 VISIT_AND_RETURN(Call, call)
3213 } 3278 }
3214 3279
3215 CallNew* NewCallNew(Expression* expression, 3280 CallNew* NewCallNew(Expression* expression,
3216 ZoneList<Expression*>* arguments, 3281 ZoneList<Expression*>* arguments,
3217 int pos) { 3282 int pos) {
3218 CallNew* call = new(zone_) CallNew(zone_, expression, arguments, pos); 3283 CallNew* call = new(zone_) CallNew(zone_, expression, arguments, pos);
3219 VISIT_AND_RETURN(CallNew, call) 3284 VISIT_AND_RETURN(CallNew, call)
3220 } 3285 }
3221 3286
3222 CallRuntime* NewCallRuntime(Handle<String> name, 3287 CallRuntime* NewCallRuntime(const AstString* name,
3223 const Runtime::Function* function, 3288 const Runtime::Function* function,
3224 ZoneList<Expression*>* arguments, 3289 ZoneList<Expression*>* arguments,
3225 int pos) { 3290 int pos) {
3226 CallRuntime* call = 3291 CallRuntime* call =
3227 new(zone_) CallRuntime(zone_, name, function, arguments, pos); 3292 new(zone_) CallRuntime(zone_, name, function, arguments, pos);
3228 VISIT_AND_RETURN(CallRuntime, call) 3293 VISIT_AND_RETURN(CallRuntime, call)
3229 } 3294 }
3230 3295
3231 UnaryOperation* NewUnaryOperation(Token::Value op, 3296 UnaryOperation* NewUnaryOperation(Token::Value op,
3232 Expression* expression, 3297 Expression* expression,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3290 zone_, generator_object, expression, yield_kind, pos); 3355 zone_, generator_object, expression, yield_kind, pos);
3291 VISIT_AND_RETURN(Yield, yield) 3356 VISIT_AND_RETURN(Yield, yield)
3292 } 3357 }
3293 3358
3294 Throw* NewThrow(Expression* exception, int pos) { 3359 Throw* NewThrow(Expression* exception, int pos) {
3295 Throw* t = new(zone_) Throw(zone_, exception, pos); 3360 Throw* t = new(zone_) Throw(zone_, exception, pos);
3296 VISIT_AND_RETURN(Throw, t) 3361 VISIT_AND_RETURN(Throw, t)
3297 } 3362 }
3298 3363
3299 FunctionLiteral* NewFunctionLiteral( 3364 FunctionLiteral* NewFunctionLiteral(
3300 Handle<String> name, 3365 const AstString* name,
3366 AstValueFactory* ast_value_factory,
3301 Scope* scope, 3367 Scope* scope,
3302 ZoneList<Statement*>* body, 3368 ZoneList<Statement*>* body,
3303 int materialized_literal_count, 3369 int materialized_literal_count,
3304 int expected_property_count, 3370 int expected_property_count,
3305 int handler_count, 3371 int handler_count,
3306 int parameter_count, 3372 int parameter_count,
3307 FunctionLiteral::ParameterFlag has_duplicate_parameters, 3373 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3308 FunctionLiteral::FunctionType function_type, 3374 FunctionLiteral::FunctionType function_type,
3309 FunctionLiteral::IsFunctionFlag is_function, 3375 FunctionLiteral::IsFunctionFlag is_function,
3310 FunctionLiteral::IsParenthesizedFlag is_parenthesized, 3376 FunctionLiteral::IsParenthesizedFlag is_parenthesized,
3311 FunctionLiteral::IsGeneratorFlag is_generator, 3377 FunctionLiteral::IsGeneratorFlag is_generator,
3312 int position) { 3378 int position) {
3313 FunctionLiteral* lit = new(zone_) FunctionLiteral( 3379 FunctionLiteral* lit = new(zone_) FunctionLiteral(
3314 zone_, name, scope, body, 3380 zone_, name, ast_value_factory, scope, body,
3315 materialized_literal_count, expected_property_count, handler_count, 3381 materialized_literal_count, expected_property_count, handler_count,
3316 parameter_count, function_type, has_duplicate_parameters, is_function, 3382 parameter_count, function_type, has_duplicate_parameters, is_function,
3317 is_parenthesized, is_generator, position); 3383 is_parenthesized, is_generator, position);
3318 // Top-level literal doesn't count for the AST's properties. 3384 // Top-level literal doesn't count for the AST's properties.
3319 if (is_function == FunctionLiteral::kIsFunction) { 3385 if (is_function == FunctionLiteral::kIsFunction) {
3320 visitor_.VisitFunctionLiteral(lit); 3386 visitor_.VisitFunctionLiteral(lit);
3321 } 3387 }
3322 return lit; 3388 return lit;
3323 } 3389 }
3324 3390
3325 NativeFunctionLiteral* NewNativeFunctionLiteral( 3391 NativeFunctionLiteral* NewNativeFunctionLiteral(
3326 Handle<String> name, v8::Extension* extension, int pos) { 3392 const AstString* name, v8::Extension* extension,
3393 int pos) {
3327 NativeFunctionLiteral* lit = 3394 NativeFunctionLiteral* lit =
3328 new(zone_) NativeFunctionLiteral(zone_, name, extension, pos); 3395 new(zone_) NativeFunctionLiteral(zone_, name, extension, pos);
3329 VISIT_AND_RETURN(NativeFunctionLiteral, lit) 3396 VISIT_AND_RETURN(NativeFunctionLiteral, lit)
3330 } 3397 }
3331 3398
3332 ThisFunction* NewThisFunction(int pos) { 3399 ThisFunction* NewThisFunction(int pos) {
3333 ThisFunction* fun = new(zone_) ThisFunction(zone_, pos); 3400 ThisFunction* fun = new(zone_) ThisFunction(zone_, pos);
3334 VISIT_AND_RETURN(ThisFunction, fun) 3401 VISIT_AND_RETURN(ThisFunction, fun)
3335 } 3402 }
3336 3403
3337 #undef VISIT_AND_RETURN 3404 #undef VISIT_AND_RETURN
3338 3405
3339 private: 3406 private:
3340 Zone* zone_; 3407 Zone* zone_;
3341 Visitor visitor_; 3408 Visitor visitor_;
3409 AstValueFactory* ast_value_factory_;
3342 }; 3410 };
3343 3411
3344 3412
3345 } } // namespace v8::internal 3413 } } // namespace v8::internal
3346 3414
3347 #endif // V8_AST_H_ 3415 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/ast.cc » ('j') | src/ast-value-factory.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698