[cfe-commits] r94355 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_translation_unit.py

Daniel Dunbar daniel at zuster.org
Sat Jan 23 20:09:44 PST 2010


Author: ddunbar
Date: Sat Jan 23 22:09:43 2010
New Revision: 94355

URL: http://llvm.org/viewvc/llvm-project?rev=94355&view=rev
Log:
cindex/Python: Add TranslationUnit.cursor.

Modified:
    cfe/trunk/bindings/python/clang/cindex.py
    cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=94355&r1=94354&r2=94355&view=diff

==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sat Jan 23 22:09:43 2010
@@ -308,14 +308,14 @@
         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 @@
                                   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

Modified: cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py?rev=94355&r1=94354&r2=94355&view=diff

==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py Sat Jan 23 22:09:43 2010
@@ -8,3 +8,11 @@
     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





More information about the cfe-commits mailing list