[llvm-branch-commits] [cfe-branch] r314434 - Merging r312622:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Sep 28 10:22:56 PDT 2017


Author: tstellar
Date: Thu Sep 28 10:22:56 2017
New Revision: 314434

URL: http://llvm.org/viewvc/llvm-project?rev=314434&view=rev
Log:
Merging r312622:

------------------------------------------------------------------------
r312622 | jbcoe | 2017-09-06 00:33:32 -0700 (Wed, 06 Sep 2017) | 13 lines

Fix __repr__ for Diagnostic in clang.cindex

Summary: Also move misplaced tests for exception specification to fix failing Python tests.

Reviewers: hans, compnerd

Reviewed By: compnerd

Subscribers: cfe-commits

Tags: #clang-c

Differential Revision: https://reviews.llvm.org/D37490
------------------------------------------------------------------------

Added:
    cfe/branches/release_50/bindings/python/tests/cindex/test_exception_specification_kind.py
      - copied, changed from r314381, cfe/branches/release_50/bindings/python/tests/test_exception_specification_kind.py
Removed:
    cfe/branches/release_50/bindings/python/tests/test_exception_specification_kind.py
Modified:
    cfe/branches/release_50/bindings/python/clang/cindex.py
    cfe/branches/release_50/bindings/python/tests/cindex/test_diagnostics.py

Modified: cfe/branches/release_50/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/bindings/python/clang/cindex.py?rev=314434&r1=314433&r2=314434&view=diff
==============================================================================
--- cfe/branches/release_50/bindings/python/clang/cindex.py (original)
+++ cfe/branches/release_50/bindings/python/clang/cindex.py Thu Sep 28 10:22:56 2017
@@ -207,7 +207,7 @@ class _CXString(Structure):
         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 @@ class Diagnostic(object):
         """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 @@ class Diagnostic(object):
             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>" % (

Modified: cfe/branches/release_50/bindings/python/tests/cindex/test_diagnostics.py
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/bindings/python/tests/cindex/test_diagnostics.py?rev=314434&r1=314433&r2=314434&view=diff
==============================================================================
--- cfe/branches/release_50/bindings/python/tests/cindex/test_diagnostics.py (original)
+++ cfe/branches/release_50/bindings/python/tests/cindex/test_diagnostics.py Thu Sep 28 10:22:56 2017
@@ -92,3 +92,11 @@ def test_diagnostic_children():
     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">'
+    

Copied: cfe/branches/release_50/bindings/python/tests/cindex/test_exception_specification_kind.py (from r314381, cfe/branches/release_50/bindings/python/tests/test_exception_specification_kind.py)
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/bindings/python/tests/cindex/test_exception_specification_kind.py?p2=cfe/branches/release_50/bindings/python/tests/cindex/test_exception_specification_kind.py&p1=cfe/branches/release_50/bindings/python/tests/test_exception_specification_kind.py&r1=314381&r2=314434&rev=314434&view=diff
==============================================================================
    (empty)

Removed: cfe/branches/release_50/bindings/python/tests/test_exception_specification_kind.py
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/bindings/python/tests/test_exception_specification_kind.py?rev=314433&view=auto
==============================================================================
--- cfe/branches/release_50/bindings/python/tests/test_exception_specification_kind.py (original)
+++ cfe/branches/release_50/bindings/python/tests/test_exception_specification_kind.py (removed)
@@ -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




More information about the llvm-branch-commits mailing list