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

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

Issue 2289663002: [parser] Hide expression classifiers in parser implementation (Closed)
Patch Set: Rebase 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
« no previous file with comments | « src/parsing/expression-classifier.h ('k') | 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 template <> 140 template <>
141 struct ParserTypes<Parser> { 141 struct ParserTypes<Parser> {
142 typedef ParserBase<Parser> Base; 142 typedef ParserBase<Parser> Base;
143 typedef Parser Impl; 143 typedef Parser Impl;
144 144
145 typedef Variable GeneratorVariable; 145 typedef Variable GeneratorVariable;
146 146
147 typedef v8::internal::AstProperties AstProperties; 147 typedef v8::internal::AstProperties AstProperties;
148 148
149 typedef v8::internal::ExpressionClassifier<ParserTypes<Parser>>
150 ExpressionClassifier;
151
152 // Return types for traversing functions. 149 // Return types for traversing functions.
153 typedef const AstRawString* Identifier; 150 typedef const AstRawString* Identifier;
154 typedef v8::internal::Expression* Expression; 151 typedef v8::internal::Expression* Expression;
155 typedef Yield* YieldExpression; 152 typedef Yield* YieldExpression;
156 typedef v8::internal::FunctionLiteral* FunctionLiteral; 153 typedef v8::internal::FunctionLiteral* FunctionLiteral;
157 typedef v8::internal::ClassLiteral* ClassLiteral; 154 typedef v8::internal::ClassLiteral* ClassLiteral;
158 typedef v8::internal::Literal* Literal; 155 typedef v8::internal::Literal* Literal;
159 typedef ObjectLiteral::Property* ObjectLiteralProperty; 156 typedef ObjectLiteral::Property* ObjectLiteralProperty;
160 typedef ZoneList<v8::internal::Expression*>* ExpressionList; 157 typedef ZoneList<v8::internal::Expression*>* ExpressionList;
161 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; 158 typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 Expression* iterable, Statement* body, 434 Expression* iterable, Statement* body,
438 bool finalize, 435 bool finalize,
439 int next_result_pos = kNoSourcePosition); 436 int next_result_pos = kNoSourcePosition);
440 Statement* DesugarLexicalBindingsInForStatement( 437 Statement* DesugarLexicalBindingsInForStatement(
441 Scope* inner_scope, VariableMode mode, 438 Scope* inner_scope, VariableMode mode,
442 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init, 439 ZoneList<const AstRawString*>* names, ForStatement* loop, Statement* init,
443 Expression* cond, Statement* next, Statement* body, bool* ok); 440 Expression* cond, Statement* next, Statement* body, bool* ok);
444 441
445 void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope, 442 void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope,
446 ZoneList<Statement*>* body, 443 ZoneList<Statement*>* body,
447 ExpressionClassifier* classifier,
448 FunctionKind kind, FunctionBodyType type, 444 FunctionKind kind, FunctionBodyType type,
449 bool accept_IN, int pos, bool* ok); 445 bool accept_IN, int pos, bool* ok);
450 446
451 void RewriteDoExpression(Expression* expr, bool* ok); 447 void RewriteDoExpression(Expression* expr, bool* ok);
452 448
453 FunctionLiteral* ParseFunctionLiteral( 449 FunctionLiteral* ParseFunctionLiteral(
454 const AstRawString* name, Scanner::Location function_name_location, 450 const AstRawString* name, Scanner::Location function_name_location,
455 FunctionNameValidity function_name_validity, FunctionKind kind, 451 FunctionNameValidity function_name_validity, FunctionKind kind,
456 int function_token_position, FunctionLiteral::FunctionType type, 452 int function_token_position, FunctionLiteral::FunctionType type,
457 LanguageMode language_mode, bool* ok); 453 LanguageMode language_mode, bool* ok);
458 454
459 Expression* ParseClassLiteral(ExpressionClassifier* classifier, 455 Expression* ParseClassLiteral(const AstRawString* name,
460 const AstRawString* name,
461 Scanner::Location class_name_location, 456 Scanner::Location class_name_location,
462 bool name_is_strict_reserved, int pos, 457 bool name_is_strict_reserved, int pos,
463 bool* ok); 458 bool* ok);
464 459
465 // Magical syntax support. 460 // Magical syntax support.
466 Expression* ParseV8Intrinsic(bool* ok); 461 Expression* ParseV8Intrinsic(bool* ok);
467 462
468 // Get odd-ball literals. 463 // Get odd-ball literals.
469 Literal* GetLiteralUndefined(int position); 464 Literal* GetLiteralUndefined(int position);
470 465
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 TemplateLiteralState OpenTemplateLiteral(int pos); 567 TemplateLiteralState OpenTemplateLiteral(int pos);
573 void AddTemplateSpan(TemplateLiteralState* state, bool tail); 568 void AddTemplateSpan(TemplateLiteralState* state, bool tail);
574 void AddTemplateExpression(TemplateLiteralState* state, 569 void AddTemplateExpression(TemplateLiteralState* state,
575 Expression* expression); 570 Expression* expression);
576 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start, 571 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start,
577 Expression* tag); 572 Expression* tag);
578 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit); 573 uint32_t ComputeTemplateLiteralHash(const TemplateLiteral* lit);
579 574
580 void ParseAsyncArrowSingleExpressionBody(ZoneList<Statement*>* body, 575 void ParseAsyncArrowSingleExpressionBody(ZoneList<Statement*>* body,
581 bool accept_IN, 576 bool accept_IN,
582 ExpressionClassifier* classifier,
583 int pos, bool* ok) { 577 int pos, bool* ok) {
584 DesugarAsyncFunctionBody(ast_value_factory()->empty_string(), scope(), body, 578 DesugarAsyncFunctionBody(
585 classifier, kAsyncArrowFunction, 579 ast_value_factory()->empty_string(), scope(), body, kAsyncArrowFunction,
586 FunctionBodyType::kSingleExpression, accept_IN, 580 FunctionBodyType::kSingleExpression, accept_IN, pos, ok);
587 pos, ok);
588 } 581 }
589 582
590 ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list); 583 ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list);
591 Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args, 584 Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args,
592 int pos); 585 int pos);
593 Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args, 586 Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args,
594 int pos); 587 int pos);
595 588
596 void SetLanguageMode(Scope* scope, LanguageMode mode); 589 void SetLanguageMode(Scope* scope, LanguageMode mode);
597 void RaiseLanguageMode(LanguageMode mode); 590 void RaiseLanguageMode(LanguageMode mode);
598 591
599 V8_INLINE void MarkCollectedTailCallExpressions(); 592 V8_INLINE void MarkCollectedTailCallExpressions();
600 V8_INLINE void MarkTailPosition(Expression* expression); 593 V8_INLINE void MarkTailPosition(Expression* expression);
601 594
602 // Rewrite all DestructuringAssignments in the current FunctionState. 595 // Rewrite all DestructuringAssignments in the current FunctionState.
603 V8_INLINE void RewriteDestructuringAssignments(); 596 V8_INLINE void RewriteDestructuringAssignments();
604 597
605 V8_INLINE Expression* RewriteExponentiation(Expression* left, 598 V8_INLINE Expression* RewriteExponentiation(Expression* left,
606 Expression* right, int pos); 599 Expression* right, int pos);
607 V8_INLINE Expression* RewriteAssignExponentiation(Expression* left, 600 V8_INLINE Expression* RewriteAssignExponentiation(Expression* left,
608 Expression* right, int pos); 601 Expression* right, int pos);
609 602
610 friend class NonPatternRewriter; 603 friend class NonPatternRewriter;
611 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); 604 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit);
612 605
613 // Rewrite expressions that are not used as patterns 606 // Rewrite expressions that are not used as patterns
614 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok); 607 V8_INLINE void RewriteNonPattern(bool* ok);
615 608
616 V8_INLINE void QueueDestructuringAssignmentForRewriting( 609 V8_INLINE void QueueDestructuringAssignmentForRewriting(
617 Expression* assignment); 610 Expression* assignment);
618 V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok); 611 V8_INLINE void QueueNonPatternForRewriting(Expression* expr, bool* ok);
619 612
620 friend class InitializerRewriter; 613 friend class InitializerRewriter;
621 void RewriteParameterInitializer(Expression* expr, Scope* scope); 614 void RewriteParameterInitializer(Expression* expr, Scope* scope);
622 615
623 Expression* BuildCreateJSGeneratorObject(int pos, FunctionKind kind); 616 Expression* BuildCreateJSGeneratorObject(int pos, FunctionKind kind);
624 Expression* BuildResolvePromise(Expression* value, int pos); 617 Expression* BuildResolvePromise(Expression* value, int pos);
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 ? pattern->AsVariableProxy()->raw_name() 939 ? pattern->AsVariableProxy()->raw_name()
947 : ast_value_factory()->empty_string(); 940 : ast_value_factory()->empty_string();
948 parameters->params.Add( 941 parameters->params.Add(
949 ParserFormalParameters::Parameter(name, pattern, initializer, 942 ParserFormalParameters::Parameter(name, pattern, initializer,
950 initializer_end_position, is_rest), 943 initializer_end_position, is_rest),
951 parameters->scope->zone()); 944 parameters->scope->zone());
952 } 945 }
953 946
954 V8_INLINE void DeclareFormalParameter( 947 V8_INLINE void DeclareFormalParameter(
955 DeclarationScope* scope, 948 DeclarationScope* scope,
956 const ParserFormalParameters::Parameter& parameter, 949 const ParserFormalParameters::Parameter& parameter) {
957 ExpressionClassifier* classifier) {
958 bool is_duplicate = false; 950 bool is_duplicate = false;
959 bool is_simple = classifier->is_simple_parameter_list(); 951 bool is_simple = classifier()->is_simple_parameter_list();
960 auto name = is_simple || parameter.is_rest 952 auto name = is_simple || parameter.is_rest
961 ? parameter.name 953 ? parameter.name
962 : ast_value_factory()->empty_string(); 954 : ast_value_factory()->empty_string();
963 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; 955 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY;
964 if (!is_simple) scope->SetHasNonSimpleParameters(); 956 if (!is_simple) scope->SetHasNonSimpleParameters();
965 bool is_optional = parameter.initializer != nullptr; 957 bool is_optional = parameter.initializer != nullptr;
966 Variable* var = 958 Variable* var =
967 scope->DeclareParameter(name, mode, is_optional, parameter.is_rest, 959 scope->DeclareParameter(name, mode, is_optional, parameter.is_rest,
968 &is_duplicate, ast_value_factory()); 960 &is_duplicate, ast_value_factory());
969 if (is_duplicate) { 961 if (is_duplicate) {
970 classifier->RecordDuplicateFormalParameterError(scanner()->location()); 962 classifier()->RecordDuplicateFormalParameterError(scanner()->location());
971 } 963 }
972 if (is_sloppy(scope->language_mode())) { 964 if (is_sloppy(scope->language_mode())) {
973 // TODO(sigurds) Mark every parameter as maybe assigned. This is a 965 // TODO(sigurds) Mark every parameter as maybe assigned. This is a
974 // conservative approximation necessary to account for parameters 966 // conservative approximation necessary to account for parameters
975 // that are assigned via the arguments array. 967 // that are assigned via the arguments array.
976 var->set_maybe_assigned(); 968 var->set_maybe_assigned();
977 } 969 }
978 } 970 }
979 971
980 void ParseArrowFunctionFormalParameterList( 972 void ParseArrowFunctionFormalParameterList(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 static const int kLiteralTypeSlot = 0; 1050 static const int kLiteralTypeSlot = 0;
1059 static const int kElementsSlot = 1; 1051 static const int kElementsSlot = 1;
1060 1052
1061 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 1053 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
1062 }; 1054 };
1063 1055
1064 } // namespace internal 1056 } // namespace internal
1065 } // namespace v8 1057 } // namespace v8
1066 1058
1067 #endif // V8_PARSING_PARSER_H_ 1059 #endif // V8_PARSING_PARSER_H_
OLDNEW
« no previous file with comments | « src/parsing/expression-classifier.h ('k') | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698