GTIRB  v1.10.4
GrammaTech Intermediate Representation for Binaries: C++ API
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
gtirb::Symbol Class Reference

Represents a Symbol, which maps a name to an object in the IR. More...

#include <Symbol.hpp>

Inheritance diagram for gtirb::Symbol:
Inheritance graph
[legend]
Collaboration diagram for gtirb::Symbol:
Collaboration graph
[legend]

Public Types

using supported_referent_types = TypeList< CodeBlock, DataBlock, ProxyBlock >
 The list of supported referent types. More...
 

Public Member Functions

std::optional< AddrgetAddress () const
 Get the effective address. More...
 
bool getAtEnd () const
 If true, this symbol is pointing to the end of the referent rather than at the beginning. More...
 
ModulegetModule ()
 Get the Module this symbol belongs to. More...
 
const ModulegetModule () const
 Get the Module this symbol belongs to. More...
 
const std::string & getName () const
 Get the name. More...
 
template<typename NodeTy >
NodeTy * getReferent ()
 Get the referent to which this symbol refers. More...
 
template<typename NodeTy >
const NodeTy * getReferent () const
 Get the referent to which this symbol refers. More...
 
bool hasReferent () const
 Check if this symbol has a referent. More...
 
void setAddress (Addr A)
 Set the address of a symbol. More...
 
void setAtEnd (bool AE)
 sets whether or not this symbol is pointing to the end of the referent rather than at the beginning. More...
 
void setName (const std::string &N)
 Set the name of a symbol. More...
 
template<typename NodeTy >
std::enable_if_t< is_supported_type< NodeTy >)> setReferent (NodeTy *N)
 Set the referent of a symbol. More...
 
template<typename Callable >
auto visit (Callable &&Visitor) const
 Visits the symbol's referent, if one is present, by concrete referent type. More...
 
- Public Member Functions inherited from gtirb::Node
 Node (const Node &)=delete
 Copying Nodes is explicitly disabled. More...
 
 Node (Node &&)=delete
 Move-constructing Nodes is explicitly disabled. More...
 
 ~Node () noexcept
 Cleans up resources no longer needed by the Node object. More...
 
const UUIDgetUUID () const
 Get the Universally Unique ID (UUID) for this. More...
 
Nodeoperator= (const Node &)=delete
 Copying Nodes is explicilty disabled. More...
 
Nodeoperator= (Node &&)=delete
 Move-assigning Nodes is explicilty disabled. More...
 

Static Public Member Functions

static SymbolCreate (Context &C)
 Create an unitialized Symbol object. More...
 
static SymbolCreate (Context &C, Addr X, const std::string &Name, bool AtEnd=false)
 Create a Symbol object. More...
 
static SymbolCreate (Context &C, const std::string &Name, bool AtEnd=false)
 Create a Symbol object. More...
 
template<typename NodeTy >
static SymbolCreate (Context &C, NodeTy *Referent, const std::string &Name, bool AtEnd=false)
 Create a Symbol object. More...
 
template<typename NodeTy >
static constexpr bool is_supported_type ()
 
- Static Public Member Functions inherited from gtirb::Node
static NodeCreate (Context &C)
 Create a Node object in its default state. More...
 
static const NodegetByUUID (const Context &C, const UUID &Uuid)
 Retrieve a node by its UUID. More...
 
static NodegetByUUID (Context &C, const UUID &Uuid)
 Retrieve a node by its UUID. More...
 

Friends

class Context
 
class Module
 
class SerializationTestHarness
 
template<typename T >
T::MessageType toProtobuf (const T &)
 

Detailed Description

Represents a Symbol, which maps a name to an object in the IR.

Member Typedef Documentation

◆ supported_referent_types

The list of supported referent types.

Member Function Documentation

◆ Create() [1/4]

static Symbol* gtirb::Symbol::Create ( Context C)
inlinestatic

Create an unitialized Symbol object.

Parameters
CThe Context in which this Symbol will be held.
Returns
The newly created Symbol.

◆ Create() [2/4]

static Symbol* gtirb::Symbol::Create ( Context C,
Addr  X,
const std::string &  Name,
bool  AtEnd = false 
)
inlinestatic

Create a Symbol object.

Parameters
CThe Context in which this object will be held.
XThe address of the symbol.
NameThe name of the symbol.
AtEndIf true, this symbol points to the end of its referent, rather than at the beginning. Defaults to false.
Returns
The newly created object.

◆ Create() [3/4]

static Symbol* gtirb::Symbol::Create ( Context C,
const std::string &  Name,
bool  AtEnd = false 
)
inlinestatic

Create a Symbol object.

Parameters
CThe Context in which this object will be held.
NameThe name of the symbol.
AtEndIf true, this symbol points to the end of its referent, rather than at the beginning. Defaults to false.
Returns
The newly created object.

