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

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

Issue 2289663002: [parser] Hide expression classifiers in parser implementation (Closed)
Patch Set: Created 4 years, 3 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
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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 Expression* iterable, Statement* body, 470 Expression* iterable, Statement* body,
471 bool finalize, 471 bool finalize,
472 int next_result_pos = kNoSourcePosition); 472 int next_result_pos = kNoSourcePosition);
473 Statement* DesugarLexicalBindingsInForStatement( 473 Statement* DesugarLexicalBindingsInForStatement(
474 Scope* inner_scope, VariableMode mode, 474 Scope* inner_scope, VariableMode mode,
475 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init, 475 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init,
476 Expression* cond, Statement* next, Statement* body, bool* ok); 476 Expression* cond, Statement* next, Statement* body, bool* ok);
477 477
478 void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope, 478 void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope,
479 ZoneList<Statement*>* body, 479 ZoneList<Statement*>* body,
480 ExpressionClassifier* classifier,
481 FunctionKind kind, FunctionBodyType type, 480 FunctionKind kind, FunctionBodyType type,
482 bool accept_IN, int pos, bool* ok); 481 bool accept_IN, int pos, bool* ok);
483 482
484 void RewriteDoExpression(Expression* expr, bool* ok); 483 void RewriteDoExpression(Expression* expr, bool* ok);
485 484
486 FunctionLiteral* ParseFunctionLiteral( 485 FunctionLiteral* ParseFunctionLiteral(
487 const AstRawString* name, Scanner::Location function_name_location, 486 const AstRawString* name, Scanner::Location function_name_location,
488 FunctionNameValidity function_name_validity, FunctionKind kind, 487 FunctionNameValidity function_name_validity, FunctionKind kind,
489 int function_token_position, FunctionLiteral::FunctionType type, 488 int function_token_position, FunctionLiteral::FunctionType type,
490 LanguageMode language_mode, bool* ok); 489 LanguageMode language_mode, bool* ok);
491 490
492 Expression* ParseClassLiteral(ExpressionClassifier* classifier, 491 Expression* ParseClassLiteral(const AstRawString* name,
493 const AstRawString* name,
494 Scanner::Location class_name_location, 492 Scanner::Location class_name_location,
495 bool name_is_strict_reserved, int pos, 493 bool name_is_strict_reserved, int pos,
496 bool* ok); 494 bool* ok);
497 495
498 // Magical syntax support. 496 // Magical syntax support.
499 Expression* ParseV8Intrinsic(bool* ok); 497 Expression* ParseV8Intrinsic(bool* ok);
500 498
501 // Get odd-ball literals. 499 // Get odd-ball literals.
502 Literal* GetLiteralUndefined(int position); 500 Literal* GetLiteralUndefined(int position);
503 501
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 TemplateLiteralState OpenTemplateLiteral(int pos); 603 TemplateLiteralState OpenTemplateLiteral(int pos);
606 void AddTemplateSpan(TemplateLiteralState* state, bool tail); 604 void AddTemplateSpan(TemplateLiteralState* state, bool tail);
607 void AddTemplateExpression(TemplateLiteralState* state, 605 void AddTemplateExpression(TemplateLiteralState* state,
608 Expression* expression); 606 Expression* expression);
609 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, 607 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start,
610 Expression* tag); 608 Expression* tag);
611 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit); 609 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit);
612 610
613 void ParseAsyncArrowSingleExpressionBody(ZoneList<Statement*>* body, 611 void ParseAsyncArrowSingleExpressionBody(ZoneList<Statement*>* body,
614 bool accept_IN, 612 bool accept_IN,
615 ExpressionClassifier* classifier,
616 int pos, bool* ok) { 613 int pos, bool* ok) {
617 DesugarAsyncFunctionBody(ast_value_factory()->empty_string(), scope(), body, 614 DesugarAsyncFunctionBody(
618 classifier, kAsyncArrowFunction, 615 ast_value_factory()->empty_string(), scope(), body, kAsyncArrowFunction,
619 FunctionBodyType::kSingleExpression, accept_IN, 616 FunctionBodyType::kSingleExpression, accept_IN, pos, ok);
620 pos, ok);
621 } 617 }
622 618
623 ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list); 619 ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list);
624 Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args, 620 Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args,
625 int pos); 621 int pos);
626 Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args, 622 Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args,
627 int pos); 623 int pos);
628 624
629 void SetLanguageMode(Scope* scope, LanguageMode mode); 625 void SetLanguageMode(Scope* scope, LanguageMode mode);
630 void RaiseLanguageMode(LanguageMode mode); 626 void RaiseLanguageMode(LanguageMode mode);
631 627
632 V8_INLINE void MarkCollectedTailCallExpressions(); 628 V8_INLINE void MarkCollectedTailCallExpressions();
633 V8_INLINE void MarkTailPosition(Expression* expression); 629 V8_INLINE void MarkTailPosition(Expression* expression);
634 630
635 // Rewrite all DestructuringAssignments in the current FunctionState. 631 // Rewrite all DestructuringAssignments in the current FunctionState.
636 V8_INLINE void RewriteDestructuringAssignments(); 632 V8_INLINE void RewriteDestructuringAssignments();
637 633
638 V8_INLINE Expression* RewriteExponentiation(Expression* left, 634 V8_INLINE Expression* RewriteExponentiation(Expression* left,
639 Expression* right, int pos); 635 Expression* right, int pos);
640 V8_INLINE Expression* RewriteAssignExponentiation(Expression* left, 636 V8_INLINE Expression* RewriteAssignExponentiation(Expression* left,
641 Expression* right, int pos); 637 Expression* right, int pos);
642 638
643 friend class NonPatternRewriter; 639 friend class NonPatternRewriter;
644 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); 640 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit);
645 641
646 // Rewrite expressions that are not used as patterns 642 // Rewrite expressions that are not used as patterns
647 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok); 643 V8_INLINE void RewriteNonPattern(bool* ok);
648 644
649 V8_INLINE void QueueDestructuringAssignmentForRewriting( 645 V8_INLINE void QueueDestructuringAssignmentForRewriting(
650 Expression* assignment); 646 Expression* assignment);
651 V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok); 647 V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok);
652 648
653 friend class InitializerRewriter; 649 friend class InitializerRewriter;
654 void RewriteParameterInitializer(Expression* expr, Scope* scope); 650 void RewriteParameterInitializer(Expression* expr, Scope* scope);
655 651
656 Expression* BuildCreateJSGeneratorObject(int pos, FunctionKind kind); 652 Expression* BuildCreateJSGeneratorObject(int pos, FunctionKind kind);
657 Expression* BuildResolvePromise(Expression* value, int pos); 653 Expression* BuildResolvePromise(Expression* value, int pos);
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 ? pattern->AsVariableProxy()->raw_name() 971 ? pattern->AsVariableProxy()->raw_name()
976 : ast_value_factory()->empty_string(); 972 : ast_value_factory()->empty_string();
977 parameters->params.Add( 973 parameters->params.Add(
978 ParserFormalParameters::Parameter(name, pattern, initializer, 974 ParserFormalParameters::Parameter(name, pattern, initializer,
979 initializer_end_position, is_rest), 975 initializer_end_position, is_rest),
980 parameters->scope->zone()); 976 parameters->scope->zone());
981 } 977 }
982 978
983 V8_INLINE void DeclareFormalParameter( 979 V8_INLINE void DeclareFormalParameter(
984 DeclarationScope* scope, 980 DeclarationScope* scope,
985 const ParserFormalParameters::Parameter& parameter, 981 const ParserFormalParameters::Parameter& parameter) {
986 ExpressionClassifier* classifier) {
987 bool is_duplicate = false; 982 bool is_duplicate = false;
988 bool is_simple = classifier->is_simple_parameter_list(); 983 bool is_simple = classifier()->is_simple_parameter_list();
989 auto name = is_simple || parameter.is_rest 984 auto name = is_simple || parameter.is_rest
990 ? parameter.name 985 ? parameter.name
991 : ast_value_factory()->empty_string(); 986 : ast_value_factory()->empty_string();
992 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; 987 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY;
993 if (!is_simple) scope->SetHasNonSimpleParameters(); 988 if (!is_simple) scope->SetHasNonSimpleParameters();
994 bool is_optional = parameter.initializer != nullptr; 989 bool is_optional = parameter.initializer != nullptr;
995 Variable* var = 990 Variable* var =
996 scope->DeclareParameter(name, mode, is_optional, parameter.is_rest, 991 scope->DeclareParameter(name, mode, is_optional, parameter.is_rest,
997 &is_duplicate, ast_value_factory()); 992 &is_duplicate, ast_value_factory());
998 if (is_duplicate) { 993 if (is_duplicate) {
999 classifier->RecordDuplicateFormalParameterError(scanner()->location()); 994 classifier()->RecordDuplicateFormalParameterError(scanner()->location());
1000 } 995 }
1001 if (is_sloppy(scope->language_mode())) { 996 if (is_sloppy(scope->language_mode())) {
1002 // TODO(sigurds) Mark every parameter as maybe assigned. This is a 997 // TODO(sigurds) Mark every parameter as maybe assigned. This is a
1003 // conservative approximation necessary to account for parameters 998 // conservative approximation necessary to account for parameters
1004 // that are assigned via the arguments array. 999 // that are assigned via the arguments array.
1005 var->set_maybe_assigned(); 1000 var->set_maybe_assigned();
1006 } 1001 }
1007 } 1002 }
1008 1003
1009 void ParseArrowFunctionFormalParameterList( 1004 void ParseArrowFunctionFormalParameterList(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 static const int kLiteralTypeSlot = 0; 1082 static const int kLiteralTypeSlot = 0;
1088 static const int kElementsSlot = 1; 1083 static const int kElementsSlot = 1;
1089 1084
1090 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 1085 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
1091 }; 1086 };
1092 1087
1093 } // namespace internal 1088 } // namespace internal
1094 } // namespace v8 1089 } // namespace v8
1095 1090
1096 #endif // V8_PARSING_PARSER_H_ 1091 #endif // V8_PARSING_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698