Hex-Rays logo State-of-the-art binary code analysis tools
email icon

Ctree item: expression. More...

#include <hexrays.hpp>

Inheritance diagram for cexpr_t:
citem_t carg_t

Public Member Functions

bool cpadone (void) const
 Pointer arithmetic correction done for this expression? More...
 
bool is_odd_lvalue (void) const
 
bool is_fpop (void) const
 
bool is_cstr (void) const
 
bool is_type_partial (void) const
 
bool is_undef_val (void) const
 
bool is_jumpout (void) const
 
bool is_vftable (void) const
 
void set_cpadone (void)
 
void set_vftable (void)
 
void set_type_partial (bool val=true)
 
 cexpr_t (ctype_t cop, cexpr_t *_x)
 
 cexpr_t (ctype_t cop, cexpr_t *_x, cexpr_t *_y)
 
 cexpr_t (ctype_t cop, cexpr_t *_x, cexpr_t *_y, cexpr_t *_z)
 
 cexpr_t (mba_t *mba, const lvar_t &v)
 
 cexpr_t (const cexpr_t &r)
 
void swap (cexpr_t &r)
 
cexpr_toperator= (const cexpr_t &r)
 
cexpr_tassign (const cexpr_t &r)
 
 DECLARE_COMPARISONS (cexpr_t)
 
void replace_by (cexpr_t *r)
 Replace the expression. More...
 
void cleanup (void)
 Cleanup the expression. More...
 
void put_number (cfunc_t *func, uint64 value, int nbytes, type_sign_t sign=no_sign)
 Assign a number to the expression. More...
 
void print1 (qstring *vout, const cfunc_t *func) const
 Print expression into one line. More...
 
void calc_type (bool recursive)
 Calculate the type of the expression. More...
 
bool equal_effect (const cexpr_t &r) const
 Compare two expressions. More...
 
bool is_child_of (const citem_t *parent) const
 Verify if the specified item is our parent. More...
 
bool contains_operator (ctype_t needed_op, int times=1) const
 Check if the expression contains the specified operator. More...
 
bool contains_comma (int times=1) const
 Does the expression contain a comma operator? More...
 
bool contains_insn (int times=1) const
 Does the expression contain an embedded statement operator? More...
 
bool contains_insn_or_label (void) const
 Does the expression contain an embedded statement operator or a label? More...
 
bool contains_comma_or_insn_or_label (int maxcommas=1) const
 Does the expression contain a comma operator or an embedded statement operator or a label? More...
 
bool is_nice_expr (void) const
 Is nice expression? Nice expressions do not contain comma operators, embedded statements, or labels. More...
 
bool is_nice_cond (void) const
 Is nice condition?. More...
 
bool is_call_object_of (const citem_t *parent) const
 Is call object? More...
 
bool is_call_arg_of (const citem_t *parent) const
 Is call argument? More...
 
type_sign_t get_type_sign (void) const
 Get expression sign. More...
 
bool is_type_unsigned (void) const
 Is expression unsigned? More...
 
bool is_type_signed (void) const
 Is expression signed? More...
 
bit_bound_t get_high_nbit_bound (void) const
 Get max number of bits that can really be used by the expression. More...
 
int get_low_nbit_bound () const
 Get min number of bits that are certainly required to represent the expression. More...
 
bool requires_lvalue (const cexpr_t *child) const
 Check if the expression requires an lvalue. More...
 
bool has_side_effects (void) const
 Check if the expression has side effects. More...
 
bool like_boolean (void) const
 Does the expression look like a boolean expression? In other words, its possible values are only 0 and 1.
 
bool is_aliasable (void) const
 Check if the expression if aliasable. More...
 
uint64 numval (void) const
 Get numeric value of the expression. More...
 
bool is_const_value (uint64 _v) const
 Check if the expression is a number with the specified value. More...
 
bool is_negative_const (void) const
 Check if the expression is a negative number. More...
 
