From: Ilya Biryukov Date: Fri, 22 Sep 2017 19:07:37 +0000 (+0000) Subject: Set completion priority of destructors and operators to CCP_Unlikely. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cdbc9913b93325c6737764734bc5ac92207bafa;p=clang Set completion priority of destructors and operators to CCP_Unlikely. Summary: It will move destructors and operators to the end of completion list. Destructors and operators are currently very high on the completion list, as they have the same priority as member functions. However, they are clearly not something users usually choose in completion lists. Reviewers: arphaman, erikjv, bkramer, krasimir Reviewed By: arphaman Subscribers: eraman, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D38081 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314019 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 7001849426..d3138a9650 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -10,7 +10,7 @@ // This file defines the code-completion semantic actions. // //===----------------------------------------------------------------------===// -#include "clang/Sema/SemaInternal.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" @@ -23,6 +23,7 @@ #include "clang/Sema/Overload.h" #include "clang/Sema/Scope.h" #include "clang/Sema/ScopeInfo.h" +#include "clang/Sema/SemaInternal.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallBitVector.h" #include "llvm/ADT/SmallPtrSet.h" @@ -741,8 +742,18 @@ unsigned ResultBuilder::getBasePriority(const NamedDecl *ND) { } const DeclContext *DC = ND->getDeclContext()->getRedeclContext(); - if (DC->isRecord() || isa(DC)) + if (DC->isRecord() || isa(DC)) { + // Explicit destructor calls are very rare. + if (isa(ND)) + return CCP_Unlikely; + // Explicit operator and conversion function calls are also very rare. + auto DeclNameKind = ND->getDeclName().getNameKind(); + if (DeclNameKind == DeclarationName::CXXOperatorName || + DeclNameKind == DeclarationName::CXXLiteralOperatorName || + DeclNameKind == DeclarationName::CXXConversionFunctionName) + return CCP_Unlikely; return CCP_MemberDeclaration; + } // Content-based decisions. if (isa(ND)) diff --git a/test/Index/complete-access-checks.cpp b/test/Index/complete-access-checks.cpp index c77a5d656a..7eec41ec56 100644 --- a/test/Index/complete-access-checks.cpp +++ b/test/Index/complete-access-checks.cpp @@ -41,12 +41,12 @@ void Y::doSomething() { // CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member1} (37) // CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member2} (37) (inaccessible) // CHECK-SUPER-ACCESS: FieldDecl:{ResultType int}{Informative X::}{TypedText member3} (37) (inaccessible) -// CHECK-SUPER-ACCESS: CXXMethod:{ResultType Y &}{TypedText operator=}{LeftParen (}{Placeholder const Y &}{RightParen )} (34) -// CHECK-SUPER-ACCESS: CXXMethod:{ResultType X &}{Text X::}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (36) +// CHECK-SUPER-ACCESS: CXXMethod:{ResultType Y &}{TypedText operator=}{LeftParen (}{Placeholder const Y &}{RightParen )} (79) +// CHECK-SUPER-ACCESS: CXXMethod:{ResultType X &}{Text X::}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (81) // CHECK-SUPER-ACCESS: StructDecl:{TypedText X}{Text ::} (77) // CHECK-SUPER-ACCESS: StructDecl:{TypedText Y}{Text ::} (75) -// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} (36) -// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Y}{LeftParen (}{RightParen )} (34) +// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{Informative X::}{TypedText ~X}{LeftParen (}{RightParen )} (81) +// CHECK-SUPER-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Y}{LeftParen (}{RightParen )} (79) // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func1}{LeftParen (}{RightParen )} (34) // CHECK-ACCESS: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (34) (inaccessible) @@ -54,9 +54,9 @@ void Y::doSomething() { // CHECK-ACCESS: FieldDecl:{ResultType int}{TypedText member1} (35) // CHECK-ACCESS: FieldDecl:{ResultType int}{TypedText member2} (35) (inaccessible) // CHECK-ACCESS: FieldDecl:{ResultType int}{TypedText member3} (35) (inaccessible) -// CHECK-ACCESS: CXXMethod:{ResultType Z &}{TypedText operator=}{LeftParen (}{Placeholder const Z &}{RightParen )} (34) +// CHECK-ACCESS: CXXMethod:{ResultType Z &}{TypedText operator=}{LeftParen (}{Placeholder const Z &}{RightParen )} (79) // CHECK-ACCESS: ClassDecl:{TypedText Z}{Text ::} (75) -// CHECK-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Z}{LeftParen (}{RightParen )} (34) +// CHECK-ACCESS: CXXDestructor:{ResultType void}{TypedText ~Z}{LeftParen (}{RightParen )} (79) class P { protected: @@ -76,14 +76,14 @@ void f(P x, Q y) { } // CHECK-USING-INACCESSIBLE: FieldDecl:{ResultType int}{TypedText member} (35) (inaccessible) -// CHECK-USING-INACCESSIBLE: CXXMethod:{ResultType P &}{TypedText operator=}{LeftParen (}{Placeholder const P &}{RightParen )} (34) +// CHECK-USING-INACCESSIBLE: CXXMethod:{ResultType P &}{TypedText operator=}{LeftParen (}{Placeholder const P &}{RightParen )} (79) // CHECK-USING-INACCESSIBLE: ClassDecl:{TypedText P}{Text ::} (75) -// CHECK-USING-INACCESSIBLE: CXXDestructor:{ResultType void}{TypedText ~P}{LeftParen (}{RightParen )} (34) +// CHECK-USING-INACCESSIBLE: CXXDestructor:{ResultType void}{TypedText ~P}{LeftParen (}{RightParen )} (79) // CHECK-USING-ACCESSIBLE: FieldDecl:{ResultType int}{TypedText member} (35) -// CHECK-USING-ACCESSIBLE: CXXMethod:{ResultType Q &}{TypedText operator=}{LeftParen (}{Placeholder const Q &}{RightParen )} (34) -// CHECK-USING-ACCESSIBLE: CXXMethod:{ResultType P &}{Text P::}{TypedText operator=}{LeftParen (}{Placeholder const P &}{RightParen )} (36) +// CHECK-USING-ACCESSIBLE: CXXMethod:{ResultType Q &}{TypedText operator=}{LeftParen (}{Placeholder const Q &}{RightParen )} (79) +// CHECK-USING-ACCESSIBLE: CXXMethod:{ResultType P &}{Text P::}{TypedText operator=}{LeftParen (}{Placeholder const P &}{RightParen )} (81) // CHECK-USING-ACCESSIBLE: ClassDecl:{TypedText P}{Text ::} (77) // CHECK-USING-ACCESSIBLE: ClassDecl:{TypedText Q}{Text ::} (75) -// CHECK-USING-ACCESSIBLE: CXXDestructor:{ResultType void}{Informative P::}{TypedText ~P}{LeftParen (}{RightParen )} (36) -// CHECK-USING-ACCESSIBLE: CXXDestructor:{ResultType void}{TypedText ~Q}{LeftParen (}{RightParen )} (34) +// CHECK-USING-ACCESSIBLE: CXXDestructor:{ResultType void}{Informative P::}{TypedText ~P}{LeftParen (}{RightParen )} (81) +// CHECK-USING-ACCESSIBLE: CXXDestructor:{ResultType void}{TypedText ~Q}{LeftParen (}{RightParen )} (79) diff --git a/test/Index/complete-cxx-inline-methods.cpp b/test/Index/complete-cxx-inline-methods.cpp index ee359f75e4..c0a4a8d75c 100644 --- a/test/Index/complete-cxx-inline-methods.cpp +++ b/test/Index/complete-cxx-inline-methods.cpp @@ -25,11 +25,11 @@ private: // RUN: c-index-test -code-completion-at=%s:4:9 -std=c++98 %s | FileCheck %s // RUN: c-index-test -code-completion-at=%s:13:7 -std=c++98 %s | FileCheck %s -// CHECK: CXXMethod:{ResultType MyCls::Vec &}{TypedText operator=}{LeftParen (}{Placeholder const MyCls::Vec &}{RightParen )} (34) +// CHECK: CXXMethod:{ResultType MyCls::Vec &}{TypedText operator=}{LeftParen (}{Placeholder const MyCls::Vec &}{RightParen )} (79) // CHECK-NEXT: StructDecl:{TypedText Vec}{Text ::} (75) // CHECK-NEXT: FieldDecl:{ResultType int}{TypedText x} (35) // CHECK-NEXT: FieldDecl:{ResultType int}{TypedText y} (35) -// CHECK-NEXT: CXXDestructor:{ResultType void}{TypedText ~Vec}{LeftParen (}{RightParen )} (34) +// CHECK-NEXT: CXXDestructor:{ResultType void}{TypedText ~Vec}{LeftParen (}{RightParen )} (79) // CHECK-NEXT: Completion contexts: // CHECK-NEXT: Dot member access // CHECK-NEXT: Container Kind: StructDecl diff --git a/test/Index/complete-qualified.cpp b/test/Index/complete-qualified.cpp index a17ea25370..11abd53b86 100644 --- a/test/Index/complete-qualified.cpp +++ b/test/Index/complete-qualified.cpp @@ -17,4 +17,4 @@ void foo() // CHECK-CC1: FieldDecl:{ResultType C}{TypedText c} (35) // CHECK-CC1: ClassDecl:{TypedText Foo} (35) // CHECK-CC1: CXXMethod:{ResultType Foo &}{TypedText operator=}{LeftParen (}{Placeholder const Foo &}{RightParen )} -// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo}{LeftParen (}{RightParen )} (35) +// CHECK-CC1: CXXDestructor:{ResultType void}{TypedText ~Foo}{LeftParen (}{RightParen )} (80) diff --git a/test/Index/complete-with-annotations.cpp b/test/Index/complete-with-annotations.cpp index afa8d9ed66..7bad8f1b7c 100644 --- a/test/Index/complete-with-annotations.cpp +++ b/test/Index/complete-with-annotations.cpp @@ -17,7 +17,7 @@ void X::doSomething() { // CHECK: FieldDecl:{ResultType int}{TypedText field} (35) ("three", "two", "one") // CHECK: CXXMethod:{ResultType void}{TypedText func2}{LeftParen (}{RightParen )} (34) ("some annotation") // CHECK: FieldDecl:{ResultType int}{TypedText member2} (35) ("another annotation", "some annotation") -// CHECK: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (34) +// CHECK: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (79) // CHECK: ClassDecl:{TypedText X}{Text ::} (75) -// CHECK: CXXDestructor:{ResultType void}{TypedText ~X}{LeftParen (}{RightParen )} (34) +// CHECK: CXXDestructor:{ResultType void}{TypedText ~X}{LeftParen (}{RightParen )} (79)