ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
irep2.h File Reference

Classes and definitions for non-stringy internal representation. More...

#include <big-int/bigint.hh>
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <stdexcept>
#include <thread>
#include <type_traits>
#include <utility>
#include <util/base/compiler_defs.h>
#include <util/irep/irep_idt.h>
#include <util/irep/irep.h>
#include <irep2/type_kinds.inc>
#include <irep2/expr_kinds.inc>
Include dependency graph for irep2.h:

Go to the source code of this file.

Classes

class  esbmct::function_ref< R(Args...)>
class  irep_container< T >
 Reference counted container for irep2 nodes. More...
class  irep2t
 Base class for every irep2 node. More...
class  type2t
 Base class for all types. More...
class  type2t::symbolic_type_excp
 Symbolic type exception class. More...
class  expr2t
 Base class for all expressions. More...
struct  esbmct::member_traits< M C::* >
struct  esbmct::member_traits< const M C::* >
struct  esbmct::kind_excluded_field_bytes< K, class >
struct  esbmct::kind_excluded_field_bytes< K, std::void_t< decltype(K::excluded_field_bytes)> >
struct  irep2_hash
struct  type2_hash
class  irep2_cast_error

Namespaces

namespace  esbmct
 Containers and field-walking infrastructure for irep2 nodes.

Macros

#define IREP2_TYPE(kind, pretty)
#define IREP2_EXPR(kind, pretty)

Typedefs

typedef irep_container< type2t > type2tc
typedef irep_container< expr2t > expr2tc
typedef std::pair< std::string, std::string > member_entryt
typedef std::list< member_entryt > list_of_memberst

Functions

template<class T>
void esbmct::hash_combine (std::size_t &seed, const T &v)
 Mix a value into a running hash seed.
template<class T, class... Args>
irep_container< typename T::base_type > make_irep (Args &&... args)
 Allocate a fresh irep2 node and adopt it into an irep_container.
std::string get_type_id (const type2t &type)
 Fetch identifying name for a type.
static std::string get_type_id (const type2tc &type)
 Fetch identifying name for a type.
bool is_nil_expr (const expr2tc &exp)
template<class T>
bool same_pointer (const irep_container< T > &a, const irep_container< T > &b)
 Node-identity test: true iff a and b refer to the very same hash-consed node.
bool is_nil_type (const type2tc &t)
std::size_t hash_value (const expr2tc &expr)
std::string get_expr_id (const expr2t &expr)
 Fetch string identifier for an expression.
static std::string get_expr_id (const expr2tc &expr)
 Fetch string identifier for an expression.
template<class K, std::size_t I>
constexpr std::size_t esbmct::nth_field_size_in_derived ()
template<class K, std::size_t... Is>
constexpr std::size_t esbmct::sum_derived_field_sizes (std::index_sequence< Is... >)
template<class K, std::size_t... Is>
constexpr std::size_t esbmct::count_derived_field_entries (std::index_sequence< Is... >)
template<class K>
constexpr bool esbmct::fields_cover_class ()
template<class K>
constexpr std::size_t esbmct::derived_field_count ()
template<class K>
constexpr bool esbmct::assert_kind_invariants ()
std::ostream & operator<< (std::ostream &out, const expr2tc &a)
void irep2_bad_type_cast (unsigned actual, unsigned expected, const char *target)
void irep2_bad_expr_cast (unsigned actual, unsigned expected, const char *target)
void irep2_bad_family_cast (unsigned actual, const char *accessor)
template<typename Derived>
Derived & irep2_checked_type_cast (type2t &t, type2t::type_ids expected, const char *target_name)
template<typename Derived>
const Derived & irep2_checked_type_cast (const type2t &t, type2t::type_ids expected, const char *target_name)
template<typename Derived>
Derived & irep2_checked_expr_cast (expr2t &e, expr2t::expr_ids expected, const char *target_name)
template<typename Derived>
const Derived & irep2_checked_expr_cast (const expr2t &e, expr2t::expr_ids expected, const char *target_name)

Variables

const unsigned int esbmct::num_type_fields = 6
 Maximum number of fields to support in expr2t subclasses.

Detailed Description

Classes and definitions for non-stringy internal representation.

Threading contract: irep2 nodes (type2t, expr2t) are designed for single-writer / thread-confined construction and rewriting.

Ownership is handled by an intrusive atomic refcount sitting on every node (irep2t::refcount); irep_container is a raw pointer that increments on copy, decrements on destruction, and deletes the pointee when the count drops to zero. The refcount is atomic so two containers holding the same node can be dropped from different threads safely, but the pointee's state is not — only one thread at a time may obtain a mutable view (the non-const irep_container::get() / operator-> / operator*, which detach if refcount > 1 and otherwise hand back the underlying object).

