summaryrefslogtreecommitdiff
path: root/deps/v8/src/ast/ast-literal-reindexer.h
blob: b33e0c541c9b5adc18f13e4e30260d6c19f38a83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// 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_AST_AST_LITERAL_REINDEXER
#define V8_AST_AST_LITERAL_REINDEXER

#include "src/ast/ast.h"
#include "src/ast/scopes.h"

namespace v8 {
namespace internal {

class AstLiteralReindexer final : public AstVisitor<AstLiteralReindexer> {
 public:
  AstLiteralReindexer() : next_index_(0) {}

  int count() const { return next_index_; }
  void Reindex(Expression* pattern);

 private:
#define DEFINE_VISIT(type) void Visit##type(type* node);
  AST_NODE_LIST(DEFINE_VISIT)
#undef DEFINE_VISIT

  void VisitStatements(ZoneList<Statement*>* statements);
  void VisitDeclarations(ZoneList<Declaration*>* declarations);
  void VisitArguments(ZoneList<Expression*>* arguments);
  void VisitObjectLiteralProperty(ObjectLiteralProperty* property);

  void UpdateIndex(MaterializedLiteral* literal) {
    literal->literal_index_ = next_index_++;
  }

  int next_index_;

  DEFINE_AST_VISITOR_MEMBERS_WITHOUT_STACKOVERFLOW()
  DISALLOW_COPY_AND_ASSIGN(AstLiteralReindexer);
};
}  // namespace internal
}  // namespace v8

#endif  // V8_AST_AST_LITERAL_REINDEXER