diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2010-01-24 04:10:22 +0000 | 
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2010-01-24 04:10:22 +0000 | 
| commit | fd7caa25a69cb347bf93bc70ccf24f21a67ac15d (patch) | |
| tree | d602db1f18303c0122cf01b0b8118f6bc5b3b07c | |
| parent | 7bcfd6eb6d77f64fc0d2ab5c866c08d2a521574a (diff) | |
| download | bcm5719-llvm-fd7caa25a69cb347bf93bc70ccf24f21a67ac15d.tar.gz bcm5719-llvm-fd7caa25a69cb347bf93bc70ccf24f21a67ac15d.zip | |
cindex/Python: Add Cursor.get_children()
llvm-svn: 94359
| -rw-r--r-- | clang/bindings/python/clang/cindex.py | 21 | 
1 files changed, 18 insertions, 3 deletions
| diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 43d9caf1c49..394214c3a98 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -221,6 +221,17 @@ class Cursor(Structure):          """          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 @@ class File(ClangObject):  # 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 @@ SourceRange_end.restype = SourceLocation  # 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 = lib.clang_getCursorReferenced  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] | 

