| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 204 |
| 205 void* operator new(size_t size, Zone* zone) { | 205 void* operator new(size_t size, Zone* zone) { |
| 206 return zone->New(static_cast<int>(size)); | 206 return zone->New(static_cast<int>(size)); |
| 207 } | 207 } |
| 208 | 208 |
| 209 AstNode() { } | 209 AstNode() { } |
| 210 | 210 |
| 211 virtual ~AstNode() { } | 211 virtual ~AstNode() { } |
| 212 | 212 |
| 213 virtual void Accept(AstVisitor* v) = 0; | 213 virtual void Accept(AstVisitor* v) = 0; |
| 214 virtual Type node_type() const { return kInvalid; } | 214 virtual Type node_type() const = 0; |
| 215 | 215 |
| 216 // Type testing & conversion functions overridden by concrete subclasses. | 216 // Type testing & conversion functions overridden by concrete subclasses. |
| 217 #define DECLARE_NODE_FUNCTIONS(type) \ | 217 #define DECLARE_NODE_FUNCTIONS(type) \ |
| 218 bool Is##type() { return node_type() == AstNode::k##type; } \ | 218 bool Is##type() { return node_type() == AstNode::k##type; } \ |
| 219 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } | 219 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } |
| 220 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 220 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 221 #undef DECLARE_NODE_FUNCTIONS | 221 #undef DECLARE_NODE_FUNCTIONS |
| 222 | 222 |
| 223 virtual Declaration* AsDeclaration() { return NULL; } | |
| 224 virtual Statement* AsStatement() { return NULL; } | |
| 225 virtual Expression* AsExpression() { return NULL; } | |
| 226 virtual TargetCollector* AsTargetCollector() { return NULL; } | 223 virtual TargetCollector* AsTargetCollector() { return NULL; } |
| 227 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 224 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
| 228 virtual IterationStatement* AsIterationStatement() { return NULL; } | 225 virtual IterationStatement* AsIterationStatement() { return NULL; } |
| 229 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } | 226 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
| 230 | 227 |
| 231 protected: | 228 protected: |
| 232 static int GetNextId(Isolate* isolate) { | 229 static int GetNextId(Isolate* isolate) { |
| 233 return ReserveIdRange(isolate, 1); | 230 return ReserveIdRange(isolate, 1); |
| 234 } | 231 } |
| 235 | 232 |
| 236 static int ReserveIdRange(Isolate* isolate, int n) { | 233 static int ReserveIdRange(Isolate* isolate, int n) { |
| 237 int tmp = isolate->ast_node_id(); | 234 int tmp = isolate->ast_node_id(); |
| 238 isolate->set_ast_node_id(tmp + n); | 235 isolate->set_ast_node_id(tmp + n); |
| 239 return tmp; | 236 return tmp; |
| 240 } | 237 } |
| 241 | 238 |
| 242 private: | 239 private: |
| 243 // Hidden to prevent accidental usage. It would have to load the | 240 // Hidden to prevent accidental usage. It would have to load the |
| 244 // current zone from the TLS. | 241 // current zone from the TLS. |
| 245 void* operator new(size_t size); | 242 void* operator new(size_t size); |
| 246 | 243 |
| 247 friend class CaseClause; // Generates AST IDs. | 244 friend class CaseClause; // Generates AST IDs. |
| 248 }; | 245 }; |
| 249 | 246 |
| 250 | 247 |
| 251 class Statement: public AstNode { | 248 class Statement: public AstNode { |
| 252 public: | 249 public: |
| 253 Statement() : statement_pos_(RelocInfo::kNoPosition) {} | 250 Statement() : statement_pos_(RelocInfo::kNoPosition) {} |
| 254 | 251 |
| 255 virtual Statement* AsStatement() { return this; } | |
| 256 | |
| 257 bool IsEmpty() { return AsEmptyStatement() != NULL; } | 252 bool IsEmpty() { return AsEmptyStatement() != NULL; } |
| 258 | 253 |
| 259 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } | 254 void set_statement_pos(int statement_pos) { statement_pos_ = statement_pos; } |
| 260 int statement_pos() const { return statement_pos_; } | 255 int statement_pos() const { return statement_pos_; } |
| 261 | 256 |
| 262 private: | 257 private: |
| 263 int statement_pos_; | 258 int statement_pos_; |
| 264 }; | 259 }; |
| 265 | 260 |
| 266 | 261 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 kValue, | 302 kValue, |
| 308 // Evaluated for control flow (and side effects). | 303 // Evaluated for control flow (and side effects). |
| 309 kTest | 304 kTest |
| 310 }; | 305 }; |
| 311 | 306 |
| 312 virtual int position() const { | 307 virtual int position() const { |
| 313 UNREACHABLE(); | 308 UNREACHABLE(); |
| 314 return 0; | 309 return 0; |
| 315 } | 310 } |
| 316 | 311 |
| 317 virtual Expression* AsExpression() { return this; } | |
| 318 | |
| 319 virtual bool IsValidLeftHandSide() { return false; } | 312 virtual bool IsValidLeftHandSide() { return false; } |
| 320 | 313 |
| 321 // Helpers for ToBoolean conversion. | 314 // Helpers for ToBoolean conversion. |
| 322 virtual bool ToBooleanIsTrue() { return false; } | 315 virtual bool ToBooleanIsTrue() { return false; } |
| 323 virtual bool ToBooleanIsFalse() { return false; } | 316 virtual bool ToBooleanIsFalse() { return false; } |
| 324 | 317 |
| 325 // Symbols that cannot be parsed as array indices are considered property | 318 // Symbols that cannot be parsed as array indices are considered property |
| 326 // names. We do not treat symbols that can be array indexes as property | 319 // names. We do not treat symbols that can be array indexes as property |
| 327 // names because [] for string objects is handled only by keyed ICs. | 320 // names because [] for string objects is handled only by keyed ICs. |
| 328 virtual bool IsPropertyName() { return false; } | 321 virtual bool IsPropertyName() { return false; } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 358 | 351 |
| 359 unsigned id() const { return id_; } | 352 unsigned id() const { return id_; } |
| 360 unsigned test_id() const { return test_id_; } | 353 unsigned test_id() const { return test_id_; } |
| 361 | 354 |
| 362 protected: | 355 protected: |
| 363 explicit Expression(Isolate* isolate) | 356 explicit Expression(Isolate* isolate) |
| 364 : id_(GetNextId(isolate)), | 357 : id_(GetNextId(isolate)), |
| 365 test_id_(GetNextId(isolate)) {} | 358 test_id_(GetNextId(isolate)) {} |
| 366 | 359 |
| 367 private: | 360 private: |
| 368 int id_; | 361 const int id_; |
| 369 int test_id_; | 362 const int test_id_; |
| 370 }; | 363 }; |
| 371 | 364 |
| 372 | 365 |
| 373 class BreakableStatement: public Statement { | 366 class BreakableStatement: public Statement { |
| 374 public: | 367 public: |
| 375 enum Type { | 368 enum Type { |
| 376 TARGET_FOR_ANONYMOUS, | 369 TARGET_FOR_ANONYMOUS, |
| 377 TARGET_FOR_NAMED_ONLY | 370 TARGET_FOR_NAMED_ONLY |
| 378 }; | 371 }; |
| 379 | 372 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 401 entry_id_(GetNextId(isolate)), | 394 entry_id_(GetNextId(isolate)), |
| 402 exit_id_(GetNextId(isolate)) { | 395 exit_id_(GetNextId(isolate)) { |
| 403 ASSERT(labels == NULL || labels->length() > 0); | 396 ASSERT(labels == NULL || labels->length() > 0); |
| 404 } | 397 } |
| 405 | 398 |
| 406 | 399 |
| 407 private: | 400 private: |
| 408 ZoneStringList* labels_; | 401 ZoneStringList* labels_; |
| 409 Type type_; | 402 Type type_; |
| 410 Label break_target_; | 403 Label break_target_; |
| 411 int entry_id_; | 404 const int entry_id_; |
| 412 int exit_id_; | 405 const int exit_id_; |
| 413 }; | 406 }; |
| 414 | 407 |
| 415 | 408 |
| 416 class Block: public BreakableStatement { | 409 class Block: public BreakableStatement { |
| 417 public: | 410 public: |
| 418 DECLARE_NODE_TYPE(Block) | 411 DECLARE_NODE_TYPE(Block) |
| 419 | 412 |
| 420 void AddStatement(Statement* statement, Zone* zone) { | 413 void AddStatement(Statement* statement, Zone* zone) { |
| 421 statements_.Add(statement, zone); | 414 statements_.Add(statement, zone); |
| 422 } | 415 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 449 | 442 |
| 450 | 443 |
| 451 class Declaration: public AstNode { | 444 class Declaration: public AstNode { |
| 452 public: | 445 public: |
| 453 VariableProxy* proxy() const { return proxy_; } | 446 VariableProxy* proxy() const { return proxy_; } |
| 454 VariableMode mode() const { return mode_; } | 447 VariableMode mode() const { return mode_; } |
| 455 Scope* scope() const { return scope_; } | 448 Scope* scope() const { return scope_; } |
| 456 virtual InitializationFlag initialization() const = 0; | 449 virtual InitializationFlag initialization() const = 0; |
| 457 virtual bool IsInlineable() const; | 450 virtual bool IsInlineable() const; |
| 458 | 451 |
| 459 virtual Declaration* AsDeclaration() { return this; } | |
| 460 | |
| 461 protected: | 452 protected: |
| 462 Declaration(VariableProxy* proxy, | 453 Declaration(VariableProxy* proxy, |
| 463 VariableMode mode, | 454 VariableMode mode, |
| 464 Scope* scope) | 455 Scope* scope) |
| 465 : proxy_(proxy), | 456 : proxy_(proxy), |
| 466 mode_(mode), | 457 mode_(mode), |
| 467 scope_(scope) { | 458 scope_(scope) { |
| 468 ASSERT(mode == VAR || | 459 ASSERT(mode == VAR || |
| 469 mode == CONST || | 460 mode == CONST || |
| 470 mode == CONST_HARMONY || | 461 mode == CONST_HARMONY || |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 osr_entry_id_(GetNextId(isolate)) { | 691 osr_entry_id_(GetNextId(isolate)) { |
| 701 } | 692 } |
| 702 | 693 |
| 703 void Initialize(Statement* body) { | 694 void Initialize(Statement* body) { |
| 704 body_ = body; | 695 body_ = body; |
| 705 } | 696 } |
| 706 | 697 |
| 707 private: | 698 private: |
| 708 Statement* body_; | 699 Statement* body_; |
| 709 Label continue_target_; | 700 Label continue_target_; |
| 710 int osr_entry_id_; | 701 const int osr_entry_id_; |
| 711 }; | 702 }; |
| 712 | 703 |
| 713 | 704 |
| 714 class DoWhileStatement: public IterationStatement { | 705 class DoWhileStatement: public IterationStatement { |
| 715 public: | 706 public: |
| 716 DECLARE_NODE_TYPE(DoWhileStatement) | 707 DECLARE_NODE_TYPE(DoWhileStatement) |
| 717 | 708 |
| 718 void Initialize(Expression* cond, Statement* body) { | 709 void Initialize(Expression* cond, Statement* body) { |
| 719 IterationStatement::Initialize(body); | 710 IterationStatement::Initialize(body); |
| 720 cond_ = cond; | 711 cond_ = cond; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 739 : IterationStatement(isolate, labels), | 730 : IterationStatement(isolate, labels), |
| 740 cond_(NULL), | 731 cond_(NULL), |
| 741 condition_position_(-1), | 732 condition_position_(-1), |
| 742 continue_id_(GetNextId(isolate)), | 733 continue_id_(GetNextId(isolate)), |
| 743 back_edge_id_(GetNextId(isolate)) { | 734 back_edge_id_(GetNextId(isolate)) { |
| 744 } | 735 } |
| 745 | 736 |
| 746 private: | 737 private: |
| 747 Expression* cond_; | 738 Expression* cond_; |
| 748 int condition_position_; | 739 int condition_position_; |
| 749 int continue_id_; | 740 const int continue_id_; |
| 750 int back_edge_id_; | 741 const int back_edge_id_; |
| 751 }; | 742 }; |
| 752 | 743 |
| 753 | 744 |
| 754 class WhileStatement: public IterationStatement { | 745 class WhileStatement: public IterationStatement { |
| 755 public: | 746 public: |
| 756 DECLARE_NODE_TYPE(WhileStatement) | 747 DECLARE_NODE_TYPE(WhileStatement) |
| 757 | 748 |
| 758 void Initialize(Expression* cond, Statement* body) { | 749 void Initialize(Expression* cond, Statement* body) { |
| 759 IterationStatement::Initialize(body); | 750 IterationStatement::Initialize(body); |
| 760 cond_ = cond; | 751 cond_ = cond; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 780 : IterationStatement(isolate, labels), | 771 : IterationStatement(isolate, labels), |
| 781 cond_(NULL), | 772 cond_(NULL), |
| 782 may_have_function_literal_(true), | 773 may_have_function_literal_(true), |
| 783 body_id_(GetNextId(isolate)) { | 774 body_id_(GetNextId(isolate)) { |
| 784 } | 775 } |
| 785 | 776 |
| 786 private: | 777 private: |
| 787 Expression* cond_; | 778 Expression* cond_; |
| 788 // True if there is a function literal subexpression in the condition. | 779 // True if there is a function literal subexpression in the condition. |
| 789 bool may_have_function_literal_; | 780 bool may_have_function_literal_; |
| 790 int body_id_; | 781 const int body_id_; |
| 791 }; | 782 }; |
| 792 | 783 |
| 793 | 784 |
| 794 class ForStatement: public IterationStatement { | 785 class ForStatement: public IterationStatement { |
| 795 public: | 786 public: |
| 796 DECLARE_NODE_TYPE(ForStatement) | 787 DECLARE_NODE_TYPE(ForStatement) |
| 797 | 788 |
| 798 void Initialize(Statement* init, | 789 void Initialize(Statement* init, |
| 799 Expression* cond, | 790 Expression* cond, |
| 800 Statement* next, | 791 Statement* next, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 body_id_(GetNextId(isolate)) { | 830 body_id_(GetNextId(isolate)) { |
| 840 } | 831 } |
| 841 | 832 |
| 842 private: | 833 private: |
| 843 Statement* init_; | 834 Statement* init_; |
| 844 Expression* cond_; | 835 Expression* cond_; |
| 845 Statement* next_; | 836 Statement* next_; |
| 846 // True if there is a function literal subexpression in the condition. | 837 // True if there is a function literal subexpression in the condition. |
| 847 bool may_have_function_literal_; | 838 bool may_have_function_literal_; |
| 848 Variable* loop_variable_; | 839 Variable* loop_variable_; |
| 849 int continue_id_; | 840 const int continue_id_; |
| 850 int body_id_; | 841 const int body_id_; |
| 851 }; | 842 }; |
| 852 | 843 |
| 853 | 844 |
| 854 class ForInStatement: public IterationStatement { | 845 class ForInStatement: public IterationStatement { |
| 855 public: | 846 public: |
| 856 DECLARE_NODE_TYPE(ForInStatement) | 847 DECLARE_NODE_TYPE(ForInStatement) |
| 857 | 848 |
| 858 void Initialize(Expression* each, Expression* enumerable, Statement* body) { | 849 void Initialize(Expression* each, Expression* enumerable, Statement* body) { |
| 859 IterationStatement::Initialize(body); | 850 IterationStatement::Initialize(body); |
| 860 each_ = each; | 851 each_ = each; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 876 : IterationStatement(isolate, labels), | 867 : IterationStatement(isolate, labels), |
| 877 each_(NULL), | 868 each_(NULL), |
| 878 enumerable_(NULL), | 869 enumerable_(NULL), |
| 879 body_id_(GetNextId(isolate)), | 870 body_id_(GetNextId(isolate)), |
| 880 prepare_id_(GetNextId(isolate)) { | 871 prepare_id_(GetNextId(isolate)) { |
| 881 } | 872 } |
| 882 | 873 |
| 883 private: | 874 private: |
| 884 Expression* each_; | 875 Expression* each_; |
| 885 Expression* enumerable_; | 876 Expression* enumerable_; |
| 886 int body_id_; | 877 const int body_id_; |
| 887 int prepare_id_; | 878 const int prepare_id_; |
| 888 }; | 879 }; |
| 889 | 880 |
| 890 | 881 |
| 891 class ExpressionStatement: public Statement { | 882 class ExpressionStatement: public Statement { |
| 892 public: | 883 public: |
| 893 DECLARE_NODE_TYPE(ExpressionStatement) | 884 DECLARE_NODE_TYPE(ExpressionStatement) |
| 894 | 885 |
| 895 void set_expression(Expression* e) { expression_ = e; } | 886 void set_expression(Expression* e) { expression_ = e; } |
| 896 Expression* expression() const { return expression_; } | 887 Expression* expression() const { return expression_; } |
| 897 | 888 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 ZoneList<Statement*>* statements_; | 1002 ZoneList<Statement*>* statements_; |
| 1012 int position_; | 1003 int position_; |
| 1013 enum CompareTypeFeedback { | 1004 enum CompareTypeFeedback { |
| 1014 NONE, | 1005 NONE, |
| 1015 SMI_ONLY, | 1006 SMI_ONLY, |
| 1016 SYMBOL_ONLY, | 1007 SYMBOL_ONLY, |
| 1017 STRING_ONLY, | 1008 STRING_ONLY, |
| 1018 OBJECT_ONLY | 1009 OBJECT_ONLY |
| 1019 }; | 1010 }; |
| 1020 CompareTypeFeedback compare_type_; | 1011 CompareTypeFeedback compare_type_; |
| 1021 int compare_id_; | 1012 const int compare_id_; |
| 1022 int entry_id_; | 1013 const int entry_id_; |
| 1023 }; | 1014 }; |
| 1024 | 1015 |
| 1025 | 1016 |
| 1026 class SwitchStatement: public BreakableStatement { | 1017 class SwitchStatement: public BreakableStatement { |
| 1027 public: | 1018 public: |
| 1028 DECLARE_NODE_TYPE(SwitchStatement) | 1019 DECLARE_NODE_TYPE(SwitchStatement) |
| 1029 | 1020 |
| 1030 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { | 1021 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { |
| 1031 tag_ = tag; | 1022 tag_ = tag; |
| 1032 cases_ = cases; | 1023 cases_ = cases; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 else_statement_(else_statement), | 1072 else_statement_(else_statement), |
| 1082 if_id_(GetNextId(isolate)), | 1073 if_id_(GetNextId(isolate)), |
| 1083 then_id_(GetNextId(isolate)), | 1074 then_id_(GetNextId(isolate)), |
| 1084 else_id_(GetNextId(isolate)) { | 1075 else_id_(GetNextId(isolate)) { |
| 1085 } | 1076 } |
| 1086 | 1077 |
| 1087 private: | 1078 private: |
| 1088 Expression* condition_; | 1079 Expression* condition_; |
| 1089 Statement* then_statement_; | 1080 Statement* then_statement_; |
| 1090 Statement* else_statement_; | 1081 Statement* else_statement_; |
| 1091 int if_id_; | 1082 const int if_id_; |
| 1092 int then_id_; | 1083 const int then_id_; |
| 1093 int else_id_; | 1084 const int else_id_; |
| 1094 }; | 1085 }; |
| 1095 | 1086 |
| 1096 | 1087 |
| 1097 // NOTE: TargetCollectors are represented as nodes to fit in the target | 1088 // NOTE: TargetCollectors are represented as nodes to fit in the target |
| 1098 // stack in the compiler; this should probably be reworked. | 1089 // stack in the compiler; this should probably be reworked. |
| 1099 class TargetCollector: public AstNode { | 1090 class TargetCollector: public AstNode { |
| 1100 public: | 1091 public: |
| 1101 explicit TargetCollector(Zone* zone) : targets_(0, zone) { } | 1092 explicit TargetCollector(Zone* zone) : targets_(0, zone) { } |
| 1102 | 1093 |
| 1103 // Adds a jump target to the collector. The collector stores a pointer not | 1094 // Adds a jump target to the collector. The collector stores a pointer not |
| 1104 // a copy of the target to make binding work, so make sure not to pass in | 1095 // a copy of the target to make binding work, so make sure not to pass in |
| 1105 // references to something on the stack. | 1096 // references to something on the stack. |
| 1106 void AddTarget(Label* target, Zone* zone); | 1097 void AddTarget(Label* target, Zone* zone); |
| 1107 | 1098 |
| 1108 // Virtual behaviour. TargetCollectors are never part of the AST. | 1099 // Virtual behaviour. TargetCollectors are never part of the AST. |
| 1109 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } | 1100 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } |
| 1101 virtual Type node_type() const { return kInvalid; } |
| 1110 virtual TargetCollector* AsTargetCollector() { return this; } | 1102 virtual TargetCollector* AsTargetCollector() { return this; } |
| 1111 | 1103 |
| 1112 ZoneList<Label*>* targets() { return &targets_; } | 1104 ZoneList<Label*>* targets() { return &targets_; } |
| 1113 | 1105 |
| 1114 private: | 1106 private: |
| 1115 ZoneList<Label*> targets_; | 1107 ZoneList<Label*> targets_; |
| 1116 }; | 1108 }; |
| 1117 | 1109 |
| 1118 | 1110 |
| 1119 class TryStatement: public Statement { | 1111 class TryStatement: public Statement { |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1446 bool is_simple, | 1438 bool is_simple, |
| 1447 int depth) | 1439 int depth) |
| 1448 : MaterializedLiteral(isolate, literal_index, is_simple, depth), | 1440 : MaterializedLiteral(isolate, literal_index, is_simple, depth), |
| 1449 constant_elements_(constant_elements), | 1441 constant_elements_(constant_elements), |
| 1450 values_(values), | 1442 values_(values), |
| 1451 first_element_id_(ReserveIdRange(isolate, values->length())) {} | 1443 first_element_id_(ReserveIdRange(isolate, values->length())) {} |
| 1452 | 1444 |
| 1453 private: | 1445 private: |
| 1454 Handle<FixedArray> constant_elements_; | 1446 Handle<FixedArray> constant_elements_; |
| 1455 ZoneList<Expression*>* values_; | 1447 ZoneList<Expression*>* values_; |
| 1456 int first_element_id_; | 1448 const int first_element_id_; |
| 1457 }; | 1449 }; |
| 1458 | 1450 |
| 1459 | 1451 |
| 1460 class VariableProxy: public Expression { | 1452 class VariableProxy: public Expression { |
| 1461 public: | 1453 public: |
| 1462 DECLARE_NODE_TYPE(VariableProxy) | 1454 DECLARE_NODE_TYPE(VariableProxy) |
| 1463 | 1455 |
| 1464 virtual bool IsValidLeftHandSide() { | 1456 virtual bool IsValidLeftHandSide() { |
| 1465 return var_ == NULL ? true : var_->IsValidLeftHandSide(); | 1457 return var_ == NULL ? true : var_->IsValidLeftHandSide(); |
| 1466 } | 1458 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 ZoneList<Expression*>* arguments_; | 1610 ZoneList<Expression*>* arguments_; |
| 1619 int pos_; | 1611 int pos_; |
| 1620 | 1612 |
| 1621 bool is_monomorphic_; | 1613 bool is_monomorphic_; |
| 1622 CheckType check_type_; | 1614 CheckType check_type_; |
| 1623 SmallMapList receiver_types_; | 1615 SmallMapList receiver_types_; |
| 1624 Handle<JSFunction> target_; | 1616 Handle<JSFunction> target_; |
| 1625 Handle<JSObject> holder_; | 1617 Handle<JSObject> holder_; |
| 1626 Handle<JSGlobalPropertyCell> cell_; | 1618 Handle<JSGlobalPropertyCell> cell_; |
| 1627 | 1619 |
| 1628 int return_id_; | 1620 const int return_id_; |
| 1629 }; | 1621 }; |
| 1630 | 1622 |
| 1631 | 1623 |
| 1632 class CallNew: public Expression { | 1624 class CallNew: public Expression { |
| 1633 public: | 1625 public: |
| 1634 DECLARE_NODE_TYPE(CallNew) | 1626 DECLARE_NODE_TYPE(CallNew) |
| 1635 | 1627 |
| 1636 Expression* expression() const { return expression_; } | 1628 Expression* expression() const { return expression_; } |
| 1637 ZoneList<Expression*>* arguments() const { return arguments_; } | 1629 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1638 virtual int position() const { return pos_; } | 1630 virtual int position() const { return pos_; } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1659 return_id_(GetNextId(isolate)) { } | 1651 return_id_(GetNextId(isolate)) { } |
| 1660 | 1652 |
| 1661 private: | 1653 private: |
| 1662 Expression* expression_; | 1654 Expression* expression_; |
| 1663 ZoneList<Expression*>* arguments_; | 1655 ZoneList<Expression*>* arguments_; |
| 1664 int pos_; | 1656 int pos_; |
| 1665 | 1657 |
| 1666 bool is_monomorphic_; | 1658 bool is_monomorphic_; |
| 1667 Handle<JSFunction> target_; | 1659 Handle<JSFunction> target_; |
| 1668 | 1660 |
| 1669 int return_id_; | 1661 const int return_id_; |
| 1670 }; | 1662 }; |
| 1671 | 1663 |
| 1672 | 1664 |
| 1673 // The CallRuntime class does not represent any official JavaScript | 1665 // The CallRuntime class does not represent any official JavaScript |
| 1674 // language construct. Instead it is used to call a C or JS function | 1666 // language construct. Instead it is used to call a C or JS function |
| 1675 // with a set of arguments. This is used from the builtins that are | 1667 // with a set of arguments. This is used from the builtins that are |
| 1676 // implemented in JavaScript (see "v8natives.js"). | 1668 // implemented in JavaScript (see "v8natives.js"). |
| 1677 class CallRuntime: public Expression { | 1669 class CallRuntime: public Expression { |
| 1678 public: | 1670 public: |
| 1679 DECLARE_NODE_TYPE(CallRuntime) | 1671 DECLARE_NODE_TYPE(CallRuntime) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1719 template<class> friend class AstNodeFactory; | 1711 template<class> friend class AstNodeFactory; |
| 1720 | 1712 |
| 1721 UnaryOperation(Isolate* isolate, | 1713 UnaryOperation(Isolate* isolate, |
| 1722 Token::Value op, | 1714 Token::Value op, |
| 1723 Expression* expression, | 1715 Expression* expression, |
| 1724 int pos) | 1716 int pos) |
| 1725 : Expression(isolate), | 1717 : Expression(isolate), |
| 1726 op_(op), | 1718 op_(op), |
| 1727 expression_(expression), | 1719 expression_(expression), |
| 1728 pos_(pos), | 1720 pos_(pos), |
| 1729 materialize_true_id_(AstNode::kNoNumber), | 1721 materialize_true_id_(GetNextId(isolate)), |
| 1730 materialize_false_id_(AstNode::kNoNumber) { | 1722 materialize_false_id_(GetNextId(isolate)) { |
| 1731 ASSERT(Token::IsUnaryOp(op)); | 1723 ASSERT(Token::IsUnaryOp(op)); |
| 1732 if (op == Token::NOT) { | |
| 1733 materialize_true_id_ = GetNextId(isolate); | |
| 1734 materialize_false_id_ = GetNextId(isolate); | |
| 1735 } | |
| 1736 } | 1724 } |
| 1737 | 1725 |
| 1738 private: | 1726 private: |
| 1739 Token::Value op_; | 1727 Token::Value op_; |
| 1740 Expression* expression_; | 1728 Expression* expression_; |
| 1741 int pos_; | 1729 int pos_; |
| 1742 | 1730 |
| 1743 // For unary not (Token::NOT), the AST ids where true and false will | 1731 // For unary not (Token::NOT), the AST ids where true and false will |
| 1744 // actually be materialized, respectively. | 1732 // actually be materialized, respectively. |
| 1745 int materialize_true_id_; | 1733 const int materialize_true_id_; |
| 1746 int materialize_false_id_; | 1734 const int materialize_false_id_; |
| 1747 }; | 1735 }; |
| 1748 | 1736 |
| 1749 | 1737 |
| 1750 class BinaryOperation: public Expression { | 1738 class BinaryOperation: public Expression { |
| 1751 public: | 1739 public: |
| 1752 DECLARE_NODE_TYPE(BinaryOperation) | 1740 DECLARE_NODE_TYPE(BinaryOperation) |
| 1753 | 1741 |
| 1754 virtual bool ResultOverwriteAllowed(); | 1742 virtual bool ResultOverwriteAllowed(); |
| 1755 | 1743 |
| 1756 Token::Value op() const { return op_; } | 1744 Token::Value op() const { return op_; } |
| 1757 Expression* left() const { return left_; } | 1745 Expression* left() const { return left_; } |
| 1758 Expression* right() const { return right_; } | 1746 Expression* right() const { return right_; } |
| 1759 virtual int position() const { return pos_; } | 1747 virtual int position() const { return pos_; } |
| 1760 | 1748 |
| 1761 // Bailout support. | 1749 // Bailout support. |
| 1762 int RightId() const { return right_id_; } | 1750 int RightId() const { return right_id_; } |
| 1763 | 1751 |
| 1764 protected: | 1752 protected: |
| 1765 template<class> friend class AstNodeFactory; | 1753 template<class> friend class AstNodeFactory; |
| 1766 | 1754 |
| 1767 BinaryOperation(Isolate* isolate, | 1755 BinaryOperation(Isolate* isolate, |
| 1768 Token::Value op, | 1756 Token::Value op, |
| 1769 Expression* left, | 1757 Expression* left, |
| 1770 Expression* right, | 1758 Expression* right, |
| 1771 int pos) | 1759 int pos) |
| 1772 : Expression(isolate), op_(op), left_(left), right_(right), pos_(pos) { | 1760 : Expression(isolate), |
| 1761 op_(op), |
| 1762 left_(left), |
| 1763 right_(right), |
| 1764 pos_(pos), |
| 1765 right_id_(GetNextId(isolate)) { |
| 1773 ASSERT(Token::IsBinaryOp(op)); | 1766 ASSERT(Token::IsBinaryOp(op)); |
| 1774 right_id_ = (op == Token::AND || op == Token::OR) | |
| 1775 ? GetNextId(isolate) | |
| 1776 : AstNode::kNoNumber; | |
| 1777 } | 1767 } |
| 1778 | 1768 |
| 1779 private: | 1769 private: |
| 1780 Token::Value op_; | 1770 Token::Value op_; |
| 1781 Expression* left_; | 1771 Expression* left_; |
| 1782 Expression* right_; | 1772 Expression* right_; |
| 1783 int pos_; | 1773 int pos_; |
| 1784 // The short-circuit logical operations have an AST ID for their | 1774 // The short-circuit logical operations need an AST ID for their |
| 1785 // right-hand subexpression. | 1775 // right-hand subexpression. |
| 1786 int right_id_; | 1776 const int right_id_; |
| 1787 }; | 1777 }; |
| 1788 | 1778 |
| 1789 | 1779 |
| 1790 class CountOperation: public Expression { | 1780 class CountOperation: public Expression { |
| 1791 public: | 1781 public: |
| 1792 DECLARE_NODE_TYPE(CountOperation) | 1782 DECLARE_NODE_TYPE(CountOperation) |
| 1793 | 1783 |
| 1794 bool is_prefix() const { return is_prefix_; } | 1784 bool is_prefix() const { return is_prefix_; } |
| 1795 bool is_postfix() const { return !is_prefix_; } | 1785 bool is_postfix() const { return !is_prefix_; } |
| 1796 | 1786 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1827 pos_(pos), | 1817 pos_(pos), |
| 1828 assignment_id_(GetNextId(isolate)), | 1818 assignment_id_(GetNextId(isolate)), |
| 1829 count_id_(GetNextId(isolate)) {} | 1819 count_id_(GetNextId(isolate)) {} |
| 1830 | 1820 |
| 1831 private: | 1821 private: |
| 1832 Token::Value op_; | 1822 Token::Value op_; |
| 1833 bool is_prefix_; | 1823 bool is_prefix_; |
| 1834 bool is_monomorphic_; | 1824 bool is_monomorphic_; |
| 1835 Expression* expression_; | 1825 Expression* expression_; |
| 1836 int pos_; | 1826 int pos_; |
| 1837 int assignment_id_; | 1827 const int assignment_id_; |
| 1838 int count_id_; | 1828 const int count_id_; |
| 1839 SmallMapList receiver_types_; | 1829 SmallMapList receiver_types_; |
| 1840 }; | 1830 }; |
| 1841 | 1831 |
| 1842 | 1832 |
| 1843 class CompareOperation: public Expression { | 1833 class CompareOperation: public Expression { |
| 1844 public: | 1834 public: |
| 1845 DECLARE_NODE_TYPE(CompareOperation) | 1835 DECLARE_NODE_TYPE(CompareOperation) |
| 1846 | 1836 |
| 1847 Token::Value op() const { return op_; } | 1837 Token::Value op() const { return op_; } |
| 1848 Expression* left() const { return left_; } | 1838 Expression* left() const { return left_; } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1918 else_expression_position_(else_expression_position), | 1908 else_expression_position_(else_expression_position), |
| 1919 then_id_(GetNextId(isolate)), | 1909 then_id_(GetNextId(isolate)), |
| 1920 else_id_(GetNextId(isolate)) { } | 1910 else_id_(GetNextId(isolate)) { } |
| 1921 | 1911 |
| 1922 private: | 1912 private: |
| 1923 Expression* condition_; | 1913 Expression* condition_; |
| 1924 Expression* then_expression_; | 1914 Expression* then_expression_; |
| 1925 Expression* else_expression_; | 1915 Expression* else_expression_; |
| 1926 int then_expression_position_; | 1916 int then_expression_position_; |
| 1927 int else_expression_position_; | 1917 int else_expression_position_; |
| 1928 int then_id_; | 1918 const int then_id_; |
| 1929 int else_id_; | 1919 const int else_id_; |
| 1930 }; | 1920 }; |
| 1931 | 1921 |
| 1932 | 1922 |
| 1933 class Assignment: public Expression { | 1923 class Assignment: public Expression { |
| 1934 public: | 1924 public: |
| 1935 DECLARE_NODE_TYPE(Assignment) | 1925 DECLARE_NODE_TYPE(Assignment) |
| 1936 | 1926 |
| 1937 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } | 1927 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } |
| 1938 | 1928 |
| 1939 Token::Value binary_op() const; | 1929 Token::Value binary_op() const; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 Expression* target, | 1963 Expression* target, |
| 1974 Expression* value, | 1964 Expression* value, |
| 1975 int pos); | 1965 int pos); |
| 1976 | 1966 |
| 1977 template<class Visitor> | 1967 template<class Visitor> |
| 1978 void Init(Isolate* isolate, AstNodeFactory<Visitor>* factory) { | 1968 void Init(Isolate* isolate, AstNodeFactory<Visitor>* factory) { |
| 1979 ASSERT(Token::IsAssignmentOp(op_)); | 1969 ASSERT(Token::IsAssignmentOp(op_)); |
| 1980 if (is_compound()) { | 1970 if (is_compound()) { |
| 1981 binary_operation_ = | 1971 binary_operation_ = |
| 1982 factory->NewBinaryOperation(binary_op(), target_, value_, pos_ + 1); | 1972 factory->NewBinaryOperation(binary_op(), target_, value_, pos_ + 1); |
| 1983 compound_load_id_ = GetNextId(isolate); | |
| 1984 } | 1973 } |
| 1985 } | 1974 } |
| 1986 | 1975 |
| 1987 private: | 1976 private: |
| 1988 Token::Value op_; | 1977 Token::Value op_; |
| 1989 Expression* target_; | 1978 Expression* target_; |
| 1990 Expression* value_; | 1979 Expression* value_; |
| 1991 int pos_; | 1980 int pos_; |
| 1992 BinaryOperation* binary_operation_; | 1981 BinaryOperation* binary_operation_; |
| 1993 int compound_load_id_; | 1982 const int compound_load_id_; |
| 1994 int assignment_id_; | 1983 const int assignment_id_; |
| 1995 | 1984 |
| 1996 bool block_start_; | 1985 bool block_start_; |
| 1997 bool block_end_; | 1986 bool block_end_; |
| 1998 | 1987 |
| 1999 bool is_monomorphic_; | 1988 bool is_monomorphic_; |
| 2000 SmallMapList receiver_types_; | 1989 SmallMapList receiver_types_; |
| 2001 }; | 1990 }; |
| 2002 | 1991 |
| 2003 | 1992 |
| 2004 class Throw: public Expression { | 1993 class Throw: public Expression { |
| (...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2983 private: | 2972 private: |
| 2984 Isolate* isolate_; | 2973 Isolate* isolate_; |
| 2985 Zone* zone_; | 2974 Zone* zone_; |
| 2986 Visitor visitor_; | 2975 Visitor visitor_; |
| 2987 }; | 2976 }; |
| 2988 | 2977 |
| 2989 | 2978 |
| 2990 } } // namespace v8::internal | 2979 } } // namespace v8::internal |
| 2991 | 2980 |
| 2992 #endif // V8_AST_H_ | 2981 #endif // V8_AST_H_ |
| OLD | NEW |