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 (void) const
 Should the parent information by maintained? More...
 
bool must_prune (void) const
 Should the traversal skip the children of the current item? More...
 
bool must_restart (void) const
 Should the traversal restart? More...
 
bool is_postorder (void) const
 Should the leave...() functions be called? More...
 
bool only_insns (void) const
 Should all expressions be automatically pruned? More...
 
void prune_now (void)
 Prune children. More...
 
void clr_prune (void)
 Do not prune children. This is an internal function, no need to call it. More...
 
void set_restart (void)
 Restart the travesal. Meaningful only in apply_to_exprs() More...
 
void clr_restart (void)
 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 (void)
 Get parent of the current item as an expression. More...
 
cinsn_tparent_insn (void)
 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 5712 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 5754 of file hexrays.hpp.

◆ ~ctree_visitor_t()

virtual ctree_visitor_t::~ctree_visitor_t ( )
virtual

Definition at line 5756 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 11423 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 11429 of file hexrays.hpp.

◆ clr_prune()

void ctree_visitor_t::clr_prune ( void  )

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

Definition at line 5743 of file hexrays.hpp.

◆ clr_restart()

void ctree_visitor_t::clr_restart ( void  )

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

Definition at line 5747 of file hexrays.hpp.

◆ is_postorder()

bool ctree_visitor_t::is_postorder ( void  ) const

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

Definition at line 5736 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 5811 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 5803 of file hexrays.hpp.

◆ maintain_parents()

bool ctree_visitor_t::maintain_parents ( void  ) const

Should the parent information by maintained?

Definition at line 5730 of file hexrays.hpp.

References CV_PARENTS.

◆ must_prune()

bool ctree_visitor_t::must_prune ( void  ) const

Should the traversal skip the children of the current item?

Definition at line 5732 of file hexrays.hpp.

References CV_PRUNE.

◆ must_restart()

bool ctree_visitor_t::must_restart ( void  ) const

Should the traversal restart?

Definition at line 5734 of file hexrays.hpp.

References CV_RESTART.

◆ only_insns()

bool ctree_visitor_t::only_insns ( void  ) const

Should all expressions be automatically pruned?

Definition at line 5738 of file hexrays.hpp.

References CV_INSNS.

◆ parent_expr()

cexpr_t * ctree_visitor_t::parent_expr ( void  )

Get parent of the current item as an expression.

Definition at line 5774 of file hexrays.hpp.

◆ parent_insn()

cinsn_t * ctree_visitor_t::parent_insn ( void  )

Get parent of the current item as a statement.

Definition at line 5776 of file hexrays.hpp.

◆ prune_now()

void ctree_visitor_t::prune_now ( void  )

Prune children.

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

Definition at line 5741 of file hexrays.hpp.

References CV_PRUNE.

◆ set_restart()

void ctree_visitor_t::set_restart ( void  )

Restart the travesal. Meaningful only in apply_to_exprs()

Definition at line 5745 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 5795 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 5787 of file hexrays.hpp.

Member Data Documentation

◆ cv_flags

int ctree_visitor_t::cv_flags

Ctree visitor property bits

Definition at line 5714 of file hexrays.hpp.

◆ parents

parents_t ctree_visitor_t::parents

Vector of parents of the current item.

Definition at line 5749 of file hexrays.hpp.

Referenced by ctree_parentee_t::get_block().