summaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorGregory Szorc <gregory.szorc@gmail.com>2012-11-01 05:46:30 +0000
committerGregory Szorc <gregory.szorc@gmail.com>2012-11-01 05:46:30 +0000
commit245296ed403ce07f8d8c514b6ca500a80492fc8c (patch)
treeacc46fe8b3d5f58c047d196b6a1864bcf8a53458 /clang
parentebe8c8cea23a138441ab5ab08fe62cf47a09e9d0 (diff)
downloadllvm-245296ed403ce07f8d8c514b6ca500a80492fc8c.tar.gz
[clang.py] Add Cursor.get_arguments()
Patch provided by Matthias Kleine <matthias_kleine@gmx.de> llvm-svn: 167216
Diffstat (limited to 'clang')
-rw-r--r--clang/bindings/python/clang/cindex.py15
-rw-r--r--clang/bindings/python/tests/cindex/test_cursor.py9
2 files changed, 24 insertions, 0 deletions
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 8f03dd6b1b58..5e162c0e8349 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -1271,6 +1271,12 @@ class Cursor(Structure):
# 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 @@ functionList = [
("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):
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py b/clang/bindings/python/tests/cindex/test_cursor.py
index 51695e20b0c7..edb209b52b96 100644
--- a/clang/bindings/python/tests/cindex/test_cursor.py
+++ b/clang/bindings/python/tests/cindex/test_cursor.py
@@ -241,3 +241,12 @@ def test_get_tokens():
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"