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_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 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 Scanner::Location bindings_loc; | 1020 Scanner::Location bindings_loc; |
1021 }; | 1021 }; |
1022 | 1022 |
1023 class PatternRewriter : private AstVisitor { | 1023 class PatternRewriter : private AstVisitor { |
1024 public: | 1024 public: |
1025 static void DeclareAndInitializeVariables( | 1025 static void DeclareAndInitializeVariables( |
1026 Block* block, const DeclarationDescriptor* declaration_descriptor, | 1026 Block* block, const DeclarationDescriptor* declaration_descriptor, |
1027 const DeclarationParsingResult::Declaration* declaration, | 1027 const DeclarationParsingResult::Declaration* declaration, |
1028 ZoneList<const AstRawString*>* names, bool* ok); | 1028 ZoneList<const AstRawString*>* names, bool* ok); |
1029 | 1029 |
| 1030 static Variable* RewriteDestructuringAssignment(Parser* parser, |
| 1031 Block* block, |
| 1032 Expression* pattern, |
| 1033 Expression* value, |
| 1034 Variable* result, bool* ok); |
| 1035 |
1030 void set_initializer_position(int pos) { initializer_position_ = pos; } | 1036 void set_initializer_position(int pos) { initializer_position_ = pos; } |
1031 | 1037 |
1032 private: | 1038 private: |
1033 PatternRewriter() {} | 1039 PatternRewriter() {} |
1034 | 1040 |
1035 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override; | 1041 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override; |
1036 // Visiting functions for AST nodes make this an AstVisitor. | 1042 // Visiting functions for AST nodes make this an AstVisitor. |
1037 AST_NODE_LIST(DECLARE_VISIT) | 1043 AST_NODE_LIST(DECLARE_VISIT) |
1038 #undef DECLARE_VISIT | 1044 #undef DECLARE_VISIT |
1039 virtual void Visit(AstNode* node) override; | 1045 virtual void Visit(AstNode* node) override; |
1040 | 1046 |
| 1047 enum PatternContext { BINDING = 0, INITIALIZER, ASSIGNMENT }; |
| 1048 |
| 1049 PatternContext context() const { return context_; } |
| 1050 void set_context(PatternContext ctx) { context_ = ctx; } |
| 1051 |
1041 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) { | 1052 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) { |
1042 Expression* old_value = current_value_; | 1053 Expression* old_value = current_value_; |
1043 current_value_ = value; | 1054 current_value_ = value; |
1044 pattern->Accept(this); | 1055 pattern->Accept(this); |
1045 current_value_ = old_value; | 1056 current_value_ = old_value; |
1046 } | 1057 } |
1047 | 1058 |
1048 Variable* CreateTempVar(Expression* value = nullptr); | 1059 Variable* CreateTempVar(Expression* value = nullptr); |
1049 | 1060 |
1050 AstNodeFactory* factory() const { return descriptor_->parser->factory(); } | 1061 AstNodeFactory* factory() const { return parser_->factory(); } |
| 1062 Parser* parser() const { return parser_; } |
| 1063 Scope* parser_scope() const { return parser_->scope_; } |
1051 AstValueFactory* ast_value_factory() const { | 1064 AstValueFactory* ast_value_factory() const { |
1052 return descriptor_->parser->ast_value_factory(); | 1065 return parser_->ast_value_factory(); |
1053 } | 1066 } |
1054 bool inside_with() const { return descriptor_->parser->inside_with(); } | 1067 bool inside_with() const { return parser_->inside_with(); } |
1055 Zone* zone() const { return descriptor_->parser->zone(); } | 1068 Zone* zone() const { return parser_->zone(); } |
1056 | 1069 |
| 1070 Parser* parser_; |
| 1071 PatternContext context_; |
1057 Expression* pattern_; | 1072 Expression* pattern_; |
1058 int initializer_position_; | 1073 int initializer_position_; |
1059 Block* block_; | 1074 Block* block_; |
1060 const DeclarationDescriptor* descriptor_; | 1075 const DeclarationDescriptor* descriptor_; |
1061 ZoneList<const AstRawString*>* names_; | 1076 ZoneList<const AstRawString*>* names_; |
1062 Expression* current_value_; | 1077 Expression* current_value_; |
1063 bool* ok_; | 1078 bool* ok_; |
| 1079 Variable* rhs_; |
1064 }; | 1080 }; |
1065 | 1081 |
1066 | 1082 |
1067 void ParseVariableDeclarations(VariableDeclarationContext var_context, | 1083 void ParseVariableDeclarations(VariableDeclarationContext var_context, |
1068 DeclarationParsingResult* parsing_result, | 1084 DeclarationParsingResult* parsing_result, |
1069 bool* ok); | 1085 bool* ok); |
1070 Statement* ParseExpressionOrLabelledStatement( | 1086 Statement* ParseExpressionOrLabelledStatement( |
1071 ZoneList<const AstRawString*>* labels, bool* ok); | 1087 ZoneList<const AstRawString*>* labels, bool* ok); |
1072 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels, | 1088 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels, |
1073 bool* ok); | 1089 bool* ok); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 Expression* subject, | 1121 Expression* subject, |
1106 Statement* body); | 1122 Statement* body); |
1107 Statement* DesugarLexicalBindingsInForStatement( | 1123 Statement* DesugarLexicalBindingsInForStatement( |
1108 Scope* inner_scope, bool is_const, ZoneList<const AstRawString*>* names, | 1124 Scope* inner_scope, bool is_const, ZoneList<const AstRawString*>* names, |
1109 ForStatement* loop, Statement* init, Expression* cond, Statement* next, | 1125 ForStatement* loop, Statement* init, Expression* cond, Statement* next, |
1110 Statement* body, bool* ok); | 1126 Statement* body, bool* ok); |
1111 | 1127 |
1112 void RewriteDoExpression(Expression* expr, bool* ok); | 1128 void RewriteDoExpression(Expression* expr, bool* ok); |
1113 | 1129 |
1114 Expression* DesugarDestructuringAssignment(Expression* expr); | 1130 Expression* DesugarDestructuringAssignment(Expression* expr); |
| 1131 Expression* DesugarDestructuringAssignmentInternal(Expression* expr, |
| 1132 Variable** result); |
1115 | 1133 |
1116 FunctionLiteral* ParseFunctionLiteral( | 1134 FunctionLiteral* ParseFunctionLiteral( |
1117 const AstRawString* name, Scanner::Location function_name_location, | 1135 const AstRawString* name, Scanner::Location function_name_location, |
1118 FunctionNameValidity function_name_validity, FunctionKind kind, | 1136 FunctionNameValidity function_name_validity, FunctionKind kind, |
1119 int function_token_position, FunctionLiteral::FunctionType type, | 1137 int function_token_position, FunctionLiteral::FunctionType type, |
1120 FunctionLiteral::ArityRestriction arity_restriction, | 1138 FunctionLiteral::ArityRestriction arity_restriction, |
1121 LanguageMode language_mode, bool* ok); | 1139 LanguageMode language_mode, bool* ok); |
1122 | 1140 |
1123 | 1141 |
1124 ClassLiteral* ParseClassLiteral(const AstRawString* name, | 1142 ClassLiteral* ParseClassLiteral(const AstRawString* name, |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 inline Expression* ParserTraits::RewriteDestructuringAssignment( | 1415 inline Expression* ParserTraits::RewriteDestructuringAssignment( |
1398 Expression* expr) { | 1416 Expression* expr) { |
1399 return parser_->DesugarDestructuringAssignment(expr); | 1417 return parser_->DesugarDestructuringAssignment(expr); |
1400 } | 1418 } |
1401 | 1419 |
1402 | 1420 |
1403 } // namespace internal | 1421 } // namespace internal |
1404 } // namespace v8 | 1422 } // namespace v8 |
1405 | 1423 |
1406 #endif // V8_PARSER_H_ | 1424 #endif // V8_PARSER_H_ |
OLD | NEW |