class procedure_callers_iterator

Iterator over the call sites ( point of kind point_kind.CALL_SITE) whose target is a particular procedure.

Initialize with procedure.callers().

Use as you would any other Python iterator. For example:

# set up procedure proc, then...
for e in proc.callers():
    print('point: ', e)

procedure_callers_iterator Details

class cs.procedure_callers_iterator

Iterator over the call sites ( point of kind point_kind.CALL_SITE) whose target is a particular procedure.

__eq__(other)

Iterator equality.

Parameters:other (procedure_callers_iterator) –
Return type:bool
Returns:True if and only if self and other are at the same position. Behavior is undefined if self and other are not iterating over the same collection.
>>> cu = next(c for c in project.current().compunits() if c.name().endswith('apitest.cpp'))
>>> proc = next(p for p in cu.procedures() if p.name()=='bar')
>>> c_iterA = proc.callers()
>>> c_iterB = proc.callers()
>>> c_iterA == c_iterB
True
>>> for p in c_iterA:
...     if p.get_procedure().name() == 'bar':
...         break
...
>>> c_iterA == c_iterB
False
__iter__()

Get the iterator object.

Return type:procedure_callers_iterator
Returns:self.
>>> cu = next(c for c in project.current().compunits() if c.name().endswith('apitest.cpp'))
>>> proc = next(p for p in cu.procedures() if p.name()=='bar')
>>> for p in proc.callers(): # iteration is managed by procedure_callers_iterator.__iter__()
...                          # and  procedure_callers_iterator.__next__()
...     print(p.get_procedure())
...
foo
foo
foo
bar
__ne__(other)

Iterator inequality.

Parameters:other (procedure_callers_iterator) – The iterator to compare against.
Return type:bool
Returns:False if and only if self and other are at the same position. Behavior is undefined if self and other are not iterating over the same collection.
>>> cu = next(c for c in project.current().compunits() if c.name().endswith('apitest.cpp'))
>>> proc = next(p for p in cu.procedures() if p.name()=='bar')
>>> c_iterA = proc.callers()
>>> c_iterB = proc.callers()
>>> c_iterA != c_iterB
False
>>> for p in c_iterA:
...     if p.get_procedure().name() == 'bar':
...         break
...
>>> c_iterA != c_iterB
True
__next__()

Iterator dereference operator.

Return type:point
Returns:The element at the current iterator position.
Raises:StopIteration
  • Side effects: Modifies self.

The typical use is implicit:

>>> for item in myiter:
...   (do something to item)
>>> cu = next(c for c in project.current().compunits() if c.name().endswith('apitest.cpp'))
>>> proc = next(p for p in cu.procedures() if p.name()=='bar')
>>> for p in proc.callers(): # iteration is managed by procedure_callers_iterator.__iter__()
...                          # and  procedure_callers_iterator.__next__()
...     print(p.get_procedure())
...
foo
foo
foo
bar
__repr__()

Get a representation of the iterator that includes information useful for debugging.

Return type:str
Returns:The string representation.
>>> proc = next(p for p in cu.procedures() if p.name()=='foo')
>>> callers = proc.callers()
>>> repr(callers)
__str__()

Get a simple string representation of the iterator.

Return type:str
Returns:The string representation.
>>> proc = next(p for p in cu.procedures() if p.name()=='foo')
>>> callers = proc.callers()
>>> str(callers)
'<cs.procedure_callers_iterator begin>'
at_end()

Check: is the iterator at the end of the structure?

Return type:bool
Returns:True if the iterator is at the end of the structure (there are no more elements to iterate over), False otherwise.
>>> proc = next(p for p in cu.procedures() if p.name()=='foo')
>>> callers = proc.callers()
>>> callers.at_end()
True