OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/ast.h" | 7 #include "src/ast.h" |
8 #include "src/ast-numbering.h" | 8 #include "src/ast-numbering.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/scopes.h" | 10 #include "src/scopes.h" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 | 14 |
15 | 15 |
16 class AstNumberingVisitor FINAL : public AstVisitor { | 16 class AstNumberingVisitor FINAL : public AstVisitor { |
17 public: | 17 public: |
18 explicit AstNumberingVisitor(Zone* zone) | 18 explicit AstNumberingVisitor(Zone* zone) |
19 : AstVisitor(), | 19 : AstVisitor(), |
20 next_id_(BailoutId::FirstUsable().ToInt()), | 20 next_id_(BailoutId::FirstUsable().ToInt()), |
21 dont_crankshaft_reason_(kNoReason), | 21 dont_crankshaft_reason_(kNoReason), |
22 dont_turbofan_reason_(kNoReason) { | 22 dont_turbofan_reason_(kNoReason) { |
23 InitializeAstVisitor(zone); | 23 InitializeAstVisitor(zone); |
24 } | 24 } |
25 | 25 |
26 void Renumber(FunctionLiteral* node); | 26 bool Renumber(FunctionLiteral* node); |
27 | 27 |
28 private: | 28 private: |
29 // AST node visitor interface. | 29 // AST node visitor interface. |
30 #define DEFINE_VISIT(type) virtual void Visit##type(type* node) OVERRIDE; | 30 #define DEFINE_VISIT(type) virtual void Visit##type(type* node) OVERRIDE; |
31 AST_NODE_LIST(DEFINE_VISIT) | 31 AST_NODE_LIST(DEFINE_VISIT) |
32 #undef DEFINE_VISIT | 32 #undef DEFINE_VISIT |
33 | 33 |
| 34 bool Finish(FunctionLiteral* node); |
| 35 |
34 void VisitStatements(ZoneList<Statement*>* statements) OVERRIDE; | 36 void VisitStatements(ZoneList<Statement*>* statements) OVERRIDE; |
35 void VisitDeclarations(ZoneList<Declaration*>* declarations) OVERRIDE; | 37 void VisitDeclarations(ZoneList<Declaration*>* declarations) OVERRIDE; |
36 void VisitArguments(ZoneList<Expression*>* arguments); | 38 void VisitArguments(ZoneList<Expression*>* arguments); |
37 void VisitObjectLiteralProperty(ObjectLiteralProperty* property); | 39 void VisitObjectLiteralProperty(ObjectLiteralProperty* property); |
38 | 40 |
39 int ReserveIdRange(int n) { | 41 int ReserveIdRange(int n) { |
40 int tmp = next_id_; | 42 int tmp = next_id_; |
41 next_id_ += n; | 43 next_id_ += n; |
42 return tmp; | 44 return tmp; |
43 } | 45 } |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 | 532 |
531 | 533 |
532 void AstNumberingVisitor::VisitFunctionLiteral(FunctionLiteral* node) { | 534 void AstNumberingVisitor::VisitFunctionLiteral(FunctionLiteral* node) { |
533 IncrementNodeCount(); | 535 IncrementNodeCount(); |
534 node->set_base_id(ReserveIdRange(FunctionLiteral::num_ids())); | 536 node->set_base_id(ReserveIdRange(FunctionLiteral::num_ids())); |
535 // We don't recurse into the declarations or body of the function literal: | 537 // We don't recurse into the declarations or body of the function literal: |
536 // you have to separately Renumber() each FunctionLiteral that you compile. | 538 // you have to separately Renumber() each FunctionLiteral that you compile. |
537 } | 539 } |
538 | 540 |
539 | 541 |
540 void AstNumberingVisitor::Renumber(FunctionLiteral* node) { | 542 bool AstNumberingVisitor::Finish(FunctionLiteral* node) { |
541 if (node->scope()->HasIllegalRedeclaration()) { | 543 node->set_ast_properties(&properties_); |
542 node->scope()->VisitIllegalRedeclaration(this); | 544 node->set_dont_optimize_reason(dont_optimize_reason()); |
543 node->set_ast_properties(&properties_); | 545 return !HasStackOverflow(); |
544 return; | 546 } |
| 547 |
| 548 |
| 549 bool AstNumberingVisitor::Renumber(FunctionLiteral* node) { |
| 550 Scope* scope = node->scope(); |
| 551 |
| 552 if (scope->HasIllegalRedeclaration()) { |
| 553 scope->VisitIllegalRedeclaration(this); |
| 554 DisableCrankshaft(kFunctionWithIllegalRedeclaration); |
| 555 return Finish(node); |
| 556 } |
| 557 if (scope->calls_eval()) DisableCrankshaft(kFunctionCallsEval); |
| 558 if (scope->arguments() != NULL && !scope->arguments()->IsStackAllocated()) { |
| 559 DisableCrankshaft(kContextAllocatedArguments); |
545 } | 560 } |
546 | 561 |
547 Scope* scope = node->scope(); | |
548 VisitDeclarations(scope->declarations()); | 562 VisitDeclarations(scope->declarations()); |
549 if (scope->is_function_scope() && scope->function() != NULL) { | 563 if (scope->is_function_scope() && scope->function() != NULL) { |
550 // Visit the name of the named function expression. | 564 // Visit the name of the named function expression. |
551 Visit(scope->function()); | 565 Visit(scope->function()); |
552 } | 566 } |
553 VisitStatements(node->body()); | 567 VisitStatements(node->body()); |
554 | 568 |
555 node->set_ast_properties(&properties_); | 569 return Finish(node); |
556 node->set_dont_optimize_reason(dont_optimize_reason()); | |
557 } | 570 } |
558 | 571 |
559 | 572 |
560 bool AstNumbering::Renumber(FunctionLiteral* function, Zone* zone) { | 573 bool AstNumbering::Renumber(FunctionLiteral* function, Zone* zone) { |
561 AstNumberingVisitor visitor(zone); | 574 AstNumberingVisitor visitor(zone); |
562 visitor.Renumber(function); | 575 return visitor.Renumber(function); |
563 return !visitor.HasStackOverflow(); | |
564 } | 576 } |
565 } | 577 } |
566 } // namespace v8::internal | 578 } // namespace v8::internal |
OLD | NEW |