aboutsummaryrefslogtreecommitdiff
path: root/tools/CIndex/CXCursor.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-01-16 00:36:30 +0000
committerTed Kremenek <kremenek@apple.com>2010-01-16 00:36:30 +0000
commitedc8aa68ef91aeea686c5aadf64ef902c38318dd (patch)
tree0957aa7404dccb1d4ff704ed6ec10564a094f680 /tools/CIndex/CXCursor.cpp
parent3005efeb131ccddcda9c332c83e49c32349e2aed (diff)
Migrate Decl* -> cursorkind logic into CXCursor.cpp, and drastically tighten TUVisitor.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93599 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/CIndex/CXCursor.cpp')
-rw-r--r--tools/CIndex/CXCursor.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tools/CIndex/CXCursor.cpp b/tools/CIndex/CXCursor.cpp
index 0c72e96900..00313edc45 100644
--- a/tools/CIndex/CXCursor.cpp
+++ b/tools/CIndex/CXCursor.cpp
@@ -15,6 +15,7 @@
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
+#include "llvm/Support/ErrorHandling.h"
using namespace clang;
@@ -29,6 +30,37 @@ CXCursor cxcursor::MakeCXCursor(CXCursorKind K, Decl *D, Stmt *S) {
return C;
}
+static CXCursorKind GetCursorKind(Decl *D) {
+ switch (D->getKind()) {
+ case Decl::Function:
+ return cast<FunctionDecl>(D)->isThisDeclarationADefinition()
+ ? CXCursor_FunctionDefn : CXCursor_FunctionDecl;
+ case Decl::ObjCCategory: return CXCursor_ObjCCategoryDecl;
+ case Decl::ObjCCategoryImpl: return CXCursor_ObjCCategoryDefn;
+ case Decl::ObjCImplementation: return CXCursor_ObjCClassDefn;
+ case Decl::ObjCInterface: return CXCursor_ObjCInterfaceDecl;
+ case Decl::ObjCProtocol: return CXCursor_ObjCProtocolDecl;
+ case Decl::Typedef: return CXCursor_TypedefDecl;
+ case Decl::Var: return CXCursor_VarDecl;
+ default:
+ if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
+ switch (TD->getTagKind()) {
+ case TagDecl::TK_struct: return CXCursor_StructDecl;
+ case TagDecl::TK_class: return CXCursor_ClassDecl;
+ case TagDecl::TK_union: return CXCursor_UnionDecl;
+ case TagDecl::TK_enum: return CXCursor_EnumDecl;
+ }
+ }
+ }
+
+ llvm_unreachable("Invalid Decl");
+ return CXCursor_NotImplemented;
+}
+
+CXCursor cxcursor::MakeCXCursor(Decl *D) {
+ return MakeCXCursor(GetCursorKind(D), D);
+}
+
Decl *cxcursor::getCursorDecl(CXCursor Cursor) {
return (Decl *)Cursor.data[0];
}