CBMC
exprt Class Reference

Base class for all expressions. More...

#include <expr.h>

+ Inheritance diagram for exprt:
+ Collaboration diagram for exprt:

Public Types

typedef std::vector< exprtoperandst
 
- Public Types inherited from irept
using baset = tree_implementationt
 
- Public Types inherited from sharing_treet< irept, forward_list_as_mapt< irep_idt, irept > >
using dt = tree_nodet< irept, forward_list_as_mapt< irep_idt, irept >, true >
 
using subt = typename dt::subt
 
using named_subt = typename dt::named_subt
 
using tree_implementationt = sharing_treet
 Used to refer to this class from derived classes. More...
 

Public Member Functions

 exprt ()
 
 exprt (const irep_idt &_id)
 
 exprt (irep_idt _id, typet _type)
 
 exprt (irep_idt _id, typet _type, operandst &&_operands)
 
 exprt (const irep_idt &id, typet type, source_locationt loc)
 
typettype ()
 Return the type of the expression. More...
 
const typettype () const
 
bool has_operands () const
 Return true if there is at least one operand. More...
 
operandstoperands ()
 
const operandstoperands () const
 
template<typename T >
T & with_source_location (const exprt &other) &
 Add the source location from other, if it has any. More...
 
template<typename T >
T && with_source_location (const exprt &other) &&
 Add the source location from other, if it has any. More...
 
void reserve_operands (operandst::size_type n)
 
void copy_to_operands (const exprt &expr)
 Copy the given argument to the end of exprt's operands. More...
 
void add_to_operands (const exprt &expr)
 Add the given argument to the end of exprt's operands. More...
 
void add_to_operands (exprt &&expr)
 Add the given argument to the end of exprt's operands. More...
 
void add_to_operands (exprt &&e1, exprt &&e2)
 Add the given arguments to the end of exprt's operands. More...
 
void add_to_operands (exprt &&e1, exprt &&e2, exprt &&e3)
 Add the given arguments to the end of exprt's operands. More...
 
bool is_constant () const
 Return whether the expression is a constant. More...
 
bool is_true () const
 Return whether the expression is a constant representing true. More...
 
bool is_false () const
 Return whether the expression is a constant representing false. More...
 
bool is_zero () const
 Return whether the expression is a constant representing 0. More...
 
bool is_one () const
 Return whether the expression is a constant representing 1. More...
 
bool is_boolean () const
 Return whether the expression represents a Boolean. More...
 
const source_locationtfind_source_location () const
 Get a source_locationt from the expression or from its operands (non-recursively). More...
 
const source_locationtsource_location () const
 
source_locationtadd_source_location ()
 
void drop_source_location ()
 
void visit (class expr_visitort &visitor)
 These are pre-order traversal visitors, i.e., the visitor is executed on a node before its children have been visited. More...
 
void visit (class const_expr_visitort &visitor) const
 
void visit_pre (std::function< void(exprt &)>)
 
void visit_pre (std::function< void(const exprt &)>) const
 
void visit_post (std::function< void(exprt &)>)
 These are post-order traversal visitors, i.e., the visitor is executed on a node after its children have been visited. More...
 
void visit_post (std::function< void(const exprt &)>) const
 
depth_iteratort depth_begin ()
 
depth_iteratort depth_end ()
 
const_depth_iteratort depth_begin () const
 
const_depth_iteratort depth_end () const
 
const_depth_iteratort depth_cbegin () const
 
const_depth_iteratort depth_cend () const
 
depth_iteratort depth_begin (std::function< exprt &()> mutate_root) const
 
const_unique_depth_iteratort unique_depth_begin () const
 
const_unique_depth_iteratort unique_depth_end () const
 
const_unique_depth_iteratort unique_depth_cbegin () const
 
const_unique_depth_iteratort unique_depth_cend () const
 
- Public Member Functions inherited from irept
bool is_nil () const
 
