Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: src/parsing/parser.h

Issue 2368083002: [parser] Refactor of ParseClass* and ParseNativeDeclaration (Closed)
Patch Set: Rebase again Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/parsing/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 const AstRawString* local_name; 263 const AstRawString* local_name;
263 const Scanner::Location location; 264 const Scanner::Location location;
264 NamedImport(const AstRawString* import_name, const AstRawString* local_name, 265 NamedImport(const AstRawString* import_name, const AstRawString* local_name,
265 Scanner::Location location) 266 Scanner::Location location)
266 : import_name(import_name), 267 : import_name(import_name),
267 local_name(local_name), 268 local_name(local_name),
268 location(location) {} 269 location(location) {}
269 }; 270 };
270 ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok); 271 ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok);
271 Statement* ParseFunctionDeclaration(bool* ok); 272 Statement* ParseFunctionDeclaration(bool* ok);
272 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names,
273 bool default_export, bool* ok);
274 Statement* ParseNativeDeclaration(bool* ok);
275 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, 273 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result,
276 ZoneList<const AstRawString*>* names, 274 ZoneList<const AstRawString*>* names,
277 bool* ok); 275 bool* ok);
278 void DeclareAndInitializeVariables( 276 void DeclareAndInitializeVariables(
279 Block* block, const DeclarationDescriptor* declaration_descriptor, 277 Block* block, const DeclarationDescriptor* declaration_descriptor,
280 const DeclarationParsingResult::Declaration* declaration, 278 const DeclarationParsingResult::Declaration* declaration,
281 ZoneList<const AstRawString*>* names, bool* ok); 279 ZoneList<const AstRawString*>* names, bool* ok);
282 ZoneList<const AstRawString*>* DeclareLabel( 280 ZoneList<const AstRawString*>* DeclareLabel(
283 ZoneList<const AstRawString*>* labels, VariableProxy* expr, bool* ok); 281 ZoneList<const AstRawString*>* labels, VariableProxy* expr, bool* ok);
284 bool ContainsLabel(ZoneList<const AstRawString*>* labels, 282 bool ContainsLabel(ZoneList<const AstRawString*>* labels,
285 const AstRawString* label); 283 const AstRawString* label);
286 Expression* RewriteReturn(Expression* return_value, int pos); 284 Expression* RewriteReturn(Expression* return_value, int pos);
287 Statement* RewriteSwitchStatement(Expression* tag, 285 Statement* RewriteSwitchStatement(Expression* tag,
288 SwitchStatement* switch_statement, 286 SwitchStatement* switch_statement,
289 ZoneList<CaseClause*>* cases, Scope* scope); 287 ZoneList<CaseClause*>* cases, Scope* scope);
290 void RewriteCatchPattern(CatchInfo* catch_info, bool* ok); 288 void RewriteCatchPattern(CatchInfo* catch_info, bool* ok);
291 void ValidateCatchBlock(const CatchInfo& catch_info, bool* ok); 289 void ValidateCatchBlock(const CatchInfo& catch_info, bool* ok);
292 Statement* RewriteTryStatement(Block* try_block, Block* catch_block, 290 Statement* RewriteTryStatement(Block* try_block, Block* catch_block,
293 Block* finally_block, 291 Block* finally_block,
294 const CatchInfo& catch_info, int pos); 292 const CatchInfo& catch_info, int pos);
295 293
296 Statement* DeclareFunction(const AstRawString* variable_name, 294 Statement* DeclareFunction(const AstRawString* variable_name,
297 FunctionLiteral* function, int pos, 295 FunctionLiteral* function, int pos,
298 bool is_generator, bool is_async, 296 bool is_generator, bool is_async,
299 ZoneList<const AstRawString*>* names, bool* ok); 297 ZoneList<const AstRawString*>* names, bool* ok);
298 V8_INLINE Statement* DeclareClass(const AstRawString* variable_name,
299 Expression* value,
300 ZoneList<const AstRawString*>* names,
301 int class_token_pos, int end_pos, bool* ok);
302 V8_INLINE void DeclareClassVariable(const AstRawString* name,
303 Scope* block_scope, ClassInfo* class_info,
304 int class_token_pos, bool* ok);
305 V8_INLINE void DeclareClassProperty(const AstRawString* class_name,
306 ClassLiteralProperty* property,
307 ClassInfo* class_info, bool* ok);
308 V8_INLINE Expression* RewriteClassLiteral(const AstRawString* name,
309 ClassInfo* class_info, int pos,
310 bool* ok);
311 V8_INLINE Statement* DeclareNative(const AstRawString* name, int pos,
312 bool* ok);
300 313
301 Expression* ParseYieldStarExpression(bool* ok); 314 Expression* ParseYieldStarExpression(bool* ok);
302 315
303 class PatternRewriter final : public AstVisitor<PatternRewriter> { 316 class PatternRewriter final : public AstVisitor<PatternRewriter> {
304 public: 317 public:
305 static void DeclareAndInitializeVariables( 318 static void DeclareAndInitializeVariables(
306 Parser* parser, Block* block, 319 Parser* parser, Block* block,
307 const DeclarationDescriptor* declaration_descriptor, 320 const DeclarationDescriptor* declaration_descriptor,
308 const DeclarationParsingResult::Declaration* declaration, 321 const DeclarationParsingResult::Declaration* declaration,
309 ZoneList<const AstRawString*>* names, bool* ok); 322 ZoneList<const AstRawString*>* names, bool* ok);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 const AstRawString* name, Scanner::Location function_name_location, 425 const AstRawString* name, Scanner::Location function_name_location,
413 FunctionNameValidity function_name_validity, FunctionKind kind, 426 FunctionNameValidity function_name_validity, FunctionKind kind,
414 int function_token_position, FunctionLiteral::FunctionType type, 427 int function_token_position, FunctionLiteral::FunctionType type,
415 LanguageMode language_mode, bool* ok); 428 LanguageMode language_mode, bool* ok);
416 429
417 Expression* InstallHomeObject(Expression* function_literal, 430 Expression* InstallHomeObject(Expression* function_literal,
418 Expression* home_object); 431 Expression* home_object);
419 FunctionLiteral* SynthesizeClassFieldInitializer(int count); 432 FunctionLiteral* SynthesizeClassFieldInitializer(int count);
420 FunctionLiteral* InsertClassFieldInitializer(FunctionLiteral* constructor); 433 FunctionLiteral* InsertClassFieldInitializer(FunctionLiteral* constructor);
421 434
422 Expression* ParseClassLiteral(const AstRawString* name,
423 Scanner::Location class_name_location,
424 bool name_is_strict_reserved, int pos,
425 bool* ok);
426
427 // Get odd-ball literals. 435 // Get odd-ball literals.
428 Literal* GetLiteralUndefined(int position); 436 Literal* GetLiteralUndefined(int position);
429 437
430 // Check if the scope has conflicting var/let declarations from different 438 // Check if the scope has conflicting var/let declarations from different
431 // scopes. This covers for example 439 // scopes. This covers for example
432 // 440 //
433 // function f() { { { var x; } let x; } } 441 // function f() { { { var x; } let x; } }
434 // function g() { { var x; let x; } } 442 // function g() { { var x; let x; } }
435 // 443 //
436 // The var declarations are hoisted to the function scope, but originate from 444 // The var declarations are hoisted to the function scope, but originate from
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 } else { 740 } else {
733 fni_->PushLiteralName(ast_value_factory()->anonymous_function_string()); 741 fni_->PushLiteralName(ast_value_factory()->anonymous_function_string());
734 } 742 }
735 } 743 }
736 744
737 V8_INLINE void PushEnclosingName(const AstRawString* name) { 745 V8_INLINE void PushEnclosingName(const AstRawString* name) {
738 DCHECK_NOT_NULL(fni_); 746 DCHECK_NOT_NULL(fni_);
739 fni_->PushEnclosingName(name); 747 fni_->PushEnclosingName(name);
740 } 748 }
741 749
742 V8_INLINE void InferFunctionName(FunctionLiteral* func_to_infer) { 750 V8_INLINE void AddFunctionForNameInference(FunctionLiteral* func_to_infer) {
751 DCHECK_NOT_NULL(fni_);
743 fni_->AddFunction(func_to_infer); 752 fni_->AddFunction(func_to_infer);
744 } 753 }
745 754
755 V8_INLINE void InferFunctionName() {
756 DCHECK_NOT_NULL(fni_);
757 fni_->Infer();
758 }
759
746 // If we assign a function literal to a property we pretenure the 760 // If we assign a function literal to a property we pretenure the
747 // literal so it can be added as a constant function property. 761 // literal so it can be added as a constant function property.
748 V8_INLINE static void CheckAssigningFunctionLiteralToProperty( 762 V8_INLINE static void CheckAssigningFunctionLiteralToProperty(
749 Expression* left, Expression* right) { 763 Expression* left, Expression* right) {
750 DCHECK(left != NULL); 764 DCHECK(left != NULL);
751 if (left->IsProperty() && right->IsFunctionLiteral()) { 765 if (left->IsProperty() && right->IsFunctionLiteral()) {
752 right->AsFunctionLiteral()->set_pretenure(); 766 right->AsFunctionLiteral()->set_pretenure();
753 } 767 }
754 } 768 }
755 769
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 943
930 V8_INLINE Expression* ExpressionFromString(int pos) { 944 V8_INLINE Expression* ExpressionFromString(int pos) {
931 const AstRawString* symbol = GetSymbol(); 945 const AstRawString* symbol = GetSymbol();
932 fni_->PushLiteralName(symbol); 946 fni_->PushLiteralName(symbol);
933 return factory()->NewStringLiteral(symbol, pos); 947 return factory()->NewStringLiteral(symbol, pos);
934 } 948 }
935 949
936 V8_INLINE ZoneList<Expression*>* NewExpressionList(int size) const { 950 V8_INLINE ZoneList<Expression*>* NewExpressionList(int size) const {
937 return new (zone()) ZoneList<Expression*>(size, zone()); 951 return new (zone()) ZoneList<Expression*>(size, zone());
938 } 952 }
939 V8_INLINE ZoneList<ObjectLiteral::Property*>* NewPropertyList( 953 V8_INLINE ZoneList<ObjectLiteral::Property*>* NewObjectPropertyList(
940 int size) const { 954 int size) const {
941 return new (zone()) ZoneList<ObjectLiteral::Property*>(size, zone()); 955 return new (zone()) ZoneList<ObjectLiteral::Property*>(size, zone());
942 } 956 }
943 V8_INLINE ZoneList<ClassLiteral::Property*>* NewClassPropertyList( 957 V8_INLINE ZoneList<ClassLiteral::Property*>* NewClassPropertyList(
944 int size) const { 958 int size) const {
945 return new (zone()) ZoneList<ClassLiteral::Property*>(size, zone()); 959 return new (zone()) ZoneList<ClassLiteral::Property*>(size, zone());
946 } 960 }
947 V8_INLINE ZoneList<Statement*>* NewStatementList(int size) const { 961 V8_INLINE ZoneList<Statement*>* NewStatementList(int size) const {
948 return new (zone()) ZoneList<Statement*>(size, zone()); 962 return new (zone()) ZoneList<Statement*>(size, zone());
949 } 963 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 int total_preparse_skipped_; 1090 int total_preparse_skipped_;
1077 HistogramTimer* pre_parse_timer_; 1091 HistogramTimer* pre_parse_timer_;
1078 1092
1079 bool parsing_on_main_thread_; 1093 bool parsing_on_main_thread_;
1080 }; 1094 };
1081 1095
1082 } // namespace internal 1096 } // namespace internal
1083 } // namespace v8 1097 } // namespace v8
1084 1098
1085 #endif // V8_PARSING_PARSER_H_ 1099 #endif // V8_PARSING_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698