bool is_non_negative_const (void) const
 Check if the expression is a non-negative number. More...
 
bool is_non_zero_const (void) const
 Check if the expression is a non-zero number. More...
 
bool is_zero_const (void) const
 Check if the expression is a zero. More...
 
bool is_value_used (const citem_t *parent) const
 Does the PARENT need the expression value.
 
bool get_const_value (uint64 *out) const
 Get expression value. More...
 
bool maybe_ptr (void) const
 May the expression be a pointer? More...
 
cexpr_tget_ptr_or_array (void)
 Find pointer or array child. More...
 
const cexpr_tfind_op (ctype_t _op) const
 Find the child with the specified operator. More...
 
cexpr_tfind_op (ctype_t _op)
 
const cexpr_tfind_num_op (void) const
 Find the operand with a numeric value. More...
 
cexpr_tfind_num_op (void)
 
const cexpr_tfind_ptr_or_array (bool remove_eqsize_casts) const
 Find the pointer operand. More...
 
const cexpr_ttheother (const cexpr_t *what) const
 Get the other operand. More...
 
cexpr_ttheother (const cexpr_t *what)
 
bool get_1num_op (cexpr_t **o1, cexpr_t **o2)
 Get pointers to operands. More...
 
bool get_1num_op (const cexpr_t **o1, const cexpr_t **o2) const
 
- Public Member Functions inherited from citem_t
 citem_t (ctype_t o=cot_empty)
 
void swap (citem_t &r)
 Swap two citem_t. More...
 
bool is_expr (void) const
 Is an expression? More...
 
bool contains_expr (const cexpr_t *e) const
 Does the item contain an expression? More...
 
bool contains_label (void) const
 Does the item contain a label? More...
 
const citem_tfind_parent_of (const citem_t *sitem) const
 Find parent of the specified item. More...
 
citem_tfind_parent_of (const citem_t *item)
 
citem_tfind_closest_addr (ea_t _ea)
 
void print1 (qstring *vout, const cfunc_t *func) const
 Print item into one line. More...
 

Public Attributes

union {
   cnumber_t *   n
 used for cot_num More...
 
   fnumber_t *   fpc
 used for cot_fnum More...
 
   struct {
      union {
         var_ref_t   v
 used for cot_var More...
 
         ea_t   obj_ea
 used for cot_obj More...
 
      } 
 
      int   refwidth
 how many bytes are accessed? (-1: none) More...
 
   } 
 
   struct {
      cexpr_t *   x
 the first operand of the expression More...
 
      union {
         cexpr_t *   y
 the second operand of the expression More...
 
         carglist_t *   a
 argument list (used for cot_call) More...
 
         uint32   m
 member offset (used for cot_memptr, cot_memref) for unions, the member number More...
 
      } 
 
      union {
         cexpr_t *   z
 the third operand of the expression More...
 
         int   ptrsize
 memory access size (used for cot_ptr, cot_memptr) More...
 
      } 
 
   } 
 
   cinsn_t *   insn
 an embedded statement, they are prohibited at the final maturity stage (CMAT_FINAL) More...
 
   char *   helper
 helper name (used for cot_helper) More...
 
   char *   string
 utf8 string constant, user representation (used for cot_str) More...
 
}; 
 
tinfo_t type
 expression type. must be carefully maintained More...
 
uint32 exflags
 Expression attributes More...
 
- Public Attributes inherited from citem_t
ea_t ea = BADADDR
 address that corresponds to the item. may be BADADDR More...
 
ctype_t op = cot_empty
 item type More...
 
int label_num = -1
 label number. More...
 
int index = -1
 an index in cfunc_t::treeitems. More...
 

Detailed Description

Ctree item: expression.

Depending on the exact expression item type, various fields of this structure are used.

Examples
hexrays_sample17.cpp, hexrays_sample2.cpp, hexrays_sample3.cpp, and hexrays_sample5.cpp.

Definition at line 6037 of file hexrays.hpp.

Constructor & Destructor Documentation

