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/api.h" | 7 #include "src/api.h" |
8 #include "src/ast.h" | 8 #include "src/ast.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 Expression* ParserTraits::MarkExpressionAsAssigned(Expression* expression) { | 407 Expression* ParserTraits::MarkExpressionAsAssigned(Expression* expression) { |
408 VariableProxy* proxy = | 408 VariableProxy* proxy = |
409 expression != NULL ? expression->AsVariableProxy() : NULL; | 409 expression != NULL ? expression->AsVariableProxy() : NULL; |
410 if (proxy != NULL) proxy->set_is_assigned(); | 410 if (proxy != NULL) proxy->set_is_assigned(); |
411 return expression; | 411 return expression; |
412 } | 412 } |
413 | 413 |
414 | 414 |
415 bool ParserTraits::ShortcutNumericLiteralBinaryExpression( | 415 bool ParserTraits::ShortcutNumericLiteralBinaryExpression( |
416 Expression** x, Expression* y, Token::Value op, int pos, | 416 Expression** x, Expression* y, Token::Value op, int pos, |
417 AstNodeFactory<AstConstructionVisitor>* factory) { | 417 AstNodeFactory* factory) { |
418 if ((*x)->AsLiteral() && (*x)->AsLiteral()->raw_value()->IsNumber() && | 418 if ((*x)->AsLiteral() && (*x)->AsLiteral()->raw_value()->IsNumber() && |
419 y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) { | 419 y->AsLiteral() && y->AsLiteral()->raw_value()->IsNumber()) { |
420 double x_val = (*x)->AsLiteral()->raw_value()->AsNumber(); | 420 double x_val = (*x)->AsLiteral()->raw_value()->AsNumber(); |
421 double y_val = y->AsLiteral()->raw_value()->AsNumber(); | 421 double y_val = y->AsLiteral()->raw_value()->AsNumber(); |
422 switch (op) { | 422 switch (op) { |
423 case Token::ADD: | 423 case Token::ADD: |
424 *x = factory->NewNumberLiteral(x_val + y_val, pos); | 424 *x = factory->NewNumberLiteral(x_val + y_val, pos); |
425 return true; | 425 return true; |
426 case Token::SUB: | 426 case Token::SUB: |
427 *x = factory->NewNumberLiteral(x_val - y_val, pos); | 427 *x = factory->NewNumberLiteral(x_val - y_val, pos); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 return true; | 465 return true; |
466 } | 466 } |
467 default: | 467 default: |
468 break; | 468 break; |
469 } | 469 } |
470 } | 470 } |
471 return false; | 471 return false; |
472 } | 472 } |
473 | 473 |
474 | 474 |
475 Expression* ParserTraits::BuildUnaryExpression( | 475 Expression* ParserTraits::BuildUnaryExpression(Expression* expression, |
476 Expression* expression, Token::Value op, int pos, | 476 Token::Value op, int pos, |
477 AstNodeFactory<AstConstructionVisitor>* factory) { | 477 AstNodeFactory* factory) { |
478 DCHECK(expression != NULL); | 478 DCHECK(expression != NULL); |
479 if (expression->IsLiteral()) { | 479 if (expression->IsLiteral()) { |
480 const AstValue* literal = expression->AsLiteral()->raw_value(); | 480 const AstValue* literal = expression->AsLiteral()->raw_value(); |
481 if (op == Token::NOT) { | 481 if (op == Token::NOT) { |
482 // Convert the literal to a boolean condition and negate it. | 482 // Convert the literal to a boolean condition and negate it. |
483 bool condition = literal->BooleanValue(); | 483 bool condition = literal->BooleanValue(); |
484 return factory->NewBooleanLiteral(!condition, pos); | 484 return factory->NewBooleanLiteral(!condition, pos); |
485 } else if (literal->IsNumber()) { | 485 } else if (literal->IsNumber()) { |
486 // Compute some expressions involving only number literals. | 486 // Compute some expressions involving only number literals. |
487 double value = literal->AsNumber(); | 487 double value = literal->AsNumber(); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 DoubleToCString(double_value, Vector<char>(array, arraysize(array))); | 627 DoubleToCString(double_value, Vector<char>(array, arraysize(array))); |
628 return ast_value_factory()->GetOneByteString(string); | 628 return ast_value_factory()->GetOneByteString(string); |
629 } | 629 } |
630 | 630 |
631 | 631 |
632 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { | 632 const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) { |
633 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); | 633 return parser_->scanner()->NextSymbol(parser_->ast_value_factory()); |
634 } | 634 } |
635 | 635 |
636 | 636 |
637 Expression* ParserTraits::ThisExpression( | 637 Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory, |
638 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) { | 638 int pos) { |
639 return factory->NewVariableProxy(scope->receiver(), pos); | 639 return factory->NewVariableProxy(scope->receiver(), pos); |
640 } | 640 } |
641 | 641 |
642 Expression* ParserTraits::SuperReference( | 642 Expression* ParserTraits::SuperReference(Scope* scope, AstNodeFactory* factory, |
643 Scope* scope, AstNodeFactory<AstConstructionVisitor>* factory, int pos) { | 643 int pos) { |
644 return factory->NewSuperReference( | 644 return factory->NewSuperReference( |
645 ThisExpression(scope, factory, pos)->AsVariableProxy(), | 645 ThisExpression(scope, factory, pos)->AsVariableProxy(), |
646 pos); | 646 pos); |
647 } | 647 } |
648 | 648 |
649 Expression* ParserTraits::ClassExpression( | 649 Expression* ParserTraits::ClassExpression( |
650 const AstRawString* name, Expression* extends, Expression* constructor, | 650 const AstRawString* name, Expression* extends, Expression* constructor, |
651 ZoneList<ObjectLiteral::Property*>* properties, int start_position, | 651 ZoneList<ObjectLiteral::Property*>* properties, int start_position, |
652 int end_position, AstNodeFactory<AstConstructionVisitor>* factory) { | 652 int end_position, AstNodeFactory* factory) { |
653 return factory->NewClassLiteral(name, extends, constructor, properties, | 653 return factory->NewClassLiteral(name, extends, constructor, properties, |
654 start_position, end_position); | 654 start_position, end_position); |
655 } | 655 } |
656 | 656 |
657 Literal* ParserTraits::ExpressionFromLiteral( | 657 Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos, |
658 Token::Value token, int pos, | 658 Scanner* scanner, |
659 Scanner* scanner, | 659 AstNodeFactory* factory) { |
660 AstNodeFactory<AstConstructionVisitor>* factory) { | |
661 switch (token) { | 660 switch (token) { |
662 case Token::NULL_LITERAL: | 661 case Token::NULL_LITERAL: |
663 return factory->NewNullLiteral(pos); | 662 return factory->NewNullLiteral(pos); |
664 case Token::TRUE_LITERAL: | 663 case Token::TRUE_LITERAL: |
665 return factory->NewBooleanLiteral(true, pos); | 664 return factory->NewBooleanLiteral(true, pos); |
666 case Token::FALSE_LITERAL: | 665 case Token::FALSE_LITERAL: |
667 return factory->NewBooleanLiteral(false, pos); | 666 return factory->NewBooleanLiteral(false, pos); |
668 case Token::NUMBER: { | 667 case Token::NUMBER: { |
669 double value = scanner->DoubleValue(); | 668 double value = scanner->DoubleValue(); |
670 return factory->NewNumberLiteral(value, pos); | 669 return factory->NewNumberLiteral(value, pos); |
671 } | 670 } |
672 default: | 671 default: |
673 DCHECK(false); | 672 DCHECK(false); |
674 } | 673 } |
675 return NULL; | 674 return NULL; |
676 } | 675 } |
677 | 676 |
678 | 677 |
679 Expression* ParserTraits::ExpressionFromIdentifier( | 678 Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, |
680 const AstRawString* name, int pos, Scope* scope, | 679 int pos, Scope* scope, |
681 AstNodeFactory<AstConstructionVisitor>* factory) { | 680 AstNodeFactory* factory) { |
682 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); | 681 if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name); |
683 // The name may refer to a module instance object, so its type is unknown. | 682 // The name may refer to a module instance object, so its type is unknown. |
684 #ifdef DEBUG | 683 #ifdef DEBUG |
685 if (FLAG_print_interface_details) | 684 if (FLAG_print_interface_details) |
686 PrintF("# Variable %.*s ", name->length(), name->raw_data()); | 685 PrintF("# Variable %.*s ", name->length(), name->raw_data()); |
687 #endif | 686 #endif |
688 Interface* interface = Interface::NewUnknown(parser_->zone()); | 687 Interface* interface = Interface::NewUnknown(parser_->zone()); |
689 return scope->NewUnresolved(factory, name, interface, pos); | 688 return scope->NewUnresolved(factory, name, interface, pos); |
690 } | 689 } |
691 | 690 |
692 | 691 |
693 Expression* ParserTraits::ExpressionFromString( | 692 Expression* ParserTraits::ExpressionFromString(int pos, Scanner* scanner, |
694 int pos, Scanner* scanner, | 693 AstNodeFactory* factory) { |
695 AstNodeFactory<AstConstructionVisitor>* factory) { | |
696 const AstRawString* symbol = GetSymbol(scanner); | 694 const AstRawString* symbol = GetSymbol(scanner); |
697 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); | 695 if (parser_->fni_ != NULL) parser_->fni_->PushLiteralName(symbol); |
698 return factory->NewStringLiteral(symbol, pos); | 696 return factory->NewStringLiteral(symbol, pos); |
699 } | 697 } |
700 | 698 |
701 | 699 |
702 Expression* ParserTraits::GetIterator( | 700 Expression* ParserTraits::GetIterator(Expression* iterable, |
703 Expression* iterable, AstNodeFactory<AstConstructionVisitor>* factory) { | 701 AstNodeFactory* factory) { |
704 Expression* iterator_symbol_literal = | 702 Expression* iterator_symbol_literal = |
705 factory->NewSymbolLiteral("symbolIterator", RelocInfo::kNoPosition); | 703 factory->NewSymbolLiteral("symbolIterator", RelocInfo::kNoPosition); |
706 int pos = iterable->position(); | 704 int pos = iterable->position(); |
707 Expression* prop = | 705 Expression* prop = |
708 factory->NewProperty(iterable, iterator_symbol_literal, pos); | 706 factory->NewProperty(iterable, iterator_symbol_literal, pos); |
709 Zone* zone = parser_->zone(); | 707 Zone* zone = parser_->zone(); |
710 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); | 708 ZoneList<Expression*>* args = new (zone) ZoneList<Expression*>(0, zone); |
711 return factory->NewCall(prop, args, pos); | 709 return factory->NewCall(prop, args, pos); |
712 } | 710 } |
713 | 711 |
714 | 712 |
715 Literal* ParserTraits::GetLiteralTheHole( | 713 Literal* ParserTraits::GetLiteralTheHole(int position, |
716 int position, AstNodeFactory<AstConstructionVisitor>* factory) { | 714 AstNodeFactory* factory) { |
717 return factory->NewTheHoleLiteral(RelocInfo::kNoPosition); | 715 return factory->NewTheHoleLiteral(RelocInfo::kNoPosition); |
718 } | 716 } |
719 | 717 |
720 | 718 |
721 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { | 719 Expression* ParserTraits::ParseV8Intrinsic(bool* ok) { |
722 return parser_->ParseV8Intrinsic(ok); | 720 return parser_->ParseV8Intrinsic(ok); |
723 } | 721 } |
724 | 722 |
725 | 723 |
726 FunctionLiteral* ParserTraits::ParseFunctionLiteral( | 724 FunctionLiteral* ParserTraits::ParseFunctionLiteral( |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 | 868 |
871 // Compute the parsing mode. | 869 // Compute the parsing mode. |
872 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; | 870 Mode mode = (FLAG_lazy && allow_lazy()) ? PARSE_LAZILY : PARSE_EAGERLY; |
873 if (allow_natives_syntax() || extension_ != NULL || | 871 if (allow_natives_syntax() || extension_ != NULL || |
874 (*scope)->is_eval_scope()) { | 872 (*scope)->is_eval_scope()) { |
875 mode = PARSE_EAGERLY; | 873 mode = PARSE_EAGERLY; |
876 } | 874 } |
877 ParsingModeScope parsing_mode(this, mode); | 875 ParsingModeScope parsing_mode(this, mode); |
878 | 876 |
879 // Enters 'scope'. | 877 // Enters 'scope'. |
880 AstNodeFactory<AstConstructionVisitor> function_factory( | 878 AstNodeFactory function_factory(ast_value_factory()); |
881 ast_value_factory()); | |
882 FunctionState function_state(&function_state_, &scope_, *scope, | 879 FunctionState function_state(&function_state_, &scope_, *scope, |
883 &function_factory); | 880 &function_factory); |
884 | 881 |
885 scope_->SetStrictMode(info->strict_mode()); | 882 scope_->SetStrictMode(info->strict_mode()); |
886 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); | 883 ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone()); |
887 bool ok = true; | 884 bool ok = true; |
888 int beg_pos = scanner()->location().beg_pos; | 885 int beg_pos = scanner()->location().beg_pos; |
889 ParseSourceElements(body, Token::EOS, info->is_eval(), true, eval_scope, | 886 ParseSourceElements(body, Token::EOS, info->is_eval(), true, eval_scope, |
890 &ok); | 887 &ok); |
891 | 888 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 | 979 |
983 { | 980 { |
984 // Parse the function literal. | 981 // Parse the function literal. |
985 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); | 982 Scope* scope = NewScope(scope_, GLOBAL_SCOPE); |
986 info()->SetGlobalScope(scope); | 983 info()->SetGlobalScope(scope); |
987 if (!info()->closure().is_null()) { | 984 if (!info()->closure().is_null()) { |
988 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, | 985 scope = Scope::DeserializeScopeChain(info()->closure()->context(), scope, |
989 zone()); | 986 zone()); |
990 } | 987 } |
991 original_scope_ = scope; | 988 original_scope_ = scope; |
992 AstNodeFactory<AstConstructionVisitor> function_factory( | 989 AstNodeFactory function_factory(ast_value_factory()); |
993 ast_value_factory()); | |
994 FunctionState function_state(&function_state_, &scope_, scope, | 990 FunctionState function_state(&function_state_, &scope_, scope, |
995 &function_factory); | 991 &function_factory); |
996 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); | 992 DCHECK(scope->strict_mode() == SLOPPY || info()->strict_mode() == STRICT); |
997 DCHECK(info()->strict_mode() == shared_info->strict_mode()); | 993 DCHECK(info()->strict_mode() == shared_info->strict_mode()); |
998 scope->SetStrictMode(shared_info->strict_mode()); | 994 scope->SetStrictMode(shared_info->strict_mode()); |
999 FunctionLiteral::FunctionType function_type = shared_info->is_expression() | 995 FunctionLiteral::FunctionType function_type = shared_info->is_expression() |
1000 ? (shared_info->is_anonymous() | 996 ? (shared_info->is_anonymous() |
1001 ? FunctionLiteral::ANONYMOUS_EXPRESSION | 997 ? FunctionLiteral::ANONYMOUS_EXPRESSION |
1002 : FunctionLiteral::NAMED_EXPRESSION) | 998 : FunctionLiteral::NAMED_EXPRESSION) |
1003 : FunctionLiteral::DECLARATION; | 999 : FunctionLiteral::DECLARATION; |
(...skipping 2489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3493 int materialized_literal_count = -1; | 3489 int materialized_literal_count = -1; |
3494 int expected_property_count = -1; | 3490 int expected_property_count = -1; |
3495 int handler_count = 0; | 3491 int handler_count = 0; |
3496 FunctionLiteral::ParameterFlag duplicate_parameters = | 3492 FunctionLiteral::ParameterFlag duplicate_parameters = |
3497 FunctionLiteral::kNoDuplicateParameters; | 3493 FunctionLiteral::kNoDuplicateParameters; |
3498 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ | 3494 FunctionLiteral::IsParenthesizedFlag parenthesized = parenthesized_function_ |
3499 ? FunctionLiteral::kIsParenthesized | 3495 ? FunctionLiteral::kIsParenthesized |
3500 : FunctionLiteral::kNotParenthesized; | 3496 : FunctionLiteral::kNotParenthesized; |
3501 // Parse function body. | 3497 // Parse function body. |
3502 { | 3498 { |
3503 AstNodeFactory<AstConstructionVisitor> function_factory( | 3499 AstNodeFactory function_factory(ast_value_factory()); |
3504 ast_value_factory()); | |
3505 FunctionState function_state(&function_state_, &scope_, scope, | 3500 FunctionState function_state(&function_state_, &scope_, scope, |
3506 &function_factory); | 3501 &function_factory); |
3507 scope_->SetScopeName(function_name); | 3502 scope_->SetScopeName(function_name); |
3508 | 3503 |
3509 if (is_generator) { | 3504 if (is_generator) { |
3510 // For generators, allocating variables in contexts is currently a win | 3505 // For generators, allocating variables in contexts is currently a win |
3511 // because it minimizes the work needed to suspend and resume an | 3506 // because it minimizes the work needed to suspend and resume an |
3512 // activation. | 3507 // activation. |
3513 scope_->ForceContextAllocation(); | 3508 scope_->ForceContextAllocation(); |
3514 | 3509 |
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4951 | 4946 |
4952 // We cannot internalize on a background thread; a foreground task will take | 4947 // We cannot internalize on a background thread; a foreground task will take |
4953 // care of calling Parser::Internalize just before compilation. | 4948 // care of calling Parser::Internalize just before compilation. |
4954 | 4949 |
4955 if (compile_options() == ScriptCompiler::kProduceParserCache) { | 4950 if (compile_options() == ScriptCompiler::kProduceParserCache) { |
4956 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); | 4951 if (result != NULL) *info_->cached_data() = recorder.GetScriptData(); |
4957 log_ = NULL; | 4952 log_ = NULL; |
4958 } | 4953 } |
4959 } | 4954 } |
4960 } } // namespace v8::internal | 4955 } } // namespace v8::internal |
OLD | NEW |