Customizes how casts from From to To are performed.

Synopsis

Declared in <llvm/Support/Casting.h>

template<
    typename To,
    typename From,
    typename Enable = void>
struct CastInfo
    : CastIsPossible<To, From>

Description

This struct provides a method for customizing the way a cast is performed. It inherits from CastIsPossible, to support the case of declaring many CastIsPossible specializations without having to specialize the full CastInfo.

In order to specialize different behaviors, specify different functions in your CastInfo specialization. For isa<> customization, provide:

static bool isPossible(const From &f)

For cast<> customization, provide:

static To doCast(const From &f)

For dyn_cast<> and the *_if_present<> variants' customization, provide:

static To castFailed() and static To doCastIfPossible(const From &f)

Your specialization might look something like this:

template<> struct CastInfo<foo, bar> : public CastIsPossible<foo, bar> { static inline foo doCast(const bar &b) { return foo(const_cast<bar &>(b)); } static inline foo castFailed() { return foo(); } static inline foo doCastIfPossible(const bar &b) { if (!CastInfo<foo, bar>::isPossible(b)) return castFailed(); return doCast(b); } };

Base Classes

Name

Description

CastIsPossible<To, From>

Trait that reports whether a cast from From to To is possible.

Type Aliases

Name

Description

CastReturnType

Return type produced by successful casts in this specialization.

Self

This CastInfo specialization, used for CRTP‐style calls.

Static Member Functions

Name

Description

castFailed

Returns a null cast result used when the cast fails.

doCast

Unconditionally converts f to the cast return type.

doCastIfPossible

Casts f if possible; otherwise returns castFailed().

isPossible

Returns true if a cast from f to To is possible.

Specializations

Name

Description

CastInfo<To, IRUnitRef>

Lets isa/cast/dyn_cast query which IR unit an IRUnitRef holds, naming the IR unit itself rather than a pointer to it: dyn_cast<Module>(IR).

CastInfo<To, IRUnitRef const>

CastInfo specialization for const IRUnitRef, forwarding to the non‐const case.

CastInfo<SCEVUseT<ToSCEVPtrT>, SCEVUse>

Provide CastInfo for SCEVUseT so that cast<SCEVUseT<const To *>>(use) returns SCEVUseT<const To *> with flags preserved.

CastInfo<SCEVUseT<ToSCEVPtrT>, SCEVUse const>

CastInfo specialization for const SCEVUse, forwarding to the non‐const case.

CastInfo<To, From>

Cast traits for DIExpression typed operand views.

CastInfo<To, From>

CastInfo specialization that forwards through simplify_type.

CastInfo<To, From>

CastInfo specialization that forwards through simplify_type.

CastInfo<To, PointerUnion<PTs...>>

CastInfo specialization for non‐const PointerUnion sources.

CastInfo<To, std::optional<From>>

Provide a CastInfo specialized for casting out of std::optional.

CastInfo<To, std::unique_ptr<From>>

Provide a CastInfo specialized for std::unique_ptr.

CastInfo<To, PointerUnion<PTs...> const>

CastInfo specialization for const PointerUnion sources.

Derived Classes

Name

Description

CastInfo<To, IRUnitRef const>

CastInfo specialization for const IRUnitRef, forwarding to the non‐const case.

CastInfo<SCEVUseT<ToSCEVPtrT>, SCEVUse const>

CastInfo specialization for const SCEVUse, forwarding to the non‐const case.

Created with MrDocs