Re: [PATCH] D17841: [libclang/python] Add bindings for children of diagnostics

2016-04-27 Thread Hanson Wang via cfe-commits
hansonw updated this revision to Diff 55378.
hansonw added a comment.

Rebase


http://reviews.llvm.org/D17841

Files:
  bindings/python/clang/cindex.py
  bindings/python/tests/cindex/test_diagnostics.py

Index: bindings/python/tests/cindex/test_diagnostics.py
===
--- bindings/python/tests/cindex/test_diagnostics.py
+++ bindings/python/tests/cindex/test_diagnostics.py
@@ -80,3 +80,15 @@
 
 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
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -360,6 +360,23 @@
 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 @@
 # 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 @@
Type,
Type.from_result),
 
+  ("clang_getChildDiagnostics",
+   [Diagnostic],
+   c_object_p),
+
   ("clang_getCompletionAvailability",
[c_void_p],
c_int),
@@ -3173,6 +3197,10 @@
_CXString,
_CXString.from_result),
 
+  ("clang_getDiagnosticInSet",
+   [c_object_p, c_uint],
+   c_object_p),
+
   ("clang_getDiagnosticLocation",
[Diagnostic],
SourceLocation),
@@ -3274,6 +3302,10 @@
[c_object_p],
c_uint),
 
+  ("clang_getNumDiagnosticsInSet",
+   [c_object_p],
+   c_uint),
+
   ("clang_getNumElements",
[Type],
c_longlong),


Index: bindings/python/tests/cindex/test_diagnostics.py
===
--- bindings/python/tests/cindex/test_diagnostics.py
+++ bindings/python/tests/cindex/test_diagnostics.py
@@ -80,3 +80,15 @@
 
 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
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -360,6 +360,23 @@
 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 @@
 # 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 @@
Type,
Type.from_resu

Re: [PATCH] D17841: [libclang/python] Add bindings for children of diagnostics

2016-04-27 Thread Hanson Wang via cfe-commits
hansonw added reviewers: compnerd, skalinichev.
hansonw added a comment.

Adding you guys since you reviewed some recent changes :)


http://reviews.llvm.org/D17841



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17841: [libclang/python] Add bindings for children of diagnostics

2016-04-28 Thread Hanson Wang via cfe-commits
hansonw added a comment.

Thanks! I don't have commit permissions; could you check this in for me?



Comment at: bindings/python/clang/cindex.py:369
@@ +368,3 @@
+def __len__(self):
+return 
int(conf.lib.clang_getNumDiagnosticsInSet(self.diag_set))
+

compnerd wrote:
> Why does this need the explicit int construction?
This returns a long on 64-bit systems - however `__len__` must return a plain 
int.


http://reviews.llvm.org/D17841



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits