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

Dmitri Gribenko gribozavr at gmail.com
Fri May 17 11:38:35 PDT 2013


Author: gribozavr
Date: Fri May 17 13:38:35 2013
New Revision: 182139

URL: http://llvm.org/viewvc/llvm-project?rev=182139&view=rev
Log:
libclang: add a function to check whether a member function is pure virtual

Patch by Seth Fowler.

Modified:
    cfe/trunk/bindings/python/clang/cindex.py
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/test/Index/overrides.cpp
    cfe/trunk/tools/c-index-test/c-index-test.c
    cfe/trunk/tools/libclang/CIndex.cpp
    cfe/trunk/tools/libclang/libclang.exports

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=182139&r1=182138&r2=182139&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Fri May 17 13:38:35 2013
@@ -2590,6 +2590,10 @@ functionList = [
    [Index, c_char_p],
    c_object_p),
 
+  ("clang_CXXMethod_isPureVirtual",
+   [Cursor],
+   bool),
+
   ("clang_CXXMethod_isStatic",
    [Cursor],
    bool),

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=182139&r1=182138&r2=182139&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Fri May 17 13:38:35 2013
@@ -4035,6 +4035,12 @@ CINDEX_LINKAGE CXString clang_FullCommen
  */
 
 /**
+ * \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'.
  */

Modified: cfe/trunk/test/Index/overrides.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/overrides.cpp?rev=182139&r1=182138&r2=182139&view=diff
==============================================================================
--- cfe/trunk/test/Index/overrides.cpp (original)
+++ cfe/trunk/test/Index/overrides.cpp Fri May 17 13:38:35 2013
@@ -17,7 +17,14 @@ struct D : C {
 
 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]

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=182139&r1=182138&r2=182139&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Fri May 17 13:38:35 2013
@@ -694,7 +694,8 @@ static void PrintCursor(CXCursor Cursor,
       printf(" (static)");
     if (clang_CXXMethod_isVirtual(Cursor))
       printf(" (virtual)");
-
+    if (clang_CXXMethod_isPureVirtual(Cursor))
+      printf(" (pure)");
     if (clang_Cursor_isVariadic(Cursor))
       printf(" (variadic)");
     

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=182139&r1=182138&r2=182139&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Fri May 17 13:38:35 2013
@@ -6118,6 +6118,20 @@ CXFile clang_Module_getTopLevelHeader(CX
 //===----------------------------------------------------------------------===//
 
 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;

Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=182139&r1=182138&r2=182139&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Fri May 17 13:38:35 2013
@@ -2,6 +2,7 @@ clang_CXCursorSet_contains
 clang_CXCursorSet_insert
 clang_CXIndex_getGlobalOptions
 clang_CXIndex_setGlobalOptions
+clang_CXXMethod_isPureVirtual
 clang_CXXMethod_isStatic
 clang_CXXMethod_isVirtual
 clang_Cursor_getArgument





More information about the cfe-commits mailing list