| 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" | |
| 9 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 10 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
| 11 #include "src/compiler.h" // TODO(titzer): remove this include dependency | |
| 12 #include "src/parsing/parser-base.h" | 10 #include "src/parsing/parser-base.h" |
| 13 #include "src/parsing/preparse-data.h" | 11 #include "src/parsing/preparse-data.h" |
| 14 #include "src/parsing/preparse-data-format.h" | 12 #include "src/parsing/preparse-data-format.h" |
| 15 #include "src/parsing/preparser.h" | 13 #include "src/parsing/preparser.h" |
| 16 #include "src/pending-compilation-error-handler.h" | 14 #include "src/pending-compilation-error-handler.h" |
| 17 | 15 |
| 18 namespace v8 { | 16 namespace v8 { |
| 19 | 17 |
| 20 class ScriptCompiler; | 18 class ScriptCompiler; |
| 21 | 19 |
| 22 namespace internal { | 20 namespace internal { |
| 23 | 21 |
| 22 class ParseInfo; |
| 23 class ScriptData; |
| 24 class Target; | 24 class Target; |
| 25 | 25 |
| 26 // A container for the inputs, configuration options, and outputs of parsing. | |
| 27 class ParseInfo { | |
| 28 public: | |
| 29 explicit ParseInfo(Zone* zone); | |
| 30 ParseInfo(Zone* zone, Handle<JSFunction> function); | |
| 31 ParseInfo(Zone* zone, Handle<Script> script); | |
| 32 // TODO(all) Only used via Debug::FindSharedFunctionInfoInScript, remove? | |
| 33 ParseInfo(Zone* zone, Handle<SharedFunctionInfo> shared); | |
| 34 | |
| 35 ~ParseInfo() { | |
| 36 if (ast_value_factory_owned()) { | |
| 37 delete ast_value_factory_; | |
| 38 set_ast_value_factory_owned(false); | |
| 39 } | |
| 40 ast_value_factory_ = nullptr; | |
| 41 } | |
| 42 | |
| 43 Zone* zone() const { return zone_; } | |
| 44 | |
| 45 // Convenience accessor methods for flags. | |
| 46 #define FLAG_ACCESSOR(flag, getter, setter) \ | |
| 47 bool getter() const { return GetFlag(flag); } \ | |
| 48 void setter() { SetFlag(flag); } \ | |
| 49 void setter(bool val) { SetFlag(flag, val); } | |
| 50 | |
| 51 FLAG_ACCESSOR(kToplevel, is_toplevel, set_toplevel) | |
| 52 FLAG_ACCESSOR(kLazy, is_lazy, set_lazy) | |
| 53 FLAG_ACCESSOR(kEval, is_eval, set_eval) | |
| 54 FLAG_ACCESSOR(kGlobal, is_global, set_global) | |
| 55 FLAG_ACCESSOR(kStrictMode, is_strict_mode, set_strict_mode) | |
| 56 FLAG_ACCESSOR(kNative, is_native, set_native) | |
| 57 FLAG_ACCESSOR(kModule, is_module, set_module) | |
| 58 FLAG_ACCESSOR(kAllowLazyParsing, allow_lazy_parsing, set_allow_lazy_parsing) | |
| 59 FLAG_ACCESSOR(kAstValueFactoryOwned, ast_value_factory_owned, | |
| 60 set_ast_value_factory_owned) | |
| 61 FLAG_ACCESSOR(kIsNamedExpression, is_named_expression, | |
| 62 set_is_named_expression) | |
| 63 FLAG_ACCESSOR(kCallsEval, calls_eval, set_calls_eval) | |
| 64 | |
| 65 #undef FLAG_ACCESSOR | |
| 66 | |
| 67 void set_parse_restriction(ParseRestriction restriction) { | |
| 68 SetFlag(kParseRestriction, restriction != NO_PARSE_RESTRICTION); | |
| 69 } | |
| 70 | |
| 71 ParseRestriction parse_restriction() const { | |
| 72 return GetFlag(kParseRestriction) ? ONLY_SINGLE_FUNCTION_LITERAL | |
| 73 : NO_PARSE_RESTRICTION; | |
| 74 } | |
| 75 | |
| 76 ScriptCompiler::ExternalSourceStream* source_stream() const { | |
| 77 return source_stream_; | |
| 78 } | |
| 79 void set_source_stream(ScriptCompiler::ExternalSourceStream* source_stream) { | |
| 80 source_stream_ = source_stream; | |
| 81 } | |
| 82 | |
| 83 ScriptCompiler::StreamedSource::Encoding source_stream_encoding() const { | |
| 84 return source_stream_encoding_; | |
| 85 } | |
| 86 void set_source_stream_encoding( | |
| 87 ScriptCompiler::StreamedSource::Encoding source_stream_encoding) { | |
| 88 source_stream_encoding_ = source_stream_encoding; | |
| 89 } | |
| 90 | |
| 91 Utf16CharacterStream* character_stream() const { return character_stream_; } | |
| 92 void set_character_stream(Utf16CharacterStream* character_stream) { | |
| 93 character_stream_ = character_stream; | |
| 94 } | |
| 95 | |
| 96 v8::Extension* extension() const { return extension_; } | |
| 97 void set_extension(v8::Extension* extension) { extension_ = extension; } | |
| 98 | |
| 99 ScriptData** cached_data() const { return cached_data_; } | |
| 100 void set_cached_data(ScriptData** cached_data) { cached_data_ = cached_data; } | |
| 101 | |
| 102 ScriptCompiler::CompileOptions compile_options() const { | |
| 103 return compile_options_; | |
| 104 } | |
| 105 void set_compile_options(ScriptCompiler::CompileOptions compile_options) { | |
| 106 compile_options_ = compile_options; | |
| 107 } | |
| 108 | |
| 109 DeclarationScope* script_scope() const { return script_scope_; } | |
| 110 void set_script_scope(DeclarationScope* script_scope) { | |
| 111 script_scope_ = script_scope; | |
| 112 } | |
| 113 | |
| 114 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } | |
| 115 void set_ast_value_factory(AstValueFactory* ast_value_factory) { | |
| 116 ast_value_factory_ = ast_value_factory; | |
| 117 } | |
| 118 | |
| 119 const AstRawString* function_name() const { return function_name_; } | |
| 120 void set_function_name(const AstRawString* function_name) { | |
| 121 function_name_ = function_name; | |
| 122 } | |
| 123 | |
| 124 FunctionLiteral* literal() const { return literal_; } | |
| 125 void set_literal(FunctionLiteral* literal) { literal_ = literal; } | |
| 126 | |
| 127 DeclarationScope* scope() const { return literal()->scope(); } | |
| 128 | |
| 129 UnicodeCache* unicode_cache() const { return unicode_cache_; } | |
| 130 void set_unicode_cache(UnicodeCache* unicode_cache) { | |
| 131 unicode_cache_ = unicode_cache; | |
| 132 } | |
| 133 | |
| 134 uintptr_t stack_limit() const { return stack_limit_; } | |
| 135 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | |
| 136 | |
| 137 uint32_t hash_seed() const { return hash_seed_; } | |
| 138 void set_hash_seed(uint32_t hash_seed) { hash_seed_ = hash_seed; } | |
| 139 | |
| 140 int compiler_hints() const { return compiler_hints_; } | |
| 141 void set_compiler_hints(int compiler_hints) { | |
| 142 compiler_hints_ = compiler_hints; | |
| 143 } | |
| 144 | |
| 145 int start_position() const { return start_position_; } | |
| 146 void set_start_position(int start_position) { | |
| 147 start_position_ = start_position; | |
| 148 } | |
| 149 | |
| 150 int end_position() const { return end_position_; } | |
| 151 void set_end_position(int end_position) { end_position_ = end_position; } | |
| 152 | |
| 153 // Getters for individual compiler hints. | |
| 154 bool is_declaration() const; | |
| 155 bool is_arrow() const; | |
| 156 bool is_async() const; | |
| 157 bool is_default_constructor() const; | |
| 158 FunctionKind function_kind() const; | |
| 159 | |
| 160 //-------------------------------------------------------------------------- | |
| 161 // TODO(titzer): these should not be part of ParseInfo. | |
| 162 //-------------------------------------------------------------------------- | |
| 163 Isolate* isolate() const { return isolate_; } | |
| 164 Handle<SharedFunctionInfo> shared_info() const { return shared_; } | |
| 165 Handle<Script> script() const { return script_; } | |
| 166 Handle<Context> context() const { return context_; } | |
| 167 void clear_script() { script_ = Handle<Script>::null(); } | |
| 168 void set_isolate(Isolate* isolate) { isolate_ = isolate; } | |
| 169 void set_shared_info(Handle<SharedFunctionInfo> shared) { shared_ = shared; } | |
| 170 void set_context(Handle<Context> context) { context_ = context; } | |
| 171 void set_script(Handle<Script> script) { script_ = script; } | |
| 172 //-------------------------------------------------------------------------- | |
| 173 | |
| 174 LanguageMode language_mode() const { | |
| 175 return construct_language_mode(is_strict_mode()); | |
| 176 } | |
| 177 void set_language_mode(LanguageMode language_mode) { | |
| 178 STATIC_ASSERT(LANGUAGE_END == 2); | |
| 179 set_strict_mode(is_strict(language_mode)); | |
| 180 } | |
| 181 | |
| 182 void ReopenHandlesInNewHandleScope() { | |
| 183 shared_ = Handle<SharedFunctionInfo>(*shared_); | |
| 184 script_ = Handle<Script>(*script_); | |
| 185 context_ = Handle<Context>(*context_); | |
| 186 } | |
| 187 | |
| 188 #ifdef DEBUG | |
| 189 bool script_is_native() const { | |
| 190 return script_->type() == Script::TYPE_NATIVE; | |
| 191 } | |
| 192 #endif // DEBUG | |
| 193 | |
| 194 private: | |
| 195 // Various configuration flags for parsing. | |
| 196 enum Flag { | |
| 197 // ---------- Input flags --------------------------- | |
| 198 kToplevel = 1 << 0, | |
| 199 kLazy = 1 << 1, | |
| 200 kEval = 1 << 2, | |
| 201 kGlobal = 1 << 3, | |
| 202 kStrictMode = 1 << 4, | |
| 203 kNative = 1 << 5, | |
| 204 kParseRestriction = 1 << 6, | |
| 205 kModule = 1 << 7, | |
| 206 kAllowLazyParsing = 1 << 8, | |
| 207 kIsNamedExpression = 1 << 9, | |
| 208 kCallsEval = 1 << 10, | |
| 209 // ---------- Output flags -------------------------- | |
| 210 kAstValueFactoryOwned = 1 << 11 | |
| 211 }; | |
| 212 | |
| 213 //------------- Inputs to parsing and scope analysis ----------------------- | |
| 214 Zone* zone_; | |
| 215 unsigned flags_; | |
| 216 ScriptCompiler::ExternalSourceStream* source_stream_; | |
| 217 ScriptCompiler::StreamedSource::Encoding source_stream_encoding_; | |
| 218 Utf16CharacterStream* character_stream_; | |
| 219 v8::Extension* extension_; | |
| 220 ScriptCompiler::CompileOptions compile_options_; | |
| 221 DeclarationScope* script_scope_; | |
| 222 UnicodeCache* unicode_cache_; | |
| 223 uintptr_t stack_limit_; | |
| 224 uint32_t hash_seed_; | |
| 225 int compiler_hints_; | |
| 226 int start_position_; | |
| 227 int end_position_; | |
| 228 | |
| 229 // TODO(titzer): Move handles and isolate out of ParseInfo. | |
| 230 Isolate* isolate_; | |
| 231 Handle<SharedFunctionInfo> shared_; | |
| 232 Handle<Script> script_; | |
| 233 Handle<Context> context_; | |
| 234 | |
| 235 //----------- Inputs+Outputs of parsing and scope analysis ----------------- | |
| 236 ScriptData** cached_data_; // used if available, populated if requested. | |
| 237 AstValueFactory* ast_value_factory_; // used if available, otherwise new. | |
| 238 const AstRawString* function_name_; | |
| 239 | |
| 240 //----------- Output of parsing and scope analysis ------------------------ | |
| 241 FunctionLiteral* literal_; | |
| 242 | |
| 243 void SetFlag(Flag f) { flags_ |= f; } | |
| 244 void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; } | |
| 245 bool GetFlag(Flag f) const { return (flags_ & f) != 0; } | |
| 246 }; | |
| 247 | |
| 248 class FunctionEntry BASE_EMBEDDED { | 26 class FunctionEntry BASE_EMBEDDED { |
| 249 public: | 27 public: |
| 250 enum { | 28 enum { |
| 251 kStartPositionIndex, | 29 kStartPositionIndex, |
| 252 kEndPositionIndex, | 30 kEndPositionIndex, |
| 253 kLiteralCountIndex, | 31 kLiteralCountIndex, |
| 254 kPropertyCountIndex, | 32 kPropertyCountIndex, |
| 255 kLanguageModeIndex, | 33 kLanguageModeIndex, |
| 256 kUsesSuperPropertyIndex, | 34 kUsesSuperPropertyIndex, |
| 257 kCallsEvalIndex, | 35 kCallsEvalIndex, |
| (...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 | 1133 |
| 1356 Expression* ParserTraits::RewriteYieldStar(Expression* generator, | 1134 Expression* ParserTraits::RewriteYieldStar(Expression* generator, |
| 1357 Expression* iterable, int pos) { | 1135 Expression* iterable, int pos) { |
| 1358 return parser_->RewriteYieldStar(generator, iterable, pos); | 1136 return parser_->RewriteYieldStar(generator, iterable, pos); |
| 1359 } | 1137 } |
| 1360 | 1138 |
| 1361 } // namespace internal | 1139 } // namespace internal |
| 1362 } // namespace v8 | 1140 } // namespace v8 |
| 1363 | 1141 |
| 1364 #endif // V8_PARSING_PARSER_H_ | 1142 #endif // V8_PARSING_PARSER_H_ |
| OLD | NEW |