17 #ifndef LLVM_CLANG_ANALYSIS_CALLGRAPH_H
18 #define LLVM_CLANG_ANALYSIS_CALLGRAPH_H
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/GraphTraits.h"
24 #include "llvm/ADT/SetVector.h"
37 typedef llvm::DenseMap<const Decl *, CallGraphNode *> FunctionMapTy;
40 FunctionMapTy FunctionMap;
77 unsigned size()
const {
return FunctionMap.size(); }
89 void print(raw_ostream &os)
const;
115 addNodeForDecl(MD,
true);
127 void addNodeForDecl(
Decl *D,
bool IsGlobal);
156 inline bool empty()
const {
return CalledFunctions.empty(); }
157 inline unsigned size()
const {
return CalledFunctions.size(); }
160 CalledFunctions.push_back(N);
165 void print(raw_ostream &os)
const;
173 template <>
struct GraphTraits<clang::CallGraphNode*> {
191 template <>
struct GraphTraits<const clang::CallGraphNode*> {
199 template <>
struct GraphTraits<clang::CallGraph*>
200 :
public GraphTraits<clang::CallGraphNode*> {
205 typedef std::pair<const clang::Decl*, clang::CallGraphNode*>
PairTy;
206 typedef std::pointer_to_unary_function<PairTy, clang::CallGraphNode&>
DerefFun;
214 return map_iterator(CG->
end(),
DerefFun(CGdereference));
225 template <>
struct GraphTraits<const clang::CallGraph*> :
226 public GraphTraits<const clang::CallGraphNode*> {
230 typedef std::pair<const clang::Decl*, clang::CallGraphNode*>
PairTy;
231 typedef std::pointer_to_unary_function<PairTy, clang::CallGraphNode&>
DerefFun;
240 return map_iterator(CG->
end(),
DerefFun(CGdereference));
The AST-based call graph.
clang::CallGraphNode NodeType
CallGraphNode * getOrInsertNode(Decl *)
Lookup the node for the given declaration. If none found, insert one into the graph.
static ChildIteratorType child_end(NodeType *N)
mapped_iterator< NodeType::iterator, CGNDerefFun > ChildIteratorType
bool TraverseDecl(Decl *D)
Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic ty...
static unsigned size(const clang::CallGraph *CG)
bool shouldWalkTypesOfTypeLocs() const
static NodeType * getEntryNode(const clang::CallGraph *CGN)
NodeType::const_iterator ChildIteratorType
static nodes_iterator nodes_begin(clang::CallGraph *CG)
const_iterator begin() const
llvm::SetVector< CallGraphNode * >::iterator nodes_iterator
std::pair< const clang::Decl *, clang::CallGraphNode * > PairTy
unsigned size() const
Get the number of nodes in the graph.
void addNodesForBlocks(DeclContext *D)
CallGraphNode * CallRecord
const_iterator end() const
static NodeType * getEntryNode(const clang::CallGraphNode *CGN)
static nodes_iterator nodes_begin(const clang::CallGraph *CG)
A class that does preorder depth-first traversal on the entire Clang AST and visits each node...
CallGraphNode * getRoot() const
void addCallee(CallGraphNode *N, CallGraph *CG)
void print(raw_ostream &os) const
SmallVectorImpl< CallRecord >::const_iterator const_iterator
static clang::CallGraphNode & CGdereference(PairTy P)
bool isGlobal() const
Determines whether this is a global function.
CallGraphNode * getNode(const Decl *) const
Lookup the node for the given declaration.
std::pointer_to_unary_function< CallRecordTy, clang::CallGraphNode * > CGNDerefFun
static ChildIteratorType child_end(NodeType *N)
static ChildIteratorType child_begin(NodeType *N)
bool VisitFunctionDecl(FunctionDecl *FD)
const clang::CallGraphNode NodeType
static nodes_iterator nodes_end(clang::CallGraph *CG)
FunctionMapTy::iterator iterator
bool TraverseStmt(Stmt *S)
static ChildIteratorType child_begin(NodeType *N)
static bool includeInGraph(const Decl *D)
Determine if a declaration should be included in the graph.
static nodes_iterator nodes_end(const clang::CallGraph *CG)
llvm::SetVector< CallGraphNode * >::const_iterator const_nodes_iterator
static NodeType * getEntryNode(clang::CallGraphNode *CGN)
const_iterator end() const
void print(raw_ostream &os) const
static NodeType * getEntryNode(clang::CallGraph *CGN)
iterator begin()
Iterators through all the callees/children of the node.
mapped_iterator< clang::CallGraph::const_iterator, DerefFun > nodes_iterator
std::pointer_to_unary_function< PairTy, clang::CallGraphNode & > DerefFun
static unsigned size(clang::CallGraph *CG)
static clang::CallGraphNode & CGdereference(PairTy P)
std::pointer_to_unary_function< PairTy, clang::CallGraphNode & > DerefFun
SmallVectorImpl< CallRecord >::iterator iterator
static clang::CallGraphNode * CGNDeref(CallRecordTy P)
mapped_iterator< clang::CallGraph::iterator, DerefFun > nodes_iterator
void addToCallGraph(Decl *D)
Populate the call graph with the functions in the given declaration.
const_iterator begin() const
bool VisitObjCMethodDecl(ObjCMethodDecl *MD)
Part of recursive declaration visitation.
FunctionMapTy::const_iterator const_iterator
std::pair< const clang::Decl *, clang::CallGraphNode * > PairTy
clang::CallGraphNode::CallRecord CallRecordTy