clang 20.0.0git
|
A dynamically typed AST node container. More...
#include "clang/AST/ASTTypeTraits.h"
Public Member Functions | |
template<typename T > | |
const T * | get () const |
Retrieve the stored node as type T . | |
template<typename T > | |
const T & | getUnchecked () const |
Retrieve the stored node as type T . | |
ASTNodeKind | getNodeKind () const |
const void * | getMemoizationData () const |
Returns a pointer that identifies the stored AST node. | |
void | print (llvm::raw_ostream &OS, const PrintingPolicy &PP) const |
Prints the node to the given output stream. | |
void | dump (llvm::raw_ostream &OS, const ASTContext &Context) const |
Dumps the node to the given output stream. | |
SourceRange | getSourceRange () const |
For nodes which represent textual entities in the source code, return their SourceRange. | |
bool | operator< (const DynTypedNode &Other) const |
bool | operator== (const DynTypedNode &Other) const |
bool | operator!= (const DynTypedNode &Other) const |
Static Public Member Functions | |
template<typename T > | |
static DynTypedNode | create (const T &Node) |
Creates a DynTypedNode from Node . | |
A dynamically typed AST node container.
Stores an AST node in a type safe way. This allows writing code that works with different kinds of AST nodes, despite the fact that they don't have a common base class.
Use create(Node)
to create a DynTypedNode
from an AST node, and get<T>()
to retrieve the node as type T if the types match.
See ASTNodeKind
for which node base types are currently supported; You can create DynTypedNodes for all nodes in the inheritance hierarchy of the supported base types.
Definition at line 257 of file ASTTypeTraits.h.
|
inlinestatic |
Creates a DynTypedNode
from Node
.
Definition at line 261 of file ASTTypeTraits.h.
References Node.
Referenced by clang::ParentMapContext::ParentMap::AscendIgnoreUnlessSpelledInSource(), clang::ast_matchers::AST_MATCHER_P(), clang::ast_matchers::AST_POLYMORPHIC_MATCHER_P(), createDynTypedNode(), clang::ParentMapContext::getParents(), clang::ParentMapContext::ParentMap::getParents(), clang::ast_matchers::MatchFinder::match(), clang::ast_matchers::match(), clang::ast_matchers::matchDynamic(), and clang::ParentMapContext::traverseIgnored().
void DynTypedNode::dump | ( | llvm::raw_ostream & | OS, |
const ASTContext & | Context | ||
) | const |
Dumps the node to the given output stream.
Definition at line 221 of file ASTTypeTraits.cpp.
References clang::ASTNodeKind::asStringRef(), clang::C, D, clang::Decl::dump(), clang::Type::dump(), and clang::T.
Retrieve the stored node as type T
.
Returns NULL if the stored node does not have a type that is convertible to T
.
For types that have identity via their pointer in the AST (like Stmt
, Decl
, Type
and NestedNameSpecifier
) the returned pointer points to the referenced AST node. For other types (like QualType
) the value is stored directly in the DynTypedNode
, and the returned pointer points at the storage inside DynTypedNode. For those nodes, do not use the pointer outside the scope of the DynTypedNode.
Definition at line 277 of file ASTTypeTraits.h.
Referenced by dump(), findDeepestWithKind(), clang::ast_matchers::MatchDescendantVisitor::findMatch(), clang::tooling::CodeRangeASTSelection::getFunctionLikeNearestParent(), clang::diff::SyntaxTree::Impl::getNodeValue(), clang::CallGraph::getOrInsertNode(), clang::ParentMapContext::ParentMap::getParents(), clang::tooling::CodeRangeASTSelection::isInFunctionLikeBodyOfCode(), clang::transformer::member(), clang::transformer::name(), clang::transformer::node(), clang::transformer::detail::rewriteDescendants(), clang::ParentMapContext::traverseIgnored(), clang::ASTNodeTraverser< Derived, NodeDelegateType >::Visit(), and clang::ParentMapContext::ParentMap::~ParentMap().
|
inline |
Returns a pointer that identifies the stored AST node.
Note that this is not supported by all AST nodes. For AST nodes that don't have a pointer-defined identity inside the AST, this method returns NULL.
Definition at line 296 of file ASTTypeTraits.h.
References clang::ASTNodeKind::hasPointerIdentity().
Referenced by clang::DynTypedNode::DenseMapInfo::getHashValue(), clang::ParentMapContext::ParentMap::getParents(), operator<(), and operator==().
|
inline |
Definition at line 289 of file ASTTypeTraits.h.
Referenced by clang::ParentMapContext::ParentMap::getParents(), clang::transformer::member(), clang::transformer::name(), and clang::transformer::detail::rewriteDescendants().
SourceRange DynTypedNode::getSourceRange | ( | ) | const |
For nodes which represent textual entities in the source code, return their SourceRange.
For all other nodes, return SourceRange().
Definition at line 237 of file ASTTypeTraits.cpp.
References clang::C, D, clang::Decl::getSourceRange(), and P.
Referenced by fixUPCAddressofArraySubscriptWithSpan(), clang::transformer::node(), and clang::TextNodeDumper::Visit().
Retrieve the stored node as type T
.
Similar to get()
, but asserts that the type is what we are expecting.
Definition at line 285 of file ASTTypeTraits.h.
Referenced by clang::DynTypedNode::DenseMapInfo::getHashValue().
|
inline |
Definition at line 368 of file ASTTypeTraits.h.
References operator==(), and clang::Other.
|
inline |
Imposes an order on DynTypedNode
.
Supports comparison of nodes that support memoization. FIXME: Implement comparison for other node types (currently only Stmt, Decl, Type and NestedNameSpecifier return memoization data).
Definition at line 318 of file ASTTypeTraits.h.
References getMemoizationData(), clang::ASTNodeKind::isSame(), and clang::Other.
|
inline |
Definition at line 348 of file ASTTypeTraits.h.
References getMemoizationData(), clang::ASTNodeKind::isSame(), and clang::Other.
Referenced by operator!=().
void DynTypedNode::print | ( | llvm::raw_ostream & | OS, |
const PrintingPolicy & | PP | ||
) | const |
Prints the node to the given output stream.
Definition at line 186 of file ASTTypeTraits.cpp.
References clang::ASTNodeKind::asStringRef(), clang::C, D, P, clang::QualType::print(), clang::Decl::print(), and clang::T.
Referenced by clang::TextNodeDumper::VisitObjCMessageExpr(), clang::TextNodeDumper::VisitObjCPropertyRefExpr(), clang::TextNodeDumper::VisitObjCSelectorExpr(), and clang::TextNodeDumper::VisitObjCSubscriptRefExpr().