forked from OSchip/llvm-project
[python bindings] Expose cursor.referenced (clang_getCursorReferenced).
Patch by Matthew King! llvm-svn: 171423
This commit is contained in:
parent
1654035a3b
commit
eedb5432c5
|
@ -1271,6 +1271,17 @@ class Cursor(Structure):
|
|||
# created.
|
||||
return self._tu
|
||||
|
||||
@property
|
||||
def referenced(self):
|
||||
"""
|
||||
For a cursor that is a reference, returns a cursor
|
||||
representing the entity that it references.
|
||||
"""
|
||||
if not hasattr(self, '_referenced'):
|
||||
self._referenced = conf.lib.clang_getCursorReferenced(self)
|
||||
|
||||
return self._referenced
|
||||
|
||||
def get_arguments(self):
|
||||
"""Return an iterator for accessing the arguments of this cursor."""
|
||||
num_args = conf.lib.clang_Cursor_getNumArguments(self)
|
||||
|
|
|
@ -250,3 +250,12 @@ def test_get_arguments():
|
|||
assert len(arguments) == 2
|
||||
assert arguments[0].spelling == "i"
|
||||
assert arguments[1].spelling == "j"
|
||||
|
||||
def test_referenced():
|
||||
tu = get_tu('void foo(); void bar() { foo(); }')
|
||||
foo = get_cursor(tu, 'foo')
|
||||
bar = get_cursor(tu, 'bar')
|
||||
for c in bar.get_children():
|
||||
if c.kind == CursorKind.CALL_EXPR:
|
||||
assert c.referenced.spelling == foo.spelling
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue