OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_PARSING_PARSER_H_ | 5 #ifndef V8_PARSING_PARSER_H_ |
6 #define V8_PARSING_PARSER_H_ | 6 #define V8_PARSING_PARSER_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared); | 33 ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared); |
34 | 34 |
35 ~ParseInfo() { | 35 ~ParseInfo() { |
36 if (ast_value_factory_owned()) { | 36 if (ast_value_factory_owned()) { |
37 delete ast_value_factory_; | 37 delete ast_value_factory_; |
38 set_ast_value_factory_owned(false); | 38 set_ast_value_factory_owned(false); |
39 } | 39 } |
40 ast_value_factory_ = nullptr; | 40 ast_value_factory_ = nullptr; |
41 } | 41 } |
42 | 42 |
43 Zone* zone() { return zone_; } | 43 Zone* zone() const { return zone_; } |
44 | 44 |
45 // Convenience accessor methods for flags. | 45 // Convenience accessor methods for flags. |
46 #define FLAG_ACCESSOR(flag, getter, setter) \ | 46 #define FLAG_ACCESSOR(flag, getter, setter) \ |
47 bool getter() const { return GetFlag(flag); } \ | 47 bool getter() const { return GetFlag(flag); } \ |
48 void setter() { SetFlag(flag); } \ | 48 void setter() { SetFlag(flag); } \ |
49 void setter(bool val) { SetFlag(flag, val); } | 49 void setter(bool val) { SetFlag(flag, val); } |
50 | 50 |
51 FLAG_ACCESSOR(kToplevel, is_toplevel, set_toplevel) | 51 FLAG_ACCESSOR(kToplevel, is_toplevel, set_toplevel) |
52 FLAG_ACCESSOR(kLazy, is_lazy, set_lazy) | 52 FLAG_ACCESSOR(kLazy, is_lazy, set_lazy) |
53 FLAG_ACCESSOR(kEval, is_eval, set_eval) | 53 FLAG_ACCESSOR(kEval, is_eval, set_eval) |
(...skipping 12 matching lines...) Expand all Loading... |
66 | 66 |
67 void set_parse_restriction(ParseRestriction restriction) { | 67 void set_parse_restriction(ParseRestriction restriction) { |
68 SetFlag(kParseRestriction, restriction != NO_PARSE_RESTRICTION); | 68 SetFlag(kParseRestriction, restriction != NO_PARSE_RESTRICTION); |
69 } | 69 } |
70 | 70 |
71 ParseRestriction parse_restriction() const { | 71 ParseRestriction parse_restriction() const { |
72 return GetFlag(kParseRestriction) ? ONLY_SINGLE_FUNCTION_LITERAL | 72 return GetFlag(kParseRestriction) ? ONLY_SINGLE_FUNCTION_LITERAL |
73 : NO_PARSE_RESTRICTION; | 73 : NO_PARSE_RESTRICTION; |
74 } | 74 } |
75 | 75 |
76 ScriptCompiler::ExternalSourceStream* source_stream() { | 76 ScriptCompiler::ExternalSourceStream* source_stream() const { |
77 return source_stream_; | 77 return source_stream_; |
78 } | 78 } |
79 void set_source_stream(ScriptCompiler::ExternalSourceStream* source_stream) { | 79 void set_source_stream(ScriptCompiler::ExternalSourceStream* source_stream) { |
80 source_stream_ = source_stream; | 80 source_stream_ = source_stream; |
81 } | 81 } |
82 | 82 |
83 ScriptCompiler::StreamedSource::Encoding source_stream_encoding() { | 83 ScriptCompiler::StreamedSource::Encoding source_stream_encoding() const { |
84 return source_stream_encoding_; | 84 return source_stream_encoding_; |
85 } | 85 } |
86 void set_source_stream_encoding( | 86 void set_source_stream_encoding( |
87 ScriptCompiler::StreamedSource::Encoding source_stream_encoding) { | 87 ScriptCompiler::StreamedSource::Encoding source_stream_encoding) { |
88 source_stream_encoding_ = source_stream_encoding; | 88 source_stream_encoding_ = source_stream_encoding; |
89 } | 89 } |
90 | 90 |
91 Utf16CharacterStream* character_stream() const { return character_stream_; } | 91 Utf16CharacterStream* character_stream() const { return character_stream_; } |
92 void set_character_stream(Utf16CharacterStream* character_stream) { | 92 void set_character_stream(Utf16CharacterStream* character_stream) { |
93 character_stream_ = character_stream; | 93 character_stream_ = character_stream; |
94 } | 94 } |
95 | 95 |
96 v8::Extension* extension() { return extension_; } | 96 v8::Extension* extension() const { return extension_; } |
97 void set_extension(v8::Extension* extension) { extension_ = extension; } | 97 void set_extension(v8::Extension* extension) { extension_ = extension; } |
98 | 98 |
99 ScriptData** cached_data() { return cached_data_; } | 99 ScriptData** cached_data() const { return cached_data_; } |
100 void set_cached_data(ScriptData** cached_data) { cached_data_ = cached_data; } | 100 void set_cached_data(ScriptData** cached_data) { cached_data_ = cached_data; } |
101 | 101 |
102 ScriptCompiler::CompileOptions compile_options() { return compile_options_; } | 102 ScriptCompiler::CompileOptions compile_options() const { |
| 103 return compile_options_; |
| 104 } |
103 void set_compile_options(ScriptCompiler::CompileOptions compile_options) { | 105 void set_compile_options(ScriptCompiler::CompileOptions compile_options) { |
104 compile_options_ = compile_options; | 106 compile_options_ = compile_options; |
105 } | 107 } |
106 | 108 |
107 DeclarationScope* script_scope() { return script_scope_; } | 109 DeclarationScope* script_scope() const { return script_scope_; } |
108 void set_script_scope(DeclarationScope* script_scope) { | 110 void set_script_scope(DeclarationScope* script_scope) { |
109 script_scope_ = script_scope; | 111 script_scope_ = script_scope; |
110 } | 112 } |
111 | 113 |
112 AstValueFactory* ast_value_factory() { return ast_value_factory_; } | 114 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } |
113 void set_ast_value_factory(AstValueFactory* ast_value_factory) { | 115 void set_ast_value_factory(AstValueFactory* ast_value_factory) { |
114 ast_value_factory_ = ast_value_factory; | 116 ast_value_factory_ = ast_value_factory; |
115 } | 117 } |
116 | 118 |
117 const AstRawString* function_name() const { return function_name_; } | 119 const AstRawString* function_name() const { return function_name_; } |
118 void set_function_name(const AstRawString* function_name) { | 120 void set_function_name(const AstRawString* function_name) { |
119 function_name_ = function_name; | 121 function_name_ = function_name; |
120 } | 122 } |
121 | 123 |
122 FunctionLiteral* literal() { return literal_; } | 124 FunctionLiteral* literal() const { return literal_; } |
123 void set_literal(FunctionLiteral* literal) { literal_ = literal; } | 125 void set_literal(FunctionLiteral* literal) { literal_ = literal; } |
124 | 126 |
125 DeclarationScope* scope() { return scope_; } | 127 DeclarationScope* scope() const { return literal()->scope(); } |
126 void set_scope(DeclarationScope* scope) { scope_ = scope; } | |
127 | 128 |
128 UnicodeCache* unicode_cache() { return unicode_cache_; } | 129 UnicodeCache* unicode_cache() const { return unicode_cache_; } |
129 void set_unicode_cache(UnicodeCache* unicode_cache) { | 130 void set_unicode_cache(UnicodeCache* unicode_cache) { |
130 unicode_cache_ = unicode_cache; | 131 unicode_cache_ = unicode_cache; |
131 } | 132 } |
132 | 133 |
133 uintptr_t stack_limit() { return stack_limit_; } | 134 uintptr_t stack_limit() const { return stack_limit_; } |
134 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 135 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
135 | 136 |
136 uint32_t hash_seed() { return hash_seed_; } | 137 uint32_t hash_seed() const { return hash_seed_; } |
137 void set_hash_seed(uint32_t hash_seed) { hash_seed_ = hash_seed; } | 138 void set_hash_seed(uint32_t hash_seed) { hash_seed_ = hash_seed; } |
138 | 139 |
139 int compiler_hints() const { return compiler_hints_; } | 140 int compiler_hints() const { return compiler_hints_; } |
140 void set_compiler_hints(int compiler_hints) { | 141 void set_compiler_hints(int compiler_hints) { |
141 compiler_hints_ = compiler_hints; | 142 compiler_hints_ = compiler_hints; |
142 } | 143 } |
143 | 144 |
144 int start_position() const { return start_position_; } | 145 int start_position() const { return start_position_; } |
145 void set_start_position(int start_position) { | 146 void set_start_position(int start_position) { |
146 start_position_ = start_position; | 147 start_position_ = start_position; |
147 } | 148 } |
148 | 149 |
149 int end_position() const { return end_position_; } | 150 int end_position() const { return end_position_; } |
150 void set_end_position(int end_position) { end_position_ = end_position; } | 151 void set_end_position(int end_position) { end_position_ = end_position; } |
151 | 152 |
152 // Getters for individual compiler hints. | 153 // Getters for individual compiler hints. |
153 bool is_declaration() const; | 154 bool is_declaration() const; |
154 bool is_arrow() const; | 155 bool is_arrow() const; |
155 bool is_async() const; | 156 bool is_async() const; |
156 bool is_default_constructor() const; | 157 bool is_default_constructor() const; |
157 FunctionKind function_kind() const; | 158 FunctionKind function_kind() const; |
158 | 159 |
159 //-------------------------------------------------------------------------- | 160 //-------------------------------------------------------------------------- |
160 // TODO(titzer): these should not be part of ParseInfo. | 161 // TODO(titzer): these should not be part of ParseInfo. |
161 //-------------------------------------------------------------------------- | 162 //-------------------------------------------------------------------------- |
162 Isolate* isolate() { return isolate_; } | 163 Isolate* isolate() const { return isolate_; } |
163 Handle<SharedFunctionInfo> shared_info() { return shared_; } | 164 Handle<SharedFunctionInfo> shared_info() const { return shared_; } |
164 Handle<Script> script() { return script_; } | 165 Handle<Script> script() const { return script_; } |
165 Handle<Context> context() { return context_; } | 166 Handle<Context> context() const { return context_; } |
166 void clear_script() { script_ = Handle<Script>::null(); } | 167 void clear_script() { script_ = Handle<Script>::null(); } |
167 void set_isolate(Isolate* isolate) { isolate_ = isolate; } | 168 void set_isolate(Isolate* isolate) { isolate_ = isolate; } |
168 void set_shared_info(Handle<SharedFunctionInfo> shared) { shared_ = shared; } | 169 void set_shared_info(Handle<SharedFunctionInfo> shared) { shared_ = shared; } |
169 void set_context(Handle<Context> context) { context_ = context; } | 170 void set_context(Handle<Context> context) { context_ = context; } |
170 void set_script(Handle<Script> script) { script_ = script; } | 171 void set_script(Handle<Script> script) { script_ = script; } |
171 //-------------------------------------------------------------------------- | 172 //-------------------------------------------------------------------------- |
172 | 173 |
173 LanguageMode language_mode() { | 174 LanguageMode language_mode() const { |
174 return construct_language_mode(is_strict_mode()); | 175 return construct_language_mode(is_strict_mode()); |
175 } | 176 } |
176 void set_language_mode(LanguageMode language_mode) { | 177 void set_language_mode(LanguageMode language_mode) { |
177 STATIC_ASSERT(LANGUAGE_END == 3); | 178 STATIC_ASSERT(LANGUAGE_END == 3); |
178 set_strict_mode(is_strict(language_mode)); | 179 set_strict_mode(is_strict(language_mode)); |
179 } | 180 } |
180 | 181 |
181 void ReopenHandlesInNewHandleScope() { | 182 void ReopenHandlesInNewHandleScope() { |
182 shared_ = Handle<SharedFunctionInfo>(*shared_); | 183 shared_ = Handle<SharedFunctionInfo>(*shared_); |
183 script_ = Handle<Script>(*script_); | 184 script_ = Handle<Script>(*script_); |
184 context_ = Handle<Context>(*context_); | 185 context_ = Handle<Context>(*context_); |
185 } | 186 } |
186 | 187 |
187 #ifdef DEBUG | 188 #ifdef DEBUG |
188 bool script_is_native() { return script_->type() == Script::TYPE_NATIVE; } | 189 bool script_is_native() const { |
| 190 return script_->type() == Script::TYPE_NATIVE; |
| 191 } |
189 #endif // DEBUG | 192 #endif // DEBUG |
190 | 193 |
191 private: | 194 private: |
192 // Various configuration flags for parsing. | 195 // Various configuration flags for parsing. |
193 enum Flag { | 196 enum Flag { |
194 // ---------- Input flags --------------------------- | 197 // ---------- Input flags --------------------------- |
195 kToplevel = 1 << 0, | 198 kToplevel = 1 << 0, |
196 kLazy = 1 << 1, | 199 kLazy = 1 << 1, |
197 kEval = 1 << 2, | 200 kEval = 1 << 2, |
198 kGlobal = 1 << 3, | 201 kGlobal = 1 << 3, |
(...skipping 28 matching lines...) Expand all Loading... |
227 Isolate* isolate_; | 230 Isolate* isolate_; |
228 Handle<SharedFunctionInfo> shared_; | 231 Handle<SharedFunctionInfo> shared_; |
229 Handle<Script> script_; | 232 Handle<Script> script_; |
230 Handle<Context> context_; | 233 Handle<Context> context_; |
231 | 234 |
232 //----------- Inputs+Outputs of parsing and scope analysis ----------------- | 235 //----------- Inputs+Outputs of parsing and scope analysis ----------------- |
233 ScriptData** cached_data_; // used if available, populated if requested. | 236 ScriptData** cached_data_; // used if available, populated if requested. |
234 AstValueFactory* ast_value_factory_; // used if available, otherwise new. | 237 AstValueFactory* ast_value_factory_; // used if available, otherwise new. |
235 const AstRawString* function_name_; | 238 const AstRawString* function_name_; |
236 | 239 |
237 //----------- Outputs of parsing and scope analysis ------------------------ | 240 //----------- Output of parsing and scope analysis ------------------------ |
238 FunctionLiteral* literal_; // produced by full parser. | 241 FunctionLiteral* literal_; |
239 DeclarationScope* scope_; // produced by scope analysis. | |
240 | 242 |
241 void SetFlag(Flag f) { flags_ |= f; } | 243 void SetFlag(Flag f) { flags_ |= f; } |
242 void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; } | 244 void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; } |
243 bool GetFlag(Flag f) const { return (flags_ & f) != 0; } | 245 bool GetFlag(Flag f) const { return (flags_ & f) != 0; } |
244 }; | 246 }; |
245 | 247 |
246 class FunctionEntry BASE_EMBEDDED { | 248 class FunctionEntry BASE_EMBEDDED { |
247 public: | 249 public: |
248 enum { | 250 enum { |
249 kStartPositionIndex, | 251 kStartPositionIndex, |
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 | 1363 |
1362 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { | 1364 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { |
1363 return parser_->ParseDoExpression(ok); | 1365 return parser_->ParseDoExpression(ok); |
1364 } | 1366 } |
1365 | 1367 |
1366 | 1368 |
1367 } // namespace internal | 1369 } // namespace internal |
1368 } // namespace v8 | 1370 } // namespace v8 |
1369 | 1371 |
1370 #endif // V8_PARSING_PARSER_H_ | 1372 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |