clang 20.0.0git
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
clang::CallGraph Class Reference

The AST-based call graph. More...

#include "clang/Analysis/CallGraph.h"

Inheritance diagram for clang::CallGraph:
Inheritance graph
[legend]

Public Types

using iterator = FunctionMapTy::iterator
 
using const_iterator = FunctionMapTy::const_iterator
 
using nodes_iterator = llvm::SetVector< CallGraphNode * >::iterator
 Iterators through all the nodes of the graph that have no parent.
 
using const_nodes_iterator = llvm::SetVector< CallGraphNode * >::const_iterator
 
- Public Types inherited from clang::RecursiveASTVisitor< CallGraph >
typedef SmallVectorImpl< llvm::PointerIntPair< Stmt *, 1, bool > > DataRecursionQueue
 A queue used for performing data recursion over statements.
 

Public Member Functions

 CallGraph ()
 
 ~CallGraph ()
 
void addToCallGraph (Decl *D)
 Populate the call graph with the functions in the given declaration.
 
CallGraphNodegetNode (const Decl *) const
 Lookup the node for the given declaration.
 
CallGraphNodegetOrInsertNode (Decl *)
 Lookup the node for the given declaration.
 
iterator begin ()
 Iterators through all the elements in the graph.
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
unsigned size () const
 Get the number of nodes in the graph.
 
CallGraphNodegetRoot () const
 Get the virtual root of the graph, all the functions available externally are represented as callees of the node.
 
void print (raw_ostream &os) const
 
void dump () const
 
void viewGraph () const
 
void addNodesForBlocks (DeclContext *D)
 
bool VisitFunctionDecl (FunctionDecl *FD)
 Part of recursive declaration visitation.
 
bool VisitObjCMethodDecl (ObjCMethodDecl *MD)
 Part of recursive declaration visitation.
 
bool TraverseStmt (Stmt *S)
 
bool shouldWalkTypesOfTypeLocs () const
 
bool shouldVisitTemplateInstantiations () const
 
bool shouldVisitImplicitCode () const
 
- Public Member Functions inherited from clang::RecursiveASTVisitor< CallGraph >
CallGraphgetDerived ()
 Return a reference to the derived class.
 
bool shouldVisitTemplateInstantiations () const
 Return whether this visitor should recurse into template instantiations.
 
bool shouldWalkTypesOfTypeLocs () const
 Return whether this visitor should recurse into the types of TypeLocs.
 
bool shouldVisitImplicitCode () const
 Return whether this visitor should recurse into implicit code, e.g., implicit constructors and destructors.
 
bool shouldVisitLambdaBody () const
 Return whether this visitor should recurse into lambda body.
 
bool shouldTraversePostOrder () const
 Return whether this visitor should traverse post-order.
 
bool TraverseAST (ASTContext &AST)
 Recursively visits an entire AST, starting from the TranslationUnitDecl.
 
bool TraverseStmt (Stmt *S, DataRecursionQueue *Queue=nullptr)
 Recursively visit a statement or expression, by dispatching to Traverse*() based on the argument's dynamic type.
 
bool dataTraverseStmtPre (Stmt *S)
 Invoked before visiting a statement or expression via data recursion.
 
bool dataTraverseStmtPost (Stmt *S)
 Invoked after visiting a statement or expression via data recursion.
 
bool TraverseType (QualType T)
 Recursively visit a type, by dispatching to Traverse*Type() based on the argument's getTypeClass() property.
 
bool TraverseTypeLoc (TypeLoc TL)
 Recursively visit a type with location, by dispatching to Traverse*TypeLoc() based on the argument type's getTypeClass() property.
 
bool TraverseAttr (Attr *At)
 Recursively visit an attribute, by dispatching to Traverse*Attr() based on the argument's dynamic type.
 
bool TraverseDecl (Decl *D)
 Recursively visit a declaration, by dispatching to Traverse*Decl() based on the argument's dynamic type.
 
bool TraverseNestedNameSpecifier (NestedNameSpecifier *NNS)
 Recursively visit a C++ nested-name-specifier.
 
bool TraverseNestedNameSpecifierLoc (NestedNameSpecifierLoc NNS)
 Recursively visit a C++ nested-name-specifier with location information.
 
bool TraverseDeclarationNameInfo (DeclarationNameInfo NameInfo)
 Recursively visit a name with its location information.
 
bool TraverseTemplateName (TemplateName Template)
 Recursively visit a template name and dispatch to the appropriate method.
 
bool TraverseTemplateArgument (const TemplateArgument &Arg)
 Recursively visit a template argument and dispatch to the appropriate method for the argument type.
 
