Skip to content

Commit d829379

Browse files
committed
[python bindings] Expose cursor.referenced (clang_getCursorReferenced).
Patch by Matthew King! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171423 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f5e208c commit d829379

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

bindings/python/clang/cindex.py

+11
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,17 @@ def translation_unit(self):
12711271
# created.
12721272
return self._tu
12731273

1274+
@property
1275+
def referenced(self):
1276+
"""
1277+
For a cursor that is a reference, returns a cursor
1278+
representing the entity that it references.
1279+
"""
1280+
if not hasattr(self, '_referenced'):
1281+
self._referenced = conf.lib.clang_getCursorReferenced(self)
1282+
1283+
return self._referenced
1284+
12741285
def get_arguments(self):
12751286
"""Return an iterator for accessing the arguments of this cursor."""
12761287
num_args = conf.lib.clang_Cursor_getNumArguments(self)

bindings/python/tests/cindex/test_cursor.py

+9
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,12 @@ def test_get_arguments():
250250
assert len(arguments) == 2
251251
assert arguments[0].spelling == "i"
252252
assert arguments[1].spelling == "j"
253+
254+
def test_referenced():
255+
tu = get_tu('void foo(); void bar() { foo(); }')
256+
foo = get_cursor(tu, 'foo')
257+
bar = get_cursor(tu, 'bar')
258+
for c in bar.get_children():
259+
if c.kind == CursorKind.CALL_EXPR:
260+
assert c.referenced.spelling == foo.spelling
261+
break

0 commit comments

Comments
 (0)