blob: e2a71d3c471837bb8c27f635eec5c94f42a8b3be [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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_AST_AST_LITERAL_REINDEXER
6#define V8_AST_AST_LITERAL_REINDEXER
7
8#include "src/ast/ast.h"
9#include "src/ast/scopes.h"
10
11namespace v8 {
12namespace internal {
13
14class AstLiteralReindexer final : public AstVisitor {
15 public:
16 AstLiteralReindexer() : AstVisitor(), next_index_(0) {}
17
18 int count() const { return next_index_; }
19 void Reindex(Expression* pattern);
20
21 private:
22#define DEFINE_VISIT(type) void Visit##type(type* node) override;
23 AST_NODE_LIST(DEFINE_VISIT)
24#undef DEFINE_VISIT
25
26 void VisitStatements(ZoneList<Statement*>* statements) override;
27 void VisitDeclarations(ZoneList<Declaration*>* declarations) override;
28 void VisitArguments(ZoneList<Expression*>* arguments);
29 void VisitObjectLiteralProperty(ObjectLiteralProperty* property);
30
31 void UpdateIndex(MaterializedLiteral* literal) {
32 literal->literal_index_ = next_index_++;
33 }
34
35 void Visit(AstNode* node) override { node->Accept(this); }
36
37 int next_index_;
38
39 DISALLOW_COPY_AND_ASSIGN(AstLiteralReindexer);
40};
41} // namespace internal
42} // namespace v8
43
44#endif // V8_AST_AST_LITERAL_REINDEXER