ilya-biryukov created this revision. Herald added a subscriber: eraman. Adjusted PrintingPolicy inside code completion to avoid printing some redundant name qualifiers.
Before this change, typedefs that were written unqualified in source code were printed with qualifiers in completion. For example, in the following code struct foo { typedef int type; type method(); }; completion item for `method` had return type of `foo::type`, even though the original code used `type` without qualifiers. After this change, the completion item has return type `type`, as originally written in the source code. Note that this change does not suppress qualifiers written by the user. For example, in the following code typedef int type; struct foo { typedef int type; ::type method(foo::type); }; completion item for `method` has return type of `::type` and parameter type of `foo::type`, as originally written in the source code. https://reviews.llvm.org/D38538 Files: lib/Sema/SemaCodeComplete.cpp test/CodeCompletion/call.cpp test/CodeCompletion/enum-switch-case-qualified.cpp test/CodeCompletion/enum-switch-case.cpp test/CodeCompletion/qualifiers-as-written.cpp test/CodeCompletion/uninstantiated_params.cpp test/Index/code-completion.cpp test/Index/complete-cxx-inline-methods.cpp test/Index/complete-documentation-templates.cpp
Index: test/Index/complete-documentation-templates.cpp =================================================================== --- test/Index/complete-documentation-templates.cpp +++ test/Index/complete-documentation-templates.cpp @@ -119,7 +119,7 @@ // CHECK-CC3: FieldDecl:{ResultType int}{TypedText T7}{{.*}}(brief comment: This is T7.) // RUN: env CINDEXTEST_COMPLETION_BRIEF_COMMENTS=1 c-index-test -code-completion-at=%s:59:12 %s | FileCheck -check-prefix=CHECK-CC4 %s -// CHECK-CC4: EnumConstantDecl:{ResultType T3<int>::T9}{TypedText T10}{{.*}}(brief comment: This is T10.) +// CHECK-CC4: EnumConstantDecl:{ResultType T9}{TypedText T10}{{.*}}(brief comment: This is T10.) // FIXME: after we implement propagating comments through typedefs, this // typedef for implicit instantiation should pick up the documentation // comment from class template. @@ -140,7 +140,7 @@ // RUN: env CINDEXTEST_COMPLETION_BRIEF_COMMENTS=1 c-index-test -code-completion-at=%s:105:20 %s | FileCheck -check-prefix=CHECK-CC7 %s // CHECK-CC7: ClassDecl:{TypedText T105}{{.*}}(brief comment: This is T105.) // CHECK-CC7: EnumDecl:{TypedText T106}{{.*}}(brief comment: This is T106.) -// CHECK-CC7: EnumConstantDecl:{ResultType T100<int, long>::T106}{TypedText T107}{{.*}}(brief comment: This is T107.) +// CHECK-CC7: EnumConstantDecl:{ResultType T106}{TypedText T107}{{.*}}(brief comment: This is T107.) // FIXME: after we implement propagating comments through typedefs, these two // typedefs for implicit instantiations should pick up the documentation // comment from class template. Index: test/Index/complete-cxx-inline-methods.cpp =================================================================== --- test/Index/complete-cxx-inline-methods.cpp +++ test/Index/complete-cxx-inline-methods.cpp @@ -25,7 +25,7 @@ // 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 )} (79) +// CHECK: CXXMethod:{ResultType Vec &}{TypedText operator=}{LeftParen (}{Placeholder const 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) Index: test/Index/code-completion.cpp =================================================================== --- test/Index/code-completion.cpp +++ test/Index/code-completion.cpp @@ -55,7 +55,7 @@ // CHECK-MEMBER: CXXMethod:{ResultType Z &}{TypedText operator=}{LeftParen (}{Placeholder const Z &}{RightParen )} // CHECK-MEMBER: CXXMethod:{ResultType X &}{Text X::}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} // CHECK-MEMBER: CXXMethod:{ResultType Y &}{Text Y::}{TypedText operator=}{LeftParen (}{Placeholder const Y &}{RightParen )} -// CHECK-MEMBER: EnumConstantDecl:{ResultType X::E}{Informative E::}{TypedText Val1} +// CHECK-MEMBER: EnumConstantDecl:{ResultType E}{Informative E::}{TypedText Val1} // CHECK-MEMBER: StructDecl:{TypedText X}{Text ::} // CHECK-MEMBER: StructDecl:{TypedText Y}{Text ::} // CHECK-MEMBER: StructDecl:{TypedText Z}{Text ::} Index: test/CodeCompletion/uninstantiated_params.cpp =================================================================== --- test/CodeCompletion/uninstantiated_params.cpp +++ test/CodeCompletion/uninstantiated_params.cpp @@ -9,5 +9,5 @@ unique_ptr<int> x; x. // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:10:5 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s - // CHECK-CC1: [#void#]reset({#<#unique_ptr<int>::pointer ptr = pointer()#>#}) + // CHECK-CC1: [#void#]reset({#<#pointer ptr = pointer()#>#}) } Index: test/CodeCompletion/qualifiers-as-written.cpp =================================================================== --- /dev/null +++ test/CodeCompletion/qualifiers-as-written.cpp @@ -0,0 +1,11 @@ +struct foo { + typedef int type; + + type method(type, foo::type, ::foo::type, ::foo::foo::type); +}; + +void test() { + foo(). + // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:8:9 %s -o - | FileCheck %s + // CHECK: COMPLETION: method : [#type#]method(<#type#>, <#foo::type#>, <#::foo::type#>, <#::foo::foo::type#>) +} Index: test/CodeCompletion/enum-switch-case.cpp =================================================================== --- test/CodeCompletion/enum-switch-case.cpp +++ test/CodeCompletion/enum-switch-case.cpp @@ -20,9 +20,9 @@ case // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:21:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s - // CHECK-CC1: Blue : [#N::Color#]N::Blue - // CHECK-CC1-NEXT: Green : [#N::Color#]N::Green - // CHECK-CC1-NEXT: Indigo : [#N::Color#]N::Indigo - // CHECK-CC1-NEXT: Orange : [#N::Color#]N::Orange - // CHECK-CC1-NEXT: Violet : [#N::Color#]N::Violet + // CHECK-CC1: Blue : [#Color#]N::Blue + // CHECK-CC1-NEXT: Green : [#Color#]N::Green + // CHECK-CC1-NEXT: Indigo : [#Color#]N::Indigo + // CHECK-CC1-NEXT: Orange : [#Color#]N::Orange + // CHECK-CC1-NEXT: Violet : [#Color#]N::Violet Index: test/CodeCompletion/enum-switch-case-qualified.cpp =================================================================== --- test/CodeCompletion/enum-switch-case-qualified.cpp +++ test/CodeCompletion/enum-switch-case-qualified.cpp @@ -22,11 +22,11 @@ switch (color) { case // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:23:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s - // CHECK-CC1: Blue : [#M::N::C::Color#]N::C::Blue - // CHECK-CC1-NEXT: Green : [#M::N::C::Color#]N::C::Green - // CHECK-CC1-NEXT: Indigo : [#M::N::C::Color#]N::C::Indigo - // CHECK-CC1-NEXT: Orange : [#M::N::C::Color#]N::C::Orange - // CHECK-CC1-NEXT: Red : [#M::N::C::Color#]N::C::Red - // CHECK-CC1-NEXT: Violet : [#M::N::C::Color#]N::C::Violet - // CHECK-CC1: Yellow : [#M::N::C::Color#]N::C::Yellow + // CHECK-CC1: Blue : [#Color#]N::C::Blue + // CHECK-CC1-NEXT: Green : [#Color#]N::C::Green + // CHECK-CC1-NEXT: Indigo : [#Color#]N::C::Indigo + // CHECK-CC1-NEXT: Orange : [#Color#]N::C::Orange + // CHECK-CC1-NEXT: Red : [#Color#]N::C::Red + // CHECK-CC1-NEXT: Violet : [#Color#]N::C::Violet + // CHECK-CC1: Yellow : [#Color#]N::C::Yellow Index: test/CodeCompletion/call.cpp =================================================================== --- test/CodeCompletion/call.cpp +++ test/CodeCompletion/call.cpp @@ -19,10 +19,10 @@ f(Y(), 0, 0); // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:19:9 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s // CHECK-CC1: COMPLETION: Pattern : dynamic_cast<<#type#>>(<#expression#>) - // CHECK-CC1: f(N::Y y, <#int ZZ#>) + // CHECK-CC1: f(Y y, <#int ZZ#>) // CHECK-CC1-NEXT: f(int i, <#int j#>, int k) // CHECK-CC1-NEXT: f(float x, <#float y#>) // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:13 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s - // CHECK-CC2-NOT: f(N::Y y, int ZZ) + // CHECK-CC2-NOT: f(Y y, int ZZ) // CHECK-CC2: f(int i, int j, <#int k#>) } Index: lib/Sema/SemaCodeComplete.cpp =================================================================== --- lib/Sema/SemaCodeComplete.cpp +++ lib/Sema/SemaCodeComplete.cpp @@ -1495,6 +1495,7 @@ Policy.AnonymousTagLocations = false; Policy.SuppressStrongLifetime = true; Policy.SuppressUnwrittenScope = true; + Policy.SuppressScope = true; return Policy; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits