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

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: Remove facilities for rewriting the expression multiple ways 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
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 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 V8_INLINE ZoneList<v8::internal::Expression*>* PrepareSpreadArguments( 891 V8_INLINE ZoneList<v8::internal::Expression*>* PrepareSpreadArguments(
892 ZoneList<v8::internal::Expression*>* list); 892 ZoneList<v8::internal::Expression*>* list);
893 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {} 893 V8_INLINE void MaterializeUnspreadArgumentsLiterals(int count) {}
894 V8_INLINE Expression* SpreadCall(Expression* function, 894 V8_INLINE Expression* SpreadCall(Expression* function,
895 ZoneList<v8::internal::Expression*>* args, 895 ZoneList<v8::internal::Expression*>* args,
896 int pos); 896 int pos);
897 V8_INLINE Expression* SpreadCallNew(Expression* function, 897 V8_INLINE Expression* SpreadCallNew(Expression* function,
898 ZoneList<v8::internal::Expression*>* args, 898 ZoneList<v8::internal::Expression*>* args,
899 int pos); 899 int pos);
900 900
901 // Rewrite all DestructuringAssignments in the current FunctionState.
902 V8_INLINE void RewriteDestructuringAssignments();
903
904 V8_INLINE void QueueDestructuringAssignmentForRewriting(
905 Expression* assignment);
906
901 private: 907 private:
902 Parser* parser_; 908 Parser* parser_;
903 }; 909 };
904 910
905 911
906 class Parser : public ParserBase<ParserTraits> { 912 class Parser : public ParserBase<ParserTraits> {
907 public: 913 public:
908 explicit Parser(ParseInfo* info); 914 explicit Parser(ParseInfo* info);
909 ~Parser() { 915 ~Parser() {
910 delete reusable_preparser_; 916 delete reusable_preparser_;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 Scanner::Location bindings_loc; 1043 Scanner::Location bindings_loc;
1038 }; 1044 };
1039 1045
1040 class PatternRewriter : private AstVisitor { 1046 class PatternRewriter : private AstVisitor {
1041 public: 1047 public:
1042 static void DeclareAndInitializeVariables( 1048 static void DeclareAndInitializeVariables(
1043 Block* block, const DeclarationDescriptor* declaration_descriptor, 1049 Block* block, const DeclarationDescriptor* declaration_descriptor,
1044 const DeclarationParsingResult::Declaration* declaration, 1050 const DeclarationParsingResult::Declaration* declaration,
1045 ZoneList<const AstRawString*>* names, bool* ok); 1051 ZoneList<const AstRawString*>* names, bool* ok);
1046 1052
1053 static void RewriteDestructuringAssignment(Parser* parser,
1054 RewritableExpression* expr,
1055 Scope* Scope, bool* ok);
1056
1047 void set_initializer_position(int pos) { initializer_position_ = pos; } 1057 void set_initializer_position(int pos) { initializer_position_ = pos; }
1048 1058
1049 private: 1059 private:
1050 PatternRewriter() {} 1060 PatternRewriter() {}
1051 1061
1052 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override; 1062 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override;
1053 // Visiting functions for AST nodes make this an AstVisitor. 1063 // Visiting functions for AST nodes make this an AstVisitor.
1054 AST_NODE_LIST(DECLARE_VISIT) 1064 AST_NODE_LIST(DECLARE_VISIT)
1055 #undef DECLARE_VISIT 1065 #undef DECLARE_VISIT
1056 void Visit(AstNode* node) override; 1066 void Visit(AstNode* node) override;
1057 1067
1068 enum PatternContext {
1069 BINDING,
1070 INITIALIZER,
1071 ASSIGNMENT,
1072 ASSIGNMENT_INITIALIZER
1073 };
1074
1075 PatternContext context() const { return context_; }
1076 void set_context(PatternContext context) { context_ = context; }
1077
1058 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) { 1078 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) {
1059 Expression* old_value = current_value_; 1079 Expression* old_value = current_value_;
1060 current_value_ = value; 1080 current_value_ = value;
1061 pattern->Accept(this); 1081 pattern->Accept(this);
1062 current_value_ = old_value; 1082 current_value_ = old_value;
1063 } 1083 }
1064 1084
1085 void VisitObjectLiteral(ObjectLiteral* node, Variable** temp_var);
1086 void VisitArrayLiteral(ArrayLiteral* node, Variable** temp_var);
1087
1088 bool IsBindingContext() const { return IsBindingContext(context_); }
1089 bool IsInitializerContext() const { return context_ != ASSIGNMENT; }
1090 bool IsAssignmentContext() const { return IsAssignmentContext(context_); }
1091 bool IsAssignmentContext(PatternContext c) const;
1092 bool IsBindingContext(PatternContext c) const;
1093 PatternContext SetAssignmentContextIfNeeded(Expression* node);
1094 PatternContext SetInitializerContextIfNeeded(Expression* node);
1095
1065 Variable* CreateTempVar(Expression* value = nullptr); 1096 Variable* CreateTempVar(Expression* value = nullptr);
1066 1097
1067 AstNodeFactory* factory() const { return descriptor_->parser->factory(); } 1098 AstNodeFactory* factory() const { return parser_->factory(); }
1068 AstValueFactory* ast_value_factory() const { 1099 AstValueFactory* ast_value_factory() const {
1069 return descriptor_->parser->ast_value_factory(); 1100 return parser_->ast_value_factory();
1070 } 1101 }
1071 Zone* zone() const { return descriptor_->parser->zone(); } 1102 Zone* zone() const { return parser_->zone(); }
1103 Scope* scope() const { return scope_; }
1072 1104
1105 Scope* scope_;
1106 Parser* parser_;
1107 PatternContext context_;
1073 Expression* pattern_; 1108 Expression* pattern_;
1074 int initializer_position_; 1109 int initializer_position_;
1075 Block* block_; 1110 Block* block_;
1076 const DeclarationDescriptor* descriptor_; 1111 const DeclarationDescriptor* descriptor_;
1077 ZoneList<const AstRawString*>* names_; 1112 ZoneList<const AstRawString*>* names_;
1078 Expression* current_value_; 1113 Expression* current_value_;
1079 bool* ok_; 1114 bool* ok_;
1080 }; 1115 };
1081 1116
1082 1117
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 ZoneList<v8::internal::Expression*>* PrepareSpreadArguments( 1247 ZoneList<v8::internal::Expression*>* PrepareSpreadArguments(
1213 ZoneList<v8::internal::Expression*>* list); 1248 ZoneList<v8::internal::Expression*>* list);
1214 Expression* SpreadCall(Expression* function, 1249 Expression* SpreadCall(Expression* function,
1215 ZoneList<v8::internal::Expression*>* args, int pos); 1250 ZoneList<v8::internal::Expression*>* args, int pos);
1216 Expression* SpreadCallNew(Expression* function, 1251 Expression* SpreadCallNew(Expression* function,
1217 ZoneList<v8::internal::Expression*>* args, int pos); 1252 ZoneList<v8::internal::Expression*>* args, int pos);
1218 1253
1219 void SetLanguageMode(Scope* scope, LanguageMode mode); 1254 void SetLanguageMode(Scope* scope, LanguageMode mode);
1220 void RaiseLanguageMode(LanguageMode mode); 1255 void RaiseLanguageMode(LanguageMode mode);
1221 1256
1257 V8_INLINE void RewriteDestructuringAssignments();
1258
1259 friend class InitializerRewriter;
1260 void RewriteParameterInitializer(Expression* expr, Scope* scope);
1261
1222 Scanner scanner_; 1262 Scanner scanner_;
1223 PreParser* reusable_preparser_; 1263 PreParser* reusable_preparser_;
1224 Scope* original_scope_; // for ES5 function declarations in sloppy eval 1264 Scope* original_scope_; // for ES5 function declarations in sloppy eval
1225 Target* target_stack_; // for break, continue statements 1265 Target* target_stack_; // for break, continue statements
1226 ScriptCompiler::CompileOptions compile_options_; 1266 ScriptCompiler::CompileOptions compile_options_;
1227 ParseData* cached_parse_data_; 1267 ParseData* cached_parse_data_;
1228 1268
1229 PendingCompilationErrorHandler pending_error_handler_; 1269 PendingCompilationErrorHandler pending_error_handler_;
1230 1270
1231 // Other information which will be stored in Parser and moved to Isolate after 1271 // 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
1407 1447
1408 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { 1448 DoExpression* ParserTraits::ParseDoExpression(bool* ok) {
1409 return parser_->ParseDoExpression(ok); 1449 return parser_->ParseDoExpression(ok);
1410 } 1450 }
1411 1451
1412 1452
1413 } // namespace internal 1453 } // namespace internal
1414 } // namespace v8 1454 } // namespace v8
1415 1455
1416 #endif // V8_PARSING_PARSER_H_ 1456 #endif // V8_PARSING_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698