ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
expr2t Class Reference

Base class for all expressions. More...

#include <irep2.h>

Inherits irep2t.

Inherited by address_of2t, bitcast2t, byte_extract2t, byte_update2t, cmp_three_way2t, code_asm2t, code_assert2t, code_assign2t, code_assume2t, code_block2t, code_break2t, code_comma2t, code_continue2t, code_cpp_catch2t, code_cpp_throw2t, code_decl2t, code_dowhile2t, code_for2t, code_function_call2t, code_goto2t, code_ifthenelse2t, code_label2t, code_printf2t, code_skip2t, code_switch2t, code_switch_case2t, code_while2t, concat2t, constant_array2t, constant_array_of2t, constant_bool2t, constant_fixedbv2t, constant_floatbv2t, constant_int2t, constant_string2t, constant_struct2t, constant_union2t, constant_vector2t, dereference2t, dynamic_object2t, exists2t, extract2t, forall2t, ieee_fma2t, ieee_sqrt2t, if2t, index2t, invalid_pointer2t, member2t, member_ref2t, nearbyint2t, new_object2t, not2t, object_descriptor2t, overflow2t, overflow_cast2t, overflow_neg2t, pointer_offset2t, ptr_mem2t, same_object2t, sideeffect2t, sideeffect_assign2t, sizeof2t, symbol2t, typecast2t, uninterpreted_func2t, and with2t.

Public Types

enum  expr_ids { end_expr_id }
 Enumeration identifying each sort of expr. More...
typedef esbmct::function_ref< void(const expr2tc &)> const_op_delegate
typedef esbmct::function_ref< void(expr2tc &)> op_delegate
typedef expr2tc container_type
typedef expr2t base_type

Public Member Functions

virtual ~expr2t ()=default
expr2tc clone () const
expr2tc with_type (const type2tc &new_type) const
 Build a fresh expression of the same kind and field values as this one, but with a different type.
bool operator== (const expr2t &ref) const
bool operator< (const expr2t &ref) const
bool operator!= (const expr2t &ref) const
std::string pretty (unsigned int indent=0) const
 Produce textual representation of this expr.
DUMP_METHOD void dump () const
 Write textual representation of this object to stdout.
size_t crc () const
 Calculate a hash/digest of the current expr.
bool cmp (const expr2t &ref) const
 Structural comparison.
int lt (const expr2t &ref) const
 Trinary structural ordering.
list_of_memberst tostring (unsigned int indent) const
 Convert fields of subclasses to a string representation.
const expr2tc * get_sub_expr (size_t idx) const
 Fetch a sub-operand.
size_t get_num_sub_exprs () const
 Count the number of sub-exprs there are.
expr2tc simplify () const
 Simplify an expression.
expr2tc simplify (bool suppress_reassoc) const
 Simplify with reassociation suppression.
virtual expr2tc do_simplify () const
 expr-specific simplification methods.
template<typename T>
void foreach_operand (T &&t) const
 Indirect, abstract operand iteration.
template<typename T>
void Foreach_operand (T &&t)
Public Member Functions inherited from irep2t
 irep2t () noexcept
 irep2t (const irep2t &) noexcept
irep2t & operator= (const irep2t &)=delete
virtual ~irep2t ()=default
void mark_writer () const noexcept
void clear_writer () const noexcept

Public Attributes

const expr_ids expr_id
 Instance of expr_ids recording tihs exprs type.
const type2tc type
 Type of this expr.
std::atomic< size_t > crc_val
Public Attributes inherited from irep2t
std::atomic< unsigned int > refcount
std::atomic< std::uintptr_t > writer_thread

Protected Member Functions

 expr2t (const type2tc &type, expr_ids id)
 Primary constructor.
 expr2t (const expr2t &ref)
 Copy constructor.
void foreach_operand_impl_const (const_op_delegate &expr) const
void foreach_operand_impl (op_delegate &expr)

Additional Inherited Members

Static Public Member Functions inherited from irep2t
static std::uintptr_t current_thread_tag () noexcept

Detailed Description

Base class for all expressions.

In this base, contains an expression id used for distinguishing different classes of expr, in addition we have a type as all exprs should have types.

Member Typedef Documentation

◆ base_type

◆ const_op_delegate

◆ container_type

◆ op_delegate

Member Enumeration Documentation

◆ expr_ids

Enumeration identifying each sort of expr.

Enumerator
end_expr_id 

Constructor & Destructor Documentation

◆ expr2t() [1/2]

expr2t::expr2t ( const type2tc & type,
expr_ids id )
protected

Primary constructor.

Parameters
typeType of this new expr
idClass identifier for this new expr

◆ expr2t() [2/2]

expr2t::expr2t ( const expr2t & ref)
protected

Copy constructor.

◆ ~expr2t()

virtual expr2t::~expr2t ( )
virtualdefault

Member Function Documentation

◆ clone()

expr2tc expr2t::clone ( ) const

◆ cmp()

bool expr2t::cmp ( const expr2t & ref) const

Structural comparison.

The expr_id check is done by the switch dispatcher inside, so callers don't have to gate the call on kind. Should normally be reached via operator==.

See also
type2t::cmp
Parameters
refExpr object to compare this against
Returns
True if objects are the same; false otherwise.

◆ crc()

size_t expr2t::crc ( ) const

Calculate a hash/digest of the current expr.

For use in hash data structures; produces a size_t digest via hash_combine over the node's fields (formerly a crc32).

Returns
Hash value of this expr

◆ do_simplify()

