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/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/parsing/parser-base.h" | 10 #include "src/parsing/parser-base.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 typedef v8::internal::Variable Variable; | 146 typedef v8::internal::Variable Variable; |
147 | 147 |
148 // Return types for traversing functions. | 148 // Return types for traversing functions. |
149 typedef const AstRawString* Identifier; | 149 typedef const AstRawString* Identifier; |
150 typedef v8::internal::Expression* Expression; | 150 typedef v8::internal::Expression* Expression; |
151 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 151 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
152 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 152 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
153 typedef ClassLiteral::Property* ClassLiteralProperty; | 153 typedef ClassLiteral::Property* ClassLiteralProperty; |
154 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 154 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
155 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 155 typedef ZoneList<ObjectLiteral::Property*>* ObjectPropertyList; |
| 156 typedef ZoneList<ClassLiteral::Property*>* ClassPropertyList; |
156 typedef ParserFormalParameters FormalParameters; | 157 typedef ParserFormalParameters FormalParameters; |
157 typedef v8::internal::Statement* Statement; | 158 typedef v8::internal::Statement* Statement; |
158 typedef ZoneList<v8::internal::Statement*>* StatementList; | 159 typedef ZoneList<v8::internal::Statement*>* StatementList; |
159 typedef v8::internal::Block* Block; | 160 typedef v8::internal::Block* Block; |
160 typedef v8::internal::BreakableStatement* BreakableStatement; | 161 typedef v8::internal::BreakableStatement* BreakableStatement; |
161 typedef v8::internal::IterationStatement* IterationStatement; | 162 typedef v8::internal::IterationStatement* IterationStatement; |
162 | 163 |
163 // For constructing objects returned by the traversing functions. | 164 // For constructing objects returned by the traversing functions. |
164 typedef AstNodeFactory Factory; | 165 typedef AstNodeFactory Factory; |
165 | 166 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 Scanner::Location location) | 268 Scanner::Location location) |
268 : import_name(import_name), | 269 : import_name(import_name), |
269 local_name(local_name), | 270 local_name(local_name), |
270 location(location) {} | 271 location(location) {} |
271 }; | 272 }; |
272 ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok); | 273 ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok); |
273 Statement* ParseFunctionDeclaration(bool* ok); | 274 Statement* ParseFunctionDeclaration(bool* ok); |
274 Statement* ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, | 275 Statement* ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, |
275 bool default_export, bool* ok); | 276 bool default_export, bool* ok); |
276 Expression* ParseAsyncFunctionExpression(bool* ok); | 277 Expression* ParseAsyncFunctionExpression(bool* ok); |
277 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, | |
278 bool default_export, bool* ok); | |
279 Statement* ParseNativeDeclaration(bool* ok); | |
280 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, | 278 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, |
281 ZoneList<const AstRawString*>* names, | 279 ZoneList<const AstRawString*>* names, |
282 bool* ok); | 280 bool* ok); |
283 void DeclareAndInitializeVariables( | 281 void DeclareAndInitializeVariables( |
284 Block* block, const DeclarationDescriptor* declaration_descriptor, | 282 Block* block, const DeclarationDescriptor* declaration_descriptor, |
285 const DeclarationParsingResult::Declaration* declaration, | 283 const DeclarationParsingResult::Declaration* declaration, |
286 ZoneList<const AstRawString*>* names, bool* ok); | 284 ZoneList<const AstRawString*>* names, bool* ok); |
287 ZoneList<const AstRawString*>* DeclareLabel( | 285 ZoneList<const AstRawString*>* DeclareLabel( |
288 ZoneList<const AstRawString*>* labels, VariableProxy* expr, bool* ok); | 286 ZoneList<const AstRawString*>* labels, VariableProxy* expr, bool* ok); |
289 bool ContainsLabel(ZoneList<const AstRawString*>* labels, | 287 bool ContainsLabel(ZoneList<const AstRawString*>* labels, |
290 const AstRawString* label); | 288 const AstRawString* label); |
291 Expression* RewriteReturn(Expression* return_value, int pos); | 289 Expression* RewriteReturn(Expression* return_value, int pos); |
292 Statement* RewriteSwitchStatement(Expression* tag, | 290 Statement* RewriteSwitchStatement(Expression* tag, |
293 SwitchStatement* switch_statement, | 291 SwitchStatement* switch_statement, |
294 ZoneList<CaseClause*>* cases, Scope* scope); | 292 ZoneList<CaseClause*>* cases, Scope* scope); |
295 void RewriteCatchPattern(CatchInfo* catch_info, bool* ok); | 293 void RewriteCatchPattern(CatchInfo* catch_info, bool* ok); |
296 void ValidateCatchBlock(const CatchInfo& catch_info, bool* ok); | 294 void ValidateCatchBlock(const CatchInfo& catch_info, bool* ok); |
297 Statement* RewriteTryStatement(Block* try_block, Block* catch_block, | 295 Statement* RewriteTryStatement(Block* try_block, Block* catch_block, |
298 Block* finally_block, | 296 Block* finally_block, |
299 const CatchInfo& catch_info, int pos); | 297 const CatchInfo& catch_info, int pos); |
300 | 298 |
301 Statement* DeclareFunction(const AstRawString* variable_name, | 299 Statement* DeclareFunction(const AstRawString* variable_name, |
302 FunctionLiteral* function, int pos, | 300 FunctionLiteral* function, int pos, |
303 bool is_generator, bool is_async, | 301 bool is_generator, bool is_async, |
304 ZoneList<const AstRawString*>* names, bool* ok); | 302 ZoneList<const AstRawString*>* names, bool* ok); |
| 303 V8_INLINE Statement* DeclareClass(const AstRawString* variable_name, |
| 304 Expression* value, |
| 305 ZoneList<const AstRawString*>* names, |
| 306 int class_token_pos, bool* ok); |
| 307 V8_INLINE void DeclareClassVariable(const AstRawString* name, |
| 308 Scope* block_scope, ClassInfo* class_info, |
| 309 int class_token_pos, bool* ok); |
| 310 V8_INLINE void DeclareClassProperty(const AstRawString* class_name, |
| 311 ClassLiteralProperty* property, |
| 312 ClassInfo* class_info, bool* ok); |
| 313 V8_INLINE Expression* RewriteClassLiteral(const AstRawString* name, |
| 314 ClassInfo* class_info, int pos, |
| 315 bool* ok); |
| 316 V8_INLINE Statement* DeclareNative(const AstRawString* name, int pos, |
| 317 bool* ok); |
305 | 318 |
306 Expression* ParseYieldStarExpression(bool* ok); | 319 Expression* ParseYieldStarExpression(bool* ok); |
307 | 320 |
308 class PatternRewriter final : public AstVisitor<PatternRewriter> { | 321 class PatternRewriter final : public AstVisitor<PatternRewriter> { |
309 public: | 322 public: |
310 static void DeclareAndInitializeVariables( | 323 static void DeclareAndInitializeVariables( |
311 Parser* parser, Block* block, | 324 Parser* parser, Block* block, |
312 const DeclarationDescriptor* declaration_descriptor, | 325 const DeclarationDescriptor* declaration_descriptor, |
313 const DeclarationParsingResult::Declaration* declaration, | 326 const DeclarationParsingResult::Declaration* declaration, |
314 ZoneList<const AstRawString*>* names, bool* ok); | 327 ZoneList<const AstRawString*>* names, bool* ok); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 const AstRawString* name, Scanner::Location function_name_location, | 434 const AstRawString* name, Scanner::Location function_name_location, |
422 FunctionNameValidity function_name_validity, FunctionKind kind, | 435 FunctionNameValidity function_name_validity, FunctionKind kind, |
423 int function_token_position, FunctionLiteral::FunctionType type, | 436 int function_token_position, FunctionLiteral::FunctionType type, |
424 LanguageMode language_mode, bool* ok); | 437 LanguageMode language_mode, bool* ok); |
425 | 438 |
426 Expression* InstallHomeObject(Expression* function_literal, | 439 Expression* InstallHomeObject(Expression* function_literal, |
427 Expression* home_object); | 440 Expression* home_object); |
428 FunctionLiteral* SynthesizeClassFieldInitializer(int count); | 441 FunctionLiteral* SynthesizeClassFieldInitializer(int count); |
429 FunctionLiteral* InsertClassFieldInitializer(FunctionLiteral* constructor); | 442 FunctionLiteral* InsertClassFieldInitializer(FunctionLiteral* constructor); |
430 | 443 |
431 Expression* ParseClassLiteral(const AstRawString* name, | |
432 Scanner::Location class_name_location, | |
433 bool name_is_strict_reserved, int pos, | |
434 bool* ok); | |
435 | |
436 // Get odd-ball literals. | 444 // Get odd-ball literals. |
437 Literal* GetLiteralUndefined(int position); | 445 Literal* GetLiteralUndefined(int position); |
438 | 446 |
439 // Check if the scope has conflicting var/let declarations from different | 447 // Check if the scope has conflicting var/let declarations from different |
440 // scopes. This covers for example | 448 // scopes. This covers for example |
441 // | 449 // |
442 // function f() { { { var x; } let x; } } | 450 // function f() { { { var x; } let x; } } |
443 // function g() { { var x; let x; } } | 451 // function g() { { var x; let x; } } |
444 // | 452 // |
445 // The var declarations are hoisted to the function scope, but originate from | 453 // The var declarations are hoisted to the function scope, but originate from |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 | 755 |
748 V8_INLINE void PushEnclosingName(const AstRawString* name) { | 756 V8_INLINE void PushEnclosingName(const AstRawString* name) { |
749 DCHECK_NOT_NULL(fni_); | 757 DCHECK_NOT_NULL(fni_); |
750 fni_->PushEnclosingName(name); | 758 fni_->PushEnclosingName(name); |
751 } | 759 } |
752 | 760 |
753 V8_INLINE void InferFunctionName(FunctionLiteral* func_to_infer) { | 761 V8_INLINE void InferFunctionName(FunctionLiteral* func_to_infer) { |
754 fni_->AddFunction(func_to_infer); | 762 fni_->AddFunction(func_to_infer); |
755 } | 763 } |
756 | 764 |
| 765 V8_INLINE void Infer() { |
| 766 DCHECK_NOT_NULL(fni_); |
| 767 fni_->Infer(); |
| 768 } |
| 769 |
757 // If we assign a function literal to a property we pretenure the | 770 // If we assign a function literal to a property we pretenure the |
758 // literal so it can be added as a constant function property. | 771 // literal so it can be added as a constant function property. |
759 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( | 772 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( |
760 Expression* left, Expression* right) { | 773 Expression* left, Expression* right) { |
761 DCHECK(left != NULL); | 774 DCHECK(left != NULL); |
762 if (left->IsProperty() && right->IsFunctionLiteral()) { | 775 if (left->IsProperty() && right->IsFunctionLiteral()) { |
763 right->AsFunctionLiteral()->set_pretenure(); | 776 right->AsFunctionLiteral()->set_pretenure(); |
764 } | 777 } |
765 } | 778 } |
766 | 779 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 | 953 |
941 V8_INLINE Expression* ExpressionFromString(int pos) { | 954 V8_INLINE Expression* ExpressionFromString(int pos) { |
942 const AstRawString* symbol = GetSymbol(); | 955 const AstRawString* symbol = GetSymbol(); |
943 fni_->PushLiteralName(symbol); | 956 fni_->PushLiteralName(symbol); |
944 return factory()->NewStringLiteral(symbol, pos); | 957 return factory()->NewStringLiteral(symbol, pos); |
945 } | 958 } |
946 | 959 |
947 V8_INLINE ZoneList<Expression*>* NewExpressionList(int size) const { | 960 V8_INLINE ZoneList<Expression*>* NewExpressionList(int size) const { |
948 return new (zone()) ZoneList<Expression*>(size, zone()); | 961 return new (zone()) ZoneList<Expression*>(size, zone()); |
949 } | 962 } |
950 V8_INLINE ZoneList<ObjectLiteral::Property*>* NewPropertyList( | 963 V8_INLINE ZoneList<ObjectLiteral::Property*>* NewObjectPropertyList( |
951 int size) const { | 964 int size) const { |
952 return new (zone()) ZoneList<ObjectLiteral::Property*>(size, zone()); | 965 return new (zone()) ZoneList<ObjectLiteral::Property*>(size, zone()); |
953 } | 966 } |
954 V8_INLINE ZoneList<ClassLiteral::Property*>* NewClassPropertyList( | 967 V8_INLINE ZoneList<ClassLiteral::Property*>* NewClassPropertyList( |
955 int size) const { | 968 int size) const { |
956 return new (zone()) ZoneList<ClassLiteral::Property*>(size, zone()); | 969 return new (zone()) ZoneList<ClassLiteral::Property*>(size, zone()); |
957 } | 970 } |
958 V8_INLINE ZoneList<Statement*>* NewStatementList(int size) const { | 971 V8_INLINE ZoneList<Statement*>* NewStatementList(int size) const { |
959 return new (zone()) ZoneList<Statement*>(size, zone()); | 972 return new (zone()) ZoneList<Statement*>(size, zone()); |
960 } | 973 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 int total_preparse_skipped_; | 1096 int total_preparse_skipped_; |
1084 HistogramTimer* pre_parse_timer_; | 1097 HistogramTimer* pre_parse_timer_; |
1085 | 1098 |
1086 bool parsing_on_main_thread_; | 1099 bool parsing_on_main_thread_; |
1087 }; | 1100 }; |
1088 | 1101 |
1089 } // namespace internal | 1102 } // namespace internal |
1090 } // namespace v8 | 1103 } // namespace v8 |
1091 | 1104 |
1092 #endif // V8_PARSING_PARSER_H_ | 1105 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |