LLVM API Documentation

llvm::PointerUnion< PT1, PT2 > Class Template Reference

#include <PointerUnion.h>

Inheritance diagram for llvm::PointerUnion< PT1, PT2 >:
[legend]
Collaboration diagram for llvm::PointerUnion< PT1, PT2 >:
[legend]

List of all members.

Public Types

typedef PointerIntPair< void
*, 1, bool,
PointerUnionUIntTraits< PT1,
PT2 > > 
ValTy

Public Member Functions

 PointerUnion ()
 PointerUnion (PT1 V)
 PointerUnion (PT2 V)
bool isNull () const
 operator bool () const
template<typename T>
int is () const
 is<T>() return true if the Union currently holds the type matching T.
template<typename T>
T get () const
template<typename T>
T dyn_cast () const
const PointerUnion & operator= (const PT1 &RHS)
const PointerUnion & operator= (const PT2 &RHS)
void * getOpaqueValue () const

Static Public Member Functions

static PointerUnion getFromOpaqueValue (void *VP)


Detailed Description

template<typename PT1, typename PT2>
class llvm::PointerUnion< PT1, PT2 >

PointerUnion - This implements a discriminated union of two pointer types, and keeps the discriminator bit-mangled into the low bits of the pointer. This allows the implementation to be extremely efficient in space, but permits a very natural and type-safe API.

Common use patterns would be something like this: PointerUnion<int*, float*> P; P = (int*)0; printf("%d %d", P.is<int*>(), P.is<float*>()); // prints "1 0" X = P.get<int*>(); // ok. Y = P.get<float*>(); // runtime assertion failure. Z = P.get<double*>(); // runtime assertion failure (regardless of tag) P = (float*)0; Y = P.get<float*>(); // ok. X = P.get<int*>(); // runtime assertion failure.

Definition at line 62 of file PointerUnion.h.


Member Typedef Documentation

template<typename PT1, typename PT2>
typedef PointerIntPair<void*, 1, bool, PointerUnionUIntTraits<PT1,PT2> > llvm::PointerUnion< PT1, PT2 >::ValTy

Definition at line 65 of file PointerUnion.h.


Constructor & Destructor Documentation

template<typename PT1, typename PT2>
llvm::PointerUnion< PT1, PT2 >::PointerUnion (  )  [inline]

Definition at line 69 of file PointerUnion.h.

template<typename PT1, typename PT2>
llvm::PointerUnion< PT1, PT2 >::PointerUnion ( PT1  V  )  [inline]

Definition at line 71 of file PointerUnion.h.

template<typename PT1, typename PT2>
llvm::PointerUnion< PT1, PT2 >::PointerUnion ( PT2  V  )  [inline]

Definition at line 76 of file PointerUnion.h.


Member Function Documentation

template<typename PT1, typename PT2>
bool llvm::PointerUnion< PT1, PT2 >::isNull (  )  const [inline]

isNull - Return true if the pointer held in the union is null, regardless of which type it is.

Definition at line 84 of file PointerUnion.h.

Referenced by llvm::PointerUnion< llvm::PointerUnion, PT3 >::operator bool().

template<typename PT1, typename PT2>
llvm::PointerUnion< PT1, PT2 >::operator bool (  )  const [inline]

Definition at line 85 of file PointerUnion.h.

template<typename PT1, typename PT2>
template<typename T>
int llvm::PointerUnion< PT1, PT2 >::is (  )  const [inline]

is<T>() return true if the Union currently holds the type matching T.

Definition at line 89 of file PointerUnion.h.

template<typename PT1, typename PT2>
template<typename T>
T llvm::PointerUnion< PT1, PT2 >::get (  )  const [inline]

get<T>() - Return the value of the specified pointer type. If the specified pointer type is incorrect, assert.

Definition at line 98 of file PointerUnion.h.

template<typename PT1, typename PT2>
template<typename T>
T llvm::PointerUnion< PT1, PT2 >::dyn_cast (  )  const [inline]

dyn_cast<T>() - If the current value is of the specified pointer type, return it, otherwise return null.

Definition at line 106 of file PointerUnion.h.

template<typename PT1, typename PT2>
const PointerUnion& llvm::PointerUnion< PT1, PT2 >::operator= ( const PT1 &  RHS  )  [inline]

Assignment operators - Allow assigning into this union from either pointer type, setting the discriminator to remember what it came from.

Definition at line 113 of file PointerUnion.h.

template<typename PT1, typename PT2>
const PointerUnion& llvm::PointerUnion< PT1, PT2 >::operator= ( const PT2 &  RHS  )  [inline]

Definition at line 119 of file PointerUnion.h.

template<typename PT1, typename PT2>
void* llvm::PointerUnion< PT1, PT2 >::getOpaqueValue (  )  const [inline]

template<typename PT1, typename PT2>
static PointerUnion llvm::PointerUnion< PT1, PT2 >::getFromOpaqueValue ( void *  VP  )  [inline, static]

Definition at line 127 of file PointerUnion.h.


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