This revision was automatically updated to reflect the committed changes.
Closed by commit rL312622: Fix __repr__ for Diagnostic in clang.cindex 
(authored by jbcoe).

Changed prior to commit:
  https://reviews.llvm.org/D37490?vs=113896&id=113966#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37490

Files:
  cfe/trunk/bindings/python/clang/cindex.py
  cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py
  cfe/trunk/bindings/python/tests/cindex/test_exception_specification_kind.py
  cfe/trunk/bindings/python/tests/test_exception_specification_kind.py

Index: cfe/trunk/bindings/python/clang/cindex.py
===================================================================
--- cfe/trunk/bindings/python/clang/cindex.py
+++ cfe/trunk/bindings/python/clang/cindex.py
@@ -207,7 +207,7 @@
         conf.lib.clang_disposeString(self)
 
     @staticmethod
-    def from_result(res, fn, args):
+    def from_result(res, fn=None, args=None):
         assert isinstance(res, _CXString)
         return conf.lib.clang_getCString(res)
 
@@ -459,8 +459,7 @@
         """The command-line option that disables this diagnostic."""
         disable = _CXString()
         conf.lib.clang_getDiagnosticOption(self, byref(disable))
-
-        return conf.lib.clang_getCString(disable)
+        return _CXString.from_result(disable)
 
     def format(self, options=None):
         """
@@ -473,8 +472,7 @@
             options = conf.lib.clang_defaultDiagnosticDisplayOptions()
         if options & ~Diagnostic._FormatOptionsMask:
             raise ValueError('Invalid format options')
-        formatted = conf.lib.clang_formatDiagnostic(self, options)
-        return conf.lib.clang_getCString(formatted)
+        return conf.lib.clang_formatDiagnostic(self, options)
 
     def __repr__(self):
         return "<Diagnostic severity %r, location %r, spelling %r>" % (
Index: cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py
===================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py
+++ cfe/trunk/bindings/python/tests/cindex/test_diagnostics.py
@@ -92,3 +92,11 @@
     assert children[0].spelling.endswith('declared here')
     assert children[0].location.line == 1
     assert children[0].location.column == 1
+
+def test_diagnostic_string_repr():
+    tu = get_tu('struct MissingSemicolon{}')
+    assert len(tu.diagnostics) == 1
+    d = tu.diagnostics[0]
+
+    assert repr(d) == '<Diagnostic severity 3, location <SourceLocation file \'t.c\', line 1, column 26>, spelling "expected \';\' after struct">'
+    
Index: cfe/trunk/bindings/python/tests/cindex/test_exception_specification_kind.py
===================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_exception_specification_kind.py
+++ cfe/trunk/bindings/python/tests/cindex/test_exception_specification_kind.py
@@ -0,0 +1,27 @@
+import clang.cindex
+from clang.cindex import ExceptionSpecificationKind
+from .util import get_tu
+
+
+def find_function_declarations(node, declarations=[]):
+    if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
+        declarations.append((node.spelling, node.exception_specification_kind))
+    for child in node.get_children():
+        declarations = find_function_declarations(child, declarations)
+    return declarations
+
+
+def test_exception_specification_kind():
+    source = """int square1(int x);
+                int square2(int x) noexcept;
+                int square3(int x) noexcept(noexcept(x * x));"""
+
+    tu = get_tu(source, lang='cpp', flags=['-std=c++14'])
+
+    declarations = find_function_declarations(tu.cursor)
+    expected = [
+        ('square1', ExceptionSpecificationKind.NONE),
+        ('square2', ExceptionSpecificationKind.BASIC_NOEXCEPT),
+        ('square3', ExceptionSpecificationKind.COMPUTED_NOEXCEPT)
+    ]
+    assert declarations == expected
Index: cfe/trunk/bindings/python/tests/test_exception_specification_kind.py
===================================================================
--- cfe/trunk/bindings/python/tests/test_exception_specification_kind.py
+++ cfe/trunk/bindings/python/tests/test_exception_specification_kind.py
@@ -1,27 +0,0 @@
-import clang.cindex
-from clang.cindex import ExceptionSpecificationKind
-from .util import get_tu
-
-
-def find_function_declarations(node, declarations=[]):
-    if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
-        declarations.append((node.spelling, node.exception_specification_kind))
-    for child in node.get_children():
-        declarations = find_function_declarations(child, declarations)
-    return declarations
-
-
-def test_exception_specification_kind():
-    source = """int square1(int x);
-                int square2(int x) noexcept;
-                int square3(int x) noexcept(noexcept(x * x));"""
-
-    tu = get_tu(source, lang='cpp', flags=['-std=c++14'])
-
-    declarations = find_function_declarations(tu.cursor)
-    expected = [
-        ('square1', ExceptionSpecificationKind.NONE),
-        ('square2', ExceptionSpecificationKind.BASIC_NOEXCEPT),
-        ('square3', ExceptionSpecificationKind.COMPUTED_NOEXCEPT)
-    ]
-    assert declarations == expected
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D37490: Fix __repr_... Jonathan B Coe via Phabricator via cfe-commits
    • [PATCH] D37490: Fix __... Jonathan B Coe via Phabricator via cfe-commits

Reply via email to