GTIRB  v2.1.0
GrammaTech Intermediate Representation for Binaries: C++ API
Files
Casting

Node and its subclasses support custom casting machinery that allows for type checking, safer static casting, and safe dynamic casting without needing the overhead of a vtable or RTTI. More...

Files

file  Casting.hpp
 The various casting and type checking operations that apply to gtirb::Node subclasses.
 

Detailed Description

Node and its subclasses support custom casting machinery that allows for type checking, safer static casting, and safe dynamic casting without needing the overhead of a vtable or RTTI.

File Casting.hpp defines the various operations that apply to Node subclasses.

Casting Operations

isa<Ty>

Perform a type check.

Parameters
ValThe object to check. Cannot be null.
Returns
true if Val is an instance of the template parameter type, false otherwise.

Example usage:

void f(Node *N) { if (isa<Block>(N) { ... } }

cast<Ty>

Cast to the specified type; the argument cannot be null.

Parameters
Valthe value to cast. Cannot be null; consider using cast_or_null<Ty> in that case.
Returns
The result of casting Val to the specified type. This function asserts that the types match and will not return null on failure.

Example usage:

void f(Node * N) { auto *B = cast<Block>(N); }

cast_or_null<Ty>

Cast to the specified type; the argument can be null.

Parameters
Valthe value to cast. Can be null.
Returns
The result of casting Val to the specified type. This function asserts that the types match and will not return null on failure. If Val is null, returns a null pointer cast to the given type.

Example usage:

void f(Node *N) { auto *B = cast_or_null<Block>(N); }

dyn_cast<Ty>

Dynamic cast to the specified type; the argument cannot be null.

Parameters
Valthe value to cast. Cannot be null; consider using dyn_cast_or_null<Ty> in that case.
Returns
The result of casting Val to the specified type, or null if the casting operation fails because the types do not match.

Example usage:

void f(Node * N) { auto *B = dyn_cast<Block>(N); }

dyn_cast_or_null<Ty>

Cast to the specified type; the argument can be null.

Parameters
Valthe value to cast. Can be null.
Returns
The result of casting Val to the specified type, or null if the casting operation fails because the types do not match. If Val is null, returns a null pointer cast to the given type.

Example usage:

void f(Node *N) { auto *B = dyn_cast_or_null<Block>(N); }