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 FunctionLiteral* literal() { return literal_; } | 119 FunctionLiteral* literal() const { return literal_; } |
118 void set_literal(FunctionLiteral* literal) { literal_ = literal; } | 120 void set_literal(FunctionLiteral* literal) { literal_ = literal; } |
119 | 121 |
120 DeclarationScope* scope() { return scope_; } | 122 DeclarationScope* scope() const { return literal()->scope(); } |
121 void set_scope(DeclarationScope* scope) { scope_ = scope; } | |
122 | 123 |
123 UnicodeCache* unicode_cache() { return unicode_cache_; } | 124 UnicodeCache* unicode_cache() const { return unicode_cache_; } |
124 void set_unicode_cache(UnicodeCache* unicode_cache) { | 125 void set_unicode_cache(UnicodeCache* unicode_cache) { |
125 unicode_cache_ = unicode_cache; | 126 unicode_cache_ = unicode_cache; |
126 } | 127 } |
127 | 128 |
128 uintptr_t stack_limit() { return stack_limit_; } | 129 uintptr_t stack_limit() const { return stack_limit_; } |
129 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 130 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
130 | 131 |
131 uint32_t hash_seed() { return hash_seed_; } | 132 uint32_t hash_seed() const { return hash_seed_; } |
132 void set_hash_seed(uint32_t hash_seed) { hash_seed_ = hash_seed; } | 133 void set_hash_seed(uint32_t hash_seed) { hash_seed_ = hash_seed; } |
133 | 134 |
134 int compiler_hints() const { return compiler_hints_; } | 135 int compiler_hints() const { return compiler_hints_; } |
135 void set_compiler_hints(int compiler_hints) { | 136 void set_compiler_hints(int compiler_hints) { |
136 compiler_hints_ = compiler_hints; | 137 compiler_hints_ = compiler_hints; |
137 } | 138 } |
138 | 139 |
139 int start_position() const { return start_position_; } | 140 int start_position() const { return start_position_; } |
140 void set_start_position(int start_position) { | 141 void set_start_position(int start_position) { |
141 start_position_ = start_position; | 142 start_position_ = start_position; |
142 } | 143 } |
143 | 144 |
144 int end_position() const { return end_position_; } | 145 int end_position() const { return end_position_; } |
145 void set_end_position(int end_position) { end_position_ = end_position; } | 146 void set_end_position(int end_position) { end_position_ = end_position; } |
146 | 147 |
147 // Getters for individual compiler hints. | 148 // Getters for individual compiler hints. |
148 bool is_declaration() const; | 149 bool is_declaration() const; |
149 bool is_arrow() const; | 150 bool is_arrow() const; |
150 bool is_async() const; | 151 bool is_async() const; |
151 bool is_default_constructor() const; | 152 bool is_default_constructor() const; |
152 FunctionKind function_kind() const; | 153 FunctionKind function_kind() const; |
153 | 154 |
154 //-------------------------------------------------------------------------- | 155 //-------------------------------------------------------------------------- |
155 // TODO(titzer): these should not be part of ParseInfo. | 156 // TODO(titzer): these should not be part of ParseInfo. |
156 //-------------------------------------------------------------------------- | 157 //-------------------------------------------------------------------------- |
157 Isolate* isolate() { return isolate_; } | 158 Isolate* isolate() const { return isolate_; } |
158 Handle<SharedFunctionInfo> shared_info() { return shared_; } | 159 Handle<SharedFunctionInfo> shared_info() const { return shared_; } |
159 Handle<Script> script() { return script_; } | 160 Handle<Script> script() const { return script_; } |
160 Handle<Context> context() { return context_; } | 161 Handle<Context> context() const { return context_; } |
161 void clear_script() { script_ = Handle<Script>::null(); } | 162 void clear_script() { script_ = Handle<Script>::null(); } |
162 void set_isolate(Isolate* isolate) { isolate_ = isolate; } | 163 void set_isolate(Isolate* isolate) { isolate_ = isolate; } |
163 void set_shared_info(Handle<SharedFunctionInfo> shared) { shared_ = shared; } | 164 void set_shared_info(Handle<SharedFunctionInfo> shared) { shared_ = shared; } |
164 void set_context(Handle<Context> context) { context_ = context; } | 165 void set_context(Handle<Context> context) { context_ = context; } |
165 void set_script(Handle<Script> script) { script_ = script; } | 166 void set_script(Handle<Script> script) { script_ = script; } |
166 //-------------------------------------------------------------------------- | 167 //-------------------------------------------------------------------------- |
167 | 168 |
168 LanguageMode language_mode() { | 169 LanguageMode language_mode() const { |
169 return construct_language_mode(is_strict_mode()); | 170 return construct_language_mode(is_strict_mode()); |
170 } | 171 } |
171 void set_language_mode(LanguageMode language_mode) { | 172 void set_language_mode(LanguageMode language_mode) { |
172 STATIC_ASSERT(LANGUAGE_END == 3); | 173 STATIC_ASSERT(LANGUAGE_END == 3); |
173 set_strict_mode(is_strict(language_mode)); | 174 set_strict_mode(is_strict(language_mode)); |
174 } | 175 } |
175 | 176 |
176 void ReopenHandlesInNewHandleScope() { | 177 void ReopenHandlesInNewHandleScope() { |
177 shared_ = Handle<SharedFunctionInfo>(*shared_); | 178 shared_ = Handle<SharedFunctionInfo>(*shared_); |
178 script_ = Handle<Script>(*script_); | 179 script_ = Handle<Script>(*script_); |
179 context_ = Handle<Context>(*context_); | 180 context_ = Handle<Context>(*context_); |
180 } | 181 } |
181 | 182 |
182 #ifdef DEBUG | 183 #ifdef DEBUG |
183 bool script_is_native() { return script_->type() == Script::TYPE_NATIVE; } | 184 bool script_is_native() const { |
| 185 return script_->type() == Script::TYPE_NATIVE; |
| 186 } |
184 #endif // DEBUG | 187 #endif // DEBUG |
185 | 188 |
186 private: | 189 private: |
187 // Various configuration flags for parsing. | 190 // Various configuration flags for parsing. |
188 enum Flag { | 191 enum Flag { |
189 // ---------- Input flags --------------------------- | 192 // ---------- Input flags --------------------------- |
190 kToplevel = 1 << 0, | 193 kToplevel = 1 << 0, |
191 kLazy = 1 << 1, | 194 kLazy = 1 << 1, |
192 kEval = 1 << 2, | 195 kEval = 1 << 2, |
193 kGlobal = 1 << 3, | 196 kGlobal = 1 << 3, |
(...skipping 27 matching lines...) Expand all Loading... |
221 // TODO(titzer): Move handles and isolate out of ParseInfo. | 224 // TODO(titzer): Move handles and isolate out of ParseInfo. |
222 Isolate* isolate_; | 225 Isolate* isolate_; |
223 Handle<SharedFunctionInfo> shared_; | 226 Handle<SharedFunctionInfo> shared_; |
224 Handle<Script> script_; | 227 Handle<Script> script_; |
225 Handle<Context> context_; | 228 Handle<Context> context_; |
226 | 229 |
227 //----------- Inputs+Outputs of parsing and scope analysis ----------------- | 230 //----------- Inputs+Outputs of parsing and scope analysis ----------------- |
228 ScriptData** cached_data_; // used if available, populated if requested. | 231 ScriptData** cached_data_; // used if available, populated if requested. |
229 AstValueFactory* ast_value_factory_; // used if available, otherwise new. | 232 AstValueFactory* ast_value_factory_; // used if available, otherwise new. |
230 | 233 |
231 //----------- Outputs of parsing and scope analysis ------------------------ | 234 //----------- Output of parsing and scope analysis ------------------------ |
232 FunctionLiteral* literal_; // produced by full parser. | 235 FunctionLiteral* literal_; |
233 DeclarationScope* scope_; // produced by scope analysis. | |
234 | 236 |
235 void SetFlag(Flag f) { flags_ |= f; } | 237 void SetFlag(Flag f) { flags_ |= f; } |
236 void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; } | 238 void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; } |
237 bool GetFlag(Flag f) const { return (flags_ & f) != 0; } | 239 bool GetFlag(Flag f) const { return (flags_ & f) != 0; } |
238 }; | 240 }; |
239 | 241 |
240 class FunctionEntry BASE_EMBEDDED { | 242 class FunctionEntry BASE_EMBEDDED { |
241 public: | 243 public: |
242 enum { | 244 enum { |
243 kStartPositionIndex, | 245 kStartPositionIndex, |
(...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 | 1358 |
1357 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { | 1359 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { |
1358 return parser_->ParseDoExpression(ok); | 1360 return parser_->ParseDoExpression(ok); |
1359 } | 1361 } |
1360 | 1362 |
1361 | 1363 |
1362 } // namespace internal | 1364 } // namespace internal |
1363 } // namespace v8 | 1365 } // namespace v8 |
1364 | 1366 |
1365 #endif // V8_PARSING_PARSER_H_ | 1367 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |