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 int initializer_position; | |
22 VariableMode mode; | |
23 ZoneList<const AstRawString*>* names; | |
24 bool is_const; | |
25 Block* block; | |
26 bool needs_init; | |
27 int pos; | |
28 Token::Value init_op; | |
29 }; | |
30 | |
31 explicit PatternRewriter(const DeclarationDescriptor* decl, | |
32 Expression* pattern) | |
33 : decl_(decl), | |
34 pattern_(pattern), | |
35 current_value_(nullptr), | |
36 ok_(nullptr), | |
37 nvars_(nullptr) {} | |
38 | |
39 PatternRewriter() | |
40 : decl_(nullptr), | |
41 pattern_(nullptr), | |
42 current_value_(nullptr), | |
43 ok_(nullptr), | |
44 nvars_(nullptr) {} | |
45 | |
46 bool IsSingleVariableBinding() const; | |
47 const AstRawString* SingleName() const; | |
48 | |
49 void DeclareAndInitializeVariables(Expression* value, int* nvars, bool* ok); | |
50 | |
51 private: | |
52 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override; | |
53 // Visiting functions for AST nodes make this an AstVisitor. | |
54 AST_NODE_LIST(DECLARE_VISIT) | |
55 #undef DECLARE_VISIT | |
56 virtual void Visit(AstNode* node) override; | |
57 | |
58 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) { | |
59 Expression* old_value = current_value_; | |
60 current_value_ = value; | |
61 pattern->Accept(this); | |
62 current_value_ = old_value; | |
63 } | |
64 | |
65 AstNodeFactory* factory() const { return decl_->parser->factory(); } | |
66 AstValueFactory* ast_value_factory() const { | |
67 return decl_->parser->ast_value_factory(); | |
68 } | |
69 bool inside_with() const { return decl_->parser->inside_with(); } | |
70 Zone* zone() const { return decl_->parser->zone(); } | |
71 | |
72 const DeclarationDescriptor* decl_; | |
73 Expression* pattern_; | |
74 Expression* current_value_; | |
75 bool* ok_; | |
76 int* nvars_; | |
77 }; | |
78 } | |
79 } // namespace v8::internal | |
80 | |
81 | |
82 #endif // V8_PATTERN_MATCHER_H_ | |
OLD | NEW |