◆ Create() [4/4]

template<typename NodeTy >
static Symbol* gtirb::Symbol::Create ( Context C,
NodeTy *  Referent,
const std::string &  Name,
bool  AtEnd = false 
)
inlinestatic

Create a Symbol object.

Parameters
CThe Context in which this object will be held.
ReferentThe DataBlock this symbol refers to.
NameThe name of the symbol.
AtEndIf true, this symbol points to the end of its referent, rather than at the beginning. Defaults to false.
Returns
The newly created object.

◆ getAddress()

std::optional<Addr> gtirb::Symbol::getAddress ( ) const

Get the effective address.

Returns
The effective address.

◆ getAtEnd()

bool gtirb::Symbol::getAtEnd ( ) const
inline

If true, this symbol is pointing to the end of the referent rather than at the beginning.

This value has no meaning for integral symbols.

◆ getModule() [1/2]

Module* gtirb::Symbol::getModule ( )
inline

Get the Module this symbol belongs to.

◆ getModule() [2/2]

const Module* gtirb::Symbol::getModule ( ) const
inline

Get the Module this symbol belongs to.

◆ getName()

const std::string& gtirb::Symbol::getName ( ) const
inline

Get the name.

Returns
The name.

◆ getReferent() [1/2]

template<typename NodeTy >
NodeTy* gtirb::Symbol::getReferent ( )
inline

Get the referent to which this symbol refers.

Template Parameters
NodeTyA Node type of a supported referent.
Returns
The data, dynamically typed as the given NodeTy, or null if there is no referent of that type.

◆ getReferent() [2/2]

template<typename NodeTy >
const NodeTy* gtirb::Symbol::getReferent ( ) const
inline

Get the referent to which this symbol refers.

Template Parameters
NodeTyA Node type of a supported referent.
Returns
The data, dynamically typed as the given NodeTy, or null if there is no referent of that type.

◆ hasReferent()

bool gtirb::Symbol::hasReferent ( ) const
inline

Check if this symbol has a referent.

Returns
true if the symbol has a referent, false otherwise.

◆ is_supported_type()

template<typename NodeTy >
static constexpr bool gtirb::Symbol::is_supported_type ( )
inlinestaticconstexpr

◆ setAddress()

void gtirb::Symbol::setAddress ( Addr  A)
inline

Set the address of a symbol.

◆ setAtEnd()

void gtirb::Symbol::setAtEnd ( bool  AE)
inline

sets whether or not this symbol is pointing to the end of the referent rather than at the beginning.

This value has no meaning for integral symbols.

◆ setName()

void gtirb::Symbol::setName ( const std::string &  N)
inline

Set the name of a symbol.

◆ setReferent()

template<typename NodeTy >
std::enable_if_t<is_supported_type<NodeTy>)> gtirb::Symbol::setReferent ( NodeTy *  N)
inline

Set the referent of a symbol.

If the referent of a symbol is set to null, then the value of the symbol's payload will be cleared (that is, hasReference will return false).

◆ visit()

template<typename Callable >
auto gtirb::Symbol::visit ( Callable &&  Visitor) const
inline

Visits the symbol's referent, if one is present, by concrete referent type.

Template Parameters
CallableA callable function type. This type must be able to be called with a pointer to all of the types listed in supported_referent_types. All overloaded functions must have a common, compatible return type.
Parameters
VisitorA callable object that will be called with a nonnull symbol referent.
Returns
The common type of each of the return types in the Callable overload set. Notionally returns: std::common_type_t<Overload1(Ty1), Overload2(Ty2), ...> which can be void.

For example:

struct Visitor {
int operator()(CfgNode*) { return 0; }
long operator()(DataBlock*) { return 1; }
};
Context Ctx;
Symbol* SymB = Symbol::Create(Ctx, Block::Create(Ctx), "");
Symbol* SymD = Symbol::Create(Ctx, DataBlock::Create(Ctx), "");
Symbol* SymX = Symbol::Create(Ctx, Addr(42), "");
Symbol* SymN = Symbol::Create(Ctx);
SymB->visit(Visitor{}); // Will call Visitor::operator()(CfgNode*);
SymD->visit(Visitor{}); // Will call Visitor::operator()(DataBlock*);
SymX->visit(Visitor{}); // Will not call any overload
SymN->visit(Visitor{}); // Will not call any overload
friend class Context
Definition: Symbol.hpp:398
static Symbol * Create(Context &C)
Create an unitialized Symbol object.
Definition: Symbol.hpp:219

Friends And Related Function Documentation

◆ Context

friend class Context
friend

◆ Module

friend class Module
friend

◆ SerializationTestHarness

friend class SerializationTestHarness
friend

◆ toProtobuf

template<typename T >
T::MessageType toProtobuf ( const T &  )
friend

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