From 1b945a7455e17fd792ef3bd3790dc88beea5faad Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sun, 24 Jan 2010 04:09:43 +0000 Subject: cindex/Python: Add TranslationUnit.cursor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94355 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/python/clang/cindex.py | 14 +++++++++----- bindings/python/tests/cindex/test_translation_unit.py | 8 ++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) (limited to 'bindings/python') diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index 772875c45a..2545c45ac8 100644 --- a/bindings/python/clang/cindex.py +++ b/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/bindings/python/tests/cindex/test_translation_unit.py b/bindings/python/tests/cindex/test_translation_unit.py index e101247460..f8d4bebc1b 100644 --- a/bindings/python/tests/cindex/test_translation_unit.py +++ b/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 -- cgit v1.2.3-70-g09d2