Latest available version: IDA and decompilers v8.4.240215 see all releases
Hex-Rays logo State-of-the-art binary code analysis tools
email icon
ctree_visitor_t Struct Reference

A generic helper class that is used for ctree traversal. More...

#include <hexrays.hpp>

Inheritance diagram for ctree_visitor_t:
ctree_parentee_t cfunc_parentee_t

Public Member Functions

bool maintain_parents () const
 Should the parent information by maintained? More...
 
bool must_prune () const
 Should the traversal skip the children of the current item? More...
 
bool must_restart () const
 Should the traversal restart? More...
 
bool is_postorder () const
 Should the leave...() functions be called? More...
 
bool only_insns () const
 Should all expressions be automatically pruned? More...
 
void prune_now ()
 Prune children. More...
 
void clr_prune ()
 Do not prune children. This is an internal function, no need to call it. More...
 
void set_restart ()
 Restart the travesal. Meaningful only in apply_to_exprs() More...
 
void clr_restart ()
 Do not restart. This is an internal function, no need to call it. More...
 
 ctree_visitor_t (int _flags)
 Constructor. More...
 
int apply_to (citem_t *item, citem_t *parent)
 Traverse ctree. More...
 
int apply_to_exprs (citem_t *item, citem_t *parent)
 Traverse only expressions. More...
 
cexpr_tparent_expr ()
 Get parent of the current item as an expression. More...
 
cinsn_tparent_insn ()
 Get parent of the current item as a statement. More...
 
virtual int visit_insn (cinsn_t *)
 Visit a statement. More...
 
virtual int visit_expr (cexpr_t *)
 Visit an expression. More...
 
virtual int leave_insn (cinsn_t *)
 Visit a statement after having visited its children. More...
 
virtual int leave_expr (cexpr_t *)
 Visit an expression after having visited its children. More...
 

Public Attributes

int cv_flags
 Ctree visitor property bits More...
 
parents_t parents
 Vector of parents of the current item. More...
 

Detailed Description

A generic helper class that is used for ctree traversal.

When traversing the ctree, the currently visited ctree item and its children can be freely modified without interrupting the traversal. However, if a parent of the visited item is modified, the traversal must be immediately stopped by returning a non-zero value.

Examples
hexrays_sample2.cpp, hexrays_sample3.cpp, and hexrays_sample7.cpp.

Definition at line 5789 of file hexrays.hpp.

Constructor & Destructor Documentation

◆ ctree_visitor_t()

ctree_visitor_t::ctree_visitor_t ( int  _flags)

Constructor.

This constructor can be used with CV_FAST, CV_PARENTS combined with CV_POST, CV_ONLYINS

Definition at line 5831 of file hexrays.hpp.

◆ ~ctree_visitor_t()

virtual ctree_visitor_t::~ctree_visitor_t ( )
virtual

Definition at line 5833 of file hexrays.hpp.

Member Function Documentation

◆ apply_to()

int ctree_visitor_t::apply_to ( citem_t item,
citem_t parent 
)

Traverse ctree.

The traversal will start at the specified item and continue until of one the visit_...() functions return a non-zero value.

Parameters
itemroot of the ctree to traverse
parentparent of the specified item. can be specified as nullptr.
Returns
0 or a non-zero value returned by a visit_...() function

Definition at line 11641 of file hexrays.hpp.

◆ apply_to_exprs()

int ctree_visitor_t::apply_to_exprs ( citem_t item,
citem_t parent 
)

Traverse only expressions.

The traversal will start at the specified item and continue until of one the visit_...() functions return a non-zero value.

Parameters
itemroot of the ctree to traverse
parentparent of the specified item. can be specified as nullptr.
Returns
0 or a non-zero value returned by a visit_...() function

Definition at line 11647 of file hexrays.hpp.

◆ clr_prune()

void ctree_visitor_t::clr_prune ( )

Do not prune children. This is an internal function, no need to call it.

Definition at line 5820 of file hexrays.hpp.

◆ clr_restart()

