ast-function-literal-id-reindexer.h 1.49 KB
Newer Older
1 2 3 4
// Copyright 2016 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.

5 6
#ifndef V8_AST_AST_FUNCTION_LITERAL_ID_REINDEXER_H_
#define V8_AST_AST_FUNCTION_LITERAL_ID_REINDEXER_H_
7 8 9 10

#include "src/ast/ast-traversal-visitor.h"
#include "src/base/macros.h"

11 12 13 14
#ifdef DEBUG
#include <set>
#endif

15 16 17 18 19 20 21 22 23
namespace v8 {
namespace internal {

// Changes the ID of all FunctionLiterals in the given Expression by adding the
// given delta.
class AstFunctionLiteralIdReindexer final
    : public AstTraversalVisitor<AstFunctionLiteralIdReindexer> {
 public:
  AstFunctionLiteralIdReindexer(size_t stack_limit, int delta);
24 25 26
  AstFunctionLiteralIdReindexer(const AstFunctionLiteralIdReindexer&) = delete;
  AstFunctionLiteralIdReindexer& operator=(
      const AstFunctionLiteralIdReindexer&) = delete;
27 28 29 30 31 32
  ~AstFunctionLiteralIdReindexer();

  void Reindex(Expression* pattern);

  // AstTraversalVisitor implementation.
  void VisitFunctionLiteral(FunctionLiteral* lit);
33
  void VisitClassLiteral(ClassLiteral* lit);
34 35 36 37

 private:
  int delta_;

38 39 40 41 42 43 44 45 46 47
#ifdef DEBUG
  // Visited set, only used in DCHECKs for verification.
  std::set<FunctionLiteral*> visited_;

  // Visit all function literals, checking if they have already been visited
  // (are in the visited set).
  void CheckVisited(Expression* expr);
#else
  void CheckVisited(Expression* expr) {}
#endif
48 49 50 51 52
};

}  // namespace internal
}  // namespace v8

53
#endif  // V8_AST_AST_FUNCTION_LITERAL_ID_REINDEXER_H_