[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-commits
Subject:    [cfe-commits] [PATCH] Add clang_getCursorReferenced to Python binding
From:       Matthew King <matthew.y.king () gmail ! com>
Date:       2012-12-30 22:09:30
Message-ID: CAMSN=51CZykQtNWMtqxHrWRF_jfA+o72cUDtxhHFJgYz_nEDWg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Exposes cursor.referenced (clang_getCursorReferenced). I was trying to find
the function declaration corresponding to a function call, and I believe
this is the most direct way.

Unit test included.

Matt

[Attachment #5 (text/html)]

<div dir="ltr">Exposes cursor.referenced (clang_getCursorReferenced). I was trying to \
find the function declaration corresponding to a function call, and I believe this is \
the most direct way. <div><div><br></div><div style> Unit test \
included.</div><div><br></div><div style>Matt</div></div></div>

--e89a8f839dfb998b2904d21926b6--


["referenced.patch" (application/octet-stream)]

Index: bindings/python/clang/cindex.py
===================================================================
--- bindings/python/clang/cindex.py	(revision 171262)
+++ bindings/python/clang/cindex.py	(working copy)
@@ -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)
Index: bindings/python/tests/cindex/test_cursor.py
===================================================================
--- bindings/python/tests/cindex/test_cursor.py	(revision 171262)
+++ bindings/python/tests/cindex/test_cursor.py	(working copy)
@@ -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


_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic