clang 19.0.0git
Classes | Public Member Functions | List of all members
clang::ParentMapContext Class Reference

#include "clang/AST/ParentMapContext.h"

Classes

class  ParentMap
 

Public Member Functions

 ParentMapContext (ASTContext &Ctx)
 
 ~ParentMapContext ()
 
template<typename NodeT >
DynTypedNodeList getParents (const NodeT &Node)
 Returns the parents of the given node (within the traversal scope).
 
DynTypedNodeList getParents (const DynTypedNode &Node)
 
void clear ()
 Clear parent maps.
 
TraversalKind getTraversalKind () const
 
void setTraversalKind (TraversalKind TK)
 
const ExprtraverseIgnored (const Expr *E) const
 
ExprtraverseIgnored (Expr *E) const
 
DynTypedNode traverseIgnored (const DynTypedNode &N) const
 

Detailed Description

Definition at line 23 of file ParentMapContext.h.

Constructor & Destructor Documentation

◆ ParentMapContext()

ParentMapContext::ParentMapContext ( ASTContext Ctx)

Definition at line 22 of file ParentMapContext.cpp.

◆ ~ParentMapContext()

ParentMapContext::~ParentMapContext ( )
default

Member Function Documentation

◆ clear()

void ParentMapContext::clear ( )

Clear parent maps.

Definition at line 26 of file ParentMapContext.cpp.

Referenced by clang::ASTContext::setTraversalScope().

◆ getParents() [1/2]

DynTypedNodeList ParentMapContext::getParents ( const DynTypedNode Node)

Definition at line 459 of file ParentMapContext.cpp.

References getTraversalKind(), and Node.

◆ getParents() [2/2]

template<typename NodeT >
DynTypedNodeList clang::ParentMapContext::getParents ( const NodeT &  Node)
inline

Returns the parents of the given node (within the traversal scope).

Note that this will lazily compute the parents of all nodes and store them for later retrieval. Thus, the first call is O(n) in the number of AST nodes.

Caveats and FIXMEs: Calculating the parent map over all AST nodes will need to load the full AST. This can be undesirable in the case where the full AST is expensive to create (for example, when using precompiled header preambles). Thus, there are good opportunities for optimization here. One idea is to walk the given node downwards, looking for references to declaration contexts - once a declaration context is found, compute the parent map for the declaration context; if that can satisfy the request, loading the whole AST can be avoided. Note that this is made more complex by statements in templates having multiple parents - those problems can be solved by building closure over the templated parts of the AST, which also avoids touching large parts of the AST. Additionally, we will want to add an interface to already give a hint where to search for the parents, for example when looking at a statement inside a certain function.

'NodeT' can be one of Decl, Stmt, Type, TypeLoc, NestedNameSpecifier or NestedNameSpecifierLoc.

Definition at line 126 of file ParentMapContext.h.

References clang::DynTypedNode::create(), getParents(), and Node.

Referenced by clang::ASTContext::getParents(), getParents(), and isInCondition().

◆ getTraversalKind()

TraversalKind clang::ParentMapContext::getTraversalKind ( ) const
inline

Definition at line 60 of file ParentMapContext.h.

Referenced by getParents(), and clang::TraversalKindScope::TraversalKindScope().

◆ setTraversalKind()

void clang::ParentMapContext::setTraversalKind ( TraversalKind  TK)
inline

◆ traverseIgnored() [1/3]

DynTypedNode ParentMapContext::traverseIgnored ( const DynTypedNode N) const

◆ traverseIgnored() [2/3]

const Expr * ParentMapContext::traverseIgnored ( const Expr E) const

Definition at line 28 of file ParentMapContext.cpp.

References traverseIgnored().

Referenced by traverseIgnored().

◆ traverseIgnored() [3/3]

Expr * ParentMapContext::traverseIgnored ( Expr E) const

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