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

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

Issue 1309813007: [es6] implement destructuring assignment (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase*** oops Created 5 years 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/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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 V8_INLINE ZoneList<v8::internal::Expression*>* PrepareSpreadArguments( 892 V8_INLINE ZoneList<v8::internal::Expression*>* PrepareSpreadArguments(
893 ZoneList<v8::internal::Expression*>* list); 893 ZoneList<v8::internal::Expression*>* list);
894 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {} 894 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {}
895 V8_INLINE Expression* SpreadCall(Expression* function, 895 V8_INLINE Expression* SpreadCall(Expression* function,
896 ZoneList<v8::internal::Expression*>* args, 896 ZoneList<v8::internal::Expression*>* args,
897 int pos); 897 int pos);
898 V8_INLINE Expression* SpreadCallNew(Expression* function, 898 V8_INLINE Expression* SpreadCallNew(Expression* function,
899 ZoneList<v8::internal::Expression*>* args, 899 ZoneList<v8::internal::Expression*>* args,
900 int pos); 900 int pos);
901 901
902 // Rewrite all DestructuringAssignments in the current FunctionState.
903 V8_INLINE void RewriteDestructuringAssignments();
904
905 V8_INLINE void QueueDestructuringAssignmentForRewriting(
906 Expression* assignment);
907
902 private: 908 private:
903 Parser* parser_; 909 Parser* parser_;
904 }; 910 };
905 911
906 912
907 class Parser : public ParserBase<ParserTraits> { 913 class Parser : public ParserBase<ParserTraits> {
908 public: 914 public:
909 explicit Parser(ParseInfo* info); 915 explicit Parser(ParseInfo* info);
910 ~Parser() { 916 ~Parser() {
911 delete reusable_preparser_; 917 delete reusable_preparser_;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 Scanner::Location bindings_loc; 1038 Scanner::Location bindings_loc;
1033 }; 1039 };
1034 1040
1035 class PatternRewriter : private AstVisitor { 1041 class PatternRewriter : private AstVisitor {
1036 public: 1042 public:
1037 static void DeclareAndInitializeVariables( 1043 static void DeclareAndInitializeVariables(
1038 Block* block, const DeclarationDescriptor* declaration_descriptor, 1044 Block* block, const DeclarationDescriptor* declaration_descriptor,
1039 const DeclarationParsingResult::Declaration* declaration, 1045 const DeclarationParsingResult::Declaration* declaration,
1040 ZoneList<const AstRawString*>* names, bool* ok); 1046 ZoneList<const AstRawString*>* names, bool* ok);
1041 1047
1048 static void RewriteDestructuringAssignment(
1049 Parser* parser, RewritableAssignmentExpression* expr, Scope* Scope,
1050 bool* ok);
1051
1042 void set_initializer_position(int pos) { initializer_position_ = pos; } 1052 void set_initializer_position(int pos) { initializer_position_ = pos; }
1043 1053
1044 private: 1054 private:
1045 PatternRewriter() {} 1055 PatternRewriter() {}
1046 1056
1047 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override; 1057 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override;
1048 // Visiting functions for AST nodes make this an AstVisitor. 1058 // Visiting functions for AST nodes make this an AstVisitor.
1049 AST_NODE_LIST(DECLARE_VISIT) 1059 AST_NODE_LIST(DECLARE_VISIT)
1050 #undef DECLARE_VISIT 1060 #undef DECLARE_VISIT
1051 void Visit(AstNode* node) override; 1061 void Visit(AstNode* node) override;
1052 1062
1063 enum PatternContext {
1064 BINDING,
1065 INITIALIZER,
1066 ASSIGNMENT,
1067 ASSIGNMENT_INITIALIZER
1068 };
1069
1070 PatternContext context() const { return context_; }
1071 void set_context(PatternContext context) { context_ = context; }
1072
1053 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) { 1073 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) {
1054 Expression* old_value = current_value_; 1074 Expression* old_value = current_value_;
1055 current_value_ = value; 1075 current_value_ = value;
1056 pattern->Accept(this); 1076 pattern->Accept(this);
1057 current_value_ = old_value; 1077 current_value_ = old_value;
1058 } 1078 }
1059 1079
1080 void VisitObjectLiteral(ObjectLiteral* node, Variable** temp_var);
1081 void VisitArrayLiteral(ArrayLiteral* node, Variable** temp_var);
1082
1083 bool IsBindingContext() const { return IsBindingContext(context_); }
1084 bool IsInitializerContext() const { return context_ != ASSIGNMENT; }
1085 bool IsAssignmentContext() const { return IsAssignmentContext(context_); }
1086 bool IsAssignmentContext(PatternContext c) const;
1087 bool IsBindingContext(PatternContext c) const;
1088 PatternContext SetAssignmentContextIfNeeded(Expression* node);
1089 PatternContext SetInitializerContextIfNeeded(Expression* node);
1090
1060 Variable* CreateTempVar(Expression* value = nullptr); 1091 Variable* CreateTempVar(Expression* value = nullptr);
1061 1092
1062 AstNodeFactory* factory() const { return descriptor_->parser->factory(); } 1093 AstNodeFactory* factory() const { return parser_->factory(); }
1063 AstValueFactory* ast_value_factory() const { 1094 AstValueFactory* ast_value_factory() const {
1064 return descriptor_->parser->ast_value_factory(); 1095 return parser_->ast_value_factory();
1065 } 1096 }
1066 Zone* zone() const { return descriptor_->parser->zone(); } 1097 Zone* zone() const { return parser_->zone(); }
1098 Scope* scope() const { return scope_; }
1067 1099
1100 Scope* scope_;
1101 Parser* parser_;
1102 PatternContext context_;
1068 Expression* pattern_; 1103 Expression* pattern_;
1069 int initializer_position_; 1104 int initializer_position_;
1070 Block* block_; 1105 Block* block_;
1071 const DeclarationDescriptor* descriptor_; 1106 const DeclarationDescriptor* descriptor_;
1072 ZoneList<const AstRawString*>* names_; 1107 ZoneList<const AstRawString*>* names_;
1073 Expression* current_value_; 1108 Expression* current_value_;
1074 bool* ok_; 1109 bool* ok_;
1075 }; 1110 };
1076 1111
1077 1112
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 ZoneList<v8::internal::Expression*>* PrepareSpreadArguments( 1242 ZoneList<v8::internal::Expression*>* PrepareSpreadArguments(
1208 ZoneList<v8::internal::Expression*>* list); 1243 ZoneList<v8::internal::Expression*>* list);
1209 Expression* SpreadCall(Expression* function, 1244 Expression* SpreadCall(Expression* function,
1210 ZoneList<v8::internal::Expression*>* args, int pos); 1245 ZoneList<v8::internal::Expression*>* args, int pos);
1211 Expression* SpreadCallNew(Expression* function, 1246 Expression* SpreadCallNew(Expression* function,
1212 ZoneList<v8::internal::Expression*>* args, int pos); 1247 ZoneList<v8::internal::Expression*>* args, int pos);
1213 1248
1214 void SetLanguageMode(Scope* scope, LanguageMode mode); 1249 void SetLanguageMode(Scope* scope, LanguageMode mode);
1215 void RaiseLanguageMode(LanguageMode mode); 1250 void RaiseLanguageMode(LanguageMode mode);
1216 1251
1252 V8_INLINE void RewriteDestructuringAssignments();
1253
1254 friend class InitializerRewriter;
1255 void RewriteParameterInitializer(Expression* expr, Scope* scope);
1256
1217 Scanner scanner_; 1257 Scanner scanner_;
1218 PreParser* reusable_preparser_; 1258 PreParser* reusable_preparser_;
1219 Scope* original_scope_; // for ES5 function declarations in sloppy eval 1259 Scope* original_scope_; // for ES5 function declarations in sloppy eval
1220 Target* target_stack_; // for break, continue statements 1260 Target* target_stack_; // for break, continue statements
1221 ScriptCompiler::CompileOptions compile_options_; 1261 ScriptCompiler::CompileOptions compile_options_;
1222 ParseData* cached_parse_data_; 1262 ParseData* cached_parse_data_;
1223 1263
1224 PendingCompilationErrorHandler pending_error_handler_; 1264 PendingCompilationErrorHandler pending_error_handler_;
1225 1265
1226 // Other information which will be stored in Parser and moved to Isolate after 1266 // Other information which will be stored in Parser and moved to Isolate after
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 1442
1403 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { 1443 DoExpression* ParserTraits::ParseDoExpression(bool* ok) {
1404 return parser_->ParseDoExpression(ok); 1444 return parser_->ParseDoExpression(ok);
1405 } 1445 }
1406 1446
1407 1447
1408 } // namespace internal 1448 } // namespace internal
1409 } // namespace v8 1449 } // namespace v8
1410 1450
1411 #endif // V8_PARSING_PARSER_H_ 1451 #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