From 7f764978ee5008c04694e3a8fc97a872fa2a6537 Mon Sep 17 00:00:00 2001 From: "lrn@chromium.org" Date: Tue, 2 Nov 2010 11:45:47 +0000 Subject: [PATCH] Remove old preparser option and behavior from the parser. Review URL: http://codereview.chromium.org/4244003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5752 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compiler.cc | 1 - src/parser.cc | 811 ++++++++++++++++++-------------------------------------- src/parser.h | 180 ++++++------- src/scanner.h | 1 - 4 files changed, 353 insertions(+), 640 deletions(-) diff --git a/src/compiler.cc b/src/compiler.cc index 6f02960..29bbbc7 100755 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -279,7 +279,6 @@ Handle Compiler::Compile(Handle source, // in that case too. ScriptDataImpl* pre_data = input_pre_data; if (pre_data == NULL - && FLAG_lazy && source_length >= FLAG_min_preparse_length) { pre_data = ParserApi::PartialPreParse(source, NULL, extension); } diff --git a/src/parser.cc b/src/parser.cc index 796283e..a0f3b71 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -39,7 +39,6 @@ #include "preparser.h" #include "runtime.h" #include "scopeinfo.h" -#include "scopes.h" #include "string-stream.h" #include "ast-inl.h" @@ -324,144 +323,37 @@ TemporaryScope::~TemporaryScope() { } -// A zone list wrapper lets code either access a access a zone list -// or appear to do so while actually ignoring all operations. -template -class ZoneListWrapper { - public: - ZoneListWrapper() : list_(NULL) { } - explicit ZoneListWrapper(int size) : list_(new ZoneList(size)) { } - void Add(T* that) { if (list_) list_->Add(that); } - int length() { return list_->length(); } - ZoneList* elements() { return list_; } - T* at(int index) { return list_->at(index); } - private: - ZoneList* list_; -}; - - -// Allocation macro that should be used to allocate objects that must -// only be allocated in real parsing mode. Note that in preparse mode -// not only is the syntax tree not created but the constructor -// arguments are not evaluated. -#define NEW(expr) (is_pre_parsing_ ? NULL : new expr) - - -class ParserFactory BASE_EMBEDDED { - public: - explicit ParserFactory(bool is_pre_parsing) : - is_pre_parsing_(is_pre_parsing) { } - - virtual ~ParserFactory() { } - - virtual Scope* NewScope(Scope* parent, Scope::Type type, bool inside_with); - - virtual Handle LookupSymbol(int index, Vector string) { - return Handle(); - } - - virtual Handle EmptySymbol() { - return Handle(); - } - - virtual Expression* NewProperty(Expression* obj, Expression* key, int pos) { - if (obj == VariableProxySentinel::this_proxy()) { - return Property::this_property(); - } else { - return ValidLeftHandSideSentinel::instance(); - } - } - - virtual Expression* NewCall(Expression* expression, - ZoneList* arguments, - int pos) { - return Call::sentinel(); - } - - virtual Statement* EmptyStatement() { - return NULL; - } - - template ZoneListWrapper NewList(int size) { - return is_pre_parsing_ ? ZoneListWrapper() : ZoneListWrapper(size); - } - - private: - bool is_pre_parsing_; -}; - - -class ConditionalLogPauseScope { - public: - ConditionalLogPauseScope(bool pause, ParserLog* log) - : log_(log), pause_(pause) { - if (pause) log->PauseRecording(); - } - ~ConditionalLogPauseScope() { - if (pause_) log_->ResumeRecording(); - } - private: - ParserLog* log_; - bool pause_; -}; - - -class AstBuildingParserFactory : public ParserFactory { - public: - explicit AstBuildingParserFactory(int expected_symbols) - : ParserFactory(false), symbol_cache_(expected_symbols) { } - - virtual Scope* NewScope(Scope* parent, Scope::Type type, bool inside_with); - - virtual Handle LookupSymbol(int symbol_id, - Vector string) { - // Length of symbol cache is the number of identified symbols. - // If we are larger than that, or negative, it's not a cached symbol. - // This might also happen if there is no preparser symbol data, even - // if there is some preparser data. - if (static_cast(symbol_id) - >= static_cast(symbol_cache_.length())) { - return Factory::LookupSymbol(string); - } - return LookupCachedSymbol(symbol_id, string); - } - - Handle LookupCachedSymbol(int symbol_id, +Handle Parser::LookupSymbol(int symbol_id, Vector string) { - // Make sure the cache is large enough to hold the symbol identifier. - if (symbol_cache_.length() <= symbol_id) { - // Increase length to index + 1. - symbol_cache_.AddBlock(Handle::null(), - symbol_id + 1 - symbol_cache_.length()); - } - Handle result = symbol_cache_.at(symbol_id); - if (result.is_null()) { - result = Factory::LookupSymbol(string); - symbol_cache_.at(symbol_id) = result; - return result; - } - Counters::total_preparse_symbols_skipped.Increment(); + // Length of symbol cache is the number of identified symbols. + // If we are larger than that, or negative, it's not a cached symbol. + // This might also happen if there is no preparser symbol data, even + // if there is some preparser data. + if (static_cast(symbol_id) + >= static_cast(symbol_cache_.length())) { + return Factory::LookupSymbol(string); + } + return LookupCachedSymbol(symbol_id, string); +} + + +Handle Parser::LookupCachedSymbol(int symbol_id, + Vector string) { + // Make sure the cache is large enough to hold the symbol identifier. + if (symbol_cache_.length() <= symbol_id) { + // Increase length to index + 1. + symbol_cache_.AddBlock(Handle::null(), + symbol_id + 1 - symbol_cache_.length()); + } + Handle result = symbol_cache_.at(symbol_id); + if (result.is_null()) { + result = Factory::LookupSymbol(string); + symbol_cache_.at(symbol_id) = result; return result; } - - virtual Handle EmptySymbol() { - return Factory::empty_symbol(); - } - - virtual Expression* NewProperty(Expression* obj, Expression* key, int pos) { - return new Property(obj, key, pos); - } - - virtual Expression* NewCall(Expression* expression, - ZoneList* arguments, - int pos) { - return new Call(expression, arguments, pos); - } - - virtual Statement* EmptyStatement(); - private: - List > symbol_cache_; -}; + Counters::total_preparse_symbols_skipped.Increment(); + return result; +} Vector PartialParserRecorder::ExtractData() { @@ -523,8 +415,6 @@ Vector CompleteParserRecorder::ExtractData() { } - - FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) { // The current pre-data entry must be a FunctionEntry with the given // start position. @@ -704,108 +594,12 @@ unsigned* ScriptDataImpl::ReadAddress(int position) { } -class AstBuildingParser : public Parser { - public: - AstBuildingParser(Handle