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

Side by Side Diff: src/parser.h

Issue 1130623004: [destructuring] Implement basic binding destructuring infrastructure (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: CR feedback Created 5 years, 7 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 | « BUILD.gn ('k') | src/parser.cc » ('j') | src/parser.cc » ('J')
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_PARSER_H_ 5 #ifndef V8_PARSER_H_
6 #define V8_PARSER_H_ 6 #define V8_PARSER_H_
7 7
8 #include "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/ast.h" 9 #include "src/ast.h"
10 #include "src/compiler.h" // TODO(titzer): remove this include dependency 10 #include "src/compiler.h" // TODO(titzer): remove this include dependency
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 bool* ok); 930 bool* ok);
931 Statement* ParseFunctionDeclaration(ZoneList<const AstRawString*>* names, 931 Statement* ParseFunctionDeclaration(ZoneList<const AstRawString*>* names,
932 bool* ok); 932 bool* ok);
933 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, 933 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names,
934 bool* ok); 934 bool* ok);
935 Statement* ParseNativeDeclaration(bool* ok); 935 Statement* ParseNativeDeclaration(bool* ok);
936 Block* ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok); 936 Block* ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok);
937 Block* ParseVariableStatement(VariableDeclarationContext var_context, 937 Block* ParseVariableStatement(VariableDeclarationContext var_context,
938 ZoneList<const AstRawString*>* names, 938 ZoneList<const AstRawString*>* names,
939 bool* ok); 939 bool* ok);
940
941
942 class PatternMatcher : private AstVisitor {
rossberg 2015/05/11 11:49:33 Can we call this PatternRewriter? It isn't a "matc
Dmitry Lomov (no reviews) 2015/05/11 12:52:58 Oh, good trick - I didn't realize it is allowed in
943 public:
944 struct DeclarationDescriptor {
945 Parser* parser;
946 Scope* declaration_scope;
947 Scope* scope;
948 int initializer_position;
949 VariableMode mode;
950 ZoneList<const AstRawString*>* names;
951 bool is_const;
952 Block* block;
953 bool needs_init;
954 int pos;
955 Token::Value init_op;
956 int* nvars;
957
958 Scope* initialization_scope() const {
959 return is_const ? declaration_scope : scope;
rossberg 2015/05/11 11:49:33 I think this function is not very meaningful as an
Dmitry Lomov (no reviews) 2015/05/11 12:52:57 Done.
960 }
961 Zone* zone() const { return parser->zone(); }
962 bool inside_with() const { return parser->inside_with(); }
963 };
964
965 explicit PatternMatcher(const DeclarationDescriptor* decl,
966 Expression* pattern)
967 : decl_(decl), pattern_(pattern) {}
968
969 PatternMatcher() : decl_(nullptr), pattern_(nullptr) {}
970
971 bool IsSingleVariableBinding() const;
972 const AstRawString* SingleName() const;
973
974 void DeclareAndInitializeVariables(Expression* value, bool* ok);
975
976 private:
977 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override;
978 // Visiting functions for AST nodes make this an AstVisitor.
979 AST_NODE_LIST(DECLARE_VISIT)
980 #undef DECLARE_VISIT
981 virtual void Visit(AstNode* node) override;
982
983 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) {
984 Expression* old_value = current_value_;
985 current_value_ = value;
986 pattern->Accept(this);
987 current_value_ = old_value;
988 }
989
990 AstNodeFactory* factory() const { return decl_->parser->factory(); }
991 AstValueFactory* ast_value_factory() const {
992 return decl_->parser->ast_value_factory();
993 }
994 Zone* zone() const { return decl_->parser->zone(); }
995
996 const DeclarationDescriptor* decl_;
997 Expression* pattern_;
998 Expression* current_value_;
999 bool* ok_;
1000 };
1001
1002
940 Block* ParseVariableDeclarations(VariableDeclarationContext var_context, 1003 Block* ParseVariableDeclarations(VariableDeclarationContext var_context,
941 int* num_decl, 1004 int* num_decl,
942 ZoneList<const AstRawString*>* names, 1005 ZoneList<const AstRawString*>* names,
943 const AstRawString** out, 1006 const AstRawString** out,
944 Scanner::Location* first_initializer_loc, 1007 Scanner::Location* first_initializer_loc,
945 Scanner::Location* bindings_loc, bool* ok); 1008 Scanner::Location* bindings_loc, bool* ok);
946 Statement* ParseExpressionOrLabelledStatement( 1009 Statement* ParseExpressionOrLabelledStatement(
947 ZoneList<const AstRawString*>* labels, bool* ok); 1010 ZoneList<const AstRawString*>* labels, bool* ok);
948 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels, 1011 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels,
949 bool* ok); 1012 bool* ok);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 } 1241 }
1179 1242
1180 1243
1181 Expression* ParserTraits::SpreadCallNew( 1244 Expression* ParserTraits::SpreadCallNew(
1182 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { 1245 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) {
1183 return parser_->SpreadCallNew(function, args, pos); 1246 return parser_->SpreadCallNew(function, args, pos);
1184 } 1247 }
1185 } } // namespace v8::internal 1248 } } // namespace v8::internal
1186 1249
1187 #endif // V8_PARSER_H_ 1250 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/parser.cc » ('j') | src/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698