Chromium Code Reviews| Index: src/parser.h |
| diff --git a/src/parser.h b/src/parser.h |
| index 1a84ec4157aff1210e7a8aeb2458d6d4cd91a2e8..4d3673e3f684662ddc3f0bc7dc27bf3c753a8d40 100644 |
| --- a/src/parser.h |
| +++ b/src/parser.h |
| @@ -937,6 +937,69 @@ class Parser : public ParserBase<ParserTraits> { |
| Block* ParseVariableStatement(VariableDeclarationContext var_context, |
| ZoneList<const AstRawString*>* names, |
| bool* ok); |
| + |
| + |
| + class PatternMatcher : private AstVisitor { |
|
rossberg
2015/05/11 11:49:33
Can we call this PatternRewriter? It isn't a "matc
Dmitry Lomov (no reviews)
2015/05/11 12:52:58
Oh, good trick - I didn't realize it is allowed in
|
| + public: |
| + struct DeclarationDescriptor { |
| + Parser* parser; |
| + Scope* declaration_scope; |
| + Scope* scope; |
| + int initializer_position; |
| + VariableMode mode; |
| + ZoneList<const AstRawString*>* names; |
| + bool is_const; |
| + Block* block; |
| + bool needs_init; |
| + int pos; |
| + Token::Value init_op; |
| + int* nvars; |
| + |
| + Scope* initialization_scope() const { |
| + return is_const ? declaration_scope : scope; |
|
rossberg
2015/05/11 11:49:33
I think this function is not very meaningful as an
Dmitry Lomov (no reviews)
2015/05/11 12:52:57
Done.
|
| + } |
| + Zone* zone() const { return parser->zone(); } |
| + bool inside_with() const { return parser->inside_with(); } |
| + }; |
| + |
| + explicit PatternMatcher(const DeclarationDescriptor* decl, |
| + Expression* pattern) |
| + : decl_(decl), pattern_(pattern) {} |
| + |
| + PatternMatcher() : decl_(nullptr), pattern_(nullptr) {} |
| + |
| + bool IsSingleVariableBinding() const; |
| + const AstRawString* SingleName() const; |
| + |
| + void DeclareAndInitializeVariables(Expression* value, bool* ok); |
| + |
| + private: |
| +#define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override; |
| + // Visiting functions for AST nodes make this an AstVisitor. |
| + AST_NODE_LIST(DECLARE_VISIT) |
| +#undef DECLARE_VISIT |
| + virtual void Visit(AstNode* node) override; |
| + |
| + void RecurseIntoSubpattern(AstNode* pattern, Expression* value) { |
| + Expression* old_value = current_value_; |
| + current_value_ = value; |
| + pattern->Accept(this); |
| + current_value_ = old_value; |
| + } |
| + |
| + AstNodeFactory* factory() const { return decl_->parser->factory(); } |
| + AstValueFactory* ast_value_factory() const { |
| + return decl_->parser->ast_value_factory(); |
| + } |
| + Zone* zone() const { return decl_->parser->zone(); } |
| + |
| + const DeclarationDescriptor* decl_; |
| + Expression* pattern_; |
| + Expression* current_value_; |
| + bool* ok_; |
| + }; |
| + |
| + |
| Block* ParseVariableDeclarations(VariableDeclarationContext var_context, |
| int* num_decl, |
| ZoneList<const AstRawString*>* names, |