◆ cexpr_t() [1/5]

cexpr_t::cexpr_t ( void  )

Definition at line 6110 of file hexrays.hpp.

◆ cexpr_t() [2/5]

cexpr_t::cexpr_t ( ctype_t  cop,
cexpr_t _x 
)

Definition at line 6111 of file hexrays.hpp.

◆ cexpr_t() [3/5]

cexpr_t::cexpr_t ( ctype_t  cop,
cexpr_t _x,
cexpr_t _y 
)

Definition at line 6112 of file hexrays.hpp.

◆ cexpr_t() [4/5]

cexpr_t::cexpr_t ( ctype_t  cop,
cexpr_t _x,
cexpr_t _y,
cexpr_t _z 
)

Definition at line 6113 of file hexrays.hpp.

◆ cexpr_t() [5/5]

cexpr_t::cexpr_t ( const cexpr_t r)

Definition at line 6115 of file hexrays.hpp.

◆ ~cexpr_t()

cexpr_t::~cexpr_t ( void  )

Definition at line 6120 of file hexrays.hpp.

Member Function Documentation

◆ assign()

cexpr_t & cexpr_t::assign ( const cexpr_t r)

Definition at line 11477 of file hexrays.hpp.

◆ calc_type()

void cexpr_t::calc_type ( bool  recursive)

Calculate the type of the expression.

Use this function to calculate the expression type when a new expression is built

Parameters
recursiveif true, types of all children expression will be calculated before calculating our type

Definition at line 11513 of file hexrays.hpp.

◆ cleanup()

void cexpr_t::cleanup ( void  )

Cleanup the expression.

This function properly deletes all children and sets the item type to cot_empty.

Definition at line 11495 of file hexrays.hpp.

◆ contains_comma()

bool cexpr_t::contains_comma ( int  times = 1) const

Does the expression contain a comma operator?

Definition at line 6169 of file hexrays.hpp.

References cot_comma.

◆ contains_comma_or_insn_or_label()

bool cexpr_t::contains_comma_or_insn_or_label ( int  maxcommas = 1) const

Does the expression contain a comma operator or an embedded statement operator or a label?

Definition at line 6175 of file hexrays.hpp.

◆ contains_insn()

bool cexpr_t::contains_insn ( int  times = 1) const

Does the expression contain an embedded statement operator?

Definition at line 6171 of file hexrays.hpp.

References cot_insn.

◆ contains_insn_or_label()

bool cexpr_t::contains_insn_or_label ( void  ) const

Does the expression contain an embedded statement operator or a label?

Definition at line 6173 of file hexrays.hpp.

◆ contains_operator()

bool cexpr_t::contains_operator ( ctype_t  needed_op,
int  times = 1 
) const

Check if the expression contains the specified operator.

Parameters
needed_opoperator code to search for
timeshow many times the operator code should be present
Returns
true if the expression has at least TIMES children with NEEDED_OP

Definition at line 11531 of file hexrays.hpp.

◆ cpadone()

bool cexpr_t::cpadone ( void  ) const

Pointer arithmetic correction done for this expression?

Definition at line 6090 of file hexrays.hpp.

References EXFL_CPADONE.

◆ equal_effect()

bool cexpr_t::equal_effect ( const cexpr_t r) const

Compare two expressions.

This function tries to compare two expressions in an 'intelligent' manner. For example, it knows about commutitive operators and can ignore useless casts.

Parameters
rthe expression to compare against the current expression
Returns
true expressions can be considered equal

Definition at line 11519 of file hexrays.hpp.

◆ find_num_op() [1/2]

cexpr_t * cexpr_t::find_num_op ( void  )

Definition at line 6293 of file hexrays.hpp.

◆ find_num_op() [2/2]

const cexpr_t * cexpr_t::find_num_op ( void  ) const

Find the operand with a numeric value.

Definition at line 6292 of file hexrays.hpp.

References cot_num.

◆ find_op() [1/2]

