class DynTypedNode

Declaration

class DynTypedNode { /* full declaration omitted */ };

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 \c create(Node) to create a \c DynTypedNode from an AST node, and \c get<T>() to retrieve the node as type T if the types match. See \c 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.

Declared at: clang/include/clang/AST/ASTTypeTraits.h:249

Member Variables

private clang::ASTNodeKind NodeKind
private llvm::AlignedCharArrayUnion< const void*, TemplateArgument, TemplateArgumentLoc, NestedNameSpecifierLoc, QualType, TypeLoc, ObjCProtocolLoc> Storage
Note that we can store \c Decls, \c Stmts, \c Types, \c NestedNameSpecifiers and \c CXXCtorInitializer by pointer as they are guaranteed to be unique pointers pointing to dedicated storage in the AST.\c QualTypes, \c NestedNameSpecifierLocs, \c TypeLocs, \c TemplateArguments and \c TemplateArgumentLocs on the other hand do not have storage or unique pointers and thus need to be stored by value.

Method Overview

  • public template <typename T>static clang::DynTypedNode create(const T & Node)
  • public void dump(llvm::raw_ostream & OS, const clang::ASTContext & Context) const
  • public template <typename T>const T * get() const
  • public const void * getMemoizationData() const
  • public clang::ASTNodeKind getNodeKind() const
  • public clang::SourceRange getSourceRange() const
  • public template <typename T>const T & getUnchecked() const
  • public void print(llvm::raw_ostream & OS, const clang::PrintingPolicy & PP) const

Methods

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

Description

Creates a \c DynTypedNode from \c Node.

Declared at: clang/include/clang/AST/ASTTypeTraits.h:253

Templates

T

Parameters

const T& Node

void dump(llvm::raw_ostream& OS,
          const clang::ASTContext& Context) const

Description

Dumps the node to the given output stream.

Declared at: clang/include/clang/AST/ASTTypeTraits.h:298

Parameters

llvm::raw_ostream& OS
const clang::ASTContext& Context

template <typename T>
const T* get() const

Description

Retrieve the stored node as type \c T. Returns NULL if the stored node does not have a type that is convertible to \c T. For types that have identity via their pointer in the AST (like \c Stmt, \c Decl, \c Type and \c NestedNameSpecifier) the returned pointer points to the referenced AST node. For other types (like \c QualType) the value is stored directly in the \c 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.

Declared at: clang/include/clang/AST/ASTTypeTraits.h:269

Templates

T

const void* getMemoizationData() const

Description

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.

Declared at: clang/include/clang/AST/ASTTypeTraits.h:288

clang::ASTNodeKind getNodeKind() const

Declared at: clang/include/clang/AST/ASTTypeTraits.h:281

clang::SourceRange getSourceRange() const

Description

For nodes which represent textual entities in the source code, return their SourceRange. For all other nodes, return SourceRange().

Declared at: clang/include/clang/AST/ASTTypeTraits.h:302

template <typename T>
const T& getUnchecked() const

Description

Retrieve the stored node as type \c T. Similar to \c get(), but asserts that the type is what we are expecting.

Declared at: clang/include/clang/AST/ASTTypeTraits.h:277

Templates

T

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

Description

Prints the node to the given output stream.

Declared at: clang/include/clang/AST/ASTTypeTraits.h:295

Parameters

llvm::raw_ostream& OS
const clang::PrintingPolicy& PP