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

Side by Side Diff: src/parser.cc

Issue 5188006: Push version 2.5.7 to trunk.... (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
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 | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | src/platform-win32.cc » ('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 1635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 1686
1686 return false; 1687 return false;
1687 } 1688 }
1688 1689
1689 1690
1690 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, 1691 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels,
1691 bool* ok) { 1692 bool* ok) {
1692 // ExpressionStatement | LabelledStatement :: 1693 // ExpressionStatement | LabelledStatement ::
1693 // Expression ';' 1694 // Expression ';'
1694 // Identifier ':' Statement 1695 // Identifier ':' Statement
1695 1696 bool starts_with_idenfifier = (peek() == Token::IDENTIFIER);
1696 Expression* expr = ParseExpression(true, CHECK_OK); 1697 Expression* expr = ParseExpression(true, CHECK_OK);
1697 if (peek() == Token::COLON && expr && 1698 if (peek() == Token::COLON && starts_with_idenfifier && expr &&
1698 expr->AsVariableProxy() != NULL && 1699 expr->AsVariableProxy() != NULL &&
1699 !expr->AsVariableProxy()->is_this()) { 1700 !expr->AsVariableProxy()->is_this()) {
1701 // Expression is a single identifier, and not, e.g., a parenthesized
1702 // identifier.
1700 VariableProxy* var = expr->AsVariableProxy(); 1703 VariableProxy* var = expr->AsVariableProxy();
1701 Handle<String> label = var->name(); 1704 Handle<String> label = var->name();
1702 // TODO(1240780): We don't check for redeclaration of labels 1705 // TODO(1240780): We don't check for redeclaration of labels
1703 // during preparsing since keeping track of the set of active 1706 // during preparsing since keeping track of the set of active
1704 // labels requires nontrivial changes to the way scopes are 1707 // labels requires nontrivial changes to the way scopes are
1705 // structured. However, these are probably changes we want to 1708 // structured. However, these are probably changes we want to
1706 // make later anyway so we should go back and fix this then. 1709 // make later anyway so we should go back and fix this then.
1707 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { 1710 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
1708 SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS); 1711 SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS);
1709 const char* elms[2] = { "Label", *c_string }; 1712 const char* elms[2] = { "Label", *c_string };
(...skipping 2918 matching lines...) Expand 10 before | Expand all | Expand 10 after
4628 if (data >= symbol_data_end_) return -1; 4631 if (data >= symbol_data_end_) return -1;
4629 input = *data; 4632 input = *data;
4630 result = (result << 7) | (input & 0x7f); 4633 result = (result << 7) | (input & 0x7f);
4631 data++; 4634 data++;
4632 } 4635 }
4633 *source = data; 4636 *source = data;
4634 return result; 4637 return result;
4635 } 4638 }
4636 4639
4637 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
4638 // Preparse, but only collect data that is immediately useful, 4692 // Preparse, but only collect data that is immediately useful,
4639 // even if the preparser data is only used once. 4693 // even if the preparser data is only used once.
4640 ScriptDataImpl* ParserApi::PartialPreParse(Handle<String> source, 4694 ScriptDataImpl* ParserApi::PartialPreParse(Handle<String> source,
4641 unibrow::CharacterStream* stream, 4695 unibrow::CharacterStream* stream,
4642 v8::Extension* extension) { 4696 v8::Extension* extension) {
4643 Handle<Script> no_script; 4697 Handle<Script> no_script;
4644 bool allow_lazy = FLAG_lazy && (extension == NULL); 4698 bool allow_lazy = FLAG_lazy && (extension == NULL);
4645 if (!allow_lazy) { 4699 if (!allow_lazy) {
4646 // Partial preparsing is only about lazily compiled functions. 4700 // Partial preparsing is only about lazily compiled functions.
4647 // 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.
4648 return NULL; 4702 return NULL;
4649 } 4703 }
4650 preparser::PreParser<Scanner, PartialParserRecorder> parser;
4651 Scanner scanner;
4652 scanner.Initialize(source, stream, JAVASCRIPT);
4653 PartialParserRecorder recorder; 4704 PartialParserRecorder recorder;
4654 if (!parser.PreParseProgram(&scanner, &recorder, allow_lazy)) {
4655 Top::StackOverflow();
4656 return NULL;
4657 }
4658 4705
4659 // Extract the accumulated data from the recorder as a single 4706 return DoPreParse(source, stream, allow_lazy, &recorder);
4660 // contiguous vector that we are responsible for disposing.
4661 Vector<unsigned> store = recorder.ExtractData();
4662 return new ScriptDataImpl(store);
4663 } 4707 }
4664 4708
4665 4709
4666 ScriptDataImpl* ParserApi::PreParse(Handle<String> source, 4710 ScriptDataImpl* ParserApi::PreParse(Handle<String> source,
4667 unibrow::CharacterStream* stream, 4711 unibrow::CharacterStream* stream,
4668 v8::Extension* extension) { 4712 v8::Extension* extension) {
4669 Handle<Script> no_script; 4713 Handle<Script> no_script;
4670 preparser::PreParser<Scanner, CompleteParserRecorder> parser;
4671 Scanner scanner;
4672 scanner.Initialize(source, stream, JAVASCRIPT);
4673 bool allow_lazy = FLAG_lazy && (extension == NULL); 4714 bool allow_lazy = FLAG_lazy && (extension == NULL);
4674 CompleteParserRecorder recorder; 4715 CompleteParserRecorder recorder;
4675 if (!parser.PreParseProgram(&scanner, &recorder, allow_lazy)) { 4716 return DoPreParse(source, stream, allow_lazy, &recorder);
4676 Top::StackOverflow();
4677 return NULL;
4678 }
4679 // Extract the accumulated data from the recorder as a single
4680 // contiguous vector that we are responsible for disposing.
4681 Vector<unsigned> store = recorder.ExtractData();
4682 return new ScriptDataImpl(store);
4683 } 4717 }
4684 4718
4685 4719
4686 bool RegExpParser::ParseRegExp(FlatStringReader* input, 4720 bool RegExpParser::ParseRegExp(FlatStringReader* input,
4687 bool multiline, 4721 bool multiline,
4688 RegExpCompileData* result) { 4722 RegExpCompileData* result) {
4689 ASSERT(result != NULL); 4723 ASSERT(result != NULL);
4690 RegExpParser parser(input, &result->error, multiline); 4724 RegExpParser parser(input, &result->error, multiline);
4691 RegExpTree* tree = parser.ParsePattern(); 4725 RegExpTree* tree = parser.ParsePattern();
4692 if (parser.failed()) { 4726 if (parser.failed()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4732 Handle<String> source = Handle<String>(String::cast(script->source())); 4766 Handle<String> source = Handle<String>(String::cast(script->source()));
4733 result = parser.ParseProgram(source, info->is_global()); 4767 result = parser.ParseProgram(source, info->is_global());
4734 } 4768 }
4735 } 4769 }
4736 4770
4737 info->SetFunction(result); 4771 info->SetFunction(result);
4738 return (result != NULL); 4772 return (result != NULL);
4739 } 4773 }
4740 4774
4741 } } // namespace v8::internal 4775 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698