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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 #define CHECK_FAILED /**/); \ | 529 #define CHECK_FAILED /**/); \ |
530 if (failed_) return NULL; \ | 530 if (failed_) return NULL; \ |
531 ((void)0 | 531 ((void)0 |
532 #define DUMMY ) // to make indentation work | 532 #define DUMMY ) // to make indentation work |
533 #undef DUMMY | 533 #undef DUMMY |
534 | 534 |
535 // ---------------------------------------------------------------------------- | 535 // ---------------------------------------------------------------------------- |
536 // Implementation of Parser | 536 // Implementation of Parser |
537 | 537 |
538 Parser::Parser(CompilationInfo* info) | 538 Parser::Parser(CompilationInfo* info) |
539 : isolate_(info->isolate()), | 539 : ParserBase(&scanner_, info->isolate()->stack_guard()->real_climit()), |
| 540 isolate_(info->isolate()), |
540 symbol_cache_(0, info->zone()), | 541 symbol_cache_(0, info->zone()), |
541 script_(info->script()), | 542 script_(info->script()), |
542 scanner_(isolate_->unicode_cache()), | 543 scanner_(isolate_->unicode_cache()), |
543 reusable_preparser_(NULL), | 544 reusable_preparser_(NULL), |
544 top_scope_(NULL), | 545 top_scope_(NULL), |
545 original_scope_(NULL), | 546 original_scope_(NULL), |
546 current_function_state_(NULL), | 547 current_function_state_(NULL), |
547 target_stack_(NULL), | 548 target_stack_(NULL), |
548 extension_(info->extension()), | 549 extension_(info->extension()), |
549 pre_parse_data_(NULL), | 550 pre_parse_data_(NULL), |
550 fni_(NULL), | 551 fni_(NULL), |
551 allow_natives_syntax_(false), | |
552 allow_lazy_(false), | |
553 allow_generators_(false), | |
554 allow_for_of_(false), | |
555 stack_overflow_(false), | |
556 parenthesized_function_(false), | 552 parenthesized_function_(false), |
557 zone_(info->zone()), | 553 zone_(info->zone()), |
558 info_(info) { | 554 info_(info) { |
559 ASSERT(!script_.is_null()); | 555 ASSERT(!script_.is_null()); |
560 isolate_->set_ast_node_id(0); | 556 isolate_->set_ast_node_id(0); |
561 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); | 557 set_allow_harmony_scoping(!info->is_native() && FLAG_harmony_scoping); |
562 set_allow_modules(!info->is_native() && FLAG_harmony_modules); | 558 set_allow_modules(!info->is_native() && FLAG_harmony_modules); |
563 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); | 559 set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native()); |
564 set_allow_lazy(false); // Must be explicitly enabled. | 560 set_allow_lazy(false); // Must be explicitly enabled. |
565 set_allow_generators(FLAG_harmony_generators); | 561 set_allow_generators(FLAG_harmony_generators); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 0, | 679 0, |
684 FunctionLiteral::kNoDuplicateParameters, | 680 FunctionLiteral::kNoDuplicateParameters, |
685 FunctionLiteral::ANONYMOUS_EXPRESSION, | 681 FunctionLiteral::ANONYMOUS_EXPRESSION, |
686 FunctionLiteral::kGlobalOrEval, | 682 FunctionLiteral::kGlobalOrEval, |
687 FunctionLiteral::kNotParenthesized, | 683 FunctionLiteral::kNotParenthesized, |
688 FunctionLiteral::kNotGenerator, | 684 FunctionLiteral::kNotGenerator, |
689 0); | 685 0); |
690 result->set_ast_properties(factory()->visitor()->ast_properties()); | 686 result->set_ast_properties(factory()->visitor()->ast_properties()); |
691 result->set_dont_optimize_reason( | 687 result->set_dont_optimize_reason( |
692 factory()->visitor()->dont_optimize_reason()); | 688 factory()->visitor()->dont_optimize_reason()); |
693 } else if (stack_overflow_) { | 689 } else if (stack_overflow()) { |
694 isolate()->StackOverflow(); | 690 isolate()->StackOverflow(); |
695 } | 691 } |
696 } | 692 } |
697 | 693 |
698 // Make sure the target stack is empty. | 694 // Make sure the target stack is empty. |
699 ASSERT(target_stack_ == NULL); | 695 ASSERT(target_stack_ == NULL); |
700 | 696 |
701 return result; | 697 return result; |
702 } | 698 } |
703 | 699 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 function_type, | 776 function_type, |
781 &ok); | 777 &ok); |
782 // Make sure the results agree. | 778 // Make sure the results agree. |
783 ASSERT(ok == (result != NULL)); | 779 ASSERT(ok == (result != NULL)); |
784 } | 780 } |
785 | 781 |
786 // Make sure the target stack is empty. | 782 // Make sure the target stack is empty. |
787 ASSERT(target_stack_ == NULL); | 783 ASSERT(target_stack_ == NULL); |
788 | 784 |
789 if (result == NULL) { | 785 if (result == NULL) { |
790 if (stack_overflow_) isolate()->StackOverflow(); | 786 if (stack_overflow()) isolate()->StackOverflow(); |
791 } else { | 787 } else { |
792 Handle<String> inferred_name(shared_info->inferred_name()); | 788 Handle<String> inferred_name(shared_info->inferred_name()); |
793 result->set_inferred_name(inferred_name); | 789 result->set_inferred_name(inferred_name); |
794 } | 790 } |
795 return result; | 791 return result; |
796 } | 792 } |
797 | 793 |
798 | 794 |
799 Handle<String> Parser::GetSymbol() { | 795 Handle<String> Parser::GetSymbol() { |
800 int symbol_id = -1; | 796 int symbol_id = -1; |
(...skipping 2676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3477 Expect(Token::DEBUGGER, CHECK_OK); | 3473 Expect(Token::DEBUGGER, CHECK_OK); |
3478 ExpectSemicolon(CHECK_OK); | 3474 ExpectSemicolon(CHECK_OK); |
3479 return factory()->NewDebuggerStatement(pos); | 3475 return factory()->NewDebuggerStatement(pos); |
3480 } | 3476 } |
3481 | 3477 |
3482 | 3478 |
3483 void Parser::ReportUnexpectedToken(Token::Value token) { | 3479 void Parser::ReportUnexpectedToken(Token::Value token) { |
3484 // We don't report stack overflows here, to avoid increasing the | 3480 // We don't report stack overflows here, to avoid increasing the |
3485 // stack depth even further. Instead we report it after parsing is | 3481 // stack depth even further. Instead we report it after parsing is |
3486 // over, in ParseProgram/ParseJson. | 3482 // over, in ParseProgram/ParseJson. |
3487 if (token == Token::ILLEGAL && stack_overflow_) return; | 3483 if (token == Token::ILLEGAL && stack_overflow()) return; |
3488 // Four of the tokens are treated specially | 3484 // Four of the tokens are treated specially |
3489 switch (token) { | 3485 switch (token) { |
3490 case Token::EOS: | 3486 case Token::EOS: |
3491 return ReportMessage("unexpected_eos", Vector<const char*>::empty()); | 3487 return ReportMessage("unexpected_eos", Vector<const char*>::empty()); |
3492 case Token::NUMBER: | 3488 case Token::NUMBER: |
3493 return ReportMessage("unexpected_token_number", | 3489 return ReportMessage("unexpected_token_number", |
3494 Vector<const char*>::empty()); | 3490 Vector<const char*>::empty()); |
3495 case Token::STRING: | 3491 case Token::STRING: |
3496 return ReportMessage("unexpected_token_string", | 3492 return ReportMessage("unexpected_token_string", |
3497 Vector<const char*>::empty()); | 3493 Vector<const char*>::empty()); |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4371 is_lazily_compiled = false; | 4367 is_lazily_compiled = false; |
4372 } | 4368 } |
4373 } else { | 4369 } else { |
4374 // With no preparser data, we partially parse the function, without | 4370 // With no preparser data, we partially parse the function, without |
4375 // building an AST. This gathers the data needed to build a lazy | 4371 // building an AST. This gathers the data needed to build a lazy |
4376 // function. | 4372 // function. |
4377 SingletonLogger logger; | 4373 SingletonLogger logger; |
4378 PreParser::PreParseResult result = LazyParseFunctionLiteral(&logger); | 4374 PreParser::PreParseResult result = LazyParseFunctionLiteral(&logger); |
4379 if (result == PreParser::kPreParseStackOverflow) { | 4375 if (result == PreParser::kPreParseStackOverflow) { |
4380 // Propagate stack overflow. | 4376 // Propagate stack overflow. |
4381 stack_overflow_ = true; | 4377 set_stack_overflow(); |
4382 *ok = false; | 4378 *ok = false; |
4383 return NULL; | 4379 return NULL; |
4384 } | 4380 } |
4385 if (logger.has_error()) { | 4381 if (logger.has_error()) { |
4386 const char* arg = logger.argument_opt(); | 4382 const char* arg = logger.argument_opt(); |
4387 Vector<const char*> args; | 4383 Vector<const char*> args; |
4388 if (arg != NULL) { | 4384 if (arg != NULL) { |
4389 args = Vector<const char*>(&arg, 1); | 4385 args = Vector<const char*>(&arg, 1); |
4390 } | 4386 } |
4391 ReportMessageAt(Scanner::Location(logger.start(), logger.end()), | 4387 ReportMessageAt(Scanner::Location(logger.start(), logger.end()), |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4606 ReportMessage("not_defined", Vector<Handle<String> >(&name, 1)); | 4602 ReportMessage("not_defined", Vector<Handle<String> >(&name, 1)); |
4607 *ok = false; | 4603 *ok = false; |
4608 return NULL; | 4604 return NULL; |
4609 } | 4605 } |
4610 | 4606 |
4611 // We have a valid intrinsics call or a call to a builtin. | 4607 // We have a valid intrinsics call or a call to a builtin. |
4612 return factory()->NewCallRuntime(name, function, args, pos); | 4608 return factory()->NewCallRuntime(name, function, args, pos); |
4613 } | 4609 } |
4614 | 4610 |
4615 | 4611 |
4616 bool Parser::peek_any_identifier() { | 4612 bool ParserBase::peek_any_identifier() { |
4617 Token::Value next = peek(); | 4613 Token::Value next = peek(); |
4618 return next == Token::IDENTIFIER || | 4614 return next == Token::IDENTIFIER || |
4619 next == Token::FUTURE_RESERVED_WORD || | 4615 next == Token::FUTURE_RESERVED_WORD || |
4620 next == Token::FUTURE_STRICT_RESERVED_WORD || | 4616 next == Token::FUTURE_STRICT_RESERVED_WORD || |
4621 next == Token::YIELD; | 4617 next == Token::YIELD; |
4622 } | 4618 } |
4623 | 4619 |
4624 | 4620 |
4625 void Parser::Consume(Token::Value token) { | |
4626 Token::Value next = Next(); | |
4627 USE(next); | |
4628 USE(token); | |
4629 ASSERT(next == token); | |
4630 } | |
4631 | |
4632 | |
4633 void Parser::Expect(Token::Value token, bool* ok) { | |
4634 Token::Value next = Next(); | |
4635 if (next == token) return; | |
4636 ReportUnexpectedToken(next); | |
4637 *ok = false; | |
4638 } | |
4639 | |
4640 | |
4641 bool Parser::Check(Token::Value token) { | |
4642 Token::Value next = peek(); | |
4643 if (next == token) { | |
4644 Consume(next); | |
4645 return true; | |
4646 } | |
4647 return false; | |
4648 } | |
4649 | |
4650 | |
4651 bool Parser::CheckContextualKeyword(Vector<const char> keyword) { | 4621 bool Parser::CheckContextualKeyword(Vector<const char> keyword) { |
4652 if (peek() == Token::IDENTIFIER && | 4622 if (peek() == Token::IDENTIFIER && |
4653 scanner().is_next_contextual_keyword(keyword)) { | 4623 scanner().is_next_contextual_keyword(keyword)) { |
4654 Consume(Token::IDENTIFIER); | 4624 Consume(Token::IDENTIFIER); |
4655 return true; | 4625 return true; |
4656 } | 4626 } |
4657 return false; | 4627 return false; |
4658 } | 4628 } |
4659 | 4629 |
4660 | 4630 |
4661 void Parser::ExpectSemicolon(bool* ok) { | 4631 void ParserBase::ExpectSemicolon(bool* ok) { |
4662 // Check for automatic semicolon insertion according to | 4632 // Check for automatic semicolon insertion according to |
4663 // the rules given in ECMA-262, section 7.9, page 21. | 4633 // the rules given in ECMA-262, section 7.9, page 21. |
4664 Token::Value tok = peek(); | 4634 Token::Value tok = peek(); |
4665 if (tok == Token::SEMICOLON) { | 4635 if (tok == Token::SEMICOLON) { |
4666 Next(); | 4636 Next(); |
4667 return; | 4637 return; |
4668 } | 4638 } |
4669 if (scanner().HasAnyLineTerminatorBeforeNext() || | 4639 if (scanner()->HasAnyLineTerminatorBeforeNext() || |
4670 tok == Token::RBRACE || | 4640 tok == Token::RBRACE || |
4671 tok == Token::EOS) { | 4641 tok == Token::EOS) { |
4672 return; | 4642 return; |
4673 } | 4643 } |
4674 Expect(Token::SEMICOLON, ok); | 4644 Expect(Token::SEMICOLON, ok); |
4675 } | 4645 } |
4676 | 4646 |
4677 | 4647 |
4678 void Parser::ExpectContextualKeyword(Vector<const char> keyword, bool* ok) { | 4648 void Parser::ExpectContextualKeyword(Vector<const char> keyword, bool* ok) { |
4679 Expect(Token::IDENTIFIER, ok); | 4649 Expect(Token::IDENTIFIER, ok); |
(...skipping 1207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5887 ASSERT(info()->isolate()->has_pending_exception()); | 5857 ASSERT(info()->isolate()->has_pending_exception()); |
5888 } else { | 5858 } else { |
5889 result = ParseProgram(); | 5859 result = ParseProgram(); |
5890 } | 5860 } |
5891 } | 5861 } |
5892 info()->SetFunction(result); | 5862 info()->SetFunction(result); |
5893 return (result != NULL); | 5863 return (result != NULL); |
5894 } | 5864 } |
5895 | 5865 |
5896 } } // namespace v8::internal | 5866 } } // namespace v8::internal |
OLD | NEW |