[cfe-commits] r112655 - in /cfe/trunk: include/clang-c/Index.h tools/libclang/CIndex.cpp tools/libclang/CIndexCXX.cpp tools/libclang/libclang.darwin.exports tools/libclang/libclang.exports

Douglas Gregor dgregor at apple.com
Tue Aug 31 15:12:17 PDT 2010


Author: dgregor
Date: Tue Aug 31 17:12:17 2010
New Revision: 112655

URL: http://llvm.org/viewvc/llvm-project?rev=112655&view=rev
Log:
Add a new libclang function clang_getTemplateCursorKind(), which
determines the kind of declaration that would be generated if the
given template were instantiated. This allows a client to distinguish
among class/struct/union templates and function/member function/static
member function templates.

Also, teach clang_CXXMethod_isStatic() about function templates.

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/tools/libclang/CIndex.cpp
    cfe/trunk/tools/libclang/CIndexCXX.cpp
    cfe/trunk/tools/libclang/libclang.darwin.exports
    cfe/trunk/tools/libclang/libclang.exports

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=112655&r1=112654&r2=112655&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Tue Aug 31 17:12:17 2010
@@ -1716,11 +1716,31 @@
  */
 
 /**
- * \brief Determine if a C++ member function is declared 'static'.
+ * \brief Determine if a C++ member function or member function template is 
+ * declared 'static'.
  */
 CINDEX_LINKAGE unsigned clang_CXXMethod_isStatic(CXCursor C);
 
 /**
+ * \brief Given a cursor that represents a template, determine
+ * the cursor kind of the specializations would be generated by instantiating
+ * the template.
+ *
+ * This routine can be used to determine what flavor of function template,
+ * class template, or class template partial specialization is stored in the
+ * cursor. For example, it can describe whether a class template cursor is
+ * declared with "struct", "class" or "union".
+ *
+ * \param C The cursor to query. This cursor should represent a template
+ * declaration.
+ *
+ * \returns The cursor kind of the specializations that would be generated
+ * by instantiating the template \p C. If \p C is not a template, returns
+ * \c CXCursor_NoDeclFound.
+ */
+CINDEX_LINKAGE enum CXCursorKind clang_getTemplateCursorKind(CXCursor C);
+  
+/**
  * @}
  */
 

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=112655&r1=112654&r2=112655&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Aug 31 17:12:17 2010
@@ -3322,8 +3322,14 @@
 unsigned clang_CXXMethod_isStatic(CXCursor C) {
   if (!clang_isDeclaration(C.kind))
     return 0;
-  CXXMethodDecl *D = dyn_cast<CXXMethodDecl>(cxcursor::getCursorDecl(C));
-  return (D && D->isStatic()) ? 1 : 0;
+  
+  CXXMethodDecl *Method = 0;
+  Decl *D = cxcursor::getCursorDecl(C);
+  if (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->isStatic()) ? 1 : 0;
 }
 
 } // end: extern "C"

Modified: cfe/trunk/tools/libclang/CIndexCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexCXX.cpp?rev=112655&r1=112654&r2=112655&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndexCXX.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexCXX.cpp Tue Aug 31 17:12:17 2010
@@ -15,6 +15,7 @@
 #include "CXCursor.h"
 #include "CXType.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclTemplate.h"
 
 using namespace clang;
 using namespace clang::cxstring;
@@ -45,4 +46,36 @@
   return CX_CXXInvalidAccessSpecifier;
 }
 
+enum CXCursorKind clang_getTemplateCursorKind(CXCursor C) {
+  using namespace clang::cxcursor;
+  
+  switch (C.kind) {
+  case CXCursor_ClassTemplate: 
+  case CXCursor_FunctionTemplate:
+    if (TemplateDecl *Template
+                           = dyn_cast_or_null<TemplateDecl>(getCursorDecl(C)))
+      return MakeCXCursor(Template->getTemplatedDecl(), 
+                          getCursorASTUnit(C)).kind;
+    break;
+      
+  case CXCursor_ClassTemplatePartialSpecialization:
+    if (ClassTemplateSpecializationDecl *PartialSpec
+          = dyn_cast_or_null<ClassTemplatePartialSpecializationDecl>(
+                                                            getCursorDecl(C))) {
+      switch (PartialSpec->getTagKind()) {
+      case TTK_Class: return CXCursor_ClassDecl;
+      case TTK_Struct: return CXCursor_StructDecl;
+      case TTK_Union: return CXCursor_UnionDecl;
+      case TTK_Enum: return CXCursor_NoDeclFound;
+      }
+    }
+    break;
+      
+  default:
+    break;
+  }
+  
+  return CXCursor_NoDeclFound;
+}
+
 } // end extern "C"

Modified: cfe/trunk/tools/libclang/libclang.darwin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.darwin.exports?rev=112655&r1=112654&r2=112655&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.darwin.exports (original)
+++ cfe/trunk/tools/libclang/libclang.darwin.exports Tue Aug 31 17:12:17 2010
@@ -78,6 +78,7 @@
 _clang_getRangeEnd
 _clang_getRangeStart
 _clang_getResultType
+_clang_getTemplateCursorKind
 _clang_getTokenExtent
 _clang_getTokenKind
 _clang_getTokenLocation

Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=112655&r1=112654&r2=112655&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Tue Aug 31 17:12:17 2010
@@ -78,6 +78,7 @@
 clang_getRangeEnd
 clang_getRangeStart
 clang_getResultType
+clang_getTemplateCursorKind
 clang_getTokenExtent
 clang_getTokenKind
 clang_getTokenLocation





More information about the cfe-commits mailing list