summaryrefslogtreecommitdiffstats
path: root/clang/bindings/python
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2016-04-30 21:14:01 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2016-04-30 21:14:01 +0000
commitacc98ca43c376526ef31a618c774b230d6e6f51d (patch)
tree37ebc22d41293810eb00e51dd2ad80534825ed87 /clang/bindings/python
parentc179435055ac87e59f85885f04fa4dd84535afca (diff)
downloadbcm5719-llvm-acc98ca43c376526ef31a618c774b230d6e6f51d.tar.gz
bcm5719-llvm-acc98ca43c376526ef31a618c774b230d6e6f51d.zip
python: add bindings for children of diagnostics
This exposes the Clang API bindings clang_getChildDiagnostics (which returns a CXDiagnosticSet) and clang_getNumDiagnosticsInSet / clang_getDiagnosticInSet (to traverse the CXDiagnosticSet), and adds a helper children property in the Python Diagnostic wrapper. Also, this adds the missing OVERLOAD_CANDIDATE (700) cursor type. Patch by Hanson Wang! llvm-svn: 268167
Diffstat (limited to 'clang/bindings/python')
-rw-r--r--clang/bindings/python/clang/cindex.py32
-rw-r--r--clang/bindings/python/tests/cindex/test_diagnostics.py12
2 files changed, 44 insertions, 0 deletions
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index ba68c0bd8e9..b55c723dff3 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -360,6 +360,23 @@ class Diagnostic(object):
return FixItIterator(self)
@property
+ def children(self):
+ class ChildDiagnosticsIterator:
+ def __init__(self, diag):
+ self.diag_set = conf.lib.clang_getChildDiagnostics(diag)
+
+ def __len__(self):
+ return int(conf.lib.clang_getNumDiagnosticsInSet(self.diag_set))
+
+ def __getitem__(self, key):
+ diag = conf.lib.clang_getDiagnosticInSet(self.diag_set, key)
+ if not diag:
+ raise IndexError
+ return Diagnostic(diag)
+
+ return ChildDiagnosticsIterator(self)
+
+ @property
def category_number(self):
"""The category number for this diagnostic or 0 if unavailable."""
return conf.lib.clang_getDiagnosticCategory(self)
@@ -1120,6 +1137,9 @@ CursorKind.MODULE_IMPORT_DECL = CursorKind(600)
# A type alias template declaration
CursorKind.TYPE_ALIAS_TEMPLATE_DECL = CursorKind(601)
+# A code completion overload candidate.
+CursorKind.OVERLOAD_CANDIDATE = CursorKind(700)
+
### Template Argument Kinds ###
class TemplateArgumentKind(BaseEnumeration):
"""
@@ -3053,6 +3073,10 @@ functionList = [
Type,
Type.from_result),
+ ("clang_getChildDiagnostics",
+ [Diagnostic],
+ c_object_p),
+
("clang_getCompletionAvailability",
[c_void_p],
c_int),
@@ -3173,6 +3197,10 @@ functionList = [
_CXString,
_CXString.from_result),
+ ("clang_getDiagnosticInSet",
+ [c_object_p, c_uint],
+ c_object_p),
+
("clang_getDiagnosticLocation",
[Diagnostic],
SourceLocation),
@@ -3274,6 +3302,10 @@ functionList = [
[c_object_p],
c_uint),
+ ("clang_getNumDiagnosticsInSet",
+ [c_object_p],
+ c_uint),
+
("clang_getNumElements",
[Type],
c_longlong),
diff --git a/clang/bindings/python/tests/cindex/test_diagnostics.py b/clang/bindings/python/tests/cindex/test_diagnostics.py
index 48ab6176fd1..ba6e545e8b1 100644
--- a/clang/bindings/python/tests/cindex/test_diagnostics.py
+++ b/clang/bindings/python/tests/cindex/test_diagnostics.py
@@ -80,3 +80,15 @@ def test_diagnostic_option():
assert d.option == '-Wunused-parameter'
assert d.disable_option == '-Wno-unused-parameter'
+
+def test_diagnostic_children():
+ tu = get_tu('void f(int x) {} void g() { f(); }')
+ assert len(tu.diagnostics) == 1
+ d = tu.diagnostics[0]
+
+ children = d.children
+ assert len(children) == 1
+ assert children[0].severity == Diagnostic.Note
+ assert children[0].spelling.endswith('declared here')
+ assert children[0].location.line == 1
+ assert children[0].location.column == 1
OpenPOWER on IntegriCloud