class symbol_set_iterator

Iterator over the symbol elements of a symbol_set .

Use a symbol_set_iterator to iterate over a symbol_set . For example:

for e in my_symbol_set:
    print('symbol: ', e)

symbol_set_iterator Details

class cs.symbol_set_iterator

Iterator over the symbol elements of a symbol_set .

__eq__(other)

Iterator equality.

Parameters:other (symbol_set_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')
>>> pt = next(p for p in proc.points()
...           if p.get_kind()==point_kind.EXPRESSION
...           and p.get_ast()[1].get_class()==ast_class.NC_POINTEREXPR)
>>> print(pt)
[expression] *p = x
>>> pt_used = symbol_set(pt.csonar_enum_used())
>>> symset_iterA = iter(pt_used)
>>> symset_iterB = iter(pt_used)
>>> symset_iterA == symset_iterB
True
>>> for sym in symset_iterA:
...     if sym.name() =='x':
...         break
...
>>> symset_iterA == symset_iterB
False
__iter__()

Get the iterator object.

Return type:symbol_set_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')
>>> pt = next(p for p in proc.points()
...             if p.get_kind()==point_kind.EXPRESSION
...             and p.get_ast()[1].get_class()==ast_class.NC_POINTEREXPR)
>>> print(pt)
[expression] *p = x
>>> pt_used = symbol_set(pt.csonar_enum_used())
>>> for sym in iter(pt_used):            # iteration managed by symbol_set_iterator.__iter__()
...                                      # and symbol_set_iterator.__next__()
...    print(sym.file_line(), sym.name())
...
(<cs.sfileinst C:\alex\test\apitest.cpp>, 14) x
(<cs.sfileinst C:\alex\test\apitest.cpp>, 15) p
__ne__(other)

Iterator inequality.

Parameters:other (symbol_set_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')
>>> pt = next(p for p in proc.points()
...           if p.get_kind()==point_kind.EXPRESSION
...           and p.get_ast()[1].get_class()==ast_class.NC_POINTEREXPR)
>>> print(pt)
[expression] *p = x
>>> pt_used = symbol_set(pt.csonar_enum_used())
>>> symset_iterA = iter(pt_used)
>>> symset_iterB = iter(pt_used)
>>> symset_iterA != symset_iterB
False
>>> for sym in symset_iterA:
...     if sym.name() =='x':
...         break
...
>>> symset_iterA != symset_iterB
True
__next__()

Iterator dereference operator.

Return type:symbol
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')
>>> pt = next(p for p in proc.points()
...             if p.get_kind()==point_kind.EXPRESSION
...             and p.get_ast()[1].get_class()==ast_class.NC_POINTEREXPR)
>>> print(pt)
[expression] *p = x
>>> pt_used = symbol_set(pt.csonar_enum_used())
>>> for sym in iter(pt_used):            # iteration managed by symbol_set_iterator.__iter__()
...                                      # and symbol_set_iterator.__next__()
...    print(sym.file_line(), sym.name())
...
(<cs.sfileinst C:\alex\test\apitest.cpp>, 14) x
(<cs.sfileinst C:\alex\test\apitest.cpp>, 15) p
__repr__()

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

Return type:str
Returns:The string representation.
>>> v0 = symbol_set()
>>> v1 = iter(v0)
>>> repr(v1)
'<cs.symbol_set_iterator begin>'
__str__()

Get a simple string representation of the iterator.

Return type:str
Returns:The string representation.
>>> v0 = symbol_set()
>>> v1 = iter(v0)
>>> str(v1)
'<cs.symbol_set_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.
>>> v0 = symbol_set()
>>> v1 = iter(v0)
>>> v1.at_end()
True