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

Unified Diff: src/parser.cc

Issue 4343003: Version 2.5.4 (Closed)
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.h ('k') | src/platform-linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index aad7a615a514bd3427d18d8f1504b2acfdf514c4..a0f3b7147f20eda1457d4f41276c550d70b2b612 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -36,9 +36,9 @@
#include "messages.h"
#include "parser.h"
#include "platform.h"
+#include "preparser.h"
#include "runtime.h"
#include "scopeinfo.h"
-#include "scopes.h"
#include "string-stream.h"
#include "ast-inl.h"
@@ -323,302 +323,96 @@ 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 <typename T>
-class ZoneListWrapper {
- public:
- ZoneListWrapper() : list_(NULL) { }
- explicit ZoneListWrapper(int size) : list_(new ZoneList<T*>(size)) { }
- void Add(T* that) { if (list_) list_->Add(that); }
- int length() { return list_->length(); }
- ZoneList<T*>* elements() { return list_; }
- T* at(int index) { return list_->at(index); }
- private:
- ZoneList<T*>* 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<String> LookupSymbol(int index, Vector<const char> string) {
- return Handle<String>();
- }
-
- virtual Handle<String> EmptySymbol() {
- return Handle<String>();
- }
-
- 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<Expression*>* arguments,
- int pos) {
- return Call::sentinel();
- }
-
- virtual Statement* EmptyStatement() {
- return NULL;
- }
-
- template <typename T> ZoneListWrapper<T> NewList(int size) {
- return is_pre_parsing_ ? ZoneListWrapper<T>() : ZoneListWrapper<T>(size);
- }
-
- private:
- bool is_pre_parsing_;
-};
-
-
-class ParserLog BASE_EMBEDDED {
- public:
- virtual ~ParserLog() { }
-
- // Records the occurrence of a function.
- virtual FunctionEntry LogFunction(int start) { return FunctionEntry(); }
- virtual void LogSymbol(int start, Vector<const char> symbol) {}
- virtual void LogError() { }
- // Return the current position in the function entry log.
- virtual int function_position() { return 0; }
- virtual int symbol_position() { return 0; }
- virtual int symbol_ids() { return 0; }
- virtual void PauseRecording() {}
- virtual void ResumeRecording() {}
- virtual Vector<unsigned> ExtractData() {
- return Vector<unsigned>();
- };
-};
-
-
-
-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<String> LookupSymbol(int symbol_id,
- Vector<const char> 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<unsigned>(symbol_id)
- >= static_cast<unsigned>(symbol_cache_.length())) {
- return Factory::LookupSymbol(string);
- }
- return LookupCachedSymbol(symbol_id, string);
- }
-
- Handle<String> LookupCachedSymbol(int symbol_id,
+Handle<String> Parser::LookupSymbol(int symbol_id,
Vector<const char> 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<String>::null(),
- symbol_id + 1 - symbol_cache_.length());
- }
- Handle<String> 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<unsigned>(symbol_id)
+ >= static_cast<unsigned>(symbol_cache_.length())) {
+ return Factory::LookupSymbol(string);
+ }
+ return LookupCachedSymbol(symbol_id, string);
+}
+
+
+Handle<String> Parser::LookupCachedSymbol(int symbol_id,
+ Vector<const char> 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<String>::null(),
+ symbol_id + 1 - symbol_cache_.length());
+ }
+ Handle<String> result = symbol_cache_.at(symbol_id);
+ if (result.is_null()) {
+ result = Factory::LookupSymbol(string);
+ symbol_cache_.at(symbol_id) = result;
return result;
}
-
- virtual Handle<String> 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<Expression*>* arguments,
- int pos) {
- return new Call(expression, arguments, pos);
- }
-
- virtual Statement* EmptyStatement();
- private:
- List<Handle<String> > symbol_cache_;
-};
+ Counters::total_preparse_symbols_skipped.Increment();
+ return result;
+}
-// Record only functions.
-class PartialParserRecorder: public ParserLog {
- public:
- PartialParserRecorder();
- virtual FunctionEntry LogFunction(int start);
-
- virtual int function_position() { return function_store_.size(); }
-
- virtual void LogError() { }
-
- virtual void LogMessage(Scanner::Location loc,
- const char* message,
- Vector<const char*> args);
-
- virtual Vector<unsigned> ExtractData() {
- int function_size = function_store_.size();
- int total_size = ScriptDataImpl::kHeaderSize + function_size;
- Vector<unsigned> data = Vector<unsigned>::New(total_size);
- preamble_[ScriptDataImpl::kFunctionsSizeOffset] = function_size;
- preamble_[ScriptDataImpl::kSymbolCountOffset] = 0;
- memcpy(data.start(), preamble_, sizeof(preamble_));
- int symbol_start = ScriptDataImpl::kHeaderSize + function_size;
- if (function_size > 0) {
- function_store_.WriteTo(data.SubVector(ScriptDataImpl::kHeaderSize,
- symbol_start));
- }
- return data;
+Vector<unsigned> PartialParserRecorder::ExtractData() {
+ int function_size = function_store_.size();
+ int total_size = ScriptDataImpl::kHeaderSize + function_size;
+ Vector<unsigned> data = Vector<unsigned>::New(total_size);
+ preamble_[ScriptDataImpl::kFunctionsSizeOffset] = function_size;
+ preamble_[ScriptDataImpl::kSymbolCountOffset] = 0;
+ memcpy(data.start(), preamble_, sizeof(preamble_));
+ int symbol_start = ScriptDataImpl::kHeaderSize + function_size;
+ if (function_size > 0) {
+ function_store_.WriteTo(data.SubVector(ScriptDataImpl::kHeaderSize,
+ symbol_start));
}
+ return data;
+}
- virtual void PauseRecording() {
- pause_count_++;
- is_recording_ = false;
- }
- virtual void ResumeRecording() {
- ASSERT(pause_count_ > 0);
- if (--pause_count_ == 0) is_recording_ = !has_error();
- }
+void CompleteParserRecorder::LogSymbol(int start, Vector<const char> literal) {
+ if (!is_recording_) return;
- protected:
- bool has_error() {
- return static_cast<bool>(preamble_[ScriptDataImpl::kHasErrorOffset]);
- }
- bool is_recording() {
- return is_recording_;
+ int hash = vector_hash(literal);
+ HashMap::Entry* entry = symbol_table_.Lookup(&literal, hash, true);
+ int id = static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
+ if (id == 0) {
+ // Put (symbol_id_ + 1) into entry and increment it.
+ id = ++symbol_id_;
+ entry->value = reinterpret_cast<void*>(id);
+ Vector<Vector<const char> > symbol = symbol_entries_.AddBlock(1, literal);
+ entry->key = &symbol[0];
}
-
- void WriteString(Vector<const char> str);
-
- Collector<unsigned> function_store_;
- unsigned preamble_[ScriptDataImpl::kHeaderSize];
- bool is_recording_;
- int pause_count_;
-
-#ifdef DEBUG
- int prev_start;
-#endif
-};
+ WriteNumber(id - 1);
+}
-// Record both functions and symbols.
-class CompleteParserRecorder: public PartialParserRecorder {
- public:
- CompleteParserRecorder();
-
- virtual void LogSymbol(int start, Vector<const char> literal) {
- if (!is_recording_) return;
- int hash = vector_hash(literal);
- HashMap::Entry* entry = symbol_table_.Lookup(&literal, hash, true);
- int id = static_cast<int>(reinterpret_cast<intptr_t>(entry->value));
- if (id == 0) {
- // Put (symbol_id_ + 1) into entry and increment it.
- id = ++symbol_id_;
- entry->value = reinterpret_cast<void*>(id);
- Vector<Vector<const char> > symbol = symbol_entries_.AddBlock(1, literal);
- entry->key = &symbol[0];
- }
- WriteNumber(id - 1);
- }
-
- virtual Vector<unsigned> ExtractData() {
- int function_size = function_store_.size();
- // Add terminator to symbols, then pad to unsigned size.
- int symbol_size = symbol_store_.size();
- int padding = sizeof(unsigned) - (symbol_size % sizeof(unsigned));
- symbol_store_.AddBlock(padding, ScriptDataImpl::kNumberTerminator);
- symbol_size += padding;
- int total_size = ScriptDataImpl::kHeaderSize + function_size
- + (symbol_size / sizeof(unsigned));
- Vector<unsigned> data = Vector<unsigned>::New(total_size);
- preamble_[ScriptDataImpl::kFunctionsSizeOffset] = function_size;
- preamble_[ScriptDataImpl::kSymbolCountOffset] = symbol_id_;
- memcpy(data.start(), preamble_, sizeof(preamble_));
- int symbol_start = ScriptDataImpl::kHeaderSize + function_size;
- if (function_size > 0) {
- function_store_.WriteTo(data.SubVector(ScriptDataImpl::kHeaderSize,
- symbol_start));
- }
- if (!has_error()) {
- symbol_store_.WriteTo(
- Vector<byte>::cast(data.SubVector(symbol_start, total_size)));
- }
- return data;
+Vector<unsigned> CompleteParserRecorder::ExtractData() {
+ int function_size = function_store_.size();
+ // Add terminator to symbols, then pad to unsigned size.
+ int symbol_size = symbol_store_.size();
+ int padding = sizeof(unsigned) - (symbol_size % sizeof(unsigned));
+ symbol_store_.AddBlock(padding, ScriptDataImpl::kNumberTerminator);
+ symbol_size += padding;
+ int total_size = ScriptDataImpl::kHeaderSize + function_size
+ + (symbol_size / sizeof(unsigned));
+ Vector<unsigned> data = Vector<unsigned>::New(total_size);
+ preamble_[ScriptDataImpl::kFunctionsSizeOffset] = function_size;
+ preamble_[ScriptDataImpl::kSymbolCountOffset] = symbol_id_;
+ memcpy(data.start(), preamble_, sizeof(preamble_));
+ int symbol_start = ScriptDataImpl::kHeaderSize + function_size;
+ if (function_size > 0) {
+ function_store_.WriteTo(data.SubVector(ScriptDataImpl::kHeaderSize,
+ symbol_start));
}
-
- virtual int symbol_position() { return symbol_store_.size(); }
- virtual int symbol_ids() { return symbol_id_; }
- private:
- static int vector_hash(Vector<const char> string) {
- int hash = 0;
- for (int i = 0; i < string.length(); i++) {
- int c = string[i];
- hash += c;
- hash += (hash << 10);
- hash ^= (hash >> 6);
- }
- return hash;
+ if (!has_error()) {
+ symbol_store_.WriteTo(
+ Vector<byte>::cast(data.SubVector(symbol_start, total_size)));
}
-
- static bool vector_compare(void* a, void* b) {
- Vector<const char>* string1 = reinterpret_cast<Vector<const char>* >(a);
- Vector<const char>* string2 = reinterpret_cast<Vector<const char>* >(b);
- int length = string1->length();
- if (string2->length() != length) return false;
- return memcmp(string1->start(), string2->start(), length) == 0;
- }
-
- // Write a non-negative number to the symbol store.
- void WriteNumber(int number);
-
- Collector<byte> symbol_store_;
- Collector<Vector<const char> > symbol_entries_;
- HashMap symbol_table_;
- int symbol_id_;
-};
+ return data;
+}
FunctionEntry ScriptDataImpl::GetFunctionEntry(int start) {
@@ -691,7 +485,7 @@ PartialParserRecorder::PartialParserRecorder()
preamble_[ScriptDataImpl::kSizeOffset] = 0;
ASSERT_EQ(6, ScriptDataImpl::kHeaderSize);
#ifdef DEBUG
- prev_start = -1;
+ prev_start_ = -1;
#endif
}
@@ -742,8 +536,8 @@ const char* ScriptDataImpl::ReadString(unsigned* start, int* chars) {
void PartialParserRecorder::LogMessage(Scanner::Location loc,
- const char* message,
- Vector<const char*> args) {
+ const char* message,
+ Vector<const char*> args) {
if (has_error()) return;
preamble_[ScriptDataImpl::kHasErrorOffset] = true;
function_store_.Reset();
@@ -800,120 +594,12 @@ unsigned* ScriptDataImpl::ReadAddress(int position) {
}
-FunctionEntry PartialParserRecorder::LogFunction(int start) {
-#ifdef DEBUG
- ASSERT(start > prev_start);
- prev_start = start;
-#endif
- if (!is_recording_) return FunctionEntry();
- FunctionEntry result(function_store_.AddBlock(FunctionEntry::kSize, 0));
- result.set_start_pos(start);
- return result;
-}
-
-
-class AstBuildingParser : public Parser {
- public:
- AstBuildingParser(Handle<Script> script, bool allow_natives_syntax,
- v8::Extension* extension, ScriptDataImpl* pre_data)
- : Parser(script,
- allow_natives_syntax,
- extension,
- PARSE,
- factory(),
- log(),
- pre_data),
- factory_(pre_data ? pre_data->symbol_count() : 0) { }
- virtual void ReportMessageAt(Scanner::Location loc, const char* message,
- Vector<const char*> args);
- virtual VariableProxy* Declare(Handle<String> name, Variable::Mode mode,
- FunctionLiteral* fun, bool resolve, bool* ok);
- AstBuildingParserFactory* factory() { return &factory_; }
- ParserLog* log() { return &log_; }
-
- private:
- ParserLog log_;
- AstBuildingParserFactory factory_;
-};
-
-
-class PreParser : public Parser {
- public:
- PreParser(Handle<Script> script, bool allow_natives_syntax,
- v8::Extension* extension, ParserLog* recorder)
- : Parser(script, allow_natives_syntax, extension, PREPARSE,
- factory(), recorder, NULL),
- factory_(true) { }
- virtual void ReportMessageAt(Scanner::Location loc, const char* message,
- Vector<const char*> args);
- virtual VariableProxy* Declare(Handle<String> name, Variable::Mode mode,
- FunctionLiteral* fun, bool resolve, bool* ok);
- ParserFactory* factory() { return &factory_; }
- virtual PartialParserRecorder* recorder() = 0;
-
- private:
- ParserFactory factory_;
-};
-
-
-class CompletePreParser : public PreParser {
- public:
- CompletePreParser(Handle<Script> script, bool allow_natives_syntax,
- v8::Extension* extension)
- : PreParser(script, allow_natives_syntax, extension, &recorder_),
- recorder_() { }
- virtual PartialParserRecorder* recorder() { return &recorder_; }
- private:
- CompleteParserRecorder recorder_;
-};
-
-
-class PartialPreParser : public PreParser {
- public:
- PartialPreParser(Handle<Script> script, bool allow_natives_syntax,
- v8::Extension* extension)
- : PreParser(script, allow_natives_syntax, extension, &recorder_),
- recorder_() { }
- virtual PartialParserRecorder* recorder() { return &recorder_; }
- private:
- PartialParserRecorder recorder_;
-};
-
-
-Scope* AstBuildingParserFactory::NewScope(Scope* parent, Scope::Type type,
- bool inside_with) {
+Scope* Parser::NewScope(Scope* parent, Scope::Type type, bool inside_with) {
Scope* result = new Scope(parent, type);
result->Initialize(inside_with);
return result;
}
-
-Statement* AstBuildingParserFactory::EmptyStatement() {
- // Use a statically allocated empty statement singleton to avoid
- // allocating lots and lots of empty statements.
- static v8::internal::EmptyStatement empty;
- return &empty;
-}
-
-
-Scope* ParserFactory::NewScope(Scope* parent, Scope::Type type,
- bool inside_with) {
- ASSERT(parent != NULL);
- parent->type_ = type;
- // Initialize function is hijacked by DummyScope to increment scope depth.
- parent->Initialize(inside_with);
- return parent;
-}
-
-
-VariableProxy* PreParser::Declare(Handle<String> name, Variable::Mode mode,
- FunctionLiteral* fun, bool resolve,
- bool* ok) {
- return NULL;
-}
-
-
-
// ----------------------------------------------------------------------------
// Target is a support class to facilitate manipulation of the
// Parser's target_stack_ (the stack of potential 'break' and
@@ -1016,11 +702,9 @@ class LexicalScope BASE_EMBEDDED {
Parser::Parser(Handle<Script> script,
bool allow_natives_syntax,
v8::Extension* extension,
- ParserMode is_pre_parsing,
- ParserFactory* factory,
- ParserLog* log,
ScriptDataImpl* pre_data)
- : script_(script),
+ : symbol_cache_(pre_data ? pre_data->symbol_count() : 0),
+ script_(script),
scanner_(),
top_scope_(NULL),
with_nesting_level_(0),
@@ -1028,34 +712,11 @@ Parser::Parser(Handle<Script> script,
target_stack_(NULL),
allow_natives_syntax_(allow_natives_syntax),
extension_(extension),
- factory_(factory),
- log_(log),
- is_pre_parsing_(is_pre_parsing == PREPARSE),
pre_data_(pre_data),
fni_(NULL) {
}
-bool Parser::PreParseProgram(Handle<String> source,
- unibrow::CharacterStream* stream) {
- HistogramTimerScope timer(&Counters::pre_parse);
- AssertNoZoneAllocation assert_no_zone_allocation;
- AssertNoAllocation assert_no_allocation;
- NoHandleAllocation no_handle_allocation;
- scanner_.Initialize(source, stream, JAVASCRIPT);
- ASSERT(target_stack_ == NULL);
- mode_ = FLAG_lazy ? PARSE_LAZILY : PARSE_EAGERLY;
- if (allow_natives_syntax_ || extension_ != NULL) mode_ = PARSE_EAGERLY;
- DummyScope top_scope;
- LexicalScope scope(&this->top_scope_, &this->with_nesting_level_, &top_scope);
- TemporaryScope temp_scope(&this->temp_scope_);
- ZoneListWrapper<Statement> processor;
- bool ok = true;
- ParseSourceElements(&processor, Token::EOS, &ok);
- return !scanner().stack_overflow();
-}
-
-
FunctionLiteral* Parser::ParseProgram(Handle<String> source,
bool in_global_context) {
CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
@@ -1078,21 +739,21 @@ FunctionLiteral* Parser::ParseProgram(Handle<String> source,
in_global_context
? Scope::GLOBAL_SCOPE
: Scope::EVAL_SCOPE;
- Handle<String> no_name = factory()->EmptySymbol();
+ Handle<String> no_name = Factory::empty_symbol();
FunctionLiteral* result = NULL;
- { Scope* scope = factory()->NewScope(top_scope_, type, inside_with());
+ { Scope* scope = NewScope(top_scope_, type, inside_with());
LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
scope);
TemporaryScope temp_scope(&this->temp_scope_);
- ZoneListWrapper<Statement> body(16);
+ ZoneList<Statement*>* body = new ZoneList<Statement*>(16);
bool ok = true;
- ParseSourceElements(&body, Token::EOS, &ok);
+ ParseSourceElements(body, Token::EOS, &ok);
if (ok) {
- result = NEW(FunctionLiteral(
+ result = new FunctionLiteral(
no_name,
top_scope_,
- body.elements(),
+ body,
temp_scope.materialized_literal_count(),
temp_scope.expected_property_count(),
temp_scope.only_simple_this_property_assignments(),
@@ -1101,7 +762,7 @@ FunctionLiteral* Parser::ParseProgram(Handle<String> source,
0,
source->length(),
false,
- temp_scope.ContainsLoops()));
+ temp_scope.ContainsLoops());
} else if (scanner().stack_overflow()) {
Top::StackOverflow();
}
@@ -1139,9 +800,9 @@ FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info) {
{
// Parse the function literal.
- Handle<String> no_name = factory()->EmptySymbol();
+ Handle<String> no_name = Factory::empty_symbol();
Scope* scope =
- factory()->NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with());
+ NewScope(top_scope_, Scope::GLOBAL_SCOPE, inside_with());
LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
scope);
TemporaryScope temp_scope(&this->temp_scope_);
@@ -1169,28 +830,24 @@ FunctionLiteral* Parser::ParseLazy(Handle<SharedFunctionInfo> info) {
}
-void Parser::ReportMessage(const char* type, Vector<const char*> args) {
- Scanner::Location source_location = scanner_.location();
- ReportMessageAt(source_location, type, args);
-}
-
-
Handle<String> Parser::GetSymbol(bool* ok) {
- if (is_pre_parsing_) {
- log()->LogSymbol(scanner_.location().beg_pos, scanner_.literal());
- return Handle<String>::null();
- }
int symbol_id = -1;
if (pre_data() != NULL) {
symbol_id = pre_data()->GetSymbolIdentifier();
}
- return factory()->LookupSymbol(symbol_id, scanner_.literal());
+ return LookupSymbol(symbol_id, scanner_.literal());
}
-void AstBuildingParser::ReportMessageAt(Scanner::Location source_location,
- const char* type,
- Vector<const char*> args) {
+void Parser::ReportMessage(const char* type, Vector<const char*> args) {
+ Scanner::Location source_location = scanner_.location();
+ ReportMessageAt(source_location, type, args);
+}
+
+
+void Parser::ReportMessageAt(Scanner::Location source_location,
+ const char* type,
+ Vector<const char*> args) {
MessageLocation location(script_,
source_location.beg_pos, source_location.end_pos);
Handle<JSArray> array = Factory::NewJSArray(args.length());
@@ -1202,13 +859,6 @@ void AstBuildingParser::ReportMessageAt(Scanner::Location source_location,
}
-void PreParser::ReportMessageAt(Scanner::Location source_location,
- const char* type,
- Vector<const char*> args) {
- recorder()->LogMessage(source_location, type, args);
-}
-
-
// Base class containing common code for the different finder classes used by
// the parser.
class ParserFinder {
@@ -1250,6 +900,11 @@ class InitializationBlockFinder : public ParserFinder {
}
private:
+ // The minimum number of contiguous assignment that will
+ // be treated as an initialization block. Benchmarks show that
+ // the overhead exceeds the savings below this limit.
+ static const int kMinInitializationBlock = 3;
+
// Returns true if the expressions appear to denote the same object.
// In the context of initialization blocks, we only consider expressions
// of the form 'expr.x' or expr["x"].
@@ -1302,7 +957,7 @@ class InitializationBlockFinder : public ParserFinder {
}
void EndBlock() {
- if (block_size_ >= Parser::kMinInitializationBlock) {
+ if (block_size_ >= kMinInitializationBlock) {
first_in_block_->mark_block_start();
last_in_block_->mark_block_end();
}
@@ -1460,7 +1115,7 @@ class ThisNamedPropertyAssigmentFinder : public ParserFinder {
};
-void* Parser::ParseSourceElements(ZoneListWrapper<Statement>* processor,
+void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
int end_token,
bool* ok) {
// SourceElements ::
@@ -1492,7 +1147,7 @@ void* Parser::ParseSourceElements(ZoneListWrapper<Statement>* processor,
}
// Propagate the collected information on this property assignments.
- if (!is_pre_parsing_ && top_scope_->is_function_scope()) {
+ if (top_scope_->is_function_scope()) {
bool only_simple_this_property_assignments =
this_property_assignment_finder.only_simple_this_property_assignments()
&& top_scope_->declarations()->length() == 0;
@@ -1545,7 +1200,7 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) {
case Token::SEMICOLON:
Next();
- return factory()->EmptyStatement();
+ return EmptyStatement();
case Token::IF:
stmt = ParseIfStatement(labels, ok);
@@ -1593,7 +1248,7 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) {
// one must take great care not to treat it as a
// fall-through. It is much easier just to wrap the entire
// try-statement in a statement block and put the labels there
- Block* result = NEW(Block(labels, 1, false));
+ Block* result = new Block(labels, 1, false);
Target target(&this->target_stack_, result);
TryStatement* statement = ParseTryStatement(CHECK_OK);
if (statement) {
@@ -1623,11 +1278,11 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) {
}
-VariableProxy* AstBuildingParser::Declare(Handle<String> name,
- Variable::Mode mode,
- FunctionLiteral* fun,
- bool resolve,
- bool* ok) {
+VariableProxy* Parser::Declare(Handle<String> name,
+ Variable::Mode mode,
+ FunctionLiteral* fun,
+ bool resolve,
+ bool* ok) {
Variable* var = NULL;
// If we are inside a function, a declaration of a variable
// is a truly local variable, and the scope of the variable
@@ -1682,13 +1337,13 @@ VariableProxy* AstBuildingParser::Declare(Handle<String> name,
// a performance issue since it may lead to repeated
// Runtime::DeclareContextSlot() calls.
VariableProxy* proxy = top_scope_->NewUnresolved(name, inside_with());
- top_scope_->AddDeclaration(NEW(Declaration(proxy, mode, fun)));
+ top_scope_->AddDeclaration(new Declaration(proxy, mode, fun));
// For global const variables we bind the proxy to a variable.
if (mode == Variable::CONST && top_scope_->is_global_scope()) {
ASSERT(resolve); // should be set by all callers
Variable::Kind kind = Variable::NORMAL;
- var = NEW(Variable(top_scope_, name, Variable::CONST, true, kind));
+ var = new Variable(top_scope_, name, Variable::CONST, true, kind);
}
// If requested and we have a local variable, bind the proxy to the variable
@@ -1740,13 +1395,13 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) {
while (!done) {
ParseIdentifier(CHECK_OK);
done = (peek() == Token::RPAREN);
- if (!done) Expect(Token::COMMA, CHECK_OK);
+ if (!done) {
+ Expect(Token::COMMA, CHECK_OK);
+ }
}
Expect(Token::RPAREN, CHECK_OK);
Expect(Token::SEMICOLON, CHECK_OK);
- if (is_pre_parsing_) return NULL;
-
// Make sure that the function containing the native declaration
// isn't lazily compiled. The extension structures are only
// accessible while parsing the first time not when reparsing
@@ -1776,10 +1431,10 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) {
// TODO(1240846): It's weird that native function declarations are
// introduced dynamically when we meet their declarations, whereas
// other functions are setup when entering the surrounding scope.
- SharedFunctionInfoLiteral* lit = NEW(SharedFunctionInfoLiteral(shared));
+ SharedFunctionInfoLiteral* lit = new SharedFunctionInfoLiteral(shared);
VariableProxy* var = Declare(name, Variable::VAR, NULL, true, CHECK_OK);
- return NEW(ExpressionStatement(
- new Assignment(Token::INIT_VAR, var, lit, RelocInfo::kNoPosition)));
+ return new ExpressionStatement(
+ new Assignment(Token::INIT_VAR, var, lit, RelocInfo::kNoPosition));
}
@@ -1797,7 +1452,7 @@ Statement* Parser::ParseFunctionDeclaration(bool* ok) {
// scope, we treat is as such and introduce the function with it's
// initial value upon entering the corresponding scope.
Declare(name, Variable::VAR, fun, true, CHECK_OK);
- return factory()->EmptyStatement();
+ return EmptyStatement();
}
@@ -1809,7 +1464,7 @@ Block* Parser::ParseBlock(ZoneStringList* labels, bool* ok) {
// (ECMA-262, 3rd, 12.2)
//
// Construct block expecting 16 statements.
- Block* result = NEW(Block(labels, 16, false));
+ Block* result = new Block(labels, 16, false);
Target target(&this->target_stack_, result);
Expect(Token::LBRACE, CHECK_OK);
while (peek() != Token::RBRACE) {
@@ -1868,7 +1523,7 @@ Block* Parser::ParseVariableDeclarations(bool accept_IN,
// is inside an initializer block, it is ignored.
//
// Create new block with one expected declaration.
- Block* block = NEW(Block(NULL, 1, true));
+ Block* block = new Block(NULL, 1, true);
VariableProxy* last_var = NULL; // the last variable declared
int nvars = 0; // the number of variables declared
do {
@@ -1959,14 +1614,14 @@ Block* Parser::ParseVariableDeclarations(bool accept_IN,
// browsers where the global object (window) has lots of
// properties defined in prototype objects.
- if (!is_pre_parsing_ && top_scope_->is_global_scope()) {
+ if (top_scope_->is_global_scope()) {
// Compute the arguments for the runtime call.
ZoneList<Expression*>* arguments = new ZoneList<Expression*>(2);
// Be careful not to assign a value to the global variable if
// we're in a with. The initialization value should not
// necessarily be stored in the global object in that case,
// which is why we need to generate a separate assignment node.
- arguments->Add(NEW(Literal(name))); // we have at least 1 parameter
+ arguments->Add(new Literal(name)); // we have at least 1 parameter
if (is_const || (value != NULL && !inside_with())) {
arguments->Add(value);
value = NULL; // zap the value to avoid the unnecessary assignment
@@ -1978,18 +1633,18 @@ Block* Parser::ParseVariableDeclarations(bool accept_IN,
CallRuntime* initialize;
if (is_const) {
initialize =
- NEW(CallRuntime(
+ new CallRuntime(
Factory::InitializeConstGlobal_symbol(),
Runtime::FunctionForId(Runtime::kInitializeConstGlobal),
- arguments));
+ arguments);
} else {
initialize =
- NEW(CallRuntime(
+ new CallRuntime(
Factory::InitializeVarGlobal_symbol(),
Runtime::FunctionForId(Runtime::kInitializeVarGlobal),
- arguments));
+ arguments);
}
- block->AddStatement(NEW(ExpressionStatement(initialize)));
+ block->AddStatement(new ExpressionStatement(initialize));
}
// Add an assignment node to the initialization statement block if
@@ -2004,8 +1659,8 @@ Block* Parser::ParseVariableDeclarations(bool accept_IN,
// the top context for variables). Sigh...
if (value != NULL) {
Token::Value op = (is_const ? Token::INIT_CONST : Token::INIT_VAR);
- Assignment* assignment = NEW(Assignment(op, last_var, value, position));
- if (block) block->AddStatement(NEW(ExpressionStatement(assignment)));
+ Assignment* assignment = new Assignment(op, last_var, value, position);
+ if (block) block->AddStatement(new ExpressionStatement(assignment));
}
if (fni_ != NULL) fni_->Leave();
@@ -2013,14 +1668,8 @@ Block* Parser::ParseVariableDeclarations(bool accept_IN,
if (!is_const && nvars == 1) {
// We have a single, non-const variable.
- if (is_pre_parsing_) {
- // If we're preparsing then we need to set the var to something
- // in order for for-in loops to parse correctly.
- *var = ValidLeftHandSideSentinel::instance();
- } else {
- ASSERT(last_var != NULL);
- *var = last_var;
- }
+ ASSERT(last_var != NULL);
+ *var = last_var;
}
return block;
@@ -2055,29 +1704,27 @@ Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels,
// labels requires nontrivial changes to the way scopes are
// structured. However, these are probably changes we want to
// make later anyway so we should go back and fix this then.
- if (!is_pre_parsing_) {
- if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
- SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS);
- const char* elms[2] = { "Label", *c_string };
- Vector<const char*> args(elms, 2);
- ReportMessage("redeclaration", args);
- *ok = false;
- return NULL;
- }
- if (labels == NULL) labels = new ZoneStringList(4);
- labels->Add(label);
- // Remove the "ghost" variable that turned out to be a label
- // from the top scope. This way, we don't try to resolve it
- // during the scope processing.
- top_scope_->RemoveUnresolved(var);
+ if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
+ SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS);
+ const char* elms[2] = { "Label", *c_string };
+ Vector<const char*> args(elms, 2);
+ ReportMessage("redeclaration", args);
+ *ok = false;
+ return NULL;
}
+ if (labels == NULL) labels = new ZoneStringList(4);
+ labels->Add(label);
+ // Remove the "ghost" variable that turned out to be a label
+ // from the top scope. This way, we don't try to resolve it
+ // during the scope processing.
+ top_scope_->RemoveUnresolved(var);
Expect(Token::COLON, CHECK_OK);
return ParseStatement(labels, ok);
}
// Parsed expression statement.
ExpectSemicolon(CHECK_OK);
- return NEW(ExpressionStatement(expr));
+ return new ExpressionStatement(expr);
}
@@ -2094,10 +1741,10 @@ IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) {
if (peek() == Token::ELSE) {
Next();
else_statement = ParseStatement(labels, CHECK_OK);
- } else if (!is_pre_parsing_) {
- else_statement = factory()->EmptyStatement();
+ } else {
+ else_statement = EmptyStatement();
}
- return NEW(IfStatement(condition, then_statement, else_statement));
+ return new IfStatement(condition, then_statement, else_statement);
}
@@ -2113,19 +1760,17 @@ Statement* Parser::ParseContinueStatement(bool* ok) {
label = ParseIdentifier(CHECK_OK);
}
IterationStatement* target = NULL;
- if (!is_pre_parsing_) {
- target = LookupContinueTarget(label, CHECK_OK);
- if (target == NULL) {
- // Illegal continue statement. To be consistent with KJS we delay
- // reporting of the syntax error until runtime.
- Handle<String> error_type = Factory::illegal_continue_symbol();
- if (!label.is_null()) error_type = Factory::unknown_label_symbol();
- Expression* throw_error = NewThrowSyntaxError(error_type, label);
- return NEW(ExpressionStatement(throw_error));
- }
+ target = LookupContinueTarget(label, CHECK_OK);
+ if (target == NULL) {
+ // Illegal continue statement. To be consistent with KJS we delay
+ // reporting of the syntax error until runtime.
+ Handle<String> error_type = Factory::illegal_continue_symbol();
+ if (!label.is_null()) error_type = Factory::unknown_label_symbol();
+ Expression* throw_error = NewThrowSyntaxError(error_type, label);
+ return new ExpressionStatement(throw_error);
}
ExpectSemicolon(CHECK_OK);
- return NEW(ContinueStatement(target));
+ return new ContinueStatement(target);
}
@@ -2143,22 +1788,20 @@ Statement* Parser::ParseBreakStatement(ZoneStringList* labels, bool* ok) {
// Parse labeled break statements that target themselves into
// empty statements, e.g. 'l1: l2: l3: break l2;'
if (!label.is_null() && ContainsLabel(labels, label)) {
- return factory()->EmptyStatement();
+ return EmptyStatement();
}
BreakableStatement* target = NULL;
- if (!is_pre_parsing_) {
- target = LookupBreakTarget(label, CHECK_OK);
- if (target == NULL) {
- // Illegal break statement. To be consistent with KJS we delay
- // reporting of the syntax error until runtime.
- Handle<String> error_type = Factory::illegal_break_symbol();
- if (!label.is_null()) error_type = Factory::unknown_label_symbol();
- Expression* throw_error = NewThrowSyntaxError(error_type, label);
- return NEW(ExpressionStatement(throw_error));
- }
+ target = LookupBreakTarget(label, CHECK_OK);
+ if (target == NULL) {
+ // Illegal break statement. To be consistent with KJS we delay
+ // reporting of the syntax error until runtime.
+ Handle<String> error_type = Factory::illegal_break_symbol();
+ if (!label.is_null()) error_type = Factory::unknown_label_symbol();
+ Expression* throw_error = NewThrowSyntaxError(error_type, label);
+ return new ExpressionStatement(throw_error);
}
ExpectSemicolon(CHECK_OK);
- return NEW(BreakStatement(target));
+ return new BreakStatement(target);
}
@@ -2176,10 +1819,10 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
// function. See ECMA-262, section 12.9, page 67.
//
// To be consistent with KJS we report the syntax error at runtime.
- if (!is_pre_parsing_ && !top_scope_->is_function_scope()) {
+ if (!top_scope_->is_function_scope()) {
Handle<String> type = Factory::illegal_return_symbol();
Expression* throw_error = NewThrowSyntaxError(type, Handle<Object>::null());
- return NEW(ExpressionStatement(throw_error));
+ return new ExpressionStatement(throw_error);
}
Token::Value tok = peek();
@@ -2188,12 +1831,12 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
tok == Token::RBRACE ||
tok == Token::EOS) {
ExpectSemicolon(CHECK_OK);
- return NEW(ReturnStatement(GetLiteralUndefined()));
+ return new ReturnStatement(GetLiteralUndefined());
}
Expression* expr = ParseExpression(true, CHECK_OK);
ExpectSemicolon(CHECK_OK);
- return NEW(ReturnStatement(expr));
+ return new ReturnStatement(expr);
}
@@ -2202,7 +1845,7 @@ Block* Parser::WithHelper(Expression* obj,
bool is_catch_block,
bool* ok) {
// Parse the statement and collect escaping labels.
- ZoneList<BreakTarget*>* target_list = NEW(ZoneList<BreakTarget*>(0));
+ ZoneList<BreakTarget*>* target_list = new ZoneList<BreakTarget*>(0);
TargetCollector collector(target_list);
Statement* stat;
{ Target target(&this->target_stack_, &collector);
@@ -2214,21 +1857,21 @@ Block* Parser::WithHelper(Expression* obj,
// Create resulting block with two statements.
// 1: Evaluate the with expression.
// 2: The try-finally block evaluating the body.
- Block* result = NEW(Block(NULL, 2, false));
+ Block* result = new Block(NULL, 2, false);
if (result != NULL) {
- result->AddStatement(NEW(WithEnterStatement(obj, is_catch_block)));
+ result->AddStatement(new WithEnterStatement(obj, is_catch_block));
// Create body block.
- Block* body = NEW(Block(NULL, 1, false));
+ Block* body = new Block(NULL, 1, false);
body->AddStatement(stat);
// Create exit block.
- Block* exit = NEW(Block(NULL, 1, false));
- exit->AddStatement(NEW(WithExitStatement()));
+ Block* exit = new Block(NULL, 1, false);
+ exit->AddStatement(new WithExitStatement());
// Return a try-finally statement.
- TryFinallyStatement* wrapper = NEW(TryFinallyStatement(body, exit));
+ TryFinallyStatement* wrapper = new TryFinallyStatement(body, exit);
wrapper->set_escaping_targets(collector.targets());
result->AddStatement(wrapper);
}
@@ -2270,15 +1913,15 @@ CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) {
}
Expect(Token::COLON, CHECK_OK);
- ZoneListWrapper<Statement> statements = factory()->NewList<Statement>(5);
+ ZoneList<Statement*>* statements = new ZoneList<Statement*>(5);
while (peek() != Token::CASE &&
peek() != Token::DEFAULT &&
peek() != Token::RBRACE) {
Statement* stat = ParseStatement(NULL, CHECK_OK);
- statements.Add(stat);
+ statements->Add(stat);
}
- return NEW(CaseClause(label, statements.elements()));
+ return new CaseClause(label, statements);
}
@@ -2287,7 +1930,7 @@ SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels,
// SwitchStatement ::
// 'switch' '(' Expression ')' '{' CaseClause* '}'
- SwitchStatement* statement = NEW(SwitchStatement(labels));
+ SwitchStatement* statement = new SwitchStatement(labels);
Target target(&this->target_stack_, statement);
Expect(Token::SWITCH, CHECK_OK);
@@ -2296,15 +1939,15 @@ SwitchStatement* Parser::ParseSwitchStatement(ZoneStringList* labels,
Expect(Token::RPAREN, CHECK_OK);
bool default_seen = false;
- ZoneListWrapper<CaseClause> cases = factory()->NewList<CaseClause>(4);
+ ZoneList<CaseClause*>* cases = new ZoneList<CaseClause*>(4);
Expect(Token::LBRACE, CHECK_OK);
while (peek() != Token::RBRACE) {
CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK);
- cases.Add(clause);
+ cases->Add(clause);
}
Expect(Token::RBRACE, CHECK_OK);
- if (statement) statement->Initialize(tag, cases.elements());
+ if (statement) statement->Initialize(tag, cases);
return statement;
}
@@ -2323,7 +1966,7 @@ Statement* Parser::ParseThrowStatement(bool* ok) {
Expression* exception = ParseExpression(true, CHECK_OK);
ExpectSemicolon(CHECK_OK);
- return NEW(ExpressionStatement(new Throw(exception, pos)));
+ return new ExpressionStatement(new Throw(exception, pos));
}
@@ -2341,7 +1984,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
Expect(Token::TRY, CHECK_OK);
- ZoneList<BreakTarget*>* target_list = NEW(ZoneList<BreakTarget*>(0));
+ ZoneList<BreakTarget*>* target_list = new ZoneList<BreakTarget*>(0);
TargetCollector collector(target_list);
Block* try_block;
@@ -2364,7 +2007,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
// then we will need to collect jump targets from the catch block. Since
// we don't know yet if there will be a finally block, we always collect
// the jump targets.
- ZoneList<BreakTarget*>* catch_target_list = NEW(ZoneList<BreakTarget*>(0));
+ ZoneList<BreakTarget*>* catch_target_list = new ZoneList<BreakTarget*>(0);
TargetCollector catch_collector(catch_target_list);
bool has_catch = false;
if (tok == Token::CATCH) {
@@ -2379,8 +2022,8 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
// Allocate a temporary for holding the finally state while
// executing the finally block.
catch_var = top_scope_->NewTemporary(Factory::catch_var_symbol());
- Literal* name_literal = NEW(Literal(name));
- Expression* obj = NEW(CatchExtensionObject(name_literal, catch_var));
+ Literal* name_literal = new Literal(name);
+ Expression* obj = new CatchExtensionObject(name_literal, catch_var);
{ Target target(&this->target_stack_, &catch_collector);
catch_block = WithHelper(obj, NULL, true, CHECK_OK);
}
@@ -2403,30 +2046,28 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
// to:
// 'try { try { } catch { } } finally { }'
- if (!is_pre_parsing_ && catch_block != NULL && finally_block != NULL) {
+ if (catch_block != NULL && finally_block != NULL) {
TryCatchStatement* statement =
- NEW(TryCatchStatement(try_block, catch_var, catch_block));
+ new TryCatchStatement(try_block, catch_var, catch_block);
statement->set_escaping_targets(collector.targets());
- try_block = NEW(Block(NULL, 1, false));
+ try_block = new Block(NULL, 1, false);
try_block->AddStatement(statement);
catch_block = NULL;
}
TryStatement* result = NULL;
- if (!is_pre_parsing_) {
- if (catch_block != NULL) {
- ASSERT(finally_block == NULL);
- result = NEW(TryCatchStatement(try_block, catch_var, catch_block));
- result->set_escaping_targets(collector.targets());
- } else {
- ASSERT(finally_block != NULL);
- result = NEW(TryFinallyStatement(try_block, finally_block));
- // Add the jump targets of the try block and the catch block.
- for (int i = 0; i < collector.targets()->length(); i++) {
- catch_collector.AddTarget(collector.targets()->at(i));
- }
- result->set_escaping_targets(catch_collector.targets());
+ if (catch_block != NULL) {
+ ASSERT(finally_block == NULL);
+ result = new TryCatchStatement(try_block, catch_var, catch_block);
+ result->set_escaping_targets(collector.targets());
+ } else {
+ ASSERT(finally_block != NULL);
+ result = new TryFinallyStatement(try_block, finally_block);
+ // Add the jump targets of the try block and the catch block.
+ for (int i = 0; i < collector.targets()->length(); i++) {
+ catch_collector.AddTarget(collector.targets()->at(i));
}
+ result->set_escaping_targets(catch_collector.targets());
}
return result;
@@ -2439,7 +2080,7 @@ DoWhileStatement* Parser::ParseDoWhileStatement(ZoneStringList* labels,
// 'do' Statement 'while' '(' Expression ')' ';'
temp_scope_->AddLoop();
- DoWhileStatement* loop = NEW(DoWhileStatement(labels));
+ DoWhileStatement* loop = new DoWhileStatement(labels);
Target target(&this->target_stack_, loop);
Expect(Token::DO, CHECK_OK);
@@ -2472,7 +2113,7 @@ WhileStatement* Parser::ParseWhileStatement(ZoneStringList* labels, bool* ok) {
// 'while' '(' Expression ')' Statement
temp_scope_->AddLoop();
- WhileStatement* loop = NEW(WhileStatement(labels));
+ WhileStatement* loop = new WhileStatement(labels);
Target target(&this->target_stack_, loop);
Expect(Token::WHILE, CHECK_OK);
@@ -2502,7 +2143,7 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
Block* variable_statement =
ParseVariableDeclarations(false, &each, CHECK_OK);
if (peek() == Token::IN && each != NULL) {
- ForInStatement* loop = NEW(ForInStatement(labels));
+ ForInStatement* loop = new ForInStatement(labels);
Target target(&this->target_stack_, loop);
Expect(Token::IN, CHECK_OK);
@@ -2510,17 +2151,12 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
Expect(Token::RPAREN, CHECK_OK);
Statement* body = ParseStatement(NULL, CHECK_OK);
- if (is_pre_parsing_) {
- return NULL;
- } else {
- loop->Initialize(each, enumerable, body);
- Block* result = NEW(Block(NULL, 2, false));
- result->AddStatement(variable_statement);
- result->AddStatement(loop);
- // Parsed for-in loop w/ variable/const declaration.
- return result;
- }
-
+ loop->Initialize(each, enumerable, body);
+ Block* result = new Block(NULL, 2, false);
+ result->AddStatement(variable_statement);
+ result->AddStatement(loop);
+ // Parsed for-in loop w/ variable/const declaration.
+ return result;
} else {
init = variable_statement;
}
@@ -2536,7 +2172,7 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
Handle<String> type = Factory::invalid_lhs_in_for_in_symbol();
expression = NewThrowReferenceError(type);
}
- ForInStatement* loop = NEW(ForInStatement(labels));
+ ForInStatement* loop = new ForInStatement(labels);
Target target(&this->target_stack_, loop);
Expect(Token::IN, CHECK_OK);
@@ -2549,13 +2185,13 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
return loop;
} else {
- init = NEW(ExpressionStatement(expression));
+ init = new ExpressionStatement(expression);
}
}
}
// Standard 'for' loop
- ForStatement* loop = NEW(ForStatement(labels));
+ ForStatement* loop = new ForStatement(labels);
Target target(&this->target_stack_, loop);
// Parsed initializer at this point.
@@ -2571,7 +2207,7 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
Statement* next = NULL;
if (peek() != Token::RPAREN) {
Expression* exp = ParseExpression(true, CHECK_OK);
- next = NEW(ExpressionStatement(exp));
+ next = new ExpressionStatement(exp);
}
Expect(Token::RPAREN, CHECK_OK);
@@ -2592,7 +2228,7 @@ Expression* Parser::ParseExpression(bool accept_IN, bool* ok) {
Expect(Token::COMMA, CHECK_OK);
int position = scanner().location().beg_pos;
Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
- result = NEW(BinaryOperation(Token::COMMA, result, right, position));
+ result = new BinaryOperation(Token::COMMA, result, right, position);
}
return result;
}
@@ -2652,7 +2288,7 @@ Expression* Parser::ParseAssignmentExpression(bool accept_IN, bool* ok) {
fni_->Leave();
}
- return NEW(Assignment(op, expression, right, pos));
+ return new Assignment(op, expression, right, pos);
}
@@ -2674,8 +2310,8 @@ Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) {
Expect(Token::COLON, CHECK_OK);
int right_position = scanner().peek_location().beg_pos;
Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
- return NEW(Conditional(expression, left, right,
- left_position, right_position));
+ return new Conditional(expression, left, right,
+ left_position, right_position);
}
@@ -2782,12 +2418,12 @@ Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
x = NewCompareNode(cmp, x, y, position);
if (cmp != op) {
// The comparison was negated - add a NOT.
- x = NEW(UnaryOperation(Token::NOT, x));
+ x = new UnaryOperation(Token::NOT, x);
}
} else {
// We have a "normal" binary operation.
- x = NEW(BinaryOperation(op, x, y, position));
+ x = new BinaryOperation(op, x, y, position);
}
}
}
@@ -2800,19 +2436,19 @@ Expression* Parser::NewCompareNode(Token::Value op,
Expression* y,
int position) {
ASSERT(op != Token::NE && op != Token::NE_STRICT);
- if (!is_pre_parsing_ && (op == Token::EQ || op == Token::EQ_STRICT)) {
+ if (op == Token::EQ || op == Token::EQ_STRICT) {
bool is_strict = (op == Token::EQ_STRICT);
Literal* x_literal = x->AsLiteral();
if (x_literal != NULL && x_literal->IsNull()) {
- return NEW(CompareToNull(is_strict, y));
+ return new CompareToNull(is_strict, y);
}
Literal* y_literal = y->AsLiteral();
if (y_literal != NULL && y_literal->IsNull()) {
- return NEW(CompareToNull(is_strict, x));
+ return new CompareToNull(is_strict, x);
}
}
- return NEW(CompareOperation(op, x, y, position));
+ return new CompareOperation(op, x, y, position);
}
@@ -2849,7 +2485,7 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
}
}
- return NEW(UnaryOperation(op, expression));
+ return new UnaryOperation(op, expression);
} else if (Token::IsCountOp(op)) {
op = Next();
@@ -2863,8 +2499,8 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
expression = NewThrowReferenceError(type);
}
int position = scanner().location().beg_pos;
- IncrementOperation* increment = NEW(IncrementOperation(op, expression));
- return NEW(CountOperation(true /* prefix */, increment, position));
+ IncrementOperation* increment = new IncrementOperation(op, expression);
+ return new CountOperation(true /* prefix */, increment, position);
} else {
return ParsePostfixExpression(ok);
@@ -2888,8 +2524,8 @@ Expression* Parser::ParsePostfixExpression(bool* ok) {
}
Token::Value next = Next();
int position = scanner().location().beg_pos;
- IncrementOperation* increment = NEW(IncrementOperation(next, expression));
- expression = NEW(CountOperation(false /* postfix */, increment, position));
+ IncrementOperation* increment = new IncrementOperation(next, expression);
+ expression = new CountOperation(false /* postfix */, increment, position);
}
return expression;
}
@@ -2912,7 +2548,7 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
Consume(Token::LBRACK);
int pos = scanner().location().beg_pos;
Expression* index = ParseExpression(true, CHECK_OK);
- result = factory()->NewProperty(result, index, pos);
+ result = new Property(result, index, pos);
Expect(Token::RBRACK, CHECK_OK);
break;
}
@@ -2929,17 +2565,15 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
// declared in the current scope chain. These calls are marked as
// potentially direct eval calls. Whether they are actually direct calls
// to eval is determined at run time.
- if (!is_pre_parsing_) {
- VariableProxy* callee = result->AsVariableProxy();
- if (callee != NULL && callee->IsVariable(Factory::eval_symbol())) {
- Handle<String> name = callee->name();
- Variable* var = top_scope_->Lookup(name);
- if (var == NULL) {
- top_scope_->RecordEvalCall();
- }
+ VariableProxy* callee = result->AsVariableProxy();
+ if (callee != NULL && callee->IsVariable(Factory::eval_symbol())) {
+ Handle<String> name = callee->name();
+ Variable* var = top_scope_->Lookup(name);
+ if (var == NULL) {
+ top_scope_->RecordEvalCall();
}
}
- result = factory()->NewCall(result, args, pos);
+ result = NewCall(result, args, pos);
break;
}
@@ -2947,7 +2581,7 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
Consume(Token::PERIOD);
int pos = scanner().location().beg_pos;
Handle<String> name = ParseIdentifierName(CHECK_OK);
- result = factory()->NewProperty(result, NEW(Literal(name)), pos);
+ result = new Property(result, new Literal(name), pos);
if (fni_ != NULL) fni_->PushLiteralName(name);
break;
}
@@ -2959,7 +2593,6 @@ Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
}
-
Expression* Parser::ParseNewPrefix(PositionStack* stack, bool* ok) {
// NewExpression ::
// ('new')+ MemberExpression
@@ -2984,7 +2617,7 @@ Expression* Parser::ParseNewPrefix(PositionStack* stack, bool* ok) {
if (!stack->is_empty()) {
int last = stack->pop();
- result = NEW(CallNew(result, new ZoneList<Expression*>(0), last));
+ result = new CallNew(result, new ZoneList<Expression*>(0), last);
}
return result;
}
@@ -3026,7 +2659,7 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack,
Consume(Token::LBRACK);
int pos = scanner().location().beg_pos;
Expression* index = ParseExpression(true, CHECK_OK);
- result = factory()->NewProperty(result, index, pos);
+ result = new Property(result, index, pos);
Expect(Token::RBRACK, CHECK_OK);
break;
}
@@ -3034,7 +2667,7 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack,
Consume(Token::PERIOD);
int pos = scanner().location().beg_pos;
Handle<String> name = ParseIdentifierName(CHECK_OK);
- result = factory()->NewProperty(result, NEW(Literal(name)), pos);
+ result = new Property(result, new Literal(name), pos);
if (fni_ != NULL) fni_->PushLiteralName(name);
break;
}
@@ -3043,7 +2676,7 @@ Expression* Parser::ParseMemberWithNewPrefixesExpression(PositionStack* stack,
// Consume one of the new prefixes (already parsed).
ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
int last = stack->pop();
- result = NEW(CallNew(result, args, last));
+ result = new CallNew(result, args, last);
break;
}
default:
@@ -3062,7 +2695,7 @@ DebuggerStatement* Parser::ParseDebuggerStatement(bool* ok) {
Expect(Token::DEBUGGER, CHECK_OK);
ExpectSemicolon(CHECK_OK);
- return NEW(DebuggerStatement());
+ return new DebuggerStatement();
}
@@ -3120,38 +2753,30 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) {
switch (peek()) {
case Token::THIS: {
Consume(Token::THIS);
- if (is_pre_parsing_) {
- result = VariableProxySentinel::this_proxy();
- } else {
- VariableProxy* recv = top_scope_->receiver();
- result = recv;
- }
+ VariableProxy* recv = top_scope_->receiver();
+ result = recv;
break;
}
case Token::NULL_LITERAL:
Consume(Token::NULL_LITERAL);
- result = NEW(Literal(Factory::null_value()));
+ result = new Literal(Factory::null_value());
break;
case Token::TRUE_LITERAL:
Consume(Token::TRUE_LITERAL);
- result = NEW(Literal(Factory::true_value()));
+ result = new Literal(Factory::true_value());
break;
case Token::FALSE_LITERAL:
Consume(Token::FALSE_LITERAL);
- result = NEW(Literal(Factory::false_value()));
+ result = new Literal(Factory::false_value());
break;
case Token::IDENTIFIER: {
Handle<String> name = ParseIdentifier(CHECK_OK);
if (fni_ != NULL) fni_->PushVariableName(name);
- if (is_pre_parsing_) {
- result = VariableProxySentinel::identifier_proxy();
- } else {
- result = top_scope_->NewUnresolved(name, inside_with());
- }
+ result = top_scope_->NewUnresolved(name, inside_with());
break;
}
@@ -3166,7 +2791,7 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) {
case Token::STRING: {
Consume(Token::STRING);
Handle<String> symbol = GetSymbol(CHECK_OK);
- result = NEW(Literal(symbol));
+ result = new Literal(symbol);
if (fni_ != NULL) fni_->PushLiteralName(symbol);
break;
}
@@ -3244,7 +2869,7 @@ Expression* Parser::ParseArrayLiteral(bool* ok) {
// ArrayLiteral ::
// '[' Expression? (',' Expression?)* ']'
- ZoneListWrapper<Expression> values = factory()->NewList<Expression>(4);
+ ZoneList<Expression*>* values = new ZoneList<Expression*>(4);
Expect(Token::LBRACK, CHECK_OK);
while (peek() != Token::RBRACK) {
Expression* elem;
@@ -3253,7 +2878,7 @@ Expression* Parser::ParseArrayLiteral(bool* ok) {
} else {
elem = ParseAssignmentExpression(true, CHECK_OK);
}
- values.Add(elem);
+ values->Add(elem);
if (peek() != Token::RBRACK) {
Expect(Token::COMMA, CHECK_OK);
}
@@ -3263,21 +2888,19 @@ Expression* Parser::ParseArrayLiteral(bool* ok) {
// Update the scope information before the pre-parsing bailout.
int literal_index = temp_scope_->NextMaterializedLiteralIndex();
- if (is_pre_parsing_) return NULL;
-
// Allocate a fixed array with all the literals.
Handle<FixedArray> literals =
- Factory::NewFixedArray(values.length(), TENURED);
+ Factory::NewFixedArray(values->length(), TENURED);
// Fill in the literals.
bool is_simple = true;
int depth = 1;
- for (int i = 0; i < values.length(); i++) {
- MaterializedLiteral* m_literal = values.at(i)->AsMaterializedLiteral();
+ for (int i = 0, n = values->length(); i < n; i++) {
+ MaterializedLiteral* m_literal = values->at(i)->AsMaterializedLiteral();
if (m_literal != NULL && m_literal->depth() + 1 > depth) {
depth = m_literal->depth() + 1;
}
- Handle<Object> boilerplate_value = GetBoilerplateValue(values.at(i));
+ Handle<Object> boilerplate_value = GetBoilerplateValue(values->at(i));
if (boilerplate_value->IsUndefined()) {
literals->set_the_hole(i);
is_simple = false;
@@ -3288,12 +2911,12 @@ Expression* Parser::ParseArrayLiteral(bool* ok) {
// Simple and shallow arrays can be lazily copied, we transform the
// elements array to a copy-on-write array.
- if (is_simple && depth == 1 && values.length() > 0) {
+ if (is_simple && depth == 1 && values->length() > 0) {
literals->set_map(Heap::fixed_cow_array_map());
}
- return NEW(ArrayLiteral(literals, values.elements(),
- literal_index, is_simple, depth));
+ return new ArrayLiteral(literals, values,
+ literal_index, is_simple, depth);
}
@@ -3440,7 +3063,7 @@ ObjectLiteral::Property* Parser::ParseObjectLiteralGetSet(bool is_getter,
DECLARATION,
CHECK_OK);
ObjectLiteral::Property* property =
- NEW(ObjectLiteral::Property(is_getter, value));
+ new ObjectLiteral::Property(is_getter, value);
return property;
} else {
ReportUnexpectedToken(next);
@@ -3457,8 +3080,8 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
// | (('get' | 'set') (IdentifierName | String | Number) FunctionLiteral)
// )*[','] '}'
- ZoneListWrapper<ObjectLiteral::Property> properties =
- factory()->NewList<ObjectLiteral::Property>(4);
+ ZoneList<ObjectLiteral::Property*>* properties =
+ new ZoneList<ObjectLiteral::Property*>(4);
int number_of_boilerplate_properties = 0;
Expect(Token::LBRACE, CHECK_OK);
@@ -3481,7 +3104,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
if (IsBoilerplateProperty(property)) {
number_of_boilerplate_properties++;
}
- properties.Add(property);
+ properties->Add(property);
if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK);
if (fni_ != NULL) {
@@ -3492,7 +3115,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
}
// Failed to parse as get/set property, so it's just a property
// called "get" or "set".
- key = NEW(Literal(id));
+ key = new Literal(id);
break;
}
case Token::STRING: {
@@ -3504,7 +3127,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
key = NewNumberLiteral(index);
break;
}
- key = NEW(Literal(string));
+ key = new Literal(string);
break;
}
case Token::NUMBER: {
@@ -3518,7 +3141,7 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
if (Token::IsKeyword(next)) {
Consume(next);
Handle<String> string = GetSymbol(CHECK_OK);
- key = NEW(Literal(string));
+ key = new Literal(string);
} else {
// Unexpected token.
Token::Value next = Next();
@@ -3532,11 +3155,11 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
Expression* value = ParseAssignmentExpression(true, CHECK_OK);
ObjectLiteral::Property* property =
- NEW(ObjectLiteral::Property(key, value));
+ new ObjectLiteral::Property(key, value);
// Count CONSTANT or COMPUTED properties to maintain the enumeration order.
if (IsBoilerplateProperty(property)) number_of_boilerplate_properties++;
- properties.Add(property);
+ properties->Add(property);
// TODO(1240767): Consider allowing trailing comma.
if (peek() != Token::RBRACE) Expect(Token::COMMA, CHECK_OK);
@@ -3549,7 +3172,6 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
Expect(Token::RBRACE, CHECK_OK);
// Computation of literal_index must happen before pre parse bailout.
int literal_index = temp_scope_->NextMaterializedLiteralIndex();
- if (is_pre_parsing_) return NULL;
Handle<FixedArray> constant_properties =
Factory::NewFixedArray(number_of_boilerplate_properties * 2, TENURED);
@@ -3557,13 +3179,13 @@ Expression* Parser::ParseObjectLiteral(bool* ok) {
bool is_simple = true;
bool fast_elements = true;
int depth = 1;
- BuildObjectLiteralConstantProperties(properties.elements(),
+ BuildObjectLiteralConstantProperties(properties,
constant_properties,
&is_simple,
&fast_elements,
&depth);
return new ObjectLiteral(constant_properties,
- properties.elements(),
+ properties,
literal_index,
is_simple,
fast_elements,
@@ -3581,19 +3203,6 @@ Expression* Parser::ParseRegExpLiteral(bool seen_equal, bool* ok) {
int literal_index = temp_scope_->NextMaterializedLiteralIndex();
- if (is_pre_parsing_) {
- // If we're preparsing we just do all the parsing stuff without
- // building anything.
- if (!scanner_.ScanRegExpFlags()) {
- Next();
- ReportMessage("invalid_regexp_flags", Vector<const char*>::empty());
- *ok = false;
- return NULL;
- }
- Next();
- return NULL;
- }
-
Handle<String> js_pattern =
Factory::NewStringFromUtf8(scanner_.next_literal(), TENURED);
scanner_.ScanRegExpFlags();
@@ -3609,17 +3218,17 @@ ZoneList<Expression*>* Parser::ParseArguments(bool* ok) {
// Arguments ::
// '(' (AssignmentExpression)*[','] ')'
- ZoneListWrapper<Expression> result = factory()->NewList<Expression>(4);
+ ZoneList<Expression*>* result = new ZoneList<Expression*>(4);
Expect(Token::LPAREN, CHECK_OK);
bool done = (peek() == Token::RPAREN);
while (!done) {
Expression* argument = ParseAssignmentExpression(true, CHECK_OK);
- result.Add(argument);
+ result->Add(argument);
done = (peek() == Token::RPAREN);
if (!done) Expect(Token::COMMA, CHECK_OK);
}
Expect(Token::RPAREN, CHECK_OK);
- return result.elements();
+ return result;
}
@@ -3635,9 +3244,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
// this is the actual function name, otherwise this is the name of the
// variable declared and initialized with the function (expression). In
// that case, we don't have a function name (it's empty).
- Handle<String> name = is_named ? var_name : factory()->EmptySymbol();
+ Handle<String> name = is_named ? var_name : Factory::empty_symbol();
// The function name, if any.
- Handle<String> function_name = factory()->EmptySymbol();
+ Handle<String> function_name = Factory::empty_symbol();
if (is_named && (type == EXPRESSION || type == NESTED)) {
function_name = name;
}
@@ -3645,7 +3254,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
int num_parameters = 0;
// Parse function body.
{ Scope* scope =
- factory()->NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with());
+ NewScope(top_scope_, Scope::FUNCTION_SCOPE, inside_with());
LexicalScope lexical_scope(&this->top_scope_, &this->with_nesting_level_,
scope);
TemporaryScope temp_scope(&this->temp_scope_);
@@ -3658,18 +3267,16 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
bool done = (peek() == Token::RPAREN);
while (!done) {
Handle<String> param_name = ParseIdentifier(CHECK_OK);
- if (!is_pre_parsing_) {
- top_scope_->AddParameter(top_scope_->DeclareLocal(param_name,
- Variable::VAR));
- num_parameters++;
- }
+ top_scope_->AddParameter(top_scope_->DeclareLocal(param_name,
+ Variable::VAR));
+ num_parameters++;
done = (peek() == Token::RPAREN);
if (!done) Expect(Token::COMMA, CHECK_OK);
}
Expect(Token::RPAREN, CHECK_OK);
Expect(Token::LBRACE, CHECK_OK);
- ZoneListWrapper<Statement> body = factory()->NewList<Statement>(8);
+ ZoneList<Statement*>* body = new ZoneList<Statement*>(8);
// If we have a named function expression, we add a local variable
// declaration to the body of the function with the name of the
@@ -3677,17 +3284,15 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
// NOTE: We create a proxy and resolve it here so that in the
// future we can change the AST to only refer to VariableProxies
// instead of Variables and Proxis as is the case now.
- if (!is_pre_parsing_
- && !function_name.is_null()
- && function_name->length() > 0) {
+ if (!function_name.is_null() && function_name->length() > 0) {
Variable* fvar = top_scope_->DeclareFunctionVar(function_name);
VariableProxy* fproxy =
top_scope_->NewUnresolved(function_name, inside_with());
fproxy->BindTo(fvar);
- body.Add(new ExpressionStatement(
- new Assignment(Token::INIT_CONST, fproxy,
- NEW(ThisFunction()),
- RelocInfo::kNoPosition)));
+ body->Add(new ExpressionStatement(
+ new Assignment(Token::INIT_CONST, fproxy,
+ new ThisFunction(),
+ RelocInfo::kNoPosition)));
}
// Determine if the function will be lazily compiled. The mode can
@@ -3719,12 +3324,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
this_property_assignments = Factory::empty_fixed_array();
Expect(Token::RBRACE, CHECK_OK);
} else {
- FunctionEntry entry;
- if (is_lazily_compiled) entry = log()->LogFunction(function_block_pos);
- {
- ConditionalLogPauseScope pause_if(is_lazily_compiled, log());
- ParseSourceElements(&body, Token::RBRACE, CHECK_OK);
- }
+ ParseSourceElements(body, Token::RBRACE, CHECK_OK);
+
materialized_literal_count = temp_scope.materialized_literal_count();
expected_property_count = temp_scope.expected_property_count();
only_simple_this_property_assignments =
@@ -3733,19 +3334,12 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
Expect(Token::RBRACE, CHECK_OK);
end_pos = scanner_.location().end_pos;
- if (entry.is_valid()) {
- ASSERT(is_lazily_compiled);
- ASSERT(is_pre_parsing_);
- entry.set_end_pos(end_pos);
- entry.set_literal_count(materialized_literal_count);
- entry.set_property_count(expected_property_count);
- }
}
FunctionLiteral* function_literal =
- NEW(FunctionLiteral(name,
+ new FunctionLiteral(name,
top_scope_,
- body.elements(),
+ body,
materialized_literal_count,
expected_property_count,
only_simple_this_property_assignments,
@@ -3754,10 +3348,8 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
start_pos,
end_pos,
function_name->length() > 0,
- temp_scope.ContainsLoops()));
- if (!is_pre_parsing_) {
- function_literal->set_function_token_position(function_token_position);
- }
+ temp_scope.ContainsLoops());
+ function_literal->set_function_token_position(function_token_position);
if (fni_ != NULL && !is_named) fni_->AddFunction(function_literal);
return function_literal;
@@ -3772,7 +3364,6 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
Expect(Token::MOD, CHECK_OK);
Handle<String> name = ParseIdentifier(CHECK_OK);
ZoneList<Expression*>* args = ParseArguments(CHECK_OK);
- if (is_pre_parsing_) return NULL;
if (extension_ != NULL) {
// The extension structures are only accessible while parsing the
@@ -3808,7 +3399,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
}
// We have a valid intrinsics call or a call to a builtin.
- return NEW(CallRuntime(name, function, args));
+ return new CallRuntime(name, function, args);
}
@@ -3856,12 +3447,12 @@ void Parser::ExpectSemicolon(bool* ok) {
Literal* Parser::GetLiteralUndefined() {
- return NEW(Literal(Factory::undefined_value()));
+ return new Literal(Factory::undefined_value());
}
Literal* Parser::GetLiteralTheHole() {
- return NEW(Literal(Factory::the_hole_value()));
+ return new Literal(Factory::the_hole_value());
}
@@ -3964,7 +3555,7 @@ void Parser::RegisterTargetUse(BreakTarget* target, Target* stop) {
Literal* Parser::NewNumberLiteral(double number) {
- return NEW(Literal(Factory::NewNumber(number, TENURED)));
+ return new Literal(Factory::NewNumber(number, TENURED));
}
@@ -3996,8 +3587,6 @@ Expression* Parser::NewThrowTypeError(Handle<String> type,
Expression* Parser::NewThrowError(Handle<String> constructor,
Handle<String> type,
Vector< Handle<Object> > arguments) {
- if (is_pre_parsing_) return NULL;
-
int argc = arguments.length();
Handle<JSArray> array = Factory::NewJSArray(argc, TENURED);
ASSERT(array->IsJSArray() && array->HasFastElements());
@@ -4185,17 +3774,17 @@ Handle<Object> JsonParser::ParseJsonArray() {
RegExpParser::RegExpParser(FlatStringReader* in,
Handle<String>* error,
bool multiline)
- : current_(kEndMarker),
+ : error_(error),
+ captures_(NULL),
+ in_(in),
+ current_(kEndMarker),
+ next_pos_(0),
+ capture_count_(0),
has_more_(true),
multiline_(multiline),
- next_pos_(0),
- in_(in),
- error_(error),
simple_(false),
contains_anchor_(false),
- captures_(NULL),
is_scanned_for_captures_(false),
- capture_count_(0),
failed_(false) {
Advance(1);
}
@@ -5003,23 +4592,6 @@ bool ScriptDataImpl::HasError() {
}
-// Preparse, but only collect data that is immediately useful,
-// even if the preparser data is only used once.
-ScriptDataImpl* ParserApi::PartialPreParse(Handle<String> source,
- unibrow::CharacterStream* stream,
- v8::Extension* extension) {
- Handle<Script> no_script;
- bool allow_natives_syntax =
- 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
- // contiguous vector that we are responsible for disposing.
- Vector<unsigned> store = parser.recorder()->ExtractData();
- return new ScriptDataImpl(store);
-}
-
-
void ScriptDataImpl::Initialize() {
// Prepares state for use.
if (store_.length() >= kHeaderSize) {
@@ -5063,17 +4635,50 @@ int ScriptDataImpl::ReadNumber(byte** source) {
}
+// Preparse, but only collect data that is immediately useful,
+// even if the preparser data is only used once.
+ScriptDataImpl* ParserApi::PartialPreParse(Handle<String> source,
+ unibrow::CharacterStream* stream,
+ v8::Extension* extension) {
+ Handle<Script> no_script;
+ bool allow_lazy = FLAG_lazy && (extension == NULL);
+ if (!allow_lazy) {
+ // Partial preparsing is only about lazily compiled functions.
+ // If we don't allow lazy compilation, the log data will be empty.
+ return NULL;
+ }
+ preparser::PreParser<Scanner, PartialParserRecorder> parser;
+ Scanner scanner;
+ scanner.Initialize(source, stream, JAVASCRIPT);
+ PartialParserRecorder recorder;
+ if (!parser.PreParseProgram(&scanner, &recorder, allow_lazy)) {
+ Top::StackOverflow();
+ return NULL;
+ }
+
+ // Extract the accumulated data from the recorder as a single
+ // contiguous vector that we are responsible for disposing.
+ Vector<unsigned> store = recorder.ExtractData();
+ return new ScriptDataImpl(store);
+}
+
+
ScriptDataImpl* ParserApi::PreParse(Handle<String> source,
unibrow::CharacterStream* stream,
v8::Extension* extension) {
Handle<Script> no_script;
- bool allow_natives_syntax =
- FLAG_allow_natives_syntax || Bootstrapper::IsActive();
- CompletePreParser parser(no_script, allow_natives_syntax, extension);
- if (!parser.PreParseProgram(source, stream)) return NULL;
+ preparser::PreParser<Scanner, CompleteParserRecorder> parser;
+ Scanner scanner;
+ scanner.Initialize(source, stream, JAVASCRIPT);
+ bool allow_lazy = FLAG_lazy && (extension == NULL);
+ CompleteParserRecorder recorder;
+ if (!parser.PreParseProgram(&scanner, &recorder, allow_lazy)) {
+ Top::StackOverflow();
+ return NULL;
+ }
// Extract the accumulated data from the recorder as a single
// contiguous vector that we are responsible for disposing.
- Vector<unsigned> store = parser.recorder()->ExtractData();
+ Vector<unsigned> store = recorder.ExtractData();
return new ScriptDataImpl(store);
}
@@ -5105,14 +4710,13 @@ bool ParserApi::Parse(CompilationInfo* info) {
FunctionLiteral* result = NULL;
Handle<Script> script = info->script();
if (info->is_lazy()) {
- AstBuildingParser parser(script, true, NULL, NULL);
+ Parser parser(script, true, NULL, NULL);
result = parser.ParseLazy(info->shared_info());
} else {
bool allow_natives_syntax =
FLAG_allow_natives_syntax || Bootstrapper::IsActive();
ScriptDataImpl* pre_data = info->pre_parse_data();
- AstBuildingParser parser(script, allow_natives_syntax, info->extension(),
- pre_data);
+ Parser parser(script, allow_natives_syntax, info->extension(), pre_data);
if (pre_data != NULL && pre_data->has_error()) {
Scanner::Location loc = pre_data->MessageLocation();
const char* message = pre_data->BuildMessage();
@@ -5134,6 +4738,4 @@ bool ParserApi::Parse(CompilationInfo* info) {
return (result != NULL);
}
-#undef NEW
-
} } // namespace v8::internal
« no previous file with comments | « src/parser.h ('k') | src/platform-linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698