5 #ifndef V8_PARSING_PARSE_INFO_H_ 6 #define V8_PARSING_PARSE_INFO_H_ 12 #include "include/v8.h" 13 #include "src/globals.h" 14 #include "src/handles.h" 15 #include "src/objects/script.h" 16 #include "src/parsing/preparsed-scope-data.h" 17 #include "src/pending-compilation-error-handler.h" 25 class AccountingAllocator;
27 class AstStringConstants;
28 class AstValueFactory;
29 class CompilerDispatcher;
30 class DeclarationScope;
31 class FunctionLiteral;
32 class RuntimeCallStats;
35 class Utf16CharacterStream;
49 static std::unique_ptr<ParseInfo> FromParent(
57 NativesFlag natives = NOT_NATIVES_CODE);
63 Zone* zone()
const {
return zone_.get(); }
66 #define FLAG_ACCESSOR(flag, getter, setter) \ 67 bool getter() const { return GetFlag(flag); } \ 68 void setter() { SetFlag(flag); } \ 69 void setter(bool val) { SetFlag(flag, val); } 71 FLAG_ACCESSOR(kToplevel, is_toplevel, set_toplevel)
72 FLAG_ACCESSOR(kEager, is_eager, set_eager)
73 FLAG_ACCESSOR(kEval, is_eval, set_eval)
74 FLAG_ACCESSOR(kStrictMode, is_strict_mode, set_strict_mode)
75 FLAG_ACCESSOR(kNative, is_native, set_native)
76 FLAG_ACCESSOR(kModule, is_module, set_module)
77 FLAG_ACCESSOR(kAllowLazyParsing, allow_lazy_parsing, set_allow_lazy_parsing)
78 FLAG_ACCESSOR(kIsNamedExpression, is_named_expression,
79 set_is_named_expression)
80 FLAG_ACCESSOR(kLazyCompile, lazy_compile, set_lazy_compile)
81 FLAG_ACCESSOR(kCollectTypeProfile, collect_type_profile,
82 set_collect_type_profile)
83 FLAG_ACCESSOR(kIsAsmWasmBroken, is_asm_wasm_broken, set_asm_wasm_broken)
84 FLAG_ACCESSOR(kBlockCoverageEnabled, block_coverage_enabled,
85 set_block_coverage_enabled)
86 FLAG_ACCESSOR(kOnBackgroundThread, on_background_thread,
87 set_on_background_thread)
88 FLAG_ACCESSOR(kWrappedAsFunction, is_wrapped_as_function,
89 set_wrapped_as_function)
90 FLAG_ACCESSOR(kAllowEvalCache, allow_eval_cache, set_allow_eval_cache)
91 FLAG_ACCESSOR(kIsDeclaration, is_declaration, set_declaration)
92 FLAG_ACCESSOR(kRequiresInstanceMembersInitializer,
93 requires_instance_members_initializer,
94 set_requires_instance_members_initializer);
97 void set_parse_restriction(ParseRestriction restriction) {
98 SetFlag(kParseRestriction, restriction != NO_PARSE_RESTRICTION);
101 ParseRestriction parse_restriction()
const {
102 return GetFlag(kParseRestriction) ? ONLY_SINGLE_FUNCTION_LITERAL
103 : NO_PARSE_RESTRICTION;
107 return character_stream_.get();
109 void set_character_stream(
110 std::unique_ptr<Utf16CharacterStream> character_stream);
111 void ResetCharacterStream();
113 v8::Extension* extension()
const {
return extension_; }
114 void set_extension(v8::Extension* extension) { extension_ = extension; }
116 void set_consumed_preparsed_scope_data(
117 std::unique_ptr<ConsumedPreParsedScopeData> data) {
118 consumed_preparsed_scope_data_.swap(data);
121 return consumed_preparsed_scope_data_.get();
126 script_scope_ = script_scope;
130 DCHECK(ast_value_factory_.get());
131 return ast_value_factory_.get();
134 const AstRawString* function_name()
const {
return function_name_; }
135 void set_function_name(
const AstRawString* function_name) {
136 function_name_ = function_name;
144 uintptr_t stack_limit()
const {
return stack_limit_; }
145 void set_stack_limit(
uintptr_t stack_limit) { stack_limit_ = stack_limit; }
147 uint64_t hash_seed()
const {
return hash_seed_; }
148 void set_hash_seed(uint64_t hash_seed) { hash_seed_ = hash_seed; }
150 int start_position()
const {
return start_position_; }
151 void set_start_position(
int start_position) {
152 start_position_ = start_position;
155 int end_position()
const {
return end_position_; }
156 void set_end_position(
int end_position) { end_position_ = end_position; }
158 int parameters_end_pos()
const {
return parameters_end_pos_; }
159 void set_parameters_end_pos(
int parameters_end_pos) {
160 parameters_end_pos_ = parameters_end_pos;
163 int function_literal_id()
const {
return function_literal_id_; }
164 void set_function_literal_id(
int function_literal_id) {
165 function_literal_id_ = function_literal_id;
168 FunctionKind function_kind()
const {
return function_kind_; }
169 void set_function_kind(FunctionKind function_kind) {
170 function_kind_ = function_kind;
173 int max_function_literal_id()
const {
return max_function_literal_id_; }
174 void set_max_function_literal_id(
int max_function_literal_id) {
175 max_function_literal_id_ = max_function_literal_id;
179 return ast_string_constants_;
181 void set_ast_string_constants(
183 ast_string_constants_ = ast_string_constants;
186 RuntimeCallStats* runtime_call_stats()
const {
return runtime_call_stats_; }
188 runtime_call_stats_ = runtime_call_stats;
190 Logger* logger()
const {
return logger_; }
191 void set_logger(
Logger* logger) { logger_ = logger; }
193 void AllocateSourceRangeMap();
194 SourceRangeMap* source_range_map()
const {
return source_range_map_; }
196 source_range_map_ = source_range_map;
200 return &pending_error_handler_;
206 : dispatcher_(compiler_dispatcher) {
213 typedef std::forward_list<std::pair<FunctionLiteral*, uintptr_t>>::iterator
214 EnqueuedJobsIterator;
216 EnqueuedJobsIterator begin() {
return enqueued_jobs_.begin(); }
217 EnqueuedJobsIterator end() {
return enqueued_jobs_.end(); }
223 std::forward_list<std::pair<FunctionLiteral*, uintptr_t>> enqueued_jobs_;
226 ParallelTasks* parallel_tasks() {
return parallel_tasks_.get(); }
234 MaybeHandle<ScopeInfo> maybe_outer_scope_info()
const {
235 return maybe_outer_scope_info_;
237 void set_outer_scope_info(Handle<ScopeInfo> outer_scope_info) {
238 maybe_outer_scope_info_ = outer_scope_info;
241 int script_id()
const {
return script_id_; }
244 LanguageMode language_mode()
const {
245 return construct_language_mode(is_strict_mode());
247 void set_language_mode(LanguageMode language_mode) {
248 STATIC_ASSERT(LanguageModeSize == 2);
249 set_strict_mode(is_strict(language_mode));
253 void SetScriptForToplevelCompile(Isolate* isolate, Handle<Script> script);
257 template <
typename T>
258 void SetFunctionInfo(T
function);
266 kStrictMode = 1 << 3,
268 kParseRestriction = 1 << 5,
270 kAllowLazyParsing = 1 << 7,
271 kIsNamedExpression = 1 << 8,
272 kLazyCompile = 1 << 9,
273 kCollectTypeProfile = 1 << 10,
274 kBlockCoverageEnabled = 1 << 11,
275 kIsAsmWasmBroken = 1 << 12,
276 kOnBackgroundThread = 1 << 13,
277 kWrappedAsFunction = 1 << 14,
278 kAllowEvalCache = 1 << 15,
279 kIsDeclaration = 1 << 16,
280 kRequiresInstanceMembersInitializer = 1 << 17,
284 std::unique_ptr<Zone> zone_;
286 v8::Extension* extension_;
287 DeclarationScope* script_scope_;
290 FunctionKind function_kind_;
294 int parameters_end_pos_;
295 int function_literal_id_;
296 int max_function_literal_id_;
299 Handle<Script> script_;
300 MaybeHandle<ScopeInfo> maybe_outer_scope_info_;
303 std::unique_ptr<Utf16CharacterStream> character_stream_;
304 std::unique_ptr<ConsumedPreParsedScopeData> consumed_preparsed_scope_data_;
305 std::unique_ptr<AstValueFactory> ast_value_factory_;
306 const class AstStringConstants* ast_string_constants_;
307 const AstRawString* function_name_;
308 RuntimeCallStats* runtime_call_stats_;
310 SourceRangeMap* source_range_map_;
311 std::unique_ptr<ParallelTasks> parallel_tasks_;
314 FunctionLiteral* literal_;
315 PendingCompilationErrorHandler pending_error_handler_;
317 void SetFlag(Flag f) { flags_ |= f; }
318 void SetFlag(Flag f,
bool v) { flags_ = v ? flags_ | f : flags_ & ~f; }
319 bool GetFlag(Flag f)
const {
return (flags_ & f) != 0; }
325 #endif // V8_PARSING_PARSE_INFO_H_