clang: include/clang/Analysis/CallGraph.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17#ifndef LLVM_CLANG_ANALYSIS_CALLGRAPH_H

18#define LLVM_CLANG_ANALYSIS_CALLGRAPH_H

19

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"

29#include

30

32

33class CallGraphNode;

35class DeclContext;

36class Stmt;

37

38

39

40

41

42

45

46 using FunctionMapTy =

47 llvm::DenseMap<const Decl *, std::unique_ptr>;

48

49

50 FunctionMapTy FunctionMap;

51

52

54

55public:

58

59

60

61

62

65 }

66

67

69

70

71

72

74

75

77

78

79

81

82 using iterator = FunctionMapTy::iterator;

84

85

86

91

92

93 unsigned size() const { return FunctionMap.size(); }

94

95

96

98

99

100

101

102 using nodes_iterator = llvm::SetVector<CallGraphNode *>::iterator;

104

105 void print(raw_ostream &os) const;

106 void dump() const;

108

110

111

112

114

115

117

119

120

121

122 addNodeForDecl(FD, FD->isGlobal());

123 }

124 return true;

125 }

126

127

131 addNodeForDecl(MD, true);

132 }

133 return true;

134 }

135

136

138

139private:

140

141 void addNodeForDecl(Decl *D, bool IsGlobal);

142};

143

145public:

149

151

154

155

156

158 };

159

160private:

161

163

164

166

167public:

169

172

173

178

179

180 llvm::iterator_range callees() {

181 return llvm::make_range(begin(), end());

182 }

183 llvm::iterator_range<const_iterator> callees() const {

184 return llvm::make_range(begin(), end());

185 }

186

187 bool empty() const { return CalledFunctions.empty(); }

188 unsigned size() const { return CalledFunctions.size(); }

189

191

193

196 }

197

198 void print(raw_ostream &os) const;

199 void dump() const;

200};

201

202

203

207}

208

209}

210

211namespace llvm {

212

213

214template <> struct DenseMapInfo<clang::CallGraphNode::CallRecord> {

217 DenseMapInfo<clang::CallGraphNode *>::getEmptyKey(),

218 DenseMapInfo<clang::Expr *>::getEmptyKey());

219 }

220

223 DenseMapInfo<clang::CallGraphNode *>::getTombstoneKey(),

224 DenseMapInfo<clang::Expr *>::getTombstoneKey());

225 }

226

228

229

230 return DenseMapInfo<clang::CallGraphNode *>::getHashValue(Val.Callee);

231 }

232

235 return LHS == RHS;

236 }

237};

238

239

240template <> struct GraphTraits<clang::CallGraphNode*> {

244

248};

249

250template <> struct GraphTraits<const clang::CallGraphNode*> {

254

258};

259

260template <> struct GraphTraits<clang::CallGraph*>

261 : public GraphTraitsclang::CallGraphNode\* {

263 return CGN->getRoot();

264 }

265

267 CGGetValue(clang::CallGraph::const_iterator::value_type &P) {

268 return P.second.get();

269 }

270

271

274

277 }

278

281 }

282

284};

285

286template <> struct GraphTraits<const clang::CallGraph*> :

287 public GraphTraits<const clang::CallGraphNode*> {

290 }

291

293 CGGetValue(clang::CallGraph::const_iterator::value_type &P) {

294 return P.second.get();

295 }

296

297

300

303 }

304

307 }

308

310};

311

312}

313

314#endif

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) override

Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dy...

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

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.

Recursive AST visitor that supports extension via dynamic dispatch.

virtual bool TraverseDecl(Decl *D)

Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic ty...

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.

@ 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)