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

Side by Side Diff: src/parsing/parse-info.h

Issue 2268513002: Cleanup: Move ParseInfo to a separate file. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_PARSING_PARSE_INFO_H_
6 #define V8_PARSING_PARSE_INFO_H_
7
8 #include "include/v8.h"
9 #include "src/globals.h"
10 #include "src/handles.h"
11
12 namespace v8 {
13
14 class Extension;
15
16 namespace internal {
17
18 class AstRawString;
19 class AstValueFactory;
20 class DeclarationScope;
21 class FunctionLiteral;
22 class ScriptData;
23 class SharedFunctionInfo;
24 class UnicodeCache;
25 class Utf16CharacterStream;
26 class Zone;
27
28 // A container for the inputs, configuration options, and outputs of parsing.
29 class ParseInfo {
30 public:
31 explicit ParseInfo(Zone* zone);
32 ParseInfo(Zone* zone, Handle<JSFunction> function);
33 ParseInfo(Zone* zone, Handle<Script> script);
34 // TODO(all) Only used via Debug::FindSharedFunctionInfoInScript, remove?
35 ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared);
36
37 ~ParseInfo();
38
39 Zone* zone() const { return zone_; }
40
41 // Convenience accessor methods for flags.
42 #define FLAG_ACCESSOR(flag, getter, setter) \
43 bool getter() const { return GetFlag(flag); } \
44 void setter() { SetFlag(flag); } \
45 void setter(bool val) { SetFlag(flag, val); }
46
47 FLAG_ACCESSOR(kToplevel, is_toplevel, set_toplevel)
48 FLAG_ACCESSOR(kLazy, is_lazy, set_lazy)
49 FLAG_ACCESSOR(kEval, is_eval, set_eval)
50 FLAG_ACCESSOR(kGlobal, is_global, set_global)
51 FLAG_ACCESSOR(kStrictMode, is_strict_mode, set_strict_mode)
52 FLAG_ACCESSOR(kNative, is_native, set_native)
53 FLAG_ACCESSOR(kModule, is_module, set_module)
54 FLAG_ACCESSOR(kAllowLazyParsing, allow_lazy_parsing, set_allow_lazy_parsing)
55 FLAG_ACCESSOR(kAstValueFactoryOwned, ast_value_factory_owned,
56 set_ast_value_factory_owned)
57 FLAG_ACCESSOR(kIsNamedExpression, is_named_expression,
58 set_is_named_expression)
59 FLAG_ACCESSOR(kCallsEval, calls_eval, set_calls_eval)
60
61 #undef FLAG_ACCESSOR
62
63 void set_parse_restriction(ParseRestriction restriction) {
64 SetFlag(kParseRestriction, restriction != NO_PARSE_RESTRICTION);
65 }
66
67 ParseRestriction parse_restriction() const {
68 return GetFlag(kParseRestriction) ? ONLY_SINGLE_FUNCTION_LITERAL
69 : NO_PARSE_RESTRICTION;
70 }
71
72 ScriptCompiler::ExternalSourceStream* source_stream() const {
73 return source_stream_;
74 }
75 void set_source_stream(ScriptCompiler::ExternalSourceStream* source_stream) {
76 source_stream_ = source_stream;
77 }
78
79 ScriptCompiler::StreamedSource::Encoding source_stream_encoding() const {
80 return source_stream_encoding_;
81 }
82 void set_source_stream_encoding(
83 ScriptCompiler::StreamedSource::Encoding source_stream_encoding) {
84 source_stream_encoding_ = source_stream_encoding;
85 }
86
87 Utf16CharacterStream* character_stream() const { return character_stream_; }
88 void set_character_stream(Utf16CharacterStream* character_stream) {
89 character_stream_ = character_stream;
90 }
91
92 v8::Extension* extension() const { return extension_; }
93 void set_extension(v8::Extension* extension) { extension_ = extension; }
94
95 ScriptData** cached_data() const { return cached_data_; }
96 void set_cached_data(ScriptData** cached_data) { cached_data_ = cached_data; }
97
98 ScriptCompiler::CompileOptions compile_options() const {
99 return compile_options_;
100 }
101 void set_compile_options(ScriptCompiler::CompileOptions compile_options) {
102 compile_options_ = compile_options;
103 }
104
105 DeclarationScope* script_scope() const { return script_scope_; }
106 void set_script_scope(DeclarationScope* script_scope) {
107 script_scope_ = script_scope;
108 }
109
110 AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
111 void set_ast_value_factory(AstValueFactory* ast_value_factory) {
112 ast_value_factory_ = ast_value_factory;
113 }
114
115 const AstRawString* function_name() const { return function_name_; }
116 void set_function_name(const AstRawString* function_name) {
117 function_name_ = function_name;
118 }
119
120 FunctionLiteral* literal() const { return literal_; }
121 void set_literal(FunctionLiteral* literal) { literal_ = literal; }
122
123 DeclarationScope* scope() const;
124
125 UnicodeCache* unicode_cache() const { return unicode_cache_; }
126 void set_unicode_cache(UnicodeCache* unicode_cache) {
127 unicode_cache_ = unicode_cache;
128 }
129
130 uintptr_t stack_limit() const { return stack_limit_; }
131 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; }
132
133 uint32_t hash_seed() const { return hash_seed_; }
134 void set_hash_seed(uint32_t hash_seed) { hash_seed_ = hash_seed; }
135
136 int compiler_hints() const { return compiler_hints_; }
137 void set_compiler_hints(int compiler_hints) {
138 compiler_hints_ = compiler_hints;
139 }
140
141 int start_position() const { return start_position_; }
142 void set_start_position(int start_position) {
143 start_position_ = start_position;
144 }
145
146 int end_position() const { return end_position_; }
147 void set_end_position(int end_position) { end_position_ = end_position; }
148
149 // Getters for individual compiler hints.
150 bool is_declaration() const;
151 bool is_arrow() const;
152 bool is_async() const;
153 bool is_default_constructor() const;
154 FunctionKind function_kind() const;
155
156 //--------------------------------------------------------------------------
157 // TODO(titzer): these should not be part of ParseInfo.
158 //--------------------------------------------------------------------------
159 Isolate* isolate() const { return isolate_; }
160 Handle<SharedFunctionInfo> shared_info() const { return shared_; }
161 Handle<Script> script() const { return script_; }
162 Handle<Context> context() const { return context_; }
163 void clear_script() { script_ = Handle<Script>::null(); }
164 void set_isolate(Isolate* isolate) { isolate_ = isolate; }
165 void set_shared_info(Handle<SharedFunctionInfo> shared) { shared_ = shared; }
166 void set_context(Handle<Context> context) { context_ = context; }
167 void set_script(Handle<Script> script) { script_ = script; }
168 //--------------------------------------------------------------------------
169
170 LanguageMode language_mode() const {
171 return construct_language_mode(is_strict_mode());
172 }
173 void set_language_mode(LanguageMode language_mode) {
174 STATIC_ASSERT(LANGUAGE_END == 2);
175 set_strict_mode(is_strict(language_mode));
176 }
177
178 void ReopenHandlesInNewHandleScope() {
179 shared_ = Handle<SharedFunctionInfo>(*shared_);
180 script_ = Handle<Script>(*script_);
181 context_ = Handle<Context>(*context_);
182 }
183
184 #ifdef DEBUG
185 bool script_is_native() const;
186 #endif // DEBUG
187
188 private:
189 // Various configuration flags for parsing.
190 enum Flag {
191 // ---------- Input flags ---------------------------
192 kToplevel = 1 << 0,
193 kLazy = 1 << 1,
194 kEval = 1 << 2,
195 kGlobal = 1 << 3,
196 kStrictMode = 1 << 4,
197 kNative = 1 << 5,
198 kParseRestriction = 1 << 6,
199 kModule = 1 << 7,
200 kAllowLazyParsing = 1 << 8,
201 kIsNamedExpression = 1 << 9,
202 kCallsEval = 1 << 10,
203 // ---------- Output flags --------------------------
204 kAstValueFactoryOwned = 1 << 11
205 };
206
207 //------------- Inputs to parsing and scope analysis -----------------------
208 Zone* zone_;
209 unsigned flags_;
210 ScriptCompiler::ExternalSourceStream* source_stream_;
211 ScriptCompiler::StreamedSource::Encoding source_stream_encoding_;
212 Utf16CharacterStream* character_stream_;
213 v8::Extension* extension_;
214 ScriptCompiler::CompileOptions compile_options_;
215 DeclarationScope* script_scope_;
216 UnicodeCache* unicode_cache_;
217 uintptr_t stack_limit_;
218 uint32_t hash_seed_;
219 int compiler_hints_;
220 int start_position_;
221 int end_position_;
222
223 // TODO(titzer): Move handles and isolate out of ParseInfo.
224 Isolate* isolate_;
225 Handle<SharedFunctionInfo> shared_;
226 Handle<Script> script_;
227 Handle<Context> context_;
228
229 //----------- Inputs+Outputs of parsing and scope analysis -----------------
230 ScriptData** cached_data_; // used if available, populated if requested.
231 AstValueFactory* ast_value_factory_; // used if available, otherwise new.
232 const AstRawString* function_name_;
233
234 //----------- Output of parsing and scope analysis ------------------------
235 FunctionLiteral* literal_;
236
237 void SetFlag(Flag f) { flags_ |= f; }
238 void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; }
239 bool GetFlag(Flag f) const { return (flags_ & f) != 0; }
240 };
241
242 } // namespace internal
243 } // namespace v8
244
245 #endif // V8_PARSING_PARSE_INFO_H_
OLDNEW
« no previous file with comments | « src/debug/debug-scopes.cc ('k') | src/parsing/parse-info.cc » ('j') | src/parsing/parse-info.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698