From: Douglas Gregor Date: Fri, 3 Sep 2010 23:30:36 +0000 (+0000) Subject: Synchronize code-completion cursor kinds with indexing cursor X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e8d7bebc0dd037516dd695ee1ac2eb0923753b46;p=clang 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 --- diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index c8799372ab..6c1ecbf2cc 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/include/clang/Sema/CodeCompleteConsumer.h @@ -27,6 +27,8 @@ namespace llvm { namespace clang { +class Decl; + /// \brief Default priority values for code-completion results based /// on their kind. enum { @@ -122,6 +124,10 @@ QualType getDeclUsageType(ASTContext &C, NamedDecl *ND); unsigned getMacroUsagePriority(llvm::StringRef MacroName, bool PreferredTypeIsPointer = false); +/// \brief Determine the libclang cursor kind associated with the given +/// declaration. +CXCursorKind getCursorKindForDecl(Decl *D); + class FunctionDecl; class FunctionType; class FunctionTemplateDecl; 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()) Availability = CXAvailability_Deprecated; - switch (Declaration->getKind()) { - case Decl::Record: - case Decl::CXXRecord: - case Decl::ClassTemplateSpecialization: { - RecordDecl *Record = cast(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(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(Declaration)->isDeleted()) + if (FunctionDecl *Function = dyn_cast(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(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(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; diff --git a/test/Index/code-completion.cpp b/test/Index/code-completion.cpp index 354e746166..7b0c8d75d8 100644 --- a/test/Index/code-completion.cpp +++ b/test/Index/code-completion.cpp @@ -40,18 +40,18 @@ Z::operator int() const { // CHECK-MEMBER: FieldDecl:{ResultType double}{TypedText member} // CHECK-MEMBER: FieldDecl:{ResultType int}{Text X::}{TypedText member} // CHECK-MEMBER: FieldDecl:{ResultType float}{Text Y::}{TypedText member} -// CHECK-MEMBER: FunctionDecl:{ResultType void}{Informative Y::}{TypedText memfunc}{LeftParen (}{Optional {Placeholder int i}}{RightParen )} -// CHECK-MEMBER: FunctionDecl:{ResultType int}{TypedText operator int}{LeftParen (}{RightParen )}{Informative const} -// CHECK-MEMBER: FunctionDecl:{ResultType Z &}{TypedText operator=}{LeftParen (}{Placeholder Z const &}{RightParen )} -// CHECK-MEMBER: FunctionDecl:{ResultType X &}{Text X::}{TypedText operator=}{LeftParen (}{Placeholder X const &}{RightParen )} -// CHECK-MEMBER: FunctionDecl:{ResultType Y &}{Text Y::}{TypedText operator=}{LeftParen (}{Placeholder Y const &}{RightParen )} +// CHECK-MEMBER: CXXMethod:{ResultType void}{Informative Y::}{TypedText memfunc}{LeftParen (}{Optional {Placeholder int i}}{RightParen )} +// CHECK-MEMBER: CXXConversion:{ResultType int}{TypedText operator int}{LeftParen (}{RightParen )}{Informative const} +// CHECK-MEMBER: CXXMethod:{ResultType Z &}{TypedText operator=}{LeftParen (}{Placeholder Z const &}{RightParen )} +// CHECK-MEMBER: CXXMethod:{ResultType X &}{Text X::}{TypedText operator=}{LeftParen (}{Placeholder X const &}{RightParen )} +// CHECK-MEMBER: CXXMethod:{ResultType Y &}{Text Y::}{TypedText operator=}{LeftParen (}{Placeholder Y const &}{RightParen )} // CHECK-MEMBER: EnumConstantDecl:{ResultType X::E}{Informative E::}{TypedText Val1} // CHECK-MEMBER: StructDecl:{TypedText X}{Text ::} // CHECK-MEMBER: StructDecl:{TypedText Y}{Text ::} // CHECK-MEMBER: StructDecl:{TypedText Z}{Text ::} -// CHECK-MEMBER: FunctionDecl:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} -// CHECK-MEMBER: FunctionDecl:{ResultType void}{Informative Y::}{TypedText ~Y}{LeftParen (}{RightParen )} -// CHECK-MEMBER: FunctionDecl:{ResultType void}{TypedText ~Z}{LeftParen (}{RightParen )} +// CHECK-MEMBER: CXXDestructor:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} +// CHECK-MEMBER: CXXDestructor:{ResultType void}{Informative Y::}{TypedText ~Y}{LeftParen (}{RightParen )} +// CHECK-MEMBER: CXXDestructor:{ResultType void}{TypedText ~Z}{LeftParen (}{RightParen )} // CHECK-OVERLOAD: NotImplemented:{ResultType int &}{Text overloaded}{LeftParen (}{Text Z z}{Comma , }{CurrentParameter int second}{RightParen )} // CHECK-OVERLOAD: NotImplemented:{ResultType float &}{Text overloaded}{LeftParen (}{Text int i}{Comma , }{CurrentParameter long second}{RightParen )} @@ -63,5 +63,5 @@ Z::operator int() const { // CHECK-EXPR: FieldDecl:{ResultType double}{TypedText member} (10) // CHECK-EXPR: FieldDecl:{ResultType int}{Text X::}{TypedText member} (5) // CHECK-EXPR: FieldDecl:{ResultType float}{Text Y::}{TypedText member} (11) -// CHECK-EXPR: FunctionDecl:{ResultType void}{TypedText memfunc}{LeftParen (}{Optional {Placeholder int i}}{RightParen )} (22) -// CHECK-EXPR: NotImplemented:{TypedText N}{Text ::} (75) +// CHECK-EXPR: CXXMethod:{ResultType void}{TypedText memfunc}{LeftParen (}{Optional {Placeholder int i}}{RightParen )} (22) +// CHECK-EXPR: Namespace:{TypedText N}{Text ::} (75) diff --git a/test/Index/complete-declarators.cpp b/test/Index/complete-declarators.cpp index 61d7765892..8fba4db2f9 100644 --- a/test/Index/complete-declarators.cpp +++ b/test/Index/complete-declarators.cpp @@ -16,22 +16,22 @@ struct Z { // RUN: c-index-test -code-completion-at=%s:8:5 %s | FileCheck -check-prefix=CHECK-CC1 %s // CHECK-CC1: NotImplemented:{TypedText const} (30) -// CHECK-CC1: NotImplemented:{TypedText N}{Text ::} (75) +// CHECK-CC1: Namespace:{TypedText N}{Text ::} (75) // CHECK-CC1: NotImplemented:{TypedText operator} (30) // CHECK-CC1: NotImplemented:{TypedText volatile} (30) // RUN: c-index-test -code-completion-at=%s:8:11 %s | FileCheck -check-prefix=CHECK-CC2 %s // CHECK-CC2: NotImplemented:{TypedText const} (30) -// CHECK-CC2-NOT: NotImplemented:{TypedText N}{Text ::} (75) +// CHECK-CC2-NOT: Namespace:{TypedText N}{Text ::} (75) // CHECK-CC2-NOT: NotImplemented:{TypedText operator} (30) // CHECK-CC2: NotImplemented:{TypedText volatile} (30) // RUN: c-index-test -code-completion-at=%s:13:7 %s | FileCheck -check-prefix=CHECK-CC3 %s // CHECK-CC3: NotImplemented:{TypedText const} (30) -// CHECK-CC3-NOT: NotImplemented:{TypedText N}{Text ::} (75) +// CHECK-CC3-NOT: Namespace:{TypedText N}{Text ::} (75) // CHECK-CC3: NotImplemented:{TypedText operator} (30) // CHECK-CC3: NotImplemented:{TypedText volatile} (30) // RUN: c-index-test -code-completion-at=%s:14:14 %s | FileCheck -check-prefix=CHECK-CC4 %s // CHECK-CC4: NotImplemented:{TypedText const} (30) -// CHECK-CC4: NotImplemented:{TypedText N}{Text ::} (75) +// CHECK-CC4: Namespace:{TypedText N}{Text ::} (75) // CHECK-CC4: NotImplemented:{TypedText operator} (30) // CHECK-CC4: NotImplemented:{TypedText volatile} (30) // CHECK-CC4: StructDecl:{TypedText Y} (65) diff --git a/test/Index/complete-memfunc-cvquals.cpp b/test/Index/complete-memfunc-cvquals.cpp index 6635bed6ff..4e2e8200ab 100644 --- a/test/Index/complete-memfunc-cvquals.cpp +++ b/test/Index/complete-memfunc-cvquals.cpp @@ -41,41 +41,41 @@ void Foo::bingo() volatile { // RUN: c-index-test -code-completion-at=%s:19:5 %s | FileCheck -check-prefix=CHECK-NOQUALS %s // RUN: c-index-test -code-completion-at=%s:20:7 %s | FileCheck -check-prefix=CHECK-NOQUALS %s // RUN: c-index-test -code-completion-at=%s:23:7 %s | FileCheck -check-prefix=CHECK-NOQUALS %s -// CHECK-NOQUALS: FunctionDecl:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (20) -// CHECK-NOQUALS: FunctionDecl:{ResultType void}{TypedText bar}{LeftParen (}{RightParen )} (19) -// CHECK-NOQUALS: FunctionDecl:{ResultType void}{TypedText baz}{LeftParen (}{RightParen )}{Informative const} (20) -// CHECK-NOQUALS: FunctionDecl:{ResultType void}{TypedText bingo}{LeftParen (}{RightParen )}{Informative volatile} (20) +// CHECK-NOQUALS: CXXMethod:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (20) +// CHECK-NOQUALS: CXXMethod:{ResultType void}{TypedText bar}{LeftParen (}{RightParen )} (19) +// CHECK-NOQUALS: CXXMethod:{ResultType void}{TypedText baz}{LeftParen (}{RightParen )}{Informative const} (20) +// CHECK-NOQUALS: CXXMethod:{ResultType void}{TypedText bingo}{LeftParen (}{RightParen )}{Informative volatile} (20) // RUN: c-index-test -code-completion-at=%s:21:6 %s | FileCheck -check-prefix=CHECK-CONST %s // RUN: c-index-test -code-completion-at=%s:22:8 %s | FileCheck -check-prefix=CHECK-CONST %s // RUN: c-index-test -code-completion-at=%s:24:8 %s | FileCheck -check-prefix=CHECK-CONST %s -// CHECK-CONST: FunctionDecl:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (20) +// CHECK-CONST: CXXMethod:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (20) // CHECK-CONST-NOT: bar -// CHECK-CONST: FunctionDecl:{ResultType void}{TypedText baz}{LeftParen (}{RightParen )}{Informative const} (19) +// CHECK-CONST: CXXMethod:{ResultType void}{TypedText baz}{LeftParen (}{RightParen )}{Informative const} (19) // CHECK-CONST-NOT: bingo // CHECK-CONST: theend // RUN: c-index-test -code-completion-at=%s:25:8 %s | FileCheck -check-prefix=CHECK-VOLATILE %s -// CHECK-VOLATILE: FunctionDecl:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (20) +// CHECK-VOLATILE: CXXMethod:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (20) // CHECK-VOLATILE-NOT: baz -// CHECK-VOLATILE: FunctionDecl:{ResultType void}{TypedText bingo}{LeftParen (}{RightParen )}{Informative volatile} (19) +// CHECK-VOLATILE: CXXMethod:{ResultType void}{TypedText bingo}{LeftParen (}{RightParen )}{Informative volatile} (19) // Check implicit member access expressions. // RUN: c-index-test -code-completion-at=%s:29:2 %s | FileCheck -check-prefix=CHECK-IMPLICIT-NOQUALS %s -// CHECK-IMPLICIT-NOQUALS: FunctionDecl:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (15) -// CHECK-IMPLICIT-NOQUALS: FunctionDecl:{ResultType void}{TypedText bar}{LeftParen (}{RightParen )} (14) -// CHECK-IMPLICIT-NOQUALS: FunctionDecl:{ResultType void}{TypedText baz}{LeftParen (}{RightParen )}{Informative const} (15) -// CHECK-IMPLICIT-NOQUALS: FunctionDecl:{ResultType void}{TypedText bingo}{LeftParen (}{RightParen )}{Informative volatile} (15) +// CHECK-IMPLICIT-NOQUALS: CXXMethod:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (15) +// CHECK-IMPLICIT-NOQUALS: CXXMethod:{ResultType void}{TypedText bar}{LeftParen (}{RightParen )} (14) +// CHECK-IMPLICIT-NOQUALS: CXXMethod:{ResultType void}{TypedText baz}{LeftParen (}{RightParen )}{Informative const} (15) +// CHECK-IMPLICIT-NOQUALS: CXXMethod:{ResultType void}{TypedText bingo}{LeftParen (}{RightParen )}{Informative volatile} (15) // RUN: c-index-test -code-completion-at=%s:33:1 %s | FileCheck -check-prefix=CHECK-IMPLICIT-CONST %s -// CHECK-IMPLICIT-CONST: FunctionDecl:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (15) +// CHECK-IMPLICIT-CONST: CXXMethod:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (15) // CHECK-IMPLICIT-CONST-NOT: bar -// CHECK-IMPLICIT-CONST: FunctionDecl:{ResultType void}{TypedText baz}{LeftParen (}{RightParen )}{Informative const} (14) +// CHECK-IMPLICIT-CONST: CXXMethod:{ResultType void}{TypedText baz}{LeftParen (}{RightParen )}{Informative const} (14) // CHECK-IMPLICIT-CONST-NOT: bingo // CHECK-IMPLICIT-CONST: theend // RUN: c-index-test -code-completion-at=%s:37:1 %s | FileCheck -check-prefix=CHECK-IMPLICIT-VOLATILE %s -// CHECK-IMPLICIT-VOLATILE: FunctionDecl:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (15) +// CHECK-IMPLICIT-VOLATILE: CXXMethod:{ResultType void}{TypedText babble}{LeftParen (}{RightParen )}{Informative const volatile} (15) // CHECK-IMPLICIT-VOLATILE-NOT: baz -// CHECK-IMPLICIT-VOLATILE: FunctionDecl:{ResultType void}{TypedText bingo}{LeftParen (}{RightParen )}{Informative volatile} (14) +// CHECK-IMPLICIT-VOLATILE: CXXMethod:{ResultType void}{TypedText bingo}{LeftParen (}{RightParen )}{Informative volatile} (14) // RUN: c-index-test -code-completion-at=%s:4:17 %s | FileCheck -check-prefix=CHECK-CVQUAL-AFTER %s // CHECK-CVQUAL-AFTER: NotImplemented:{TypedText const} (30) diff --git a/test/Index/complete-super.cpp b/test/Index/complete-super.cpp index a10cafc2c7..49f94e40d2 100644 --- a/test/Index/complete-super.cpp +++ b/test/Index/complete-super.cpp @@ -25,8 +25,8 @@ void B::bar(float real) { // RUN: c-index-test -code-completion-at=%s:20:3 %s | FileCheck -check-prefix=CHECK-BAR-UNQUAL %s // CHECK-BAR-UNQUAL: CXXMethod:{Text A::}{TypedText bar}{LeftParen (}{Placeholder real}{RightParen )} (8) -// CHECK-BAR-UNQUAL: FunctionDecl:{ResultType void}{TypedText bar}{LeftParen (}{Placeholder float real}{RightParen )} (14) -// CHECK-BAR-UNQUAL: FunctionDecl:{ResultType void}{Text A::}{TypedText bar}{LeftParen (}{Placeholder double x}{RightParen )} (16) +// CHECK-BAR-UNQUAL: CXXMethod:{ResultType void}{TypedText bar}{LeftParen (}{Placeholder float real}{RightParen )} (14) +// CHECK-BAR-UNQUAL: CXXMethod:{ResultType void}{Text A::}{TypedText bar}{LeftParen (}{Placeholder double x}{RightParen )} (16) // RUN: c-index-test -code-completion-at=%s:16:6 %s | FileCheck -check-prefix=CHECK-FOO-QUAL %s // CHECK-FOO-QUAL: CXXMethod:{TypedText foo}{LeftParen (}{Placeholder a}{Comma , }{Placeholder b}{RightParen )} (8) diff --git a/test/Index/complete-templates.cpp b/test/Index/complete-templates.cpp new file mode 100644 index 0000000000..2f2302d08d --- /dev/null +++ b/test/Index/complete-templates.cpp @@ -0,0 +1,19 @@ +// Tests are line- and column-sensive, so run lines are below. + +template +class X { + X(); + X(const X&); + + template X(U); +}; + +template void f(T); + +void test() { + +} + +// RUN: c-index-test -code-completion-at=%s:14:2 %s | FileCheck %s +// CHECK: FunctionTemplate:{ResultType void}{TypedText f}{LeftParen (}{Placeholder T}{RightParen )} (45) +// CHECK: ClassTemplate:{TypedText X}{LeftAngle <}{Placeholder typename T}{RightAngle >} (50) diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index ddbd14b334..a8fd049c99 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -29,70 +29,6 @@ CXCursor cxcursor::MakeCXCursorInvalid(CXCursorKind K) { return C; } -static CXCursorKind GetCursorKind(Decl *D) { - assert(D && "Invalid arguments!"); - 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(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(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; - } - - llvm_unreachable("Invalid Decl"); - return CXCursor_NotImplemented; -} - static CXCursorKind GetCursorKind(const Attr *A) { assert(A && "Invalid arguments!"); switch (A->getKind()) { @@ -113,7 +49,7 @@ CXCursor cxcursor::MakeCXCursor(const Attr *A, Decl *Parent, ASTUnit *TU) { CXCursor cxcursor::MakeCXCursor(Decl *D, ASTUnit *TU) { assert(D && TU && "Invalid arguments!"); - CXCursor C = { GetCursorKind(D), { D, 0, TU } }; + CXCursor C = { getCursorKindForDecl(D), { D, 0, TU } }; return C; }