cexpr_t * cexpr_t::find_op ( ctype_t  _op)

Definition at line 6286 of file hexrays.hpp.

◆ find_op() [2/2]

const cexpr_t * cexpr_t::find_op ( ctype_t  _op) const

Find the child with the specified operator.

Definition at line 6278 of file hexrays.hpp.

◆ find_ptr_or_array()

const cexpr_t * cexpr_t::find_ptr_or_array ( bool  remove_eqsize_casts) const

Find the pointer operand.

This function returns the pointer operand for binary expressions.

◆ get_1num_op() [1/2]

bool cexpr_t::get_1num_op ( cexpr_t **  o1,
cexpr_t **  o2 
)

Get pointers to operands.

at last one operand should be a number o1 will be pointer to the number

Definition at line 7175 of file hexrays.hpp.

References cot_num.

◆ get_1num_op() [2/2]

bool cexpr_t::get_1num_op ( const cexpr_t **  o1,
const cexpr_t **  o2 
) const

Definition at line 7192 of file hexrays.hpp.

◆ get_const_value()

bool cexpr_t::get_const_value ( uint64 *  out) const

Get expression value.

Parameters
outPointer to the variable where the expression value is returned.
Returns
true if the expression is a number.

Definition at line 6247 of file hexrays.hpp.

References cot_num.

◆ get_high_nbit_bound()

bit_bound_t cexpr_t::get_high_nbit_bound ( void  ) const

Get max number of bits that can really be used by the expression.

For example, x % 16 can yield only 4 non-zero bits, higher bits are zero

Definition at line 11537 of file hexrays.hpp.

◆ get_low_nbit_bound()

int cexpr_t::get_low_nbit_bound ( void  ) const

Get min number of bits that are certainly required to represent the expression.

For example, constant 16 always uses 5 bits: 10000.

Definition at line 11545 of file hexrays.hpp.

◆ get_ptr_or_array()

cexpr_t * cexpr_t::get_ptr_or_array ( void  )

Find pointer or array child.

Definition at line 6269 of file hexrays.hpp.

◆ get_type_sign()

type_sign_t cexpr_t::get_type_sign ( void  ) const

Get expression sign.

Definition at line 6189 of file hexrays.hpp.

◆ has_side_effects()

bool cexpr_t::has_side_effects ( void  ) const

Check if the expression has side effects.

Calls, pre/post inc/dec, and assignments have side effects.

Definition at line 11557 of file hexrays.hpp.

◆ is_aliasable()

bool cexpr_t::is_aliasable ( void  ) const

Check if the expression if aliasable.

Simple registers and non-aliasble stack slots return false.

◆ is_call_arg_of()

bool cexpr_t::is_call_arg_of ( const citem_t parent) const

Is call argument?

Returns
true if our expression is a call argument of the specified parent expression.

Definition at line 6187 of file hexrays.hpp.

References cot_call, and citem_t::op.

◆ is_call_object_of()

bool cexpr_t::is_call_object_of ( const citem_t parent) const

Is call object?

Returns
true if our expression is the call object of the specified parent expression.

Definition at line 6184 of file hexrays.hpp.

References cot_call, and citem_t::op.

◆ is_child_of()

bool cexpr_t::is_child_of ( const citem_t parent) const

Verify if the specified item is our parent.

Parameters
parentpossible parent item
Returns
true if the specified item is our parent

Definition at line 11525 of file hexrays.hpp.

◆ is_const_value()

bool cexpr_t::is_const_value ( uint64  _v) const

Check if the expression is a number with the specified value.

Definition at line 6221 of file hexrays.hpp.

References cot_num.

◆ is_cstr()

bool cexpr_t::is_cstr ( void  ) const

Definition at line 6093 of file hexrays.hpp.

◆ is_fpop()

bool cexpr_t::is_fpop ( void  ) const

Definition at line 6092 of file hexrays.hpp.

◆ is_jumpout()