void ctree_visitor_t::clr_restart ( )

Do not restart. This is an internal function, no need to call it.

Definition at line 5824 of file hexrays.hpp.

◆ is_postorder()

bool ctree_visitor_t::is_postorder ( ) const

Should the leave...() functions be called?

Definition at line 5813 of file hexrays.hpp.

References CV_POST.

◆ leave_expr()

virtual int ctree_visitor_t::leave_expr ( cexpr_t )
virtual

Visit an expression after having visited its children.

This is a visitor function which should be overridden by a derived class to do some useful work. This visitor performs post-order traserval, i.e. an item is visited after its children.

Returns
0 to continue the traversal, nonzero to stop.

Definition at line 5888 of file hexrays.hpp.

◆ leave_insn()

virtual int ctree_visitor_t::leave_insn ( cinsn_t )
virtual

Visit a statement after having visited its children.

This is a visitor function which should be overridden by a derived class to do some useful work. This visitor performs post-order traserval, i.e. an item is visited after its children.

Returns
0 to continue the traversal, nonzero to stop.

Definition at line 5880 of file hexrays.hpp.

◆ maintain_parents()

bool ctree_visitor_t::maintain_parents ( ) const

Should the parent information by maintained?

Definition at line 5807 of file hexrays.hpp.

References CV_PARENTS.

◆ must_prune()

bool ctree_visitor_t::must_prune ( ) const

Should the traversal skip the children of the current item?

Definition at line 5809 of file hexrays.hpp.

References CV_PRUNE.

◆ must_restart()

bool ctree_visitor_t::must_restart ( ) const

Should the traversal restart?

Definition at line 5811 of file hexrays.hpp.

References CV_RESTART.

◆ only_insns()

bool ctree_visitor_t::only_insns ( ) const

Should all expressions be automatically pruned?

Definition at line 5815 of file hexrays.hpp.

References CV_INSNS.

◆ parent_expr()

cexpr_t * ctree_visitor_t::parent_expr ( )

Get parent of the current item as an expression.

Definition at line 5851 of file hexrays.hpp.

◆ parent_insn()

cinsn_t * ctree_visitor_t::parent_insn ( )

Get parent of the current item as a statement.

Definition at line 5853 of file hexrays.hpp.

◆ prune_now()

void ctree_visitor_t::prune_now ( )

Prune children.

This function may be called by a visitor() to skip all children of the current item.

Definition at line 5818 of file hexrays.hpp.

References CV_PRUNE.

◆ set_restart()

void ctree_visitor_t::set_restart ( )

Restart the travesal. Meaningful only in apply_to_exprs()

Definition at line 5822 of file hexrays.hpp.

References CV_RESTART.

◆ visit_expr()

virtual int ctree_visitor_t::visit_expr ( cexpr_t )
virtual

Visit an expression.

This is a visitor function which should be overridden by a derived class to do some useful work. This visitor performs pre-order traserval, i.e. an item is visited before its children.

Returns
0 to continue the traversal, nonzero to stop.
Examples
hexrays_sample2.cpp, and hexrays_sample5.cpp.

Definition at line 5872 of file hexrays.hpp.

◆ visit_insn()

virtual int ctree_visitor_t::visit_insn ( cinsn_t )
virtual

Visit a statement.

This is a visitor function which should be overridden by a derived class to do some useful work. This visitor performs pre-order traserval, i.e. an item is visited before its children.

Returns
0 to continue the traversal, nonzero to stop.
Examples
hexrays_sample3.cpp, hexrays_sample5.cpp, and hexrays_sample7.cpp.

Definition at line 5864 of file hexrays.hpp.

Member Data Documentation

◆ cv_flags

int ctree_visitor_t::cv_flags

Ctree visitor property bits

Definition at line 5791 of file hexrays.hpp.

◆ parents

parents_t ctree_visitor_t::parents

Vector of parents of the current item.

Definition at line 5826 of file hexrays.hpp.

Referenced by ctree_parentee_t::get_block().