Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: src/parser.cc

Issue 6685050: Merge r7110 from bleeding_edge to 3.0 branch. (Closed) Base URL: http://v8.googlecode.com/svn/branches/3.0/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/scopes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 691
692 // Make sure the target stack is empty. 692 // Make sure the target stack is empty.
693 ASSERT(target_stack_ == NULL); 693 ASSERT(target_stack_ == NULL);
694 694
695 // If there was a syntax error we have to get rid of the AST 695 // If there was a syntax error we have to get rid of the AST
696 // and it is not safe to do so before the scope has been deleted. 696 // and it is not safe to do so before the scope has been deleted.
697 if (result == NULL) zone_scope->DeleteOnExit(); 697 if (result == NULL) zone_scope->DeleteOnExit();
698 return result; 698 return result;
699 } 699 }
700 700
701 FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info) { 701 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info) {
702 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); 702 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
703 HistogramTimerScope timer(&Counters::parse_lazy); 703 HistogramTimerScope timer(&Counters::parse_lazy);
704 Handle<String> source(String::cast(script_->source())); 704 Handle<String> source(String::cast(script_->source()));
705 Counters::total_parse_size.Increment(source->length()); 705 Counters::total_parse_size.Increment(source->length());
706 706
707 Handle<SharedFunctionInfo> shared_info = info->shared_info();
707 // Initialize parser state. 708 // Initialize parser state.
708 source->TryFlatten(); 709 source->TryFlatten();
709 if (source->IsExternalTwoByteString()) { 710 if (source->IsExternalTwoByteString()) {
710 ExternalTwoByteStringUC16CharacterStream stream( 711 ExternalTwoByteStringUC16CharacterStream stream(
711 Handle<ExternalTwoByteString>::cast(source), 712 Handle<ExternalTwoByteString>::cast(source),
712 info->start_position(), 713 shared_info->start_position(),
713 info->end_position()); 714 shared_info->end_position());
714 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope); 715 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope);
715 return result; 716 return result;
716 } else { 717 } else {
717 GenericStringUC16CharacterStream stream(source, 718 GenericStringUC16CharacterStream stream(source,
718 info->start_position(), 719 shared_info->start_position(),
719 info->end_position()); 720 shared_info->end_position());
720 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope); 721 FunctionLiteral* result = ParseLazy(info, &stream, &zone_scope);
721 return result; 722 return result;
722 } 723 }
723 } 724 }
724 725
725 726
726 FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info, 727 FunctionLiteral* Parser::ParseLazy(CompilationInfo* info,
727 UC16CharacterStream* source, 728 UC16CharacterStream* source,
728 ZoneScope* zone_scope) { 729 ZoneScope* zone_scope) {
730 Handle<SharedFunctionInfo> shared_info = info->shared_info();
729 scanner_.Initialize(source); 731 scanner_.Initialize(source);
730 ASSERT(target_stack_ == NULL); 732 ASSERT(target_stack_ == NULL);
731 733
732 Handle<String> name(String::cast(info->name())); 734 Handle<String> name(String::cast(shared_info->name()));
733 fni_ = new FuncNameInferrer(); 735 fni_ = new FuncNameInferrer();
734 fni_->PushEnclosingName(name); 736 fni_->PushEnclosingName(name);
735 737
736 mode_ = PARSE_EAGERLY; 738 mode_ = PARSE_EAGERLY;
737 739
738 // Place holder for the result. 740 // Place holder for the result.
739 FunctionLiteral* result = NULL; 741 FunctionLiteral* result = NULL;
740 742
741 { 743 {
742 // Parse the function literal. 744 // Parse the function literal.
743 Handle<String> no_name = Factory::empty_symbol(); 745 Handle<String> no_name = Factory::empty_symbol();
744 Scope* scope = 746 Scope* scope = NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with());
745 NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with()); 747 if (!info->closure().is_null()) {
748 scope = Scope::DeserializeScopeChain(info, scope);
749 }
746 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_, 750 LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
747 scope); 751 scope);
748 TemporaryScope temp_scope(&this->temp_scope_); 752 TemporaryScope temp_scope(&this->temp_scope_);
749 753
750 FunctionLiteralType type = 754 FunctionLiteralType type =
751 info->is_expression() ? EXPRESSION : DECLARATION; 755 shared_info->is_expression() ? EXPRESSION : DECLARATION;
752 bool ok = true; 756 bool ok = true;
753 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok); 757 result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok);
754 // Make sure the results agree. 758 // Make sure the results agree.
755 ASSERT(ok == (result != NULL)); 759 ASSERT(ok == (result != NULL));
756 } 760 }
757 761
758 // Make sure the target stack is empty. 762 // Make sure the target stack is empty.
759 ASSERT(target_stack_ == NULL); 763 ASSERT(target_stack_ == NULL);
760 764
761 // If there was a stack overflow we have to get rid of AST and it is 765 // If there was a stack overflow we have to get rid of AST and it is
762 // not safe to do before scope has been deleted. 766 // not safe to do before scope has been deleted.
763 if (result == NULL) { 767 if (result == NULL) {
764 zone_scope->DeleteOnExit(); 768 zone_scope->DeleteOnExit();
765 if (stack_overflow_) Top::StackOverflow(); 769 if (stack_overflow_) Top::StackOverflow();
766 } else { 770 } else {
767 Handle<String> inferred_name(info->inferred_name()); 771 Handle<String> inferred_name(shared_info->inferred_name());
768 result->set_inferred_name(inferred_name); 772 result->set_inferred_name(inferred_name);
769 } 773 }
770 return result; 774 return result;
771 } 775 }
772 776
773 777
774 Handle<String> Parser::GetSymbol(bool* ok) { 778 Handle<String> Parser::GetSymbol(bool* ok) {
775 int symbol_id = -1; 779 int symbol_id = -1;
776 if (pre_data() != NULL) { 780 if (pre_data() != NULL) {
777 symbol_id = pre_data()->GetSymbolIdentifier(); 781 symbol_id = pre_data()->GetSymbolIdentifier();
(...skipping 4225 matching lines...) Expand 10 before | Expand all | Expand 10 after
5003 return !parser.failed(); 5007 return !parser.failed();
5004 } 5008 }
5005 5009
5006 5010
5007 bool ParserApi::Parse(CompilationInfo* info) { 5011 bool ParserApi::Parse(CompilationInfo* info) {
5008 ASSERT(info->function() == NULL); 5012 ASSERT(info->function() == NULL);
5009 FunctionLiteral* result = NULL; 5013 FunctionLiteral* result = NULL;
5010 Handle<Script> script = info->script(); 5014 Handle<Script> script = info->script();
5011 if (info->is_lazy()) { 5015 if (info->is_lazy()) {
5012 Parser parser(script, true, NULL, NULL); 5016 Parser parser(script, true, NULL, NULL);
5013 result = parser.ParseLazy(info->shared_info()); 5017 result = parser.ParseLazy(info);
5014 } else { 5018 } else {
5015 bool allow_natives_syntax = 5019 bool allow_natives_syntax =
5016 FLAG_allow_natives_syntax || Bootstrapper::IsActive(); 5020 FLAG_allow_natives_syntax || Bootstrapper::IsActive();
5017 ScriptDataImpl* pre_data = info->pre_parse_data(); 5021 ScriptDataImpl* pre_data = info->pre_parse_data();
5018 Parser parser(script, allow_natives_syntax, info->extension(), pre_data); 5022 Parser parser(script, allow_natives_syntax, info->extension(), pre_data);
5019 if (pre_data != NULL && pre_data->has_error()) { 5023 if (pre_data != NULL && pre_data->has_error()) {
5020 Scanner::Location loc = pre_data->MessageLocation(); 5024 Scanner::Location loc = pre_data->MessageLocation();
5021 const char* message = pre_data->BuildMessage(); 5025 const char* message = pre_data->BuildMessage();
5022 Vector<const char*> args = pre_data->BuildArgs(); 5026 Vector<const char*> args = pre_data->BuildArgs();
5023 parser.ReportMessageAt(loc, message, args); 5027 parser.ReportMessageAt(loc, message, args);
5024 DeleteArray(message); 5028 DeleteArray(message);
5025 for (int i = 0; i < args.length(); i++) { 5029 for (int i = 0; i < args.length(); i++) {
5026 DeleteArray(args[i]); 5030 DeleteArray(args[i]);
5027 } 5031 }
5028 DeleteArray(args.start()); 5032 DeleteArray(args.start());
5029 ASSERT(Top::has_pending_exception()); 5033 ASSERT(Top::has_pending_exception());
5030 } else { 5034 } else {
5031 Handle<String> source = Handle<String>(String::cast(script->source())); 5035 Handle<String> source = Handle<String>(String::cast(script->source()));
5032 result = parser.ParseProgram(source, info->is_global()); 5036 result = parser.ParseProgram(source, info->is_global());
5033 } 5037 }
5034 } 5038 }
5035 5039
5036 info->SetFunction(result); 5040 info->SetFunction(result);
5037 return (result != NULL); 5041 return (result != NULL);
5038 } 5042 }
5039 5043
5040 } } // namespace v8::internal 5044 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698