Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 32 | 32 |
| 33 #include "assembler.h" | 33 #include "assembler.h" |
| 34 #include "factory.h" | 34 #include "factory.h" |
| 35 #include "isolate.h" | 35 #include "isolate.h" |
| 36 #include "jsregexp.h" | 36 #include "jsregexp.h" |
| 37 #include "list-inl.h" | 37 #include "list-inl.h" |
| 38 #include "runtime.h" | 38 #include "runtime.h" |
| 39 #include "small-pointer-list.h" | 39 #include "small-pointer-list.h" |
| 40 #include "smart-array-pointer.h" | 40 #include "smart-array-pointer.h" |
| 41 #include "token.h" | 41 #include "token.h" |
| 42 #include "utils.h" | |
| 42 #include "variables.h" | 43 #include "variables.h" |
| 43 #include "zone-inl.h" | 44 #include "zone-inl.h" |
| 44 | 45 |
| 45 namespace v8 { | 46 namespace v8 { |
| 46 namespace internal { | 47 namespace internal { |
| 47 | 48 |
| 48 // The abstract syntax tree is an intermediate, light-weight | 49 // The abstract syntax tree is an intermediate, light-weight |
| 49 // representation of the parsed JavaScript code suitable for | 50 // representation of the parsed JavaScript code suitable for |
| 50 // compilation to native code. | 51 // compilation to native code. |
| 51 | 52 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 V(BinaryOperation) \ | 97 V(BinaryOperation) \ |
| 97 V(CompareOperation) \ | 98 V(CompareOperation) \ |
| 98 V(ThisFunction) | 99 V(ThisFunction) |
| 99 | 100 |
| 100 #define AST_NODE_LIST(V) \ | 101 #define AST_NODE_LIST(V) \ |
| 101 V(Declaration) \ | 102 V(Declaration) \ |
| 102 STATEMENT_NODE_LIST(V) \ | 103 STATEMENT_NODE_LIST(V) \ |
| 103 EXPRESSION_NODE_LIST(V) | 104 EXPRESSION_NODE_LIST(V) |
| 104 | 105 |
| 105 // Forward declarations | 106 // Forward declarations |
| 107 class AstConstructionVisitor; | |
| 108 class AstNodeFactory; | |
| 109 class AstProperties; | |
| 106 class AstVisitor; | 110 class AstVisitor; |
| 107 class BreakableStatement; | 111 class BreakableStatement; |
| 108 class Expression; | 112 class Expression; |
| 109 class IterationStatement; | 113 class IterationStatement; |
| 110 class MaterializedLiteral; | 114 class MaterializedLiteral; |
| 111 class Statement; | 115 class Statement; |
| 112 class TargetCollector; | 116 class TargetCollector; |
| 113 class TypeFeedbackOracle; | 117 class TypeFeedbackOracle; |
| 114 | 118 |
| 115 class RegExpAlternative; | 119 class RegExpAlternative; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 129 AST_NODE_LIST(DEF_FORWARD_DECLARATION) | 133 AST_NODE_LIST(DEF_FORWARD_DECLARATION) |
| 130 #undef DEF_FORWARD_DECLARATION | 134 #undef DEF_FORWARD_DECLARATION |
| 131 | 135 |
| 132 | 136 |
| 133 // Typedef only introduced to avoid unreadable code. | 137 // Typedef only introduced to avoid unreadable code. |
| 134 // Please do appreciate the required space in "> >". | 138 // Please do appreciate the required space in "> >". |
| 135 typedef ZoneList<Handle<String> > ZoneStringList; | 139 typedef ZoneList<Handle<String> > ZoneStringList; |
| 136 typedef ZoneList<Handle<Object> > ZoneObjectList; | 140 typedef ZoneList<Handle<Object> > ZoneObjectList; |
| 137 | 141 |
| 138 | 142 |
| 143 #define DECLARE_NODE_TYPE(type) \ | |
| 144 virtual void Accept(AstVisitor* v); \ | |
| 145 virtual AstNode::Type node_type() const { return AstNode::k##type; } \ | |
| 146 | |
| 147 | |
| 139 class AstNode: public ZoneObject { | 148 class AstNode: public ZoneObject { |
| 140 public: | 149 public: |
| 141 #define DECLARE_TYPE_ENUM(type) k##type, | 150 #define DECLARE_TYPE_ENUM(type) k##type, |
| 142 enum Type { | 151 enum Type { |
| 143 AST_NODE_LIST(DECLARE_TYPE_ENUM) | 152 AST_NODE_LIST(DECLARE_TYPE_ENUM) |
| 144 kInvalid = -1 | 153 kInvalid = -1 |
| 145 }; | 154 }; |
| 146 #undef DECLARE_TYPE_ENUM | 155 #undef DECLARE_TYPE_ENUM |
| 147 | 156 |
| 148 static const int kNoNumber = -1; | 157 static const int kNoNumber = -1; |
| 149 static const int kFunctionEntryId = 2; // Using 0 could disguise errors. | 158 static const int kFunctionEntryId = 2; // Using 0 could disguise errors. |
| 150 // This AST id identifies the point after the declarations have been | 159 // This AST id identifies the point after the declarations have been |
| 151 // visited. We need it to capture the environment effects of declarations | 160 // visited. We need it to capture the environment effects of declarations |
| 152 // that emit code (function declarations). | 161 // that emit code (function declarations). |
| 153 static const int kDeclarationsId = 3; | 162 static const int kDeclarationsId = 3; |
| 154 | 163 |
| 155 // Override ZoneObject's new to count allocated AST nodes. | |
| 156 void* operator new(size_t size, Zone* zone) { | 164 void* operator new(size_t size, Zone* zone) { |
| 157 Isolate* isolate = zone->isolate(); | |
| 158 isolate->set_ast_node_count(isolate->ast_node_count() + 1); | |
| 159 return zone->New(static_cast<int>(size)); | 165 return zone->New(static_cast<int>(size)); |
| 160 } | 166 } |
| 161 | 167 |
| 162 AstNode() {} | 168 AstNode() { } |
| 163 | 169 |
| 164 virtual ~AstNode() { } | 170 virtual ~AstNode() { } |
| 165 | 171 |
| 166 virtual void Accept(AstVisitor* v) = 0; | 172 virtual void Accept(AstVisitor* v) = 0; |
| 167 virtual Type node_type() const { return kInvalid; } | 173 virtual Type node_type() const { return kInvalid; } |
| 168 | 174 |
| 169 // Type testing & conversion functions overridden by concrete subclasses. | 175 // Type testing & conversion functions overridden by concrete subclasses. |
| 170 #define DECLARE_NODE_FUNCTIONS(type) \ | 176 #define DECLARE_NODE_FUNCTIONS(type) \ |
| 171 bool Is##type() { return node_type() == AstNode::k##type; } \ | 177 bool Is##type() { return node_type() == AstNode::k##type; } \ |
| 172 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } | 178 type* As##type() { return Is##type() ? reinterpret_cast<type*>(this) : NULL; } |
| 173 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 179 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 174 #undef DECLARE_NODE_FUNCTIONS | 180 #undef DECLARE_NODE_FUNCTIONS |
| 175 | 181 |
| 176 virtual Statement* AsStatement() { return NULL; } | 182 virtual Statement* AsStatement() { return NULL; } |
| 177 virtual Expression* AsExpression() { return NULL; } | 183 virtual Expression* AsExpression() { return NULL; } |
| 178 virtual TargetCollector* AsTargetCollector() { return NULL; } | 184 virtual TargetCollector* AsTargetCollector() { return NULL; } |
| 179 virtual BreakableStatement* AsBreakableStatement() { return NULL; } | 185 virtual BreakableStatement* AsBreakableStatement() { return NULL; } |
| 180 virtual IterationStatement* AsIterationStatement() { return NULL; } | 186 virtual IterationStatement* AsIterationStatement() { return NULL; } |
| 181 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } | 187 virtual MaterializedLiteral* AsMaterializedLiteral() { return NULL; } |
| 182 | 188 |
| 183 // True if the node is simple enough for us to inline calls containing it. | |
| 184 virtual bool IsInlineable() const = 0; | |
| 185 | |
| 186 static int Count() { return Isolate::Current()->ast_node_count(); } | |
| 187 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } | 189 static void ResetIds() { Isolate::Current()->set_ast_node_id(0); } |
| 188 | 190 |
| 189 protected: | 191 protected: |
| 190 static unsigned GetNextId(Isolate* isolate) { | 192 static unsigned GetNextId(Isolate* isolate) { |
| 191 return ReserveIdRange(isolate, 1); | 193 return ReserveIdRange(isolate, 1); |
| 192 } | 194 } |
| 193 | 195 |
| 194 static unsigned ReserveIdRange(Isolate* isolate, int n) { | 196 static unsigned ReserveIdRange(Isolate* isolate, int n) { |
| 195 unsigned tmp = isolate->ast_node_id(); | 197 unsigned tmp = isolate->ast_node_id(); |
| 196 isolate->set_ast_node_id(tmp + n); | 198 isolate->set_ast_node_id(tmp + n); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 ZoneStringList* labels_; | 371 ZoneStringList* labels_; |
| 370 Type type_; | 372 Type type_; |
| 371 Label break_target_; | 373 Label break_target_; |
| 372 int entry_id_; | 374 int entry_id_; |
| 373 int exit_id_; | 375 int exit_id_; |
| 374 }; | 376 }; |
| 375 | 377 |
| 376 | 378 |
| 377 class Block: public BreakableStatement { | 379 class Block: public BreakableStatement { |
| 378 public: | 380 public: |
| 379 Block(Isolate* isolate, | |
| 380 ZoneStringList* labels, | |
| 381 int capacity, | |
| 382 bool is_initializer_block) | |
| 383 : BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY), | |
| 384 statements_(capacity), | |
| 385 is_initializer_block_(is_initializer_block), | |
| 386 block_scope_(NULL) { | |
| 387 } | |
| 388 | |
| 389 | |
| 390 DECLARE_NODE_TYPE(Block) | 381 DECLARE_NODE_TYPE(Block) |
| 391 | 382 |
| 392 virtual bool IsInlineable() const; | |
| 393 | |
| 394 void AddStatement(Statement* statement) { statements_.Add(statement); } | 383 void AddStatement(Statement* statement) { statements_.Add(statement); } |
| 395 | 384 |
| 396 ZoneList<Statement*>* statements() { return &statements_; } | 385 ZoneList<Statement*>* statements() { return &statements_; } |
| 397 bool is_initializer_block() const { return is_initializer_block_; } | 386 bool is_initializer_block() const { return is_initializer_block_; } |
| 398 | 387 |
| 399 Scope* block_scope() const { return block_scope_; } | 388 Scope* block_scope() const { return block_scope_; } |
| 400 void set_block_scope(Scope* block_scope) { block_scope_ = block_scope; } | 389 void set_block_scope(Scope* block_scope) { block_scope_ = block_scope; } |
| 401 | 390 |
| 391 protected: | |
| 392 friend class AstNodeFactory; | |
| 393 | |
| 394 Block(Isolate* isolate, | |
| 395 ZoneStringList* labels, | |
| 396 int capacity, | |
| 397 bool is_initializer_block) | |
| 398 : BreakableStatement(isolate, labels, TARGET_FOR_NAMED_ONLY), | |
| 399 statements_(capacity), | |
| 400 is_initializer_block_(is_initializer_block), | |
| 401 block_scope_(NULL) { | |
| 402 } | |
| 403 | |
| 402 private: | 404 private: |
| 403 ZoneList<Statement*> statements_; | 405 ZoneList<Statement*> statements_; |
| 404 bool is_initializer_block_; | 406 bool is_initializer_block_; |
| 405 Scope* block_scope_; | 407 Scope* block_scope_; |
| 406 }; | 408 }; |
| 407 | 409 |
| 408 | 410 |
| 409 class Declaration: public AstNode { | 411 class Declaration: public AstNode { |
| 410 public: | 412 public: |
| 413 DECLARE_NODE_TYPE(Declaration) | |
| 414 | |
| 415 VariableProxy* proxy() const { return proxy_; } | |
| 416 VariableMode mode() const { return mode_; } | |
| 417 FunctionLiteral* fun() const { return fun_; } // may be NULL | |
| 418 bool IsInlineable() const; | |
| 419 Scope* scope() const { return scope_; } | |
| 420 | |
| 421 protected: | |
| 422 friend class AstNodeFactory; | |
| 423 | |
| 411 Declaration(VariableProxy* proxy, | 424 Declaration(VariableProxy* proxy, |
| 412 VariableMode mode, | 425 VariableMode mode, |
| 413 FunctionLiteral* fun, | 426 FunctionLiteral* fun, |
| 414 Scope* scope) | 427 Scope* scope) |
| 415 : proxy_(proxy), | 428 : proxy_(proxy), |
| 416 mode_(mode), | 429 mode_(mode), |
| 417 fun_(fun), | 430 fun_(fun), |
| 418 scope_(scope) { | 431 scope_(scope) { |
| 419 ASSERT(mode == VAR || | 432 ASSERT(mode == VAR || |
| 420 mode == CONST || | 433 mode == CONST || |
| 421 mode == CONST_HARMONY || | 434 mode == CONST_HARMONY || |
| 422 mode == LET); | 435 mode == LET); |
| 423 // At the moment there are no "const functions"'s in JavaScript... | 436 // At the moment there are no "const functions"'s in JavaScript... |
| 424 ASSERT(fun == NULL || mode == VAR || mode == LET); | 437 ASSERT(fun == NULL || mode == VAR || mode == LET); |
| 425 } | 438 } |
| 426 | 439 |
| 427 DECLARE_NODE_TYPE(Declaration) | |
| 428 | |
| 429 VariableProxy* proxy() const { return proxy_; } | |
| 430 VariableMode mode() const { return mode_; } | |
| 431 FunctionLiteral* fun() const { return fun_; } // may be NULL | |
| 432 virtual bool IsInlineable() const; | |
| 433 Scope* scope() const { return scope_; } | |
| 434 | |
| 435 private: | 440 private: |
| 436 VariableProxy* proxy_; | 441 VariableProxy* proxy_; |
| 437 VariableMode mode_; | 442 VariableMode mode_; |
| 438 FunctionLiteral* fun_; | 443 FunctionLiteral* fun_; |
| 439 | 444 |
| 440 // Nested scope from which the declaration originated. | 445 // Nested scope from which the declaration originated. |
| 441 Scope* scope_; | 446 Scope* scope_; |
| 442 }; | 447 }; |
| 443 | 448 |
| 444 | 449 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 470 | 475 |
| 471 private: | 476 private: |
| 472 Statement* body_; | 477 Statement* body_; |
| 473 Label continue_target_; | 478 Label continue_target_; |
| 474 int osr_entry_id_; | 479 int osr_entry_id_; |
| 475 }; | 480 }; |
| 476 | 481 |
| 477 | 482 |
| 478 class DoWhileStatement: public IterationStatement { | 483 class DoWhileStatement: public IterationStatement { |
| 479 public: | 484 public: |
| 480 DoWhileStatement(Isolate* isolate, ZoneStringList* labels) | |
| 481 : IterationStatement(isolate, labels), | |
| 482 cond_(NULL), | |
| 483 condition_position_(-1), | |
| 484 continue_id_(GetNextId(isolate)), | |
| 485 back_edge_id_(GetNextId(isolate)) { | |
| 486 } | |
| 487 | |
| 488 DECLARE_NODE_TYPE(DoWhileStatement) | 485 DECLARE_NODE_TYPE(DoWhileStatement) |
| 489 | 486 |
| 490 void Initialize(Expression* cond, Statement* body) { | 487 void Initialize(Expression* cond, Statement* body) { |
| 491 IterationStatement::Initialize(body); | 488 IterationStatement::Initialize(body); |
| 492 cond_ = cond; | 489 cond_ = cond; |
| 493 } | 490 } |
| 494 | 491 |
| 495 Expression* cond() const { return cond_; } | 492 Expression* cond() const { return cond_; } |
| 496 | 493 |
| 497 // Position where condition expression starts. We need it to make | 494 // Position where condition expression starts. We need it to make |
| 498 // the loop's condition a breakable location. | 495 // the loop's condition a breakable location. |
| 499 int condition_position() { return condition_position_; } | 496 int condition_position() { return condition_position_; } |
| 500 void set_condition_position(int pos) { condition_position_ = pos; } | 497 void set_condition_position(int pos) { condition_position_ = pos; } |
| 501 | 498 |
| 502 // Bailout support. | 499 // Bailout support. |
| 503 virtual int ContinueId() const { return continue_id_; } | 500 virtual int ContinueId() const { return continue_id_; } |
| 504 virtual int StackCheckId() const { return back_edge_id_; } | 501 virtual int StackCheckId() const { return back_edge_id_; } |
| 505 int BackEdgeId() const { return back_edge_id_; } | 502 int BackEdgeId() const { return back_edge_id_; } |
| 506 | 503 |
| 507 virtual bool IsInlineable() const; | 504 protected: |
| 505 friend class AstNodeFactory; | |
| 506 | |
| 507 DoWhileStatement(Isolate* isolate, ZoneStringList* labels) | |
| 508 : IterationStatement(isolate, labels), | |
| 509 cond_(NULL), | |
| 510 condition_position_(-1), | |
| 511 continue_id_(GetNextId(isolate)), | |
| 512 back_edge_id_(GetNextId(isolate)) { | |
| 513 } | |
| 508 | 514 |
| 509 private: | 515 private: |
| 510 Expression* cond_; | 516 Expression* cond_; |
| 511 int condition_position_; | 517 int condition_position_; |
| 512 int continue_id_; | 518 int continue_id_; |
| 513 int back_edge_id_; | 519 int back_edge_id_; |
| 514 }; | 520 }; |
| 515 | 521 |
| 516 | 522 |
| 517 class WhileStatement: public IterationStatement { | 523 class WhileStatement: public IterationStatement { |
| 518 public: | 524 public: |
| 519 WhileStatement(Isolate* isolate, ZoneStringList* labels) | |
| 520 : IterationStatement(isolate, labels), | |
| 521 cond_(NULL), | |
| 522 may_have_function_literal_(true), | |
| 523 body_id_(GetNextId(isolate)) { | |
| 524 } | |
| 525 | |
| 526 DECLARE_NODE_TYPE(WhileStatement) | 525 DECLARE_NODE_TYPE(WhileStatement) |
| 527 | 526 |
| 528 void Initialize(Expression* cond, Statement* body) { | 527 void Initialize(Expression* cond, Statement* body) { |
| 529 IterationStatement::Initialize(body); | 528 IterationStatement::Initialize(body); |
| 530 cond_ = cond; | 529 cond_ = cond; |
| 531 } | 530 } |
| 532 | 531 |
| 533 Expression* cond() const { return cond_; } | 532 Expression* cond() const { return cond_; } |
| 534 bool may_have_function_literal() const { | 533 bool may_have_function_literal() const { |
| 535 return may_have_function_literal_; | 534 return may_have_function_literal_; |
| 536 } | 535 } |
| 537 void set_may_have_function_literal(bool value) { | 536 void set_may_have_function_literal(bool value) { |
| 538 may_have_function_literal_ = value; | 537 may_have_function_literal_ = value; |
| 539 } | 538 } |
| 540 virtual bool IsInlineable() const; | |
| 541 | 539 |
| 542 // Bailout support. | 540 // Bailout support. |
| 543 virtual int ContinueId() const { return EntryId(); } | 541 virtual int ContinueId() const { return EntryId(); } |
| 544 virtual int StackCheckId() const { return body_id_; } | 542 virtual int StackCheckId() const { return body_id_; } |
| 545 int BodyId() const { return body_id_; } | 543 int BodyId() const { return body_id_; } |
| 546 | 544 |
| 545 protected: | |
| 546 friend class AstNodeFactory; | |
| 547 | |
| 548 WhileStatement(Isolate* isolate, ZoneStringList* labels) | |
| 549 : IterationStatement(isolate, labels), | |
| 550 cond_(NULL), | |
| 551 may_have_function_literal_(true), | |
| 552 body_id_(GetNextId(isolate)) { | |
| 553 } | |
| 554 | |
| 547 private: | 555 private: |
| 548 Expression* cond_; | 556 Expression* cond_; |
| 549 // True if there is a function literal subexpression in the condition. | 557 // True if there is a function literal subexpression in the condition. |
| 550 bool may_have_function_literal_; | 558 bool may_have_function_literal_; |
| 551 int body_id_; | 559 int body_id_; |
| 552 }; | 560 }; |
| 553 | 561 |
| 554 | 562 |
| 555 class ForStatement: public IterationStatement { | 563 class ForStatement: public IterationStatement { |
| 556 public: | 564 public: |
| 557 ForStatement(Isolate* isolate, ZoneStringList* labels) | |
| 558 : IterationStatement(isolate, labels), | |
| 559 init_(NULL), | |
| 560 cond_(NULL), | |
| 561 next_(NULL), | |
| 562 may_have_function_literal_(true), | |
| 563 loop_variable_(NULL), | |
| 564 continue_id_(GetNextId(isolate)), | |
| 565 body_id_(GetNextId(isolate)) { | |
| 566 } | |
| 567 | |
| 568 DECLARE_NODE_TYPE(ForStatement) | 565 DECLARE_NODE_TYPE(ForStatement) |
| 569 | 566 |
| 570 void Initialize(Statement* init, | 567 void Initialize(Statement* init, |
| 571 Expression* cond, | 568 Expression* cond, |
| 572 Statement* next, | 569 Statement* next, |
| 573 Statement* body) { | 570 Statement* body) { |
| 574 IterationStatement::Initialize(body); | 571 IterationStatement::Initialize(body); |
| 575 init_ = init; | 572 init_ = init; |
| 576 cond_ = cond; | 573 cond_ = cond; |
| 577 next_ = next; | 574 next_ = next; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 589 } | 586 } |
| 590 | 587 |
| 591 // Bailout support. | 588 // Bailout support. |
| 592 virtual int ContinueId() const { return continue_id_; } | 589 virtual int ContinueId() const { return continue_id_; } |
| 593 virtual int StackCheckId() const { return body_id_; } | 590 virtual int StackCheckId() const { return body_id_; } |
| 594 int BodyId() const { return body_id_; } | 591 int BodyId() const { return body_id_; } |
| 595 | 592 |
| 596 bool is_fast_smi_loop() { return loop_variable_ != NULL; } | 593 bool is_fast_smi_loop() { return loop_variable_ != NULL; } |
| 597 Variable* loop_variable() { return loop_variable_; } | 594 Variable* loop_variable() { return loop_variable_; } |
| 598 void set_loop_variable(Variable* var) { loop_variable_ = var; } | 595 void set_loop_variable(Variable* var) { loop_variable_ = var; } |
| 599 virtual bool IsInlineable() const; | 596 |
| 597 protected: | |
| 598 friend class AstNodeFactory; | |
| 599 | |
| 600 ForStatement(Isolate* isolate, ZoneStringList* labels) | |
| 601 : IterationStatement(isolate, labels), | |
| 602 init_(NULL), | |
| 603 cond_(NULL), | |
| 604 next_(NULL), | |
| 605 may_have_function_literal_(true), | |
| 606 loop_variable_(NULL), | |
| 607 continue_id_(GetNextId(isolate)), | |
| 608 body_id_(GetNextId(isolate)) { | |
| 609 } | |
| 600 | 610 |
| 601 private: | 611 private: |
| 602 Statement* init_; | 612 Statement* init_; |
| 603 Expression* cond_; | 613 Expression* cond_; |
| 604 Statement* next_; | 614 Statement* next_; |
| 605 // True if there is a function literal subexpression in the condition. | 615 // True if there is a function literal subexpression in the condition. |
| 606 bool may_have_function_literal_; | 616 bool may_have_function_literal_; |
| 607 Variable* loop_variable_; | 617 Variable* loop_variable_; |
| 608 int continue_id_; | 618 int continue_id_; |
| 609 int body_id_; | 619 int body_id_; |
| 610 }; | 620 }; |
| 611 | 621 |
| 612 | 622 |
| 613 class ForInStatement: public IterationStatement { | 623 class ForInStatement: public IterationStatement { |
| 614 public: | 624 public: |
| 615 ForInStatement(Isolate* isolate, ZoneStringList* labels) | |
| 616 : IterationStatement(isolate, labels), | |
| 617 each_(NULL), | |
| 618 enumerable_(NULL), | |
| 619 assignment_id_(GetNextId(isolate)) { | |
| 620 } | |
| 621 | |
| 622 DECLARE_NODE_TYPE(ForInStatement) | 625 DECLARE_NODE_TYPE(ForInStatement) |
| 623 | 626 |
| 624 void Initialize(Expression* each, Expression* enumerable, Statement* body) { | 627 void Initialize(Expression* each, Expression* enumerable, Statement* body) { |
| 625 IterationStatement::Initialize(body); | 628 IterationStatement::Initialize(body); |
| 626 each_ = each; | 629 each_ = each; |
| 627 enumerable_ = enumerable; | 630 enumerable_ = enumerable; |
| 628 } | 631 } |
| 629 | 632 |
| 630 Expression* each() const { return each_; } | 633 Expression* each() const { return each_; } |
| 631 Expression* enumerable() const { return enumerable_; } | 634 Expression* enumerable() const { return enumerable_; } |
| 632 virtual bool IsInlineable() const; | |
| 633 | 635 |
| 634 // Bailout support. | 636 // Bailout support. |
| 635 int AssignmentId() const { return assignment_id_; } | 637 int AssignmentId() const { return assignment_id_; } |
| 636 virtual int ContinueId() const { return EntryId(); } | 638 virtual int ContinueId() const { return EntryId(); } |
| 637 virtual int StackCheckId() const { return EntryId(); } | 639 virtual int StackCheckId() const { return EntryId(); } |
| 638 | 640 |
| 641 protected: | |
| 642 friend class AstNodeFactory; | |
| 643 | |
| 644 ForInStatement(Isolate* isolate, ZoneStringList* labels) | |
| 645 : IterationStatement(isolate, labels), | |
| 646 each_(NULL), | |
| 647 enumerable_(NULL), | |
| 648 assignment_id_(GetNextId(isolate)) { | |
| 649 } | |
| 650 | |
| 639 private: | 651 private: |
| 640 Expression* each_; | 652 Expression* each_; |
| 641 Expression* enumerable_; | 653 Expression* enumerable_; |
| 642 int assignment_id_; | 654 int assignment_id_; |
| 643 }; | 655 }; |
| 644 | 656 |
| 645 | 657 |
| 646 class ExpressionStatement: public Statement { | 658 class ExpressionStatement: public Statement { |
| 647 public: | 659 public: |
| 648 explicit ExpressionStatement(Expression* expression) | |
| 649 : expression_(expression) { } | |
| 650 | |
| 651 DECLARE_NODE_TYPE(ExpressionStatement) | 660 DECLARE_NODE_TYPE(ExpressionStatement) |
| 652 | 661 |
| 653 virtual bool IsInlineable() const; | |
| 654 | |
| 655 void set_expression(Expression* e) { expression_ = e; } | 662 void set_expression(Expression* e) { expression_ = e; } |
| 656 Expression* expression() const { return expression_; } | 663 Expression* expression() const { return expression_; } |
| 657 | 664 |
| 665 protected: | |
| 666 friend class AstNodeFactory; | |
| 667 | |
| 668 explicit ExpressionStatement(Expression* expression) | |
| 669 : expression_(expression) { } | |
| 670 | |
| 658 private: | 671 private: |
| 659 Expression* expression_; | 672 Expression* expression_; |
| 660 }; | 673 }; |
| 661 | 674 |
| 662 | 675 |
| 663 class ContinueStatement: public Statement { | 676 class ContinueStatement: public Statement { |
| 664 public: | 677 public: |
| 678 DECLARE_NODE_TYPE(ContinueStatement) | |
| 679 | |
| 680 IterationStatement* target() const { return target_; } | |
| 681 | |
| 682 protected: | |
| 683 friend class AstNodeFactory; | |
| 684 | |
| 665 explicit ContinueStatement(IterationStatement* target) | 685 explicit ContinueStatement(IterationStatement* target) |
| 666 : target_(target) { } | 686 : target_(target) { } |
| 667 | 687 |
| 668 DECLARE_NODE_TYPE(ContinueStatement) | |
| 669 | |
| 670 IterationStatement* target() const { return target_; } | |
| 671 virtual bool IsInlineable() const; | |
| 672 | |
| 673 private: | 688 private: |
| 674 IterationStatement* target_; | 689 IterationStatement* target_; |
| 675 }; | 690 }; |
| 676 | 691 |
| 677 | 692 |
| 678 class BreakStatement: public Statement { | 693 class BreakStatement: public Statement { |
| 679 public: | 694 public: |
| 695 DECLARE_NODE_TYPE(BreakStatement) | |
| 696 | |
| 697 BreakableStatement* target() const { return target_; } | |
| 698 | |
| 699 protected: | |
| 700 friend class AstNodeFactory; | |
| 701 | |
| 680 explicit BreakStatement(BreakableStatement* target) | 702 explicit BreakStatement(BreakableStatement* target) |
| 681 : target_(target) { } | 703 : target_(target) { } |
| 682 | 704 |
| 683 DECLARE_NODE_TYPE(BreakStatement) | |
| 684 | |
| 685 BreakableStatement* target() const { return target_; } | |
| 686 virtual bool IsInlineable() const; | |
| 687 | |
| 688 private: | 705 private: |
| 689 BreakableStatement* target_; | 706 BreakableStatement* target_; |
| 690 }; | 707 }; |
| 691 | 708 |
| 692 | 709 |
| 693 class ReturnStatement: public Statement { | 710 class ReturnStatement: public Statement { |
| 694 public: | 711 public: |
| 712 DECLARE_NODE_TYPE(ReturnStatement) | |
| 713 | |
| 714 Expression* expression() const { return expression_; } | |
| 715 | |
| 716 protected: | |
| 717 friend class AstNodeFactory; | |
| 718 | |
| 695 explicit ReturnStatement(Expression* expression) | 719 explicit ReturnStatement(Expression* expression) |
| 696 : expression_(expression) { } | 720 : expression_(expression) { } |
| 697 | 721 |
| 698 DECLARE_NODE_TYPE(ReturnStatement) | |
| 699 | |
| 700 Expression* expression() const { return expression_; } | |
| 701 virtual bool IsInlineable() const; | |
| 702 | |
| 703 private: | 722 private: |
| 704 Expression* expression_; | 723 Expression* expression_; |
| 705 }; | 724 }; |
| 706 | 725 |
| 707 | 726 |
| 708 class WithStatement: public Statement { | 727 class WithStatement: public Statement { |
| 709 public: | 728 public: |
| 710 WithStatement(Expression* expression, Statement* statement) | |
| 711 : expression_(expression), statement_(statement) { } | |
| 712 | |
| 713 DECLARE_NODE_TYPE(WithStatement) | 729 DECLARE_NODE_TYPE(WithStatement) |
| 714 | 730 |
| 715 Expression* expression() const { return expression_; } | 731 Expression* expression() const { return expression_; } |
| 716 Statement* statement() const { return statement_; } | 732 Statement* statement() const { return statement_; } |
| 717 | 733 |
| 718 virtual bool IsInlineable() const; | 734 protected: |
| 735 friend class AstNodeFactory; | |
| 736 | |
| 737 WithStatement(Expression* expression, Statement* statement) | |
| 738 : expression_(expression), | |
| 739 statement_(statement) { } | |
| 719 | 740 |
| 720 private: | 741 private: |
| 721 Expression* expression_; | 742 Expression* expression_; |
| 722 Statement* statement_; | 743 Statement* statement_; |
| 723 }; | 744 }; |
| 724 | 745 |
| 725 | 746 |
| 726 class CaseClause: public ZoneObject { | 747 class CaseClause: public ZoneObject { |
| 727 public: | 748 public: |
| 728 CaseClause(Isolate* isolate, | 749 CaseClause(Isolate* isolate, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 OBJECT_ONLY | 785 OBJECT_ONLY |
| 765 }; | 786 }; |
| 766 CompareTypeFeedback compare_type_; | 787 CompareTypeFeedback compare_type_; |
| 767 int compare_id_; | 788 int compare_id_; |
| 768 int entry_id_; | 789 int entry_id_; |
| 769 }; | 790 }; |
| 770 | 791 |
| 771 | 792 |
| 772 class SwitchStatement: public BreakableStatement { | 793 class SwitchStatement: public BreakableStatement { |
| 773 public: | 794 public: |
| 774 SwitchStatement(Isolate* isolate, ZoneStringList* labels) | |
| 775 : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS), | |
| 776 tag_(NULL), | |
| 777 cases_(NULL) { | |
| 778 } | |
| 779 | |
| 780 | |
| 781 DECLARE_NODE_TYPE(SwitchStatement) | 795 DECLARE_NODE_TYPE(SwitchStatement) |
| 782 | 796 |
| 783 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { | 797 void Initialize(Expression* tag, ZoneList<CaseClause*>* cases) { |
| 784 tag_ = tag; | 798 tag_ = tag; |
| 785 cases_ = cases; | 799 cases_ = cases; |
| 786 } | 800 } |
| 787 | 801 |
| 788 Expression* tag() const { return tag_; } | 802 Expression* tag() const { return tag_; } |
| 789 ZoneList<CaseClause*>* cases() const { return cases_; } | 803 ZoneList<CaseClause*>* cases() const { return cases_; } |
| 790 virtual bool IsInlineable() const; | 804 |
| 805 protected: | |
| 806 friend class AstNodeFactory; | |
| 807 | |
| 808 SwitchStatement(Isolate* isolate, ZoneStringList* labels) | |
| 809 : BreakableStatement(isolate, labels, TARGET_FOR_ANONYMOUS), | |
| 810 tag_(NULL), | |
| 811 cases_(NULL) { } | |
| 791 | 812 |
| 792 private: | 813 private: |
| 793 Expression* tag_; | 814 Expression* tag_; |
| 794 ZoneList<CaseClause*>* cases_; | 815 ZoneList<CaseClause*>* cases_; |
| 795 }; | 816 }; |
| 796 | 817 |
| 797 | 818 |
| 798 // If-statements always have non-null references to their then- and | 819 // If-statements always have non-null references to their then- and |
| 799 // else-parts. When parsing if-statements with no explicit else-part, | 820 // else-parts. When parsing if-statements with no explicit else-part, |
| 800 // the parser implicitly creates an empty statement. Use the | 821 // the parser implicitly creates an empty statement. Use the |
| 801 // HasThenStatement() and HasElseStatement() functions to check if a | 822 // HasThenStatement() and HasElseStatement() functions to check if a |
| 802 // given if-statement has a then- or an else-part containing code. | 823 // given if-statement has a then- or an else-part containing code. |
| 803 class IfStatement: public Statement { | 824 class IfStatement: public Statement { |
| 804 public: | 825 public: |
| 805 IfStatement(Isolate* isolate, | |
| 806 Expression* condition, | |
| 807 Statement* then_statement, | |
| 808 Statement* else_statement) | |
| 809 : condition_(condition), | |
| 810 then_statement_(then_statement), | |
| 811 else_statement_(else_statement), | |
| 812 if_id_(GetNextId(isolate)), | |
| 813 then_id_(GetNextId(isolate)), | |
| 814 else_id_(GetNextId(isolate)) { | |
| 815 } | |
| 816 | |
| 817 DECLARE_NODE_TYPE(IfStatement) | 826 DECLARE_NODE_TYPE(IfStatement) |
| 818 | 827 |
| 819 virtual bool IsInlineable() const; | |
| 820 | |
| 821 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } | 828 bool HasThenStatement() const { return !then_statement()->IsEmpty(); } |
| 822 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } | 829 bool HasElseStatement() const { return !else_statement()->IsEmpty(); } |
| 823 | 830 |
| 824 Expression* condition() const { return condition_; } | 831 Expression* condition() const { return condition_; } |
| 825 Statement* then_statement() const { return then_statement_; } | 832 Statement* then_statement() const { return then_statement_; } |
| 826 Statement* else_statement() const { return else_statement_; } | 833 Statement* else_statement() const { return else_statement_; } |
| 827 | 834 |
| 828 int IfId() const { return if_id_; } | 835 int IfId() const { return if_id_; } |
| 829 int ThenId() const { return then_id_; } | 836 int ThenId() const { return then_id_; } |
| 830 int ElseId() const { return else_id_; } | 837 int ElseId() const { return else_id_; } |
| 831 | 838 |
| 839 protected: | |
| 840 friend class AstNodeFactory; | |
| 841 | |
| 842 IfStatement(Isolate* isolate, | |
| 843 Expression* condition, | |
| 844 Statement* then_statement, | |
| 845 Statement* else_statement) | |
| 846 : condition_(condition), | |
| 847 then_statement_(then_statement), | |
| 848 else_statement_(else_statement), | |
| 849 if_id_(GetNextId(isolate)), | |
| 850 then_id_(GetNextId(isolate)), | |
| 851 else_id_(GetNextId(isolate)) { | |
| 852 } | |
| 853 | |
| 832 private: | 854 private: |
| 833 Expression* condition_; | 855 Expression* condition_; |
| 834 Statement* then_statement_; | 856 Statement* then_statement_; |
| 835 Statement* else_statement_; | 857 Statement* else_statement_; |
| 836 int if_id_; | 858 int if_id_; |
| 837 int then_id_; | 859 int then_id_; |
| 838 int else_id_; | 860 int else_id_; |
| 839 }; | 861 }; |
| 840 | 862 |
| 841 | 863 |
| 842 // NOTE: TargetCollectors are represented as nodes to fit in the target | 864 // NOTE: TargetCollectors are represented as nodes to fit in the target |
| 843 // stack in the compiler; this should probably be reworked. | 865 // stack in the compiler; this should probably be reworked. |
| 844 class TargetCollector: public AstNode { | 866 class TargetCollector: public AstNode { |
| 845 public: | 867 public: |
| 846 TargetCollector(): targets_(0) { } | 868 TargetCollector() : targets_(0) { } |
| 847 | 869 |
| 848 // Adds a jump target to the collector. The collector stores a pointer not | 870 // Adds a jump target to the collector. The collector stores a pointer not |
| 849 // a copy of the target to make binding work, so make sure not to pass in | 871 // a copy of the target to make binding work, so make sure not to pass in |
| 850 // references to something on the stack. | 872 // references to something on the stack. |
| 851 void AddTarget(Label* target); | 873 void AddTarget(Label* target); |
| 852 | 874 |
| 853 // Virtual behaviour. TargetCollectors are never part of the AST. | 875 // Virtual behaviour. TargetCollectors are never part of the AST. |
| 854 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } | 876 virtual void Accept(AstVisitor* v) { UNREACHABLE(); } |
| 855 virtual TargetCollector* AsTargetCollector() { return this; } | 877 virtual TargetCollector* AsTargetCollector() { return this; } |
| 856 | 878 |
| 857 ZoneList<Label*>* targets() { return &targets_; } | 879 ZoneList<Label*>* targets() { return &targets_; } |
| 858 virtual bool IsInlineable() const; | |
| 859 | 880 |
| 860 private: | 881 private: |
| 861 ZoneList<Label*> targets_; | 882 ZoneList<Label*> targets_; |
| 862 }; | 883 }; |
| 863 | 884 |
| 864 | 885 |
| 865 class TryStatement: public Statement { | 886 class TryStatement: public Statement { |
| 866 public: | 887 public: |
| 867 explicit TryStatement(int index, Block* try_block) | |
| 868 : index_(index), | |
| 869 try_block_(try_block), | |
| 870 escaping_targets_(NULL) { | |
| 871 } | |
| 872 | |
| 873 void set_escaping_targets(ZoneList<Label*>* targets) { | 888 void set_escaping_targets(ZoneList<Label*>* targets) { |
| 874 escaping_targets_ = targets; | 889 escaping_targets_ = targets; |
| 875 } | 890 } |
| 876 | 891 |
| 877 int index() const { return index_; } | 892 int index() const { return index_; } |
| 878 Block* try_block() const { return try_block_; } | 893 Block* try_block() const { return try_block_; } |
| 879 ZoneList<Label*>* escaping_targets() const { return escaping_targets_; } | 894 ZoneList<Label*>* escaping_targets() const { return escaping_targets_; } |
| 880 virtual bool IsInlineable() const; | 895 |
| 896 protected: | |
| 897 TryStatement(int index, Block* try_block) | |
| 898 : index_(index), | |
| 899 try_block_(try_block), | |
| 900 escaping_targets_(NULL) { } | |
| 881 | 901 |
| 882 private: | 902 private: |
| 883 // Unique (per-function) index of this handler. This is not an AST ID. | 903 // Unique (per-function) index of this handler. This is not an AST ID. |
| 884 int index_; | 904 int index_; |
| 885 | 905 |
| 886 Block* try_block_; | 906 Block* try_block_; |
| 887 ZoneList<Label*>* escaping_targets_; | 907 ZoneList<Label*>* escaping_targets_; |
| 888 }; | 908 }; |
| 889 | 909 |
| 890 | 910 |
| 891 class TryCatchStatement: public TryStatement { | 911 class TryCatchStatement: public TryStatement { |
| 892 public: | 912 public: |
| 913 DECLARE_NODE_TYPE(TryCatchStatement) | |
| 914 | |
| 915 Scope* scope() { return scope_; } | |
| 916 Variable* variable() { return variable_; } | |
| 917 Block* catch_block() const { return catch_block_; } | |
| 918 | |
| 919 protected: | |
| 920 friend class AstNodeFactory; | |
| 921 | |
| 893 TryCatchStatement(int index, | 922 TryCatchStatement(int index, |
| 894 Block* try_block, | 923 Block* try_block, |
| 895 Scope* scope, | 924 Scope* scope, |
| 896 Variable* variable, | 925 Variable* variable, |
| 897 Block* catch_block) | 926 Block* catch_block) |
| 898 : TryStatement(index, try_block), | 927 : TryStatement(index, try_block), |
| 899 scope_(scope), | 928 scope_(scope), |
| 900 variable_(variable), | 929 variable_(variable), |
| 901 catch_block_(catch_block) { | 930 catch_block_(catch_block) { |
| 902 } | 931 } |
| 903 | 932 |
| 904 DECLARE_NODE_TYPE(TryCatchStatement) | |
| 905 | |
| 906 Scope* scope() { return scope_; } | |
| 907 Variable* variable() { return variable_; } | |
| 908 Block* catch_block() const { return catch_block_; } | |
| 909 virtual bool IsInlineable() const; | |
| 910 | |
| 911 private: | 933 private: |
| 912 Scope* scope_; | 934 Scope* scope_; |
| 913 Variable* variable_; | 935 Variable* variable_; |
| 914 Block* catch_block_; | 936 Block* catch_block_; |
| 915 }; | 937 }; |
| 916 | 938 |
| 917 | 939 |
| 918 class TryFinallyStatement: public TryStatement { | 940 class TryFinallyStatement: public TryStatement { |
| 919 public: | 941 public: |
| 942 DECLARE_NODE_TYPE(TryFinallyStatement) | |
| 943 | |
| 944 Block* finally_block() const { return finally_block_; } | |
| 945 | |
| 946 protected: | |
| 947 friend class AstNodeFactory; | |
| 948 | |
| 920 TryFinallyStatement(int index, Block* try_block, Block* finally_block) | 949 TryFinallyStatement(int index, Block* try_block, Block* finally_block) |
| 921 : TryStatement(index, try_block), | 950 : TryStatement(index, try_block), |
| 922 finally_block_(finally_block) { } | 951 finally_block_(finally_block) { } |
| 923 | 952 |
| 924 DECLARE_NODE_TYPE(TryFinallyStatement) | |
| 925 | |
| 926 Block* finally_block() const { return finally_block_; } | |
| 927 virtual bool IsInlineable() const; | |
| 928 | |
| 929 private: | 953 private: |
| 930 Block* finally_block_; | 954 Block* finally_block_; |
| 931 }; | 955 }; |
| 932 | 956 |
| 933 | 957 |
| 934 class DebuggerStatement: public Statement { | 958 class DebuggerStatement: public Statement { |
| 935 public: | 959 public: |
| 936 DECLARE_NODE_TYPE(DebuggerStatement) | 960 DECLARE_NODE_TYPE(DebuggerStatement) |
| 937 virtual bool IsInlineable() const; | 961 |
| 962 protected: | |
| 963 friend class AstNodeFactory; | |
| 964 | |
| 965 DebuggerStatement() {} | |
| 938 }; | 966 }; |
| 939 | 967 |
| 940 | 968 |
| 941 class EmptyStatement: public Statement { | 969 class EmptyStatement: public Statement { |
| 942 public: | 970 public: |
| 943 DECLARE_NODE_TYPE(EmptyStatement) | 971 DECLARE_NODE_TYPE(EmptyStatement) |
| 944 | 972 |
| 945 virtual bool IsInlineable() const; | 973 protected: |
| 974 friend class AstNodeFactory; | |
| 975 | |
| 976 EmptyStatement() {} | |
| 946 }; | 977 }; |
| 947 | 978 |
| 948 | 979 |
| 949 class Literal: public Expression { | 980 class Literal: public Expression { |
| 950 public: | 981 public: |
| 951 Literal(Isolate* isolate, Handle<Object> handle) | |
| 952 : Expression(isolate), handle_(handle) { } | |
| 953 | |
| 954 DECLARE_NODE_TYPE(Literal) | 982 DECLARE_NODE_TYPE(Literal) |
| 955 | 983 |
| 956 // Check if this literal is identical to the other literal. | 984 // Check if this literal is identical to the other literal. |
| 957 bool IsIdenticalTo(const Literal* other) const { | 985 bool IsIdenticalTo(const Literal* other) const { |
| 958 return handle_.is_identical_to(other->handle_); | 986 return handle_.is_identical_to(other->handle_); |
| 959 } | 987 } |
| 960 | 988 |
| 961 virtual bool IsPropertyName() { | 989 virtual bool IsPropertyName() { |
| 962 if (handle_->IsSymbol()) { | 990 if (handle_->IsSymbol()) { |
| 963 uint32_t ignored; | 991 uint32_t ignored; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 982 bool IsTrue() const { | 1010 bool IsTrue() const { |
| 983 ASSERT(!handle_.is_null()); | 1011 ASSERT(!handle_.is_null()); |
| 984 return handle_->IsTrue(); | 1012 return handle_->IsTrue(); |
| 985 } | 1013 } |
| 986 bool IsFalse() const { | 1014 bool IsFalse() const { |
| 987 ASSERT(!handle_.is_null()); | 1015 ASSERT(!handle_.is_null()); |
| 988 return handle_->IsFalse(); | 1016 return handle_->IsFalse(); |
| 989 } | 1017 } |
| 990 | 1018 |
| 991 Handle<Object> handle() const { return handle_; } | 1019 Handle<Object> handle() const { return handle_; } |
| 992 virtual bool IsInlineable() const; | 1020 |
| 1021 protected: | |
| 1022 friend class AstNodeFactory; | |
| 1023 | |
| 1024 Literal(Isolate* isolate, Handle<Object> handle) | |
| 1025 : Expression(isolate), | |
| 1026 handle_(handle) { } | |
| 993 | 1027 |
| 994 private: | 1028 private: |
| 995 Handle<Object> handle_; | 1029 Handle<Object> handle_; |
| 996 }; | 1030 }; |
| 997 | 1031 |
| 998 | 1032 |
| 999 // Base class for literals that needs space in the corresponding JSFunction. | 1033 // Base class for literals that needs space in the corresponding JSFunction. |
| 1000 class MaterializedLiteral: public Expression { | 1034 class MaterializedLiteral: public Expression { |
| 1001 public: | 1035 public: |
| 1002 MaterializedLiteral(Isolate* isolate, | |
| 1003 int literal_index, | |
| 1004 bool is_simple, | |
| 1005 int depth) | |
| 1006 : Expression(isolate), | |
| 1007 literal_index_(literal_index), | |
| 1008 is_simple_(is_simple), | |
| 1009 depth_(depth) {} | |
| 1010 | |
| 1011 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } | 1036 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } |
| 1012 | 1037 |
| 1013 int literal_index() { return literal_index_; } | 1038 int literal_index() { return literal_index_; } |
| 1014 | 1039 |
| 1015 // A materialized literal is simple if the values consist of only | 1040 // A materialized literal is simple if the values consist of only |
| 1016 // constants and simple object and array literals. | 1041 // constants and simple object and array literals. |
| 1017 bool is_simple() const { return is_simple_; } | 1042 bool is_simple() const { return is_simple_; } |
| 1018 | 1043 |
| 1019 int depth() const { return depth_; } | 1044 int depth() const { return depth_; } |
| 1020 virtual bool IsInlineable() const; | 1045 |
| 1046 protected: | |
| 1047 MaterializedLiteral(Isolate* isolate, | |
| 1048 int literal_index, | |
| 1049 bool is_simple, | |
| 1050 int depth) | |
| 1051 : Expression(isolate), | |
| 1052 literal_index_(literal_index), | |
| 1053 is_simple_(is_simple), | |
| 1054 depth_(depth) {} | |
| 1021 | 1055 |
| 1022 private: | 1056 private: |
| 1023 int literal_index_; | 1057 int literal_index_; |
| 1024 bool is_simple_; | 1058 bool is_simple_; |
| 1025 int depth_; | 1059 int depth_; |
| 1026 }; | 1060 }; |
| 1027 | 1061 |
| 1028 | 1062 |
| 1029 // An object literal has a boilerplate object that is used | 1063 // An object literal has a boilerplate object that is used |
| 1030 // for minimizing the work when constructing it at runtime. | 1064 // for minimizing the work when constructing it at runtime. |
| 1031 class ObjectLiteral: public MaterializedLiteral { | 1065 class ObjectLiteral: public MaterializedLiteral { |
| 1032 public: | 1066 public: |
| 1033 // Property is used for passing information | 1067 // Property is used for passing information |
| 1034 // about an object literal's properties from the parser | 1068 // about an object literal's properties from the parser |
| 1035 // to the code generator. | 1069 // to the code generator. |
| 1036 class Property: public ZoneObject { | 1070 class Property: public ZoneObject { |
| 1037 public: | 1071 public: |
| 1038 enum Kind { | 1072 enum Kind { |
| 1039 CONSTANT, // Property with constant value (compile time). | 1073 CONSTANT, // Property with constant value (compile time). |
| 1040 COMPUTED, // Property with computed value (execution time). | 1074 COMPUTED, // Property with computed value (execution time). |
| 1041 MATERIALIZED_LITERAL, // Property value is a materialized literal. | 1075 MATERIALIZED_LITERAL, // Property value is a materialized literal. |
| 1042 GETTER, SETTER, // Property is an accessor function. | 1076 GETTER, SETTER, // Property is an accessor function. |
| 1043 PROTOTYPE // Property is __proto__. | 1077 PROTOTYPE // Property is __proto__. |
| 1044 }; | 1078 }; |
| 1045 | 1079 |
| 1046 Property(Literal* key, Expression* value); | 1080 Property(Literal* key, Expression* value); |
| 1047 Property(bool is_getter, FunctionLiteral* value); | 1081 Property(bool is_getter, FunctionLiteral* value, AstNodeFactory* factory); |
| 1048 | 1082 |
| 1049 Literal* key() { return key_; } | 1083 Literal* key() { return key_; } |
| 1050 Expression* value() { return value_; } | 1084 Expression* value() { return value_; } |
| 1051 Kind kind() { return kind_; } | 1085 Kind kind() { return kind_; } |
| 1052 | 1086 |
| 1053 bool IsCompileTimeValue(); | 1087 bool IsCompileTimeValue(); |
| 1054 | 1088 |
| 1055 void set_emit_store(bool emit_store); | 1089 void set_emit_store(bool emit_store); |
| 1056 bool emit_store(); | 1090 bool emit_store(); |
| 1057 | 1091 |
| 1058 private: | 1092 private: |
| 1059 Literal* key_; | 1093 Literal* key_; |
| 1060 Expression* value_; | 1094 Expression* value_; |
| 1061 Kind kind_; | 1095 Kind kind_; |
| 1062 bool emit_store_; | 1096 bool emit_store_; |
| 1063 }; | 1097 }; |
| 1064 | 1098 |
| 1065 ObjectLiteral(Isolate* isolate, | |
| 1066 Handle<FixedArray> constant_properties, | |
| 1067 ZoneList<Property*>* properties, | |
| 1068 int literal_index, | |
| 1069 bool is_simple, | |
| 1070 bool fast_elements, | |
| 1071 int depth, | |
| 1072 bool has_function) | |
| 1073 : MaterializedLiteral(isolate, literal_index, is_simple, depth), | |
| 1074 constant_properties_(constant_properties), | |
| 1075 properties_(properties), | |
| 1076 fast_elements_(fast_elements), | |
| 1077 has_function_(has_function) {} | |
| 1078 | |
| 1079 DECLARE_NODE_TYPE(ObjectLiteral) | 1099 DECLARE_NODE_TYPE(ObjectLiteral) |
| 1080 | 1100 |
| 1081 Handle<FixedArray> constant_properties() const { | 1101 Handle<FixedArray> constant_properties() const { |
| 1082 return constant_properties_; | 1102 return constant_properties_; |
| 1083 } | 1103 } |
| 1084 ZoneList<Property*>* properties() const { return properties_; } | 1104 ZoneList<Property*>* properties() const { return properties_; } |
| 1085 | 1105 |
| 1086 bool fast_elements() const { return fast_elements_; } | 1106 bool fast_elements() const { return fast_elements_; } |
| 1087 | 1107 |
| 1088 bool has_function() { return has_function_; } | 1108 bool has_function() { return has_function_; } |
| 1089 | 1109 |
| 1090 // Mark all computed expressions that are bound to a key that | 1110 // Mark all computed expressions that are bound to a key that |
| 1091 // is shadowed by a later occurrence of the same key. For the | 1111 // is shadowed by a later occurrence of the same key. For the |
| 1092 // marked expressions, no store code is emitted. | 1112 // marked expressions, no store code is emitted. |
| 1093 void CalculateEmitStore(); | 1113 void CalculateEmitStore(); |
| 1094 | 1114 |
| 1095 enum Flags { | 1115 enum Flags { |
| 1096 kNoFlags = 0, | 1116 kNoFlags = 0, |
| 1097 kFastElements = 1, | 1117 kFastElements = 1, |
| 1098 kHasFunction = 1 << 1 | 1118 kHasFunction = 1 << 1 |
| 1099 }; | 1119 }; |
| 1100 | 1120 |
| 1121 protected: | |
| 1122 friend class AstNodeFactory; | |
| 1123 | |
| 1124 ObjectLiteral(Isolate* isolate, | |
| 1125 Handle<FixedArray> constant_properties, | |
| 1126 ZoneList<Property*>* properties, | |
| 1127 int literal_index, | |
| 1128 bool is_simple, | |
| 1129 bool fast_elements, | |
| 1130 int depth, | |
| 1131 bool has_function) | |
| 1132 : MaterializedLiteral(isolate, literal_index, is_simple, depth), | |
| 1133 constant_properties_(constant_properties), | |
| 1134 properties_(properties), | |
| 1135 fast_elements_(fast_elements), | |
| 1136 has_function_(has_function) {} | |
| 1137 | |
| 1101 private: | 1138 private: |
| 1102 Handle<FixedArray> constant_properties_; | 1139 Handle<FixedArray> constant_properties_; |
| 1103 ZoneList<Property*>* properties_; | 1140 ZoneList<Property*>* properties_; |
| 1104 bool fast_elements_; | 1141 bool fast_elements_; |
| 1105 bool has_function_; | 1142 bool has_function_; |
| 1106 }; | 1143 }; |
| 1107 | 1144 |
| 1108 | 1145 |
| 1109 // Node for capturing a regexp literal. | 1146 // Node for capturing a regexp literal. |
| 1110 class RegExpLiteral: public MaterializedLiteral { | 1147 class RegExpLiteral: public MaterializedLiteral { |
| 1111 public: | 1148 public: |
| 1149 DECLARE_NODE_TYPE(RegExpLiteral) | |
| 1150 | |
| 1151 Handle<String> pattern() const { return pattern_; } | |
| 1152 Handle<String> flags() const { return flags_; } | |
| 1153 | |
| 1154 protected: | |
| 1155 friend class AstNodeFactory; | |
| 1156 | |
| 1112 RegExpLiteral(Isolate* isolate, | 1157 RegExpLiteral(Isolate* isolate, |
| 1113 Handle<String> pattern, | 1158 Handle<String> pattern, |
| 1114 Handle<String> flags, | 1159 Handle<String> flags, |
| 1115 int literal_index) | 1160 int literal_index) |
| 1116 : MaterializedLiteral(isolate, literal_index, false, 1), | 1161 : MaterializedLiteral(isolate, literal_index, false, 1), |
| 1117 pattern_(pattern), | 1162 pattern_(pattern), |
| 1118 flags_(flags) {} | 1163 flags_(flags) {} |
| 1119 | 1164 |
| 1120 DECLARE_NODE_TYPE(RegExpLiteral) | |
| 1121 | |
| 1122 Handle<String> pattern() const { return pattern_; } | |
| 1123 Handle<String> flags() const { return flags_; } | |
| 1124 | |
| 1125 private: | 1165 private: |
| 1126 Handle<String> pattern_; | 1166 Handle<String> pattern_; |
| 1127 Handle<String> flags_; | 1167 Handle<String> flags_; |
| 1128 }; | 1168 }; |
| 1129 | 1169 |
| 1130 // An array literal has a literals object that is used | 1170 // An array literal has a literals object that is used |
| 1131 // for minimizing the work when constructing it at runtime. | 1171 // for minimizing the work when constructing it at runtime. |
| 1132 class ArrayLiteral: public MaterializedLiteral { | 1172 class ArrayLiteral: public MaterializedLiteral { |
| 1133 public: | 1173 public: |
| 1174 DECLARE_NODE_TYPE(ArrayLiteral) | |
| 1175 | |
| 1176 Handle<FixedArray> constant_elements() const { return constant_elements_; } | |
| 1177 ZoneList<Expression*>* values() const { return values_; } | |
| 1178 | |
| 1179 // Return an AST id for an element that is used in simulate instructions. | |
| 1180 int GetIdForElement(int i) { return first_element_id_ + i; } | |
| 1181 | |
| 1182 protected: | |
| 1183 friend class AstNodeFactory; | |
| 1184 | |
| 1134 ArrayLiteral(Isolate* isolate, | 1185 ArrayLiteral(Isolate* isolate, |
| 1135 Handle<FixedArray> constant_elements, | 1186 Handle<FixedArray> constant_elements, |
| 1136 ZoneList<Expression*>* values, | 1187 ZoneList<Expression*>* values, |
| 1137 int literal_index, | 1188 int literal_index, |
| 1138 bool is_simple, | 1189 bool is_simple, |
| 1139 int depth) | 1190 int depth) |
| 1140 : MaterializedLiteral(isolate, literal_index, is_simple, depth), | 1191 : MaterializedLiteral(isolate, literal_index, is_simple, depth), |
| 1141 constant_elements_(constant_elements), | 1192 constant_elements_(constant_elements), |
| 1142 values_(values), | 1193 values_(values), |
| 1143 first_element_id_(ReserveIdRange(isolate, values->length())) {} | 1194 first_element_id_(ReserveIdRange(isolate, values->length())) {} |
| 1144 | 1195 |
| 1145 DECLARE_NODE_TYPE(ArrayLiteral) | |
| 1146 | |
| 1147 Handle<FixedArray> constant_elements() const { return constant_elements_; } | |
| 1148 ZoneList<Expression*>* values() const { return values_; } | |
| 1149 | |
| 1150 // Return an AST id for an element that is used in simulate instructions. | |
| 1151 int GetIdForElement(int i) { return first_element_id_ + i; } | |
| 1152 | |
| 1153 private: | 1196 private: |
| 1154 Handle<FixedArray> constant_elements_; | 1197 Handle<FixedArray> constant_elements_; |
| 1155 ZoneList<Expression*>* values_; | 1198 ZoneList<Expression*>* values_; |
| 1156 int first_element_id_; | 1199 int first_element_id_; |
| 1157 }; | 1200 }; |
| 1158 | 1201 |
| 1159 | 1202 |
| 1160 class VariableProxy: public Expression { | 1203 class VariableProxy: public Expression { |
| 1161 public: | 1204 public: |
| 1162 VariableProxy(Isolate* isolate, Variable* var); | |
| 1163 | |
| 1164 VariableProxy(Isolate* isolate, | |
| 1165 Handle<String> name, | |
| 1166 bool is_this, | |
| 1167 int position = RelocInfo::kNoPosition); | |
| 1168 | |
| 1169 DECLARE_NODE_TYPE(VariableProxy) | 1205 DECLARE_NODE_TYPE(VariableProxy) |
| 1170 | 1206 |
| 1171 virtual bool IsValidLeftHandSide() { | 1207 virtual bool IsValidLeftHandSide() { |
| 1172 return var_ == NULL ? true : var_->IsValidLeftHandSide(); | 1208 return var_ == NULL ? true : var_->IsValidLeftHandSide(); |
| 1173 } | 1209 } |
| 1174 | 1210 |
| 1175 virtual bool IsInlineable() const; | |
| 1176 | |
| 1177 bool IsVariable(Handle<String> n) { | 1211 bool IsVariable(Handle<String> n) { |
| 1178 return !is_this() && name().is_identical_to(n); | 1212 return !is_this() && name().is_identical_to(n); |
| 1179 } | 1213 } |
| 1180 | 1214 |
| 1181 bool IsArguments() { return var_ != NULL && var_->is_arguments(); } | 1215 bool IsArguments() { return var_ != NULL && var_->is_arguments(); } |
| 1182 | 1216 |
| 1183 bool IsLValue() { | 1217 bool IsLValue() { |
| 1184 return is_lvalue_; | 1218 return is_lvalue_; |
| 1185 } | 1219 } |
| 1186 | 1220 |
| 1187 Handle<String> name() const { return name_; } | 1221 Handle<String> name() const { return name_; } |
| 1188 Variable* var() const { return var_; } | 1222 Variable* var() const { return var_; } |
| 1189 bool is_this() const { return is_this_; } | 1223 bool is_this() const { return is_this_; } |
| 1190 int position() const { return position_; } | 1224 int position() const { return position_; } |
| 1191 | 1225 |
| 1192 void MarkAsTrivial() { is_trivial_ = true; } | 1226 void MarkAsTrivial() { is_trivial_ = true; } |
| 1193 void MarkAsLValue() { is_lvalue_ = true; } | 1227 void MarkAsLValue() { is_lvalue_ = true; } |
| 1194 | 1228 |
| 1195 // Bind this proxy to the variable var. | 1229 // Bind this proxy to the variable var. |
| 1196 void BindTo(Variable* var); | 1230 void BindTo(Variable* var); |
| 1197 | 1231 |
| 1198 protected: | 1232 protected: |
| 1233 friend class AstNodeFactory; | |
| 1234 | |
| 1235 VariableProxy(Isolate* isolate, Variable* var); | |
| 1236 | |
| 1237 VariableProxy(Isolate* isolate, | |
| 1238 Handle<String> name, | |
| 1239 bool is_this, | |
| 1240 int position); | |
| 1241 | |
| 1199 Handle<String> name_; | 1242 Handle<String> name_; |
| 1200 Variable* var_; // resolved variable, or NULL | 1243 Variable* var_; // resolved variable, or NULL |
| 1201 bool is_this_; | 1244 bool is_this_; |
| 1202 bool is_trivial_; | 1245 bool is_trivial_; |
| 1203 // True if this variable proxy is being used in an assignment | 1246 // True if this variable proxy is being used in an assignment |
| 1204 // or with a increment/decrement operator. | 1247 // or with a increment/decrement operator. |
| 1205 bool is_lvalue_; | 1248 bool is_lvalue_; |
| 1206 int position_; | 1249 int position_; |
| 1207 }; | 1250 }; |
| 1208 | 1251 |
| 1209 | 1252 |
| 1210 class Property: public Expression { | 1253 class Property: public Expression { |
| 1211 public: | 1254 public: |
| 1212 Property(Isolate* isolate, | |
| 1213 Expression* obj, | |
| 1214 Expression* key, | |
| 1215 int pos) | |
| 1216 : Expression(isolate), | |
| 1217 obj_(obj), | |
| 1218 key_(key), | |
| 1219 pos_(pos), | |
| 1220 is_monomorphic_(false), | |
| 1221 is_array_length_(false), | |
| 1222 is_string_length_(false), | |
| 1223 is_string_access_(false), | |
| 1224 is_function_prototype_(false) { } | |
| 1225 | |
| 1226 DECLARE_NODE_TYPE(Property) | 1255 DECLARE_NODE_TYPE(Property) |
| 1227 | 1256 |
| 1228 virtual bool IsValidLeftHandSide() { return true; } | 1257 virtual bool IsValidLeftHandSide() { return true; } |
| 1229 virtual bool IsInlineable() const; | |
| 1230 | 1258 |
| 1231 Expression* obj() const { return obj_; } | 1259 Expression* obj() const { return obj_; } |
| 1232 Expression* key() const { return key_; } | 1260 Expression* key() const { return key_; } |
| 1233 virtual int position() const { return pos_; } | 1261 virtual int position() const { return pos_; } |
| 1234 | 1262 |
| 1235 bool IsStringLength() const { return is_string_length_; } | 1263 bool IsStringLength() const { return is_string_length_; } |
| 1236 bool IsStringAccess() const { return is_string_access_; } | 1264 bool IsStringAccess() const { return is_string_access_; } |
| 1237 bool IsFunctionPrototype() const { return is_function_prototype_; } | 1265 bool IsFunctionPrototype() const { return is_function_prototype_; } |
| 1238 | 1266 |
| 1239 // Type feedback information. | 1267 // Type feedback information. |
| 1240 void RecordTypeFeedback(TypeFeedbackOracle* oracle); | 1268 void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
| 1241 virtual bool IsMonomorphic() { return is_monomorphic_; } | 1269 virtual bool IsMonomorphic() { return is_monomorphic_; } |
| 1242 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } | 1270 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } |
| 1243 bool IsArrayLength() { return is_array_length_; } | 1271 bool IsArrayLength() { return is_array_length_; } |
| 1244 | 1272 |
| 1273 protected: | |
| 1274 friend class AstNodeFactory; | |
| 1275 | |
| 1276 Property(Isolate* isolate, | |
| 1277 Expression* obj, | |
| 1278 Expression* key, | |
| 1279 int pos) | |
| 1280 : Expression(isolate), | |
| 1281 obj_(obj), | |
| 1282 key_(key), | |
| 1283 pos_(pos), | |
| 1284 is_monomorphic_(false), | |
| 1285 is_array_length_(false), | |
| 1286 is_string_length_(false), | |
| 1287 is_string_access_(false), | |
| 1288 is_function_prototype_(false) { } | |
| 1289 | |
| 1245 private: | 1290 private: |
| 1246 Expression* obj_; | 1291 Expression* obj_; |
| 1247 Expression* key_; | 1292 Expression* key_; |
| 1248 int pos_; | 1293 int pos_; |
| 1249 | 1294 |
| 1250 SmallMapList receiver_types_; | 1295 SmallMapList receiver_types_; |
| 1251 bool is_monomorphic_ : 1; | 1296 bool is_monomorphic_ : 1; |
| 1252 bool is_array_length_ : 1; | 1297 bool is_array_length_ : 1; |
| 1253 bool is_string_length_ : 1; | 1298 bool is_string_length_ : 1; |
| 1254 bool is_string_access_ : 1; | 1299 bool is_string_access_ : 1; |
| 1255 bool is_function_prototype_ : 1; | 1300 bool is_function_prototype_ : 1; |
| 1256 }; | 1301 }; |
| 1257 | 1302 |
| 1258 | 1303 |
| 1259 class Call: public Expression { | 1304 class Call: public Expression { |
| 1260 public: | 1305 public: |
| 1261 Call(Isolate* isolate, | |
| 1262 Expression* expression, | |
| 1263 ZoneList<Expression*>* arguments, | |
| 1264 int pos) | |
| 1265 : Expression(isolate), | |
| 1266 expression_(expression), | |
| 1267 arguments_(arguments), | |
| 1268 pos_(pos), | |
| 1269 is_monomorphic_(false), | |
| 1270 check_type_(RECEIVER_MAP_CHECK), | |
| 1271 return_id_(GetNextId(isolate)) { | |
| 1272 } | |
| 1273 | |
| 1274 DECLARE_NODE_TYPE(Call) | 1306 DECLARE_NODE_TYPE(Call) |
| 1275 | 1307 |
| 1276 virtual bool IsInlineable() const; | |
| 1277 | |
| 1278 Expression* expression() const { return expression_; } | 1308 Expression* expression() const { return expression_; } |
| 1279 ZoneList<Expression*>* arguments() const { return arguments_; } | 1309 ZoneList<Expression*>* arguments() const { return arguments_; } |
| 1280 virtual int position() const { return pos_; } | 1310 virtual int position() const { return pos_; } |
| 1281 | 1311 |
| 1282 void RecordTypeFeedback(TypeFeedbackOracle* oracle, | 1312 void RecordTypeFeedback(TypeFeedbackOracle* oracle, |
| 1283 CallKind call_kind); | 1313 CallKind call_kind); |
| 1284 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } | 1314 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } |
| 1285 virtual bool IsMonomorphic() { return is_monomorphic_; } | 1315 virtual bool IsMonomorphic() { return is_monomorphic_; } |
| 1286 CheckType check_type() const { return check_type_; } | 1316 CheckType check_type() const { return check_type_; } |
| 1287 Handle<JSFunction> target() { return target_; } | 1317 Handle<JSFunction> target() { return target_; } |
| 1288 Handle<JSObject> holder() { return holder_; } | 1318 Handle<JSObject> holder() { return holder_; } |
| 1289 Handle<JSGlobalPropertyCell> cell() { return cell_; } | 1319 Handle<JSGlobalPropertyCell> cell() { return cell_; } |
| 1290 | 1320 |
| 1291 bool ComputeTarget(Handle<Map> type, Handle<String> name); | 1321 bool ComputeTarget(Handle<Map> type, Handle<String> name); |
| 1292 bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupResult* lookup); | 1322 bool ComputeGlobalTarget(Handle<GlobalObject> global, LookupResult* lookup); |
| 1293 | 1323 |
| 1294 // Bailout support. | 1324 // Bailout support. |
| 1295 int ReturnId() const { return return_id_; } | 1325 int ReturnId() const { return return_id_; } |
| 1296 | 1326 |
| 1297 #ifdef DEBUG | 1327 #ifdef DEBUG |
| 1298 // Used to assert that the FullCodeGenerator records the return site. | 1328 // Used to assert that the FullCodeGenerator records the return site. |
| 1299 bool return_is_recorded_; | 1329 bool return_is_recorded_; |
| 1300 #endif | 1330 #endif |
| 1301 | 1331 |
| 1332 protected: | |
| 1333 friend class AstNodeFactory; | |
| 1334 | |
| 1335 Call(Isolate* isolate, | |
| 1336 Expression* expression, | |
| 1337 ZoneList<Expression*>* arguments, | |
| 1338 int pos) | |
| 1339 : Expression(isolate), | |
| 1340 expression_(expression), | |
| 1341 arguments_(arguments), | |
| 1342 pos_(pos), | |
| 1343 is_monomorphic_(false), | |
| 1344 check_type_(RECEIVER_MAP_CHECK), | |
| 1345 return_id_(GetNextId(isolate)) { } | |
| 1346 | |
| 1302 private: | 1347 private: |
| 1303 Expression* expression_; | 1348 Expression* expression_; |
| 1304 ZoneList<Expression*>* arguments_; | 1349 ZoneList<Expression*>* arguments_; |
| 1305 int pos_; | 1350 int pos_; |
| 1306 | 1351 |
| 1307 bool is_monomorphic_; | 1352 bool is_monomorphic_; |
| 1308 CheckType check_type_; | 1353 CheckType check_type_; |
| 1309 SmallMapList receiver_types_; | 1354 SmallMapList receiver_types_; |
| 1310 Handle<JSFunction> target_; | 1355 Handle<JSFunction> target_; |
| 1311 Handle<JSObject> holder_; | 1356 Handle<JSObject> holder_; |
| 1312 Handle<JSGlobalPropertyCell> cell_; | 1357 Handle<JSGlobalPropertyCell> cell_; |
| 1313 | 1358 |
| 1314 int return_id_; | 1359 int return_id_; |
| 1315 }; | 1360 }; |
| 1316 | 1361 |
| 1317 | 1362 |
| 1318 class CallNew: public Expression { | 1363 class CallNew: public Expression { |
| 1319 public: | 1364 public: |
| 1365 DECLARE_NODE_TYPE(CallNew) | |
| 1366 | |
| 1367 Expression* expression() const { return expression_; } | |
| 1368 ZoneList<Expression*>* arguments() const { return arguments_; } | |
| 1369 virtual int position() const { return pos_; } | |
| 1370 | |
| 1371 protected: | |
| 1372 friend class AstNodeFactory; | |
| 1373 | |
| 1320 CallNew(Isolate* isolate, | 1374 CallNew(Isolate* isolate, |
| 1321 Expression* expression, | 1375 Expression* expression, |
| 1322 ZoneList<Expression*>* arguments, | 1376 ZoneList<Expression*>* arguments, |
| 1323 int pos) | 1377 int pos) |
| 1324 : Expression(isolate), | 1378 : Expression(isolate), |
| 1325 expression_(expression), | 1379 expression_(expression), |
| 1326 arguments_(arguments), | 1380 arguments_(arguments), |
| 1327 pos_(pos) { } | 1381 pos_(pos) { } |
| 1328 | 1382 |
| 1329 DECLARE_NODE_TYPE(CallNew) | |
| 1330 | |
| 1331 virtual bool IsInlineable() const; | |
| 1332 | |
| 1333 Expression* expression() const { return expression_; } | |
| 1334 ZoneList<Expression*>* arguments() const { return arguments_; } | |
| 1335 virtual int position() const { return pos_; } | |
| 1336 | |
| 1337 private: | 1383 private: |
| 1338 Expression* expression_; | 1384 Expression* expression_; |
| 1339 ZoneList<Expression*>* arguments_; | 1385 ZoneList<Expression*>* arguments_; |
| 1340 int pos_; | 1386 int pos_; |
| 1341 }; | 1387 }; |
| 1342 | 1388 |
| 1343 | 1389 |
| 1344 // The CallRuntime class does not represent any official JavaScript | 1390 // The CallRuntime class does not represent any official JavaScript |
| 1345 // language construct. Instead it is used to call a C or JS function | 1391 // language construct. Instead it is used to call a C or JS function |
| 1346 // with a set of arguments. This is used from the builtins that are | 1392 // with a set of arguments. This is used from the builtins that are |
| 1347 // implemented in JavaScript (see "v8natives.js"). | 1393 // implemented in JavaScript (see "v8natives.js"). |
| 1348 class CallRuntime: public Expression { | 1394 class CallRuntime: public Expression { |
| 1349 public: | 1395 public: |
| 1396 DECLARE_NODE_TYPE(CallRuntime) | |
| 1397 | |
| 1398 Handle<String> name() const { return name_; } | |
| 1399 const Runtime::Function* function() const { return function_; } | |
| 1400 ZoneList<Expression*>* arguments() const { return arguments_; } | |
| 1401 bool is_jsruntime() const { return function_ == NULL; } | |
| 1402 | |
| 1403 protected: | |
| 1404 friend class AstNodeFactory; | |
| 1405 | |
| 1350 CallRuntime(Isolate* isolate, | 1406 CallRuntime(Isolate* isolate, |
| 1351 Handle<String> name, | 1407 Handle<String> name, |
| 1352 const Runtime::Function* function, | 1408 const Runtime::Function* function, |
| 1353 ZoneList<Expression*>* arguments) | 1409 ZoneList<Expression*>* arguments) |
| 1354 : Expression(isolate), | 1410 : Expression(isolate), |
| 1355 name_(name), | 1411 name_(name), |
| 1356 function_(function), | 1412 function_(function), |
| 1357 arguments_(arguments) { } | 1413 arguments_(arguments) { } |
| 1358 | 1414 |
| 1359 DECLARE_NODE_TYPE(CallRuntime) | |
| 1360 | |
| 1361 virtual bool IsInlineable() const; | |
| 1362 | |
| 1363 Handle<String> name() const { return name_; } | |
| 1364 const Runtime::Function* function() const { return function_; } | |
| 1365 ZoneList<Expression*>* arguments() const { return arguments_; } | |
| 1366 bool is_jsruntime() const { return function_ == NULL; } | |
| 1367 | |
| 1368 private: | 1415 private: |
| 1369 Handle<String> name_; | 1416 Handle<String> name_; |
| 1370 const Runtime::Function* function_; | 1417 const Runtime::Function* function_; |
| 1371 ZoneList<Expression*>* arguments_; | 1418 ZoneList<Expression*>* arguments_; |
| 1372 }; | 1419 }; |
| 1373 | 1420 |
| 1374 | 1421 |
| 1375 class UnaryOperation: public Expression { | 1422 class UnaryOperation: public Expression { |
| 1376 public: | 1423 public: |
| 1424 DECLARE_NODE_TYPE(UnaryOperation) | |
| 1425 | |
| 1426 virtual bool ResultOverwriteAllowed(); | |
| 1427 | |
| 1428 Token::Value op() const { return op_; } | |
| 1429 Expression* expression() const { return expression_; } | |
| 1430 virtual int position() const { return pos_; } | |
| 1431 | |
| 1432 int MaterializeTrueId() { return materialize_true_id_; } | |
| 1433 int MaterializeFalseId() { return materialize_false_id_; } | |
| 1434 | |
| 1435 protected: | |
| 1436 friend class AstNodeFactory; | |
| 1437 | |
| 1377 UnaryOperation(Isolate* isolate, | 1438 UnaryOperation(Isolate* isolate, |
| 1378 Token::Value op, | 1439 Token::Value op, |
| 1379 Expression* expression, | 1440 Expression* expression, |
| 1380 int pos) | 1441 int pos) |
| 1381 : Expression(isolate), | 1442 : Expression(isolate), |
| 1382 op_(op), | 1443 op_(op), |
| 1383 expression_(expression), | 1444 expression_(expression), |
| 1384 pos_(pos), | 1445 pos_(pos), |
| 1385 materialize_true_id_(AstNode::kNoNumber), | 1446 materialize_true_id_(AstNode::kNoNumber), |
| 1386 materialize_false_id_(AstNode::kNoNumber) { | 1447 materialize_false_id_(AstNode::kNoNumber) { |
| 1387 ASSERT(Token::IsUnaryOp(op)); | 1448 ASSERT(Token::IsUnaryOp(op)); |
| 1388 if (op == Token::NOT) { | 1449 if (op == Token::NOT) { |
| 1389 materialize_true_id_ = GetNextId(isolate); | 1450 materialize_true_id_ = GetNextId(isolate); |
| 1390 materialize_false_id_ = GetNextId(isolate); | 1451 materialize_false_id_ = GetNextId(isolate); |
| 1391 } | 1452 } |
| 1392 } | 1453 } |
| 1393 | 1454 |
| 1394 DECLARE_NODE_TYPE(UnaryOperation) | |
| 1395 | |
| 1396 virtual bool IsInlineable() const; | |
| 1397 | |
| 1398 virtual bool ResultOverwriteAllowed(); | |
| 1399 | |
| 1400 Token::Value op() const { return op_; } | |
| 1401 Expression* expression() const { return expression_; } | |
| 1402 virtual int position() const { return pos_; } | |
| 1403 | |
| 1404 int MaterializeTrueId() { return materialize_true_id_; } | |
| 1405 int MaterializeFalseId() { return materialize_false_id_; } | |
| 1406 | |
| 1407 private: | 1455 private: |
| 1408 Token::Value op_; | 1456 Token::Value op_; |
| 1409 Expression* expression_; | 1457 Expression* expression_; |
| 1410 int pos_; | 1458 int pos_; |
| 1411 | 1459 |
| 1412 // For unary not (Token::NOT), the AST ids where true and false will | 1460 // For unary not (Token::NOT), the AST ids where true and false will |
| 1413 // actually be materialized, respectively. | 1461 // actually be materialized, respectively. |
| 1414 int materialize_true_id_; | 1462 int materialize_true_id_; |
| 1415 int materialize_false_id_; | 1463 int materialize_false_id_; |
| 1416 }; | 1464 }; |
| 1417 | 1465 |
| 1418 | 1466 |
| 1419 class BinaryOperation: public Expression { | 1467 class BinaryOperation: public Expression { |
| 1420 public: | 1468 public: |
| 1421 BinaryOperation(Isolate* isolate, | |
| 1422 Token::Value op, | |
| 1423 Expression* left, | |
| 1424 Expression* right, | |
| 1425 int pos) | |
| 1426 : Expression(isolate), op_(op), left_(left), right_(right), pos_(pos) { | |
| 1427 ASSERT(Token::IsBinaryOp(op)); | |
| 1428 right_id_ = (op == Token::AND || op == Token::OR) | |
| 1429 ? static_cast<int>(GetNextId(isolate)) | |
| 1430 : AstNode::kNoNumber; | |
| 1431 } | |
| 1432 | |
| 1433 DECLARE_NODE_TYPE(BinaryOperation) | 1469 DECLARE_NODE_TYPE(BinaryOperation) |
| 1434 | 1470 |
| 1435 virtual bool IsInlineable() const; | |
| 1436 | |
| 1437 virtual bool ResultOverwriteAllowed(); | 1471 virtual bool ResultOverwriteAllowed(); |
| 1438 | 1472 |
| 1439 Token::Value op() const { return op_; } | 1473 Token::Value op() const { return op_; } |
| 1440 Expression* left() const { return left_; } | 1474 Expression* left() const { return left_; } |
| 1441 Expression* right() const { return right_; } | 1475 Expression* right() const { return right_; } |
| 1442 virtual int position() const { return pos_; } | 1476 virtual int position() const { return pos_; } |
| 1443 | 1477 |
| 1444 // Bailout support. | 1478 // Bailout support. |
| 1445 int RightId() const { return right_id_; } | 1479 int RightId() const { return right_id_; } |
| 1446 | 1480 |
| 1481 protected: | |
| 1482 friend class AstNodeFactory; | |
| 1483 | |
| 1484 BinaryOperation(Isolate* isolate, | |
| 1485 Token::Value op, | |
| 1486 Expression* left, | |
| 1487 Expression* right, | |
| 1488 int pos) | |
| 1489 : Expression(isolate), op_(op), left_(left), right_(right), pos_(pos) { | |
| 1490 ASSERT(Token::IsBinaryOp(op)); | |
| 1491 right_id_ = (op == Token::AND || op == Token::OR) | |
| 1492 ? static_cast<int>(GetNextId(isolate)) | |
|
fschneider
2012/02/06 14:14:29
GetNextId returns unsigned, yet all ast ids are st
Jakob Kummerow
2012/02/07 12:38:37
Done.
| |
| 1493 : AstNode::kNoNumber; | |
| 1494 } | |
| 1495 | |
| 1447 private: | 1496 private: |
| 1448 Token::Value op_; | 1497 Token::Value op_; |
| 1449 Expression* left_; | 1498 Expression* left_; |
| 1450 Expression* right_; | 1499 Expression* right_; |
| 1451 int pos_; | 1500 int pos_; |
| 1452 // The short-circuit logical operations have an AST ID for their | 1501 // The short-circuit logical operations have an AST ID for their |
| 1453 // right-hand subexpression. | 1502 // right-hand subexpression. |
| 1454 int right_id_; | 1503 int right_id_; |
| 1455 }; | 1504 }; |
| 1456 | 1505 |
| 1457 | 1506 |
| 1458 class CountOperation: public Expression { | 1507 class CountOperation: public Expression { |
| 1459 public: | 1508 public: |
| 1460 CountOperation(Isolate* isolate, | |
| 1461 Token::Value op, | |
| 1462 bool is_prefix, | |
| 1463 Expression* expr, | |
| 1464 int pos) | |
| 1465 : Expression(isolate), | |
| 1466 op_(op), | |
| 1467 is_prefix_(is_prefix), | |
| 1468 expression_(expr), | |
| 1469 pos_(pos), | |
| 1470 assignment_id_(GetNextId(isolate)), | |
| 1471 count_id_(GetNextId(isolate)) {} | |
| 1472 | |
| 1473 DECLARE_NODE_TYPE(CountOperation) | 1509 DECLARE_NODE_TYPE(CountOperation) |
| 1474 | 1510 |
| 1475 bool is_prefix() const { return is_prefix_; } | 1511 bool is_prefix() const { return is_prefix_; } |
| 1476 bool is_postfix() const { return !is_prefix_; } | 1512 bool is_postfix() const { return !is_prefix_; } |
| 1477 | 1513 |
| 1478 Token::Value op() const { return op_; } | 1514 Token::Value op() const { return op_; } |
| 1479 Token::Value binary_op() { | 1515 Token::Value binary_op() { |
| 1480 return (op() == Token::INC) ? Token::ADD : Token::SUB; | 1516 return (op() == Token::INC) ? Token::ADD : Token::SUB; |
| 1481 } | 1517 } |
| 1482 | 1518 |
| 1483 Expression* expression() const { return expression_; } | 1519 Expression* expression() const { return expression_; } |
| 1484 virtual int position() const { return pos_; } | 1520 virtual int position() const { return pos_; } |
| 1485 | 1521 |
| 1486 virtual void MarkAsStatement() { is_prefix_ = true; } | 1522 virtual void MarkAsStatement() { is_prefix_ = true; } |
| 1487 | 1523 |
| 1488 virtual bool IsInlineable() const; | |
| 1489 | |
| 1490 void RecordTypeFeedback(TypeFeedbackOracle* oracle); | 1524 void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
| 1491 virtual bool IsMonomorphic() { return is_monomorphic_; } | 1525 virtual bool IsMonomorphic() { return is_monomorphic_; } |
| 1492 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } | 1526 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } |
| 1493 | 1527 |
| 1494 // Bailout support. | 1528 // Bailout support. |
| 1495 int AssignmentId() const { return assignment_id_; } | 1529 int AssignmentId() const { return assignment_id_; } |
| 1496 int CountId() const { return count_id_; } | 1530 int CountId() const { return count_id_; } |
| 1497 | 1531 |
| 1532 protected: | |
| 1533 friend class AstNodeFactory; | |
| 1534 | |
| 1535 CountOperation(Isolate* isolate, | |
| 1536 Token::Value op, | |
| 1537 bool is_prefix, | |
| 1538 Expression* expr, | |
| 1539 int pos) | |
| 1540 : Expression(isolate), | |
| 1541 op_(op), | |
| 1542 is_prefix_(is_prefix), | |
| 1543 expression_(expr), | |
| 1544 pos_(pos), | |
| 1545 assignment_id_(GetNextId(isolate)), | |
| 1546 count_id_(GetNextId(isolate)) {} | |
| 1547 | |
| 1498 private: | 1548 private: |
| 1499 Token::Value op_; | 1549 Token::Value op_; |
| 1500 bool is_prefix_; | 1550 bool is_prefix_; |
| 1501 bool is_monomorphic_; | 1551 bool is_monomorphic_; |
| 1502 Expression* expression_; | 1552 Expression* expression_; |
| 1503 int pos_; | 1553 int pos_; |
| 1504 int assignment_id_; | 1554 int assignment_id_; |
| 1505 int count_id_; | 1555 int count_id_; |
| 1506 SmallMapList receiver_types_; | 1556 SmallMapList receiver_types_; |
| 1507 }; | 1557 }; |
| 1508 | 1558 |
| 1509 | 1559 |
| 1510 class CompareOperation: public Expression { | 1560 class CompareOperation: public Expression { |
| 1511 public: | 1561 public: |
| 1512 CompareOperation(Isolate* isolate, | |
| 1513 Token::Value op, | |
| 1514 Expression* left, | |
| 1515 Expression* right, | |
| 1516 int pos) | |
| 1517 : Expression(isolate), | |
| 1518 op_(op), | |
| 1519 left_(left), | |
| 1520 right_(right), | |
| 1521 pos_(pos), | |
| 1522 compare_type_(NONE) { | |
| 1523 ASSERT(Token::IsCompareOp(op)); | |
| 1524 } | |
| 1525 | |
| 1526 DECLARE_NODE_TYPE(CompareOperation) | 1562 DECLARE_NODE_TYPE(CompareOperation) |
| 1527 | 1563 |
| 1528 Token::Value op() const { return op_; } | 1564 Token::Value op() const { return op_; } |
| 1529 Expression* left() const { return left_; } | 1565 Expression* left() const { return left_; } |
| 1530 Expression* right() const { return right_; } | 1566 Expression* right() const { return right_; } |
| 1531 virtual int position() const { return pos_; } | 1567 virtual int position() const { return pos_; } |
| 1532 | 1568 |
| 1533 virtual bool IsInlineable() const; | |
| 1534 | |
| 1535 // Type feedback information. | 1569 // Type feedback information. |
| 1536 void RecordTypeFeedback(TypeFeedbackOracle* oracle); | 1570 void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
| 1537 bool IsSmiCompare() { return compare_type_ == SMI_ONLY; } | 1571 bool IsSmiCompare() { return compare_type_ == SMI_ONLY; } |
| 1538 bool IsObjectCompare() { return compare_type_ == OBJECT_ONLY; } | 1572 bool IsObjectCompare() { return compare_type_ == OBJECT_ONLY; } |
| 1539 | 1573 |
| 1540 // Match special cases. | 1574 // Match special cases. |
| 1541 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check); | 1575 bool IsLiteralCompareTypeof(Expression** expr, Handle<String>* check); |
| 1542 bool IsLiteralCompareUndefined(Expression** expr); | 1576 bool IsLiteralCompareUndefined(Expression** expr); |
| 1543 bool IsLiteralCompareNull(Expression** expr); | 1577 bool IsLiteralCompareNull(Expression** expr); |
| 1544 | 1578 |
| 1579 protected: | |
| 1580 friend class AstNodeFactory; | |
| 1581 | |
| 1582 CompareOperation(Isolate* isolate, | |
| 1583 Token::Value op, | |
| 1584 Expression* left, | |
| 1585 Expression* right, | |
| 1586 int pos) | |
| 1587 : Expression(isolate), | |
| 1588 op_(op), | |
| 1589 left_(left), | |
| 1590 right_(right), | |
| 1591 pos_(pos), | |
| 1592 compare_type_(NONE) { | |
| 1593 ASSERT(Token::IsCompareOp(op)); | |
| 1594 } | |
| 1595 | |
| 1545 private: | 1596 private: |
| 1546 Token::Value op_; | 1597 Token::Value op_; |
| 1547 Expression* left_; | 1598 Expression* left_; |
| 1548 Expression* right_; | 1599 Expression* right_; |
| 1549 int pos_; | 1600 int pos_; |
| 1550 | 1601 |
| 1551 enum CompareTypeFeedback { NONE, SMI_ONLY, OBJECT_ONLY }; | 1602 enum CompareTypeFeedback { NONE, SMI_ONLY, OBJECT_ONLY }; |
| 1552 CompareTypeFeedback compare_type_; | 1603 CompareTypeFeedback compare_type_; |
| 1553 }; | 1604 }; |
| 1554 | 1605 |
| 1555 | 1606 |
| 1556 class Conditional: public Expression { | 1607 class Conditional: public Expression { |
| 1557 public: | 1608 public: |
| 1609 DECLARE_NODE_TYPE(Conditional) | |
| 1610 | |
| 1611 Expression* condition() const { return condition_; } | |
| 1612 Expression* then_expression() const { return then_expression_; } | |
| 1613 Expression* else_expression() const { return else_expression_; } | |
| 1614 | |
| 1615 int then_expression_position() const { return then_expression_position_; } | |
| 1616 int else_expression_position() const { return else_expression_position_; } | |
| 1617 | |
| 1618 int ThenId() const { return then_id_; } | |
| 1619 int ElseId() const { return else_id_; } | |
| 1620 | |
| 1621 protected: | |
| 1622 friend class AstNodeFactory; | |
| 1623 | |
| 1558 Conditional(Isolate* isolate, | 1624 Conditional(Isolate* isolate, |
| 1559 Expression* condition, | 1625 Expression* condition, |
| 1560 Expression* then_expression, | 1626 Expression* then_expression, |
| 1561 Expression* else_expression, | 1627 Expression* else_expression, |
| 1562 int then_expression_position, | 1628 int then_expression_position, |
| 1563 int else_expression_position) | 1629 int else_expression_position) |
| 1564 : Expression(isolate), | 1630 : Expression(isolate), |
| 1565 condition_(condition), | 1631 condition_(condition), |
| 1566 then_expression_(then_expression), | 1632 then_expression_(then_expression), |
| 1567 else_expression_(else_expression), | 1633 else_expression_(else_expression), |
| 1568 then_expression_position_(then_expression_position), | 1634 then_expression_position_(then_expression_position), |
| 1569 else_expression_position_(else_expression_position), | 1635 else_expression_position_(else_expression_position), |
| 1570 then_id_(GetNextId(isolate)), | 1636 then_id_(GetNextId(isolate)), |
| 1571 else_id_(GetNextId(isolate)) { | 1637 else_id_(GetNextId(isolate)) { } |
| 1572 } | |
| 1573 | |
| 1574 DECLARE_NODE_TYPE(Conditional) | |
| 1575 | |
| 1576 virtual bool IsInlineable() const; | |
| 1577 | |
| 1578 Expression* condition() const { return condition_; } | |
| 1579 Expression* then_expression() const { return then_expression_; } | |
| 1580 Expression* else_expression() const { return else_expression_; } | |
| 1581 | |
| 1582 int then_expression_position() const { return then_expression_position_; } | |
| 1583 int else_expression_position() const { return else_expression_position_; } | |
| 1584 | |
| 1585 int ThenId() const { return then_id_; } | |
| 1586 int ElseId() const { return else_id_; } | |
| 1587 | 1638 |
| 1588 private: | 1639 private: |
| 1589 Expression* condition_; | 1640 Expression* condition_; |
| 1590 Expression* then_expression_; | 1641 Expression* then_expression_; |
| 1591 Expression* else_expression_; | 1642 Expression* else_expression_; |
| 1592 int then_expression_position_; | 1643 int then_expression_position_; |
| 1593 int else_expression_position_; | 1644 int else_expression_position_; |
| 1594 int then_id_; | 1645 int then_id_; |
| 1595 int else_id_; | 1646 int else_id_; |
| 1596 }; | 1647 }; |
| 1597 | 1648 |
| 1598 | 1649 |
| 1599 class Assignment: public Expression { | 1650 class Assignment: public Expression { |
| 1600 public: | 1651 public: |
| 1601 Assignment(Isolate* isolate, | |
| 1602 Token::Value op, | |
| 1603 Expression* target, | |
| 1604 Expression* value, | |
| 1605 int pos); | |
| 1606 | |
| 1607 DECLARE_NODE_TYPE(Assignment) | 1652 DECLARE_NODE_TYPE(Assignment) |
| 1608 | 1653 |
| 1609 virtual bool IsInlineable() const; | |
| 1610 | |
| 1611 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } | 1654 Assignment* AsSimpleAssignment() { return !is_compound() ? this : NULL; } |
| 1612 | 1655 |
| 1613 Token::Value binary_op() const; | 1656 Token::Value binary_op() const; |
| 1614 | 1657 |
| 1615 Token::Value op() const { return op_; } | 1658 Token::Value op() const { return op_; } |
| 1616 Expression* target() const { return target_; } | 1659 Expression* target() const { return target_; } |
| 1617 Expression* value() const { return value_; } | 1660 Expression* value() const { return value_; } |
| 1618 virtual int position() const { return pos_; } | 1661 virtual int position() const { return pos_; } |
| 1619 BinaryOperation* binary_operation() const { return binary_operation_; } | 1662 BinaryOperation* binary_operation() const { return binary_operation_; } |
| 1620 | 1663 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1632 | 1675 |
| 1633 // Type feedback information. | 1676 // Type feedback information. |
| 1634 void RecordTypeFeedback(TypeFeedbackOracle* oracle); | 1677 void RecordTypeFeedback(TypeFeedbackOracle* oracle); |
| 1635 virtual bool IsMonomorphic() { return is_monomorphic_; } | 1678 virtual bool IsMonomorphic() { return is_monomorphic_; } |
| 1636 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } | 1679 virtual SmallMapList* GetReceiverTypes() { return &receiver_types_; } |
| 1637 | 1680 |
| 1638 // Bailout support. | 1681 // Bailout support. |
| 1639 int CompoundLoadId() const { return compound_load_id_; } | 1682 int CompoundLoadId() const { return compound_load_id_; } |
| 1640 int AssignmentId() const { return assignment_id_; } | 1683 int AssignmentId() const { return assignment_id_; } |
| 1641 | 1684 |
| 1685 protected: | |
| 1686 friend class AstNodeFactory; | |
| 1687 | |
| 1688 Assignment(Isolate* isolate, | |
| 1689 Token::Value op, | |
| 1690 Expression* target, | |
| 1691 Expression* value, | |
| 1692 int pos, | |
| 1693 AstNodeFactory* factory); | |
| 1694 | |
| 1642 private: | 1695 private: |
| 1643 Token::Value op_; | 1696 Token::Value op_; |
| 1644 Expression* target_; | 1697 Expression* target_; |
| 1645 Expression* value_; | 1698 Expression* value_; |
| 1646 int pos_; | 1699 int pos_; |
| 1647 BinaryOperation* binary_operation_; | 1700 BinaryOperation* binary_operation_; |
| 1648 int compound_load_id_; | 1701 int compound_load_id_; |
| 1649 int assignment_id_; | 1702 int assignment_id_; |
| 1650 | 1703 |
| 1651 bool block_start_; | 1704 bool block_start_; |
| 1652 bool block_end_; | 1705 bool block_end_; |
| 1653 | 1706 |
| 1654 bool is_monomorphic_; | 1707 bool is_monomorphic_; |
| 1655 SmallMapList receiver_types_; | 1708 SmallMapList receiver_types_; |
| 1656 }; | 1709 }; |
| 1657 | 1710 |
| 1658 | 1711 |
| 1659 class Throw: public Expression { | 1712 class Throw: public Expression { |
| 1660 public: | 1713 public: |
| 1661 Throw(Isolate* isolate, Expression* exception, int pos) | |
| 1662 : Expression(isolate), exception_(exception), pos_(pos) {} | |
| 1663 | |
| 1664 DECLARE_NODE_TYPE(Throw) | 1714 DECLARE_NODE_TYPE(Throw) |
| 1665 | 1715 |
| 1666 Expression* exception() const { return exception_; } | 1716 Expression* exception() const { return exception_; } |
| 1667 virtual int position() const { return pos_; } | 1717 virtual int position() const { return pos_; } |
| 1668 virtual bool IsInlineable() const; | 1718 |
| 1719 protected: | |
| 1720 friend class AstNodeFactory; | |
| 1721 | |
| 1722 Throw(Isolate* isolate, Expression* exception, int pos) | |
| 1723 : Expression(isolate), exception_(exception), pos_(pos) {} | |
| 1669 | 1724 |
| 1670 private: | 1725 private: |
| 1671 Expression* exception_; | 1726 Expression* exception_; |
| 1672 int pos_; | 1727 int pos_; |
| 1673 }; | 1728 }; |
| 1674 | 1729 |
| 1675 | 1730 |
| 1676 class FunctionLiteral: public Expression { | 1731 class FunctionLiteral: public Expression { |
| 1677 public: | 1732 public: |
| 1678 enum Type { | 1733 enum Type { |
| 1679 ANONYMOUS_EXPRESSION, | 1734 ANONYMOUS_EXPRESSION, |
| 1680 NAMED_EXPRESSION, | 1735 NAMED_EXPRESSION, |
| 1681 DECLARATION | 1736 DECLARATION |
| 1682 }; | 1737 }; |
| 1683 | 1738 |
| 1684 FunctionLiteral(Isolate* isolate, | |
| 1685 Handle<String> name, | |
| 1686 Scope* scope, | |
| 1687 ZoneList<Statement*>* body, | |
| 1688 int materialized_literal_count, | |
| 1689 int expected_property_count, | |
| 1690 int handler_count, | |
| 1691 bool has_only_simple_this_property_assignments, | |
| 1692 Handle<FixedArray> this_property_assignments, | |
| 1693 int parameter_count, | |
| 1694 Type type, | |
| 1695 bool has_duplicate_parameters) | |
| 1696 : Expression(isolate), | |
| 1697 name_(name), | |
| 1698 scope_(scope), | |
| 1699 body_(body), | |
| 1700 this_property_assignments_(this_property_assignments), | |
| 1701 inferred_name_(isolate->factory()->empty_string()), | |
| 1702 materialized_literal_count_(materialized_literal_count), | |
| 1703 expected_property_count_(expected_property_count), | |
| 1704 handler_count_(handler_count), | |
| 1705 parameter_count_(parameter_count), | |
| 1706 function_token_position_(RelocInfo::kNoPosition) { | |
| 1707 bitfield_ = | |
| 1708 HasOnlySimpleThisPropertyAssignments::encode( | |
| 1709 has_only_simple_this_property_assignments) | | |
| 1710 IsExpression::encode(type != DECLARATION) | | |
| 1711 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) | | |
| 1712 Pretenure::encode(false) | | |
| 1713 HasDuplicateParameters::encode(has_duplicate_parameters); | |
| 1714 } | |
| 1715 | |
| 1716 DECLARE_NODE_TYPE(FunctionLiteral) | 1739 DECLARE_NODE_TYPE(FunctionLiteral) |
| 1717 | 1740 |
| 1718 Handle<String> name() const { return name_; } | 1741 Handle<String> name() const { return name_; } |
| 1719 Scope* scope() const { return scope_; } | 1742 Scope* scope() const { return scope_; } |
| 1720 ZoneList<Statement*>* body() const { return body_; } | 1743 ZoneList<Statement*>* body() const { return body_; } |
| 1721 void set_function_token_position(int pos) { function_token_position_ = pos; } | 1744 void set_function_token_position(int pos) { function_token_position_ = pos; } |
| 1722 int function_token_position() const { return function_token_position_; } | 1745 int function_token_position() const { return function_token_position_; } |
| 1723 int start_position() const; | 1746 int start_position() const; |
| 1724 int end_position() const; | 1747 int end_position() const; |
| 1725 bool is_expression() const { return IsExpression::decode(bitfield_); } | 1748 bool is_expression() const { return IsExpression::decode(bitfield_); } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1745 return inferred_name(); | 1768 return inferred_name(); |
| 1746 } | 1769 } |
| 1747 | 1770 |
| 1748 Handle<String> inferred_name() const { return inferred_name_; } | 1771 Handle<String> inferred_name() const { return inferred_name_; } |
| 1749 void set_inferred_name(Handle<String> inferred_name) { | 1772 void set_inferred_name(Handle<String> inferred_name) { |
| 1750 inferred_name_ = inferred_name; | 1773 inferred_name_ = inferred_name; |
| 1751 } | 1774 } |
| 1752 | 1775 |
| 1753 bool pretenure() { return Pretenure::decode(bitfield_); } | 1776 bool pretenure() { return Pretenure::decode(bitfield_); } |
| 1754 void set_pretenure() { bitfield_ |= Pretenure::encode(true); } | 1777 void set_pretenure() { bitfield_ |= Pretenure::encode(true); } |
| 1755 virtual bool IsInlineable() const; | |
| 1756 | 1778 |
| 1757 bool has_duplicate_parameters() { | 1779 bool has_duplicate_parameters() { |
| 1758 return HasDuplicateParameters::decode(bitfield_); | 1780 return HasDuplicateParameters::decode(bitfield_); |
| 1759 } | 1781 } |
| 1760 | 1782 |
| 1783 bool ShouldSelfOptimize(); | |
| 1784 int AstNodeCount(); | |
| 1785 AstProperties* ast_properties() { return ast_properties_; } | |
| 1786 void set_ast_properties(AstProperties* ast_properties) { | |
| 1787 ast_properties_ = ast_properties; | |
| 1788 } | |
| 1789 | |
| 1790 protected: | |
| 1791 friend class AstNodeFactory; | |
| 1792 | |
| 1793 FunctionLiteral(Isolate* isolate, | |
| 1794 Handle<String> name, | |
| 1795 Scope* scope, | |
| 1796 ZoneList<Statement*>* body, | |
| 1797 int materialized_literal_count, | |
| 1798 int expected_property_count, | |
| 1799 int handler_count, | |
| 1800 bool has_only_simple_this_property_assignments, | |
| 1801 Handle<FixedArray> this_property_assignments, | |
| 1802 int parameter_count, | |
| 1803 Type type, | |
| 1804 bool has_duplicate_parameters) | |
| 1805 : Expression(isolate), | |
| 1806 name_(name), | |
| 1807 scope_(scope), | |
| 1808 body_(body), | |
| 1809 this_property_assignments_(this_property_assignments), | |
| 1810 inferred_name_(isolate->factory()->empty_string()), | |
| 1811 ast_properties_(NULL), | |
| 1812 materialized_literal_count_(materialized_literal_count), | |
| 1813 expected_property_count_(expected_property_count), | |
| 1814 handler_count_(handler_count), | |
| 1815 parameter_count_(parameter_count), | |
| 1816 function_token_position_(RelocInfo::kNoPosition) { | |
| 1817 bitfield_ = | |
| 1818 HasOnlySimpleThisPropertyAssignments::encode( | |
| 1819 has_only_simple_this_property_assignments) | | |
| 1820 IsExpression::encode(type != DECLARATION) | | |
| 1821 IsAnonymous::encode(type == ANONYMOUS_EXPRESSION) | | |
| 1822 Pretenure::encode(false) | | |
| 1823 HasDuplicateParameters::encode(has_duplicate_parameters); | |
| 1824 } | |
| 1825 | |
| 1761 private: | 1826 private: |
| 1762 Handle<String> name_; | 1827 Handle<String> name_; |
| 1763 Scope* scope_; | 1828 Scope* scope_; |
| 1764 ZoneList<Statement*>* body_; | 1829 ZoneList<Statement*>* body_; |
| 1765 Handle<FixedArray> this_property_assignments_; | 1830 Handle<FixedArray> this_property_assignments_; |
| 1766 Handle<String> inferred_name_; | 1831 Handle<String> inferred_name_; |
| 1832 AstProperties* ast_properties_; | |
| 1767 | 1833 |
| 1768 int materialized_literal_count_; | 1834 int materialized_literal_count_; |
| 1769 int expected_property_count_; | 1835 int expected_property_count_; |
| 1770 int handler_count_; | 1836 int handler_count_; |
| 1771 int parameter_count_; | 1837 int parameter_count_; |
| 1772 int function_token_position_; | 1838 int function_token_position_; |
| 1773 | 1839 |
| 1774 unsigned bitfield_; | 1840 unsigned bitfield_; |
| 1775 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {}; | 1841 class HasOnlySimpleThisPropertyAssignments: public BitField<bool, 0, 1> {}; |
| 1776 class IsExpression: public BitField<bool, 1, 1> {}; | 1842 class IsExpression: public BitField<bool, 1, 1> {}; |
| 1777 class IsAnonymous: public BitField<bool, 2, 1> {}; | 1843 class IsAnonymous: public BitField<bool, 2, 1> {}; |
| 1778 class Pretenure: public BitField<bool, 3, 1> {}; | 1844 class Pretenure: public BitField<bool, 3, 1> {}; |
| 1779 class HasDuplicateParameters: public BitField<bool, 4, 1> {}; | 1845 class HasDuplicateParameters: public BitField<bool, 4, 1> {}; |
| 1780 }; | 1846 }; |
| 1781 | 1847 |
| 1782 | 1848 |
| 1783 class SharedFunctionInfoLiteral: public Expression { | 1849 class SharedFunctionInfoLiteral: public Expression { |
| 1784 public: | 1850 public: |
| 1785 SharedFunctionInfoLiteral( | |
| 1786 Isolate* isolate, | |
| 1787 Handle<SharedFunctionInfo> shared_function_info) | |
| 1788 : Expression(isolate), shared_function_info_(shared_function_info) { } | |
| 1789 | |
| 1790 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) | 1851 DECLARE_NODE_TYPE(SharedFunctionInfoLiteral) |
| 1791 | 1852 |
| 1792 Handle<SharedFunctionInfo> shared_function_info() const { | 1853 Handle<SharedFunctionInfo> shared_function_info() const { |
| 1793 return shared_function_info_; | 1854 return shared_function_info_; |
| 1794 } | 1855 } |
| 1795 virtual bool IsInlineable() const; | 1856 |
| 1857 protected: | |
| 1858 friend class AstNodeFactory; | |
| 1859 | |
| 1860 SharedFunctionInfoLiteral( | |
| 1861 Isolate* isolate, | |
| 1862 Handle<SharedFunctionInfo> shared_function_info) | |
| 1863 : Expression(isolate), | |
| 1864 shared_function_info_(shared_function_info) { } | |
| 1796 | 1865 |
| 1797 private: | 1866 private: |
| 1798 Handle<SharedFunctionInfo> shared_function_info_; | 1867 Handle<SharedFunctionInfo> shared_function_info_; |
| 1799 }; | 1868 }; |
| 1800 | 1869 |
| 1801 | 1870 |
| 1802 class ThisFunction: public Expression { | 1871 class ThisFunction: public Expression { |
| 1803 public: | 1872 public: |
| 1804 explicit ThisFunction(Isolate* isolate) : Expression(isolate) {} | |
| 1805 DECLARE_NODE_TYPE(ThisFunction) | 1873 DECLARE_NODE_TYPE(ThisFunction) |
| 1806 virtual bool IsInlineable() const; | 1874 |
| 1875 protected: | |
| 1876 friend class AstNodeFactory; | |
| 1877 | |
| 1878 explicit ThisFunction(Isolate* isolate): Expression(isolate) {} | |
| 1807 }; | 1879 }; |
| 1808 | 1880 |
| 1809 | 1881 |
| 1810 // ---------------------------------------------------------------------------- | 1882 // ---------------------------------------------------------------------------- |
| 1811 // Regular expressions | 1883 // Regular expressions |
| 1812 | 1884 |
| 1813 | 1885 |
| 1814 class RegExpVisitor BASE_EMBEDDED { | 1886 class RegExpVisitor BASE_EMBEDDED { |
| 1815 public: | 1887 public: |
| 1816 virtual ~RegExpVisitor() { } | 1888 virtual ~RegExpVisitor() { } |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2200 | 2272 |
| 2201 protected: | 2273 protected: |
| 2202 Isolate* isolate() { return isolate_; } | 2274 Isolate* isolate() { return isolate_; } |
| 2203 | 2275 |
| 2204 private: | 2276 private: |
| 2205 Isolate* isolate_; | 2277 Isolate* isolate_; |
| 2206 bool stack_overflow_; | 2278 bool stack_overflow_; |
| 2207 }; | 2279 }; |
| 2208 | 2280 |
| 2209 | 2281 |
| 2282 // ---------------------------------------------------------------------------- | |
| 2283 // Construction time visitor. | |
| 2284 | |
| 2285 enum AstPropertiesFlag { | |
| 2286 kDontCrankshaft, | |
| 2287 kDontInline, | |
| 2288 kDontSelfOptimize, | |
| 2289 kDontSoftInline | |
| 2290 }; | |
| 2291 | |
| 2292 | |
| 2293 class AstProperties : public ZoneObject { | |
| 2294 public: | |
| 2295 class Flags : public EnumSet<AstPropertiesFlag, int> {}; | |
| 2296 | |
| 2297 AstProperties() : node_count_(0) { } | |
| 2298 virtual ~AstProperties() { } | |
| 2299 | |
| 2300 Flags* flags() { return &flags_; } | |
| 2301 int node_count() { return node_count_; } | |
| 2302 void add_node_count(int count) { node_count_ += count; } | |
| 2303 | |
| 2304 private: | |
| 2305 Flags flags_; | |
| 2306 int node_count_; | |
| 2307 | |
| 2308 DISALLOW_COPY_AND_ASSIGN(AstProperties); | |
| 2309 }; | |
| 2310 | |
| 2311 | |
| 2312 class AstConstructionVisitor : public AstVisitor { | |
| 2313 public: | |
| 2314 explicit AstConstructionVisitor(Zone* zone) | |
| 2315 : node_count_(0), | |
| 2316 properties_(new(zone) AstProperties()) { } | |
| 2317 virtual ~AstConstructionVisitor() {} | |
| 2318 | |
| 2319 void set_ast_properties(AstProperties* properties) { | |
| 2320 properties_ = properties; | |
| 2321 } | |
| 2322 AstProperties* DetachAstProperties(); | |
|
Kevin Millikin (Chromium)
2012/02/06 15:14:23
I don't understand why the AstProperties ownership
Jakob Kummerow
2012/02/07 12:38:37
Done.
| |
| 2323 | |
| 2324 private: | |
| 2325 friend class AstNodeFactory; | |
| 2326 | |
| 2327 // Node visitors. | |
| 2328 #define DEF_VISIT(type) \ | |
| 2329 virtual void Visit##type(type* node); | |
|
fschneider
2012/02/06 14:14:29
It seems that none of the functions actually recur
Jakob Kummerow
2012/02/07 12:38:37
Done.
| |
| 2330 AST_NODE_LIST(DEF_VISIT) | |
| 2331 #undef DEF_VISIT | |
| 2332 | |
| 2333 void increase_node_count() { node_count_++; } | |
| 2334 void add_flag(AstPropertiesFlag flag) { flags_.Add(flag); } | |
| 2335 | |
| 2336 AstProperties::Flags flags_; | |
| 2337 int node_count_; | |
| 2338 | |
| 2339 // Non-owning pointer to the AstProperties object that will eventually | |
| 2340 // hold the results; is passed to VariableProxies upon their construction | |
|
fschneider
2012/02/06 14:14:29
Comment outdated? VariableProxies don't update the
Jakob Kummerow
2012/02/07 12:38:37
Done.
| |
| 2341 // because they need to fill in more information later. | |
| 2342 AstProperties* properties_; | |
| 2343 }; | |
| 2344 | |
| 2345 | |
| 2346 | |
| 2347 // ---------------------------------------------------------------------------- | |
| 2348 // AstNode factory | |
| 2349 | |
| 2350 class AstNodeFactory BASE_EMBEDDED { | |
| 2351 public: | |
| 2352 AstNodeFactory(Isolate* isolate, | |
| 2353 Zone* zone = NULL, | |
| 2354 AstConstructionVisitor* visitor = NULL) | |
| 2355 : isolate_(isolate), | |
| 2356 zone_(zone), | |
|
fschneider
2012/02/06 14:14:29
Maybe simplify initialization to:
zone_(zone != N
Kevin Millikin (Chromium)
2012/02/06 15:14:23
Since every call (that I could find) does not pass
Jakob Kummerow
2012/02/07 12:38:37
Obsolete -- see Kevin's comment.
Jakob Kummerow
2012/02/07 12:38:37
Done.
| |
| 2357 visitor_(visitor) { | |
| 2358 if (zone == NULL) { | |
| 2359 zone_ = isolate_->zone(); | |
| 2360 } | |
| 2361 } | |
| 2362 | |
| 2363 AstConstructionVisitor* visitor() { return visitor_; } | |
| 2364 void set_visitor(AstConstructionVisitor* visitor) { | |
| 2365 visitor_ = visitor; | |
| 2366 } | |
| 2367 | |
| 2368 #define VISIT_AND_RETURN(NodeType, node) \ | |
| 2369 if (visitor_ != NULL) { \ | |
| 2370 visitor_->Visit##NodeType(node); \ | |
|
fschneider
2012/02/06 14:14:29
Suggestion for further optimization:
If the visit
Kevin Millikin (Chromium)
2012/02/06 15:14:23
Possibly:
visitor_->Visit##NodeType((node));
to
Jakob Kummerow
2012/02/07 12:38:37
Done.
Jakob Kummerow
2012/02/07 12:38:37
Done.
| |
| 2371 } \ | |
| 2372 return node; | |
| 2373 | |
| 2374 Block* NewBlock(ZoneStringList* labels, | |
| 2375 int capacity, | |
| 2376 bool is_initializer_block) { | |
| 2377 Block* block = new(zone_) Block( | |
| 2378 isolate_, labels, capacity, is_initializer_block); | |
| 2379 VISIT_AND_RETURN(Block, block) | |
| 2380 } | |
| 2381 | |
| 2382 Declaration* NewDeclaration(VariableProxy* proxy, | |
| 2383 VariableMode mode, | |
| 2384 FunctionLiteral* fun, | |
| 2385 Scope* scope) { | |
| 2386 Declaration* decl = new(zone_) Declaration(proxy, mode, fun, scope); | |
| 2387 VISIT_AND_RETURN(Declaration, decl) | |
| 2388 } | |
| 2389 | |
| 2390 #define ITERATION_STATEMENT(NodeType) \ | |
| 2391 NodeType* New##NodeType(ZoneStringList* labels) { \ | |
| 2392 NodeType* stmt = new(zone_) NodeType(isolate_, labels); \ | |
| 2393 VISIT_AND_RETURN(NodeType, stmt); \ | |
| 2394 } | |
| 2395 ITERATION_STATEMENT(DoWhileStatement) | |
| 2396 ITERATION_STATEMENT(WhileStatement) | |
| 2397 ITERATION_STATEMENT(ForStatement) | |
| 2398 ITERATION_STATEMENT(ForInStatement) | |
| 2399 ITERATION_STATEMENT(SwitchStatement) | |
|
Kevin Millikin (Chromium)
2012/02/06 15:14:23
Switch is not iteration, so this is probably a bad
Jakob Kummerow
2012/02/07 12:38:37
Done.
| |
| 2400 #undef ITERATION_STATEMENT | |
| 2401 | |
| 2402 ExpressionStatement* NewExpressionStatement(Expression* expression) { | |
| 2403 ExpressionStatement* stmt = new(zone_) ExpressionStatement(expression); | |
| 2404 VISIT_AND_RETURN(ExpressionStatement, stmt) | |
| 2405 } | |
| 2406 | |
| 2407 ContinueStatement* NewContinueStatement(IterationStatement* target) { | |
| 2408 ContinueStatement* stmt = new(zone_) ContinueStatement(target); | |
| 2409 VISIT_AND_RETURN(ContinueStatement, stmt) | |
| 2410 } | |
| 2411 | |
| 2412 BreakStatement* NewBreakStatement(BreakableStatement* target) { | |
| 2413 BreakStatement* stmt = new(zone_) BreakStatement(target); | |
| 2414 VISIT_AND_RETURN(BreakStatement, stmt) | |
| 2415 } | |
| 2416 | |
| 2417 ReturnStatement* NewReturnStatement(Expression* expression) { | |
| 2418 ReturnStatement* stmt = new(zone_) ReturnStatement(expression); | |
| 2419 VISIT_AND_RETURN(ReturnStatement, stmt) | |
| 2420 } | |
| 2421 | |
| 2422 WithStatement* NewWithStatement(Expression* expression, | |
| 2423 Statement* statement) { | |
| 2424 WithStatement* stmt = new(zone_) WithStatement(expression, statement); | |
| 2425 VISIT_AND_RETURN(WithStatement, stmt) | |
| 2426 } | |
| 2427 | |
| 2428 IfStatement* NewIfStatement(Expression* condition, | |
| 2429 Statement* then_statement, | |
| 2430 Statement* else_statement) { | |
| 2431 IfStatement* stmt = new(zone_) IfStatement( | |
| 2432 isolate_, condition, then_statement, else_statement); | |
| 2433 VISIT_AND_RETURN(IfStatement, stmt) | |
| 2434 } | |
| 2435 | |
| 2436 TryCatchStatement* NewTryCatchStatement(int index, | |
| 2437 Block* try_block, | |
| 2438 Scope* scope, | |
| 2439 Variable* variable, | |
| 2440 Block* catch_block) { | |
| 2441 TryCatchStatement* stmt = new(zone_) TryCatchStatement( | |
| 2442 index, try_block, scope, variable, catch_block); | |
| 2443 VISIT_AND_RETURN(TryCatchStatement, stmt) | |
| 2444 } | |
| 2445 | |
| 2446 TryFinallyStatement* NewTryFinallyStatement(int index, | |
| 2447 Block* try_block, | |
| 2448 Block* finally_block) { | |
| 2449 TryFinallyStatement* stmt = | |
| 2450 new(zone_) TryFinallyStatement(index, try_block, finally_block); | |
| 2451 VISIT_AND_RETURN(TryFinallyStatement, stmt) | |
| 2452 } | |
| 2453 | |
| 2454 DebuggerStatement* NewDebuggerStatement() { | |
| 2455 DebuggerStatement* stmt = new(zone_) DebuggerStatement(); | |
| 2456 VISIT_AND_RETURN(DebuggerStatement, stmt) | |
| 2457 } | |
| 2458 | |
| 2459 EmptyStatement* NewEmptyStatement() { | |
| 2460 static EmptyStatement* empty = ::new EmptyStatement(); | |
|
Kevin Millikin (Chromium)
2012/02/06 15:14:23
It seems wrong to have this singleton empty statem
Jakob Kummerow
2012/02/07 12:38:37
Done.
| |
| 2461 return empty; | |
| 2462 } | |
| 2463 | |
| 2464 Literal* NewLiteral(Handle<Object> handle) { | |
| 2465 Literal* lit = new(zone_) Literal(isolate_, handle); | |
| 2466 VISIT_AND_RETURN(Literal, lit) | |
| 2467 } | |
| 2468 | |
| 2469 Literal* NewNumberLiteral(double number) { | |
| 2470 return NewLiteral(isolate_->factory()->NewNumber(number, TENURED)); | |
| 2471 } | |
| 2472 | |
| 2473 ObjectLiteral* NewObjectLiteral( | |
| 2474 Handle<FixedArray> constant_properties, | |
| 2475 ZoneList<ObjectLiteral::Property*>* properties, | |
| 2476 int literal_index, | |
| 2477 bool is_simple, | |
| 2478 bool fast_elements, | |
| 2479 int depth, | |
| 2480 bool has_function) { | |
| 2481 ObjectLiteral* lit = new(zone_) ObjectLiteral( | |
| 2482 isolate_, constant_properties, properties, literal_index, | |
| 2483 is_simple, fast_elements, depth, has_function); | |
| 2484 VISIT_AND_RETURN(ObjectLiteral, lit) | |
| 2485 } | |
| 2486 | |
| 2487 RegExpLiteral* NewRegExpLiteral(Handle<String> pattern, | |
| 2488 Handle<String> flags, | |
| 2489 int literal_index) { | |
| 2490 RegExpLiteral* lit = | |
| 2491 new(zone_) RegExpLiteral(isolate_, pattern, flags, literal_index); | |
| 2492 VISIT_AND_RETURN(RegExpLiteral, lit); | |
| 2493 } | |
| 2494 | |
| 2495 ArrayLiteral* NewArrayLiteral(Handle<FixedArray> constant_elements, | |
| 2496 ZoneList<Expression*>* values, | |
| 2497 int literal_index, | |
| 2498 bool is_simple, | |
| 2499 int depth) { | |
| 2500 ArrayLiteral* lit = new(zone_) ArrayLiteral( | |
| 2501 isolate_, constant_elements, values, literal_index, is_simple, depth); | |
| 2502 VISIT_AND_RETURN(ArrayLiteral, lit) | |
| 2503 } | |
| 2504 | |
| 2505 VariableProxy* NewVariableProxy(Variable* var) { | |
| 2506 VariableProxy* proxy = new(zone_) VariableProxy(isolate_, var); | |
| 2507 VISIT_AND_RETURN(VariableProxy, proxy) | |
| 2508 } | |
| 2509 | |
| 2510 VariableProxy* NewVariableProxy(Handle<String> name, | |
| 2511 bool is_this, | |
| 2512 int position = RelocInfo::kNoPosition) { | |
| 2513 VariableProxy* proxy = | |
| 2514 new(zone_) VariableProxy(isolate_, name, is_this, position); | |
| 2515 VISIT_AND_RETURN(VariableProxy, proxy) | |
| 2516 } | |
| 2517 | |
| 2518 Property* NewProperty(Expression* obj, Expression* key, int pos) { | |
| 2519 Property* prop = new(zone_) Property(isolate_, obj, key, pos); | |
| 2520 VISIT_AND_RETURN(Property, prop) | |
| 2521 } | |
| 2522 | |
| 2523 Call* NewCall(Expression* expression, | |
| 2524 ZoneList<Expression*>* arguments, | |
| 2525 int pos) { | |
| 2526 Call* call = new(zone_) Call(isolate_, expression, arguments, pos); | |
| 2527 VISIT_AND_RETURN(Call, call) | |
| 2528 } | |
| 2529 | |
| 2530 CallNew* NewCallNew(Expression* expression, | |
| 2531 ZoneList<Expression*>* arguments, | |
| 2532 int pos) { | |
| 2533 CallNew* call = new(zone_) CallNew(isolate_, expression, arguments, pos); | |
| 2534 VISIT_AND_RETURN(CallNew, call) | |
| 2535 } | |
| 2536 | |
| 2537 CallRuntime* NewCallRuntime(Handle<String> name, | |
| 2538 const Runtime::Function* function, | |
| 2539 ZoneList<Expression*>* arguments) { | |
| 2540 CallRuntime* call = | |
| 2541 new(zone_) CallRuntime(isolate_, name, function, arguments); | |
| 2542 VISIT_AND_RETURN(CallRuntime, call) | |
| 2543 } | |
| 2544 | |
| 2545 UnaryOperation* NewUnaryOperation(Token::Value op, | |
| 2546 Expression* expression, | |
| 2547 int pos) { | |
| 2548 UnaryOperation* node = | |
| 2549 new(zone_) UnaryOperation(isolate_, op, expression, pos); | |
| 2550 VISIT_AND_RETURN(UnaryOperation, node) | |
| 2551 } | |
| 2552 | |
| 2553 BinaryOperation* NewBinaryOperation(Token::Value op, | |
| 2554 Expression* left, | |
| 2555 Expression* right, | |
| 2556 int pos) { | |
| 2557 BinaryOperation* node = | |
| 2558 new(zone_) BinaryOperation(isolate_, op, left, right, pos); | |
| 2559 VISIT_AND_RETURN(BinaryOperation, node) | |
| 2560 } | |
| 2561 | |
| 2562 CountOperation* NewCountOperation(Token::Value op, | |
| 2563 bool is_prefix, | |
| 2564 Expression* expr, | |
| 2565 int pos) { | |
| 2566 CountOperation* node = | |
| 2567 new(zone_) CountOperation(isolate_, op, is_prefix, expr, pos); | |
| 2568 VISIT_AND_RETURN(CountOperation, node) | |
| 2569 } | |
| 2570 | |
| 2571 CompareOperation* NewCompareOperation(Token::Value op, | |
| 2572 Expression* left, | |
| 2573 Expression* right, | |
| 2574 int pos) { | |
| 2575 CompareOperation* node = | |
| 2576 new(zone_) CompareOperation(isolate_, op, left, right, pos); | |
| 2577 VISIT_AND_RETURN(CompareOperation, node) | |
| 2578 } | |
| 2579 | |
| 2580 Conditional* NewConditional(Expression* condition, | |
| 2581 Expression* then_expression, | |
| 2582 Expression* else_expression, | |
| 2583 int then_expression_position, | |
| 2584 int else_expression_position) { | |
| 2585 Conditional* cond = new(zone_) Conditional( | |
| 2586 isolate_, condition, then_expression, else_expression, | |
| 2587 then_expression_position, else_expression_position); | |
| 2588 VISIT_AND_RETURN(Conditional, cond) | |
| 2589 } | |
| 2590 | |
| 2591 Assignment* NewAssignment(Token::Value op, | |
| 2592 Expression* target, | |
| 2593 Expression* value, | |
| 2594 int pos) { | |
| 2595 Assignment* assign = | |
| 2596 new(zone_) Assignment(isolate_, op, target, value, pos, this); | |
| 2597 VISIT_AND_RETURN(Assignment, assign) | |
| 2598 } | |
| 2599 | |
| 2600 Throw* NewThrow(Expression* exception, int pos) { | |
| 2601 Throw* t = new(zone_) Throw(isolate_, exception, pos); | |
| 2602 VISIT_AND_RETURN(Throw, t) | |
| 2603 } | |
| 2604 | |
| 2605 FunctionLiteral* NewFunctionLiteral( | |
| 2606 Handle<String> name, | |
| 2607 Scope* scope, | |
| 2608 ZoneList<Statement*>* body, | |
| 2609 int materialized_literal_count, | |
| 2610 int expected_property_count, | |
| 2611 int handler_count, | |
| 2612 bool has_only_simple_this_property_assignments, | |
| 2613 Handle<FixedArray> this_property_assignments, | |
| 2614 int parameter_count, | |
| 2615 FunctionLiteral::Type type, | |
| 2616 bool has_duplicate_parameters, | |
| 2617 bool visit_with_visitor = true) { | |
|
Kevin Millikin (Chromium)
2012/02/06 15:14:23
No need for default value. Boolean default values
Jakob Kummerow
2012/02/07 12:38:37
Done.
| |
| 2618 FunctionLiteral* lit = new(zone_) FunctionLiteral( | |
| 2619 isolate_, name, scope, body, | |
| 2620 materialized_literal_count, expected_property_count, handler_count, | |
| 2621 has_only_simple_this_property_assignments, this_property_assignments, | |
| 2622 parameter_count, type, has_duplicate_parameters); | |
| 2623 if (visit_with_visitor && visitor_ != NULL) { | |
| 2624 visitor_->VisitFunctionLiteral(lit); | |
| 2625 } | |
| 2626 return lit; | |
| 2627 } | |
| 2628 | |
| 2629 SharedFunctionInfoLiteral* NewSharedFunctionInfoLiteral( | |
| 2630 Handle<SharedFunctionInfo> shared_function_info) { | |
| 2631 SharedFunctionInfoLiteral* lit = | |
| 2632 new(zone_) SharedFunctionInfoLiteral(isolate_, shared_function_info); | |
| 2633 VISIT_AND_RETURN(SharedFunctionInfoLiteral, lit) | |
| 2634 } | |
| 2635 | |
| 2636 ThisFunction* NewThisFunction() { | |
| 2637 ThisFunction* fun = new(zone_) ThisFunction(isolate_); | |
| 2638 VISIT_AND_RETURN(ThisFunction, fun) | |
| 2639 } | |
| 2640 | |
| 2641 #undef VISIT_AND_RETURN | |
| 2642 | |
| 2643 private: | |
| 2644 Isolate* isolate_; | |
| 2645 Zone* zone_; | |
| 2646 AstConstructionVisitor* visitor_; | |
| 2647 }; | |
| 2648 | |
| 2649 | |
| 2210 } } // namespace v8::internal | 2650 } } // namespace v8::internal |
| 2211 | 2651 |
| 2212 #endif // V8_AST_H_ | 2652 #endif // V8_AST_H_ |
| OLD | NEW |