expr2tc expr2t::do_simplify ( ) const
nodiscardvirtual

expr-specific simplification methods.

By default, an expression can't be simplified, and this method returns a nil expression to show that. However if simplification is possible, the subclass overrides this and if it can simplify its operands, returns a new simplified expression. It should attempt to modify itself (it's const).

If simplification failed the first time around, the simplify method will simplify this expressions individual operands, and will then call an expr with the simplified operands to see if it's now become simplifiable. This call occurs whether or not any operands were actually simplified, see below.

The 'second' parameter can be used to avoid invoking expensive attempts to simplify an expression more than once - on the first call to do_simplify this parameter will be false, then on the second it's be true, allowing method implementation to save the expensive stuff until all of its operands have certainly been simplified.

Currently simplification does some things that it shouldn't: pointer arithmetic for example. I'm not sure where this can be relocated to though.

Returns
expr2tc A nil expression if no simplifcation could occur, or a new simplified object if it can.

Reimplemented in address_of2t, bitcast2t, byte_extract2t, byte_update2t, cmp_three_way2t, code_decl2t, concat2t, constant_array2t, constant_struct2t, extract2t, ieee_fma2t, ieee_sqrt2t, if2t, index2t, member2t, nearbyint2t, new_object2t, not2t, overflow2t, overflow_cast2t, pointer_offset2t, same_object2t, sizeof2t, typecast2t, and with2t.

◆ dump()

void expr2t::dump ( ) const

Write textual representation of this object to stdout.

For use in debugging - dumps the output of the pretty method to stdout. Can either be used in portion of code, or more commonly called from gdb.

◆ Foreach_operand()

template<typename T>
void expr2t::Foreach_operand ( T && t)
inline

◆ foreach_operand()

template<typename T>
void expr2t::foreach_operand ( T && t) const
inline

Indirect, abstract operand iteration.

Lambda-based accessor: the delegate is called on every expr2tc field in this expression, in K::fields order. For a vector<expr2tc> field, the delegate is called once per element. Delegates are wrapped in a non-owning function_ref so any callable (lambda, free function, member-pointer-with-bound-instance) flows through without dynamic allocation.

The lowercase version is const; the capitalised version is non-const (and so one needs to .get() a mutable expr2t pointer when calling). When modifying operands, preserving type correctness is imperative.

Parameters
tA delegate to be called for each expression operand; must have a type of void f(const expr2tc &)

◆ foreach_operand_impl()

void expr2t::foreach_operand_impl ( op_delegate & expr)
protected

◆ foreach_operand_impl_const()

void expr2t::foreach_operand_impl_const ( const_op_delegate & expr) const
protected

◆ get_num_sub_exprs()

size_t expr2t::get_num_sub_exprs ( ) const

Count the number of sub-exprs there are.

◆ get_sub_expr()

const expr2tc * expr2t::get_sub_expr ( size_t idx) const

Fetch a sub-operand.

These can come out of any field that is an expr2tc, or contains them. No particular numbering order is promised.

◆ lt()

int expr2t::lt ( const expr2t & ref) const

Trinary structural ordering.

Mirrors cmp but returns -1/0/+1; mismatched expr_ids are ordered by the id itself.

Parameters
refExpr object to compare this against
Returns
0 If exprs are the same, 1 if this > ref, -1 if ref > this.

◆ operator!=()

bool expr2t::operator!= ( const expr2t & ref) const

◆ operator<()

bool expr2t::operator< ( const expr2t & ref) const

◆ operator==()

bool expr2t::operator== ( const expr2t & ref) const

◆ pretty()

std::string expr2t::pretty ( unsigned int indent = 0) const

Produce textual representation of this expr.

Takes the current object and produces a textual representation that can be read by a human to understand what's going on.

Parameters
indentNumber of spaces to indent the output string lines by
Returns
String object containing textual expr representation.

◆ simplify() [1/2]

expr2tc expr2t::simplify ( ) const

Simplify an expression.

Returns a new expression when a calculation or operation can be folded.

Returns
Either a nil expr (null pointer contents) if nothing could be simplified or a simplified expression.

◆ simplify() [2/2]

expr2tc expr2t::simplify ( bool suppress_reassoc) const

Simplify with reassociation suppression.

When suppress_reassoc is true, the chain-root reassociation step is skipped throughout the subtree (the flag propagates to every descendant, including those reached through non-chain ops like modulus). Used by simplify_no_reassoc to walk a subtree with peepholes only, e.g. on a freshly-rebuilt chain. External callers should prefer simplify_no_reassoc in util/expr_reassociate.h over calling this overload directly.

◆ tostring()

list_of_memberst expr2t::tostring ( unsigned int indent) const

Convert fields of subclasses to a string representation.

Used internally by the pretty method - creates a list of pairs representing the fields in the subclass. Each pair is a pair of strings of the form fieldname : value. The value may be multiline, in which case the new line will have at least indent number of indenting spaces.

Parameters
indentNumber of spaces to indent multiline output by
Returns
list of string pairs, of form fieldname:value

◆ with_type()

expr2tc expr2t::with_type ( const type2tc & new_type) const

Build a fresh expression of the same kind and field values as this one, but with a different type.

Assumes every kind's primary constructor takes (type, fields...) matching its K::fields tuple in order.

Member Data Documentation

◆ crc_val

std::atomic<size_t> expr2t::crc_val
mutable

◆ expr_id

const expr_ids expr2t::expr_id

Instance of expr_ids recording tihs exprs type.

◆ type

const type2tc expr2t::type

Type of this expr.

All exprs have a type.


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