clang  6.0.0svn
Classes | Public Member Functions | Static Public Member Functions | List of all members
clang::ast_type_traits::DynTypedNode Class Reference

A dynamically typed AST node container. More...

#include "clang/AST/ASTTypeTraits.h"

Classes

struct  BaseConverter< CXXCtorInitializer, void >
 
struct  BaseConverter< NestedNameSpecifier, void >
 
struct  BaseConverter< NestedNameSpecifierLoc, void >
 
struct  BaseConverter< QualType, void >
 
struct  BaseConverter< T, typename std::enable_if< std::is_base_of< Decl, T >::value >::type >
 
struct  BaseConverter< T, typename std::enable_if< std::is_base_of< Stmt, T >::value >::type >
 
struct  BaseConverter< T, typename std::enable_if< std::is_base_of< Type, T >::value >::type >
 
struct  BaseConverter< TemplateArgument, void >
 
struct  BaseConverter< TemplateName, void >
 
struct  BaseConverter< TypeLoc, void >
 
struct  DenseMapInfo
 Hooks for using DynTypedNode as a key in a DenseMap. More...
 

Public Member Functions

template<typename T >
const Tget () const
 Retrieve the stored node as type T. More...
 
template<typename T >
const TgetUnchecked () const
 Retrieve the stored node as type T. More...
 
ASTNodeKind getNodeKind () const
 
const void * getMemoizationData () const
 Returns a pointer that identifies the stored AST node. More...
 
void print (llvm::raw_ostream &OS, const PrintingPolicy &PP) const
 Prints the node to the given output stream. More...
 
void dump (llvm::raw_ostream &OS, SourceManager &SM) const
 Dumps the node to the given output stream. More...
 
SourceRange getSourceRange () const
 For nodes which represent textual entities in the source code, return their SourceRange. More...
 
bool operator< (const DynTypedNode &Other) const
 Imposes an order on DynTypedNode. More...
 
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. More...
 

Detailed Description

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 212 of file ASTTypeTraits.h.

Member Function Documentation

◆ create()

template<typename T >
static DynTypedNode clang::ast_type_traits::DynTypedNode::create ( const T Node)
inlinestatic

◆ dump()

void clang::ast_type_traits::DynTypedNode::dump ( llvm::raw_ostream &  OS,
SourceManager SM 
) const

Dumps the node to the given output stream.

Definition at line 133 of file ASTTypeTraits.cpp.

◆ get()

template<typename T >
const T* clang::ast_type_traits::DynTypedNode::get ( ) const
inline

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 233 of file ASTTypeTraits.h.

Referenced by findDeepestWithKind(), clang::tooling::CodeRangeASTSelection::getFunctionLikeNearestParent(), clang::CallGraph::getOrInsertNode(), clang::diff::SyntaxTree::getSourceRangeOffsets(), and clang::tooling::CodeRangeASTSelection::isInFunctionLikeBodyOfCode().

◆ getMemoizationData()

const void* clang::ast_type_traits::DynTypedNode::getMemoizationData ( ) const
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 252 of file ASTTypeTraits.h.

References dump(), clang::tooling::fixit::internal::getSourceRange(), and SM.

Referenced by clang::ast_type_traits::DynTypedNode::DenseMapInfo::getHashValue(), clang::ASTContext::getParents(), operator<(), and operator==().

◆ getNodeKind()

ASTNodeKind clang::ast_type_traits::DynTypedNode::getNodeKind ( ) const
inline

Definition at line 245 of file ASTTypeTraits.h.

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

◆ getSourceRange()

SourceRange clang::ast_type_traits::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 144 of file ASTTypeTraits.cpp.

Referenced by clang::diff::SyntaxTree::getSourceRangeOffsets().

◆ getUnchecked()

template<typename T >
const T& clang::ast_type_traits::DynTypedNode::getUnchecked ( ) const
inline

Retrieve the stored node as type T.

Similar to get(), but asserts that the type is what we are expecting.

Definition at line 241 of file ASTTypeTraits.h.

Referenced by clang::ast_type_traits::DynTypedNode::DenseMapInfo::getHashValue(), operator<(), and operator==().

◆ operator!=()

bool clang::ast_type_traits::DynTypedNode::operator!= ( const DynTypedNode Other) const
inline

Definition at line 324 of file ASTTypeTraits.h.

References clang::operator==().

◆ operator<()

bool clang::ast_type_traits::DynTypedNode::operator< ( const DynTypedNode Other) const
inline

Imposes an order on DynTypedNode.

Supports comparison of nodes that support memoization. FIXME: Implement comparsion for other node types (currently only Stmt, Decl, Type and NestedNameSpecifier return memoization data).

Definition at line 274 of file ASTTypeTraits.h.

References getMemoizationData(), getUnchecked(), and clang::if().

◆ operator==()

bool clang::ast_type_traits::DynTypedNode::operator== ( const DynTypedNode Other) const
inline

Definition at line 304 of file ASTTypeTraits.h.

References getMemoizationData(), and getUnchecked().

◆ print()

void clang::ast_type_traits::DynTypedNode::print ( llvm::raw_ostream &  OS,
const PrintingPolicy PP 
) const

Prints the node to the given output stream.

Definition at line 109 of file ASTTypeTraits.cpp.


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