Author: ibiryukov Date: Wed Nov 7 02:02:31 2018 New Revision: 346301 URL: http://llvm.org/viewvc/llvm-project?rev=346301&view=rev Log: [CodeComplete] Do not complete self-initializations
Summary: Removes references to initialized variable from the following completions: int x = ^; Handles only the trivial cases where the variable name is completed immediately at the start of initializer or assignment, more complicated cases aren't covered, e.g. these completions still contain 'x': // More complicated expressions. int x = foo(^); int x = 10 + ^; // Other kinds of initialization. int x{^}; int x(^); // Constructor initializers. struct Foo { Foo() : x(^) {} int x; }; We should address those in the future, but they are outside of the scope of this initial change. Reviewers: sammccall Reviewed By: sammccall Subscribers: arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D54156 Added: cfe/trunk/test/CodeCompletion/self-inits.cpp Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp cfe/trunk/test/CodeCompletion/ordinary-name.cpp cfe/trunk/test/Index/complete-type-factors.m Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=346301&r1=346300&r2=346301&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original) +++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Nov 7 02:02:31 2018 @@ -4747,7 +4747,12 @@ void Sema::CodeCompleteInitializer(Scope return; } - CodeCompleteExpression(S, VD->getType()); + CodeCompleteExpressionData Data; + Data.PreferredType = VD->getType(); + // Ignore VD to avoid completing the variable itself, e.g. in 'int foo = ^'. + Data.IgnoreDecls.push_back(VD); + + CodeCompleteExpression(S, Data); } void Sema::CodeCompleteReturn(Scope *S) { Modified: cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp?rev=346301&r1=346300&r2=346301&view=diff ============================================================================== --- cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp (original) +++ cfe/trunk/test/CodeCompletion/ordinary-name-cxx11.cpp Wed Nov 7 02:02:31 2018 @@ -197,7 +197,6 @@ void foo() { // CHECK-CC4-NEXT: COMPLETION: volatile // CHECK-CC4-NEXT: COMPLETION: wchar_t // CHECK-CC4-NEXT: COMPLETION: X : X - // CHECK-CC4-NEXT: COMPLETION: y : [#int#]y // CHECK-CC4-NEXT: COMPLETION: z : [#void#]z(<#int#>) // RUN: %clang_cc1 -fsyntax-only -fno-rtti -code-completion-patterns -code-completion-at=%s:6:14 -std=gnu++11 %s -o - | FileCheck -check-prefix=CHECK-NO-RTTI %s Modified: cfe/trunk/test/CodeCompletion/ordinary-name.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/ordinary-name.cpp?rev=346301&r1=346300&r2=346301&view=diff ============================================================================== --- cfe/trunk/test/CodeCompletion/ordinary-name.cpp (original) +++ cfe/trunk/test/CodeCompletion/ordinary-name.cpp Wed Nov 7 02:02:31 2018 @@ -171,7 +171,6 @@ void foo() { // CHECK-CC4-NEXT: COMPLETION: volatile // CHECK-CC4-NEXT: COMPLETION: wchar_t // CHECK-CC4-NEXT: COMPLETION: X : X - // CHECK-CC4-NEXT: COMPLETION: y : [#int#]y // CHECK-CC4-NEXT: COMPLETION: z : [#void#]z(<#int#>) // RUN: %clang_cc1 -fsyntax-only -fno-rtti -code-completion-patterns -code-completion-at=%s:6:14 -std=gnu++98 %s -o - | FileCheck -check-prefix=CHECK-NO-RTTI %s Added: cfe/trunk/test/CodeCompletion/self-inits.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/self-inits.cpp?rev=346301&view=auto ============================================================================== --- cfe/trunk/test/CodeCompletion/self-inits.cpp (added) +++ cfe/trunk/test/CodeCompletion/self-inits.cpp Wed Nov 7 02:02:31 2018 @@ -0,0 +1,3 @@ +int foo = 10; +// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:1:11 %s -o - | FileCheck --check-prefix=CC1 %s +// CC1-NOT: foo Modified: cfe/trunk/test/Index/complete-type-factors.m URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-type-factors.m?rev=346301&r1=346300&r2=346301&view=diff ============================================================================== --- cfe/trunk/test/Index/complete-type-factors.m (original) +++ cfe/trunk/test/Index/complete-type-factors.m Wed Nov 7 02:02:31 2018 @@ -39,7 +39,6 @@ void test2(A *a) { // CHECK-CC1: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (25) // CHECK-CC1: EnumConstantDecl:{ResultType enum Color}{TypedText Green} (32) // CHECK-CC1: EnumConstantDecl:{ResultType enum Priority}{TypedText High} (32) -// CHECK-CC1: VarDecl:{ResultType int}{TypedText i} (8) // CHECK-CC1: ParmDecl:{ResultType int}{TypedText integer} (8) // CHECK-CC1: EnumConstantDecl:{ResultType enum Priority}{TypedText Low} (32) // CHECK-CC1: ParmDecl:{ResultType enum Priority}{TypedText priority} (17) @@ -48,7 +47,6 @@ void test2(A *a) { // CHECK-CC1: FunctionDecl:{ResultType enum Priority}{TypedText test1}{LeftParen (}{Placeholder enum Priority priority}{Comma , }{Placeholder enum Color color}{Comma , }{Placeholder int integer}{RightParen )} (25) // RUN: c-index-test -code-completion-at=%s:17:18 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC2 %s // CHECK-CC2: EnumConstantDecl:{ResultType enum Color}{TypedText Blue} (16) -// CHECK-CC2: VarDecl:{ResultType enum Color}{TypedText c} (8) // CHECK-CC2: ParmDecl:{ResultType enum Color}{TypedText color} (8) // CHECK-CC2: FunctionDecl:{ResultType int}{TypedText func1}{LeftParen (}{Placeholder enum Color}{RightParen )} (25) // CHECK-CC2: FunctionDecl:{ResultType enum Priority}{TypedText func2}{LeftParen (}{Placeholder int}{RightParen )} (50) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits