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

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

Issue 2142233003: Templatize AstVisitor with its subclass (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 4 years, 5 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/interpreter/bytecode-generator.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/allocation.h" 8 #include "src/allocation.h"
9 #include "src/ast/ast.h" 9 #include "src/ast/ast.h"
10 #include "src/ast/scopes.h" 10 #include "src/ast/scopes.h"
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 // Odd-ball literal creators. 500 // Odd-ball literal creators.
501 Literal* GetLiteralTheHole(int position, AstNodeFactory* factory); 501 Literal* GetLiteralTheHole(int position, AstNodeFactory* factory);
502 502
503 // Producing data during the recursive descent. 503 // Producing data during the recursive descent.
504 const AstRawString* GetSymbol(Scanner* scanner); 504 const AstRawString* GetSymbol(Scanner* scanner);
505 const AstRawString* GetNextSymbol(Scanner* scanner); 505 const AstRawString* GetNextSymbol(Scanner* scanner);
506 const AstRawString* GetNumberAsSymbol(Scanner* scanner); 506 const AstRawString* GetNumberAsSymbol(Scanner* scanner);
507 507
508 Expression* ThisExpression(Scope* scope, AstNodeFactory* factory, 508 Expression* ThisExpression(Scope* scope, AstNodeFactory* factory,
509 int pos = kNoSourcePosition); 509 int pos = kNoSourcePosition);
510 Expression* SuperPropertyReference(Scope* scope, AstNodeFactory* factory, 510 Expression* NewSuperPropertyReference(Scope* scope, AstNodeFactory* factory,
511 int pos); 511 int pos);
512 Expression* SuperCallReference(Scope* scope, AstNodeFactory* factory, 512 Expression* NewSuperCallReference(Scope* scope, AstNodeFactory* factory,
513 int pos); 513 int pos);
514 Expression* NewTargetExpression(Scope* scope, AstNodeFactory* factory, 514 Expression* NewTargetExpression(Scope* scope, AstNodeFactory* factory,
515 int pos); 515 int pos);
516 Expression* FunctionSentExpression(Scope* scope, AstNodeFactory* factory, 516 Expression* FunctionSentExpression(Scope* scope, AstNodeFactory* factory,
517 int pos); 517 int pos);
518 Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner, 518 Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner,
519 AstNodeFactory* factory); 519 AstNodeFactory* factory);
520 Expression* ExpressionFromIdentifier(const AstRawString* name, 520 Expression* ExpressionFromIdentifier(const AstRawString* name,
521 int start_position, int end_position, 521 int start_position, int end_position,
522 Scope* scope, AstNodeFactory* factory); 522 Scope* scope, AstNodeFactory* factory);
523 Expression* ExpressionFromString(int pos, Scanner* scanner, 523 Expression* ExpressionFromString(int pos, Scanner* scanner,
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 833
834 Block* BuildInitializationBlock(ZoneList<const AstRawString*>* names, 834 Block* BuildInitializationBlock(ZoneList<const AstRawString*>* names,
835 bool* ok); 835 bool* ok);
836 836
837 DeclarationDescriptor descriptor; 837 DeclarationDescriptor descriptor;
838 List<Declaration> declarations; 838 List<Declaration> declarations;
839 Scanner::Location first_initializer_loc; 839 Scanner::Location first_initializer_loc;
840 Scanner::Location bindings_loc; 840 Scanner::Location bindings_loc;
841 }; 841 };
842 842
843 class PatternRewriter : private AstVisitor { 843 class PatternRewriter final : private AstVisitor<PatternRewriter> {
844 public: 844 public:
845 static void DeclareAndInitializeVariables( 845 static void DeclareAndInitializeVariables(
846 Block* block, const DeclarationDescriptor* declaration_descriptor, 846 Block* block, const DeclarationDescriptor* declaration_descriptor,
847 const DeclarationParsingResult::Declaration* declaration, 847 const DeclarationParsingResult::Declaration* declaration,
848 ZoneList<const AstRawString*>* names, bool* ok); 848 ZoneList<const AstRawString*>* names, bool* ok);
849 849
850 static void RewriteDestructuringAssignment(Parser* parser, 850 static void RewriteDestructuringAssignment(Parser* parser,
851 RewritableExpression* expr, 851 RewritableExpression* expr,
852 Scope* Scope); 852 Scope* Scope);
853 853
854 static Expression* RewriteDestructuringAssignment(Parser* parser, 854 static Expression* RewriteDestructuringAssignment(Parser* parser,
855 Assignment* assignment, 855 Assignment* assignment,
856 Scope* scope); 856 Scope* scope);
857 857
858 private: 858 private:
859 PatternRewriter() {} 859 PatternRewriter() {}
860 860
861 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override; 861 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node);
862 // Visiting functions for AST nodes make this an AstVisitor. 862 // Visiting functions for AST nodes make this an AstVisitor.
863 AST_NODE_LIST(DECLARE_VISIT) 863 AST_NODE_LIST(DECLARE_VISIT)
864 #undef DECLARE_VISIT 864 #undef DECLARE_VISIT
865 void Visit(AstNode* node) override;
866 865
867 enum PatternContext { 866 enum PatternContext {
868 BINDING, 867 BINDING,
869 INITIALIZER, 868 INITIALIZER,
870 ASSIGNMENT, 869 ASSIGNMENT,
871 ASSIGNMENT_INITIALIZER 870 ASSIGNMENT_INITIALIZER
872 }; 871 };
873 872
874 PatternContext context() const { return context_; } 873 PatternContext context() const { return context_; }
875 void set_context(PatternContext context) { context_ = context; } 874 void set_context(PatternContext context) { context_ = context; }
876 875
877 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) { 876 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) {
878 Expression* old_value = current_value_; 877 Expression* old_value = current_value_;
879 current_value_ = value; 878 current_value_ = value;
880 recursion_level_++; 879 recursion_level_++;
881 pattern->Accept(this); 880 Visit(pattern);
882 recursion_level_--; 881 recursion_level_--;
883 current_value_ = old_value; 882 current_value_ = old_value;
884 } 883 }
885 884
886 void VisitObjectLiteral(ObjectLiteral* node, Variable** temp_var); 885 void VisitObjectLiteral(ObjectLiteral* node, Variable** temp_var);
887 void VisitArrayLiteral(ArrayLiteral* node, Variable** temp_var); 886 void VisitArrayLiteral(ArrayLiteral* node, Variable** temp_var);
888 887
889 bool IsBindingContext() const { return IsBindingContext(context_); } 888 bool IsBindingContext() const { return IsBindingContext(context_); }
890 bool IsInitializerContext() const { return context_ != ASSIGNMENT; } 889 bool IsInitializerContext() const { return context_ != ASSIGNMENT; }
891 bool IsAssignmentContext() const { return IsAssignmentContext(context_); } 890 bool IsAssignmentContext() const { return IsAssignmentContext(context_); }
(...skipping 18 matching lines...) Expand all
910 Parser* parser_; 909 Parser* parser_;
911 PatternContext context_; 910 PatternContext context_;
912 Expression* pattern_; 911 Expression* pattern_;
913 int initializer_position_; 912 int initializer_position_;
914 Block* block_; 913 Block* block_;
915 const DeclarationDescriptor* descriptor_; 914 const DeclarationDescriptor* descriptor_;
916 ZoneList<const AstRawString*>* names_; 915 ZoneList<const AstRawString*>* names_;
917 Expression* current_value_; 916 Expression* current_value_;
918 int recursion_level_; 917 int recursion_level_;
919 bool* ok_; 918 bool* ok_;
919
920 DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW()
920 }; 921 };
921 922
922 Block* ParseVariableDeclarations(VariableDeclarationContext var_context, 923 Block* ParseVariableDeclarations(VariableDeclarationContext var_context,
923 DeclarationParsingResult* parsing_result, 924 DeclarationParsingResult* parsing_result,
924 ZoneList<const AstRawString*>* names, 925 ZoneList<const AstRawString*>* names,
925 bool* ok); 926 bool* ok);
926 Statement* ParseExpressionOrLabelledStatement( 927 Statement* ParseExpressionOrLabelledStatement(
927 ZoneList<const AstRawString*>* labels, 928 ZoneList<const AstRawString*>* labels,
928 AllowLabelledFunctionStatement allow_function, bool* ok); 929 AllowLabelledFunctionStatement allow_function, bool* ok);
929 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels, 930 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels,
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 1299
1299 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { 1300 DoExpression* ParserTraits::ParseDoExpression(bool* ok) {
1300 return parser_->ParseDoExpression(ok); 1301 return parser_->ParseDoExpression(ok);
1301 } 1302 }
1302 1303
1303 1304
1304 } // namespace internal 1305 } // namespace internal
1305 } // namespace v8 1306 } // namespace v8
1306 1307
1307 #endif // V8_PARSING_PARSER_H_ 1308 #endif // V8_PARSING_PARSER_H_
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-generator.h ('k') | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698