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