diff options
author | Alex Lorenz <arphaman@gmail.com> | 2017-12-14 22:01:50 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2017-12-14 22:01:50 +0000 |
commit | 2e8732d1c668d518d3799a141051f7b8db0b5f74 (patch) | |
tree | 84e038b616b7d0485dbd1967ca072a7c2d2018e1 /tools | |
parent | d32e8534a612dedd328b5c4546123211c97ee265 (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 'tools')
-rw-r--r-- | tools/c-index-test/c-index-test.c | 2 | ||||
-rw-r--r-- | tools/libclang/CIndex.cpp | 11 | ||||
-rw-r--r-- | tools/libclang/libclang.exports | 1 |
3 files changed, 14 insertions, 0 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 91afbe219a..99f05669b6 100644 --- a/tools/c-index-test/c-index-test.c +++ b/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/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 656df9b09b..f4d347108c 100644 --- a/tools/libclang/CIndex.cpp +++ b/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/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index bd262ee1a0..4d3a029567 100644 --- a/tools/libclang/libclang.exports +++ b/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 |