The CRC cache (irep2t::crc_val) is a single std::atomic<size_t> with 0 meaning "not yet computed". Readers do an acquire load, producers compute on a stack local and release-store the result, so concurrent readers see either 0 (and recompute, getting the same value) or the final cache entry — never a half-mixed state.

Treat an irep2 tree as owned by a single rewriter at a time; publish to other threads only once mutation is complete and only for read-only consumption.

Macro Definition Documentation

◆ IREP2_EXPR

#define IREP2_EXPR ( kind,
pretty )
Value:
kind##_id,

◆ IREP2_TYPE

#define IREP2_TYPE ( kind,
pretty )
Value:
kind##_id,

Typedef Documentation

◆ expr2tc

◆ list_of_memberst

typedef std::list<member_entryt> list_of_memberst

◆ member_entryt

typedef std::pair<std::string, std::string> member_entryt

◆ type2tc

Function Documentation

◆ get_expr_id() [1/2]

std::string get_expr_id ( const expr2t & expr)

Fetch string identifier for an expression.

Parameters
exprExpression to operate upon
Returns
String containing class name of expression.

◆ get_expr_id() [2/2]

std::string get_expr_id ( const expr2tc & expr)
inlinestatic

Fetch string identifier for an expression.

Like the expr2t equivalent with the same name, but de-ensapculates an expr2tc.

◆ get_type_id() [1/2]

std::string get_type_id ( const type2t & type)

Fetch identifying name for a type.

Parameters
typeType to fetch identifier for
Returns
String containing name of type class.

◆ get_type_id() [2/2]

std::string get_type_id ( const type2tc & type)
inlinestatic

Fetch identifying name for a type.

Just passes through to type2t accepting function with the same name.

Parameters
typeType to fetch identifier for
Returns
String containing name of type class.

◆ hash_value()

std::size_t hash_value ( const expr2tc & expr)
inline

◆ irep2_bad_expr_cast()

void irep2_bad_expr_cast ( unsigned actual,
unsigned expected,
const char * target )

◆ irep2_bad_family_cast()

void irep2_bad_family_cast ( unsigned actual,
const char * accessor )

◆ irep2_bad_type_cast()

void irep2_bad_type_cast ( unsigned actual,
unsigned expected,
const char * target )

◆ irep2_checked_expr_cast() [1/2]

template<typename Derived>
const Derived & irep2_checked_expr_cast ( const expr2t & e,
expr2t::expr_ids expected,
const char * target_name )
inline

◆ irep2_checked_expr_cast() [2/2]

template<typename Derived>
Derived & irep2_checked_expr_cast ( expr2t & e,
expr2t::expr_ids expected,
const char * target_name )
inline

◆ irep2_checked_type_cast() [1/2]

template<typename Derived>
const Derived & irep2_checked_type_cast ( const type2t & t,
type2t::type_ids expected,
const char * target_name )
inline

◆ irep2_checked_type_cast() [2/2]

template<typename Derived>
Derived & irep2_checked_type_cast ( type2t & t,
type2t::type_ids expected,
const char * target_name )
inline

◆ is_nil_expr()

bool is_nil_expr ( const expr2tc & exp)
inline

◆ is_nil_type()

bool is_nil_type ( const type2tc & t)
inline

◆ make_irep()

template<class T, class... Args>
irep_container< typename T::base_type > make_irep ( Args &&... args)
inline

Allocate a fresh irep2 node and adopt it into an irep_container.

The single canonical construction path for the intrusive refcount scheme. T must derive from an irep2 base (type2t / expr2t) that exposes base_type as its method-side base; the returned container is irep_container<T::base_type> (i.e. type2tc or expr2tc).

Single allocation, no separate control block, exception-safe (if any argument constructor throws, the new hasn't run yet; if the new itself throws, no leak; the only ordering between new succeeding and the container adopting it is straight-line code inside this function).

Callers should prefer this helper over a raw new-into-container so the allocation site stays in one place.

◆ operator<<()

std::ostream & operator<< ( std::ostream & out,
const expr2tc & a )
inline

◆ same_pointer()

template<class T>
bool same_pointer ( const irep_container< T > & a,
const irep_container< T > & b )
inline

Node-identity test: true iff a and b refer to the very same hash-consed node.

This is not a value comparison — use operator== for structural equality, which additionally walks the trees when the pointers differ (two distinct nodes can still be structurally equal if hash-consing did not unify them). same_pointer is the O(1) identity check; reach for it only when you specifically want "is this literally the same object", e.g. fast-path short-circuits over hash-consed conjuncts. The underlying pointer is already public via get(); this just names the comparison so call sites stop hand-rolling a.get() == b.get().