Ted Kremenek | 585b318 | 2010-08-27 21:57:20 +0000 | [diff] [blame] | 1 | //===- CIndexCXX.cpp - Clang-C Source Indexing Library --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the libclang support for C++ cursors. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CIndexer.h" |
| 15 | #include "CXCursor.h" |
| 16 | #include "CXType.h" |
| 17 | #include "clang/AST/DeclCXX.h" |
Douglas Gregor | 49f6f54 | 2010-08-31 22:12:17 +0000 | [diff] [blame^] | 18 | #include "clang/AST/DeclTemplate.h" |
Ted Kremenek | 585b318 | 2010-08-27 21:57:20 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace clang; |
| 21 | using namespace clang::cxstring; |
| 22 | |
| 23 | extern "C" { |
| 24 | |
| 25 | unsigned clang_isVirtualBase(CXCursor C) { |
| 26 | if (C.kind != CXCursor_CXXBaseSpecifier) |
| 27 | return 0; |
| 28 | |
| 29 | CXXBaseSpecifier *B = cxcursor::getCursorCXXBaseSpecifier(C); |
| 30 | return B->isVirtual(); |
| 31 | } |
| 32 | |
| 33 | enum CX_CXXAccessSpecifier clang_getCXXAccessSpecifier(CXCursor C) { |
| 34 | if (C.kind != CXCursor_CXXBaseSpecifier) |
| 35 | return CX_CXXInvalidAccessSpecifier; |
| 36 | |
| 37 | CXXBaseSpecifier *B = cxcursor::getCursorCXXBaseSpecifier(C); |
| 38 | switch (B->getAccessSpecifier()) { |
| 39 | case AS_public: return CX_CXXPublic; |
| 40 | case AS_protected: return CX_CXXProtected; |
| 41 | case AS_private: return CX_CXXPrivate; |
| 42 | case AS_none: return CX_CXXInvalidAccessSpecifier; |
| 43 | } |
| 44 | |
| 45 | // FIXME: Clang currently thinks this is reachable. |
| 46 | return CX_CXXInvalidAccessSpecifier; |
| 47 | } |
| 48 | |
Douglas Gregor | 49f6f54 | 2010-08-31 22:12:17 +0000 | [diff] [blame^] | 49 | enum CXCursorKind clang_getTemplateCursorKind(CXCursor C) { |
| 50 | using namespace clang::cxcursor; |
| 51 | |
| 52 | switch (C.kind) { |
| 53 | case CXCursor_ClassTemplate: |
| 54 | case CXCursor_FunctionTemplate: |
| 55 | if (TemplateDecl *Template |
| 56 | = dyn_cast_or_null<TemplateDecl>(getCursorDecl(C))) |
| 57 | return MakeCXCursor(Template->getTemplatedDecl(), |
| 58 | getCursorASTUnit(C)).kind; |
| 59 | break; |
| 60 | |
| 61 | case CXCursor_ClassTemplatePartialSpecialization: |
| 62 | if (ClassTemplateSpecializationDecl *PartialSpec |
| 63 | = dyn_cast_or_null<ClassTemplatePartialSpecializationDecl>( |
| 64 | getCursorDecl(C))) { |
| 65 | switch (PartialSpec->getTagKind()) { |
| 66 | case TTK_Class: return CXCursor_ClassDecl; |
| 67 | case TTK_Struct: return CXCursor_StructDecl; |
| 68 | case TTK_Union: return CXCursor_UnionDecl; |
| 69 | case TTK_Enum: return CXCursor_NoDeclFound; |
| 70 | } |
| 71 | } |
| 72 | break; |
| 73 | |
| 74 | default: |
| 75 | break; |
| 76 | } |
| 77 | |
| 78 | return CXCursor_NoDeclFound; |
| 79 | } |
| 80 | |
Ted Kremenek | 585b318 | 2010-08-27 21:57:20 +0000 | [diff] [blame] | 81 | } // end extern "C" |