[cfe-commits] [PATCH] Expose clang_Cursor_getArgument via Python-bindings

Matthias Kleine matthias_kleine at gmx.de
Tue Oct 16 10:19:09 PDT 2012


http://llvm-reviews.chandlerc.com/D64

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

Index: bindings/python/clang/cindex.py
===================================================================
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1271,6 +1271,12 @@
         # created.
         return self._tu
 
+    def get_arguments(self):
+        """Return an iterator for accessing the arguments of this cursor."""
+        num_args = conf.lib.clang_Cursor_getNumArguments(self)
+        for i in range(0, num_args):
+            yield conf.lib.clang_Cursor_getArgument(self, i)
+
     def get_children(self):
         """Return an iterator for accessing the children of this cursor."""
 
@@ -2973,6 +2979,15 @@
   ("clang_visitChildren",
    [Cursor, callbacks['cursor_visit'], py_object],
    c_uint),
+
+  ("clang_Cursor_getNumArguments",
+   [Cursor],
+   c_int),
+
+  ("clang_Cursor_getArgument",
+   [Cursor, c_uint],
+   Cursor,
+   Cursor.from_result),
 ]
 
 class LibclangError(Exception):
Index: bindings/python/tests/cindex/test_cursor.py
===================================================================
--- bindings/python/tests/cindex/test_cursor.py
+++ bindings/python/tests/cindex/test_cursor.py
@@ -241,3 +241,12 @@
     assert len(tokens) == 7
     assert tokens[0].spelling == 'int'
     assert tokens[1].spelling == 'foo'
+
+def test_get_arguments():
+    tu = get_tu('void foo(int i, int j);')
+    foo = get_cursor(tu, 'foo')
+    arguments = list(foo.get_arguments())
+
+    assert len(arguments) == 2
+    assert arguments[0].spelling == "i"
+    assert arguments[1].spelling == "j"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64.1.patch
Type: text/x-patch
Size: 1551 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121016/fc1a00ef/attachment.bin>


More information about the cfe-commits mailing list