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