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

Side by Side Diff: src/parser.cc

Issue 5136002: Extract scanner base/JS/JSON and move base and JS to scanner-base. (Closed)
Patch Set: Created 10 years, 1 month 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
« no previous file with comments | « src/parser.h ('k') | src/prescanner.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 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 FunctionLiteral* Parser::ParseProgram(Handle<String> source, 721 FunctionLiteral* Parser::ParseProgram(Handle<String> source,
722 bool in_global_context) { 722 bool in_global_context) {
723 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); 723 CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
724 724
725 HistogramTimerScope timer(&Counters::parse); 725 HistogramTimerScope timer(&Counters::parse);
726 Counters::total_parse_size.Increment(source->length()); 726 Counters::total_parse_size.Increment(source->length());
727 fni_ = new FuncNameInferrer(); 727 fni_ = new FuncNameInferrer();
728 728
729 // Initialize parser state. 729 // Initialize parser state.
730 source->TryFlatten(); 730 source->TryFlatten();
731 scanner_.Initialize(source, JAVASCRIPT); 731 scanner_.Initialize(source);
732 ASSERT(target_stack_ == NULL); 732 ASSERT(target_stack_ == NULL);
733 if (pre_data_ != NULL) pre_data_->Initialize(); 733 if (pre_data_ != NULL) pre_data_->Initialize();
734 734
735 // Compute the parsing mode. 735 // Compute the parsing mode.
736 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY; 736 mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY;
737 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY; 737 if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY;
738 738
739 Scope::Type type = 739 Scope::Type type =
740 in_global_context 740 in_global_context
741 ? Scope::GLOBAL_SCOPE 741 ? Scope::GLOBAL_SCOPE
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 HistogramTimerScope timer(&Counters::parse_lazy); 784 HistogramTimerScope timer(&Counters::parse_lazy);
785 Handle<String> source(String::cast(script_->source())); 785 Handle<String> source(String::cast(script_->source()));
786 Counters::total_parse_size.Increment(source->length()); 786 Counters::total_parse_size.Increment(source->length());
787 787
788 Handle<String> name(String::cast(info->name())); 788 Handle<String> name(String::cast(info->name()));
789 fni_ = new FuncNameInferrer(); 789 fni_ = new FuncNameInferrer();
790 fni_->PushEnclosingName(name); 790 fni_->PushEnclosingName(name);
791 791
792 // Initialize parser state. 792 // Initialize parser state.
793 source->TryFlatten(); 793 source->TryFlatten();
794 scanner_.Initialize(source, info->start_position(), info->end_position(), 794 scanner_.Initialize(source, info->start_position(), info->end_position());
795 JAVASCRIPT);
796 ASSERT(target_stack_ == NULL); 795 ASSERT(target_stack_ == NULL);
797 mode_ = PARSE_EAGERLY; 796 mode_ = PARSE_EAGERLY;
798 797
799 // Place holder for the result. 798 // Place holder for the result.
800 FunctionLiteral* result = NULL; 799 FunctionLiteral* result = NULL;
801 800
802 { 801 {
803 // Parse the function literal. 802 // Parse the function literal.
804 Handle<String> no_name = Factory::empty_symbol(); 803 Handle<String> no_name = Factory::empty_symbol();
805 Scope* scope = 804 Scope* scope =
(...skipping 2800 matching lines...) Expand 10 before | Expand all | Expand 10 after
3606 args->Add(new Literal(array)); 3605 args->Add(new Literal(array));
3607 return new Throw(new CallRuntime(constructor, NULL, args), 3606 return new Throw(new CallRuntime(constructor, NULL, args),
3608 scanner().location().beg_pos); 3607 scanner().location().beg_pos);
3609 } 3608 }
3610 3609
3611 // ---------------------------------------------------------------------------- 3610 // ----------------------------------------------------------------------------
3612 // JSON 3611 // JSON
3613 3612
3614 Handle<Object> JsonParser::ParseJson(Handle<String> source) { 3613 Handle<Object> JsonParser::ParseJson(Handle<String> source) {
3615 source->TryFlatten(); 3614 source->TryFlatten();
3616 scanner_.Initialize(source, JSON); 3615 scanner_.Initialize(source);
3617 Handle<Object> result = ParseJsonValue(); 3616 Handle<Object> result = ParseJsonValue();
3618 if (result.is_null() || scanner_.Next() != Token::EOS) { 3617 if (result.is_null() || scanner_.Next() != Token::EOS) {
3619 if (scanner_.stack_overflow()) { 3618 if (scanner_.stack_overflow()) {
3620 // Scanner failed. 3619 // Scanner failed.
3621 Top::StackOverflow(); 3620 Top::StackOverflow();
3622 } else { 3621 } else {
3623 // Parse failed. Scanner's current token is the unexpected token. 3622 // Parse failed. Scanner's current token is the unexpected token.
3624 Token::Value token = scanner_.current_token(); 3623 Token::Value token = scanner_.current_token();
3625 3624
3626 const char* message; 3625 const char* message;
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
4634 data++; 4633 data++;
4635 } 4634 }
4636 *source = data; 4635 *source = data;
4637 return result; 4636 return result;
4638 } 4637 }
4639 4638
4640 4639
4641 static ScriptDataImpl* DoPreParse(UTF16Buffer* stream, 4640 static ScriptDataImpl* DoPreParse(UTF16Buffer* stream,
4642 bool allow_lazy, 4641 bool allow_lazy,
4643 PartialParserRecorder* recorder) { 4642 PartialParserRecorder* recorder) {
4644 typedef preparser::Scanner<UTF16Buffer, UTF8Buffer> PreScanner; 4643 preparser::Scanner scanner;
4645 PreScanner scanner;
4646 scanner.Initialize(stream); 4644 scanner.Initialize(stream);
4647 preparser::PreParser<PreScanner, PartialParserRecorder> preparser; 4645 preparser::PreParser<preparser::Scanner, PartialParserRecorder> preparser;
4648 if (!preparser.PreParseProgram(&scanner, recorder, allow_lazy)) { 4646 if (!preparser.PreParseProgram(&scanner, recorder, allow_lazy)) {
4649 Top::StackOverflow(); 4647 Top::StackOverflow();
4650 return NULL; 4648 return NULL;
4651 } 4649 }
4652 4650
4653 // Extract the accumulated data from the recorder as a single 4651 // Extract the accumulated data from the recorder as a single
4654 // contiguous vector that we are responsible for disposing. 4652 // contiguous vector that we are responsible for disposing.
4655 Vector<unsigned> store = recorder->ExtractData(); 4653 Vector<unsigned> store = recorder->ExtractData();
4656 return new ScriptDataImpl(store); 4654 return new ScriptDataImpl(store);
4657 } 4655 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
4766 Handle<String> source = Handle<String>(String::cast(script->source())); 4764 Handle<String> source = Handle<String>(String::cast(script->source()));
4767 result = parser.ParseProgram(source, info->is_global()); 4765 result = parser.ParseProgram(source, info->is_global());
4768 } 4766 }
4769 } 4767 }
4770 4768
4771 info->SetFunction(result); 4769 info->SetFunction(result);
4772 return (result != NULL); 4770 return (result != NULL);
4773 } 4771 }
4774 4772
4775 } } // namespace v8::internal 4773 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/prescanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698