bool is_not_nil () const
 
 irept (const irep_idt &_id)
 
 irept (const irep_idt &_id, const named_subt &_named_sub, const subt &_sub)
 
 irept ()=default
 
const irep_idtid () const
 
const std::string & id_string () const
 
void id (const irep_idt &_data)
 
const ireptfind (const irep_idt &name) const
 
ireptadd (const irep_idt &name)
 
ireptadd (const irep_idt &name, irept irep)
 
const std::string & get_string (const irep_idt &name) const
 
const irep_idtget (const irep_idt &name) const
 
bool get_bool (const irep_idt &name) const
 
signed int get_int (const irep_idt &name) const
 
std::size_t get_size_t (const irep_idt &name) const
 
long long get_long_long (const irep_idt &name) const
 
void set (const irep_idt &name, const irep_idt &value)
 
void set (const irep_idt &name, irept irep)
 
void set (const irep_idt &name, const long long value)
 
void set_size_t (const irep_idt &name, const std::size_t value)
 
void remove (const irep_idt &name)
 
void move_to_sub (irept &irep)
 
void move_to_named_sub (const irep_idt &name, irept &irep)
 
bool operator== (const irept &other) const
 
bool operator!= (const irept &other) const
 
void swap (irept &irep)
 
bool operator< (const irept &other) const
 defines ordering on the internal representation More...
 
bool ordering (const irept &other) const
 defines ordering on the internal representation More...
 
int compare (const irept &i) const
 defines ordering on the internal representation comments are ignored More...
 
void clear ()
 
void make_nil ()
 
subtget_sub ()
 
const subtget_sub () const
 
named_subtget_named_sub ()
 
const named_subtget_named_sub () const
 
std::size_t hash () const
 
std::size_t full_hash () const
 
bool full_eq (const irept &other) const
 
std::string pretty (unsigned indent=0, unsigned max_indent=0) const
 
- Public Member Functions inherited from sharing_treet< irept, forward_list_as_mapt< irep_idt, irept > >
 sharing_treet (irep_idt _id)
 
 sharing_treet (irep_idt _id, named_subt _named_sub, subt _sub)
 
 sharing_treet ()
 
 sharing_treet (const sharing_treet &irep)
 
 sharing_treet (sharing_treet &&irep)
 
sharing_treetoperator= (const sharing_treet &irep)
 
sharing_treetoperator= (sharing_treet &&irep)
 
 ~sharing_treet ()
 
const dtread () const
 
dtwrite ()
 

Static Public Member Functions

static void check (const exprt &, const validation_modet)
 Check that the expression is well-formed (shallow checks only, i.e., subexpressions and its type are not checked). More...
 
static void validate (const exprt &expr, const namespacet &, const validation_modet vm=validation_modet::INVARIANT)
 Check that the expression is well-formed, assuming that its subexpressions and type have all ready been checked for well-formedness. More...
 
static void validate_full (const exprt &expr, const namespacet &ns, const validation_modet vm=validation_modet::INVARIANT)
 Check that the expression is well-formed (full check, including checks of all subexpressions and the type) More...
 
- Static Public Member Functions inherited from irept
static bool is_comment (const irep_idt &name)
 
static std::size_t number_of_non_comments (const named_subt &)
 count the number of named_sub elements that are not comments More...
 

Protected Member Functions

exprtop0 ()
 
exprtop1 ()
 
exprtop2 ()
 
exprtop3 ()
 
const exprtop0 () const
 
const exprtop1 () const
 
const exprtop2 () const
 
const exprtop3 () const
 
exprtadd_expr (const irep_idt &name)
 
const exprtfind_expr (const irep_idt &name) const
 
- Protected Member Functions inherited from sharing_treet< irept, forward_list_as_mapt< irep_idt, irept > >
void detach ()
 

Additional Inherited Members

- Static Protected Member Functions inherited from sharing_treet< irept, forward_list_as_mapt< irep_idt, irept > >
static void remove_ref (dt *old_data)
 
static void nonrecursive_destructor (dt *old_data)
 Does the same as remove_ref, but using an explicit stack instead of recursion. More...
 
