[cfe-commits] r94385 - /cfe/trunk/bindings/python/clang/cindex.py
Daniel Dunbar
daniel at zuster.org
Sun Jan 24 13:20:05 PST 2010
Author: ddunbar
Date: Sun Jan 24 15:20:05 2010
New Revision: 94385
URL: http://llvm.org/viewvc/llvm-project?rev=94385&view=rev
Log:
cindex/Python: Return null cursors as None instead of exposing this notion.
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=94385&r1=94384&r2=94385&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sun Jan 24 15:20:05 2010
@@ -133,11 +133,6 @@
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 @@
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_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_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_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]
More information about the cfe-commits
mailing list