bool cexpr_t::is_jumpout ( void  ) const

Definition at line 6096 of file hexrays.hpp.

◆ is_negative_const()

bool cexpr_t::is_negative_const ( void  ) const

Check if the expression is a negative number.

Definition at line 6226 of file hexrays.hpp.

References cot_num.

◆ is_nice_cond()

bool cexpr_t::is_nice_cond ( void  ) const

Is nice condition?.

Nice condition is a nice expression of the boolean type.

Definition at line 6181 of file hexrays.hpp.

◆ is_nice_expr()

bool cexpr_t::is_nice_expr ( void  ) const

Is nice expression? Nice expressions do not contain comma operators, embedded statements, or labels.

Definition at line 6178 of file hexrays.hpp.

◆ is_non_negative_const()

bool cexpr_t::is_non_negative_const ( void  ) const

Check if the expression is a non-negative number.

Definition at line 6231 of file hexrays.hpp.

References cot_num.

◆ is_non_zero_const()

bool cexpr_t::is_non_zero_const ( void  ) const

Check if the expression is a non-zero number.

Definition at line 6236 of file hexrays.hpp.

References cot_num.

◆ is_odd_lvalue()

bool cexpr_t::is_odd_lvalue ( void  ) const

Definition at line 6091 of file hexrays.hpp.

◆ is_type_partial()

bool cexpr_t::is_type_partial ( void  ) const

Definition at line 6094 of file hexrays.hpp.

◆ is_type_signed()

bool cexpr_t::is_type_signed ( void  ) const

Is expression signed?

Definition at line 6193 of file hexrays.hpp.

◆ is_type_unsigned()

bool cexpr_t::is_type_unsigned ( void  ) const

Is expression unsigned?

Definition at line 6191 of file hexrays.hpp.

◆ is_undef_val()

bool cexpr_t::is_undef_val ( void  ) const

Definition at line 6095 of file hexrays.hpp.

◆ is_vftable()

bool cexpr_t::is_vftable ( void  ) const

Definition at line 6097 of file hexrays.hpp.

◆ is_zero_const()

bool cexpr_t::is_zero_const ( void  ) const

Check if the expression is a zero.

Examples
hexrays_sample2.cpp.

Definition at line 6241 of file hexrays.hpp.

◆ maybe_ptr()

bool cexpr_t::maybe_ptr ( void  ) const

May the expression be a pointer?

Definition at line 6258 of file hexrays.hpp.

◆ numval()

uint64 cexpr_t::numval ( void  ) const

Get numeric value of the expression.

This function can be called only on cot_num expressions!

Definition at line 6215 of file hexrays.hpp.

References cot_num.

◆ operator=()

cexpr_t & cexpr_t::operator= ( const cexpr_t r)

Definition at line 6117 of file hexrays.hpp.

◆ print1()

void cexpr_t::print1 ( qstring *  vout,
const cfunc_t func 
) const

Print expression into one line.

Parameters
voutoutput buffer
funcparent function. This argument is used to find out the referenced variable names.
Examples
hexrays_sample5.cpp.

Definition at line 11507 of file hexrays.hpp.

◆ put_number()

void cexpr_t::put_number ( cfunc_t func,
uint64  value,
int  nbytes,
type_sign_t  sign = no_sign 
)

Assign a number to the expression.

Parameters
funccurrent function
valuenumber value
nbytessize of the number in bytes
signnumber sign

Definition at line 11501 of file hexrays.hpp.

◆ replace_by()

void cexpr_t::replace_by ( cexpr_t r)

Replace the expression.

The children of the expression are abandoned (not freed). The expression pointed by 'r' is moved to 'this' expression

Parameters
rthe source expression. It is deleted after being copied

Definition at line 11489 of file hexrays.hpp.

◆ requires_lvalue()

bool cexpr_t::requires_lvalue ( const cexpr_t child) const

Check if the expression requires an lvalue.

Parameters
childThe function will check if this child of our expression must be an lvalue.
Returns
true if child must be an lvalue.

