Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Unified Diff: src/pattern-rewriter.h

Issue 1130623004: [destructuring] Implement basic binding destructuring infrastructure (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Patch for landing Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.cc ('k') | src/pattern-rewriter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pattern-rewriter.h
diff --git a/src/pattern-rewriter.h b/src/pattern-rewriter.h
new file mode 100644
index 0000000000000000000000000000000000000000..4fb90740723c1513a2df294ff53cf6ac16e02ba5
--- /dev/null
+++ b/src/pattern-rewriter.h
@@ -0,0 +1,82 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef V8_PATTERN_MATCHER_H_
+#define V8_PATTERN_MATCHER_H_
+
+#include "src/ast.h"
+#include "src/parser.h"
+
+namespace v8 {
+
+namespace internal {
+
+class Parser::PatternRewriter : private AstVisitor {
+ 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;
+ };
+
+ explicit PatternRewriter(const DeclarationDescriptor* decl,
+ Expression* pattern)
+ : decl_(decl),
+ pattern_(pattern),
+ current_value_(nullptr),
+ ok_(nullptr),
+ nvars_(nullptr) {}
+
+ PatternRewriter()
+ : decl_(nullptr),
+ pattern_(nullptr),
+ current_value_(nullptr),
+ ok_(nullptr),
+ nvars_(nullptr) {}
+
+ bool IsSingleVariableBinding() const;
+ const AstRawString* SingleName() const;
+
+ void DeclareAndInitializeVariables(Expression* value, int* nvars, 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();
+ }
+ bool inside_with() const { return decl_->parser->inside_with(); }
+ Zone* zone() const { return decl_->parser->zone(); }
+
+ const DeclarationDescriptor* decl_;
+ Expression* pattern_;
+ Expression* current_value_;
+ bool* ok_;
+ int* nvars_;
+};
+}
+} // namespace v8::internal
+
+
+#endif // V8_PATTERN_MATCHER_H_
« no previous file with comments | « src/parser.cc ('k') | src/pattern-rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698