libclang: add a function to check whether a member function is pure virtual

Patch by Seth Fowler.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182139 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 880a150..f2e752a 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -2590,6 +2590,10 @@
    [Index, c_char_p],
    c_object_p),
 
+  ("clang_CXXMethod_isPureVirtual",
+   [Cursor],
+   bool),
+
   ("clang_CXXMethod_isStatic",
    [Cursor],
    bool),
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index d8c37eb..21b7dba 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -4035,6 +4035,12 @@
  */
 
 /**
+ * \brief Determine if a C++ member function or member function template is
+ * pure virtual.
+ */
+CINDEX_LINKAGE unsigned clang_CXXMethod_isPureVirtual(CXCursor C);
+
+/**
  * \brief Determine if a C++ member function or member function template is 
  * declared 'static'.
  */
diff --git a/test/Index/overrides.cpp b/test/Index/overrides.cpp
index a711d82..e311699 100644
--- a/test/Index/overrides.cpp
+++ b/test/Index/overrides.cpp
@@ -17,7 +17,14 @@
 
 void C::g() {}
 
+struct E {
+  virtual void h() = 0;
+  template <typename T> void i(T);
+};
+
 // RUN: c-index-test -test-load-source local %s | FileCheck %s
 // CHECK: overrides.cpp:11:16: CXXMethod=g:11:16 (virtual) [Overrides @7:16] Extent=[11:3 - 11:19]
 // CHECK: overrides.cpp:15:16: CXXMethod=f:15:16 (virtual) [Overrides @2:16, @6:16] Extent=[15:3 - 15:22]
 // CHECK: overrides.cpp:18:9: CXXMethod=g:18:9 (Definition) (virtual) [Overrides @7:16] Extent=[18:1 - 18:15]
+// CHECK: overrides.cpp:21:16: CXXMethod=h:21:16 (virtual) (pure) Extent=[21:3 - 21:23]
+// CHECK: overrides.cpp:22:30: FunctionTemplate=i:22:30 Extent=[22:3 - 22:34]
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index e575234..a824a9f 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -694,7 +694,8 @@
       printf(" (static)");
     if (clang_CXXMethod_isVirtual(Cursor))
       printf(" (virtual)");
-
+    if (clang_CXXMethod_isPureVirtual(Cursor))
+      printf(" (pure)");
     if (clang_Cursor_isVariadic(Cursor))
       printf(" (variadic)");
     
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index db7faab..bd20800 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -6118,6 +6118,20 @@
 //===----------------------------------------------------------------------===//
 
 extern "C" {
+unsigned clang_CXXMethod_isPureVirtual(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+    return 0;
+
+  const CXXMethodDecl *Method = 0;
+  const Decl *D = cxcursor::getCursorDecl(C);
+  if (const FunctionTemplateDecl *FunTmpl =
+          dyn_cast_or_null<FunctionTemplateDecl>(D))
+    Method = dyn_cast<CXXMethodDecl>(FunTmpl->getTemplatedDecl());
+  else
+    Method = dyn_cast_or_null<CXXMethodDecl>(D);
+  return (Method && Method->isVirtual() && Method->isPure()) ? 1 : 0;
+}
+
 unsigned clang_CXXMethod_isStatic(CXCursor C) {
   if (!clang_isDeclaration(C.kind))
     return 0;
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index 0c9912e..4a134d9 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -2,6 +2,7 @@
 clang_CXCursorSet_insert
 clang_CXIndex_getGlobalOptions
 clang_CXIndex_setGlobalOptions
+clang_CXXMethod_isPureVirtual
 clang_CXXMethod_isStatic
 clang_CXXMethod_isVirtual
 clang_Cursor_getArgument