bool TraverseTemplateArgumentLoc (const TemplateArgumentLoc &ArgLoc)
 Recursively visit a template argument location and dispatch to the appropriate method for the argument type.
 
bool TraverseTemplateArguments (ArrayRef< TemplateArgument > Args)
 Recursively visit a set of template arguments.
 
bool TraverseCXXBaseSpecifier (const CXXBaseSpecifier &Base)
 Recursively visit a base specifier.
 
bool TraverseConstructorInitializer (CXXCtorInitializer *Init)
 Recursively visit a constructor initializer.
 
bool TraverseLambdaCapture (LambdaExpr *LE, const LambdaCapture *C, Expr *Init)
 Recursively visit a lambda capture.
 
bool TraverseSynOrSemInitListExpr (InitListExpr *S, DataRecursionQueue *Queue=nullptr)
 Recursively visit the syntactic or semantic form of an initialization list.
 
bool TraverseObjCProtocolLoc (ObjCProtocolLoc ProtocolLoc)
 Recursively visit an Objective-C protocol reference with location information.
 
bool TraverseConceptReference (ConceptReference *CR)
 Recursively visit concept reference with location information.
 
bool VisitConceptReference (ConceptReference *CR)
 
bool VisitAttr (Attr *A)
 
Stmt::child_range getStmtChildren (Stmt *S)
 
bool WalkUpFromStmt (Stmt *S)
 
bool VisitStmt (Stmt *S)
 
bool WalkUpFromType (Type *T)
 
bool VisitType (Type *T)
 
bool WalkUpFromTypeLoc (TypeLoc TL)
 
bool VisitTypeLoc (TypeLoc TL)
 
bool WalkUpFromQualifiedTypeLoc (QualifiedTypeLoc TL)
 
bool VisitQualifiedTypeLoc (QualifiedTypeLoc TL)
 
bool WalkUpFromUnqualTypeLoc (UnqualTypeLoc TL)
 
bool VisitUnqualTypeLoc (UnqualTypeLoc TL)
 
bool WalkUpFromDecl (Decl *D)
 
bool VisitDecl (Decl *D)
 
bool canIgnoreChildDeclWhileTraversingDeclContext (const Decl *Child)
 
bool TraverseTypeConstraint (const TypeConstraint *C)
 
bool TraverseConceptRequirement (concepts::Requirement *R)
 
bool TraverseConceptTypeRequirement (concepts::TypeRequirement *R)
 
bool TraverseConceptExprRequirement (concepts::ExprRequirement *R)
 
bool TraverseConceptNestedRequirement (concepts::NestedRequirement *R)
 
bool dataTraverseNode (Stmt *S, DataRecursionQueue *Queue)
 

Static Public Member Functions

static bool includeInGraph (const Decl *D)
 Determine if a declaration should be included in the graph.
 
static bool includeCalleeInGraph (const Decl *D)
 Determine if a declaration should be included in the graph for the purposes of being a callee.
 

Friends

class CallGraphNode
 

Detailed Description

The AST-based call graph.

The call graph extends itself with the given declarations by implementing the recursive AST visitor, which constructs the graph by visiting the given declarations.

Definition at line 42 of file CallGraph.h.

Member Typedef Documentation

◆ const_iterator

using clang::CallGraph::const_iterator = FunctionMapTy::const_iterator

Definition at line 82 of file CallGraph.h.

◆ const_nodes_iterator

Definition at line 102 of file CallGraph.h.

◆ iterator

using clang::CallGraph::iterator = FunctionMapTy::iterator

Definition at line 81 of file CallGraph.h.

◆ nodes_iterator

Iterators through all the nodes of the graph that have no parent.

These are the unreachable nodes, which are either unused or are due to us failing to add a call edge due to the analysis imprecision.

Definition at line 101 of file CallGraph.h.

Constructor & Destructor Documentation

◆ CallGraph()

CallGraph::CallGraph ( )

Definition at line 149 of file CallGraph.cpp.

References getOrInsertNode().

◆ ~CallGraph()

CallGraph::~CallGraph ( )
default

Member Function Documentation

◆ addNodesForBlocks()

void CallGraph::addNodesForBlocks ( DeclContext D)

Definition at line 140 of file CallGraph.cpp.

References addNodesForBlocks(), and D.

Referenced by addNodesForBlocks(), VisitFunctionDecl(), and VisitObjCMethodDecl().

◆ addToCallGraph()

void clang::CallGraph::addToCallGraph ( Decl D)
inline

Populate the call graph with the functions in the given declaration.

Recursively walks the declaration to find all the dependent Decls as well.

Definition at line 62 of file CallGraph.h.

References D, and clang::RecursiveASTVisitor< CallGraph >::TraverseDecl().

◆ begin() [1/2]

