summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/bindings/python/clang/cindex.py20
-rw-r--r--clang/bindings/python/tests/cindex/test_cursor.py22
-rw-r--r--clang/include/clang-c/Index.h8
-rw-r--r--clang/test/Index/load-classes.cpp2
-rw-r--r--clang/tools/c-index-test/c-index-test.c2
-rw-r--r--clang/tools/libclang/CIndex.cpp11
-rw-r--r--clang/tools/libclang/libclang.exports1
7 files changed, 64 insertions, 2 deletions
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index d72dd14ef9f..6cdb10ef081 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/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/clang/bindings/python/tests/cindex/test_cursor.py b/clang/bindings/python/tests/cindex/test_cursor.py
index 41ef62757ac..80f023912ac 100644
--- a/clang/bindings/python/tests/cindex/test_cursor.py
+++ b/clang/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 {};'
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 1204d6a5d88..587008a7210 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -32,7 +32,7 @@
* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
*/
#define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 44
+#define CINDEX_VERSION_MINOR 45
#define CINDEX_VERSION_ENCODE(major, minor) ( \
((major) * 10000) \
@@ -4467,6 +4467,12 @@ CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
CINDEX_LINKAGE unsigned clang_CXXMethod_isVirtual(CXCursor C);
/**
+ * \brief Determine if a C++ record is abstract, i.e. whether a class or struct
+ * has a pure virtual member function.
+ */
+CINDEX_LINKAGE unsigned clang_CXXRecord_isAbstract(CXCursor C);
+
+/**
* \brief Determine if an enum declaration refers to a scoped enum.
*/
CINDEX_LINKAGE unsigned clang_EnumDecl_isScoped(CXCursor C);
diff --git a/clang/test/Index/load-classes.cpp b/clang/test/Index/load-classes.cpp
index 8b1ed317e3b..b6c25b4f751 100644
--- a/clang/test/Index/load-classes.cpp
+++ b/clang/test/Index/load-classes.cpp
@@ -29,7 +29,7 @@ X::X(int value) {
}
// RUN: c-index-test -test-load-source all %s | FileCheck %s
-// CHECK: load-classes.cpp:3:8: StructDecl=X:3:8 (Definition) Extent=[3:1 - 26:2]
+// CHECK: load-classes.cpp:3:8: StructDecl=X:3:8 (Definition) (abstract) Extent=[3:1 - 26:2]
// CHECK: load-classes.cpp:4:3: CXXConstructor=X:4:3 (converting constructor) Extent=[4:3 - 4:15] [access=public]
// FIXME: missing TypeRef in the constructor name
// CHECK: load-classes.cpp:4:9: ParmDecl=value:4:9 (Definition) Extent=[4:5 - 4:14]
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 91afbe219ac..99f05669b64 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -804,6 +804,8 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
printf(" (const)");
if (clang_CXXMethod_isPureVirtual(Cursor))
printf(" (pure)");
+ if (clang_CXXRecord_isAbstract(Cursor))
+ printf(" (abstract)");
if (clang_EnumDecl_isScoped(Cursor))
printf(" (scoped)");
if (clang_Cursor_isVariadic(Cursor))
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 656df9b09b0..f4d347108c9 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -7919,6 +7919,17 @@ unsigned clang_CXXMethod_isVirtual(CXCursor C) {
return (Method && Method->isVirtual()) ? 1 : 0;
}
+unsigned clang_CXXRecord_isAbstract(CXCursor C) {
+ if (!clang_isDeclaration(C.kind))
+ return 0;
+
+ const auto *D = cxcursor::getCursorDecl(C);
+ const auto *RD = dyn_cast_or_null<CXXRecordDecl>(D);
+ if (RD)
+ RD = RD->getDefinition();
+ return (RD && RD->isAbstract()) ? 1 : 0;
+}
+
unsigned clang_EnumDecl_isScoped(CXCursor C) {
if (!clang_isDeclaration(C.kind))
return 0;
diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports
index bd262ee1a04..4d3a029567d 100644
--- a/clang/tools/libclang/libclang.exports
+++ b/clang/tools/libclang/libclang.exports
@@ -13,6 +13,7 @@ clang_CXXMethod_isConst
clang_CXXMethod_isPureVirtual
clang_CXXMethod_isStatic
clang_CXXMethod_isVirtual
+clang_CXXRecord_isAbstract
clang_EnumDecl_isScoped
clang_Cursor_getArgument
clang_Cursor_getNumTemplateArguments
OpenPOWER on IntegriCloud