Definition at line 11551 of file hexrays.hpp.

◆ set_cpadone()

void cexpr_t::set_cpadone ( void  )

Definition at line 6100 of file hexrays.hpp.

◆ set_type_partial()

void cexpr_t::set_type_partial ( bool  val = true)

Definition at line 6102 of file hexrays.hpp.

◆ set_vftable()

void cexpr_t::set_vftable ( void  )

Definition at line 6101 of file hexrays.hpp.

◆ swap()

void cexpr_t::swap ( cexpr_t r)
Examples
hexrays_sample3.cpp.

Definition at line 6116 of file hexrays.hpp.

◆ theother() [1/2]

cexpr_t * cexpr_t::theother ( const cexpr_t what)

Definition at line 6301 of file hexrays.hpp.

◆ theother() [2/2]

const cexpr_t * cexpr_t::theother ( const cexpr_t what) const

Get the other operand.

This function returns the other operand (not the specified one) for binary expressions.

Definition at line 6300 of file hexrays.hpp.

Member Data Documentation

◆ a

carglist_t* cexpr_t::a

argument list (used for cot_call)

Examples
hexrays_sample2.cpp.

Definition at line 6058 of file hexrays.hpp.

◆ exflags

uint32 cexpr_t::exflags

Expression attributes

Definition at line 6074 of file hexrays.hpp.

◆ fpc

fnumber_t* cexpr_t::fpc

used for cot_fnum

Definition at line 6042 of file hexrays.hpp.

◆ helper

char* cexpr_t::helper

helper name (used for cot_helper)

Definition at line 6070 of file hexrays.hpp.

◆ insn

cinsn_t* cexpr_t::insn

an embedded statement, they are prohibited at the final maturity stage (CMAT_FINAL)

Definition at line 6068 of file hexrays.hpp.

◆ m

uint32 cexpr_t::m

member offset (used for cot_memptr, cot_memref) for unions, the member number

Examples
hexrays_sample17.cpp, and hexrays_sample5.cpp.

Definition at line 6059 of file hexrays.hpp.

◆ n

cnumber_t* cexpr_t::n

used for cot_num

Examples
hexrays_sample2.cpp.

Definition at line 6041 of file hexrays.hpp.

◆ obj_ea

ea_t cexpr_t::obj_ea

used for cot_obj

Definition at line 6048 of file hexrays.hpp.

◆ ptrsize

int cexpr_t::ptrsize

memory access size (used for cot_ptr, cot_memptr)

Examples
hexrays_sample5.cpp.

Definition at line 6065 of file hexrays.hpp.

◆ refwidth

int cexpr_t::refwidth

how many bytes are accessed? (-1: none)

Examples
hexrays_sample5.cpp.

Definition at line 6050 of file hexrays.hpp.

◆ string

char* cexpr_t::string

utf8 string constant, user representation (used for cot_str)

Definition at line 6071 of file hexrays.hpp.

◆ type

tinfo_t cexpr_t::type

expression type. must be carefully maintained

Examples
hexrays_sample17.cpp, hexrays_sample2.cpp, and hexrays_sample5.cpp.

Definition at line 6073 of file hexrays.hpp.

◆ v

var_ref_t cexpr_t::v

used for cot_var

Definition at line 6047 of file hexrays.hpp.

◆ x

cexpr_t* cexpr_t::x

the first operand of the expression

Examples
hexrays_sample17.cpp, hexrays_sample2.cpp, and hexrays_sample5.cpp.

Definition at line 6054 of file hexrays.hpp.

◆ y

cexpr_t* cexpr_t::y

the second operand of the expression

Examples
hexrays_sample2.cpp, and hexrays_sample5.cpp.

Definition at line 6057 of file hexrays.hpp.

◆ z

cexpr_t* cexpr_t::z

the third operand of the expression

Examples
hexrays_sample5.cpp.

Definition at line 6064 of file hexrays.hpp.