Cleanup: Move ParseInfo to a separate file.
This makes us able to get rid of dependencies to parser.h from places which only need the ParseInfo, and also gets rid of the curious Parser <-> Compiler circular dependency. Also IWYUd where necessary. BUG= Review-Url: https://codereview.chromium.org/2268513002 Cr-Commit-Position: refs/heads/master@{#38777}
This commit is contained in:
parent
a311bfa693
commit
f9d6076115
6
BUILD.gn
6
BUILD.gn
@ -1450,6 +1450,8 @@ v8_source_set("v8_base") {
|
||||
"src/parsing/func-name-inferrer.h",
|
||||
"src/parsing/parameter-initializer-rewriter.cc",
|
||||
"src/parsing/parameter-initializer-rewriter.h",
|
||||
"src/parsing/parse-info.cc",
|
||||
"src/parsing/parse-info.h",
|
||||
"src/parsing/parser-base.h",
|
||||
"src/parsing/parser.cc",
|
||||
"src/parsing/parser.h",
|
||||
@ -2082,9 +2084,7 @@ v8_source_set("v8_libbase") {
|
||||
defines = []
|
||||
|
||||
if (is_posix) {
|
||||
sources += [
|
||||
"src/base/platform/platform-posix.cc",
|
||||
]
|
||||
sources += [ "src/base/platform/platform-posix.cc" ]
|
||||
}
|
||||
|
||||
if (is_linux) {
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "src/handles.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/objects.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
|
||||
#include "src/wasm/encoder.h"
|
||||
#include "src/wasm/module-decoder.h"
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "src/accessors.h"
|
||||
#include "src/bootstrapper.h"
|
||||
#include "src/messages.h"
|
||||
#include "src/parsing/parser.h" // for ParseInfo
|
||||
#include "src/parsing/parse-info.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "src/base/platform/platform.h"
|
||||
#include "src/base/platform/semaphore.h"
|
||||
#include "src/compiler.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/parser.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "src/global-handles.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/scanner-character-streams.h"
|
||||
#include "src/unicode-cache.h"
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "src/compiler/operator-properties.h"
|
||||
#include "src/compiler/type-hint-analyzer.h"
|
||||
#include "src/isolate-inl.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/rewriter.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -69,7 +69,7 @@
|
||||
#include "src/compiler/zone-pool.h"
|
||||
#include "src/isolate-inl.h"
|
||||
#include "src/ostreams.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/register-configuration.h"
|
||||
#include "src/type-info.h"
|
||||
#include "src/utils.h"
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "src/crankshaft/compilation-phase.h"
|
||||
#include "src/crankshaft/hydrogen-instructions.h"
|
||||
#include "src/globals.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/zone.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "src/frames-inl.h"
|
||||
#include "src/globals.h"
|
||||
#include "src/isolate-inl.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/rewriter.h"
|
||||
|
||||
|
113
src/parsing/parse-info.cc
Normal file
113
src/parsing/parse-info.cc
Normal file
@ -0,0 +1,113 @@
|
||||
// Copyright 2016 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "src/parsing/parse-info.h"
|
||||
|
||||
#include "src/ast/ast-value-factory.h"
|
||||
#include "src/ast/ast.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
ParseInfo::ParseInfo(Zone* zone)
|
||||
: zone_(zone),
|
||||
flags_(0),
|
||||
source_stream_(nullptr),
|
||||
source_stream_encoding_(ScriptCompiler::StreamedSource::ONE_BYTE),
|
||||
character_stream_(nullptr),
|
||||
extension_(nullptr),
|
||||
compile_options_(ScriptCompiler::kNoCompileOptions),
|
||||
script_scope_(nullptr),
|
||||
unicode_cache_(nullptr),
|
||||
stack_limit_(0),
|
||||
hash_seed_(0),
|
||||
compiler_hints_(0),
|
||||
start_position_(0),
|
||||
end_position_(0),
|
||||
isolate_(nullptr),
|
||||
cached_data_(nullptr),
|
||||
ast_value_factory_(nullptr),
|
||||
function_name_(nullptr),
|
||||
literal_(nullptr) {}
|
||||
|
||||
ParseInfo::ParseInfo(Zone* zone, Handle<JSFunction> function)
|
||||
: ParseInfo(zone, Handle<SharedFunctionInfo>(function->shared())) {
|
||||
set_context(Handle<Context>(function->context()));
|
||||
}
|
||||
|
||||
ParseInfo::ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared)
|
||||
: ParseInfo(zone) {
|
||||
isolate_ = shared->GetIsolate();
|
||||
|
||||
set_lazy();
|
||||
set_hash_seed(isolate_->heap()->HashSeed());
|
||||
set_is_named_expression(shared->is_named_expression());
|
||||
set_calls_eval(shared->scope_info()->CallsEval());
|
||||
set_compiler_hints(shared->compiler_hints());
|
||||
set_start_position(shared->start_position());
|
||||
set_end_position(shared->end_position());
|
||||
set_stack_limit(isolate_->stack_guard()->real_climit());
|
||||
set_unicode_cache(isolate_->unicode_cache());
|
||||
set_language_mode(shared->language_mode());
|
||||
set_shared_info(shared);
|
||||
|
||||
Handle<Script> script(Script::cast(shared->script()));
|
||||
set_script(script);
|
||||
if (!script.is_null() && script->type() == Script::TYPE_NATIVE) {
|
||||
set_native();
|
||||
}
|
||||
}
|
||||
|
||||
ParseInfo::ParseInfo(Zone* zone, Handle<Script> script) : ParseInfo(zone) {
|
||||
isolate_ = script->GetIsolate();
|
||||
|
||||
set_hash_seed(isolate_->heap()->HashSeed());
|
||||
set_stack_limit(isolate_->stack_guard()->real_climit());
|
||||
set_unicode_cache(isolate_->unicode_cache());
|
||||
set_script(script);
|
||||
|
||||
if (script->type() == Script::TYPE_NATIVE) {
|
||||
set_native();
|
||||
}
|
||||
}
|
||||
|
||||
ParseInfo::~ParseInfo() {
|
||||
if (ast_value_factory_owned()) {
|
||||
delete ast_value_factory_;
|
||||
set_ast_value_factory_owned(false);
|
||||
}
|
||||
ast_value_factory_ = nullptr;
|
||||
}
|
||||
|
||||
DeclarationScope* ParseInfo::scope() const { return literal()->scope(); }
|
||||
|
||||
bool ParseInfo::is_declaration() const {
|
||||
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsDeclaration)) != 0;
|
||||
}
|
||||
|
||||
bool ParseInfo::is_arrow() const {
|
||||
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsArrow)) != 0;
|
||||
}
|
||||
|
||||
bool ParseInfo::is_async() const {
|
||||
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsAsyncFunction)) != 0;
|
||||
}
|
||||
|
||||
bool ParseInfo::is_default_constructor() const {
|
||||
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsDefaultConstructor)) !=
|
||||
0;
|
||||
}
|
||||
|
||||
FunctionKind ParseInfo::function_kind() const {
|
||||
return SharedFunctionInfo::FunctionKindBits::decode(compiler_hints_);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
bool ParseInfo::script_is_native() const {
|
||||
return script_->type() == Script::TYPE_NATIVE;
|
||||
}
|
||||
#endif // DEBUG
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
245
src/parsing/parse-info.h
Normal file
245
src/parsing/parse-info.h
Normal file
@ -0,0 +1,245 @@
|
||||
// Copyright 2016 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_PARSING_PARSE_INFO_H_
|
||||
#define V8_PARSING_PARSE_INFO_H_
|
||||
|
||||
#include "include/v8.h"
|
||||
#include "src/globals.h"
|
||||
#include "src/handles.h"
|
||||
|
||||
namespace v8 {
|
||||
|
||||
class Extension;
|
||||
|
||||
namespace internal {
|
||||
|
||||
class AstRawString;
|
||||
class AstValueFactory;
|
||||
class DeclarationScope;
|
||||
class FunctionLiteral;
|
||||
class ScriptData;
|
||||
class SharedFunctionInfo;
|
||||
class UnicodeCache;
|
||||
class Utf16CharacterStream;
|
||||
class Zone;
|
||||
|
||||
// A container for the inputs, configuration options, and outputs of parsing.
|
||||
class ParseInfo {
|
||||
public:
|
||||
explicit ParseInfo(Zone* zone);
|
||||
ParseInfo(Zone* zone, Handle<JSFunction> function);
|
||||
ParseInfo(Zone* zone, Handle<Script> script);
|
||||
// TODO(all) Only used via Debug::FindSharedFunctionInfoInScript, remove?
|
||||
ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared);
|
||||
|
||||
~ParseInfo();
|
||||
|
||||
Zone* zone() const { 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(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)
|
||||
FLAG_ACCESSOR(kIsNamedExpression, is_named_expression,
|
||||
set_is_named_expression)
|
||||
FLAG_ACCESSOR(kCallsEval, calls_eval, set_calls_eval)
|
||||
|
||||
#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() const {
|
||||
return source_stream_;
|
||||
}
|
||||
void set_source_stream(ScriptCompiler::ExternalSourceStream* source_stream) {
|
||||
source_stream_ = source_stream;
|
||||
}
|
||||
|
||||
ScriptCompiler::StreamedSource::Encoding source_stream_encoding() const {
|
||||
return source_stream_encoding_;
|
||||
}
|
||||
void set_source_stream_encoding(
|
||||
ScriptCompiler::StreamedSource::Encoding source_stream_encoding) {
|
||||
source_stream_encoding_ = source_stream_encoding;
|
||||
}
|
||||
|
||||
Utf16CharacterStream* character_stream() const { return character_stream_; }
|
||||
void set_character_stream(Utf16CharacterStream* character_stream) {
|
||||
character_stream_ = character_stream;
|
||||
}
|
||||
|
||||
v8::Extension* extension() const { return extension_; }
|
||||
void set_extension(v8::Extension* extension) { extension_ = extension; }
|
||||
|
||||
ScriptData** cached_data() const { return cached_data_; }
|
||||
void set_cached_data(ScriptData** cached_data) { cached_data_ = cached_data; }
|
||||
|
||||
ScriptCompiler::CompileOptions compile_options() const {
|
||||
return compile_options_;
|
||||
}
|
||||
void set_compile_options(ScriptCompiler::CompileOptions compile_options) {
|
||||
compile_options_ = compile_options;
|
||||
}
|
||||
|
||||
DeclarationScope* script_scope() const { return script_scope_; }
|
||||
void set_script_scope(DeclarationScope* script_scope) {
|
||||
script_scope_ = script_scope;
|
||||
}
|
||||
|
||||
AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
|
||||
void set_ast_value_factory(AstValueFactory* ast_value_factory) {
|
||||
ast_value_factory_ = ast_value_factory;
|
||||
}
|
||||
|
||||
const AstRawString* function_name() const { return function_name_; }
|
||||
void set_function_name(const AstRawString* function_name) {
|
||||
function_name_ = function_name;
|
||||
}
|
||||
|
||||
FunctionLiteral* literal() const { return literal_; }
|
||||
void set_literal(FunctionLiteral* literal) { literal_ = literal; }
|
||||
|
||||
DeclarationScope* scope() const;
|
||||
|
||||
UnicodeCache* unicode_cache() const { return unicode_cache_; }
|
||||
void set_unicode_cache(UnicodeCache* unicode_cache) {
|
||||
unicode_cache_ = unicode_cache;
|
||||
}
|
||||
|
||||
uintptr_t stack_limit() const { return stack_limit_; }
|
||||
void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; }
|
||||
|
||||
uint32_t hash_seed() const { return hash_seed_; }
|
||||
void set_hash_seed(uint32_t hash_seed) { hash_seed_ = hash_seed; }
|
||||
|
||||
int compiler_hints() const { return compiler_hints_; }
|
||||
void set_compiler_hints(int compiler_hints) {
|
||||
compiler_hints_ = compiler_hints;
|
||||
}
|
||||
|
||||
int start_position() const { return start_position_; }
|
||||
void set_start_position(int start_position) {
|
||||
start_position_ = start_position;
|
||||
}
|
||||
|
||||
int end_position() const { return end_position_; }
|
||||
void set_end_position(int end_position) { end_position_ = end_position; }
|
||||
|
||||
// Getters for individual compiler hints.
|
||||
bool is_declaration() const;
|
||||
bool is_arrow() const;
|
||||
bool is_async() const;
|
||||
bool is_default_constructor() const;
|
||||
FunctionKind function_kind() const;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// TODO(titzer): these should not be part of ParseInfo.
|
||||
//--------------------------------------------------------------------------
|
||||
Isolate* isolate() const { return isolate_; }
|
||||
Handle<SharedFunctionInfo> shared_info() const { return shared_; }
|
||||
Handle<Script> script() const { return script_; }
|
||||
Handle<Context> context() const { return context_; }
|
||||
void clear_script() { script_ = Handle<Script>::null(); }
|
||||
void set_isolate(Isolate* isolate) { isolate_ = isolate; }
|
||||
void set_shared_info(Handle<SharedFunctionInfo> shared) { shared_ = shared; }
|
||||
void set_context(Handle<Context> context) { context_ = context; }
|
||||
void set_script(Handle<Script> script) { script_ = script; }
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
LanguageMode language_mode() const {
|
||||
return construct_language_mode(is_strict_mode());
|
||||
}
|
||||
void set_language_mode(LanguageMode language_mode) {
|
||||
STATIC_ASSERT(LANGUAGE_END == 2);
|
||||
set_strict_mode(is_strict(language_mode));
|
||||
}
|
||||
|
||||
void ReopenHandlesInNewHandleScope() {
|
||||
shared_ = Handle<SharedFunctionInfo>(*shared_);
|
||||
script_ = Handle<Script>(*script_);
|
||||
context_ = Handle<Context>(*context_);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
bool script_is_native() const;
|
||||
#endif // DEBUG
|
||||
|
||||
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,
|
||||
kNative = 1 << 5,
|
||||
kParseRestriction = 1 << 6,
|
||||
kModule = 1 << 7,
|
||||
kAllowLazyParsing = 1 << 8,
|
||||
kIsNamedExpression = 1 << 9,
|
||||
kCallsEval = 1 << 10,
|
||||
// ---------- Output flags --------------------------
|
||||
kAstValueFactoryOwned = 1 << 11
|
||||
};
|
||||
|
||||
//------------- Inputs to parsing and scope analysis -----------------------
|
||||
Zone* zone_;
|
||||
unsigned flags_;
|
||||
ScriptCompiler::ExternalSourceStream* source_stream_;
|
||||
ScriptCompiler::StreamedSource::Encoding source_stream_encoding_;
|
||||
Utf16CharacterStream* character_stream_;
|
||||
v8::Extension* extension_;
|
||||
ScriptCompiler::CompileOptions compile_options_;
|
||||
DeclarationScope* script_scope_;
|
||||
UnicodeCache* unicode_cache_;
|
||||
uintptr_t stack_limit_;
|
||||
uint32_t hash_seed_;
|
||||
int compiler_hints_;
|
||||
int start_position_;
|
||||
int end_position_;
|
||||
|
||||
// TODO(titzer): Move handles and isolate out of ParseInfo.
|
||||
Isolate* isolate_;
|
||||
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.
|
||||
const AstRawString* function_name_;
|
||||
|
||||
//----------- Output of parsing and scope analysis ------------------------
|
||||
FunctionLiteral* literal_;
|
||||
|
||||
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; }
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_PARSING_PARSE_INFO_H_
|
@ -7,19 +7,16 @@
|
||||
#include <memory>
|
||||
|
||||
#include "src/api.h"
|
||||
#include "src/ast/ast.h"
|
||||
#include "src/ast/ast-expression-rewriter.h"
|
||||
#include "src/ast/ast-literal-reindexer.h"
|
||||
#include "src/ast/ast-traversal-visitor.h"
|
||||
#include "src/ast/ast.h"
|
||||
#include "src/bailout-reason.h"
|
||||
#include "src/base/platform/platform.h"
|
||||
#include "src/bootstrapper.h"
|
||||
#include "src/char-predicates-inl.h"
|
||||
#include "src/codegen.h"
|
||||
#include "src/compiler.h"
|
||||
#include "src/messages.h"
|
||||
#include "src/parsing/parameter-initializer-rewriter.h"
|
||||
#include "src/parsing/parser-base.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/rewriter.h"
|
||||
#include "src/parsing/scanner-character-streams.h"
|
||||
#include "src/runtime/runtime.h"
|
||||
@ -40,91 +37,6 @@ ScriptData::ScriptData(const byte* data, int length)
|
||||
}
|
||||
}
|
||||
|
||||
ParseInfo::ParseInfo(Zone* zone)
|
||||
: zone_(zone),
|
||||
flags_(0),
|
||||
source_stream_(nullptr),
|
||||
source_stream_encoding_(ScriptCompiler::StreamedSource::ONE_BYTE),
|
||||
character_stream_(nullptr),
|
||||
extension_(nullptr),
|
||||
compile_options_(ScriptCompiler::kNoCompileOptions),
|
||||
script_scope_(nullptr),
|
||||
unicode_cache_(nullptr),
|
||||
stack_limit_(0),
|
||||
hash_seed_(0),
|
||||
compiler_hints_(0),
|
||||
start_position_(0),
|
||||
end_position_(0),
|
||||
isolate_(nullptr),
|
||||
cached_data_(nullptr),
|
||||
ast_value_factory_(nullptr),
|
||||
function_name_(nullptr),
|
||||
literal_(nullptr) {}
|
||||
|
||||
ParseInfo::ParseInfo(Zone* zone, Handle<JSFunction> function)
|
||||
: ParseInfo(zone, Handle<SharedFunctionInfo>(function->shared())) {
|
||||
set_context(Handle<Context>(function->context()));
|
||||
}
|
||||
|
||||
|
||||
ParseInfo::ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared)
|
||||
: ParseInfo(zone) {
|
||||
isolate_ = shared->GetIsolate();
|
||||
|
||||
set_lazy();
|
||||
set_hash_seed(isolate_->heap()->HashSeed());
|
||||
set_is_named_expression(shared->is_named_expression());
|
||||
set_calls_eval(shared->scope_info()->CallsEval());
|
||||
set_compiler_hints(shared->compiler_hints());
|
||||
set_start_position(shared->start_position());
|
||||
set_end_position(shared->end_position());
|
||||
set_stack_limit(isolate_->stack_guard()->real_climit());
|
||||
set_unicode_cache(isolate_->unicode_cache());
|
||||
set_language_mode(shared->language_mode());
|
||||
set_shared_info(shared);
|
||||
|
||||
Handle<Script> script(Script::cast(shared->script()));
|
||||
set_script(script);
|
||||
if (!script.is_null() && script->type() == Script::TYPE_NATIVE) {
|
||||
set_native();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ParseInfo::ParseInfo(Zone* zone, Handle<Script> script) : ParseInfo(zone) {
|
||||
isolate_ = script->GetIsolate();
|
||||
|
||||
set_hash_seed(isolate_->heap()->HashSeed());
|
||||
set_stack_limit(isolate_->stack_guard()->real_climit());
|
||||
set_unicode_cache(isolate_->unicode_cache());
|
||||
set_script(script);
|
||||
|
||||
if (script->type() == Script::TYPE_NATIVE) {
|
||||
set_native();
|
||||
}
|
||||
}
|
||||
|
||||
bool ParseInfo::is_declaration() const {
|
||||
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsDeclaration)) != 0;
|
||||
}
|
||||
|
||||
bool ParseInfo::is_arrow() const {
|
||||
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsArrow)) != 0;
|
||||
}
|
||||
|
||||
bool ParseInfo::is_async() const {
|
||||
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsAsyncFunction)) != 0;
|
||||
}
|
||||
|
||||
bool ParseInfo::is_default_constructor() const {
|
||||
return (compiler_hints_ & (1 << SharedFunctionInfo::kIsDefaultConstructor)) !=
|
||||
0;
|
||||
}
|
||||
|
||||
FunctionKind ParseInfo::function_kind() const {
|
||||
return SharedFunctionInfo::FunctionKindBits::decode(compiler_hints_);
|
||||
}
|
||||
|
||||
FunctionEntry ParseData::GetFunctionEntry(int start) {
|
||||
// The current pre-data entry must be a FunctionEntry with the given
|
||||
// start position.
|
||||
|
@ -5,10 +5,8 @@
|
||||
#ifndef V8_PARSING_PARSER_H_
|
||||
#define V8_PARSING_PARSER_H_
|
||||
|
||||
#include "src/allocation.h"
|
||||
#include "src/ast/ast.h"
|
||||
#include "src/ast/scopes.h"
|
||||
#include "src/compiler.h" // TODO(titzer): remove this include dependency
|
||||
#include "src/parsing/parser-base.h"
|
||||
#include "src/parsing/preparse-data.h"
|
||||
#include "src/parsing/preparse-data-format.h"
|
||||
@ -21,230 +19,10 @@ class ScriptCompiler;
|
||||
|
||||
namespace internal {
|
||||
|
||||
class ParseInfo;
|
||||
class ScriptData;
|
||||
class Target;
|
||||
|
||||
// A container for the inputs, configuration options, and outputs of parsing.
|
||||
class ParseInfo {
|
||||
public:
|
||||
explicit ParseInfo(Zone* zone);
|
||||
ParseInfo(Zone* zone, Handle<JSFunction> function);
|
||||
ParseInfo(Zone* zone, Handle<Script> script);
|
||||
// TODO(all) Only used via Debug::FindSharedFunctionInfoInScript, remove?
|
||||
ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared);
|
||||
|
||||
~ParseInfo() {
|
||||
if (ast_value_factory_owned()) {
|
||||
delete ast_value_factory_;
|
||||
set_ast_value_factory_owned(false);
|
||||
}
|
||||
ast_value_factory_ = nullptr;
|
||||
}
|
||||
|
||||
Zone* zone() const { 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(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)
|
||||
FLAG_ACCESSOR(kIsNamedExpression, is_named_expression,
|
||||
set_is_named_expression)
|
||||
FLAG_ACCESSOR(kCallsEval, calls_eval, set_calls_eval)
|
||||
|
||||
#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() const {
|
||||
return source_stream_;
|
||||
}
|
||||
void set_source_stream(ScriptCompiler::ExternalSourceStream* source_stream) {
|
||||
source_stream_ = source_stream;
|
||||
}
|
||||
|
||||
ScriptCompiler::StreamedSource::Encoding source_stream_encoding() const {
|
||||
return source_stream_encoding_;
|
||||
}
|
||||
void set_source_stream_encoding(
|
||||
ScriptCompiler::StreamedSource::Encoding source_stream_encoding) {
|
||||
source_stream_encoding_ = source_stream_encoding;
|
||||
}
|
||||
|
||||
Utf16CharacterStream* character_stream() const { return character_stream_; }
|
||||
void set_character_stream(Utf16CharacterStream* character_stream) {
|
||||
character_stream_ = character_stream;
|
||||
}
|
||||
|
||||
v8::Extension* extension() const { return extension_; }
|
||||
void set_extension(v8::Extension* extension) { extension_ = extension; }
|
||||
|
||||
ScriptData** cached_data() const { return cached_data_; }
|
||||
void set_cached_data(ScriptData** cached_data) { cached_data_ = cached_data; }
|
||||
|
||||
ScriptCompiler::CompileOptions compile_options() const {
|
||||
return compile_options_;
|
||||
}
|
||||
void set_compile_options(ScriptCompiler::CompileOptions compile_options) {
|
||||
compile_options_ = compile_options;
|
||||
}
|
||||
|
||||
DeclarationScope* script_scope() const { return script_scope_; }
|
||||
void set_script_scope(DeclarationScope* script_scope) {
|
||||
script_scope_ = script_scope;
|
||||
}
|
||||
|
||||
AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
|
||||
void set_ast_value_factory(AstValueFactory* ast_value_factory) {
|
||||
ast_value_factory_ = ast_value_factory;
|
||||
}
|
||||
|
||||
const AstRawString* function_name() const { return function_name_; }
|
||||
void set_function_name(const AstRawString* function_name) {
|
||||
function_name_ = function_name;
|
||||
}
|
||||
|
||||
FunctionLiteral* literal() const { return literal_; }
|
||||
void set_literal(FunctionLiteral* literal) { literal_ = literal; }
|
||||
|
||||
DeclarationScope* scope() const { return literal()->scope(); }
|
||||
|
||||
UnicodeCache* unicode_cache() const { return unicode_cache_; }
|
||||
void set_unicode_cache(UnicodeCache* unicode_cache) {
|
||||
unicode_cache_ = unicode_cache;
|
||||
}
|
||||
|
||||
uintptr_t stack_limit() const { return stack_limit_; }
|
||||
void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; }
|
||||
|
||||
uint32_t hash_seed() const { return hash_seed_; }
|
||||
void set_hash_seed(uint32_t hash_seed) { hash_seed_ = hash_seed; }
|
||||
|
||||
int compiler_hints() const { return compiler_hints_; }
|
||||
void set_compiler_hints(int compiler_hints) {
|
||||
compiler_hints_ = compiler_hints;
|
||||
}
|
||||
|
||||
int start_position() const { return start_position_; }
|
||||
void set_start_position(int start_position) {
|
||||
start_position_ = start_position;
|
||||
}
|
||||
|
||||
int end_position() const { return end_position_; }
|
||||
void set_end_position(int end_position) { end_position_ = end_position; }
|
||||
|
||||
// Getters for individual compiler hints.
|
||||
bool is_declaration() const;
|
||||
bool is_arrow() const;
|
||||
bool is_async() const;
|
||||
bool is_default_constructor() const;
|
||||
FunctionKind function_kind() const;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// TODO(titzer): these should not be part of ParseInfo.
|
||||
//--------------------------------------------------------------------------
|
||||
Isolate* isolate() const { return isolate_; }
|
||||
Handle<SharedFunctionInfo> shared_info() const { return shared_; }
|
||||
Handle<Script> script() const { return script_; }
|
||||
Handle<Context> context() const { return context_; }
|
||||
void clear_script() { script_ = Handle<Script>::null(); }
|
||||
void set_isolate(Isolate* isolate) { isolate_ = isolate; }
|
||||
void set_shared_info(Handle<SharedFunctionInfo> shared) { shared_ = shared; }
|
||||
void set_context(Handle<Context> context) { context_ = context; }
|
||||
void set_script(Handle<Script> script) { script_ = script; }
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
LanguageMode language_mode() const {
|
||||
return construct_language_mode(is_strict_mode());
|
||||
}
|
||||
void set_language_mode(LanguageMode language_mode) {
|
||||
STATIC_ASSERT(LANGUAGE_END == 2);
|
||||
set_strict_mode(is_strict(language_mode));
|
||||
}
|
||||
|
||||
void ReopenHandlesInNewHandleScope() {
|
||||
shared_ = Handle<SharedFunctionInfo>(*shared_);
|
||||
script_ = Handle<Script>(*script_);
|
||||
context_ = Handle<Context>(*context_);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
bool script_is_native() const {
|
||||
return script_->type() == Script::TYPE_NATIVE;
|
||||
}
|
||||
#endif // DEBUG
|
||||
|
||||
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,
|
||||
kNative = 1 << 5,
|
||||
kParseRestriction = 1 << 6,
|
||||
kModule = 1 << 7,
|
||||
kAllowLazyParsing = 1 << 8,
|
||||
kIsNamedExpression = 1 << 9,
|
||||
kCallsEval = 1 << 10,
|
||||
// ---------- Output flags --------------------------
|
||||
kAstValueFactoryOwned = 1 << 11
|
||||
};
|
||||
|
||||
//------------- Inputs to parsing and scope analysis -----------------------
|
||||
Zone* zone_;
|
||||
unsigned flags_;
|
||||
ScriptCompiler::ExternalSourceStream* source_stream_;
|
||||
ScriptCompiler::StreamedSource::Encoding source_stream_encoding_;
|
||||
Utf16CharacterStream* character_stream_;
|
||||
v8::Extension* extension_;
|
||||
ScriptCompiler::CompileOptions compile_options_;
|
||||
DeclarationScope* script_scope_;
|
||||
UnicodeCache* unicode_cache_;
|
||||
uintptr_t stack_limit_;
|
||||
uint32_t hash_seed_;
|
||||
int compiler_hints_;
|
||||
int start_position_;
|
||||
int end_position_;
|
||||
|
||||
// TODO(titzer): Move handles and isolate out of ParseInfo.
|
||||
Isolate* isolate_;
|
||||
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.
|
||||
const AstRawString* function_name_;
|
||||
|
||||
//----------- Output of parsing and scope analysis ------------------------
|
||||
FunctionLiteral* literal_;
|
||||
|
||||
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; }
|
||||
};
|
||||
|
||||
class FunctionEntry BASE_EMBEDDED {
|
||||
public:
|
||||
enum {
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "src/ast/ast.h"
|
||||
#include "src/ast/scopes.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/parser.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "src/frames-inl.h"
|
||||
#include "src/isolate-inl.h"
|
||||
#include "src/messages.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/wasm/wasm-module.h"
|
||||
|
||||
|
@ -1054,6 +1054,8 @@
|
||||
'parsing/func-name-inferrer.h',
|
||||
'parsing/parameter-initializer-rewriter.cc',
|
||||
'parsing/parameter-initializer-rewriter.h',
|
||||
'parsing/parse-info.cc',
|
||||
'parsing/parse-info.h',
|
||||
'parsing/parser-base.h',
|
||||
'parsing/parser.cc',
|
||||
'parsing/parser.h',
|
||||
|
@ -10,12 +10,13 @@
|
||||
#include "src/assert-scope.h"
|
||||
#include "src/ast/ast.h"
|
||||
#include "src/ast/scopes.h"
|
||||
#include "src/compiler.h"
|
||||
#include "src/execution.h"
|
||||
#include "src/factory.h"
|
||||
#include "src/handles.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/objects.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
|
||||
#include "src/wasm/encoder.h"
|
||||
#include "src/wasm/module-decoder.h"
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include "src/ast/ast.h"
|
||||
#include "src/ast/scopes.h"
|
||||
#include "src/base/platform/platform.h"
|
||||
#include "src/compiler.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/v8.h"
|
||||
#include "test/cctest/cctest.h"
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "src/full-codegen/full-codegen.h"
|
||||
#include "src/handles.h"
|
||||
#include "src/objects-inl.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/rewriter.h"
|
||||
#include "test/cctest/cctest.h"
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "src/code-stubs.h"
|
||||
#include "src/compiler.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/zone.h"
|
||||
|
||||
#include "src/code-factory.h"
|
||||
|
@ -3,7 +3,9 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "src/ast/scopes.h"
|
||||
#include "src/compiler.h"
|
||||
#include "src/compiler/ast-loop-assignment-analyzer.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/rewriter.h"
|
||||
#include "test/cctest/cctest.h"
|
||||
|
@ -4,12 +4,13 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/compiler.h"
|
||||
#include "src/compiler/pipeline.h"
|
||||
#include "src/execution.h"
|
||||
#include "src/handles.h"
|
||||
#include "src/interpreter/bytecode-array-builder.h"
|
||||
#include "src/interpreter/interpreter.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "test/cctest/cctest.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -33,13 +33,14 @@
|
||||
|
||||
#include "src/v8.h"
|
||||
|
||||
#include "src/ast/ast.h"
|
||||
#include "src/ast/ast-numbering.h"
|
||||
#include "src/ast/ast-value-factory.h"
|
||||
#include "src/ast/ast.h"
|
||||
#include "src/compiler.h"
|
||||
#include "src/execution.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/objects.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/preparser.h"
|
||||
#include "src/parsing/rewriter.h"
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "include/v8.h"
|
||||
#include "src/objects.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/preparser.h"
|
||||
#include "test/fuzzer/fuzzer-support.h"
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "src/compiler-dispatcher/compiler-dispatcher-job.h"
|
||||
#include "src/flags.h"
|
||||
#include "src/isolate-inl.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "test/unittests/test-utils.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
|
@ -36,11 +36,12 @@
|
||||
#include "include/libplatform/libplatform.h"
|
||||
#include "src/api.h"
|
||||
#include "src/compiler.h"
|
||||
#include "src/parsing/scanner-character-streams.h"
|
||||
#include "src/parsing/parse-info.h"
|
||||
#include "src/parsing/parser.h"
|
||||
#include "src/parsing/preparse-data-format.h"
|
||||
#include "src/parsing/preparse-data.h"
|
||||
#include "src/parsing/preparser.h"
|
||||
#include "src/parsing/scanner-character-streams.h"
|
||||
#include "tools/shell-utils.h"
|
||||
|
||||
using namespace v8::internal;
|
||||
|
Loading…
Reference in New Issue
Block a user