]> granicus.if.org Git - clang/commitdiff
[python bindings] Expose cursor.referenced (clang_getCursorReferenced).
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 2 Jan 2013 22:31:57 +0000 (22:31 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 2 Jan 2013 22:31:57 +0000 (22:31 +0000)
Patch by Matthew King!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171423 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/python/clang/cindex.py
bindings/python/tests/cindex/test_cursor.py

index adbf511e685e8165e8c2a80ecae3dd9413a02d74..581f5e6fef8bfb3657b33148e76b755858d0914a 100644 (file)
@@ -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)
index edb209b52b96d40a87fbe4461e32662b2ea633ae..a27525cfe553f501202b7312c00332e84e58a3e9 100644 (file)
@@ -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