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 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 ASSIGNMENT, | 1070 ASSIGNMENT, |
1071 ASSIGNMENT_INITIALIZER | 1071 ASSIGNMENT_INITIALIZER |
1072 }; | 1072 }; |
1073 | 1073 |
1074 PatternContext context() const { return context_; } | 1074 PatternContext context() const { return context_; } |
1075 void set_context(PatternContext context) { context_ = context; } | 1075 void set_context(PatternContext context) { context_ = context; } |
1076 | 1076 |
1077 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) { | 1077 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) { |
1078 Expression* old_value = current_value_; | 1078 Expression* old_value = current_value_; |
1079 current_value_ = value; | 1079 current_value_ = value; |
| 1080 recursion_level_++; |
1080 pattern->Accept(this); | 1081 pattern->Accept(this); |
| 1082 recursion_level_--; |
1081 current_value_ = old_value; | 1083 current_value_ = old_value; |
1082 } | 1084 } |
1083 | 1085 |
1084 void VisitObjectLiteral(ObjectLiteral* node, Variable** temp_var); | 1086 void VisitObjectLiteral(ObjectLiteral* node, Variable** temp_var); |
1085 void VisitArrayLiteral(ArrayLiteral* node, Variable** temp_var); | 1087 void VisitArrayLiteral(ArrayLiteral* node, Variable** temp_var); |
1086 | 1088 |
1087 bool IsBindingContext() const { return IsBindingContext(context_); } | 1089 bool IsBindingContext() const { return IsBindingContext(context_); } |
1088 bool IsInitializerContext() const { return context_ != ASSIGNMENT; } | 1090 bool IsInitializerContext() const { return context_ != ASSIGNMENT; } |
1089 bool IsAssignmentContext() const { return IsAssignmentContext(context_); } | 1091 bool IsAssignmentContext() const { return IsAssignmentContext(context_); } |
1090 bool IsAssignmentContext(PatternContext c) const; | 1092 bool IsAssignmentContext(PatternContext c) const; |
1091 bool IsBindingContext(PatternContext c) const; | 1093 bool IsBindingContext(PatternContext c) const; |
| 1094 bool IsSubPattern() const { return recursion_level_ > 1; } |
1092 PatternContext SetAssignmentContextIfNeeded(Expression* node); | 1095 PatternContext SetAssignmentContextIfNeeded(Expression* node); |
1093 PatternContext SetInitializerContextIfNeeded(Expression* node); | 1096 PatternContext SetInitializerContextIfNeeded(Expression* node); |
1094 | 1097 |
1095 Variable* CreateTempVar(Expression* value = nullptr); | 1098 Variable* CreateTempVar(Expression* value = nullptr); |
1096 | 1099 |
1097 AstNodeFactory* factory() const { return parser_->factory(); } | 1100 AstNodeFactory* factory() const { return parser_->factory(); } |
1098 AstValueFactory* ast_value_factory() const { | 1101 AstValueFactory* ast_value_factory() const { |
1099 return parser_->ast_value_factory(); | 1102 return parser_->ast_value_factory(); |
1100 } | 1103 } |
1101 Zone* zone() const { return parser_->zone(); } | 1104 Zone* zone() const { return parser_->zone(); } |
1102 Scope* scope() const { return scope_; } | 1105 Scope* scope() const { return scope_; } |
1103 | 1106 |
1104 Scope* scope_; | 1107 Scope* scope_; |
1105 Parser* parser_; | 1108 Parser* parser_; |
1106 PatternContext context_; | 1109 PatternContext context_; |
1107 Expression* pattern_; | 1110 Expression* pattern_; |
1108 int initializer_position_; | 1111 int initializer_position_; |
1109 Block* block_; | 1112 Block* block_; |
1110 const DeclarationDescriptor* descriptor_; | 1113 const DeclarationDescriptor* descriptor_; |
1111 ZoneList<const AstRawString*>* names_; | 1114 ZoneList<const AstRawString*>* names_; |
1112 Expression* current_value_; | 1115 Expression* current_value_; |
| 1116 int recursion_level_; |
1113 bool* ok_; | 1117 bool* ok_; |
1114 }; | 1118 }; |
1115 | 1119 |
1116 | 1120 |
1117 void ParseVariableDeclarations(VariableDeclarationContext var_context, | 1121 void ParseVariableDeclarations(VariableDeclarationContext var_context, |
1118 DeclarationParsingResult* parsing_result, | 1122 DeclarationParsingResult* parsing_result, |
1119 bool* ok); | 1123 bool* ok); |
1120 Statement* ParseExpressionOrLabelledStatement( | 1124 Statement* ParseExpressionOrLabelledStatement( |
1121 ZoneList<const AstRawString*>* labels, bool* ok); | 1125 ZoneList<const AstRawString*>* labels, bool* ok); |
1122 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels, | 1126 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels, |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 | 1446 |
1443 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { | 1447 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { |
1444 return parser_->ParseDoExpression(ok); | 1448 return parser_->ParseDoExpression(ok); |
1445 } | 1449 } |
1446 | 1450 |
1447 | 1451 |
1448 } // namespace internal | 1452 } // namespace internal |
1449 } // namespace v8 | 1453 } // namespace v8 |
1450 | 1454 |
1451 #endif // V8_PARSING_PARSER_H_ | 1455 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |