diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-09-03 23:30:36 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-09-03 23:30:36 +0000 |
commit | e8d7bebc0dd037516dd695ee1ac2eb0923753b46 (patch) | |
tree | 9e1129df37bbdafe6ce6e8c3f73e9ea0fac343da /lib | |
parent | 469a20de757ff872c90ff6b1134f6346909ff652 (diff) |
Synchronize code-completion cursor kinds with indexing cursor
kinds. How shameful that this code was duplicated!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113033 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/CodeCompleteConsumer.cpp | 92 | ||||
-rw-r--r-- | lib/Sema/SemaCodeComplete.cpp | 63 |
2 files changed, 68 insertions, 87 deletions
diff --git a/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index 1f6d3e75e2..58a1627b47 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/lib/Sema/CodeCompleteConsumer.cpp @@ -510,95 +510,13 @@ void CodeCompletionResult::computeCursorKindAndAvailability() { else if (Declaration->getAttr<DeprecatedAttr>()) Availability = CXAvailability_Deprecated; - switch (Declaration->getKind()) { - case Decl::Record: - case Decl::CXXRecord: - case Decl::ClassTemplateSpecialization: { - RecordDecl *Record = cast<RecordDecl>(Declaration); - if (Record->isStruct()) - CursorKind = CXCursor_StructDecl; - else if (Record->isUnion()) - CursorKind = CXCursor_UnionDecl; - else - CursorKind = CXCursor_ClassDecl; - break; - } - - case Decl::ObjCMethod: { - ObjCMethodDecl *Method = cast<ObjCMethodDecl>(Declaration); - if (Method->isInstanceMethod()) - CursorKind = CXCursor_ObjCInstanceMethodDecl; - else - CursorKind = CXCursor_ObjCClassMethodDecl; - break; - } - - case Decl::Typedef: - CursorKind = CXCursor_TypedefDecl; - break; - - case Decl::Enum: - CursorKind = CXCursor_EnumDecl; - break; - - case Decl::Field: - CursorKind = CXCursor_FieldDecl; - break; - - case Decl::EnumConstant: - CursorKind = CXCursor_EnumConstantDecl; - break; - - case Decl::Function: - case Decl::CXXMethod: - case Decl::CXXConstructor: - case Decl::CXXDestructor: - case Decl::CXXConversion: - CursorKind = CXCursor_FunctionDecl; - if (cast<FunctionDecl>(Declaration)->isDeleted()) + if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Declaration)) + if (Function->isDeleted()) Availability = CXAvailability_NotAvailable; - break; - - case Decl::Var: - CursorKind = CXCursor_VarDecl; - break; - - case Decl::ParmVar: - CursorKind = CXCursor_ParmDecl; - break; - - case Decl::ObjCInterface: - CursorKind = CXCursor_ObjCInterfaceDecl; - break; - - case Decl::ObjCCategory: - CursorKind = CXCursor_ObjCCategoryDecl; - break; - - case Decl::ObjCProtocol: - CursorKind = CXCursor_ObjCProtocolDecl; - break; - - case Decl::ObjCProperty: - CursorKind = CXCursor_ObjCPropertyDecl; - break; - - case Decl::ObjCIvar: - CursorKind = CXCursor_ObjCIvarDecl; - break; - - case Decl::ObjCImplementation: - CursorKind = CXCursor_ObjCImplementationDecl; - break; - - case Decl::ObjCCategoryImpl: - CursorKind = CXCursor_ObjCCategoryImplDecl; - break; - - default: + + CursorKind = getCursorKindForDecl(Declaration); + if (CursorKind == CXCursor_UnexposedDecl) CursorKind = CXCursor_NotImplemented; - break; - } break; case RK_Macro: diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 7088e55304..f00d1cd20f 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -2317,6 +2317,69 @@ unsigned clang::getMacroUsagePriority(llvm::StringRef MacroName, return Priority; } +CXCursorKind clang::getCursorKindForDecl(Decl *D) { + if (!D) + return CXCursor_UnexposedDecl; + + switch (D->getKind()) { + case Decl::Enum: return CXCursor_EnumDecl; + case Decl::EnumConstant: return CXCursor_EnumConstantDecl; + case Decl::Field: return CXCursor_FieldDecl; + case Decl::Function: + return CXCursor_FunctionDecl; + case Decl::ObjCCategory: return CXCursor_ObjCCategoryDecl; + case Decl::ObjCCategoryImpl: return CXCursor_ObjCCategoryImplDecl; + case Decl::ObjCClass: + // FIXME + return CXCursor_UnexposedDecl; + case Decl::ObjCForwardProtocol: + // FIXME + return CXCursor_UnexposedDecl; + case Decl::ObjCImplementation: return CXCursor_ObjCImplementationDecl; + case Decl::ObjCInterface: return CXCursor_ObjCInterfaceDecl; + case Decl::ObjCIvar: return CXCursor_ObjCIvarDecl; + case Decl::ObjCMethod: + return cast<ObjCMethodDecl>(D)->isInstanceMethod() + ? CXCursor_ObjCInstanceMethodDecl : CXCursor_ObjCClassMethodDecl; + case Decl::CXXMethod: return CXCursor_CXXMethod; + case Decl::CXXConstructor: return CXCursor_Constructor; + case Decl::CXXDestructor: return CXCursor_Destructor; + case Decl::CXXConversion: return CXCursor_ConversionFunction; + case Decl::ObjCProperty: return CXCursor_ObjCPropertyDecl; + case Decl::ObjCProtocol: return CXCursor_ObjCProtocolDecl; + case Decl::ParmVar: return CXCursor_ParmDecl; + case Decl::Typedef: return CXCursor_TypedefDecl; + case Decl::Var: return CXCursor_VarDecl; + case Decl::Namespace: return CXCursor_Namespace; + case Decl::NamespaceAlias: return CXCursor_NamespaceAlias; + case Decl::TemplateTypeParm: return CXCursor_TemplateTypeParameter; + case Decl::NonTypeTemplateParm:return CXCursor_NonTypeTemplateParameter; + case Decl::TemplateTemplateParm:return CXCursor_TemplateTemplateParameter; + case Decl::FunctionTemplate: return CXCursor_FunctionTemplate; + case Decl::ClassTemplate: return CXCursor_ClassTemplate; + case Decl::ClassTemplatePartialSpecialization: + return CXCursor_ClassTemplatePartialSpecialization; + case Decl::UsingDirective: return CXCursor_UsingDirective; + + case Decl::Using: + case Decl::UnresolvedUsingValue: + case Decl::UnresolvedUsingTypename: + return CXCursor_UsingDeclaration; + + default: + if (TagDecl *TD = dyn_cast<TagDecl>(D)) { + switch (TD->getTagKind()) { + case TTK_Struct: return CXCursor_StructDecl; + case TTK_Class: return CXCursor_ClassDecl; + case TTK_Union: return CXCursor_UnionDecl; + case TTK_Enum: return CXCursor_EnumDecl; + } + } + } + + return CXCursor_UnexposedDecl; +} + static void AddMacroResults(Preprocessor &PP, ResultBuilder &Results, bool TargetTypeIsPointer = false) { typedef CodeCompletionResult Result; |