summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-03-06 15:38:03 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-03-06 15:38:03 +0000
commit1d02ccd1aa9bab97d0c0869d54df05a4e5f57b1b (patch)
tree39aaabe987a8eb44ed09fe6fd646ec2f676231a1 /bindings
parent3b0cf09f9c84e75881b261eb4a7a69d99aa0335a (diff)
Rename the new Iterator objects and raise an assertion instead of returning invalid objects when the key is out of range.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97881 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/clang/cindex.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 4a14b880a1..f4409aec33 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -207,7 +207,7 @@ class Diagnostic(object):
@property
def ranges(self):
- class Ranges:
+ class RangeIterator:
def __init__(self, diag):
self.diag = diag
@@ -217,11 +217,11 @@ class Diagnostic(object):
def __getitem__(self, key):
return _clang_getDiagnosticRange(self.diag, key)
- return Ranges(self.ptr)
+ return RangeIterator(self.ptr)
@property
def fixits(self):
- class FixIts:
+ class FixItIterator:
def __init__(self, diag):
self.diag = diag
@@ -231,10 +231,12 @@ class Diagnostic(object):
def __getitem__(self, key):
range = SourceRange()
value = _clang_getDiagnosticFixIt(self.diag, key, byref(range))
+ if len(value) == 0:
+ raise IndexError
return FixIt(range, value)
- return FixIts(self.ptr)
+ return FixItIterator(self.ptr)
def __repr__(self):
return "<Diagnostic severity %r, location %r, spelling %r>" % (
@@ -581,9 +583,6 @@ class _CXUnsavedFile(Structure):
## Diagnostic Conversion ##
-# Diagnostic objects are temporary, we must extract all the information from the
-# diagnostic object when it is passed to the callback.
-
_clang_getNumDiagnostics = lib.clang_getNumDiagnostics
_clang_getNumDiagnostics.argtypes = [c_object_p]
_clang_getNumDiagnostics.restype = c_uint
@@ -730,7 +729,7 @@ class TranslationUnit(ClangObject):
"""
Return an iterable (and indexable) object containing the diagnostics.
"""
- class Diags:
+ class DiagIterator:
def __init__(self, tu):
self.tu = tu
@@ -738,9 +737,12 @@ class TranslationUnit(ClangObject):
return int(_clang_getNumDiagnostics(self.tu))
def __getitem__(self, key):
- return Diagnostic(_clang_getDiagnostic(self.tu, key))
+ diag = _clang_getDiagnostic(self.tu, key)
+ if not diag:
+ raise IndexError
+ return Diagnostic(diag)
- return Diags(self)
+ return DiagIterator(self)
class File(ClangObject):
"""