diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp index e08b85e9f868..7f9417b609ec 100644 --- a/clang/lib/Index/USRGeneration.cpp +++ b/clang/lib/Index/USRGeneration.cpp @@ -198,7 +198,9 @@ void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) { return; VisitDeclContext(D->getDeclContext()); + bool IsTemplate = false; if (FunctionTemplateDecl *FunTmpl = D->getDescribedFunctionTemplate()) { + IsTemplate = true; Out << "@FT@"; VisitTemplateParameterList(FunTmpl->getTemplateParameters()); } else @@ -226,6 +228,15 @@ void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) { } if (D->isVariadic()) Out << '.'; + if (IsTemplate) { + // Function templates can be overloaded by return type, for example: + // \code + // template typename T::A foo() {} + // template typename T::B foo() {} + // \endcode + Out << '#'; + VisitType(D->getReturnType()); + } Out << '#'; if (const CXXMethodDecl *MD = dyn_cast(D)) { if (MD->isStatic()) @@ -668,6 +679,18 @@ void USRGenerator::VisitType(QualType T) { VisitTemplateArgument(Spec->getArg(I)); return; } + if (const DependentNameType *DNT = T->getAs()) { + Out << '^'; + // FIXME: Encode the qualifier, don't just print it. + PrintingPolicy PO(Ctx.getLangOpts()); + PO.SuppressTagKeyword = true; + PO.SuppressUnwrittenScope = true; + PO.ConstantArraySizeAsWritten = false; + PO.AnonymousTagLocations = false; + DNT->getQualifier()->print(Out, PO); + Out << ':' << DNT->getIdentifier()->getName(); + return; + } // Unhandled type. Out << ' '; diff --git a/clang/test/Index/comment-to-html-xml-conversion.cpp b/clang/test/Index/comment-to-html-xml-conversion.cpp index 95e11c3bc348..33d70a06ddb1 100644 --- a/clang/test/Index/comment-to-html-xml-conversion.cpp +++ b/clang/test/Index/comment-to-html-xml-conversion.cpp @@ -325,7 +325,7 @@ void test_cmd_param_6(int x1, ...); template void test_cmd_tparam_1(T aaa); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=test_cmd_tparam_1:{{.*}} FullCommentAsHTML=[
aaa
Blah blah
] FullCommentAsXML=[test_cmd_tparam_1c:@FT@>1#Ttest_cmd_tparam_1#t0.0#template <typename T> void test_cmd_tparam_1(T aaa)aaa0in Blah blah] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=test_cmd_tparam_1:{{.*}} FullCommentAsHTML=[
aaa
Blah blah
] FullCommentAsXML=[test_cmd_tparam_1c:@FT@>1#Ttest_cmd_tparam_1#t0.0#v#template <typename T> void test_cmd_tparam_1(T aaa)aaa0in Blah blah] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph IsWhitespace @@ -342,7 +342,7 @@ void test_cmd_tparam_1(T aaa); template void test_cmd_tparam_2(T aaa); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=test_cmd_tparam_2:{{.*}} FullCommentAsHTML=[
aaa
Blah blah
] FullCommentAsXML=[test_cmd_tparam_2c:@FT@>1#Ttest_cmd_tparam_2#t0.0#template <typename T> void test_cmd_tparam_2(T aaa)aaa0in Blah blah] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=test_cmd_tparam_2:{{.*}} FullCommentAsHTML=[
aaa
Blah blah
] FullCommentAsXML=[test_cmd_tparam_2c:@FT@>1#Ttest_cmd_tparam_2#t0.0#v#template <typename T> void test_cmd_tparam_2(T aaa)aaa0in Blah blah] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph IsWhitespace @@ -359,7 +359,7 @@ void test_cmd_tparam_2(T aaa); template void test_cmd_tparam_3(T1 aaa, T2 bbb); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=test_cmd_tparam_3:{{.*}} FullCommentAsHTML=[
T1
Aaa
T2
Bbb
] FullCommentAsXML=[test_cmd_tparam_3c:@FT@>2#T#Ttest_cmd_tparam_3#t0.0#t0.1#template <typename T1, typename T2> void test_cmd_tparam_3(T1 aaa, T2 bbb)T10 AaaT21 Bbb ] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=test_cmd_tparam_3:{{.*}} FullCommentAsHTML=[
T1
Aaa
T2
Bbb
] FullCommentAsXML=[test_cmd_tparam_3c:@FT@>2#T#Ttest_cmd_tparam_3#t0.0#t0.1#v#template <typename T1, typename T2> void test_cmd_tparam_3(T1 aaa, T2 bbb)T10 AaaT21 Bbb ] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph IsWhitespace @@ -379,7 +379,7 @@ void test_cmd_tparam_3(T1 aaa, T2 bbb); template void test_cmd_tparam_4(T1 aaa, T2 bbb); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=test_cmd_tparam_4:{{.*}} FullCommentAsHTML=[
T1
Aaa
T2
Bbb
V
Ccc
U
Zzz
] FullCommentAsXML=[test_cmd_tparam_4c:@FT@>3#T#T#NItest_cmd_tparam_4#t0.0#t0.1#template <typename T1, typename T2, int V>\nvoid test_cmd_tparam_4(T1 aaa, T2 bbb)T10 AaaT21 Bbb V2 Ccc U Zzz ] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=test_cmd_tparam_4:{{.*}} FullCommentAsHTML=[
T1
Aaa
T2
Bbb
V
Ccc
U
Zzz
] FullCommentAsXML=[test_cmd_tparam_4c:@FT@>3#T#T#NItest_cmd_tparam_4#t0.0#t0.1#v#template <typename T1, typename T2, int V>\nvoid test_cmd_tparam_4(T1 aaa, T2 bbb)T10 AaaT21 Bbb V2 Ccc U Zzz ] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph IsWhitespace @@ -407,7 +407,7 @@ void test_cmd_tparam_4(T1 aaa, T2 bbb); template class TT, class C> class TTT> void test_cmd_tparam_5(); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=test_cmd_tparam_5:{{.*}} FullCommentAsHTML=[
TTT
Ddd
C
Ccc
T
Aaa
TT
Bbb
] FullCommentAsXML=[test_cmd_tparam_5c:@FT@>1#t>2#t>1#T#Ttest_cmd_tparam_5#template <template <template <typename T> class TT, class C> class TTT>\nvoid test_cmd_tparam_5()TTT0 Ddd C Ccc T Aaa TT Bbb] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=test_cmd_tparam_5:{{.*}} FullCommentAsHTML=[
TTT
Ddd
C
Ccc
T
Aaa
TT
Bbb
] FullCommentAsXML=[test_cmd_tparam_5c:@FT@>1#t>2#t>1#T#Ttest_cmd_tparam_5#v#template <template <template <typename T> class TT, class C> class TTT>\nvoid test_cmd_tparam_5()TTT0 Ddd C Ccc T Aaa TT Bbb] // CHECK-NEXT: CommentAST=[ // CHECK-NEXT: (CXComment_FullComment // CHECK-NEXT: (CXComment_Paragraph IsWhitespace @@ -806,7 +806,7 @@ class comment_to_xml_conversion_01 { template void comment_to_xml_conversion_10(T aaa, U bbb); -// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=comment_to_xml_conversion_10:{{.*}} FullCommentAsXML=[comment_to_xml_conversion_10c:@FT@>2#T#Tcomment_to_xml_conversion_10#t0.0#t0.1#template <typename T, typename U>\nvoid comment_to_xml_conversion_10(T aaa, U bbb) Aaa.] +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionTemplate=comment_to_xml_conversion_10:{{.*}} FullCommentAsXML=[comment_to_xml_conversion_10c:@FT@>2#T#Tcomment_to_xml_conversion_10#t0.0#t0.1#v#template <typename T, typename U>\nvoid comment_to_xml_conversion_10(T aaa, U bbb) Aaa.] /// Aaa. template<> diff --git a/clang/test/Index/index-templates.cpp b/clang/test/Index/index-templates.cpp index 1552235fff4f..dc9036c3bbbb 100644 --- a/clang/test/Index/index-templates.cpp +++ b/clang/test/Index/index-templates.cpp @@ -191,11 +191,11 @@ void foo(float Value); // CHECK-LOAD: index-templates.cpp:111:6: FunctionDecl=foo:111:6 [Specialization of foo:107:6] [Template arg 0: kind: 1, type: float] [Template arg 1: kind: 4, intval: 9] [Template arg 2: kind: 4, intval: 1] [Template arg 3: kind: 4, intval: 14] Extent=[110:1 - 111:64] // RUN: c-index-test -test-load-source-usrs all -fno-delayed-template-parsing %s | FileCheck -check-prefix=CHECK-USRS %s -// CHECK-USRS: index-templates.cpp c:@FT@>3#T#Nt0.0#t>2#T#Nt1.0f#>t0.22S0_# Extent=[3:1 - 4:22] +// CHECK-USRS: index-templates.cpp c:@FT@>3#T#Nt0.0#t>2#T#Nt1.0f#>t0.22S0_#v# Extent=[3:1 - 4:22] // CHECK-USRS: index-templates.cpp c:index-templates.cpp@70 Extent=[3:10 - 3:20] // CHECK-USRS: index-templates.cpp c:index-templates.cpp@82 Extent=[3:22 - 3:29] // CHECK-USRS: index-templates.cpp c:index-templates.cpp@91 Extent=[3:31 - 3:67] -// CHECK-USRS: index-templates.cpp c:index-templates.cpp@136@FT@>3#T#Nt0.0#t>2#T#Nt1.0f#>t0.22S0_#@x Extent=[4:8 - 4:21] +// CHECK-USRS: index-templates.cpp c:index-templates.cpp@136@FT@>3#T#Nt0.0#t>2#T#Nt1.0f#>t0.22S0_#v#@x Extent=[4:8 - 4:21] // CHECK-USRS: index-templates.cpp c:@CT>1#T@allocator Extent=[6:1 - 6:37] // CHECK-USRS: index-templates.cpp c:index-templates.cpp@162 Extent=[6:10 - 6:20] // CHECK-USRS: index-templates.cpp c:@CT>2#T#T@vector Extent=[8:1 - 11:2] diff --git a/clang/test/Index/overriding-ftemplate-comments.cpp b/clang/test/Index/overriding-ftemplate-comments.cpp index 0bc3c2f0ae8e..7fc15f0b00bd 100644 --- a/clang/test/Index/overriding-ftemplate-comments.cpp +++ b/clang/test/Index/overriding-ftemplate-comments.cpp @@ -13,12 +13,12 @@ template void comment_to_html_conversion_17(T AAA); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_17c:@FT@>1#Tcomment_to_html_conversion_17#t0.0#template <typename T> void comment_to_html_conversion_17(T AAA)AAA0in Blah blah] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_17c:@FT@>1#Tcomment_to_html_conversion_17#t0.0#v#template <typename T> void comment_to_html_conversion_17(T AAA)AAA0in Blah blah] template void comment_to_html_conversion_17(T PPP); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_17c:@FT@>1#Tcomment_to_html_conversion_17#t0.0#template <typename T> void comment_to_html_conversion_17(T PPP)PPP0in Blah blah] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_17c:@FT@>1#Tcomment_to_html_conversion_17#t0.0#v#template <typename T> void comment_to_html_conversion_17(T PPP)PPP0in Blah blah] //===----------------------------------------------------------------------===// @@ -27,12 +27,12 @@ void comment_to_html_conversion_17(T PPP); template void comment_to_html_conversion_19(AAA aaa, BBB bbb); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_19c:@FT@>2#T#Tcomment_to_html_conversion_19#t0.0#t0.1#template <typename AAA, typename BBB>\nvoid comment_to_html_conversion_19(AAA aaa, BBB bbb)AAA0 AaaBBB1 Bbb ] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_19c:@FT@>2#T#Tcomment_to_html_conversion_19#t0.0#t0.1#v#template <typename AAA, typename BBB>\nvoid comment_to_html_conversion_19(AAA aaa, BBB bbb)AAA0 AaaBBB1 Bbb ] template void comment_to_html_conversion_19(PPP aaa, QQQ bbb); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_19c:@FT@>2#T#Tcomment_to_html_conversion_19#t0.0#t0.1#template <typename PPP, typename QQQ>\nvoid comment_to_html_conversion_19(PPP aaa, QQQ bbb)PPP0 AaaQQQ1 Bbb ] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_19c:@FT@>2#T#Tcomment_to_html_conversion_19#t0.0#t0.1#v#template <typename PPP, typename QQQ>\nvoid comment_to_html_conversion_19(PPP aaa, QQQ bbb)PPP0 AaaQQQ1 Bbb ] //===----------------------------------------------------------------------===// @@ -43,12 +43,12 @@ void comment_to_html_conversion_19(PPP aaa, QQQ bbb); template void comment_to_html_conversion_20(AAA aaa, BBB bbb); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_20c:@FT@>3#T#T#NIcomment_to_html_conversion_20#t0.0#t0.1#template <typename AAA, typename BBB, int CCC>\nvoid comment_to_html_conversion_20(AAA aaa, BBB bbb)AAA0 AaaBBB1 Bbb CCC2 Ccc UUU Zzz ] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_20c:@FT@>3#T#T#NIcomment_to_html_conversion_20#t0.0#t0.1#v#template <typename AAA, typename BBB, int CCC>\nvoid comment_to_html_conversion_20(AAA aaa, BBB bbb)AAA0 AaaBBB1 Bbb CCC2 Ccc UUU Zzz ] template void comment_to_html_conversion_20(PPP aaa, QQQ bbb); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_20c:@FT@>3#T#T#NIcomment_to_html_conversion_20#t0.0#t0.1#template <typename PPP, typename QQQ, int RRR>\nvoid comment_to_html_conversion_20(PPP aaa, QQQ bbb)PPP0 AaaQQQ1 Bbb RRR2 Ccc UUU Zzz ] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_20c:@FT@>3#T#T#NIcomment_to_html_conversion_20#t0.0#t0.1#v#template <typename PPP, typename QQQ, int RRR>\nvoid comment_to_html_conversion_20(PPP aaa, QQQ bbb)PPP0 AaaQQQ1 Bbb RRR2 Ccc UUU Zzz ] //===----------------------------------------------------------------------===// @@ -59,12 +59,12 @@ void comment_to_html_conversion_20(PPP aaa, QQQ bbb); template class DDD, class BBB> class AAA> void comment_to_html_conversion_21(); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_21c:@FT@>1#t>2#t>1#T#Tcomment_to_html_conversion_21#template <template <template <typename CCC> class DDD, class BBB> class AAA>\nvoid comment_to_html_conversion_21()AAA0 Aaa BBB Bbb CCC Ccc DDD Ddd] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_21c:@FT@>1#t>2#t>1#T#Tcomment_to_html_conversion_21#v#template <template <template <typename CCC> class DDD, class BBB> class AAA>\nvoid comment_to_html_conversion_21()AAA0 Aaa BBB Bbb CCC Ccc DDD Ddd] template class SSS, class QQQ> class PPP> void comment_to_html_conversion_21(); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_21c:@FT@>1#t>2#t>1#T#Tcomment_to_html_conversion_21#template <template <template <typename RRR> class SSS, class QQQ> class PPP>\nvoid comment_to_html_conversion_21()PPP0 Aaa QQQ Bbb RRR Ccc SSS Ddd] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_21c:@FT@>1#t>2#t>1#T#Tcomment_to_html_conversion_21#v#template <template <template <typename RRR> class SSS, class QQQ> class PPP>\nvoid comment_to_html_conversion_21()PPP0 Aaa QQQ Bbb RRR Ccc SSS Ddd] //===----------------------------------------------------------------------===// @@ -77,10 +77,10 @@ void comment_to_html_conversion_21(); template class BBB > class AAA> void comment_to_html_conversion_22(); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#template <class C1, template <class C2, template <class C3, class C4> class BBB>\n class AAA>\nvoid comment_to_html_conversion_22()C10 Ccc 1 AAA1 Zzz C2 Ccc 2 C3 Ccc 3 C4 Ccc 4 BBB Bbb] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#v#template <class C1, template <class C2, template <class C3, class C4> class BBB>\n class AAA>\nvoid comment_to_html_conversion_22()C10 Ccc 1 AAA1 Zzz C2 Ccc 2 C3 Ccc 3 C4 Ccc 4 BBB Bbb] template class QQQ> class PPP> void comment_to_html_conversion_22(); -// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#template <class CCC1, template <class CCC2, template <class CCC3, class CCC4>\n class QQQ> class PPP>\nvoid comment_to_html_conversion_22()CCC10 Ccc 1 PPP1 Zzz CCC2 Ccc 2 CCC3 Ccc 3 CCC4 Ccc 4 QQQ Bbb] +// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#v#template <class CCC1, template <class CCC2, template <class CCC3, class CCC4>\n class QQQ> class PPP>\nvoid comment_to_html_conversion_22()CCC10 Ccc 1 PPP1 Zzz CCC2 Ccc 2 CCC3 Ccc 3 CCC4 Ccc 4 QQQ Bbb] diff --git a/clang/test/Index/overriding-method-comments.mm b/clang/test/Index/overriding-method-comments.mm index 9285693396e0..d995e0eca782 100644 --- a/clang/test/Index/overriding-method-comments.mm +++ b/clang/test/Index/overriding-method-comments.mm @@ -116,10 +116,10 @@ void foo1(int TTT); template void foo(AAA, BBB); -// CHECK: FullCommentAsXML=[fooc:@FT@>2#T#Tfoo#t0.0#t0.1#template <typename AAA, typename BBB> void foo(AAA, BBB) Documentation AAA0 The type, silly as well.BBB1 The type, silly. ] +// CHECK: FullCommentAsXML=[fooc:@FT@>2#T#Tfoo#t0.0#t0.1#v#template <typename AAA, typename BBB> void foo(AAA, BBB) Documentation AAA0 The type, silly as well.BBB1 The type, silly. ] template void foo(PPP, QQQ); -// CHECK: FullCommentAsXML=[fooc:@FT@>2#T#Tfoo#t0.0#t0.1#template <typename PPP, typename QQQ> void foo(PPP, QQQ) Documentation PPP0 The type, silly as well.QQQ1 The type, silly. ] +// CHECK: FullCommentAsXML=[fooc:@FT@>2#T#Tfoo#t0.0#t0.1#v#template <typename PPP, typename QQQ> void foo(PPP, QQQ) Documentation PPP0 The type, silly as well.QQQ1 The type, silly. ] diff --git a/clang/test/Index/usrs.cpp b/clang/test/Index/usrs.cpp index 909ce75922a9..dca141e8f059 100644 --- a/clang/test/Index/usrs.cpp +++ b/clang/test/Index/usrs.cpp @@ -79,6 +79,10 @@ void rdar9371763() { foo.bar(); } +template typename T::A someTemplFn() {} +template typename T::B someTemplFn() {} +template int someTemplFn() {} + // RUN: c-index-test -test-load-source-usrs all %s | FileCheck %s // CHECK: usrs.cpp c:@N@foo Extent=[1:1 - 4:2] // CHECK: usrs.cpp c:@N@foo@x Extent=[2:3 - 2:8] @@ -143,4 +147,6 @@ void rdar9371763() { // CHECK: usrs.cpp c:usrs.cpp@aN@C@RDar9371763_Foo@F@bar# Extent=[75:1 - 75:31] // CHECK: usrs.cpp c:@F@rdar9371763# Extent=[77:1 - 80:2] // CHECK: usrs.cpp c:usrs.cpp@1204@F@rdar9371763#@foo Extent=[78:3 - 78:22] - +// CHECK: usrs.cpp c:@FT@>1#TsomeTemplFn#^type-parameter-0-0:::A# Extent=[82:1 - 82:50] +// CHECK: usrs.cpp c:@FT@>1#TsomeTemplFn#^type-parameter-0-0:::B# Extent=[83:1 - 83:50] +// CHECK: usrs.cpp c:@FT@>1#TsomeTemplFn#I# Extent=[84:1 - 84:40]