2012-02-08 09:56:33 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_PARSER_H_
|
|
|
|
#define V8_PARSER_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
|
|
|
#include "src/ast.h"
|
2015-03-09 14:51:13 +00:00
|
|
|
#include "src/compiler.h" // TODO(titzer): remove this include dependency
|
2015-02-25 14:17:39 +00:00
|
|
|
#include "src/pending-compilation-error-handler.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/preparse-data.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/preparse-data-format.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/preparser.h"
|
2014-06-20 08:40:11 +00:00
|
|
|
#include "src/scopes.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
2015-03-09 14:51:13 +00:00
|
|
|
|
2014-03-19 13:24:13 +00:00
|
|
|
class ScriptCompiler;
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-10-01 14:10:47 +00:00
|
|
|
class Target;
|
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
// A container for the inputs, configuration options, and outputs of parsing.
|
|
|
|
class ParseInfo {
|
|
|
|
public:
|
2015-03-12 11:46:12 +00:00
|
|
|
explicit ParseInfo(Zone* zone);
|
|
|
|
ParseInfo(Zone* zone, Handle<JSFunction> function);
|
|
|
|
ParseInfo(Zone* zone, Handle<Script> script);
|
2015-03-19 12:39:43 +00:00
|
|
|
// TODO(all) Only used via Debug::FindSharedFunctionInfoInScript, remove?
|
|
|
|
ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared);
|
2015-03-09 14:51:13 +00:00
|
|
|
|
|
|
|
~ParseInfo() {
|
|
|
|
if (ast_value_factory_owned()) {
|
|
|
|
delete ast_value_factory_;
|
|
|
|
set_ast_value_factory_owned(false);
|
|
|
|
}
|
|
|
|
ast_value_factory_ = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Zone* zone() { return zone_; }
|
|
|
|
|
|
|
|
// Convenience accessor methods for flags.
|
|
|
|
#define FLAG_ACCESSOR(flag, getter, setter) \
|
|
|
|
bool getter() const { return GetFlag(flag); } \
|
|
|
|
void setter() { SetFlag(flag); } \
|
|
|
|
void setter(bool val) { SetFlag(flag, val); }
|
|
|
|
|
|
|
|
FLAG_ACCESSOR(kToplevel, is_toplevel, set_toplevel)
|
|
|
|
FLAG_ACCESSOR(kLazy, is_lazy, set_lazy)
|
|
|
|
FLAG_ACCESSOR(kEval, is_eval, set_eval)
|
|
|
|
FLAG_ACCESSOR(kGlobal, is_global, set_global)
|
|
|
|
FLAG_ACCESSOR(kStrictMode, is_strict_mode, set_strict_mode)
|
|
|
|
FLAG_ACCESSOR(kStrongMode, is_strong_mode, set_strong_mode)
|
|
|
|
FLAG_ACCESSOR(kNative, is_native, set_native)
|
|
|
|
FLAG_ACCESSOR(kModule, is_module, set_module)
|
|
|
|
FLAG_ACCESSOR(kAllowLazyParsing, allow_lazy_parsing, set_allow_lazy_parsing)
|
|
|
|
FLAG_ACCESSOR(kAstValueFactoryOwned, ast_value_factory_owned,
|
|
|
|
set_ast_value_factory_owned)
|
|
|
|
|
|
|
|
#undef FLAG_ACCESSOR
|
|
|
|
|
|
|
|
void set_parse_restriction(ParseRestriction restriction) {
|
|
|
|
SetFlag(kParseRestriction, restriction != NO_PARSE_RESTRICTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
ParseRestriction parse_restriction() const {
|
|
|
|
return GetFlag(kParseRestriction) ? ONLY_SINGLE_FUNCTION_LITERAL
|
|
|
|
: NO_PARSE_RESTRICTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptCompiler::ExternalSourceStream* source_stream() {
|
|
|
|
return source_stream_;
|
|
|
|
}
|
|
|
|
void set_source_stream(ScriptCompiler::ExternalSourceStream* source_stream) {
|
|
|
|
source_stream_ = source_stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptCompiler::StreamedSource::Encoding source_stream_encoding() {
|
|
|
|
return source_stream_encoding_;
|
|
|
|
}
|
|
|
|
void set_source_stream_encoding(
|
|
|
|
ScriptCompiler::StreamedSource::Encoding source_stream_encoding) {
|
|
|
|
source_stream_encoding_ = source_stream_encoding;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Extension* extension() { return extension_; }
|
|
|
|
void set_extension(v8::Extension* extension) { extension_ = extension; }
|
|
|
|
|
|
|
|
ScriptData** cached_data() { return cached_data_; }
|
|
|
|
void set_cached_data(ScriptData** cached_data) { cached_data_ = cached_data; }
|
|
|
|
|
|
|
|
ScriptCompiler::CompileOptions compile_options() { return compile_options_; }
|
|
|
|
void set_compile_options(ScriptCompiler::CompileOptions compile_options) {
|
|
|
|
compile_options_ = compile_options;
|
|
|
|
}
|
|
|
|
|
|
|
|
Scope* script_scope() { return script_scope_; }
|
|
|
|
void set_script_scope(Scope* script_scope) { script_scope_ = script_scope; }
|
|
|
|
|
|
|
|
AstValueFactory* ast_value_factory() { return ast_value_factory_; }
|
|
|
|
void set_ast_value_factory(AstValueFactory* ast_value_factory) {
|
|
|
|
ast_value_factory_ = ast_value_factory;
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionLiteral* function() { // TODO(titzer): temporary name adapter
|
|
|
|
return literal_;
|
|
|
|
}
|
|
|
|
FunctionLiteral* literal() { return literal_; }
|
|
|
|
void set_literal(FunctionLiteral* literal) { literal_ = literal; }
|
|
|
|
|
|
|
|
Scope* scope() { return scope_; }
|
|
|
|
void set_scope(Scope* scope) { scope_ = scope; }
|
|
|
|
|
|
|
|
UnicodeCache* unicode_cache() { return unicode_cache_; }
|
|
|
|
void set_unicode_cache(UnicodeCache* unicode_cache) {
|
|
|
|
unicode_cache_ = unicode_cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t stack_limit() { return stack_limit_; }
|
|
|
|
void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; }
|
|
|
|
|
|
|
|
uint32_t hash_seed() { return hash_seed_; }
|
|
|
|
void set_hash_seed(uint32_t hash_seed) { hash_seed_ = hash_seed; }
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
// TODO(titzer): these should not be part of ParseInfo.
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
Isolate* isolate() { return isolate_; }
|
|
|
|
Handle<JSFunction> closure() { return closure_; }
|
|
|
|
Handle<SharedFunctionInfo> shared_info() { return shared_; }
|
|
|
|
Handle<Script> script() { return script_; }
|
|
|
|
Handle<Context> context() { return context_; }
|
|
|
|
void clear_script() { script_ = Handle<Script>::null(); }
|
|
|
|
void set_isolate(Isolate* isolate) { isolate_ = isolate; }
|
|
|
|
void set_context(Handle<Context> context) { context_ = context; }
|
|
|
|
void set_script(Handle<Script> script) { script_ = script; }
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
LanguageMode language_mode() {
|
|
|
|
return construct_language_mode(is_strict_mode(), is_strong_mode());
|
|
|
|
}
|
|
|
|
void set_language_mode(LanguageMode language_mode) {
|
|
|
|
STATIC_ASSERT(LANGUAGE_END == 3);
|
|
|
|
set_strict_mode(language_mode & STRICT_BIT);
|
|
|
|
set_strong_mode(language_mode & STRONG_BIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReopenHandlesInNewHandleScope() {
|
|
|
|
closure_ = Handle<JSFunction>(*closure_);
|
|
|
|
shared_ = Handle<SharedFunctionInfo>(*shared_);
|
|
|
|
script_ = Handle<Script>(*script_);
|
|
|
|
context_ = Handle<Context>(*context_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Various configuration flags for parsing.
|
|
|
|
enum Flag {
|
|
|
|
// ---------- Input flags ---------------------------
|
|
|
|
kToplevel = 1 << 0,
|
|
|
|
kLazy = 1 << 1,
|
|
|
|
kEval = 1 << 2,
|
|
|
|
kGlobal = 1 << 3,
|
|
|
|
kStrictMode = 1 << 4,
|
|
|
|
kStrongMode = 1 << 5,
|
|
|
|
kNative = 1 << 6,
|
|
|
|
kParseRestriction = 1 << 7,
|
|
|
|
kModule = 1 << 8,
|
|
|
|
kAllowLazyParsing = 1 << 9,
|
|
|
|
// ---------- Output flags --------------------------
|
2015-03-23 14:48:16 +00:00
|
|
|
kAstValueFactoryOwned = 1 << 10
|
2015-03-09 14:51:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//------------- Inputs to parsing and scope analysis -----------------------
|
|
|
|
Zone* zone_;
|
|
|
|
unsigned flags_;
|
|
|
|
ScriptCompiler::ExternalSourceStream* source_stream_;
|
|
|
|
ScriptCompiler::StreamedSource::Encoding source_stream_encoding_;
|
|
|
|
v8::Extension* extension_;
|
|
|
|
ScriptCompiler::CompileOptions compile_options_;
|
|
|
|
Scope* script_scope_;
|
|
|
|
UnicodeCache* unicode_cache_;
|
|
|
|
uintptr_t stack_limit_;
|
|
|
|
uint32_t hash_seed_;
|
|
|
|
|
|
|
|
// TODO(titzer): Move handles and isolate out of ParseInfo.
|
|
|
|
Isolate* isolate_;
|
|
|
|
Handle<JSFunction> closure_;
|
|
|
|
Handle<SharedFunctionInfo> shared_;
|
|
|
|
Handle<Script> script_;
|
|
|
|
Handle<Context> context_;
|
|
|
|
|
|
|
|
//----------- Inputs+Outputs of parsing and scope analysis -----------------
|
|
|
|
ScriptData** cached_data_; // used if available, populated if requested.
|
|
|
|
AstValueFactory* ast_value_factory_; // used if available, otherwise new.
|
|
|
|
|
|
|
|
//----------- Outputs of parsing and scope analysis ------------------------
|
|
|
|
FunctionLiteral* literal_; // produced by full parser.
|
|
|
|
Scope* scope_; // produced by scope analysis.
|
|
|
|
|
|
|
|
void SetFlag(Flag f) { flags_ |= f; }
|
|
|
|
void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; }
|
|
|
|
bool GetFlag(Flag f) const { return (flags_ & f) != 0; }
|
|
|
|
|
|
|
|
void set_shared_info(Handle<SharedFunctionInfo> shared) { shared_ = shared; }
|
|
|
|
void set_closure(Handle<JSFunction> closure) { closure_ = closure; }
|
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
class FunctionEntry BASE_EMBEDDED {
|
|
|
|
public:
|
2011-11-09 13:54:26 +00:00
|
|
|
enum {
|
|
|
|
kStartPositionIndex,
|
|
|
|
kEndPositionIndex,
|
|
|
|
kLiteralCountIndex,
|
|
|
|
kPropertyCountIndex,
|
2015-02-04 09:34:05 +00:00
|
|
|
kLanguageModeIndex,
|
2015-02-13 18:34:52 +00:00
|
|
|
kUsesSuperPropertyIndex,
|
2015-06-04 21:16:18 +00:00
|
|
|
kCallsEvalIndex,
|
2011-11-09 13:54:26 +00:00
|
|
|
kSize
|
|
|
|
};
|
|
|
|
|
2011-11-25 09:36:31 +00:00
|
|
|
explicit FunctionEntry(Vector<unsigned> backing)
|
|
|
|
: backing_(backing) { }
|
|
|
|
|
|
|
|
FunctionEntry() : backing_() { }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-11-09 13:54:26 +00:00
|
|
|
int start_pos() { return backing_[kStartPositionIndex]; }
|
|
|
|
int end_pos() { return backing_[kEndPositionIndex]; }
|
|
|
|
int literal_count() { return backing_[kLiteralCountIndex]; }
|
|
|
|
int property_count() { return backing_[kPropertyCountIndex]; }
|
2015-02-04 09:34:05 +00:00
|
|
|
LanguageMode language_mode() {
|
|
|
|
DCHECK(is_valid_language_mode(backing_[kLanguageModeIndex]));
|
|
|
|
return static_cast<LanguageMode>(backing_[kLanguageModeIndex]);
|
2011-10-27 13:08:51 +00:00
|
|
|
}
|
2015-02-13 18:34:52 +00:00
|
|
|
bool uses_super_property() { return backing_[kUsesSuperPropertyIndex]; }
|
2015-06-04 21:16:18 +00:00
|
|
|
bool calls_eval() { return backing_[kCallsEvalIndex]; }
|
2010-08-27 08:26:29 +00:00
|
|
|
|
2011-11-09 13:54:26 +00:00
|
|
|
bool is_valid() { return !backing_.is_empty(); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Vector<unsigned> backing_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-10 10:28:05 +00:00
|
|
|
// Wrapper around ScriptData to provide parser-specific functionality.
|
|
|
|
class ParseData {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2014-11-17 12:16:27 +00:00
|
|
|
static ParseData* FromCachedData(ScriptData* cached_data) {
|
|
|
|
ParseData* pd = new ParseData(cached_data);
|
|
|
|
if (pd->IsSane()) return pd;
|
|
|
|
cached_data->Reject();
|
|
|
|
delete pd;
|
|
|
|
return NULL;
|
2014-07-10 10:28:05 +00:00
|
|
|
}
|
2014-11-17 12:16:27 +00:00
|
|
|
|
2010-09-15 10:54:35 +00:00
|
|
|
void Initialize();
|
2010-08-27 08:26:29 +00:00
|
|
|
FunctionEntry GetFunctionEntry(int start);
|
2014-07-10 10:28:05 +00:00
|
|
|
int FunctionCount();
|
|
|
|
|
|
|
|
bool HasError();
|
|
|
|
|
|
|
|
unsigned* Data() { // Writable data as unsigned int array.
|
|
|
|
return reinterpret_cast<unsigned*>(const_cast<byte*>(script_data_->data()));
|
2014-04-04 12:36:23 +00:00
|
|
|
}
|
2010-09-15 10:54:35 +00:00
|
|
|
|
2014-12-08 11:47:44 +00:00
|
|
|
void Reject() { script_data_->Reject(); }
|
|
|
|
|
|
|
|
bool rejected() const { return script_data_->rejected(); }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2014-11-17 12:16:27 +00:00
|
|
|
explicit ParseData(ScriptData* script_data) : script_data_(script_data) {}
|
|
|
|
|
2014-07-10 10:28:05 +00:00
|
|
|
bool IsSane();
|
|
|
|
unsigned Magic();
|
|
|
|
unsigned Version();
|
|
|
|
int FunctionsSize();
|
|
|
|
int Length() const {
|
|
|
|
// Script data length is already checked to be a multiple of unsigned size.
|
|
|
|
return script_data_->length() / sizeof(unsigned);
|
|
|
|
}
|
2010-08-27 08:26:29 +00:00
|
|
|
|
2014-07-10 10:28:05 +00:00
|
|
|
ScriptData* script_data_;
|
|
|
|
int function_index_;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-07-10 10:28:05 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ParseData);
|
2010-10-27 12:33:48 +00:00
|
|
|
};
|
|
|
|
|
2010-11-02 11:45:47 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// REGEXP PARSING
|
2010-10-27 12:33:48 +00:00
|
|
|
|
2012-01-16 12:38:59 +00:00
|
|
|
// A BufferedZoneList is an automatically growing list, just like (and backed
|
2010-10-27 12:33:48 +00:00
|
|
|
// by) a ZoneList, that is optimized for the case of adding and removing
|
|
|
|
// a single element. The last element added is stored outside the backing list,
|
|
|
|
// and if no more than one element is ever added, the ZoneList isn't even
|
|
|
|
// allocated.
|
|
|
|
// Elements must not be NULL pointers.
|
|
|
|
template <typename T, int initial_size>
|
|
|
|
class BufferedZoneList {
|
|
|
|
public:
|
|
|
|
BufferedZoneList() : list_(NULL), last_(NULL) {}
|
|
|
|
|
|
|
|
// Adds element at end of list. This element is buffered and can
|
|
|
|
// be read using last() or removed using RemoveLast until a new Add or until
|
|
|
|
// RemoveLast or GetList has been called.
|
2012-06-11 12:42:31 +00:00
|
|
|
void Add(T* value, Zone* zone) {
|
2010-10-27 12:33:48 +00:00
|
|
|
if (last_ != NULL) {
|
|
|
|
if (list_ == NULL) {
|
2012-06-11 12:42:31 +00:00
|
|
|
list_ = new(zone) ZoneList<T*>(initial_size, zone);
|
2010-10-27 12:33:48 +00:00
|
|
|
}
|
2012-06-11 12:42:31 +00:00
|
|
|
list_->Add(last_, zone);
|
2010-10-27 12:33:48 +00:00
|
|
|
}
|
|
|
|
last_ = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* last() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(last_ != NULL);
|
2010-10-27 12:33:48 +00:00
|
|
|
return last_;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* RemoveLast() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(last_ != NULL);
|
2010-10-27 12:33:48 +00:00
|
|
|
T* result = last_;
|
|
|
|
if ((list_ != NULL) && (list_->length() > 0))
|
|
|
|
last_ = list_->RemoveLast();
|
|
|
|
else
|
|
|
|
last_ = NULL;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
T* Get(int i) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK((0 <= i) && (i < length()));
|
2010-10-27 12:33:48 +00:00
|
|
|
if (list_ == NULL) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK_EQ(0, i);
|
2010-10-27 12:33:48 +00:00
|
|
|
return last_;
|
|
|
|
} else {
|
|
|
|
if (i == list_->length()) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(last_ != NULL);
|
2010-10-27 12:33:48 +00:00
|
|
|
return last_;
|
|
|
|
} else {
|
|
|
|
return list_->at(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear() {
|
|
|
|
list_ = NULL;
|
|
|
|
last_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int length() {
|
|
|
|
int length = (list_ == NULL) ? 0 : list_->length();
|
|
|
|
return length + ((last_ == NULL) ? 0 : 1);
|
|
|
|
}
|
|
|
|
|
2012-06-11 12:42:31 +00:00
|
|
|
ZoneList<T*>* GetList(Zone* zone) {
|
2010-10-27 12:33:48 +00:00
|
|
|
if (list_ == NULL) {
|
2012-06-11 12:42:31 +00:00
|
|
|
list_ = new(zone) ZoneList<T*>(initial_size, zone);
|
2010-10-27 12:33:48 +00:00
|
|
|
}
|
|
|
|
if (last_ != NULL) {
|
2012-06-11 12:42:31 +00:00
|
|
|
list_->Add(last_, zone);
|
2010-10-27 12:33:48 +00:00
|
|
|
last_ = NULL;
|
|
|
|
}
|
|
|
|
return list_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ZoneList<T*>* list_;
|
|
|
|
T* last_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Accumulates RegExp atoms and assertions into lists of terms and alternatives.
|
|
|
|
class RegExpBuilder: public ZoneObject {
|
|
|
|
public:
|
2012-06-04 14:42:58 +00:00
|
|
|
explicit RegExpBuilder(Zone* zone);
|
2010-10-27 12:33:48 +00:00
|
|
|
void AddCharacter(uc16 character);
|
|
|
|
// "Adds" an empty expression. Does nothing except consume a
|
|
|
|
// following quantifier
|
|
|
|
void AddEmpty();
|
|
|
|
void AddAtom(RegExpTree* tree);
|
|
|
|
void AddAssertion(RegExpTree* tree);
|
|
|
|
void NewAlternative(); // '|'
|
2013-06-06 13:28:22 +00:00
|
|
|
void AddQuantifierToAtom(
|
|
|
|
int min, int max, RegExpQuantifier::QuantifierType type);
|
2010-10-27 12:33:48 +00:00
|
|
|
RegExpTree* ToRegExp();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void FlushCharacters();
|
|
|
|
void FlushText();
|
|
|
|
void FlushTerms();
|
2012-06-11 12:42:31 +00:00
|
|
|
Zone* zone() const { return zone_; }
|
2011-04-04 06:29:02 +00:00
|
|
|
|
|
|
|
Zone* zone_;
|
2010-10-27 12:33:48 +00:00
|
|
|
bool pending_empty_;
|
|
|
|
ZoneList<uc16>* characters_;
|
|
|
|
BufferedZoneList<RegExpTree, 2> terms_;
|
|
|
|
BufferedZoneList<RegExpTree, 2> text_;
|
|
|
|
BufferedZoneList<RegExpTree, 2> alternatives_;
|
|
|
|
#ifdef DEBUG
|
|
|
|
enum {ADD_NONE, ADD_CHAR, ADD_TERM, ADD_ASSERT, ADD_ATOM} last_added_;
|
|
|
|
#define LAST(x) last_added_ = x;
|
|
|
|
#else
|
|
|
|
#define LAST(x)
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-04-08 11:53:50 +00:00
|
|
|
class RegExpParser BASE_EMBEDDED {
|
2010-10-27 12:33:48 +00:00
|
|
|
public:
|
2015-01-12 09:50:15 +00:00
|
|
|
RegExpParser(FlatStringReader* in, Handle<String>* error, bool multiline_mode,
|
2015-01-23 15:19:34 +00:00
|
|
|
bool unicode, Isolate* isolate, Zone* zone);
|
2010-10-01 14:10:47 +00:00
|
|
|
|
2015-01-23 15:19:34 +00:00
|
|
|
static bool ParseRegExp(Isolate* isolate, Zone* zone, FlatStringReader* input,
|
|
|
|
bool multiline, bool unicode,
|
|
|
|
RegExpCompileData* result);
|
2010-10-01 14:10:47 +00:00
|
|
|
|
2010-10-27 12:33:48 +00:00
|
|
|
RegExpTree* ParsePattern();
|
|
|
|
RegExpTree* ParseDisjunction();
|
|
|
|
RegExpTree* ParseGroup();
|
|
|
|
RegExpTree* ParseCharacterClass();
|
|
|
|
|
|
|
|
// Parses a {...,...} quantifier and stores the range in the given
|
|
|
|
// out parameters.
|
|
|
|
bool ParseIntervalQuantifier(int* min_out, int* max_out);
|
|
|
|
|
|
|
|
// Parses and returns a single escaped character. The character
|
|
|
|
// must not be 'b' or 'B' since they are usually handle specially.
|
|
|
|
uc32 ParseClassCharacterEscape();
|
|
|
|
|
|
|
|
// Checks whether the following is a length-digit hexadecimal number,
|
|
|
|
// and sets the value if it is.
|
|
|
|
bool ParseHexEscape(int length, uc32* value);
|
2015-01-12 09:50:15 +00:00
|
|
|
bool ParseUnicodeEscape(uc32* value);
|
|
|
|
bool ParseUnlimitedLengthHexNumber(int max_value, uc32* value);
|
2010-10-27 12:33:48 +00:00
|
|
|
|
|
|
|
uc32 ParseOctalLiteral();
|
|
|
|
|
|
|
|
// Tries to parse the input as a back reference. If successful it
|
|
|
|
// stores the result in the output parameter and returns true. If
|
|
|
|
// it fails it will push back the characters read so the same characters
|
|
|
|
// can be reparsed.
|
|
|
|
bool ParseBackReferenceIndex(int* index_out);
|
|
|
|
|
|
|
|
CharacterRange ParseClassAtom(uc16* char_class);
|
|
|
|
RegExpTree* ReportError(Vector<const char> message);
|
|
|
|
void Advance();
|
|
|
|
void Advance(int dist);
|
|
|
|
void Reset(int pos);
|
|
|
|
|
|
|
|
// Reports whether the pattern might be used as a literal search string.
|
|
|
|
// Only use if the result of the parse is a single atom node.
|
|
|
|
bool simple();
|
|
|
|
bool contains_anchor() { return contains_anchor_; }
|
|
|
|
void set_contains_anchor() { contains_anchor_ = true; }
|
|
|
|
int captures_started() { return captures_ == NULL ? 0 : captures_->length(); }
|
|
|
|
int position() { return next_pos_ - 1; }
|
|
|
|
bool failed() { return failed_; }
|
|
|
|
|
2015-01-12 09:50:15 +00:00
|
|
|
static bool IsSyntaxCharacter(uc32 c);
|
|
|
|
|
2010-10-27 12:33:48 +00:00
|
|
|
static const int kMaxCaptures = 1 << 16;
|
|
|
|
static const uc32 kEndMarker = (1 << 21);
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum SubexpressionType {
|
|
|
|
INITIAL,
|
|
|
|
CAPTURE, // All positive values represent captures.
|
|
|
|
POSITIVE_LOOKAHEAD,
|
|
|
|
NEGATIVE_LOOKAHEAD,
|
|
|
|
GROUPING
|
|
|
|
};
|
|
|
|
|
|
|
|
class RegExpParserState : public ZoneObject {
|
|
|
|
public:
|
|
|
|
RegExpParserState(RegExpParserState* previous_state,
|
|
|
|
SubexpressionType group_type,
|
2012-06-04 14:42:58 +00:00
|
|
|
int disjunction_capture_index,
|
|
|
|
Zone* zone)
|
2010-10-27 12:33:48 +00:00
|
|
|
: previous_state_(previous_state),
|
2012-06-11 12:42:31 +00:00
|
|
|
builder_(new(zone) RegExpBuilder(zone)),
|
2010-10-27 12:33:48 +00:00
|
|
|
group_type_(group_type),
|
|
|
|
disjunction_capture_index_(disjunction_capture_index) {}
|
|
|
|
// Parser state of containing expression, if any.
|
|
|
|
RegExpParserState* previous_state() { return previous_state_; }
|
|
|
|
bool IsSubexpression() { return previous_state_ != NULL; }
|
|
|
|
// RegExpBuilder building this regexp's AST.
|
|
|
|
RegExpBuilder* builder() { return builder_; }
|
|
|
|
// Type of regexp being parsed (parenthesized group or entire regexp).
|
|
|
|
SubexpressionType group_type() { return group_type_; }
|
|
|
|
// Index in captures array of first capture in this sub-expression, if any.
|
|
|
|
// Also the capture index of this sub-expression itself, if group_type
|
|
|
|
// is CAPTURE.
|
|
|
|
int capture_index() { return disjunction_capture_index_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Linked list implementation of stack of states.
|
|
|
|
RegExpParserState* previous_state_;
|
|
|
|
// Builder for the stored disjunction.
|
|
|
|
RegExpBuilder* builder_;
|
|
|
|
// Stored disjunction type (capture, look-ahead or grouping), if any.
|
|
|
|
SubexpressionType group_type_;
|
|
|
|
// Stored disjunction's capture index (if any).
|
|
|
|
int disjunction_capture_index_;
|
|
|
|
};
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate() { return isolate_; }
|
2012-06-20 08:58:41 +00:00
|
|
|
Zone* zone() const { return zone_; }
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2010-10-27 12:33:48 +00:00
|
|
|
uc32 current() { return current_; }
|
|
|
|
bool has_more() { return has_more_; }
|
|
|
|
bool has_next() { return next_pos_ < in()->length(); }
|
|
|
|
uc32 Next();
|
|
|
|
FlatStringReader* in() { return in_; }
|
|
|
|
void ScanForCaptures();
|
2010-11-02 11:45:47 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate_;
|
2012-06-20 08:58:41 +00:00
|
|
|
Zone* zone_;
|
2010-11-02 11:45:47 +00:00
|
|
|
Handle<String>* error_;
|
|
|
|
ZoneList<RegExpCapture*>* captures_;
|
|
|
|
FlatStringReader* in_;
|
2010-10-27 12:33:48 +00:00
|
|
|
uc32 current_;
|
2010-11-02 11:45:47 +00:00
|
|
|
int next_pos_;
|
|
|
|
// The capture count is only valid after we have scanned for captures.
|
|
|
|
int capture_count_;
|
2010-10-27 12:33:48 +00:00
|
|
|
bool has_more_;
|
|
|
|
bool multiline_;
|
2015-01-12 09:50:15 +00:00
|
|
|
bool unicode_;
|
2010-10-27 12:33:48 +00:00
|
|
|
bool simple_;
|
|
|
|
bool contains_anchor_;
|
|
|
|
bool is_scanned_for_captures_;
|
|
|
|
bool failed_;
|
|
|
|
};
|
|
|
|
|
2010-11-02 11:45:47 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// JAVASCRIPT PARSING
|
2010-10-27 12:33:48 +00:00
|
|
|
|
2014-02-11 09:35:32 +00:00
|
|
|
class Parser;
|
2011-11-25 09:36:31 +00:00
|
|
|
class SingletonLogger;
|
|
|
|
|
2014-02-11 09:35:32 +00:00
|
|
|
class ParserTraits {
|
|
|
|
public:
|
2014-02-13 16:17:55 +00:00
|
|
|
struct Type {
|
2014-03-12 19:15:17 +00:00
|
|
|
// TODO(marja): To be removed. The Traits object should contain all the data
|
|
|
|
// it needs.
|
2014-02-13 16:17:55 +00:00
|
|
|
typedef v8::internal::Parser* Parser;
|
|
|
|
|
|
|
|
typedef Variable GeneratorVariable;
|
|
|
|
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
typedef v8::internal::AstProperties AstProperties;
|
|
|
|
|
2014-02-13 16:17:55 +00:00
|
|
|
// Return types for traversing functions.
|
2014-06-24 14:03:24 +00:00
|
|
|
typedef const AstRawString* Identifier;
|
2014-02-13 16:17:55 +00:00
|
|
|
typedef v8::internal::Expression* Expression;
|
2014-03-14 09:51:22 +00:00
|
|
|
typedef Yield* YieldExpression;
|
2014-03-11 15:40:41 +00:00
|
|
|
typedef v8::internal::FunctionLiteral* FunctionLiteral;
|
2014-09-16 22:15:39 +00:00
|
|
|
typedef v8::internal::ClassLiteral* ClassLiteral;
|
2014-03-11 15:40:41 +00:00
|
|
|
typedef v8::internal::Literal* Literal;
|
|
|
|
typedef ObjectLiteral::Property* ObjectLiteralProperty;
|
2014-02-19 08:56:11 +00:00
|
|
|
typedef ZoneList<v8::internal::Expression*>* ExpressionList;
|
2014-03-11 15:40:41 +00:00
|
|
|
typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
|
2015-04-21 11:09:53 +00:00
|
|
|
typedef const v8::internal::AstRawString* FormalParameter;
|
|
|
|
typedef Scope FormalParameterScope;
|
2014-04-25 09:44:20 +00:00
|
|
|
typedef ZoneList<v8::internal::Statement*>* StatementList;
|
2014-03-12 19:15:17 +00:00
|
|
|
|
|
|
|
// For constructing objects returned by the traversing functions.
|
2014-11-14 13:13:09 +00:00
|
|
|
typedef AstNodeFactory Factory;
|
2014-02-13 16:17:55 +00:00
|
|
|
};
|
2014-02-11 09:35:32 +00:00
|
|
|
|
|
|
|
explicit ParserTraits(Parser* parser) : parser_(parser) {}
|
|
|
|
|
|
|
|
// Helper functions for recursive descent.
|
2015-02-19 14:58:32 +00:00
|
|
|
bool IsEval(const AstRawString* identifier) const;
|
|
|
|
bool IsArguments(const AstRawString* identifier) const;
|
2014-06-24 14:03:24 +00:00
|
|
|
bool IsEvalOrArguments(const AstRawString* identifier) const;
|
2015-04-10 12:04:51 +00:00
|
|
|
bool IsUndefined(const AstRawString* identifier) const;
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
V8_INLINE bool IsFutureStrictReserved(const AstRawString* identifier) const;
|
2014-02-11 09:35:32 +00:00
|
|
|
|
2014-03-14 09:43:04 +00:00
|
|
|
// Returns true if the expression is of type "this.foo".
|
|
|
|
static bool IsThisProperty(Expression* expression);
|
|
|
|
|
2014-03-19 14:08:47 +00:00
|
|
|
static bool IsIdentifier(Expression* expression);
|
|
|
|
|
2014-09-16 22:15:39 +00:00
|
|
|
bool IsPrototype(const AstRawString* identifier) const;
|
|
|
|
|
|
|
|
bool IsConstructor(const AstRawString* identifier) const;
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
static const AstRawString* AsIdentifier(Expression* expression) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(IsIdentifier(expression));
|
2014-06-24 14:03:24 +00:00
|
|
|
return expression->AsVariableProxy()->raw_name();
|
2014-04-02 11:03:05 +00:00
|
|
|
}
|
|
|
|
|
2014-03-11 15:40:41 +00:00
|
|
|
static bool IsBoilerplateProperty(ObjectLiteral::Property* property) {
|
|
|
|
return ObjectLiteral::IsBoilerplateProperty(property);
|
|
|
|
}
|
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
static bool IsArrayIndex(const AstRawString* string, uint32_t* index) {
|
|
|
|
return string->AsArrayIndex(index);
|
2014-03-11 15:40:41 +00:00
|
|
|
}
|
|
|
|
|
2014-10-07 16:24:59 +00:00
|
|
|
static Expression* GetPropertyValue(ObjectLiteral::Property* property) {
|
|
|
|
return property->value();
|
|
|
|
}
|
|
|
|
|
2014-03-14 09:43:04 +00:00
|
|
|
// Functions for encapsulating the differences between parsing and preparsing;
|
|
|
|
// operations interleaved with the recursive descent.
|
2014-06-24 14:03:24 +00:00
|
|
|
static void PushLiteralName(FuncNameInferrer* fni, const AstRawString* id) {
|
2014-03-11 15:40:41 +00:00
|
|
|
fni->PushLiteralName(id);
|
|
|
|
}
|
2015-01-15 20:02:20 +00:00
|
|
|
|
2014-03-21 10:34:51 +00:00
|
|
|
void PushPropertyName(FuncNameInferrer* fni, Expression* expression);
|
2015-01-15 20:02:20 +00:00
|
|
|
|
2014-07-21 09:58:01 +00:00
|
|
|
static void InferFunctionName(FuncNameInferrer* fni,
|
|
|
|
FunctionLiteral* func_to_infer) {
|
|
|
|
fni->AddFunction(func_to_infer);
|
|
|
|
}
|
2014-03-11 15:40:41 +00:00
|
|
|
|
|
|
|
static void CheckFunctionLiteralInsideTopLevelObjectLiteral(
|
2014-08-20 15:51:07 +00:00
|
|
|
Scope* scope, ObjectLiteralProperty* property, bool* has_function) {
|
|
|
|
Expression* value = property->value();
|
2014-11-12 11:34:09 +00:00
|
|
|
if (scope->DeclarationScope()->is_script_scope() &&
|
2014-03-11 15:40:41 +00:00
|
|
|
value->AsFunctionLiteral() != NULL) {
|
|
|
|
*has_function = true;
|
|
|
|
value->AsFunctionLiteral()->set_pretenure();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-14 09:43:04 +00:00
|
|
|
// If we assign a function literal to a property we pretenure the
|
|
|
|
// literal so it can be added as a constant function property.
|
|
|
|
static void CheckAssigningFunctionLiteralToProperty(Expression* left,
|
|
|
|
Expression* right);
|
|
|
|
|
2014-03-21 09:51:33 +00:00
|
|
|
// Keep track of eval() calls since they disable all local variable
|
|
|
|
// optimizations. This checks if expression is an eval call, and if yes,
|
|
|
|
// forwards the information to scope.
|
|
|
|
void CheckPossibleEvalCall(Expression* expression, Scope* scope);
|
|
|
|
|
2014-03-14 09:43:04 +00:00
|
|
|
// Determine if the expression is a variable proxy and mark it as being used
|
2014-06-26 11:59:42 +00:00
|
|
|
// in an assignment or with a increment/decrement operator.
|
|
|
|
static Expression* MarkExpressionAsAssigned(Expression* expression);
|
2014-03-14 09:43:04 +00:00
|
|
|
|
2014-03-17 13:54:42 +00:00
|
|
|
// Returns true if we have a binary expression between two numeric
|
|
|
|
// literals. In that case, *x will be changed to an expression which is the
|
|
|
|
// computed value.
|
2014-11-14 13:13:09 +00:00
|
|
|
bool ShortcutNumericLiteralBinaryExpression(Expression** x, Expression* y,
|
|
|
|
Token::Value op, int pos,
|
|
|
|
AstNodeFactory* factory);
|
2014-03-17 13:54:42 +00:00
|
|
|
|
2014-03-19 14:08:47 +00:00
|
|
|
// Rewrites the following types of unary expressions:
|
|
|
|
// not <literal> -> true / false
|
|
|
|
// + <numeric literal> -> <numeric literal>
|
|
|
|
// - <numeric literal> -> <numeric literal with value negated>
|
|
|
|
// ! <literal> -> true / false
|
|
|
|
// The following rewriting rules enable the collection of type feedback
|
|
|
|
// without any special stub and the multiplication is removed later in
|
|
|
|
// Crankshaft's canonicalization pass.
|
|
|
|
// + foo -> foo * 1
|
|
|
|
// - foo -> foo * (-1)
|
|
|
|
// ~ foo -> foo ^(~0)
|
2014-11-14 13:13:09 +00:00
|
|
|
Expression* BuildUnaryExpression(Expression* expression, Token::Value op,
|
|
|
|
int pos, AstNodeFactory* factory);
|
2014-03-19 14:08:47 +00:00
|
|
|
|
2014-04-02 11:03:05 +00:00
|
|
|
// Generate AST node that throws a ReferenceError with the given type.
|
2015-05-18 08:34:05 +00:00
|
|
|
Expression* NewThrowReferenceError(MessageTemplate::Template message,
|
|
|
|
int pos);
|
2014-04-02 11:03:05 +00:00
|
|
|
|
|
|
|
// Generate AST node that throws a SyntaxError with the given
|
|
|
|
// type. The first argument may be null (in the handle sense) in
|
|
|
|
// which case no arguments are passed to the constructor.
|
2015-05-18 08:34:05 +00:00
|
|
|
Expression* NewThrowSyntaxError(MessageTemplate::Template message,
|
|
|
|
const AstRawString* arg, int pos);
|
2014-04-02 11:03:05 +00:00
|
|
|
|
|
|
|
// Generate AST node that throws a TypeError with the given
|
|
|
|
// type. Both arguments must be non-null (in the handle sense).
|
2015-05-18 08:34:05 +00:00
|
|
|
Expression* NewThrowTypeError(MessageTemplate::Template message,
|
|
|
|
const AstRawString* arg, int pos);
|
2014-04-02 11:03:05 +00:00
|
|
|
|
|
|
|
// Generic AST generator for throwing errors from compiled code.
|
2015-05-18 08:34:05 +00:00
|
|
|
Expression* NewThrowError(const AstRawString* constructor,
|
|
|
|
MessageTemplate::Template message,
|
|
|
|
const AstRawString* arg, int pos);
|
2014-04-02 11:03:05 +00:00
|
|
|
|
2014-02-11 09:35:32 +00:00
|
|
|
// Reporting errors.
|
2015-05-18 08:34:05 +00:00
|
|
|
void ReportMessageAt(Scanner::Location source_location,
|
|
|
|
MessageTemplate::Template message,
|
2014-06-20 09:45:05 +00:00
|
|
|
const char* arg = NULL,
|
2015-02-20 21:19:43 +00:00
|
|
|
ParseErrorType error_type = kSyntaxError);
|
2015-05-18 08:34:05 +00:00
|
|
|
void ReportMessage(MessageTemplate::Template message, const char* arg = NULL,
|
2015-02-20 21:19:43 +00:00
|
|
|
ParseErrorType error_type = kSyntaxError);
|
2015-05-18 08:34:05 +00:00
|
|
|
void ReportMessage(MessageTemplate::Template message, const AstRawString* arg,
|
2015-02-20 21:19:43 +00:00
|
|
|
ParseErrorType error_type = kSyntaxError);
|
2015-05-18 08:34:05 +00:00
|
|
|
void ReportMessageAt(Scanner::Location source_location,
|
|
|
|
MessageTemplate::Template message,
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* arg,
|
2015-02-20 21:19:43 +00:00
|
|
|
ParseErrorType error_type = kSyntaxError);
|
2014-02-11 09:35:32 +00:00
|
|
|
|
2014-02-11 11:51:01 +00:00
|
|
|
// "null" return type creators.
|
2014-06-24 14:03:24 +00:00
|
|
|
static const AstRawString* EmptyIdentifier() {
|
|
|
|
return NULL;
|
2014-02-11 09:35:32 +00:00
|
|
|
}
|
2014-02-13 16:17:55 +00:00
|
|
|
static Expression* EmptyExpression() {
|
2014-02-11 11:51:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-03-11 15:40:41 +00:00
|
|
|
static Literal* EmptyLiteral() {
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-08-20 15:51:07 +00:00
|
|
|
static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return NULL; }
|
2014-09-16 22:15:39 +00:00
|
|
|
static FunctionLiteral* EmptyFunctionLiteral() { return NULL; }
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
|
2014-03-21 10:34:51 +00:00
|
|
|
// Used in error return values.
|
2014-03-11 16:30:47 +00:00
|
|
|
static ZoneList<Expression*>* NullExpressionList() {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-04-21 11:09:53 +00:00
|
|
|
static const AstRawString* EmptyFormalParameter() { return NULL; }
|
2014-02-11 09:35:32 +00:00
|
|
|
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
// Non-NULL empty string.
|
|
|
|
V8_INLINE const AstRawString* EmptyIdentifierString();
|
|
|
|
|
2014-02-19 08:56:11 +00:00
|
|
|
// Odd-ball literal creators.
|
2014-11-14 13:13:09 +00:00
|
|
|
Literal* GetLiteralTheHole(int position, AstNodeFactory* factory);
|
2014-02-19 08:56:11 +00:00
|
|
|
|
2014-02-11 11:51:01 +00:00
|
|
|
// Producing data during the recursive descent.
|
2014-06-24 14:03:24 +00:00
|
|
|
const AstRawString* GetSymbol(Scanner* scanner);
|
|
|
|
const AstRawString* GetNextSymbol(Scanner* scanner);
|
2014-08-22 14:40:38 +00:00
|
|
|
const AstRawString* GetNumberAsSymbol(Scanner* scanner);
|
2014-06-24 14:03:24 +00:00
|
|
|
|
2014-11-14 13:13:09 +00:00
|
|
|
Expression* ThisExpression(Scope* scope, AstNodeFactory* factory,
|
2014-07-21 09:58:01 +00:00
|
|
|
int pos = RelocInfo::kNoPosition);
|
2015-06-02 22:04:25 +00:00
|
|
|
Expression* SuperPropertyReference(Scope* scope, AstNodeFactory* factory,
|
|
|
|
int pos);
|
|
|
|
Expression* SuperCallReference(Scope* scope, AstNodeFactory* factory,
|
|
|
|
int pos);
|
2015-06-09 15:43:07 +00:00
|
|
|
Expression* NewTargetExpression(Scope* scope, AstNodeFactory* factory,
|
|
|
|
int pos);
|
2014-11-07 16:39:00 +00:00
|
|
|
Expression* DefaultConstructor(bool call_super, Scope* scope, int pos,
|
|
|
|
int end_pos);
|
2014-11-14 13:13:09 +00:00
|
|
|
Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner,
|
|
|
|
AstNodeFactory* factory);
|
2015-02-26 13:48:10 +00:00
|
|
|
Expression* ExpressionFromIdentifier(const AstRawString* name,
|
|
|
|
int start_position, int end_position,
|
2014-11-14 13:13:09 +00:00
|
|
|
Scope* scope, AstNodeFactory* factory);
|
|
|
|
Expression* ExpressionFromString(int pos, Scanner* scanner,
|
|
|
|
AstNodeFactory* factory);
|
|
|
|
Expression* GetIterator(Expression* iterable, AstNodeFactory* factory);
|
2014-02-19 08:56:11 +00:00
|
|
|
ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) {
|
|
|
|
return new(zone) ZoneList<v8::internal::Expression*>(size, zone);
|
|
|
|
}
|
2014-03-11 15:40:41 +00:00
|
|
|
ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) {
|
|
|
|
return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone);
|
|
|
|
}
|
2014-04-25 09:44:20 +00:00
|
|
|
ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) {
|
|
|
|
return new(zone) ZoneList<v8::internal::Statement*>(size, zone);
|
|
|
|
}
|
2015-02-03 17:42:41 +00:00
|
|
|
V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type,
|
|
|
|
FunctionKind kind = kNormalFunction);
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
|
2015-06-09 17:13:35 +00:00
|
|
|
V8_INLINE void DeclareFormalParameter(Scope* scope, const AstRawString* name,
|
|
|
|
ExpressionClassifier* classifier,
|
|
|
|
bool is_rest);
|
2015-04-21 14:44:18 +00:00
|
|
|
void DeclareArrowFunctionParameters(Scope* scope, Expression* expr,
|
|
|
|
const Scanner::Location& params_loc,
|
2015-05-13 11:45:04 +00:00
|
|
|
Scanner::Location* duplicate_loc,
|
2015-04-21 14:44:18 +00:00
|
|
|
bool* ok);
|
2015-05-13 11:45:04 +00:00
|
|
|
void ParseArrowFunctionFormalParameters(Scope* scope, Expression* params,
|
|
|
|
const Scanner::Location& params_loc,
|
|
|
|
bool* is_rest,
|
|
|
|
Scanner::Location* duplicate_loc,
|
|
|
|
bool* ok);
|
2015-04-21 14:44:18 +00:00
|
|
|
|
2014-02-14 11:24:26 +00:00
|
|
|
// Temporary glue; these functions will move to ParserBase.
|
|
|
|
Expression* ParseV8Intrinsic(bool* ok);
|
2014-03-11 15:40:41 +00:00
|
|
|
FunctionLiteral* ParseFunctionLiteral(
|
2014-09-10 16:39:42 +00:00
|
|
|
const AstRawString* name, Scanner::Location function_name_location,
|
|
|
|
bool name_is_strict_reserved, FunctionKind kind,
|
|
|
|
int function_token_position, FunctionLiteral::FunctionType type,
|
|
|
|
FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
|
2015-05-06 10:21:20 +00:00
|
|
|
V8_INLINE void SkipLazyFunctionBody(
|
|
|
|
int* materialized_literal_count, int* expected_property_count, bool* ok,
|
|
|
|
Scanner::BookmarkScope* bookmark = nullptr);
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody(
|
|
|
|
const AstRawString* name, int pos, Variable* fvar,
|
2015-02-06 10:34:50 +00:00
|
|
|
Token::Value fvar_init_op, FunctionKind kind, bool* ok);
|
2014-11-14 15:05:05 +00:00
|
|
|
|
|
|
|
ClassLiteral* ParseClassLiteral(const AstRawString* name,
|
|
|
|
Scanner::Location class_name_location,
|
|
|
|
bool name_is_strict_reserved, int pos,
|
|
|
|
bool* ok);
|
|
|
|
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope,
|
|
|
|
bool* ok);
|
2014-02-11 09:35:32 +00:00
|
|
|
|
2014-11-14 18:53:41 +00:00
|
|
|
class TemplateLiteral : public ZoneObject {
|
|
|
|
public:
|
|
|
|
TemplateLiteral(Zone* zone, int pos)
|
2014-12-03 14:17:16 +00:00
|
|
|
: cooked_(8, zone), raw_(8, zone), expressions_(8, zone), pos_(pos) {}
|
2014-11-14 18:53:41 +00:00
|
|
|
|
|
|
|
const ZoneList<Expression*>* cooked() const { return &cooked_; }
|
2014-12-03 14:17:16 +00:00
|
|
|
const ZoneList<Expression*>* raw() const { return &raw_; }
|
2014-11-14 18:53:41 +00:00
|
|
|
const ZoneList<Expression*>* expressions() const { return &expressions_; }
|
|
|
|
int position() const { return pos_; }
|
|
|
|
|
2014-12-03 14:17:16 +00:00
|
|
|
void AddTemplateSpan(Literal* cooked, Literal* raw, int end, Zone* zone) {
|
2014-11-14 18:53:41 +00:00
|
|
|
DCHECK_NOT_NULL(cooked);
|
2014-12-03 14:17:16 +00:00
|
|
|
DCHECK_NOT_NULL(raw);
|
2014-11-14 18:53:41 +00:00
|
|
|
cooked_.Add(cooked, zone);
|
2014-12-03 14:17:16 +00:00
|
|
|
raw_.Add(raw, zone);
|
2014-11-14 18:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddExpression(Expression* expression, Zone* zone) {
|
|
|
|
DCHECK_NOT_NULL(expression);
|
|
|
|
expressions_.Add(expression, zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ZoneList<Expression*> cooked_;
|
2014-12-03 14:17:16 +00:00
|
|
|
ZoneList<Expression*> raw_;
|
2014-11-14 18:53:41 +00:00
|
|
|
ZoneList<Expression*> expressions_;
|
|
|
|
int pos_;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef TemplateLiteral* TemplateLiteralState;
|
|
|
|
|
|
|
|
V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos);
|
|
|
|
V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail);
|
|
|
|
V8_INLINE void AddTemplateExpression(TemplateLiteralState* state,
|
|
|
|
Expression* expression);
|
|
|
|
V8_INLINE Expression* CloseTemplateLiteral(TemplateLiteralState* state,
|
|
|
|
int start, Expression* tag);
|
|
|
|
V8_INLINE Expression* NoTemplateTag() { return NULL; }
|
2014-12-11 15:43:01 +00:00
|
|
|
V8_INLINE static bool IsTaggedTemplate(const Expression* tag) {
|
|
|
|
return tag != NULL;
|
|
|
|
}
|
2014-11-14 18:53:41 +00:00
|
|
|
|
2015-04-09 19:37:14 +00:00
|
|
|
V8_INLINE ZoneList<v8::internal::Expression*>* PrepareSpreadArguments(
|
|
|
|
ZoneList<v8::internal::Expression*>* list);
|
|
|
|
V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {}
|
|
|
|
V8_INLINE Expression* SpreadCall(Expression* function,
|
|
|
|
ZoneList<v8::internal::Expression*>* args,
|
|
|
|
int pos);
|
|
|
|
V8_INLINE Expression* SpreadCallNew(Expression* function,
|
|
|
|
ZoneList<v8::internal::Expression*>* args,
|
|
|
|
int pos);
|
|
|
|
|
2014-02-11 09:35:32 +00:00
|
|
|
private:
|
|
|
|
Parser* parser_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Parser : public ParserBase<ParserTraits> {
|
2010-10-27 12:33:48 +00:00
|
|
|
public:
|
2015-03-09 14:51:13 +00:00
|
|
|
explicit Parser(ParseInfo* info);
|
2013-04-08 11:53:50 +00:00
|
|
|
~Parser() {
|
2012-02-08 09:56:33 +00:00
|
|
|
delete reusable_preparser_;
|
|
|
|
reusable_preparser_ = NULL;
|
2014-07-10 11:34:14 +00:00
|
|
|
delete cached_parse_data_;
|
|
|
|
cached_parse_data_ = NULL;
|
2011-11-25 09:36:31 +00:00
|
|
|
}
|
2010-10-27 12:33:48 +00:00
|
|
|
|
Refactor parser mode configuration for correctness
This patch refactors the parser and preparser interface to be more
readable and type-safe. It has no behavior changes.
Previously, parsers and preparsers were configured via bitfield called
parser_flags in the Parser constructor, and flags in
PreParser::PreParseProgram, ParserApi::Parse, and ParserApi::PreParse.
This was error-prone in practice: six call sites passed incorrectly
typed values to this interface (a boolean FLAG value, a boolean false
and a boolean true value). None of these errors were caught by the
compiler because it's just an "int".
The parser flags interface was also awkward because it encoded a
language mode, but the language mode was only used to turn on harmony
scoping or not -- it wasn't used to actually set the parser's language
mode.
Fundamentally these errors came in because of the desire for a
procedural parser interface, in ParserApi. Because we need to be able
to configure the parser in various ways, the flags argument got added;
but no one understood how to use the flags properly. Also they were
only used by constructors: callers packed bits, and the constructors
unpacked them into booleans on the parser or preparser.
The solution is to allow parser construction, configuration, and
invocation to be separated. This patch does that.
It passes the existing tests.
BUG=
Review URL: https://codereview.chromium.org/13450007
Patch from Andy Wingo <wingo@igalia.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14151 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-04-05 13:01:06 +00:00
|
|
|
// Parses the source code represented by the compilation info and sets its
|
|
|
|
// function literal. Returns false (and deallocates any allocated AST
|
|
|
|
// nodes) if parsing failed.
|
2015-03-09 14:51:13 +00:00
|
|
|
static bool ParseStatic(ParseInfo* info);
|
|
|
|
bool Parse(ParseInfo* info);
|
|
|
|
void ParseOnBackground(ParseInfo* info);
|
2014-09-12 09:12:08 +00:00
|
|
|
|
|
|
|
// Handle errors detected during parsing, move statistics to Isolate,
|
|
|
|
// internalize strings (move them to the heap).
|
2015-02-20 09:39:32 +00:00
|
|
|
void Internalize(Isolate* isolate, Handle<Script> script, bool error);
|
|
|
|
void HandleSourceURLComments(Isolate* isolate, Handle<Script> script);
|
Refactor parser mode configuration for correctness
This patch refactors the parser and preparser interface to be more
readable and type-safe. It has no behavior changes.
Previously, parsers and preparsers were configured via bitfield called
parser_flags in the Parser constructor, and flags in
PreParser::PreParseProgram, ParserApi::Parse, and ParserApi::PreParse.
This was error-prone in practice: six call sites passed incorrectly
typed values to this interface (a boolean FLAG value, a boolean false
and a boolean true value). None of these errors were caught by the
compiler because it's just an "int".
The parser flags interface was also awkward because it encoded a
language mode, but the language mode was only used to turn on harmony
scoping or not -- it wasn't used to actually set the parser's language
mode.
Fundamentally these errors came in because of the desire for a
procedural parser interface, in ParserApi. Because we need to be able
to configure the parser in various ways, the flags argument got added;
but no one understood how to use the flags properly. Also they were
only used by constructors: callers packed bits, and the constructors
unpacked them into booleans on the parser or preparser.
The solution is to allow parser construction, configuration, and
invocation to be separated. This patch does that.
It passes the existing tests.
BUG=
Review URL: https://codereview.chromium.org/13450007
Patch from Andy Wingo <wingo@igalia.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14151 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-04-05 13:01:06 +00:00
|
|
|
|
2011-06-30 14:37:55 +00:00
|
|
|
private:
|
2014-02-11 09:35:32 +00:00
|
|
|
friend class ParserTraits;
|
|
|
|
|
2014-03-20 13:37:26 +00:00
|
|
|
// Limit the allowed number of local variables in a function. The hard limit
|
|
|
|
// is that offsets computed by FullCodeGenerator::StackOperand and similar
|
|
|
|
// functions are ints, and they should not overflow. In addition, accessing
|
|
|
|
// local variables creates user-controlled constants in the generated code,
|
|
|
|
// and we don't want too much user-controlled memory inside the code (this was
|
|
|
|
// the reason why this limit was introduced in the first place; see
|
|
|
|
// https://codereview.chromium.org/7003030/ ).
|
|
|
|
static const int kMaxNumFunctionLocals = 4194303; // 2^22-1
|
2011-11-09 13:54:26 +00:00
|
|
|
|
2013-10-01 09:27:03 +00:00
|
|
|
// Returns NULL if parsing failed.
|
2015-03-09 14:51:13 +00:00
|
|
|
FunctionLiteral* ParseProgram(Isolate* isolate, ParseInfo* info);
|
2013-10-01 09:27:03 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
FunctionLiteral* ParseLazy(Isolate* isolate, ParseInfo* info);
|
|
|
|
FunctionLiteral* ParseLazy(Isolate* isolate, ParseInfo* info,
|
2015-02-12 13:02:30 +00:00
|
|
|
Utf16CharacterStream* source);
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2010-12-07 14:03:59 +00:00
|
|
|
// Called by ParseProgram after setting up the scanner.
|
2015-04-16 12:42:43 +00:00
|
|
|
FunctionLiteral* DoParseProgram(ParseInfo* info);
|
2010-12-07 14:03:59 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
void SetCachedData(ParseInfo* info);
|
Refactor parser mode configuration for correctness
This patch refactors the parser and preparser interface to be more
readable and type-safe. It has no behavior changes.
Previously, parsers and preparsers were configured via bitfield called
parser_flags in the Parser constructor, and flags in
PreParser::PreParseProgram, ParserApi::Parse, and ParserApi::PreParse.
This was error-prone in practice: six call sites passed incorrectly
typed values to this interface (a boolean FLAG value, a boolean false
and a boolean true value). None of these errors were caught by the
compiler because it's just an "int".
The parser flags interface was also awkward because it encoded a
language mode, but the language mode was only used to turn on harmony
scoping or not -- it wasn't used to actually set the parser's language
mode.
Fundamentally these errors came in because of the desire for a
procedural parser interface, in ParserApi. Because we need to be able
to configure the parser in various ways, the flags argument got added;
but no one understood how to use the flags properly. Also they were
only used by constructors: callers packed bits, and the constructors
unpacked them into booleans on the parser or preparser.
The solution is to allow parser construction, configuration, and
invocation to be separated. This patch does that.
It passes the existing tests.
BUG=
Review URL: https://codereview.chromium.org/13450007
Patch from Andy Wingo <wingo@igalia.com>.
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14151 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2013-04-05 13:01:06 +00:00
|
|
|
|
2014-02-12 12:02:07 +00:00
|
|
|
bool inside_with() const { return scope_->inside_with(); }
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
ScriptCompiler::CompileOptions compile_options() const {
|
2015-02-12 13:02:30 +00:00
|
|
|
return compile_options_;
|
Change ScriptCompiler::CompileOptions to allow for two 'cache' modes
(parser or code) and to be explicit about cache consumption or production
(rather than making presence of cached_data imply one or the other.)
Also add a --cache flag to d8, to allow testing the functionality.
-----------------------------
API change
Reason: Currently, V8 supports a 'parser cache' for repeatedly executing the same script. We'd like to add a 2nd mode that would cache code, and would like to let the embedder decide which mode they chose (if any).
Note: Previously, the 'use cached data' property was implied by the presence of the cached data itself. (That is, kNoCompileOptions and source->cached_data != NULL.) That is no longer sufficient, since the presence of data is no longer sufficient to determine /which kind/ of data is present.
Changes from old behaviour:
- If you previously didn't use caching, nothing changes.
Example:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
- If you previously used caching, it worked like this:
- 1st run:
v8::CompileUnbound(isolate, source, kProduceToCache);
Then, source->cached_data would contain the
data-to-be cached. This remains the same, except you
need to tell V8 which type of data you want.
v8::CompileUnbound(isolate, source, kProduceParserCache);
- 2nd run:
v8::CompileUnbound(isolate, source, kNoCompileOptions);
with source->cached_data set to the data you received in
the first run. This will now ignore the cached data, and
you need to explicitly tell V8 to use it:
v8::CompileUnbound(isolate, source, kConsumeParserCache);
-----------------------------
BUG=
R=marja@chromium.org, yangguo@chromium.org
Review URL: https://codereview.chromium.org/389573006
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22431 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-16 12:18:33 +00:00
|
|
|
}
|
2014-11-17 12:16:27 +00:00
|
|
|
bool consume_cached_parse_data() const {
|
2015-02-12 13:02:30 +00:00
|
|
|
return compile_options_ == ScriptCompiler::kConsumeParserCache &&
|
2014-11-17 12:16:27 +00:00
|
|
|
cached_parse_data_ != NULL;
|
|
|
|
}
|
|
|
|
bool produce_cached_parse_data() const {
|
2015-02-12 13:02:30 +00:00
|
|
|
return compile_options_ == ScriptCompiler::kProduceParserCache;
|
2014-11-17 12:16:27 +00:00
|
|
|
}
|
2012-02-28 10:12:39 +00:00
|
|
|
Scope* DeclarationScope(VariableMode mode) {
|
2012-08-29 09:19:53 +00:00
|
|
|
return IsLexicalVariableMode(mode)
|
2014-02-12 12:02:07 +00:00
|
|
|
? scope_ : scope_->DeclarationScope();
|
2012-02-28 10:12:39 +00:00
|
|
|
}
|
2010-10-01 14:10:47 +00:00
|
|
|
|
|
|
|
// All ParseXXX functions take as the last argument an *ok parameter
|
|
|
|
// which is set to false if parsing failed; it is unchanged otherwise.
|
|
|
|
// By making the 'exception handling' explicit, we are forced to check
|
|
|
|
// for failure at the call sites.
|
2015-04-27 12:13:45 +00:00
|
|
|
void* ParseStatementList(ZoneList<Statement*>* body, int end_token, bool* ok);
|
2015-01-27 21:06:36 +00:00
|
|
|
Statement* ParseStatementListItem(bool* ok);
|
2015-02-25 23:00:10 +00:00
|
|
|
void* ParseModuleItemList(ZoneList<Statement*>* body, bool* ok);
|
2015-01-27 21:06:36 +00:00
|
|
|
Statement* ParseModuleItem(bool* ok);
|
2015-02-26 18:40:50 +00:00
|
|
|
const AstRawString* ParseModuleSpecifier(bool* ok);
|
2015-01-27 21:06:36 +00:00
|
|
|
Statement* ParseImportDeclaration(bool* ok);
|
2012-02-29 12:12:52 +00:00
|
|
|
Statement* ParseExportDeclaration(bool* ok);
|
2015-01-28 19:18:37 +00:00
|
|
|
Statement* ParseExportDefault(bool* ok);
|
2015-02-19 20:14:55 +00:00
|
|
|
void* ParseExportClause(ZoneList<const AstRawString*>* export_names,
|
|
|
|
ZoneList<Scanner::Location>* export_locations,
|
|
|
|
ZoneList<const AstRawString*>* local_names,
|
2015-01-30 03:26:50 +00:00
|
|
|
Scanner::Location* reserved_loc, bool* ok);
|
2015-02-26 18:40:50 +00:00
|
|
|
ZoneList<ImportDeclaration*>* ParseNamedImports(int pos, bool* ok);
|
2014-06-24 14:03:24 +00:00
|
|
|
Statement* ParseStatement(ZoneList<const AstRawString*>* labels, bool* ok);
|
2015-02-17 16:25:49 +00:00
|
|
|
Statement* ParseSubStatement(ZoneList<const AstRawString*>* labels, bool* ok);
|
2015-04-16 13:29:29 +00:00
|
|
|
Statement* ParseStatementAsUnlabelled(ZoneList<const AstRawString*>* labels,
|
|
|
|
bool* ok);
|
2014-06-24 14:03:24 +00:00
|
|
|
Statement* ParseFunctionDeclaration(ZoneList<const AstRawString*>* names,
|
|
|
|
bool* ok);
|
2014-09-16 22:15:39 +00:00
|
|
|
Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names,
|
|
|
|
bool* ok);
|
2010-10-01 14:10:47 +00:00
|
|
|
Statement* ParseNativeDeclaration(bool* ok);
|
2014-06-24 14:03:24 +00:00
|
|
|
Block* ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok);
|
2011-08-16 14:24:12 +00:00
|
|
|
Block* ParseVariableStatement(VariableDeclarationContext var_context,
|
2014-06-24 14:03:24 +00:00
|
|
|
ZoneList<const AstRawString*>* names,
|
2011-08-16 14:24:12 +00:00
|
|
|
bool* ok);
|
2015-05-15 09:56:31 +00:00
|
|
|
|
|
|
|
struct DeclarationDescriptor {
|
|
|
|
Parser* parser;
|
|
|
|
Scope* declaration_scope;
|
|
|
|
Scope* scope;
|
|
|
|
VariableMode mode;
|
|
|
|
bool is_const;
|
|
|
|
bool needs_init;
|
2015-05-21 17:47:07 +00:00
|
|
|
int declaration_pos;
|
|
|
|
int initialization_pos;
|
2015-05-15 09:56:31 +00:00
|
|
|
Token::Value init_op;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DeclarationParsingResult {
|
|
|
|
struct Declaration {
|
|
|
|
Declaration(Expression* pattern, int initializer_position,
|
|
|
|
Expression* initializer)
|
|
|
|
: pattern(pattern),
|
|
|
|
initializer_position(initializer_position),
|
|
|
|
initializer(initializer) {}
|
|
|
|
|
|
|
|
Expression* pattern;
|
|
|
|
int initializer_position;
|
|
|
|
Expression* initializer;
|
|
|
|
};
|
|
|
|
|
|
|
|
DeclarationParsingResult()
|
|
|
|
: declarations(4),
|
|
|
|
first_initializer_loc(Scanner::Location::invalid()),
|
|
|
|
bindings_loc(Scanner::Location::invalid()) {}
|
|
|
|
|
|
|
|
Block* BuildInitializationBlock(ZoneList<const AstRawString*>* names,
|
|
|
|
bool* ok);
|
|
|
|
const AstRawString* SingleName() const;
|
|
|
|
|
|
|
|
DeclarationDescriptor descriptor;
|
|
|
|
List<Declaration> declarations;
|
|
|
|
Scanner::Location first_initializer_loc;
|
|
|
|
Scanner::Location bindings_loc;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PatternRewriter : private AstVisitor {
|
|
|
|
public:
|
|
|
|
static void DeclareAndInitializeVariables(
|
|
|
|
Block* block, const DeclarationDescriptor* declaration_descriptor,
|
|
|
|
const DeclarationParsingResult::Declaration* declaration,
|
|
|
|
ZoneList<const AstRawString*>* names, bool* ok);
|
|
|
|
|
|
|
|
void set_initializer_position(int pos) { initializer_position_ = pos; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
PatternRewriter() {}
|
|
|
|
|
|
|
|
#define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override;
|
|
|
|
// Visiting functions for AST nodes make this an AstVisitor.
|
|
|
|
AST_NODE_LIST(DECLARE_VISIT)
|
|
|
|
#undef DECLARE_VISIT
|
|
|
|
virtual void Visit(AstNode* node) override;
|
|
|
|
|
|
|
|
void RecurseIntoSubpattern(AstNode* pattern, Expression* value) {
|
|
|
|
Expression* old_value = current_value_;
|
|
|
|
current_value_ = value;
|
|
|
|
pattern->Accept(this);
|
|
|
|
current_value_ = old_value;
|
|
|
|
}
|
|
|
|
|
2015-05-20 08:08:26 +00:00
|
|
|
Variable* CreateTempVar(Expression* value = nullptr);
|
2015-05-19 14:29:50 +00:00
|
|
|
|
2015-05-15 09:56:31 +00:00
|
|
|
AstNodeFactory* factory() const { return descriptor_->parser->factory(); }
|
|
|
|
AstValueFactory* ast_value_factory() const {
|
|
|
|
return descriptor_->parser->ast_value_factory();
|
|
|
|
}
|
|
|
|
bool inside_with() const { return descriptor_->parser->inside_with(); }
|
|
|
|
Zone* zone() const { return descriptor_->parser->zone(); }
|
|
|
|
|
|
|
|
Expression* pattern_;
|
|
|
|
int initializer_position_;
|
|
|
|
Block* block_;
|
|
|
|
const DeclarationDescriptor* descriptor_;
|
|
|
|
ZoneList<const AstRawString*>* names_;
|
|
|
|
Expression* current_value_;
|
|
|
|
bool* ok_;
|
|
|
|
};
|
|
|
|
|
2015-06-01 18:34:55 +00:00
|
|
|
|
2015-05-15 09:56:31 +00:00
|
|
|
void ParseVariableDeclarations(VariableDeclarationContext var_context,
|
|
|
|
DeclarationParsingResult* parsing_result,
|
|
|
|
bool* ok);
|
2014-06-24 14:03:24 +00:00
|
|
|
Statement* ParseExpressionOrLabelledStatement(
|
|
|
|
ZoneList<const AstRawString*>* labels, bool* ok);
|
|
|
|
IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels,
|
|
|
|
bool* ok);
|
2010-10-01 14:10:47 +00:00
|
|
|
Statement* ParseContinueStatement(bool* ok);
|
2014-06-24 14:03:24 +00:00
|
|
|
Statement* ParseBreakStatement(ZoneList<const AstRawString*>* labels,
|
|
|
|
bool* ok);
|
2010-10-01 14:10:47 +00:00
|
|
|
Statement* ParseReturnStatement(bool* ok);
|
2014-06-24 14:03:24 +00:00
|
|
|
Statement* ParseWithStatement(ZoneList<const AstRawString*>* labels,
|
|
|
|
bool* ok);
|
2010-10-01 14:10:47 +00:00
|
|
|
CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok);
|
2014-06-24 14:03:24 +00:00
|
|
|
SwitchStatement* ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
|
|
|
|
bool* ok);
|
|
|
|
DoWhileStatement* ParseDoWhileStatement(ZoneList<const AstRawString*>* labels,
|
|
|
|
bool* ok);
|
|
|
|
WhileStatement* ParseWhileStatement(ZoneList<const AstRawString*>* labels,
|
|
|
|
bool* ok);
|
|
|
|
Statement* ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok);
|
2010-10-01 14:10:47 +00:00
|
|
|
Statement* ParseThrowStatement(bool* ok);
|
|
|
|
Expression* MakeCatchContext(Handle<String> id, VariableProxy* value);
|
|
|
|
TryStatement* ParseTryStatement(bool* ok);
|
|
|
|
DebuggerStatement* ParseDebuggerStatement(bool* ok);
|
2011-10-25 08:33:08 +00:00
|
|
|
|
|
|
|
// Support for hamony block scoped bindings.
|
2014-06-24 14:03:24 +00:00
|
|
|
Block* ParseScopedBlock(ZoneList<const AstRawString*>* labels, bool* ok);
|
2010-10-01 14:10:47 +00:00
|
|
|
|
2015-05-20 08:08:26 +00:00
|
|
|
// !%_IsSpecObject(result = iterator.next()) &&
|
|
|
|
// %ThrowIteratorResultNotAnObject(result)
|
|
|
|
Expression* BuildIteratorNextResult(Expression* iterator, Variable* result,
|
|
|
|
int pos);
|
|
|
|
|
|
|
|
|
2013-06-07 11:12:21 +00:00
|
|
|
// Initialize the components of a for-in / for-of statement.
|
|
|
|
void InitializeForEachStatement(ForEachStatement* stmt,
|
|
|
|
Expression* each,
|
|
|
|
Expression* subject,
|
|
|
|
Statement* body);
|
2015-03-03 18:34:30 +00:00
|
|
|
Statement* DesugarLexicalBindingsInForStatement(
|
|
|
|
Scope* inner_scope, bool is_const, ZoneList<const AstRawString*>* names,
|
2014-06-24 14:03:24 +00:00
|
|
|
ForStatement* loop, Statement* init, Expression* cond, Statement* next,
|
|
|
|
Statement* body, bool* ok);
|
2013-06-07 11:12:21 +00:00
|
|
|
|
2014-02-04 11:26:19 +00:00
|
|
|
FunctionLiteral* ParseFunctionLiteral(
|
2014-09-10 16:39:42 +00:00
|
|
|
const AstRawString* name, Scanner::Location function_name_location,
|
|
|
|
bool name_is_strict_reserved, FunctionKind kind,
|
|
|
|
int function_token_position, FunctionLiteral::FunctionType type,
|
|
|
|
FunctionLiteral::ArityRestriction arity_restriction, bool* ok);
|
2010-10-01 14:10:47 +00:00
|
|
|
|
2014-11-14 15:05:05 +00:00
|
|
|
|
|
|
|
ClassLiteral* ParseClassLiteral(const AstRawString* name,
|
|
|
|
Scanner::Location class_name_location,
|
|
|
|
bool name_is_strict_reserved, int pos,
|
|
|
|
bool* ok);
|
|
|
|
|
2010-10-01 14:10:47 +00:00
|
|
|
// Magical syntax support.
|
|
|
|
Expression* ParseV8Intrinsic(bool* ok);
|
|
|
|
|
|
|
|
// Get odd-ball literals.
|
2013-10-14 09:24:58 +00:00
|
|
|
Literal* GetLiteralUndefined(int position);
|
2010-10-01 14:10:47 +00:00
|
|
|
|
2011-09-01 12:31:18 +00:00
|
|
|
// For harmony block scoping mode: Check if the scope has conflicting var/let
|
|
|
|
// declarations from different scopes. It covers for example
|
|
|
|
//
|
|
|
|
// function f() { { { var x; } let x; } }
|
|
|
|
// function g() { { var x; let x; } }
|
|
|
|
//
|
|
|
|
// The var declarations are hoisted to the function scope, but originate from
|
|
|
|
// a scope where the name has also been let bound or the var declaration is
|
|
|
|
// hoisted over such a scope.
|
|
|
|
void CheckConflictingVarDeclarations(Scope* scope, bool* ok);
|
|
|
|
|
2010-10-01 14:10:47 +00:00
|
|
|
// Parser support
|
2015-02-17 20:51:24 +00:00
|
|
|
VariableProxy* NewUnresolved(const AstRawString* name, VariableMode mode);
|
2015-02-26 13:48:10 +00:00
|
|
|
Variable* Declare(Declaration* declaration, bool resolve, bool* ok);
|
2010-10-01 14:10:47 +00:00
|
|
|
|
2014-06-24 14:03:24 +00:00
|
|
|
bool TargetStackContainsLabel(const AstRawString* label);
|
|
|
|
BreakableStatement* LookupBreakTarget(const AstRawString* label, bool* ok);
|
|
|
|
IterationStatement* LookupContinueTarget(const AstRawString* label, bool* ok);
|
2010-10-01 14:10:47 +00:00
|
|
|
|
2015-02-11 17:22:50 +00:00
|
|
|
void AddAssertIsConstruct(ZoneList<Statement*>* body, int pos);
|
2015-05-18 20:15:08 +00:00
|
|
|
Statement* BuildAssertIsCoercible(Variable* var);
|
2015-02-11 17:22:50 +00:00
|
|
|
|
2010-11-02 11:45:47 +00:00
|
|
|
// Factory methods.
|
2014-11-07 16:39:00 +00:00
|
|
|
FunctionLiteral* DefaultConstructor(bool call_super, Scope* scope, int pos,
|
|
|
|
int end_pos);
|
|
|
|
|
2014-04-15 08:29:24 +00:00
|
|
|
// Skip over a lazy function, either using cached data if we have it, or
|
|
|
|
// by parsing the function with PreParser. Consumes the ending }.
|
2015-05-06 10:21:20 +00:00
|
|
|
//
|
|
|
|
// If bookmark is set, the (pre-)parser may decide to abort skipping
|
|
|
|
// in order to force the function to be eagerly parsed, after all.
|
|
|
|
// In this case, it'll reset the scanner using the bookmark.
|
2015-04-22 11:04:25 +00:00
|
|
|
void SkipLazyFunctionBody(int* materialized_literal_count,
|
2015-05-06 10:21:20 +00:00
|
|
|
int* expected_property_count, bool* ok,
|
|
|
|
Scanner::BookmarkScope* bookmark = nullptr);
|
2014-04-15 08:29:24 +00:00
|
|
|
|
|
|
|
PreParser::PreParseResult ParseLazyFunctionBodyWithPreParser(
|
2015-05-06 10:21:20 +00:00
|
|
|
SingletonLogger* logger, Scanner::BookmarkScope* bookmark = nullptr);
|
2014-04-15 08:29:24 +00:00
|
|
|
|
|
|
|
// Consumes the ending }.
|
2014-06-24 14:03:24 +00:00
|
|
|
ZoneList<Statement*>* ParseEagerFunctionBody(
|
|
|
|
const AstRawString* function_name, int pos, Variable* fvar,
|
2015-02-06 10:34:50 +00:00
|
|
|
Token::Value fvar_init_op, FunctionKind kind, bool* ok);
|
2011-11-25 09:36:31 +00:00
|
|
|
|
2015-02-12 13:02:30 +00:00
|
|
|
void ThrowPendingError(Isolate* isolate, Handle<Script> script);
|
2014-05-20 12:22:04 +00:00
|
|
|
|
2014-11-14 18:53:41 +00:00
|
|
|
TemplateLiteralState OpenTemplateLiteral(int pos);
|
|
|
|
void AddTemplateSpan(TemplateLiteralState* state, bool tail);
|
|
|
|
void AddTemplateExpression(TemplateLiteralState* state,
|
|
|
|
Expression* expression);
|
|
|
|
Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start,
|
|
|
|
Expression* tag);
|
2014-12-03 14:17:16 +00:00
|
|
|
uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit);
|
|
|
|
|
2015-04-09 19:37:14 +00:00
|
|
|
ZoneList<v8::internal::Expression*>* PrepareSpreadArguments(
|
|
|
|
ZoneList<v8::internal::Expression*>* list);
|
|
|
|
Expression* SpreadCall(Expression* function,
|
|
|
|
ZoneList<v8::internal::Expression*>* args, int pos);
|
|
|
|
Expression* SpreadCallNew(Expression* function,
|
|
|
|
ZoneList<v8::internal::Expression*>* args, int pos);
|
|
|
|
|
2011-11-01 07:47:15 +00:00
|
|
|
Scanner scanner_;
|
2013-10-14 13:07:20 +00:00
|
|
|
PreParser* reusable_preparser_;
|
2013-08-23 09:25:37 +00:00
|
|
|
Scope* original_scope_; // for ES5 function declarations in sloppy eval
|
2010-11-02 11:45:47 +00:00
|
|
|
Target* target_stack_; // for break, continue statements
|
2015-02-12 13:02:30 +00:00
|
|
|
ScriptCompiler::CompileOptions compile_options_;
|
2014-07-10 10:28:05 +00:00
|
|
|
ParseData* cached_parse_data_;
|
2011-11-11 13:48:14 +00:00
|
|
|
|
2015-02-25 14:17:39 +00:00
|
|
|
PendingCompilationErrorHandler pending_error_handler_;
|
2014-06-30 13:35:16 +00:00
|
|
|
|
2014-09-02 11:36:21 +00:00
|
|
|
// Other information which will be stored in Parser and moved to Isolate after
|
|
|
|
// parsing.
|
2014-06-30 13:35:16 +00:00
|
|
|
int use_counts_[v8::Isolate::kUseCounterFeatureCount];
|
2014-09-02 11:36:21 +00:00
|
|
|
int total_preparse_skipped_;
|
|
|
|
HistogramTimer* pre_parse_timer_;
|
2015-02-12 13:02:30 +00:00
|
|
|
|
|
|
|
bool parsing_on_main_thread_;
|
2010-10-01 14:10:47 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-23 07:27:47 +00:00
|
|
|
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
bool ParserTraits::IsFutureStrictReserved(
|
|
|
|
const AstRawString* identifier) const {
|
2014-11-03 19:53:36 +00:00
|
|
|
return parser_->scanner()->IdentifierIsFutureStrictReserved(identifier);
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-03 17:42:41 +00:00
|
|
|
Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type,
|
|
|
|
FunctionKind kind) {
|
|
|
|
return parser_->NewScope(parent_scope, scope_type, kind);
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AstRawString* ParserTraits::EmptyIdentifierString() {
|
2014-09-11 09:52:36 +00:00
|
|
|
return parser_->ast_value_factory()->empty_string();
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-22 11:04:25 +00:00
|
|
|
void ParserTraits::SkipLazyFunctionBody(int* materialized_literal_count,
|
2015-05-06 10:21:20 +00:00
|
|
|
int* expected_property_count, bool* ok,
|
|
|
|
Scanner::BookmarkScope* bookmark) {
|
|
|
|
return parser_->SkipLazyFunctionBody(materialized_literal_count,
|
|
|
|
expected_property_count, ok, bookmark);
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody(
|
|
|
|
const AstRawString* name, int pos, Variable* fvar,
|
2015-02-06 10:34:50 +00:00
|
|
|
Token::Value fvar_init_op, FunctionKind kind, bool* ok) {
|
|
|
|
return parser_->ParseEagerFunctionBody(name, pos, fvar, fvar_init_op, kind,
|
|
|
|
ok);
|
Implement handling of arrow functions in the parser
Arrow functions are parsed from ParseAssignmentExpression(). Handling the
parameter list is done by letting ParseConditionalExpression() parse a comma
separated list of identifiers, and it returns a tree of BinaryOperation nodes
with VariableProxy leaves, or a single VariableProxy if there is only one
parameter. When the arrow token "=>" is found, the VariableProxy nodes are
passed to ParseArrowFunctionLiteral(), which will then skip parsing the
paramaeter list. This avoids having to rewind when the arrow is found and
restart parsing the parameter list.
Note that the empty parameter list "()" is handled directly in
ParsePrimaryExpression(): after is has consumed the opening parenthesis,
if a closing parenthesis follows, then the only valid input is an arrow
function. In this case, ParsePrimaryExpression() directly calls
ParseArrowFunctionLiteral(), to avoid needing to return a sentinel value
to signal the empty parameter list. Because it will consume the body of
the arrow function, ParseAssignmentExpression() will not see the arrow
"=>" token as next, and return the already-parser expression.
The implementation is done in ParserBase, so it was needed to do some
additions to ParserBase, ParserTraits and PreParserTraits. Some of the
glue code can be removed later on when more more functionality is moved
to ParserBase.
Additionally, this adds a runtime flag "harmony_arrow_functions"
(disabled by default); enabling "harmony" will enable it as well.
BUG=v8:2700
LOG=N
R=marja@chromium.org
Review URL: https://codereview.chromium.org/383983002
Patch from Adrián Pérez de Castro <aperez@igalia.com>.
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22366 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-07-14 07:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParserTraits::CheckConflictingVarDeclarations(v8::internal::Scope* scope,
|
|
|
|
bool* ok) {
|
|
|
|
parser_->CheckConflictingVarDeclarations(scope, ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-23 07:27:47 +00:00
|
|
|
// Support for handling complex values (array and object literals) that
|
|
|
|
// can be fully handled at compile time.
|
|
|
|
class CompileTimeValue: public AllStatic {
|
|
|
|
public:
|
2013-06-06 13:28:22 +00:00
|
|
|
enum LiteralType {
|
2010-03-11 10:34:29 +00:00
|
|
|
OBJECT_LITERAL_FAST_ELEMENTS,
|
|
|
|
OBJECT_LITERAL_SLOW_ELEMENTS,
|
2009-03-23 07:27:47 +00:00
|
|
|
ARRAY_LITERAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool IsCompileTimeValue(Expression* expression);
|
|
|
|
|
|
|
|
// Get the value as a compile time value.
|
2013-09-04 07:05:11 +00:00
|
|
|
static Handle<FixedArray> GetValue(Isolate* isolate, Expression* expression);
|
2009-03-23 07:27:47 +00:00
|
|
|
|
|
|
|
// Get the type of a compile time value returned by GetValue().
|
2013-06-06 13:28:22 +00:00
|
|
|
static LiteralType GetLiteralType(Handle<FixedArray> value);
|
2009-03-23 07:27:47 +00:00
|
|
|
|
|
|
|
// Get the elements array of a compile time value returned by GetValue().
|
|
|
|
static Handle<FixedArray> GetElements(Handle<FixedArray> value);
|
|
|
|
|
|
|
|
private:
|
2013-06-06 13:28:22 +00:00
|
|
|
static const int kLiteralTypeSlot = 0;
|
2009-03-23 07:27:47 +00:00
|
|
|
static const int kElementsSlot = 1;
|
|
|
|
|
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
|
|
|
|
};
|
|
|
|
|
2014-11-14 18:53:41 +00:00
|
|
|
|
|
|
|
ParserTraits::TemplateLiteralState ParserTraits::OpenTemplateLiteral(int pos) {
|
|
|
|
return parser_->OpenTemplateLiteral(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ParserTraits::AddTemplateSpan(TemplateLiteralState* state, bool tail) {
|
|
|
|
parser_->AddTemplateSpan(state, tail);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ParserTraits::AddTemplateExpression(TemplateLiteralState* state,
|
|
|
|
Expression* expression) {
|
|
|
|
parser_->AddTemplateExpression(state, expression);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state,
|
|
|
|
int start, Expression* tag) {
|
|
|
|
return parser_->CloseTemplateLiteral(state, start, tag);
|
|
|
|
}
|
2015-04-09 19:37:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
ZoneList<v8::internal::Expression*>* ParserTraits::PrepareSpreadArguments(
|
|
|
|
ZoneList<v8::internal::Expression*>* list) {
|
|
|
|
return parser_->PrepareSpreadArguments(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Expression* ParserTraits::SpreadCall(Expression* function,
|
|
|
|
ZoneList<v8::internal::Expression*>* args,
|
|
|
|
int pos) {
|
|
|
|
return parser_->SpreadCall(function, args, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Expression* ParserTraits::SpreadCallNew(
|
|
|
|
Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) {
|
|
|
|
return parser_->SpreadCallNew(function, args, pos);
|
|
|
|
}
|
2015-06-09 17:13:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ParserTraits::DeclareFormalParameter(Scope* scope,
|
|
|
|
const AstRawString* name,
|
|
|
|
ExpressionClassifier* classifier,
|
|
|
|
bool is_rest) {
|
|
|
|
bool is_duplicate = false;
|
|
|
|
Variable* var = scope->DeclareParameter(name, VAR, is_rest, &is_duplicate);
|
|
|
|
if (is_sloppy(scope->language_mode())) {
|
|
|
|
// TODO(sigurds) Mark every parameter as maybe assigned. This is a
|
|
|
|
// conservative approximation necessary to account for parameters
|
|
|
|
// that are assigned via the arguments array.
|
|
|
|
var->set_maybe_assigned();
|
|
|
|
}
|
|
|
|
if (is_duplicate) {
|
|
|
|
classifier->RecordDuplicateFormalParameterError(
|
|
|
|
parser_->scanner()->location());
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_PARSER_H_
|