OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_PATTERN_MATCHER_H_ |
| 6 #define V8_PATTERN_MATCHER_H_ |
| 7 |
| 8 #include "src/ast.h" |
| 9 #include "src/parser.h" |
| 10 |
| 11 namespace v8 { |
| 12 |
| 13 namespace internal { |
| 14 |
| 15 class Parser::PatternRewriter : private AstVisitor { |
| 16 public: |
| 17 struct DeclarationDescriptor { |
| 18 Parser* parser; |
| 19 Scope* declaration_scope; |
| 20 Scope* scope; |
| 21 Scope* initialization_scope; |
| 22 int initializer_position; |
| 23 VariableMode mode; |
| 24 ZoneList<const AstRawString*>* names; |
| 25 bool is_const; |
| 26 Block* block; |
| 27 bool needs_init; |
| 28 int pos; |
| 29 Token::Value init_op; |
| 30 int* nvars; |
| 31 }; |
| 32 |
| 33 explicit PatternRewriter(const DeclarationDescriptor* decl, |
| 34 Expression* pattern) |
| 35 : decl_(decl), pattern_(pattern) {} |
| 36 |
| 37 PatternRewriter() : decl_(nullptr), pattern_(nullptr) {} |
| 38 |
| 39 bool IsSingleVariableBinding() const; |
| 40 const AstRawString* SingleName() const; |
| 41 |
| 42 void DeclareAndInitializeVariables(Expression* value, bool* ok); |
| 43 |
| 44 private: |
| 45 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override; |
| 46 // Visiting functions for AST nodes make this an AstVisitor. |
| 47 AST_NODE_LIST(DECLARE_VISIT) |
| 48 #undef DECLARE_VISIT |
| 49 virtual void Visit(AstNode* node) override; |
| 50 |
| 51 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) { |
| 52 Expression* old_value = current_value_; |
| 53 current_value_ = value; |
| 54 pattern->Accept(this); |
| 55 current_value_ = old_value; |
| 56 } |
| 57 |
| 58 AstNodeFactory* factory() const { return decl_->parser->factory(); } |
| 59 AstValueFactory* ast_value_factory() const { |
| 60 return decl_->parser->ast_value_factory(); |
| 61 } |
| 62 bool inside_with() const { return decl_->parser->inside_with(); } |
| 63 Zone* zone() const { return decl_->parser->zone(); } |
| 64 |
| 65 const DeclarationDescriptor* decl_; |
| 66 Expression* pattern_; |
| 67 Expression* current_value_; |
| 68 bool* ok_; |
| 69 }; |
| 70 } |
| 71 } // namespace v8::internal |
| 72 |
| 73 |
| 74 #endif // V8_PATTERN_MATCHER_H_ |
OLD | NEW |