//===-- UsedHelperDeclFinder.h - AST-based call graph for helper decls ----===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_MOVE_USED_HELPER_DECL_FINDER_H #define LLVM_CLANG_TOOLS_EXTRA_CLANG_MOVE_USED_HELPER_DECL_FINDER_H #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Analysis/CallGraph.h" #include "llvm/ADT/DenseSet.h" #include <memory> #include <vector> namespace clang { namespace move { // A reference graph for finding used/unused helper declarations in a single // translation unit (e.g. old.cc). We don't reuse CallGraph in clang/Analysis // because that CallGraph only supports function declarations. // // Helper declarations include following types: // * function/variable/class definitions in an anonymous namespace. // * static function/variable definitions in a global/named namespace. // // The reference graph is a directed graph. Each node in the graph represents a // helper declaration in old.cc or a non-moved/moved declaration (e.g. class, // function) in old.h, which means each node is associated with a Decl. // // To construct the graph, we use AST matcher to find interesting Decls (usually // a pair of Caller and Callee), and add an edge from the Caller node to the // Callee node. // // Specially, for a class, it might have multiple declarations such methods // and member variables. We only use a single node to present this class, and // this node is associated with the class declaration (CXXRecordDecl). // // The graph has 3 types of edges: // 1. moved_decl => helper_decl // 2. non_moved_decl => helper_decl // 3. helper_decl => helper_decl class HelperDeclRefGraph { … }; // A builder helps to construct a call graph of helper declarations. class HelperDeclRGBuilder : public ast_matchers::MatchFinder::MatchCallback { … }; } // namespace move } // namespace clang #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_MOVE_USED_HELPER_DECL_FINDER_H