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

Side by Side Diff: src/parser.cc

Issue 165403: Streamline the scanner for external two byte string input. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 4 months 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
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 class Parser { 91 class Parser {
92 public: 92 public:
93 Parser(Handle<Script> script, bool allow_natives_syntax, 93 Parser(Handle<Script> script, bool allow_natives_syntax,
94 v8::Extension* extension, bool is_pre_parsing, 94 v8::Extension* extension, bool is_pre_parsing,
95 ParserFactory* factory, ParserLog* log, ScriptDataImpl* pre_data); 95 ParserFactory* factory, ParserLog* log, ScriptDataImpl* pre_data);
96 virtual ~Parser() { } 96 virtual ~Parser() { }
97 97
98 // Pre-parse the program from the character stream; returns true on 98 // Pre-parse the program from the character stream; returns true on
99 // success, false if a stack-overflow happened during parsing. 99 // success, false if a stack-overflow happened during parsing.
100 bool PreParseProgram(unibrow::CharacterStream* stream); 100 bool PreParseProgram(Handle<String> source, unibrow::CharacterStream* stream);
101 101
102 void ReportMessage(const char* message, Vector<const char*> args); 102 void ReportMessage(const char* message, Vector<const char*> args);
103 virtual void ReportMessageAt(Scanner::Location loc, 103 virtual void ReportMessageAt(Scanner::Location loc,
104 const char* message, 104 const char* message,
105 Vector<const char*> args) = 0; 105 Vector<const char*> args) = 0;
106 106
107 107
108 // Returns NULL if parsing failed. 108 // Returns NULL if parsing failed.
109 FunctionLiteral* ParseProgram(Handle<String> source, 109 FunctionLiteral* ParseProgram(Handle<String> source,
110 unibrow::CharacterStream* stream, 110 unibrow::CharacterStream* stream,
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 target_stack_(NULL), 1160 target_stack_(NULL),
1161 allow_natives_syntax_(allow_natives_syntax), 1161 allow_natives_syntax_(allow_natives_syntax),
1162 extension_(extension), 1162 extension_(extension),
1163 factory_(factory), 1163 factory_(factory),
1164 log_(log), 1164 log_(log),
1165 is_pre_parsing_(is_pre_parsing), 1165 is_pre_parsing_(is_pre_parsing),
1166 pre_data_(pre_data) { 1166 pre_data_(pre_data) {
1167 } 1167 }
1168 1168
1169 1169
1170 bool Parser::PreParseProgram(unibrow::CharacterStream* stream) { 1170 bool Parser::PreParseProgram(Handle<String> source,
1171 unibrow::CharacterStream* stream) {
1171 HistogramTimerScope timer(&Counters::pre_parse); 1172 HistogramTimerScope timer(&Counters::pre_parse);
1172 StackGuard guard; 1173 StackGuard guard;
1173 AssertNoZoneAllocation assert_no_zone_allocation; 1174 AssertNoZoneAllocation assert_no_zone_allocation;
1174 AssertNoAllocation assert_no_allocation; 1175 AssertNoAllocation assert_no_allocation;
1175 NoHandleAllocation no_handle_allocation; 1176 NoHandleAllocation no_handle_allocation;
1176 scanner_.Init(Handle<String>(), stream, 0); 1177 scanner_.Init(source, stream, 0);
1177 ASSERT(target_stack_ == NULL); 1178 ASSERT(target_stack_ == NULL);
1178 mode_ = PARSE_EAGERLY; 1179 mode_ = PARSE_EAGERLY;
1179 DummyScope top_scope; 1180 DummyScope top_scope;
1180 LexicalScope scope(this, &top_scope); 1181 LexicalScope scope(this, &top_scope);
1181 TemporaryScope temp_scope(this); 1182 TemporaryScope temp_scope(this);
1182 ZoneListWrapper<Statement> processor; 1183 ZoneListWrapper<Statement> processor;
1183 bool ok = true; 1184 bool ok = true;
1184 ParseSourceElements(&processor, Token::EOS, &ok); 1185 ParseSourceElements(&processor, Token::EOS, &ok);
1185 return !scanner().stack_overflow(); 1186 return !scanner().stack_overflow();
1186 } 1187 }
(...skipping 3399 matching lines...) Expand 10 before | Expand all | Expand 10 after
4586 int ScriptDataImpl::Length() { 4587 int ScriptDataImpl::Length() {
4587 return store_.length(); 4588 return store_.length();
4588 } 4589 }
4589 4590
4590 4591
4591 unsigned* ScriptDataImpl::Data() { 4592 unsigned* ScriptDataImpl::Data() {
4592 return store_.start(); 4593 return store_.start();
4593 } 4594 }
4594 4595
4595 4596
4596 ScriptDataImpl* PreParse(unibrow::CharacterStream* stream, 4597 ScriptDataImpl* PreParse(Handle<String> source,
4598 unibrow::CharacterStream* stream,
4597 v8::Extension* extension) { 4599 v8::Extension* extension) {
4598 Handle<Script> no_script; 4600 Handle<Script> no_script;
4599 bool allow_natives_syntax = 4601 bool allow_natives_syntax =
4600 always_allow_natives_syntax || 4602 always_allow_natives_syntax ||
4601 FLAG_allow_natives_syntax || 4603 FLAG_allow_natives_syntax ||
4602 Bootstrapper::IsActive(); 4604 Bootstrapper::IsActive();
4603 PreParser parser(no_script, allow_natives_syntax, extension); 4605 PreParser parser(no_script, allow_natives_syntax, extension);
4604 if (!parser.PreParseProgram(stream)) return NULL; 4606 if (!parser.PreParseProgram(source, stream)) return NULL;
4605 // The list owns the backing store so we need to clone the vector. 4607 // The list owns the backing store so we need to clone the vector.
4606 // That way, the result will be exactly the right size rather than 4608 // That way, the result will be exactly the right size rather than
4607 // the expected 50% too large. 4609 // the expected 50% too large.
4608 Vector<unsigned> store = parser.recorder()->store()->ToVector().Clone(); 4610 Vector<unsigned> store = parser.recorder()->store()->ToVector().Clone();
4609 return new ScriptDataImpl(store); 4611 return new ScriptDataImpl(store);
4610 } 4612 }
4611 4613
4612 4614
4613 bool ParseRegExp(FlatStringReader* input, 4615 bool ParseRegExp(FlatStringReader* input,
4614 bool multiline, 4616 bool multiline,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
4679 start_position, 4681 start_position,
4680 is_expression); 4682 is_expression);
4681 return result; 4683 return result;
4682 } 4684 }
4683 4685
4684 4686
4685 #undef NEW 4687 #undef NEW
4686 4688
4687 4689
4688 } } // namespace v8::internal 4690 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698