summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-12-14 22:01:50 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-12-14 22:01:50 +0000
commit2e8732d1c668d518d3799a141051f7b8db0b5f74 (patch)
tree84e038b616b7d0485dbd1967ca072a7c2d2018e1 /bindings
parentd32e8534a612dedd328b5c4546123211c97ee265 (diff)
[libclang] Add support for checking abstractness of records
This patch allows checking whether a C++ record declaration is abstract through libclang and clang.cindex (Python). Patch by Johann Klähn! Differential Revision: https://reviews.llvm.org/D36952 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320748 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/clang/cindex.py20
-rw-r--r--bindings/python/tests/cindex/test_cursor.py22
2 files changed, 42 insertions, 0 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index d72dd14ef9..6cdb10ef08 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -1479,6 +1479,18 @@ class Cursor(Structure):
"""
return conf.lib.clang_CXXMethod_isVirtual(self)
+ def is_abstract_record(self):
+ """Returns True if the cursor refers to a C++ record declaration
+ that has pure virtual member functions.
+ """
+ return conf.lib.clang_CXXRecord_isAbstract(self)
+
+ def is_abstract_record(self):
+ """Returns True if the cursor refers to a C++ record declaration
+ that has pure virtual member functions.
+ """
+ return conf.lib.clang_CXXRecord_isAbstract(self)
+
def is_scoped_enum(self):
"""Returns True if the cursor refers to a scoped enum declaration.
"""
@@ -3401,6 +3413,14 @@ functionList = [
[Cursor],
bool),
+ ("clang_CXXRecord_isAbstract",
+ [Cursor],
+ bool),
+
+ ("clang_CXXRecord_isAbstract",
+ [Cursor],
+ bool),
+
("clang_EnumDecl_isScoped",
[Cursor],
bool),
diff --git a/bindings/python/tests/cindex/test_cursor.py b/bindings/python/tests/cindex/test_cursor.py
index 41ef62757a..80f023912a 100644
--- a/bindings/python/tests/cindex/test_cursor.py
+++ b/bindings/python/tests/cindex/test_cursor.py
@@ -275,6 +275,28 @@ class TestCursor(unittest.TestCase):
self.assertTrue(foo.is_virtual_method())
self.assertFalse(bar.is_virtual_method())
+ def test_is_abstract_record(self):
+ """Ensure Cursor.is_abstract_record works."""
+ source = 'struct X { virtual void x() = 0; }; struct Y : X { void x(); };'
+ tu = get_tu(source, lang='cpp')
+
+ cls = get_cursor(tu, 'X')
+ self.assertTrue(cls.is_abstract_record())
+
+ cls = get_cursor(tu, 'Y')
+ self.assertFalse(cls.is_abstract_record())
+
+ def test_is_abstract_record(self):
+ """Ensure Cursor.is_abstract_record works."""
+ source = 'struct X { virtual void x() = 0; }; struct Y : X { void x(); };'
+ tu = get_tu(source, lang='cpp')
+
+ cls = get_cursor(tu, 'X')
+ self.assertTrue(cls.is_abstract_record())
+
+ cls = get_cursor(tu, 'Y')
+ self.assertFalse(cls.is_abstract_record())
+
def test_is_scoped_enum(self):
"""Ensure Cursor.is_scoped_enum works."""
source = 'class X {}; enum RegularEnum {}; enum class ScopedEnum {};'