Commit 09c0eb15 authored by Douglas Gregor's avatar Douglas Gregor
Browse files

Synchronize code-completion cursor kinds with indexing cursor

kinds. How shameful that this code was duplicated!

llvm-svn: 113033
parent e41e5899
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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;
+5 −87
Original line number Diff line number Diff line
@@ -510,96 +510,14 @@ 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:
    Availability = CXAvailability_Available;      
+63 −0
Original line number Diff line number Diff line
@@ -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;
+10 −10
Original line number Diff line number Diff line
@@ -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)
+4 −4
Original line number Diff line number Diff line
@@ -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)
Loading