iterator clang::CallGraph::begin ( )
inline

Iterators through all the elements in the graph.

Note, this gives non-deterministic order.

Definition at line 86 of file CallGraph.h.

Referenced by llvm::GraphTraits< clang::CallGraph * >::nodes_begin(), and llvm::GraphTraits< const clang::CallGraph * >::nodes_begin().

◆ begin() [2/2]

const_iterator clang::CallGraph::begin ( ) const
inline

Definition at line 88 of file CallGraph.h.

◆ dump()

LLVM_DUMP_METHOD void CallGraph::dump ( ) const

Definition at line 246 of file CallGraph.cpp.

References print().

◆ end() [1/2]

iterator clang::CallGraph::end ( )
inline

◆ end() [2/2]

const_iterator clang::CallGraph::end ( ) const
inline

Definition at line 89 of file CallGraph.h.

◆ getNode()

CallGraphNode * CallGraph::getNode ( const Decl F) const

Lookup the node for the given declaration.

Definition at line 197 of file CallGraph.cpp.

◆ getOrInsertNode()

CallGraphNode * CallGraph::getOrInsertNode ( Decl F)

Lookup the node for the given declaration.

If none found, insert one into the graph.

Definition at line 203 of file CallGraph.cpp.

References clang::CallGraphNode::addCallee(), clang::DynTypedNode::get(), clang::Decl::getCanonicalDecl(), and Node.

Referenced by CallGraph().

◆ getRoot()

CallGraphNode * clang::CallGraph::getRoot ( ) const
inline

Get the virtual root of the graph, all the functions available externally are represented as callees of the node.

Definition at line 96 of file CallGraph.h.

Referenced by llvm::GraphTraits< clang::CallGraph * >::getEntryNode(), llvm::GraphTraits< const clang::CallGraph * >::getEntryNode(), and llvm::DOTGraphTraits< const CallGraph * >::getNodeLabel().

◆ includeCalleeInGraph()

bool CallGraph::includeCalleeInGraph ( const Decl D)
static

Determine if a declaration should be included in the graph for the purposes of being a callee.

This is similar to includeInGraph except it permits declarations, not just definitions.

Definition at line 163 of file CallGraph.cpp.

References D, and clang::IdentifierInfo::getName().

Referenced by includeInGraph().

◆ includeInGraph()

bool CallGraph::includeInGraph ( const Decl D)
static

Determine if a declaration should be included in the graph.

Definition at line 155 of file CallGraph.cpp.

References D, clang::Decl::hasBody(), and includeCalleeInGraph().

Referenced by VisitFunctionDecl(), and VisitObjCMethodDecl().

◆ print()

void CallGraph::print ( raw_ostream &  os) const

◆ shouldVisitImplicitCode()

bool clang::CallGraph::shouldVisitImplicitCode ( ) const
inline

Definition at line 140 of file CallGraph.h.

◆ shouldVisitTemplateInstantiations()

bool clang::CallGraph::shouldVisitTemplateInstantiations ( ) const
inline

Definition at line 139 of file CallGraph.h.

◆ shouldWalkTypesOfTypeLocs()

bool clang::CallGraph::shouldWalkTypesOfTypeLocs ( ) const
inline

Definition at line 138 of file CallGraph.h.

◆ size()

unsigned clang::CallGraph::size ( ) const
inline

Get the number of nodes in the graph.

Definition at line 92 of file CallGraph.h.

Referenced by llvm::GraphTraits< clang::CallGraph * >::size(), and llvm::GraphTraits< const clang::CallGraph * >::size().

◆ TraverseStmt()

bool clang::CallGraph::TraverseStmt ( Stmt S)
inline

Definition at line 136 of file CallGraph.h.

◆ viewGraph()

void CallGraph::viewGraph ( ) const

Definition at line 250 of file CallGraph.cpp.

◆ VisitFunctionDecl()

bool clang::CallGraph::VisitFunctionDecl ( FunctionDecl FD)
inline

Part of recursive declaration visitation.

We recursively visit all the declarations to collect the root functions.

Definition at line 112 of file CallGraph.h.

References addNodesForBlocks(), includeInGraph(), clang::FunctionDecl::isGlobal(), and clang::FunctionDecl::isThisDeclarationADefinition().

◆ VisitObjCMethodDecl()

bool clang::CallGraph::VisitObjCMethodDecl ( ObjCMethodDecl MD)
inline

Part of recursive declaration visitation.

Definition at line 127 of file CallGraph.h.

References addNodesForBlocks(), and includeInGraph().

Friends And Related Function Documentation

◆ CallGraphNode

friend class CallGraphNode
friend

Definition at line 43 of file CallGraph.h.


The documentation for this class was generated from the following files: