|
ESBMC
Efficient SMT-based Context-Bounded Model Checker
|
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 |
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.
| typedef expr2t expr2t::base_type |
| typedef esbmct::function_ref<void(const expr2tc &)> expr2t::const_op_delegate |
| typedef expr2tc expr2t::container_type |
| typedef esbmct::function_ref<void(expr2tc &)> expr2t::op_delegate |
Primary constructor.
| type | Type of this new expr |
| id | Class identifier for this new expr |
|
protected |
Copy constructor.
|
virtualdefault |
| expr2tc expr2t::clone | ( | ) | 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==.
| ref | Expr object to compare this against |
| 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).
|
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.
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.
| 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.
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.
| t | A delegate to be called for each expression operand; must have a type of void f(const expr2tc &) |
|
protected |
|
protected |
| size_t expr2t::get_num_sub_exprs | ( | ) | const |
Count the number of sub-exprs there are.
Fetch a sub-operand.
These can come out of any field that is an expr2tc, or contains them. No particular numbering order is promised.
| 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.
| indent | Number of spaces to indent the output string lines by |
| expr2tc expr2t::simplify | ( | ) | const |
Simplify an expression.
Returns a new expression when a calculation or operation can be folded.
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.
| 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.
| indent | Number of spaces to indent multiline output by |
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.
|
mutable |
| const type2tc expr2t::type |
Type of this expr.
All exprs have a type.