1 // Copyright 2016 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_FUNCTION_LITERAL_ID_REINDEXER_H_ 6 #define V8_AST_AST_FUNCTION_LITERAL_ID_REINDEXER_H_ 7 8 #include "src/ast/ast-traversal-visitor.h" 9 #include "src/base/macros.h" 10 11 #ifdef DEBUG 12 #include <set> 13 #endif 14 15 namespace v8 { 16 namespace internal { 17 18 // Changes the ID of all FunctionLiterals in the given Expression by adding the 19 // given delta. 20 class AstFunctionLiteralIdReindexer final 21 : public AstTraversalVisitor<AstFunctionLiteralIdReindexer> { 22 public: 23 AstFunctionLiteralIdReindexer(size_t stack_limit, int delta); 24 AstFunctionLiteralIdReindexer(const AstFunctionLiteralIdReindexer&) = delete; 25 AstFunctionLiteralIdReindexer& operator=( 26 const AstFunctionLiteralIdReindexer&) = delete; 27 ~AstFunctionLiteralIdReindexer(); 28 29 void Reindex(Expression* pattern); 30 31 // AstTraversalVisitor implementation. 32 void VisitFunctionLiteral(FunctionLiteral* lit); 33 void VisitClassLiteral(ClassLiteral* lit); 34 35 private: 36 int delta_; 37 38 #ifdef DEBUG 39 // Visited set, only used in DCHECKs for verification. 40 std::set<FunctionLiteral*> visited_; 41 42 // Visit all function literals, checking if they have already been visited 43 // (are in the visited set). 44 void CheckVisited(Expression* expr); 45 #else CheckVisited(Expression * expr)46 void CheckVisited(Expression* expr) {} 47 #endif 48 }; 49 50 } // namespace internal 51 } // namespace v8 52 53 #endif // V8_AST_AST_FUNCTION_LITERAL_ID_REINDEXER_H_ 54