17 #include "llvm/ADT/PostOrderIterator.h"
18 #include "llvm/ADT/Statistic.h"
19 #include "llvm/Support/GraphWriter.h"
21 using namespace clang;
23 #define DEBUG_TYPE "CallGraph"
25 STATISTIC(NumObjCCallEdges,
"Number of Objective-C method call edges");
26 STATISTIC(NumBlockCallEdges,
"Number of block call edges");
37 : G(g), CallerNode(N) {}
39 void VisitStmt(
Stmt *
S) { VisitChildren(S); }
47 if (
BlockExpr *Block = dyn_cast<BlockExpr>(CEE)) {
49 return Block->getBlockDecl();
55 void addCalledDecl(
Decl *D) {
56 if (G->includeInGraph(D)) {
63 if (
Decl *D = getDeclFromCall(CE))
75 D = IDecl->lookupPrivateMethod(Sel);
77 D = IDecl->lookupPrivateClassMethod(Sel);
85 void VisitChildren(
Stmt *
S) {
86 for (
Stmt *SubStmt : S->children())
95 if (
BlockDecl *BD = dyn_cast<BlockDecl>(D))
96 addNodeForDecl(BD,
true);
98 for (
auto *I : D->
decls())
99 if (
auto *DC = dyn_cast<DeclContext>(I))
108 llvm::DeleteContainerSeconds(FunctionMap);
116 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
119 if (FD->isDependentContext())
123 if (II && II->
getName().startswith(
"__inline"))
130 void CallGraph::addNodeForDecl(
Decl* D,
bool IsGlobal) {
137 CGBuilder builder(
this, Node);
143 FunctionMapTy::const_iterator I = FunctionMap.find(F);
144 if (I == FunctionMap.end())
return nullptr;
149 if (F && !isa<ObjCMethodDecl>(F))
164 OS <<
" --- Call graph Dump --- \n";
168 llvm::ReversePostOrderTraversal<const clang::CallGraph*> RPOT(
this);
169 for (llvm::ReversePostOrderTraversal<const clang::CallGraph*>::rpo_iterator
170 I = RPOT.begin(), E = RPOT.end(); I != E; ++I) {
181 CE = N->
end(); CI != CE; ++CI) {
182 assert(*CI != Root &&
"No one can call the root node.");
196 llvm::ViewGraph(
this,
"CallGraph");
200 if (
const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(FD))
201 return ND->printName(os);
222 return ND->getNameAsString();
The AST-based call graph.
Defines the clang::ASTContext interface.
Smart pointer class that efficiently represents Objective-C method names.
STATISTIC(NumObjCCallEdges,"Number of Objective-C method call edges")
const Expr * getCallee() const
CallGraphNode * getOrInsertNode(Decl *)
Lookup the node for the given declaration. If none found, insert one into the graph.
DOTGraphTraits(bool isSimple=false)
void addNodesForBlocks(DeclContext *D)
Selector getSelector() const
Represents an ObjC class declaration.
CallGraphNode * getRoot() const
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
void addCallee(CallGraphNode *N, CallGraph *CG)
bool isInstanceMessage() const
Determine whether this is an instance message to either a computed object or to super.
void print(raw_ostream &os) const
friend class CallGraphNode
SmallVectorImpl< CallRecord >::const_iterator const_iterator
static std::string getNodeLabel(const CallGraphNode *Node, const CallGraph *CG)
StringRef getName() const
Return the actual identifier string.
CallGraphNode * getNode(const Decl *) const
Lookup the node for the given declaration.
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
An expression that sends a message to the given Objective-C object or class.
static bool includeInGraph(const Decl *D)
Determine if a declaration should be included in the graph.
virtual Stmt * getBody() const
ast_type_traits::DynTypedNode Node
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return 0.
void print(raw_ostream &os) const
iterator begin()
Iterators through all the callees/children of the node.
Expr * IgnoreParenImpCasts() LLVM_READONLY
virtual bool hasBody() const
Returns true if this Decl represents a declaration for a body of code, such as a function or method d...