summaryrefslogtreecommitdiffstats
path: root/clang/bindings/python
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-01-24 21:20:05 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-01-24 21:20:05 +0000
commit501e91f3b7bc8d06f245696ff327ea6aa153ec47 (patch)
tree4ff6867f2b270d5c6edecc1af138f232e84349d0 /clang/bindings/python
parent942453284f8f918d79f7f28ed0af0d1ad6924380 (diff)
downloadbcm5719-llvm-501e91f3b7bc8d06f245696ff327ea6aa153ec47.tar.gz
bcm5719-llvm-501e91f3b7bc8d06f245696ff327ea6aa153ec47.zip
cindex/Python: Return null cursors as None instead of exposing this notion.
llvm-svn: 94385
Diffstat (limited to 'clang/bindings/python')
-rw-r--r--clang/bindings/python/clang/cindex.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 115ea9fbfd1..8b4ea5bc323 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -133,11 +133,6 @@ class Cursor(Structure):
def __ne__(self, other):
return not Cursor_eq(self, other)
- @staticmethod
- def null():
- """Return the null cursor object."""
- return Cursor_null()
-
def is_declaration(self):
"""Return True if the cursor points to a declaration."""
return Cursor_is_decl(self.kind)
@@ -204,16 +199,27 @@ class Cursor(Structure):
return Cursor_extent(self)
def get_children(self):
- """Return an iterator for the accessing children of this cursor."""
+ """Return an iterator for the accessing the children of this cursor."""
# FIXME: Expose iteration from CIndex, PR6125.
def visitor(child, parent, children):
+ # FIXME: Document this assertion in API.
+ # FIXME: There should just be an isNull method.
+ assert child != Cursor_null()
children.append(child)
return 1 # continue
children = []
Cursor_visit(self, Callback(visitor), children)
return iter(children)
+ @staticmethod
+ def from_result(res, fn, args):
+ assert isinstance(res, Cursor)
+ # FIXME: There should just be an isNull method.
+ if res == Cursor_null():
+ return None
+ return res
+
## CIndex Objects ##
# CIndex objects (derived from ClangObject) are essentially lightweight
@@ -391,6 +397,7 @@ Cursor_is_def.restype = bool
Cursor_def = lib.clang_getCursorDefinition
Cursor_def.argtypes = [Cursor]
Cursor_def.restype = Cursor
+Cursor_def.errcheck = Cursor.from_result
Cursor_eq = lib.clang_equalCursors
Cursor_eq.argtypes = [Cursor, Cursor]
@@ -412,6 +419,7 @@ Cursor_extent.restype = SourceRange
Cursor_ref = lib.clang_getCursorReferenced
Cursor_ref.argtypes = [Cursor]
Cursor_ref.restype = Cursor
+Cursor_ref.errcheck = Cursor.from_result
Cursor_visit = lib.clang_visitChildren
Cursor_visit.argtypes = [Cursor, Callback, py_object]
@@ -438,6 +446,7 @@ TranslationUnit_parse.restype = c_object_p
TranslationUnit_cursor = lib.clang_getTranslationUnitCursor
TranslationUnit_cursor.argtypes = [TranslationUnit]
TranslationUnit_cursor.restype = Cursor
+TranslationUnit_cursor.errcheck = Cursor.from_result
TranslationUnit_spelling = lib.clang_getTranslationUnitSpelling
TranslationUnit_spelling.argtypes = [TranslationUnit]
OpenPOWER on IntegriCloud