17#ifndef LLVM_CLANG_ANALYSIS_CALLGRAPH_H
18#define LLVM_CLANG_ANALYSIS_CALLGRAPH_H
23#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/GraphTraits.h"
25#include "llvm/ADT/STLExtras.h"
26#include "llvm/ADT/SetVector.h"
27#include "llvm/ADT/SmallVector.h"
28#include "llvm/ADT/iterator_range.h"
47 llvm::DenseMap<const Decl *, std::unique_ptr<CallGraphNode>>;
50 FunctionMapTy FunctionMap;
93 unsigned size()
const {
return FunctionMap.size(); }
105 void print(raw_ostream &os)
const;
131 addNodeForDecl(MD,
true);
141 void addNodeForDecl(
Decl *D,
bool IsGlobal);
181 return llvm::make_range(
begin(),
end());
183 llvm::iterator_range<const_iterator>
callees()
const {
184 return llvm::make_range(
begin(),
end());
187 bool empty()
const {
return CalledFunctions.empty(); }
188 unsigned size()
const {
return CalledFunctions.size(); }
198 void print(raw_ostream &os)
const;
214template <>
struct DenseMapInfo<
clang::CallGraphNode::CallRecord> {
217 DenseMapInfo<clang::CallGraphNode *>::getEmptyKey(),
218 DenseMapInfo<clang::Expr *>::getEmptyKey());
223 DenseMapInfo<clang::CallGraphNode *>::getTombstoneKey(),
224 DenseMapInfo<clang::Expr *>::getTombstoneKey());
230 return DenseMapInfo<clang::CallGraphNode *>::getHashValue(Val.
Callee);
240template <>
struct GraphTraits<
clang::CallGraphNode*> {
250template <>
struct GraphTraits<const
clang::CallGraphNode*> {
260template <>
struct GraphTraits<
clang::CallGraph*>
261 :
public GraphTraits<clang::CallGraphNode*> {
267 CGGetValue(clang::CallGraph::const_iterator::value_type &P) {
268 return P.second.get();
286template <>
struct GraphTraits<const
clang::CallGraph*> :
287 public GraphTraits<const clang::CallGraphNode*> {
293 CGGetValue(clang::CallGraph::const_iterator::value_type &P) {
294 return P.second.get();
SmallVectorImpl< CallRecord >::iterator iterator
FunctionDecl * getDefinition() const
llvm::iterator_range< const_iterator > callees() const
const_iterator begin() const
llvm::iterator_range< iterator > callees()
Iterator access to callees/children of the node.
iterator begin()
Iterators through all the callees/children of the node.
void print(raw_ostream &os) const
const_iterator end() const
SmallVectorImpl< CallRecord >::const_iterator const_iterator
void addCallee(CallRecord Call)
The AST-based call graph.
bool TraverseStmt(Stmt *S) override
const_iterator begin() const
void addToCallGraph(Decl *D)
Populate the call graph with the functions in the given declaration.
CallGraphNode * getNode(const Decl *) const
Lookup the node for the given declaration.
iterator begin()
Iterators through all the elements in the graph.
void addNodesForBlocks(DeclContext *D)
bool VisitFunctionDecl(FunctionDecl *FD) override
Part of recursive declaration visitation.
CallGraphNode * getOrInsertNode(Decl *)
Lookup the node for the given declaration.
FunctionMapTy::const_iterator const_iterator
llvm::SetVector< CallGraphNode * >::iterator nodes_iterator
Iterators through all the nodes of the graph that have no parent.
FunctionMapTy::iterator iterator
llvm::SetVector< CallGraphNode * >::const_iterator const_nodes_iterator
void print(raw_ostream &os) const
friend class CallGraphNode
static bool includeCalleeInGraph(const Decl *D)
Determine if a declaration should be included in the graph for the purposes of being a callee.
CallGraphNode * getRoot() const
Get the virtual root of the graph, all the functions available externally are represented as callees ...
unsigned size() const
Get the number of nodes in the graph.
bool VisitObjCMethodDecl(ObjCMethodDecl *MD) override
Part of recursive declaration visitation.
const_iterator end() const
static bool includeInGraph(const Decl *D)
Determine if a declaration should be included in the graph.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
virtual bool TraverseDecl(MaybeConst< Decl > *D)
This represents one expression.
Represents a function declaration or definition.
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
FunctionDecl * getDefinition()
Get the definition for this declaration.
bool isGlobal() const
Determines whether this is a global function.
ObjCMethodDecl - Represents an instance or class method declaration.
Stmt - This represents one statement.
The JSON file list parser is used to communicate input to InstallAPI.
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor
Diagnostic wrappers for TextAPI types for error reporting.
CallRecord(CallGraphNode *Callee_, Expr *CallExpr_)
static clang::CallGraphNode::CallRecord getTombstoneKey()
static unsigned getHashValue(const clang::CallGraphNode::CallRecord &Val)
static bool isEqual(const clang::CallGraphNode::CallRecord &LHS, const clang::CallGraphNode::CallRecord &RHS)
static clang::CallGraphNode::CallRecord getEmptyKey()
clang::CallGraphNode NodeType
NodeType::iterator ChildIteratorType
clang::CallGraphNode * NodeRef
static ChildIteratorType child_begin(NodeType *N)
static NodeType * getEntryNode(clang::CallGraphNode *CGN)
static ChildIteratorType child_end(NodeType *N)
static clang::CallGraphNode * CGGetValue(clang::CallGraph::const_iterator::value_type &P)
static NodeType * getEntryNode(clang::CallGraph *CGN)
static nodes_iterator nodes_end(clang::CallGraph *CG)
static nodes_iterator nodes_begin(clang::CallGraph *CG)
static unsigned size(clang::CallGraph *CG)
mapped_iterator< clang::CallGraph::iterator, decltype(&CGGetValue)> nodes_iterator
NodeType::const_iterator ChildIteratorType
static ChildIteratorType child_begin(NodeType *N)
const clang::CallGraphNode NodeType
static ChildIteratorType child_end(NodeType *N)
static NodeType * getEntryNode(const clang::CallGraphNode *CGN)
const clang::CallGraphNode * NodeRef
static nodes_iterator nodes_begin(const clang::CallGraph *CG)
static unsigned size(const clang::CallGraph *CG)
static clang::CallGraphNode * CGGetValue(clang::CallGraph::const_iterator::value_type &P)
static NodeType * getEntryNode(const clang::CallGraph *CGN)
mapped_iterator< clang::CallGraph::const_iterator, decltype(&CGGetValue)> nodes_iterator
static nodes_iterator nodes_end(const clang::CallGraph *CG)