- Protected Attributes inherited from sharing_treet< irept, forward_list_as_mapt< irep_idt, irept > >
dtdata
 
- Static Protected Attributes inherited from sharing_treet< irept, forward_list_as_mapt< irep_idt, irept > >
static dt empty_d
 

Detailed Description

Base class for all expressions.

Inherits from irept and has operands (stored as unnamed children of irept), and a type (which is a named sub with identifier ID_type). The class contains functions to access and modify the operands, as well as visitor utilities.

The example below shows the irept structure of the sum of integers 3 and 5.

Some context available here: exprt section in util module

Definition at line 55 of file expr.h.

Member Typedef Documentation

◆ operandst

typedef std::vector<exprt> exprt::operandst

Definition at line 58 of file expr.h.

Constructor & Destructor Documentation

◆ exprt() [1/5]

exprt::exprt ( )
inline

Definition at line 61 of file expr.h.

◆ exprt() [2/5]

exprt::exprt ( const irep_idt _id)
inlineexplicit

Definition at line 62 of file expr.h.

◆ exprt() [3/5]

exprt::exprt ( irep_idt  _id,
typet  _type 
)
inline

Definition at line 64 of file expr.h.

◆ exprt() [4/5]

exprt::exprt ( irep_idt  _id,
typet  _type,
operandst &&  _operands 
)
inline

Definition at line 69 of file expr.h.

◆ exprt() [5/5]

exprt::exprt ( const irep_idt id,
typet  type,
source_locationt  loc 
)
inline

Definition at line 77 of file expr.h.

Member Function Documentation

◆ add_expr()

exprt& exprt::add_expr ( const irep_idt name)
inlineprotected

Definition at line 282 of file expr.h.

◆ add_source_location()

source_locationt& exprt::add_source_location ( )
inline

Definition at line 216 of file expr.h.

◆ add_to_operands() [1/4]

void exprt::add_to_operands ( const exprt expr)
inline

Add the given argument to the end of exprt's operands.

Parameters
exprexprt to append to the operands

Definition at line 162 of file expr.h.

◆ add_to_operands() [2/4]

void exprt::add_to_operands ( exprt &&  e1,
exprt &&  e2 
)
inline

Add the given arguments to the end of exprt's operands.

Parameters
e1first exprt to append to the operands
e2second exprt to append to the operands

Definition at line 177 of file expr.h.

◆ add_to_operands() [3/4]

void exprt::add_to_operands ( exprt &&  e1,
exprt &&  e2,
exprt &&  e3 
)
inline

Add the given arguments to the end of exprt's operands.

Parameters
e1first exprt to append to the operands
e2second exprt to append to the operands
e3third exprt to append to the operands

Definition at line 191 of file expr.h.

◆ add_to_operands() [4/4]

void exprt::add_to_operands ( exprt &&  expr)
inline

Add the given argument to the end of exprt's operands.

Parameters
exprexprt to append to the operands

Definition at line 169 of file expr.h.

◆ check()

static void exprt::check ( const exprt ,
const  validation_modet 
)
inlinestatic

Check that the expression is well-formed (shallow checks only, i.e., subexpressions and its type are not checked).

Subclasses may override this function to provide specific well-formedness checks for the corresponding expressions.

The validation mode indicates whether well-formedness check failures are reported via DATA_INVARIANT violations or exceptions.

Definition at line 234 of file expr.h.

◆ copy_to_operands()

void exprt::copy_to_operands ( const exprt expr)
inline

Copy the given argument to the end of exprt's operands.

Parameters
exprexprt to append to the operands

Definition at line 155 of file expr.h.

◆ depth_begin() [1/3]

depth_iteratort exprt::depth_begin ( )

Definition at line 265 of file expr.cpp.

◆ depth_begin() [2/3]

const_depth_iteratort exprt::depth_begin ( ) const

Definition at line 269 of file expr.cpp.

◆ depth_begin() [3/3]

