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

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

Issue 2372733002: [parser] Refactor of (Parse|Desugar)*(Async|Arrow)* (Closed)
Patch Set: Rebase 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 friend class ParserBase<Parser>; 204 friend class ParserBase<Parser>;
205 friend class v8::internal::ExpressionClassifier<ParserTypes<Parser>>; 205 friend class v8::internal::ExpressionClassifier<ParserTypes<Parser>>;
206 206
207 // Runtime encoding of different completion modes. 207 // Runtime encoding of different completion modes.
208 enum CompletionKind { 208 enum CompletionKind {
209 kNormalCompletion, 209 kNormalCompletion,
210 kThrowCompletion, 210 kThrowCompletion,
211 kAbruptCompletion 211 kAbruptCompletion
212 }; 212 };
213 213
214 enum class FunctionBodyType { kNormal, kSingleExpression };
215
216 Variable* NewTemporary(const AstRawString* name) { 214 Variable* NewTemporary(const AstRawString* name) {
217 return scope()->NewTemporary(name); 215 return scope()->NewTemporary(name);
218 } 216 }
219 217
220 // Limit the allowed number of local variables in a function. The hard limit 218 // Limit the allowed number of local variables in a function. The hard limit
221 // is that offsets computed by FullCodeGenerator::StackOperand and similar 219 // is that offsets computed by FullCodeGenerator::StackOperand and similar
222 // functions are ints, and they should not overflow. In addition, accessing 220 // functions are ints, and they should not overflow. In addition, accessing
223 // local variables creates user-controlled constants in the generated code, 221 // local variables creates user-controlled constants in the generated code,
224 // and we don't want too much user-controlled memory inside the code (this was 222 // and we don't want too much user-controlled memory inside the code (this was
225 // the reason why this limit was introduced in the first place; see 223 // the reason why this limit was introduced in the first place; see
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 const AstRawString* local_name; 262 const AstRawString* local_name;
265 const Scanner::Location location; 263 const Scanner::Location location;
266 NamedImport(const AstRawString* import_name, const AstRawString* local_name, 264 NamedImport(const AstRawString* import_name, const AstRawString* local_name,
267 Scanner::Location location) 265 Scanner::Location location)
268 : import_name(import_name), 266 : import_name(import_name),
269 local_name(local_name), 267 local_name(local_name),
270 location(location) {} 268 location(location) {}
271 }; 269 };
272 ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok); 270 ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok);
273 Statement* ParseFunctionDeclaration(bool* ok); 271 Statement* ParseFunctionDeclaration(bool* ok);
274 Statement* ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names,
275 bool default_export, bool* ok);
276 Expression* ParseAsyncFunctionExpression(bool* ok);
277 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, 272 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names,
278 bool default_export, bool* ok); 273 bool default_export, bool* ok);
279 Statement* ParseNativeDeclaration(bool* ok); 274 Statement* ParseNativeDeclaration(bool* ok);
280 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result, 275 Block* BuildInitializationBlock(DeclarationParsingResult* parsing_result,
281 ZoneList<const AstRawString*>* names, 276 ZoneList<const AstRawString*>* names,
282 bool* ok); 277 bool* ok);
283 void DeclareAndInitializeVariables( 278 void DeclareAndInitializeVariables(
284 Block* block, const DeclarationDescriptor* declaration_descriptor, 279 Block* block, const DeclarationDescriptor* declaration_descriptor,
285 const DeclarationParsingResult::Declaration* declaration, 280 const DeclarationParsingResult::Declaration* declaration,
286 ZoneList<const AstRawString*>* names, bool* ok); 281 ZoneList<const AstRawString*>* names, bool* ok);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 Block* RewriteForVarInLegacy(const ForInfo& for_info); 399 Block* RewriteForVarInLegacy(const ForInfo& for_info);
405 void DesugarBindingInForEachStatement(ForInfo* for_info, Block** body_block, 400 void DesugarBindingInForEachStatement(ForInfo* for_info, Block** body_block,
406 Expression** each_variable, bool* ok); 401 Expression** each_variable, bool* ok);
407 Block* CreateForEachStatementTDZ(Block* init_block, const ForInfo& for_info, 402 Block* CreateForEachStatementTDZ(Block* init_block, const ForInfo& for_info,
408 bool* ok); 403 bool* ok);
409 404
410 Statement* DesugarLexicalBindingsInForStatement( 405 Statement* DesugarLexicalBindingsInForStatement(
411 ForStatement* loop, Statement* init, Expression* cond, Statement* next, 406 ForStatement* loop, Statement* init, Expression* cond, Statement* next,
412 Statement* body, Scope* inner_scope, const ForInfo& for_info, bool* ok); 407 Statement* body, Scope* inner_scope, const ForInfo& for_info, bool* ok);
413 408
414 void DesugarAsyncFunctionBody(Scope* scope, ZoneList<Statement*>* body,
415 FunctionKind kind, FunctionBodyType type,
416 bool accept_IN, int pos, bool* ok);
417
418 Expression* RewriteDoExpression(Block* body, int pos, bool* ok); 409 Expression* RewriteDoExpression(Block* body, int pos, bool* ok);
419 410
420 FunctionLiteral* ParseFunctionLiteral( 411 FunctionLiteral* ParseFunctionLiteral(
421 const AstRawString* name, Scanner::Location function_name_location, 412 const AstRawString* name, Scanner::Location function_name_location,
422 FunctionNameValidity function_name_validity, FunctionKind kind, 413 FunctionNameValidity function_name_validity, FunctionKind kind,
423 int function_token_position, FunctionLiteral::FunctionType type, 414 int function_token_position, FunctionLiteral::FunctionType type,
424 LanguageMode language_mode, bool* ok); 415 LanguageMode language_mode, bool* ok);
425 416
426 Expression* InstallHomeObject(Expression* function_literal, 417 Expression* InstallHomeObject(Expression* function_literal,
427 Expression* home_object); 418 Expression* home_object);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 typedef TemplateLiteral* TemplateLiteralState; 525 typedef TemplateLiteral* TemplateLiteralState;
535 526
536 TemplateLiteralState OpenTemplateLiteral(int pos); 527 TemplateLiteralState OpenTemplateLiteral(int pos);
537 void AddTemplateSpan(TemplateLiteralState* state, bool tail); 528 void AddTemplateSpan(TemplateLiteralState* state, bool tail);
538 void AddTemplateExpression(TemplateLiteralState* state, 529 void AddTemplateExpression(TemplateLiteralState* state,
539 Expression* expression); 530 Expression* expression);
540 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, 531 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start,
541 Expression* tag); 532 Expression* tag);
542 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit); 533 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit);
543 534
544 void ParseAsyncArrowSingleExpressionBody(ZoneList<Statement*>* body,
545 bool accept_IN,
546 int pos, bool* ok) {
547 DesugarAsyncFunctionBody(scope(), body, kAsyncArrowFunction,
548 FunctionBodyType::kSingleExpression, accept_IN,
549 pos, ok);
550 }
551
552 ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list); 535 ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list);
553 Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args, 536 Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args,
554 int pos); 537 int pos);
555 Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args, 538 Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args,
556 int pos); 539 int pos);
557 Expression* CallClassFieldInitializer(Scope* scope, Expression* this_expr); 540 Expression* CallClassFieldInitializer(Scope* scope, Expression* this_expr);
558 Expression* RewriteSuperCall(Expression* call_expression); 541 Expression* RewriteSuperCall(Expression* call_expression);
559 542
560 void SetLanguageMode(Scope* scope, LanguageMode mode); 543 void SetLanguageMode(Scope* scope, LanguageMode mode);
561 void SetAsmModule(); 544 void SetAsmModule();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 Statement* FinalizeForOfStatement(ForOfStatement* loop, Variable* completion, 583 Statement* FinalizeForOfStatement(ForOfStatement* loop, Variable* completion,
601 int pos); 584 int pos);
602 void BuildIteratorClose(ZoneList<Statement*>* statements, Variable* iterator, 585 void BuildIteratorClose(ZoneList<Statement*>* statements, Variable* iterator,
603 Variable* input, Variable* output); 586 Variable* input, Variable* output);
604 void BuildIteratorCloseForCompletion(ZoneList<Statement*>* statements, 587 void BuildIteratorCloseForCompletion(ZoneList<Statement*>* statements,
605 Variable* iterator, 588 Variable* iterator,
606 Expression* completion); 589 Expression* completion);
607 Statement* CheckCallable(Variable* var, Expression* error, int pos); 590 Statement* CheckCallable(Variable* var, Expression* error, int pos);
608 591
609 V8_INLINE Expression* RewriteAwaitExpression(Expression* value, int pos); 592 V8_INLINE Expression* RewriteAwaitExpression(Expression* value, int pos);
593 V8_INLINE void PrepareAsyncFunctionBody(ZoneList<Statement*>* body,
594 FunctionKind kind, int pos);
595 V8_INLINE void RewriteAsyncFunctionBody(ZoneList<Statement*>* body,
596 Block* block,
597 Expression* return_value, bool* ok);
610 598
611 Expression* RewriteYieldStar(Expression* generator, Expression* expression, 599 Expression* RewriteYieldStar(Expression* generator, Expression* expression,
612 int pos); 600 int pos);
613 601
614 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, 602 void AddArrowFunctionFormalParameters(ParserFormalParameters* parameters,
615 Expression* params, int end_pos, 603 Expression* params, int end_pos,
616 bool* ok); 604 bool* ok);
617 void SetFunctionName(Expression* value, const AstRawString* name); 605 void SetFunctionName(Expression* value, const AstRawString* name);
618 606
619 // Helper functions for recursive descent. 607 // Helper functions for recursive descent.
620 V8_INLINE bool IsEval(const AstRawString* identifier) const { 608 V8_INLINE bool IsEval(const AstRawString* identifier) const {
621 return identifier == ast_value_factory()->eval_string(); 609 return identifier == ast_value_factory()->eval_string();
622 } 610 }
623 611
624 V8_INLINE bool IsArguments(const AstRawString* identifier) const { 612 V8_INLINE bool IsArguments(const AstRawString* identifier) const {
625 return identifier == ast_value_factory()->arguments_string(); 613 return identifier == ast_value_factory()->arguments_string();
626 } 614 }
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 classifier()->RecordDuplicateFormalParameterError(scanner()->location()); 1006 classifier()->RecordDuplicateFormalParameterError(scanner()->location());
1019 } 1007 }
1020 if (is_sloppy(scope->language_mode())) { 1008 if (is_sloppy(scope->language_mode())) {
1021 // TODO(sigurds) Mark every parameter as maybe assigned. This is a 1009 // TODO(sigurds) Mark every parameter as maybe assigned. This is a
1022 // conservative approximation necessary to account for parameters 1010 // conservative approximation necessary to account for parameters
1023 // that are assigned via the arguments array. 1011 // that are assigned via the arguments array.
1024 var->set_maybe_assigned(); 1012 var->set_maybe_assigned();
1025 } 1013 }
1026 } 1014 }
1027 1015
1028 void ParseArrowFunctionFormalParameterList( 1016 void DeclareArrowFunctionFormalParameters(ParserFormalParameters* parameters,
1029 ParserFormalParameters* parameters, Expression* params, 1017 Expression* params,
1030 const Scanner::Location& params_loc, Scanner::Location* duplicate_loc, 1018 const Scanner::Location& params_loc,
1031 const Scope::Snapshot& scope_snapshot, bool* ok); 1019 Scanner::Location* duplicate_loc,
1020 bool* ok);
1032 1021
1033 void ReindexLiterals(const ParserFormalParameters& parameters); 1022 void ReindexLiterals(const ParserFormalParameters& parameters);
1034 1023
1035 V8_INLINE Expression* NoTemplateTag() { return NULL; } 1024 V8_INLINE Expression* NoTemplateTag() { return NULL; }
1036 V8_INLINE static bool IsTaggedTemplate(const Expression* tag) { 1025 V8_INLINE static bool IsTaggedTemplate(const Expression* tag) {
1037 return tag != NULL; 1026 return tag != NULL;
1038 } 1027 }
1039 1028
1040 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {} 1029 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {}
1041 1030
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 int total_preparse_skipped_; 1076 int total_preparse_skipped_;
1088 HistogramTimer* pre_parse_timer_; 1077 HistogramTimer* pre_parse_timer_;
1089 1078
1090 bool parsing_on_main_thread_; 1079 bool parsing_on_main_thread_;
1091 }; 1080 };
1092 1081
1093 } // namespace internal 1082 } // namespace internal
1094 } // namespace v8 1083 } // namespace v8
1095 1084
1096 #endif // V8_PARSING_PARSER_H_ 1085 #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