| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() { 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() { return compile_options_; } |
| 103 void set_compile_options(ScriptCompiler::CompileOptions compile_options) { | 103 void set_compile_options(ScriptCompiler::CompileOptions compile_options) { |
| 104 compile_options_ = compile_options; | 104 compile_options_ = compile_options; |
| 105 } | 105 } |
| 106 | 106 |
| 107 DeclarationScope* script_scope() { return script_scope_; } | 107 Scope* script_scope() { return script_scope_; } |
| 108 void set_script_scope(DeclarationScope* script_scope) { | 108 void set_script_scope(Scope* script_scope) { script_scope_ = script_scope; } |
| 109 script_scope_ = script_scope; | |
| 110 } | |
| 111 | 109 |
| 112 AstValueFactory* ast_value_factory() { return ast_value_factory_; } | 110 AstValueFactory* ast_value_factory() { return ast_value_factory_; } |
| 113 void set_ast_value_factory(AstValueFactory* ast_value_factory) { | 111 void set_ast_value_factory(AstValueFactory* ast_value_factory) { |
| 114 ast_value_factory_ = ast_value_factory; | 112 ast_value_factory_ = ast_value_factory; |
| 115 } | 113 } |
| 116 | 114 |
| 117 FunctionLiteral* literal() { return literal_; } | 115 FunctionLiteral* literal() { return literal_; } |
| 118 void set_literal(FunctionLiteral* literal) { literal_ = literal; } | 116 void set_literal(FunctionLiteral* literal) { literal_ = literal; } |
| 119 | 117 |
| 120 DeclarationScope* scope() { return scope_; } | 118 Scope* scope() { return scope_; } |
| 121 void set_scope(DeclarationScope* scope) { scope_ = scope; } | 119 void set_scope(Scope* scope) { scope_ = scope; } |
| 122 | 120 |
| 123 UnicodeCache* unicode_cache() { return unicode_cache_; } | 121 UnicodeCache* unicode_cache() { return unicode_cache_; } |
| 124 void set_unicode_cache(UnicodeCache* unicode_cache) { | 122 void set_unicode_cache(UnicodeCache* unicode_cache) { |
| 125 unicode_cache_ = unicode_cache; | 123 unicode_cache_ = unicode_cache; |
| 126 } | 124 } |
| 127 | 125 |
| 128 uintptr_t stack_limit() { return stack_limit_; } | 126 uintptr_t stack_limit() { return stack_limit_; } |
| 129 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 127 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
| 130 | 128 |
| 131 uint32_t hash_seed() { return hash_seed_; } | 129 uint32_t hash_seed() { return hash_seed_; } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 }; | 201 }; |
| 204 | 202 |
| 205 //------------- Inputs to parsing and scope analysis ----------------------- | 203 //------------- Inputs to parsing and scope analysis ----------------------- |
| 206 Zone* zone_; | 204 Zone* zone_; |
| 207 unsigned flags_; | 205 unsigned flags_; |
| 208 ScriptCompiler::ExternalSourceStream* source_stream_; | 206 ScriptCompiler::ExternalSourceStream* source_stream_; |
| 209 ScriptCompiler::StreamedSource::Encoding source_stream_encoding_; | 207 ScriptCompiler::StreamedSource::Encoding source_stream_encoding_; |
| 210 Utf16CharacterStream* character_stream_; | 208 Utf16CharacterStream* character_stream_; |
| 211 v8::Extension* extension_; | 209 v8::Extension* extension_; |
| 212 ScriptCompiler::CompileOptions compile_options_; | 210 ScriptCompiler::CompileOptions compile_options_; |
| 213 DeclarationScope* script_scope_; | 211 Scope* script_scope_; |
| 214 UnicodeCache* unicode_cache_; | 212 UnicodeCache* unicode_cache_; |
| 215 uintptr_t stack_limit_; | 213 uintptr_t stack_limit_; |
| 216 uint32_t hash_seed_; | 214 uint32_t hash_seed_; |
| 217 int compiler_hints_; | 215 int compiler_hints_; |
| 218 int start_position_; | 216 int start_position_; |
| 219 int end_position_; | 217 int end_position_; |
| 220 | 218 |
| 221 // TODO(titzer): Move handles and isolate out of ParseInfo. | 219 // TODO(titzer): Move handles and isolate out of ParseInfo. |
| 222 Isolate* isolate_; | 220 Isolate* isolate_; |
| 223 Handle<SharedFunctionInfo> shared_; | 221 Handle<SharedFunctionInfo> shared_; |
| 224 Handle<Script> script_; | 222 Handle<Script> script_; |
| 225 Handle<Context> context_; | 223 Handle<Context> context_; |
| 226 | 224 |
| 227 //----------- Inputs+Outputs of parsing and scope analysis ----------------- | 225 //----------- Inputs+Outputs of parsing and scope analysis ----------------- |
| 228 ScriptData** cached_data_; // used if available, populated if requested. | 226 ScriptData** cached_data_; // used if available, populated if requested. |
| 229 AstValueFactory* ast_value_factory_; // used if available, otherwise new. | 227 AstValueFactory* ast_value_factory_; // used if available, otherwise new. |
| 230 | 228 |
| 231 //----------- Outputs of parsing and scope analysis ------------------------ | 229 //----------- Outputs of parsing and scope analysis ------------------------ |
| 232 FunctionLiteral* literal_; // produced by full parser. | 230 FunctionLiteral* literal_; // produced by full parser. |
| 233 DeclarationScope* scope_; // produced by scope analysis. | 231 Scope* scope_; // produced by scope analysis. |
| 234 | 232 |
| 235 void SetFlag(Flag f) { flags_ |= f; } | 233 void SetFlag(Flag f) { flags_ |= f; } |
| 236 void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; } | 234 void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; } |
| 237 bool GetFlag(Flag f) const { return (flags_ & f) != 0; } | 235 bool GetFlag(Flag f) const { return (flags_ & f) != 0; } |
| 238 }; | 236 }; |
| 239 | 237 |
| 240 class FunctionEntry BASE_EMBEDDED { | 238 class FunctionEntry BASE_EMBEDDED { |
| 241 public: | 239 public: |
| 242 enum { | 240 enum { |
| 243 kStartPositionIndex, | 241 kStartPositionIndex, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 const AstRawString* name; | 334 const AstRawString* name; |
| 337 Expression* pattern; | 335 Expression* pattern; |
| 338 Expression* initializer; | 336 Expression* initializer; |
| 339 int initializer_end_position; | 337 int initializer_end_position; |
| 340 bool is_rest; | 338 bool is_rest; |
| 341 bool is_simple() const { | 339 bool is_simple() const { |
| 342 return pattern->IsVariableProxy() && initializer == nullptr && !is_rest; | 340 return pattern->IsVariableProxy() && initializer == nullptr && !is_rest; |
| 343 } | 341 } |
| 344 }; | 342 }; |
| 345 | 343 |
| 346 explicit ParserFormalParameters(DeclarationScope* scope) | 344 explicit ParserFormalParameters(Scope* scope) |
| 347 : FormalParametersBase(scope), params(4, scope->zone()) {} | 345 : FormalParametersBase(scope), params(4, scope->zone()) {} |
| 348 ZoneList<Parameter> params; | 346 ZoneList<Parameter> params; |
| 349 | 347 |
| 350 int Arity() const { return params.length(); } | 348 int Arity() const { return params.length(); } |
| 351 const Parameter& at(int i) const { return params[i]; } | 349 const Parameter& at(int i) const { return params[i]; } |
| 352 }; | 350 }; |
| 353 | 351 |
| 354 | 352 |
| 355 class ParserTraits { | 353 class ParserTraits { |
| 356 public: | 354 public: |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 | 570 |
| 573 V8_INLINE void AddParameterInitializationBlock( | 571 V8_INLINE void AddParameterInitializationBlock( |
| 574 const ParserFormalParameters& parameters, | 572 const ParserFormalParameters& parameters, |
| 575 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); | 573 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); |
| 576 | 574 |
| 577 void ParseAsyncArrowSingleExpressionBody( | 575 void ParseAsyncArrowSingleExpressionBody( |
| 578 ZoneList<Statement*>* body, bool accept_IN, | 576 ZoneList<Statement*>* body, bool accept_IN, |
| 579 Type::ExpressionClassifier* classifier, int pos, bool* ok); | 577 Type::ExpressionClassifier* classifier, int pos, bool* ok); |
| 580 | 578 |
| 581 V8_INLINE Scope* NewScope(ScopeType scope_type); | 579 V8_INLINE Scope* NewScope(ScopeType scope_type); |
| 582 V8_INLINE DeclarationScope* NewFunctionScope(FunctionKind kind); | 580 V8_INLINE Scope* NewFunctionScope(FunctionKind kind); |
| 583 V8_INLINE Scope* NewScopeWithParent(Scope* parent, ScopeType scope_type); | 581 V8_INLINE Scope* NewScopeWithParent(Scope* parent, ScopeType scope_type); |
| 584 | 582 |
| 585 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, | 583 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, |
| 586 Expression* pattern, | 584 Expression* pattern, |
| 587 Expression* initializer, | 585 Expression* initializer, |
| 588 int initializer_end_position, bool is_rest); | 586 int initializer_end_position, bool is_rest); |
| 589 V8_INLINE void DeclareFormalParameter( | 587 V8_INLINE void DeclareFormalParameter( |
| 590 DeclarationScope* scope, | 588 Scope* scope, const ParserFormalParameters::Parameter& parameter, |
| 591 const ParserFormalParameters::Parameter& parameter, | |
| 592 Type::ExpressionClassifier* classifier); | 589 Type::ExpressionClassifier* classifier); |
| 593 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, | 590 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, |
| 594 Expression* params, int end_pos, | 591 Expression* params, int end_pos, |
| 595 bool* ok); | 592 bool* ok); |
| 596 void ParseArrowFunctionFormalParameterList( | 593 void ParseArrowFunctionFormalParameterList( |
| 597 ParserFormalParameters* parameters, Expression* params, | 594 ParserFormalParameters* parameters, Expression* params, |
| 598 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 595 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
| 599 const Scope::Snapshot& scope_snapshot, bool* ok); | 596 const Scope::Snapshot& scope_snapshot, bool* ok); |
| 600 | 597 |
| 601 V8_INLINE Expression* ParseAsyncFunctionExpression(bool* ok); | 598 V8_INLINE Expression* ParseAsyncFunctionExpression(bool* ok); |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 // The var declarations are hoisted to the function scope, but originate from | 1058 // The var declarations are hoisted to the function scope, but originate from |
| 1062 // a scope where the name has also been let bound or the var declaration is | 1059 // a scope where the name has also been let bound or the var declaration is |
| 1063 // hoisted over such a scope. | 1060 // hoisted over such a scope. |
| 1064 void CheckConflictingVarDeclarations(Scope* scope, bool* ok); | 1061 void CheckConflictingVarDeclarations(Scope* scope, bool* ok); |
| 1065 | 1062 |
| 1066 // Insert initializer statements for var-bindings shadowing parameter bindings | 1063 // Insert initializer statements for var-bindings shadowing parameter bindings |
| 1067 // from a non-simple parameter list. | 1064 // from a non-simple parameter list. |
| 1068 void InsertShadowingVarBindingInitializers(Block* block); | 1065 void InsertShadowingVarBindingInitializers(Block* block); |
| 1069 | 1066 |
| 1070 // Implement sloppy block-scoped functions, ES2015 Annex B 3.3 | 1067 // Implement sloppy block-scoped functions, ES2015 Annex B 3.3 |
| 1071 void InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope, | 1068 void InsertSloppyBlockFunctionVarBindings(Scope* scope, |
| 1072 Scope* complex_params_scope, | 1069 Scope* complex_params_scope, |
| 1073 bool* ok); | 1070 bool* ok); |
| 1074 | 1071 |
| 1075 // Parser support | 1072 // Parser support |
| 1076 VariableProxy* NewUnresolved(const AstRawString* name, VariableMode mode); | 1073 VariableProxy* NewUnresolved(const AstRawString* name, VariableMode mode); |
| 1077 Variable* Declare(Declaration* declaration, | 1074 Variable* Declare(Declaration* declaration, |
| 1078 DeclarationDescriptor::Kind declaration_kind, bool resolve, | 1075 DeclarationDescriptor::Kind declaration_kind, bool resolve, |
| 1079 bool* ok, Scope* declaration_scope = nullptr); | 1076 bool* ok, Scope* declaration_scope = nullptr); |
| 1080 void DeclareImport(const AstRawString* local_name, int pos, bool* ok); | 1077 void DeclareImport(const AstRawString* local_name, int pos, bool* ok); |
| 1081 | 1078 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 } | 1180 } |
| 1184 | 1181 |
| 1185 Scope* ParserTraits::NewScopeWithParent(Scope* parent, ScopeType scope_type) { | 1182 Scope* ParserTraits::NewScopeWithParent(Scope* parent, ScopeType scope_type) { |
| 1186 return parser_->NewScopeWithParent(parent, scope_type); | 1183 return parser_->NewScopeWithParent(parent, scope_type); |
| 1187 } | 1184 } |
| 1188 | 1185 |
| 1189 Scope* ParserTraits::NewScope(ScopeType scope_type) { | 1186 Scope* ParserTraits::NewScope(ScopeType scope_type) { |
| 1190 return parser_->NewScope(scope_type); | 1187 return parser_->NewScope(scope_type); |
| 1191 } | 1188 } |
| 1192 | 1189 |
| 1193 DeclarationScope* ParserTraits::NewFunctionScope(FunctionKind kind) { | 1190 Scope* ParserTraits::NewFunctionScope(FunctionKind kind) { |
| 1194 return parser_->NewFunctionScope(kind); | 1191 return parser_->NewFunctionScope(kind); |
| 1195 } | 1192 } |
| 1196 | 1193 |
| 1197 const AstRawString* ParserTraits::EmptyIdentifierString() { | 1194 const AstRawString* ParserTraits::EmptyIdentifierString() { |
| 1198 return parser_->ast_value_factory()->empty_string(); | 1195 return parser_->ast_value_factory()->empty_string(); |
| 1199 } | 1196 } |
| 1200 | 1197 |
| 1201 | 1198 |
| 1202 void ParserTraits::SkipLazyFunctionBody(int* materialized_literal_count, | 1199 void ParserTraits::SkipLazyFunctionBody(int* materialized_literal_count, |
| 1203 int* expected_property_count, bool* ok, | 1200 int* expected_property_count, bool* ok, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; | 1296 bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; |
| 1300 const AstRawString* name = is_simple | 1297 const AstRawString* name = is_simple |
| 1301 ? pattern->AsVariableProxy()->raw_name() | 1298 ? pattern->AsVariableProxy()->raw_name() |
| 1302 : parser_->ast_value_factory()->empty_string(); | 1299 : parser_->ast_value_factory()->empty_string(); |
| 1303 parameters->params.Add( | 1300 parameters->params.Add( |
| 1304 ParserFormalParameters::Parameter(name, pattern, initializer, | 1301 ParserFormalParameters::Parameter(name, pattern, initializer, |
| 1305 initializer_end_position, is_rest), | 1302 initializer_end_position, is_rest), |
| 1306 parameters->scope->zone()); | 1303 parameters->scope->zone()); |
| 1307 } | 1304 } |
| 1308 | 1305 |
| 1306 |
| 1309 void ParserTraits::DeclareFormalParameter( | 1307 void ParserTraits::DeclareFormalParameter( |
| 1310 DeclarationScope* scope, const ParserFormalParameters::Parameter& parameter, | 1308 Scope* scope, const ParserFormalParameters::Parameter& parameter, |
| 1311 Type::ExpressionClassifier* classifier) { | 1309 Type::ExpressionClassifier* classifier) { |
| 1312 bool is_duplicate = false; | 1310 bool is_duplicate = false; |
| 1313 bool is_simple = classifier->is_simple_parameter_list(); | 1311 bool is_simple = classifier->is_simple_parameter_list(); |
| 1314 auto name = is_simple || parameter.is_rest | 1312 auto name = is_simple || parameter.is_rest |
| 1315 ? parameter.name | 1313 ? parameter.name |
| 1316 : parser_->ast_value_factory()->empty_string(); | 1314 : parser_->ast_value_factory()->empty_string(); |
| 1317 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; | 1315 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; |
| 1318 if (!is_simple) scope->SetHasNonSimpleParameters(); | 1316 if (!is_simple) scope->SetHasNonSimpleParameters(); |
| 1319 bool is_optional = parameter.initializer != nullptr; | 1317 bool is_optional = parameter.initializer != nullptr; |
| 1320 Variable* var = | 1318 Variable* var = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 | 1354 |
| 1357 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { | 1355 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { |
| 1358 return parser_->ParseDoExpression(ok); | 1356 return parser_->ParseDoExpression(ok); |
| 1359 } | 1357 } |
| 1360 | 1358 |
| 1361 | 1359 |
| 1362 } // namespace internal | 1360 } // namespace internal |
| 1363 } // namespace v8 | 1361 } // namespace v8 |
| 1364 | 1362 |
| 1365 #endif // V8_PARSING_PARSER_H_ | 1363 #endif // V8_PARSING_PARSER_H_ |
| OLD | NEW |