[cfe-commits] r94359 - /cfe/trunk/bindings/python/clang/cindex.py

Daniel Dunbar daniel at zuster.org
Sat Jan 23 20:10:22 PST 2010


Author: ddunbar
Date: Sat Jan 23 22:10:22 2010
New Revision: 94359

URL: http://llvm.org/viewvc/llvm-project?rev=94359&view=rev
Log:
cindex/Python: Add Cursor.get_children()

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

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

==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sat Jan 23 22:10:22 2010
@@ -221,6 +221,17 @@
         """
         return self.location.file
 
+    def get_children(self):
+        """Return an iterator for the accessing children of this cursor."""
+
+        # FIXME: Expose iteration from CIndex, PR6125.
+        def visitor(child, parent, children):
+            children.append(child)
+            return 1 # continue
+        children = []
+        Cursor_visit(self, Callback(visitor), children)
+        return iter(children)
+
 ## CIndex Objects ##
 
 # CIndex objects (derived from ClangObject) are essentially lightweight
@@ -326,8 +337,8 @@
 
 # Additional Functions and Types
 
-# Wrap calls to Cursor_visit.
-Callback = CFUNCTYPE(None, c_void_p, Cursor, c_void_p)
+# Wrap calls to TranslationUnit._load and Decl._load.
+Callback = CFUNCTYPE(c_int, Cursor, Cursor, py_object)
 
 # String Functions
 String_dispose = lib.clang_disposeString
@@ -350,7 +361,7 @@
 # Cursor Functions
 # TODO: Implement this function
 Cursor_get = lib.clang_getCursor
-Cursor_get.argtypes = [TranslationUnit, c_char_p, c_uint, c_uint]
+Cursor_get.argtypes = [TranslationUnit, SourceLocation]
 Cursor.restype = Cursor
 
 Cursor_null = lib.clang_getNullCursor
@@ -415,6 +426,10 @@
 Cursor_ref.argtypes = [Cursor]
 Cursor_ref.restype = Cursor
 
+Cursor_visit = lib.clang_visitChildren
+Cursor_visit.argtypes = [Cursor, Callback, py_object]
+Cursor_visit.restype = c_uint
+
 # Index Functions
 Index_create = lib.clang_createIndex
 Index_create.argtypes = [c_int, c_int]





More information about the cfe-commits mailing list