[cfe-commits] r171423 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_cursor.py

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Jan 2 14:31:58 PST 2013


Author: akirtzidis
Date: Wed Jan  2 16:31:57 2013
New Revision: 171423

URL: http://llvm.org/viewvc/llvm-project?rev=171423&view=rev
Log:
[python bindings] Expose cursor.referenced (clang_getCursorReferenced).

Patch by Matthew King!

Modified:
    cfe/trunk/bindings/python/clang/cindex.py
    cfe/trunk/bindings/python/tests/cindex/test_cursor.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=171423&r1=171422&r2=171423&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Wed Jan  2 16:31:57 2013
@@ -1271,6 +1271,17 @@
         # 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)

Modified: cfe/trunk/bindings/python/tests/cindex/test_cursor.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cursor.py?rev=171423&r1=171422&r2=171423&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_cursor.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cursor.py Wed Jan  2 16:31:57 2013
@@ -250,3 +250,12 @@
     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





More information about the cfe-commits mailing list