summaryrefslogtreecommitdiffstats
path: root/clang/bindings/python
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-01-24 04:09:43 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-01-24 04:09:43 +0000
commite79aba4c725f0fca2a65f29ff23d8785b9f68fdf (patch)
tree9d18998778cb49ce0101d26d7b63feb17d59b3a8 /clang/bindings/python
parent3615fd27f24b2a0d08508d714bb7e69a293ad352 (diff)
downloadbcm5719-llvm-e79aba4c725f0fca2a65f29ff23d8785b9f68fdf.tar.gz
bcm5719-llvm-e79aba4c725f0fca2a65f29ff23d8785b9f68fdf.zip
cindex/Python: Add TranslationUnit.cursor.
llvm-svn: 94355
Diffstat (limited to 'clang/bindings/python')
-rw-r--r--clang/bindings/python/clang/cindex.py14
-rw-r--r--clang/bindings/python/tests/cindex/test_translation_unit.py8
2 files changed, 17 insertions, 5 deletions
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 772875c45a7..2545c45ac87 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -308,14 +308,14 @@ class TranslationUnit(ClangObject):
if self.free and self.obj:
TranslationUnit_dispose(self)
- def load(self, fun, data = None):
- # Actually call this over a lambda that attaches an object the
- # underlying void pointer.
- f = lambda t, c, x: fun(TranslationUnit(t), c, x)
- TranslationUnit_load(self.obj, Callback(f), data)
+ @property
+ def cursor(self):
+ """Retrieve the cursor that represents the given translation unit."""
+ return TranslationUnit_cursor(self)
@property
def spelling(self):
+ """Get the original translation unit source file name."""
return TranslationUnit_spelling(self)
@staticmethod
@@ -504,6 +504,10 @@ TranslationUnit_parse.argtypes = [Index, c_char_p, c_int, c_void_p,
c_int, c_void_p]
TranslationUnit_parse.restype = c_object_p
+TranslationUnit_cursor = lib.clang_getTranslationUnitCursor
+TranslationUnit_cursor.argtypes = [TranslationUnit]
+TranslationUnit_cursor.restype = Cursor
+
TranslationUnit_spelling = lib.clang_getTranslationUnitSpelling
TranslationUnit_spelling.argtypes = [TranslationUnit]
TranslationUnit_spelling.restype = String
diff --git a/clang/bindings/python/tests/cindex/test_translation_unit.py b/clang/bindings/python/tests/cindex/test_translation_unit.py
index e1012474606..f8d4bebc1bc 100644
--- a/clang/bindings/python/tests/cindex/test_translation_unit.py
+++ b/clang/bindings/python/tests/cindex/test_translation_unit.py
@@ -8,3 +8,11 @@ def test_spelling():
index = Index.create()
tu = index.parse(path)
assert str(tu.spelling) == path
+
+def test_cursor():
+ path = os.path.join(kInputsDir, 'hello.cpp')
+ index = Index.create()
+ tu = index.parse(path)
+ c = tu.cursor
+ assert isinstance(c, Cursor)
+ assert c.is_translation_unit
OpenPOWER on IntegriCloud