Revision: 5561
Author: [email protected]
Date: Thu Sep 30 02:28:58 2010
Log: Cleanup of the parser.
The lazy parsing functions took a host of arguments that can all be
derived from the SharedFunctionInfo, and the SharedFunctionInfo is
always available when parsing lazily. Change the interface to take a
single CompilationInfo or SharedFunctionInfo argument.
Also remove a flag in the parser that was always false when it was read.
Review URL: http://codereview.chromium.org/3538005
http://code.google.com/p/v8/source/detail?r=5561
Modified:
/branches/bleeding_edge/src/compiler.cc
/branches/bleeding_edge/src/parser.cc
/branches/bleeding_edge/src/parser.h
=======================================
--- /branches/bleeding_edge/src/compiler.cc Thu Sep 30 01:48:37 2010
+++ /branches/bleeding_edge/src/compiler.cc Thu Sep 30 02:28:58 2010
@@ -377,20 +377,12 @@
// Compute name, source code and script data.
Handle<SharedFunctionInfo> shared = info->shared_info();
- Handle<String> name(String::cast(shared->name()));
-
- int start_position = shared->start_position();
- int end_position = shared->end_position();
- bool is_expression = shared->is_expression();
- Counters::total_compile_size.Increment(end_position - start_position);
+ int compiled_size = shared->end_position() - shared->start_position();
+ Counters::total_compile_size.Increment(compiled_size);
// Generate the AST for the lazily compiled function. The AST may be
// NULL in case of parser stack overflow.
- FunctionLiteral* lit = MakeLazyAST(info->script(),
- name,
- start_position,
- end_position,
- is_expression);
+ FunctionLiteral* lit = MakeLazyAST(shared);
// Check for parse errors.
if (lit == NULL) {
@@ -414,9 +406,9 @@
}
RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG,
- name,
+ Handle<String>(String::cast(shared->name())),
Handle<String>(shared->inferred_name()),
- start_position,
+ shared->start_position(),
info->script(),
code);
=======================================
--- /branches/bleeding_edge/src/parser.cc Tue Sep 28 00:50:32 2010
+++ /branches/bleeding_edge/src/parser.cc Thu Sep 30 02:28:58 2010
@@ -115,11 +115,7 @@
// Returns NULL if parsing failed.
FunctionLiteral* ParseProgram(Handle<String> source,
bool in_global_context);
- FunctionLiteral* ParseLazy(Handle<String> source,
- Handle<String> name,
- int start_position,
- int end_position,
- bool is_expression);
+ FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info);
FunctionLiteral* ParseJson(Handle<String> source);
// The minimum number of contiguous assignment that will
@@ -1587,21 +1583,20 @@
}
-FunctionLiteral* Parser::ParseLazy(Handle<String> source,
- Handle<String> name,
- int start_position,
- int end_position,
- bool is_expression) {
+FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info) {
CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
HistogramTimerScope timer(&Counters::parse_lazy);
+ Handle<String> source(String::cast(script_->source()));
Counters::total_parse_size.Increment(source->length());
+ Handle<String> name(String::cast(info->name()));
fni_ = new FuncNameInferrer();
fni_->PushEnclosingName(name);
// Initialize parser state.
source->TryFlatten();
- scanner_.Initialize(source, start_position, end_position, JAVASCRIPT);
+ scanner_.Initialize(source, info->start_position(), info->end_position(),
+ JAVASCRIPT);
ASSERT(target_stack_ == NULL);
mode_ = PARSE_EAGERLY;
@@ -1616,7 +1611,8 @@
LexicalScope lexical_scope(this, scope);
TemporaryScope temp_scope(this);
- FunctionLiteralType type = is_expression ? EXPRESSION : DECLARATION;
+ FunctionLiteralType type =
+ info->is_expression() ? EXPRESSION : DECLARATION;
bool ok = true;
result = ParseFunctionLiteral(name, RelocInfo::kNoPosition, type, &ok);
// Make sure the results agree.
@@ -1636,6 +1632,7 @@
}
return result;
}
+
FunctionLiteral* Parser::ParseJson(Handle<String> source) {
CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
@@ -5475,12 +5472,6 @@
//
----------------------------------------------------------------------------
// The Parser interface.
-// MakeAST() is just a wrapper for the corresponding Parser calls
-// so we don't have to expose the entire Parser class in the .h file.
-
-static bool always_allow_natives_syntax = false;
-
-
ParserMessage::~ParserMessage() {
for (int i = 0; i < args().length(); i++)
DeleteArray(args()[i]);
@@ -5515,9 +5506,7 @@
v8::Extension* extension) {
Handle<Script> no_script;
bool allow_natives_syntax =
- always_allow_natives_syntax ||
- FLAG_allow_natives_syntax ||
- Bootstrapper::IsActive();
+ FLAG_allow_natives_syntax || Bootstrapper::IsActive();
PartialPreParser parser(no_script, allow_natives_syntax, extension);
if (!parser.PreParseProgram(source, stream)) return NULL;
// Extract the accumulated data from the recorder as a single
@@ -5575,9 +5564,7 @@
v8::Extension* extension) {
Handle<Script> no_script;
bool allow_natives_syntax =
- always_allow_natives_syntax ||
- FLAG_allow_natives_syntax ||
- Bootstrapper::IsActive();
+ FLAG_allow_natives_syntax || Bootstrapper::IsActive();
CompletePreParser parser(no_script, allow_natives_syntax, extension);
if (!parser.PreParseProgram(source, stream)) return NULL;
// Extract the accumulated data from the recorder as a single
@@ -5609,15 +5596,15 @@
}
+// MakeAST is just a wrapper for the corresponding Parser calls so we don't
+// have to expose the entire Parser class in the .h file.
FunctionLiteral* MakeAST(bool compile_in_global_context,
Handle<Script> script,
v8::Extension* extension,
ScriptDataImpl* pre_data,
bool is_json) {
bool allow_natives_syntax =
- always_allow_natives_syntax ||
- FLAG_allow_natives_syntax ||
- Bootstrapper::IsActive();
+ FLAG_allow_natives_syntax || Bootstrapper::IsActive();
AstBuildingParser parser(script, allow_natives_syntax, extension,
pre_data);
if (pre_data != NULL && pre_data->has_error()) {
Scanner::Location loc = pre_data->MessageLocation();
@@ -5643,20 +5630,10 @@
}
-FunctionLiteral* MakeLazyAST(Handle<Script> script,
- Handle<String> name,
- int start_position,
- int end_position,
- bool is_expression) {
- bool allow_natives_syntax_before = always_allow_natives_syntax;
- always_allow_natives_syntax = true;
- AstBuildingParser parser(script, true, NULL, NULL); // always allow
- always_allow_natives_syntax = allow_natives_syntax_before;
- // Parse the function by pointing to the function source in the script
source.
- Handle<String> script_source(String::cast(script->source()));
- FunctionLiteral* result =
- parser.ParseLazy(script_source, name,
- start_position, end_position, is_expression);
+FunctionLiteral* MakeLazyAST(Handle<SharedFunctionInfo> info) {
+ Handle<Script> script(Script::cast(info->script()));
+ AstBuildingParser parser(script, true, NULL, NULL);
+ FunctionLiteral* result = parser.ParseLazy(info);
return result;
}
=======================================
--- /branches/bleeding_edge/src/parser.h Thu Sep 30 00:22:53 2010
+++ /branches/bleeding_edge/src/parser.h Thu Sep 30 02:28:58 2010
@@ -192,20 +192,8 @@
RegExpCompileData* result);
-// Support for doing lazy compilation. The script is the script containing
full
-// source of the script where the function is declared. The start_position
and
-// end_position specifies the part of the script source which has the
source
-// for the function declaration in the form:
-//
-// (<formal parameters>) { <function body> }
-//
-// without any function keyword or name.
-//
-FunctionLiteral* MakeLazyAST(Handle<Script> script,
- Handle<String> name,
- int start_position,
- int end_position,
- bool is_expression);
+// Support for doing lazy compilation.
+FunctionLiteral* MakeLazyAST(Handle<SharedFunctionInfo> info);
// Support for handling complex values (array and object literals) that
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev