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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 const AstRawString* local_name; | 260 const AstRawString* local_name; |
261 const Scanner::Location location; | 261 const Scanner::Location location; |
262 NamedImport(const AstRawString* import_name, const AstRawString* local_name, | 262 NamedImport(const AstRawString* import_name, const AstRawString* local_name, |
263 Scanner::Location location) | 263 Scanner::Location location) |
264 : import_name(import_name), | 264 : import_name(import_name), |
265 local_name(local_name), | 265 local_name(local_name), |
266 location(location) {} | 266 location(location) {} |
267 }; | 267 }; |
268 ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok); | 268 ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok); |
269 Statement* ParseFunctionDeclaration(bool* ok); | 269 Statement* ParseFunctionDeclaration(bool* ok); |
270 Statement* ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, | |
271 bool default_export, bool* ok); | |
272 Statement* ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, | |
273 ZoneList<const AstRawString*>* names, | |
274 bool default_export, bool* ok); | |
275 Statement* ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, | 270 Statement* ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, |
276 bool default_export, bool* ok); | 271 bool default_export, bool* ok); |
277 Expression* ParseAsyncFunctionExpression(bool* ok); | 272 Expression* ParseAsyncFunctionExpression(bool* ok); |
278 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 273 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
279 bool default_export, bool* ok); | 274 bool default_export, bool* ok); |
280 Statement* ParseNativeDeclaration(bool* ok); | 275 Statement* ParseNativeDeclaration(bool* ok); |
281 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, | 276 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, |
282 ZoneList<const AstRawString*>* names, | 277 ZoneList<const AstRawString*>* names, |
283 bool* ok); | 278 bool* ok); |
284 void DeclareAndInitializeVariables( | 279 void DeclareAndInitializeVariables( |
285 Block* block, const DeclarationDescriptor* declaration_descriptor, | 280 Block* block, const DeclarationDescriptor* declaration_descriptor, |
286 const DeclarationParsingResult::Declaration* declaration, | 281 const DeclarationParsingResult::Declaration* declaration, |
287 ZoneList<const AstRawString*>* names, bool* ok); | 282 ZoneList<const AstRawString*>* names, bool* ok); |
288 | 283 |
| 284 Statement* DeclareFunction(const AstRawString* variable_name, |
| 285 FunctionLiteral* function, int pos, |
| 286 bool is_generator, bool is_async, |
| 287 ZoneList<const AstRawString*>* names, bool* ok); |
| 288 |
289 DoExpression* ParseDoExpression(bool* ok); | 289 DoExpression* ParseDoExpression(bool* ok); |
290 Expression* ParseYieldStarExpression(bool* ok); | 290 Expression* ParseYieldStarExpression(bool* ok); |
291 | 291 |
292 class PatternRewriter final : public AstVisitor<PatternRewriter> { | 292 class PatternRewriter final : public AstVisitor<PatternRewriter> { |
293 public: | 293 public: |
294 static void DeclareAndInitializeVariables( | 294 static void DeclareAndInitializeVariables( |
295 Parser* parser, Block* block, | 295 Parser* parser, Block* block, |
296 const DeclarationDescriptor* declaration_descriptor, | 296 const DeclarationDescriptor* declaration_descriptor, |
297 const DeclarationParsingResult::Declaration* declaration, | 297 const DeclarationParsingResult::Declaration* declaration, |
298 ZoneList<const AstRawString*>* names, bool* ok); | 298 ZoneList<const AstRawString*>* names, bool* ok); |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 if (e_stat == nullptr) return false; | 692 if (e_stat == nullptr) return false; |
693 Literal* literal = e_stat->expression()->AsLiteral(); | 693 Literal* literal = e_stat->expression()->AsLiteral(); |
694 if (literal == nullptr || !literal->raw_value()->IsString()) return false; | 694 if (literal == nullptr || !literal->raw_value()->IsString()) return false; |
695 return arg == nullptr || literal->raw_value()->AsString() == arg; | 695 return arg == nullptr || literal->raw_value()->AsString() == arg; |
696 } | 696 } |
697 | 697 |
698 V8_INLINE static Expression* GetPropertyValue(LiteralProperty* property) { | 698 V8_INLINE static Expression* GetPropertyValue(LiteralProperty* property) { |
699 return property->value(); | 699 return property->value(); |
700 } | 700 } |
701 | 701 |
| 702 V8_INLINE void GetDefaultStrings( |
| 703 const AstRawString** default_string, |
| 704 const AstRawString** star_default_star_string) { |
| 705 *default_string = ast_value_factory()->default_string(); |
| 706 *star_default_star_string = ast_value_factory()->star_default_star_string(); |
| 707 } |
| 708 |
702 // Functions for encapsulating the differences between parsing and preparsing; | 709 // Functions for encapsulating the differences between parsing and preparsing; |
703 // operations interleaved with the recursive descent. | 710 // operations interleaved with the recursive descent. |
704 V8_INLINE void PushLiteralName(const AstRawString* id) { | 711 V8_INLINE void PushLiteralName(const AstRawString* id) { |
705 DCHECK_NOT_NULL(fni_); | 712 DCHECK_NOT_NULL(fni_); |
706 fni_->PushLiteralName(id); | 713 fni_->PushLiteralName(id); |
707 } | 714 } |
708 | 715 |
709 V8_INLINE void PushVariableName(const AstRawString* id) { | 716 V8_INLINE void PushVariableName(const AstRawString* id) { |
710 DCHECK_NOT_NULL(fni_); | 717 DCHECK_NOT_NULL(fni_); |
711 fni_->PushVariableName(id); | 718 fni_->PushVariableName(id); |
712 } | 719 } |
713 | 720 |
714 V8_INLINE void PushPropertyName(Expression* expression) { | 721 V8_INLINE void PushPropertyName(Expression* expression) { |
715 DCHECK_NOT_NULL(fni_); | 722 DCHECK_NOT_NULL(fni_); |
716 if (expression->IsPropertyName()) { | 723 if (expression->IsPropertyName()) { |
717 fni_->PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); | 724 fni_->PushLiteralName(expression->AsLiteral()->AsRawPropertyName()); |
718 } else { | 725 } else { |
719 fni_->PushLiteralName(ast_value_factory()->anonymous_function_string()); | 726 fni_->PushLiteralName(ast_value_factory()->anonymous_function_string()); |
720 } | 727 } |
721 } | 728 } |
722 | 729 |
| 730 V8_INLINE void PushEnclosingName(const AstRawString* name) { |
| 731 DCHECK_NOT_NULL(fni_); |
| 732 fni_->PushEnclosingName(name); |
| 733 } |
| 734 |
723 V8_INLINE void InferFunctionName(FunctionLiteral* func_to_infer) { | 735 V8_INLINE void InferFunctionName(FunctionLiteral* func_to_infer) { |
724 fni_->AddFunction(func_to_infer); | 736 fni_->AddFunction(func_to_infer); |
725 } | 737 } |
726 | 738 |
727 // If we assign a function literal to a property we pretenure the | 739 // If we assign a function literal to a property we pretenure the |
728 // literal so it can be added as a constant function property. | 740 // literal so it can be added as a constant function property. |
729 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( | 741 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( |
730 Expression* left, Expression* right) { | 742 Expression* left, Expression* right) { |
731 DCHECK(left != NULL); | 743 DCHECK(left != NULL); |
732 if (left->IsProperty() && right->IsFunctionLiteral()) { | 744 if (left->IsProperty() && right->IsFunctionLiteral()) { |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 | 1061 |
1050 #ifdef DEBUG | 1062 #ifdef DEBUG |
1051 void Print(AstNode* node); | 1063 void Print(AstNode* node); |
1052 #endif // DEBUG | 1064 #endif // DEBUG |
1053 }; | 1065 }; |
1054 | 1066 |
1055 } // namespace internal | 1067 } // namespace internal |
1056 } // namespace v8 | 1068 } // namespace v8 |
1057 | 1069 |
1058 #endif // V8_PARSING_PARSER_H_ | 1070 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |