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/STLExtras.h"
25#include "llvm/ADT/SetVector.h"
26#include "llvm/ADT/SmallVector.h"
27#include "llvm/ADT/iterator_range.h"
46 llvm::DenseMap<const Decl *, std::unique_ptr<CallGraphNode>>;
49 FunctionMapTy FunctionMap;
92 unsigned size()
const {
return FunctionMap.size(); }
104 void print(raw_ostream &os)
const;
130 addNodeForDecl(MD,
true);
144 void addNodeForDecl(
Decl *
D,
bool IsGlobal);
184 return llvm::make_range(
begin(),
end());
186 llvm::iterator_range<const_iterator>
callees()
const {
187 return llvm::make_range(
begin(),
end());
190 bool empty()
const {
return CalledFunctions.empty(); }
191 unsigned size()
const {
return CalledFunctions.size(); }
201 void print(raw_ostream &os)
const;
217template <>
struct DenseMapInfo<
clang::CallGraphNode::CallRecord> {
220 DenseMapInfo<clang::CallGraphNode *>::getEmptyKey(),
221 DenseMapInfo<clang::Expr *>::getEmptyKey());
226 DenseMapInfo<clang::CallGraphNode *>::getTombstoneKey(),
227 DenseMapInfo<clang::Expr *>::getTombstoneKey());
233 return DenseMapInfo<clang::CallGraphNode *>::getHashValue(Val.
Callee);
243template <>
struct GraphTraits<
clang::CallGraphNode*> {
253template <>
struct GraphTraits<const
clang::CallGraphNode*> {
263template <>
struct GraphTraits<
clang::CallGraph*>
264 :
public GraphTraits<clang::CallGraphNode*> {
271 return P.second.get();
289template <>
struct GraphTraits<const
clang::CallGraph*> :
290 public GraphTraits<const clang::CallGraphNode*> {
297 return P.second.get();
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
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)
bool VisitObjCMethodDecl(ObjCMethodDecl *MD)
Part of recursive declaration visitation.
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.
bool VisitFunctionDecl(FunctionDecl *FD)
Part of recursive declaration visitation.
bool shouldWalkTypesOfTypeLocs() const
iterator begin()
Iterators through all the elements in the graph.
void addNodesForBlocks(DeclContext *D)
CallGraphNode * getOrInsertNode(Decl *)
Lookup the node for the given declaration.
FunctionMapTy::const_iterator const_iterator
bool shouldVisitImplicitCode() const
bool shouldVisitTemplateInstantiations() const
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
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.
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.
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.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
bool TraverseDecl(Decl *D)
Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic ty...
Stmt - This represents one statement.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
The JSON file list parser is used to communicate input to InstallAPI.
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
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()
NodeType::iterator ChildIteratorType
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)
static ChildIteratorType child_end(NodeType *N)
static NodeType * getEntryNode(const clang::CallGraphNode *CGN)
static nodes_iterator nodes_begin(const clang::CallGraph *CG)
static unsigned size(const clang::CallGraph *CG)
mapped_iterator< clang::CallGraph::const_iterator, decltype(&CGGetValue)> nodes_iterator
static clang::CallGraphNode * CGGetValue(clang::CallGraph::const_iterator::value_type &P)
static NodeType * getEntryNode(const clang::CallGraph *CGN)
static nodes_iterator nodes_end(const clang::CallGraph *CG)