class xr_tuple

Describes an occurrence of a token in a particular kind-role and the definition corresponding to that occurrence.

This is the element type of the xr_query_iterator returned by project.token_search().

xr_tuple Details

class cs.xr_tuple

Describes an occurrence of a token in a particular kind-role and the definition corresponding to that occurrence.

__init__(_namehash, _kr, _complete, _file, _line, _def_file, _def_line)

Constructor.

Parameters:
  • _namehash (int) – The token name hash, as produced by xr_tuple.get_namehash(). If you are extracting a procedure name to hash, use procedure.basename().
  • _kr (xr_kind_role) – The token kind and role described by the xr_tuple .
  • _complete (bool) – True iff the token definition is complete. Some definitions, such as extern, are incomplete.
  • _file (sfile) – The source file containing the token occurrence.
  • _line (int) – The location in _file of the token occurrence.
  • _def_file (sfile) – The source file containing the token definition. There may be multiple corresponding definitions, in which case there will be a separate xr_tuple for each definition.
  • _def_line (int) – The location in _def_file of the token definition.
Raises:

OverflowError

>>> sf = next(s for s in project.current().sfiles()
...           if s.name().endswith('apitest.cpp'))
>>> xr_tuple(xr_namehash('bar'),
...          xr_kind_role.FUNC_CALL,
...          True,
...          sf,
...          14,
...          sf,
...          9)
<cs.xr_tuple 4e58b850a6c2ceb8, func_call, <cs.sfile C:\alex\test\apitest.cpp>:14, <cs.sfile C:\alex\test\apitest.cpp>:9>
__cmp__(other)

Comparison function for xr_tuple , with respect to a stable overall ordering.

Parameters:other (xr_tuple) – The xr_tuple object to compare against.
Return type:int
Returns:An integer N such that:
  • N==0 if the two objects compare equal
  • N<0 if self < other
  • N>0 if self > other
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok2 = next(it)
>>> tok2
<cs.xr_tuple 4e58b850a6c2ceb8, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:9, <cs.sfile C:\alex\test\apitest.cpp>:9>
>>> tok1.__cmp__(tok2)
-1
__eq__(b)

Equality operator for xr_tuple .

Parameters:b (xr_tuple) – The xr_tuple to compare against.
Return type:bool
Returns:True if self and b compare equal, False otherwise.
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok2 = next(it)
>>> tok2
<cs.xr_tuple 4e58b850a6c2ceb8, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:9, <cs.sfile C:\alex\test\apitest.cpp>:9>
>>> tok1 == tok2
False
__ge__(b)

Greater-than-or-equal operator for xr_tuple .

Parameters:b (xr_tuple) – The xr_tuple to compare against.
Return type:bool
Returns:True if self >= b , False otherwise.
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok2 = next(it)
>>> tok2
<cs.xr_tuple 4e58b850a6c2ceb8, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:9, <cs.sfile C:\alex\test\apitest.cpp>:9>
>>> tok1 >= tok2
False
__gt__(b)

Greater-than operator for xr_tuple .

Parameters:b (xr_tuple) – The xr_tuple to compare against.
Return type:bool
Returns:True if self > b , False otherwise.
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok2 = next(it)
>>> tok2
<cs.xr_tuple 4e58b850a6c2ceb8, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:9, <cs.sfile C:\alex\test\apitest.cpp>:9>
>>> tok1 > tok2
False
__hash__()

Hash function for xr_tuple .

Return type:int
Returns:The hash value.
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> hash(tok1)
1732278155
__le__(b)

Less-than-or-equal operator for xr_tuple .

Parameters:b (xr_tuple) – The xr_tuple to compare against.
Return type:bool
Returns:True if self <= b , False otherwise.
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok2 = next(it)
>>> tok2
<cs.xr_tuple 4e58b850a6c2ceb8, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:9, <cs.sfile C:\alex\test\apitest.cpp>:9>
>>> tok1 <= tok2
True
__lt__(b)

Less-than operator for xr_tuple .

Parameters:b (xr_tuple) – The xr_tuple to compare against.
Return type:bool
Returns:True if self < b , False otherwise.
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok2 = next(it)
>>> tok2
<cs.xr_tuple 4e58b850a6c2ceb8, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:9, <cs.sfile C:\alex\test\apitest.cpp>:9>
>>> tok1 < tok2
True
__ne__(b)

Inequality operator for xr_tuple .

Parameters:b (xr_tuple) – The xr_tuple to compare against.
Return type:bool
Returns:False if self and b compare equal, True otherwise.
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok2 = next(it)
>>> tok2
<cs.xr_tuple 4e58b850a6c2ceb8, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:9, <cs.sfile C:\alex\test\apitest.cpp>:9>
>>> tok1 != tok2
True
__repr__()

Get a representation of a xr_tuple object that includes information useful for debugging.

Return type:str
Returns:The string representation.
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> repr(tok1)
'<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\\alex\\test\\apitest.cpp>:3, <cs.sfile C:\\alex\test\\apitest.cpp>:3>'
__str__()

Get a simple string representation of a xr_tuple object.

Return type:str
Returns:The string representation.
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> str(tok1)
'<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\\alex\\test\\apitest.cpp>:3, <cs.sfile C:\\alex\\test\\apitest.cpp>:3>'
get_complete()

Check: is the definition complete?

Return type:bool
Returns:true if the definition is complete, false if it’s incomplete (for example, because it is an extern definition).
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok1.get_complete()
True
get_def_file()

Get the source file containing the token’s definition.

Return type:sfile
Returns:The source file ( sfile ).

If there are multiple corresponding definitions, there will be a separate xr_tuple object for each definition.

>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok1.get_def_file()
<cs.sfile C:\alex\test\apitest.cpp>
get_def_line()

Get the source file line containing the token definition.

Return type:int
Returns:The source file line (int).
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok1.get_def_line()
3
get_file()

Get the source file containing the token occurrence.

Return type:sfile
Returns:The source file ( sfile ).
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok1.get_file()
<cs.sfile C:\alex\test\apitest.cpp>
>>> tok1.get_line()
3
get_kind_role()

Get the token’s kind-role.

Return type:xr_kind_role
Returns:The token’s kind-role ( xr_kind_role ).
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok1.get_kind_role()
<cs.xr_kind_role func_definition>
get_line()

Get the source file line containing the token occurrence.

Return type:int
Returns:The source file line (int).
>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok1.get_line()
3
get_name()

Get the source token corresponding to an xr_tuple .

Return type:

str

Returns:

The source token, as a string.

Raises:

A procedure name token is the procedure basename as returned by procedure.basename().

>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok1.get_name()
'mymalloc'
get_namehash()

Get a hash of the token name.

Return type:int
Returns:A hash of the token name.

A procedure name token is the procedure basename as returned by procedure.basename().

>>> it = project.current().token_search(xr_query())
>>> tok1 = next(it)
>>> tok1
<cs.xr_tuple 357fe5812e183f28, func_definition, <cs.sfile C:\alex\test\apitest.cpp>:3, <cs.sfile C:\alex\test\apitest.cpp>:3>
>>> tok1.get_namehash()
3855052149039316776