depth_iteratort exprt::depth_begin ( std::function< exprt &()>  mutate_root) const

Definition at line 277 of file expr.cpp.

◆ depth_cbegin()

const_depth_iteratort exprt::depth_cbegin ( ) const

Definition at line 273 of file expr.cpp.

◆ depth_cend()

const_depth_iteratort exprt::depth_cend ( ) const

Definition at line 275 of file expr.cpp.

◆ depth_end() [1/2]

depth_iteratort exprt::depth_end ( )

Definition at line 267 of file expr.cpp.

◆ depth_end() [2/2]

const_depth_iteratort exprt::depth_end ( ) const

Definition at line 271 of file expr.cpp.

◆ drop_source_location()

void exprt::drop_source_location ( )
inline

Definition at line 221 of file expr.h.

◆ find_expr()

const exprt& exprt::find_expr ( const irep_idt name) const
inlineprotected

Definition at line 287 of file expr.h.

◆ find_source_location()

const source_locationt & exprt::find_source_location ( ) const

Get a source_locationt from the expression or from its operands (non-recursively).

If no source location is found, a nil source_locationt is returned.

Returns
A source location if found in the expression or its operands, nil otherwise.

Definition at line 165 of file expr.cpp.

◆ has_operands()

bool exprt::has_operands ( ) const
inline

Return true if there is at least one operand.

Definition at line 91 of file expr.h.

◆ is_boolean()

bool exprt::is_boolean ( ) const

Return whether the expression represents a Boolean.

Returns
True if is a Boolean, false otherwise.

Definition at line 52 of file expr.cpp.

◆ is_constant()

bool exprt::is_constant ( ) const

Return whether the expression is a constant.

Returns
True if is a constant, false otherwise

Definition at line 27 of file expr.cpp.

◆ is_false()

bool exprt::is_false ( ) const

Return whether the expression is a constant representing false.

Returns
True if is a Boolean constant representing false, false otherwise.

Definition at line 43 of file expr.cpp.

◆ is_one()

bool exprt::is_one ( ) const

Return whether the expression is a constant representing 1.

Will consider the following types: ID_integer, ID_natural, ID_rational, ID_unsignedbv, ID_signedbv, ID_c_bool, ID_c_bit_field, ID_fixedbv, ID_floatbv.
For all other types, return false.

Returns
True if has value 1, false otherwise.

Definition at line 114 of file expr.cpp.

◆ is_true()

bool exprt::is_true ( ) const

Return whether the expression is a constant representing true.

Returns
True if is a Boolean constant representing true, false otherwise.

Definition at line 34 of file expr.cpp.

◆ is_zero()

bool exprt::is_zero ( ) const

Return whether the expression is a constant representing 0.

Will consider the following types: ID_integer, ID_natural, ID_rational, ID_unsignedbv, ID_signedbv, ID_c_bool, ID_c_bit_field, ID_fixedbv, ID_floatbv, ID_pointer.
For ID_pointer, returns true iff the value is a zero string or a null pointer. For everything not in the above list, return false.

Returns
True if has value 0, false otherwise.

Definition at line 65 of file expr.cpp.

◆ op0() [1/2]

exprt& exprt::op0 ( )
inlineprotected

Definition at line 125 of file expr.h.

◆ op0() [2/2]

const exprt& exprt::op0 ( ) const
inlineprotected

Definition at line 137 of file expr.h.

◆ op1() [1/2]

exprt& exprt::op1 ( )
inlineprotected

Definition at line 128 of file expr.h.

◆ op1() [2/2]

const exprt& exprt::op1 ( ) const
inlineprotected

Definition at line 140 of file expr.h.

◆ op2() [1/2]

exprt& exprt::op2 ( )
inlineprotected

Definition at line 131 of file expr.h.

◆ op2() [2/2]

const exprt& exprt::op2 ( ) const
inlineprotected

Definition at line 143 of file expr.h.

◆ op3() [1/2]

exprt& exprt::op3 ( )
inlineprotected

