diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-08-31 22:12:17 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-08-31 22:12:17 +0000 |
commit | f11309e1943782d323f195c06824a486982e3340 (patch) | |
tree | a9abcb75471da769bbf5469ffbf292db9304bb4f /clang/tools | |
parent | d657d8259778129bd43393a2d65c4eb029e9eb82 (diff) | |
download | bcm5719-llvm-f11309e1943782d323f195c06824a486982e3340.tar.gz bcm5719-llvm-f11309e1943782d323f195c06824a486982e3340.zip |
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.
llvm-svn: 112655
Diffstat (limited to 'clang/tools')
-rw-r--r-- | clang/tools/libclang/CIndex.cpp | 10 | ||||
-rw-r--r-- | clang/tools/libclang/CIndexCXX.cpp | 33 | ||||
-rw-r--r-- | clang/tools/libclang/libclang.darwin.exports | 1 | ||||
-rw-r--r-- | clang/tools/libclang/libclang.exports | 1 |
4 files changed, 43 insertions, 2 deletions
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 1515ed3c2c6..2a7e6e9b065 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -3322,8 +3322,14 @@ extern "C" { 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" diff --git a/clang/tools/libclang/CIndexCXX.cpp b/clang/tools/libclang/CIndexCXX.cpp index a168f160451..ee83f98722f 100644 --- a/clang/tools/libclang/CIndexCXX.cpp +++ b/clang/tools/libclang/CIndexCXX.cpp @@ -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 @@ enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor C) { 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" diff --git a/clang/tools/libclang/libclang.darwin.exports b/clang/tools/libclang/libclang.darwin.exports index 0d01dd9b288..289026510f7 100644 --- a/clang/tools/libclang/libclang.darwin.exports +++ b/clang/tools/libclang/libclang.darwin.exports @@ -78,6 +78,7 @@ _clang_getRange _clang_getRangeEnd _clang_getRangeStart _clang_getResultType +_clang_getTemplateCursorKind _clang_getTokenExtent _clang_getTokenKind _clang_getTokenLocation diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports index 60d335299ec..254ba98a73b 100644 --- a/clang/tools/libclang/libclang.exports +++ b/clang/tools/libclang/libclang.exports @@ -78,6 +78,7 @@ clang_getRange clang_getRangeEnd clang_getRangeStart clang_getResultType +clang_getTemplateCursorKind clang_getTokenExtent clang_getTokenKind clang_getTokenLocation |