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

Side by Side Diff: src/parser.cc

Issue 5063003: Add separate scanner only intended for preparsing. (Closed)
Patch Set: Address review comments. 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 | « no previous file | 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 19 matching lines...) Expand all
30 #include "api.h" 30 #include "api.h"
31 #include "ast.h" 31 #include "ast.h"
32 #include "bootstrapper.h" 32 #include "bootstrapper.h"
33 #include "codegen.h" 33 #include "codegen.h"
34 #include "compiler.h" 34 #include "compiler.h"
35 #include "func-name-inferrer.h" 35 #include "func-name-inferrer.h"
36 #include "messages.h" 36 #include "messages.h"
37 #include "parser.h" 37 #include "parser.h"
38 #include "platform.h" 38 #include "platform.h"
39 #include "preparser.h" 39 #include "preparser.h"
40 #include "prescanner.h"
40 #include "runtime.h" 41 #include "runtime.h"
41 #include "scopeinfo.h" 42 #include "scopeinfo.h"
42 #include "string-stream.h" 43 #include "string-stream.h"
43 44
44 #include "ast-inl.h" 45 #include "ast-inl.h"
45 #include "jump-target-inl.h" 46 #include "jump-target-inl.h"
46 47
47 namespace v8 { 48 namespace v8 {
48 namespace internal { 49 namespace internal {
49 50
(...skipping 4580 matching lines...) Expand 10 before | Expand all | Expand 10 after
4630 if (data >= symbol_data_end_) return -1; 4631 if (data >= symbol_data_end_) return -1;
4631 input = *data; 4632 input = *data;
4632 result = (result << 7) | (input & 0x7f); 4633 result = (result << 7) | (input & 0x7f);
4633 data++; 4634 data++;
4634 } 4635 }
4635 *source = data; 4636 *source = data;
4636 return result; 4637 return result;
4637 } 4638 }
4638 4639
4639 4640
4641 static ScriptDataImpl* DoPreParse(UTF16Buffer* stream,
4642 bool allow_lazy,
4643 PartialParserRecorder* recorder) {
4644 typedef preparser::Scanner<UTF16Buffer, UTF8Buffer> PreScanner;
4645 PreScanner scanner;
4646 scanner.Initialize(stream);
4647 preparser::PreParser<PreScanner, PartialParserRecorder> preparser;
4648 if (!preparser.PreParseProgram(&scanner, recorder, allow_lazy)) {
4649 Top::StackOverflow();
4650 return NULL;
4651 }
4652
4653 // Extract the accumulated data from the recorder as a single
4654 // contiguous vector that we are responsible for disposing.
4655 Vector<unsigned> store = recorder->ExtractData();
4656 return new ScriptDataImpl(store);
4657 }
4658
4659
4660 // Create an UTF16Buffer for the preparser to use as input,
4661 // and preparse the source.
4662 static ScriptDataImpl* DoPreParse(Handle<String> source,
4663 unibrow::CharacterStream* stream,
4664 bool allow_lazy,
4665 PartialParserRecorder* recorder) {
4666 if (source.is_null()) {
4667 CharacterStreamUTF16Buffer buffer;
4668 int length = stream->Length();
4669 buffer.Initialize(source, stream, 0, length);
4670 return DoPreParse(&buffer, allow_lazy, recorder);
4671 } else if (source->IsExternalAsciiString()) {
4672 ExternalStringUTF16Buffer<ExternalAsciiString, char> buffer;
4673 int length = source->length();
4674 buffer.Initialize(Handle<ExternalAsciiString>::cast(source), 0, length);
4675 return DoPreParse(&buffer, allow_lazy, recorder);
4676 } else if (source->IsExternalTwoByteString()) {
4677 ExternalStringUTF16Buffer<ExternalTwoByteString, uint16_t> buffer;
4678 int length = source->length();
4679 buffer.Initialize(Handle<ExternalTwoByteString>::cast(source), 0, length);
4680 return DoPreParse(&buffer, allow_lazy, recorder);
4681 } else {
4682 CharacterStreamUTF16Buffer buffer;
4683 SafeStringInputBuffer input;
4684 input.Reset(0, source.location());
4685 int length = source->length();
4686 buffer.Initialize(source, &input, 0, length);
4687 return DoPreParse(&buffer, allow_lazy, recorder);
4688 }
4689 }
4690
4691
4640 // Preparse, but only collect data that is immediately useful, 4692 // Preparse, but only collect data that is immediately useful,
4641 // even if the preparser data is only used once. 4693 // even if the preparser data is only used once.
4642 ScriptDataImpl* ParserApi::PartialPreParse(Handle<String> source, 4694 ScriptDataImpl* ParserApi::PartialPreParse(Handle<String> source,
4643 unibrow::CharacterStream* stream, 4695 unibrow::CharacterStream* stream,
4644 v8::Extension* extension) { 4696 v8::Extension* extension) {
4645 Handle<Script> no_script; 4697 Handle<Script> no_script;
4646 bool allow_lazy = FLAG_lazy && (extension == NULL); 4698 bool allow_lazy = FLAG_lazy && (extension == NULL);
4647 if (!allow_lazy) { 4699 if (!allow_lazy) {
4648 // Partial preparsing is only about lazily compiled functions. 4700 // Partial preparsing is only about lazily compiled functions.
4649 // If we don't allow lazy compilation, the log data will be empty. 4701 // If we don't allow lazy compilation, the log data will be empty.
4650 return NULL; 4702 return NULL;
4651 } 4703 }
4652 preparser::PreParser<Scanner, PartialParserRecorder> parser;
4653 Scanner scanner;
4654 scanner.Initialize(source, stream, JAVASCRIPT);
4655 PartialParserRecorder recorder; 4704 PartialParserRecorder recorder;
4656 if (!parser.PreParseProgram(&scanner, &recorder, allow_lazy)) {
4657 Top::StackOverflow();
4658 return NULL;
4659 }
4660 4705
4661 // Extract the accumulated data from the recorder as a single 4706 return DoPreParse(source, stream, allow_lazy, &recorder);
4662 // contiguous vector that we are responsible for disposing.
4663 Vector<unsigned> store = recorder.ExtractData();
4664 return new ScriptDataImpl(store);
4665 } 4707 }
4666 4708
4667 4709
4668 ScriptDataImpl* ParserApi::PreParse(Handle<String> source, 4710 ScriptDataImpl* ParserApi::PreParse(Handle<String> source,
4669 unibrow::CharacterStream* stream, 4711 unibrow::CharacterStream* stream,
4670 v8::Extension* extension) { 4712 v8::Extension* extension) {
4671 Handle<Script> no_script; 4713 Handle<Script> no_script;
4672 preparser::PreParser<Scanner, CompleteParserRecorder> parser;
4673 Scanner scanner;
4674 scanner.Initialize(source, stream, JAVASCRIPT);
4675 bool allow_lazy = FLAG_lazy && (extension == NULL); 4714 bool allow_lazy = FLAG_lazy && (extension == NULL);
4676 CompleteParserRecorder recorder; 4715 CompleteParserRecorder recorder;
4677 if (!parser.PreParseProgram(&scanner, &recorder, allow_lazy)) { 4716 return DoPreParse(source, stream, allow_lazy, &recorder);
4678 Top::StackOverflow();
4679 return NULL;
4680 }
4681 // Extract the accumulated data from the recorder as a single
4682 // contiguous vector that we are responsible for disposing.
4683 Vector<unsigned> store = recorder.ExtractData();
4684 return new ScriptDataImpl(store);
4685 } 4717 }
4686 4718
4687 4719
4688 bool RegExpParser::ParseRegExp(FlatStringReader* input, 4720 bool RegExpParser::ParseRegExp(FlatStringReader* input,
4689 bool multiline, 4721 bool multiline,
4690 RegExpCompileData* result) { 4722 RegExpCompileData* result) {
4691 ASSERT(result != NULL); 4723 ASSERT(result != NULL);
4692 RegExpParser parser(input, &result->error, multiline); 4724 RegExpParser parser(input, &result->error, multiline);
4693 RegExpTree* tree = parser.ParsePattern(); 4725 RegExpTree* tree = parser.ParsePattern();
4694 if (parser.failed()) { 4726 if (parser.failed()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4734 Handle<String> source = Handle<String>(String::cast(script->source())); 4766 Handle<String> source = Handle<String>(String::cast(script->source()));
4735 result = parser.ParseProgram(source, info->is_global()); 4767 result = parser.ParseProgram(source, info->is_global());
4736 } 4768 }
4737 } 4769 }
4738 4770
4739 info->SetFunction(result); 4771 info->SetFunction(result);
4740 return (result != NULL); 4772 return (result != NULL);
4741 } 4773 }
4742 4774
4743 } } // namespace v8::internal 4775 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/prescanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698