Definition at line 134 of file expr.h.

◆ op3() [2/2]

const exprt& exprt::op3 ( ) const
inlineprotected

Definition at line 146 of file expr.h.

◆ operands() [1/2]

operandst& exprt::operands ( )
inline

Definition at line 94 of file expr.h.

◆ operands() [2/2]

const operandst& exprt::operands ( ) const
inline

Definition at line 97 of file expr.h.

◆ reserve_operands()

void exprt::reserve_operands ( operandst::size_type  n)
inline

Definition at line 150 of file expr.h.

◆ source_location()

const source_locationt& exprt::source_location ( ) const
inline

Definition at line 211 of file expr.h.

◆ type() [1/2]

typet& exprt::type ( )
inline

Return the type of the expression.

Definition at line 84 of file expr.h.

◆ type() [2/2]

const typet& exprt::type ( ) const
inline

Definition at line 85 of file expr.h.

◆ unique_depth_begin()

const_unique_depth_iteratort exprt::unique_depth_begin ( ) const

Definition at line 282 of file expr.cpp.

◆ unique_depth_cbegin()

const_unique_depth_iteratort exprt::unique_depth_cbegin ( ) const

Definition at line 286 of file expr.cpp.

◆ unique_depth_cend()

const_unique_depth_iteratort exprt::unique_depth_cend ( ) const

Definition at line 288 of file expr.cpp.

◆ unique_depth_end()

const_unique_depth_iteratort exprt::unique_depth_end ( ) const

Definition at line 284 of file expr.cpp.

◆ validate()

static void exprt::validate ( const exprt expr,
const namespacet ,
const validation_modet  vm = validation_modet::INVARIANT 
)
inlinestatic

Check that the expression is well-formed, assuming that its subexpressions and type have all ready been checked for well-formedness.

Subclasses may override this function to provide specific well-formedness checks for the corresponding expressions.

The validation mode indicates whether well-formedness check failures are reported via DATA_INVARIANT violations or exceptions.

Definition at line 246 of file expr.h.

◆ validate_full()

static void exprt::validate_full ( const exprt expr,
const namespacet ns,
const validation_modet  vm = validation_modet::INVARIANT 
)
inlinestatic

Check that the expression is well-formed (full check, including checks of all subexpressions and the type)

Subclasses may override this function, though in most cases the provided implementation should be sufficient.

The validation mode indicates whether well-formedness check failures are reported via DATA_INVARIANT violations or exceptions.

Definition at line 262 of file expr.h.

◆ visit() [1/2]

void exprt::visit ( class const_expr_visitort visitor) const

Definition at line 260 of file expr.cpp.

◆ visit() [2/2]

void exprt::visit ( class expr_visitort visitor)

These are pre-order traversal visitors, i.e., the visitor is executed on a node before its children have been visited.

Definition at line 255 of file expr.cpp.

◆ visit_post() [1/2]

void exprt::visit_post ( std::function< void(const exprt &)>  visitor) const

Definition at line 221 of file expr.cpp.

◆ visit_post() [2/2]

void exprt::visit_post ( std::function< void(exprt &)>  visitor)

These are post-order traversal visitors, i.e., the visitor is executed on a node after its children have been visited.

Definition at line 216 of file expr.cpp.

◆ visit_pre() [1/2]

void exprt::visit_pre ( std::function< void(const exprt &)>  visitor) const

Definition at line 250 of file expr.cpp.

◆ visit_pre() [2/2]

void exprt::visit_pre ( std::function< void(exprt &)>  visitor)

Definition at line 245 of file expr.cpp.

◆ with_source_location() [1/2]

template<typename T >
T& exprt::with_source_location ( const exprt other) &
inline

Add the source location from other, if it has any.

Definition at line 102 of file expr.h.

◆ with_source_location() [2/2]

template<typename T >
T&& exprt::with_source_location ( const exprt other) &&
inline

Add the source location from other, if it has any.

Definition at line 114 of file expr.h.


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