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

Side by Side Diff: src/parser.cc

Issue 5063003: Add separate scanner only intended for preparsing. (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 | « no previous file | src/prescanner.h » ('j') | src/prescanner.h » ('J')
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 }
Søren Thygesen Gjesse 2010/11/17 10:37:46 How about using if ... else if ... else if ... el
Lasse Reichstein 2010/11/17 13:08:39 Done.
4672 if (source->IsExternalAsciiString()) {
4673 ExternalStringUTF16Buffer<ExternalAsciiString, char> buffer;
4674 int length = source->length();
4675 buffer.Initialize(Handle<ExternalAsciiString>::cast(source), 0, length);
4676 return DoPreParse(&buffer, allow_lazy, recorder);
4677 }
4678 if (source->IsExternalTwoByteString()) {
4679 ExternalStringUTF16Buffer<ExternalTwoByteString, uint16_t> buffer;
4680 int length = source->length();
4681 buffer.Initialize(Handle<ExternalTwoByteString>::cast(source), 0, length);
4682 return DoPreParse(&buffer, allow_lazy, recorder);
4683 }
4684 CharacterStreamUTF16Buffer buffer;
4685 SafeStringInputBuffer input;
4686 input.Reset(0, source.location());
4687 int length = source->length();
4688 buffer.Initialize(source, &input, 0, length);
4689 return DoPreParse(&buffer, allow_lazy, recorder);
4690 }
4691
4692
4640 // Preparse, but only collect data that is immediately useful, 4693 // Preparse, but only collect data that is immediately useful,
4641 // even if the preparser data is only used once. 4694 // even if the preparser data is only used once.
4642 ScriptDataImpl* ParserApi::PartialPreParse(Handle<String> source, 4695 ScriptDataImpl* ParserApi::PartialPreParse(Handle<String> source,
4643 unibrow::CharacterStream* stream, 4696 unibrow::CharacterStream* stream,
4644 v8::Extension* extension) { 4697 v8::Extension* extension) {
4645 Handle<Script> no_script; 4698 Handle<Script> no_script;
4646 bool allow_lazy = FLAG_lazy && (extension == NULL); 4699 bool allow_lazy = FLAG_lazy && (extension == NULL);
4647 if (!allow_lazy) { 4700 if (!allow_lazy) {
4648 // Partial preparsing is only about lazily compiled functions. 4701 // Partial preparsing is only about lazily compiled functions.
4649 // If we don't allow lazy compilation, the log data will be empty. 4702 // If we don't allow lazy compilation, the log data will be empty.
4650 return NULL; 4703 return NULL;
4651 } 4704 }
4652 preparser::PreParser<Scanner, PartialParserRecorder> parser;
4653 Scanner scanner;
4654 scanner.Initialize(source, stream, JAVASCRIPT);
4655 PartialParserRecorder recorder; 4705 PartialParserRecorder recorder;
4656 if (!parser.PreParseProgram(&scanner, &recorder, allow_lazy)) {
4657 Top::StackOverflow();
4658 return NULL;
4659 }
4660 4706
4661 // Extract the accumulated data from the recorder as a single 4707 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 } 4708 }
4666 4709
4667 4710
4668 ScriptDataImpl* ParserApi::PreParse(Handle<String> source, 4711 ScriptDataImpl* ParserApi::PreParse(Handle<String> source,
4669 unibrow::CharacterStream* stream, 4712 unibrow::CharacterStream* stream,
4670 v8::Extension* extension) { 4713 v8::Extension* extension) {
4671 Handle<Script> no_script; 4714 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); 4715 bool allow_lazy = FLAG_lazy && (extension == NULL);
4676 CompleteParserRecorder recorder; 4716 CompleteParserRecorder recorder;
4677 if (!parser.PreParseProgram(&scanner, &recorder, allow_lazy)) { 4717 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 } 4718 }
4686 4719
4687 4720
4688 bool RegExpParser::ParseRegExp(FlatStringReader* input, 4721 bool RegExpParser::ParseRegExp(FlatStringReader* input,
4689 bool multiline, 4722 bool multiline,
4690 RegExpCompileData* result) { 4723 RegExpCompileData* result) {
4691 ASSERT(result != NULL); 4724 ASSERT(result != NULL);
4692 RegExpParser parser(input, &result->error, multiline); 4725 RegExpParser parser(input, &result->error, multiline);
4693 RegExpTree* tree = parser.ParsePattern(); 4726 RegExpTree* tree = parser.ParsePattern();
4694 if (parser.failed()) { 4727 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())); 4767 Handle<String> source = Handle<String>(String::cast(script->source()));
4735 result = parser.ParseProgram(source, info->is_global()); 4768 result = parser.ParseProgram(source, info->is_global());
4736 } 4769 }
4737 } 4770 }
4738 4771
4739 info->SetFunction(result); 4772 info->SetFunction(result);
4740 return (result != NULL); 4773 return (result != NULL);
4741 } 4774 }
4742 4775
4743 } } // namespace v8::internal 4776 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/prescanner.h » ('j') | src/prescanner.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698