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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 void set_extension(v8::Extension* extension) { extension_ = extension; } | 94 void set_extension(v8::Extension* extension) { extension_ = extension; } |
95 | 95 |
96 ScriptData** cached_data() { return cached_data_; } | 96 ScriptData** cached_data() { return cached_data_; } |
97 void set_cached_data(ScriptData** cached_data) { cached_data_ = cached_data; } | 97 void set_cached_data(ScriptData** cached_data) { cached_data_ = cached_data; } |
98 | 98 |
99 ScriptCompiler::CompileOptions compile_options() { return compile_options_; } | 99 ScriptCompiler::CompileOptions compile_options() { return compile_options_; } |
100 void set_compile_options(ScriptCompiler::CompileOptions compile_options) { | 100 void set_compile_options(ScriptCompiler::CompileOptions compile_options) { |
101 compile_options_ = compile_options; | 101 compile_options_ = compile_options; |
102 } | 102 } |
103 | 103 |
104 Scope* script_scope() { return script_scope_; } | 104 DeclarationScope* script_scope() { return script_scope_; } |
105 void set_script_scope(Scope* script_scope) { script_scope_ = script_scope; } | 105 void set_script_scope(DeclarationScope* script_scope) { |
| 106 script_scope_ = script_scope; |
| 107 } |
106 | 108 |
107 AstValueFactory* ast_value_factory() { return ast_value_factory_; } | 109 AstValueFactory* ast_value_factory() { return ast_value_factory_; } |
108 void set_ast_value_factory(AstValueFactory* ast_value_factory) { | 110 void set_ast_value_factory(AstValueFactory* ast_value_factory) { |
109 ast_value_factory_ = ast_value_factory; | 111 ast_value_factory_ = ast_value_factory; |
110 } | 112 } |
111 | 113 |
112 FunctionLiteral* literal() { return literal_; } | 114 FunctionLiteral* literal() { return literal_; } |
113 void set_literal(FunctionLiteral* literal) { literal_ = literal; } | 115 void set_literal(FunctionLiteral* literal) { literal_ = literal; } |
114 | 116 |
115 Scope* scope() { return scope_; } | 117 DeclarationScope* scope() { return scope_; } |
116 void set_scope(Scope* scope) { scope_ = scope; } | 118 void set_scope(DeclarationScope* scope) { scope_ = scope; } |
117 | 119 |
118 UnicodeCache* unicode_cache() { return unicode_cache_; } | 120 UnicodeCache* unicode_cache() { return unicode_cache_; } |
119 void set_unicode_cache(UnicodeCache* unicode_cache) { | 121 void set_unicode_cache(UnicodeCache* unicode_cache) { |
120 unicode_cache_ = unicode_cache; | 122 unicode_cache_ = unicode_cache; |
121 } | 123 } |
122 | 124 |
123 uintptr_t stack_limit() { return stack_limit_; } | 125 uintptr_t stack_limit() { return stack_limit_; } |
124 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } | 126 void set_stack_limit(uintptr_t stack_limit) { stack_limit_ = stack_limit; } |
125 | 127 |
126 uint32_t hash_seed() { return hash_seed_; } | 128 uint32_t hash_seed() { return hash_seed_; } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 }; | 178 }; |
177 | 179 |
178 //------------- Inputs to parsing and scope analysis ----------------------- | 180 //------------- Inputs to parsing and scope analysis ----------------------- |
179 Zone* zone_; | 181 Zone* zone_; |
180 unsigned flags_; | 182 unsigned flags_; |
181 ScriptCompiler::ExternalSourceStream* source_stream_; | 183 ScriptCompiler::ExternalSourceStream* source_stream_; |
182 ScriptCompiler::StreamedSource::Encoding source_stream_encoding_; | 184 ScriptCompiler::StreamedSource::Encoding source_stream_encoding_; |
183 Utf16CharacterStream* character_stream_; | 185 Utf16CharacterStream* character_stream_; |
184 v8::Extension* extension_; | 186 v8::Extension* extension_; |
185 ScriptCompiler::CompileOptions compile_options_; | 187 ScriptCompiler::CompileOptions compile_options_; |
186 Scope* script_scope_; | 188 DeclarationScope* script_scope_; |
187 UnicodeCache* unicode_cache_; | 189 UnicodeCache* unicode_cache_; |
188 uintptr_t stack_limit_; | 190 uintptr_t stack_limit_; |
189 uint32_t hash_seed_; | 191 uint32_t hash_seed_; |
190 | 192 |
191 // TODO(titzer): Move handles and isolate out of ParseInfo. | 193 // TODO(titzer): Move handles and isolate out of ParseInfo. |
192 Isolate* isolate_; | 194 Isolate* isolate_; |
193 Handle<SharedFunctionInfo> shared_; | 195 Handle<SharedFunctionInfo> shared_; |
194 Handle<Script> script_; | 196 Handle<Script> script_; |
195 Handle<Context> context_; | 197 Handle<Context> context_; |
196 | 198 |
197 //----------- Inputs+Outputs of parsing and scope analysis ----------------- | 199 //----------- Inputs+Outputs of parsing and scope analysis ----------------- |
198 ScriptData** cached_data_; // used if available, populated if requested. | 200 ScriptData** cached_data_; // used if available, populated if requested. |
199 AstValueFactory* ast_value_factory_; // used if available, otherwise new. | 201 AstValueFactory* ast_value_factory_; // used if available, otherwise new. |
200 | 202 |
201 //----------- Outputs of parsing and scope analysis ------------------------ | 203 //----------- Outputs of parsing and scope analysis ------------------------ |
202 FunctionLiteral* literal_; // produced by full parser. | 204 FunctionLiteral* literal_; // produced by full parser. |
203 Scope* scope_; // produced by scope analysis. | 205 DeclarationScope* scope_; // produced by scope analysis. |
204 | 206 |
205 void SetFlag(Flag f) { flags_ |= f; } | 207 void SetFlag(Flag f) { flags_ |= f; } |
206 void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; } | 208 void SetFlag(Flag f, bool v) { flags_ = v ? flags_ | f : flags_ & ~f; } |
207 bool GetFlag(Flag f) const { return (flags_ & f) != 0; } | 209 bool GetFlag(Flag f) const { return (flags_ & f) != 0; } |
208 }; | 210 }; |
209 | 211 |
210 class FunctionEntry BASE_EMBEDDED { | 212 class FunctionEntry BASE_EMBEDDED { |
211 public: | 213 public: |
212 enum { | 214 enum { |
213 kStartPositionIndex, | 215 kStartPositionIndex, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 const AstRawString* name; | 308 const AstRawString* name; |
307 Expression* pattern; | 309 Expression* pattern; |
308 Expression* initializer; | 310 Expression* initializer; |
309 int initializer_end_position; | 311 int initializer_end_position; |
310 bool is_rest; | 312 bool is_rest; |
311 bool is_simple() const { | 313 bool is_simple() const { |
312 return pattern->IsVariableProxy() && initializer == nullptr && !is_rest; | 314 return pattern->IsVariableProxy() && initializer == nullptr && !is_rest; |
313 } | 315 } |
314 }; | 316 }; |
315 | 317 |
316 explicit ParserFormalParameters(Scope* scope) | 318 explicit ParserFormalParameters(DeclarationScope* scope) |
317 : FormalParametersBase(scope), params(4, scope->zone()) {} | 319 : FormalParametersBase(scope), params(4, scope->zone()) {} |
318 ZoneList<Parameter> params; | 320 ZoneList<Parameter> params; |
319 | 321 |
320 int Arity() const { return params.length(); } | 322 int Arity() const { return params.length(); } |
321 const Parameter& at(int i) const { return params[i]; } | 323 const Parameter& at(int i) const { return params[i]; } |
322 }; | 324 }; |
323 | 325 |
324 | 326 |
325 class ParserTraits { | 327 class ParserTraits { |
326 public: | 328 public: |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 544 |
543 V8_INLINE void AddParameterInitializationBlock( | 545 V8_INLINE void AddParameterInitializationBlock( |
544 const ParserFormalParameters& parameters, | 546 const ParserFormalParameters& parameters, |
545 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); | 547 ZoneList<v8::internal::Statement*>* body, bool is_async, bool* ok); |
546 | 548 |
547 void ParseAsyncArrowSingleExpressionBody( | 549 void ParseAsyncArrowSingleExpressionBody( |
548 ZoneList<Statement*>* body, bool accept_IN, | 550 ZoneList<Statement*>* body, bool accept_IN, |
549 Type::ExpressionClassifier* classifier, int pos, bool* ok); | 551 Type::ExpressionClassifier* classifier, int pos, bool* ok); |
550 | 552 |
551 V8_INLINE Scope* NewScope(ScopeType scope_type); | 553 V8_INLINE Scope* NewScope(ScopeType scope_type); |
552 V8_INLINE Scope* NewFunctionScope(FunctionKind kind); | 554 V8_INLINE DeclarationScope* NewFunctionScope(FunctionKind kind); |
553 V8_INLINE Scope* NewScopeWithParent(Scope* parent, ScopeType scope_type); | 555 V8_INLINE Scope* NewScopeWithParent(Scope* parent, ScopeType scope_type); |
554 | 556 |
555 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, | 557 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, |
556 Expression* pattern, | 558 Expression* pattern, |
557 Expression* initializer, | 559 Expression* initializer, |
558 int initializer_end_position, bool is_rest); | 560 int initializer_end_position, bool is_rest); |
559 V8_INLINE void DeclareFormalParameter( | 561 V8_INLINE void DeclareFormalParameter( |
560 Scope* scope, const ParserFormalParameters::Parameter& parameter, | 562 DeclarationScope* scope, |
| 563 const ParserFormalParameters::Parameter& parameter, |
561 Type::ExpressionClassifier* classifier); | 564 Type::ExpressionClassifier* classifier); |
562 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, | 565 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, |
563 Expression* params, int end_pos, | 566 Expression* params, int end_pos, |
564 bool* ok); | 567 bool* ok); |
565 void ParseArrowFunctionFormalParameterList( | 568 void ParseArrowFunctionFormalParameterList( |
566 ParserFormalParameters* parameters, Expression* params, | 569 ParserFormalParameters* parameters, Expression* params, |
567 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, | 570 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, |
568 const Scope::Snapshot& scope_snapshot, bool* ok); | 571 const Scope::Snapshot& scope_snapshot, bool* ok); |
569 | 572 |
570 V8_INLINE Expression* ParseAsyncFunctionExpression(bool* ok); | 573 V8_INLINE Expression* ParseAsyncFunctionExpression(bool* ok); |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 // The var declarations are hoisted to the function scope, but originate from | 1029 // The var declarations are hoisted to the function scope, but originate from |
1027 // a scope where the name has also been let bound or the var declaration is | 1030 // a scope where the name has also been let bound or the var declaration is |
1028 // hoisted over such a scope. | 1031 // hoisted over such a scope. |
1029 void CheckConflictingVarDeclarations(Scope* scope, bool* ok); | 1032 void CheckConflictingVarDeclarations(Scope* scope, bool* ok); |
1030 | 1033 |
1031 // Insert initializer statements for var-bindings shadowing parameter bindings | 1034 // Insert initializer statements for var-bindings shadowing parameter bindings |
1032 // from a non-simple parameter list. | 1035 // from a non-simple parameter list. |
1033 void InsertShadowingVarBindingInitializers(Block* block); | 1036 void InsertShadowingVarBindingInitializers(Block* block); |
1034 | 1037 |
1035 // Implement sloppy block-scoped functions, ES2015 Annex B 3.3 | 1038 // Implement sloppy block-scoped functions, ES2015 Annex B 3.3 |
1036 void InsertSloppyBlockFunctionVarBindings(Scope* scope, | 1039 void InsertSloppyBlockFunctionVarBindings(DeclarationScope* scope, |
1037 Scope* complex_params_scope, | 1040 Scope* complex_params_scope, |
1038 bool* ok); | 1041 bool* ok); |
1039 | 1042 |
1040 // Parser support | 1043 // Parser support |
1041 VariableProxy* NewUnresolved(const AstRawString* name, VariableMode mode); | 1044 VariableProxy* NewUnresolved(const AstRawString* name, VariableMode mode); |
1042 Variable* Declare(Declaration* declaration, | 1045 Variable* Declare(Declaration* declaration, |
1043 DeclarationDescriptor::Kind declaration_kind, bool resolve, | 1046 DeclarationDescriptor::Kind declaration_kind, bool resolve, |
1044 bool* ok, Scope* declaration_scope = nullptr); | 1047 bool* ok, Scope* declaration_scope = nullptr); |
1045 void DeclareImport(const AstRawString* local_name, int pos, bool* ok); | 1048 void DeclareImport(const AstRawString* local_name, int pos, bool* ok); |
1046 | 1049 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 } | 1151 } |
1149 | 1152 |
1150 Scope* ParserTraits::NewScopeWithParent(Scope* parent, ScopeType scope_type) { | 1153 Scope* ParserTraits::NewScopeWithParent(Scope* parent, ScopeType scope_type) { |
1151 return parser_->NewScopeWithParent(parent, scope_type); | 1154 return parser_->NewScopeWithParent(parent, scope_type); |
1152 } | 1155 } |
1153 | 1156 |
1154 Scope* ParserTraits::NewScope(ScopeType scope_type) { | 1157 Scope* ParserTraits::NewScope(ScopeType scope_type) { |
1155 return parser_->NewScope(scope_type); | 1158 return parser_->NewScope(scope_type); |
1156 } | 1159 } |
1157 | 1160 |
1158 Scope* ParserTraits::NewFunctionScope(FunctionKind kind) { | 1161 DeclarationScope* ParserTraits::NewFunctionScope(FunctionKind kind) { |
1159 return parser_->NewFunctionScope(kind); | 1162 return parser_->NewFunctionScope(kind); |
1160 } | 1163 } |
1161 | 1164 |
1162 const AstRawString* ParserTraits::EmptyIdentifierString() { | 1165 const AstRawString* ParserTraits::EmptyIdentifierString() { |
1163 return parser_->ast_value_factory()->empty_string(); | 1166 return parser_->ast_value_factory()->empty_string(); |
1164 } | 1167 } |
1165 | 1168 |
1166 | 1169 |
1167 void ParserTraits::SkipLazyFunctionBody(int* materialized_literal_count, | 1170 void ParserTraits::SkipLazyFunctionBody(int* materialized_literal_count, |
1168 int* expected_property_count, bool* ok, | 1171 int* expected_property_count, bool* ok, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; | 1267 bool is_simple = pattern->IsVariableProxy() && initializer == nullptr; |
1265 const AstRawString* name = is_simple | 1268 const AstRawString* name = is_simple |
1266 ? pattern->AsVariableProxy()->raw_name() | 1269 ? pattern->AsVariableProxy()->raw_name() |
1267 : parser_->ast_value_factory()->empty_string(); | 1270 : parser_->ast_value_factory()->empty_string(); |
1268 parameters->params.Add( | 1271 parameters->params.Add( |
1269 ParserFormalParameters::Parameter(name, pattern, initializer, | 1272 ParserFormalParameters::Parameter(name, pattern, initializer, |
1270 initializer_end_position, is_rest), | 1273 initializer_end_position, is_rest), |
1271 parameters->scope->zone()); | 1274 parameters->scope->zone()); |
1272 } | 1275 } |
1273 | 1276 |
1274 | |
1275 void ParserTraits::DeclareFormalParameter( | 1277 void ParserTraits::DeclareFormalParameter( |
1276 Scope* scope, const ParserFormalParameters::Parameter& parameter, | 1278 DeclarationScope* scope, const ParserFormalParameters::Parameter& parameter, |
1277 Type::ExpressionClassifier* classifier) { | 1279 Type::ExpressionClassifier* classifier) { |
1278 bool is_duplicate = false; | 1280 bool is_duplicate = false; |
1279 bool is_simple = classifier->is_simple_parameter_list(); | 1281 bool is_simple = classifier->is_simple_parameter_list(); |
1280 auto name = is_simple || parameter.is_rest | 1282 auto name = is_simple || parameter.is_rest |
1281 ? parameter.name | 1283 ? parameter.name |
1282 : parser_->ast_value_factory()->empty_string(); | 1284 : parser_->ast_value_factory()->empty_string(); |
1283 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; | 1285 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; |
1284 if (!is_simple) scope->SetHasNonSimpleParameters(); | 1286 if (!is_simple) scope->SetHasNonSimpleParameters(); |
1285 bool is_optional = parameter.initializer != nullptr; | 1287 bool is_optional = parameter.initializer != nullptr; |
1286 Variable* var = | 1288 Variable* var = |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 | 1324 |
1323 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { | 1325 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { |
1324 return parser_->ParseDoExpression(ok); | 1326 return parser_->ParseDoExpression(ok); |
1325 } | 1327 } |
1326 | 1328 |
1327 | 1329 |
1328 } // namespace internal | 1330 } // namespace internal |
1329 } // namespace v8 | 1331 } // namespace v8 |
1330 | 1332 |
1331 #endif // V8_PARSING_PARSER_H_ | 1333 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |