diff --git a/clang/include/clang/AST/Comment.h b/clang/include/clang/AST/Comment.h index 00db1179915b..e3c593671b3d 100644 --- a/clang/include/clang/AST/Comment.h +++ b/clang/include/clang/AST/Comment.h @@ -905,6 +905,10 @@ struct DeclInfo { /// Declaration the comment is attached to. Should not be NULL. const Decl *CommentDecl; + /// Location of this declaration. Not necessarily same as location of + /// CommentDecl. + SourceLocation Loc; + /// Parameters that can be referenced by \\param if \c CommentDecl is something /// that we consider a "function". ArrayRef ParamVars; diff --git a/clang/lib/AST/Comment.cpp b/clang/lib/AST/Comment.cpp index a235b60bea49..e51efd9e1157 100644 --- a/clang/lib/AST/Comment.cpp +++ b/clang/lib/AST/Comment.cpp @@ -156,7 +156,8 @@ void DeclInfo::fill() { IsFilled = true; return; } - + Loc = CommentDecl->getLocation(); + Decl::Kind K = CommentDecl->getKind(); switch (K) { default: diff --git a/clang/test/Index/overriding-ftemplate-comments.cpp b/clang/test/Index/overriding-ftemplate-comments.cpp index 6e27b8abdd7e..03588f4bc4be 100644 --- a/clang/test/Index/overriding-ftemplate-comments.cpp +++ b/clang/test/Index/overriding-ftemplate-comments.cpp @@ -59,20 +59,20 @@ void comment_to_html_conversion_22(); // CHECK: FunctionTemplate=comment_to_html_conversion_17:14:6 RawComment=[/// \tparam\n/// \param AAA Blah blah] RawCommentRange=[11:1 - 12:25] FullCommentAsHTML=[
AAA
Blah blah
] FullCommentAsXML=[comment_to_html_conversion_17c:@FT@>1#Tcomment_to_html_conversion_17#t0.0#AAA0in Blah blah -// CHECK: FunctionTemplate=comment_to_html_conversion_17:17:6 RawComment=[/// \tparam\n/// \param AAA Blah blah] RawCommentRange=[11:1 - 12:25] FullCommentAsHTML=[
PPP
Blah blah
] FullCommentAsXML=[comment_to_html_conversion_17c:@FT@>1#Tcomment_to_html_conversion_17#t0.0#PPP0in Blah blah +// CHECK: FunctionTemplate=comment_to_html_conversion_17:17:6 RawComment=[/// \tparam\n/// \param AAA Blah blah] RawCommentRange=[11:1 - 12:25] FullCommentAsHTML=[
PPP
Blah blah
] FullCommentAsXML=[comment_to_html_conversion_17c:@FT@>1#Tcomment_to_html_conversion_17#t0.0#PPP0in Blah blah // CHECK: FunctionTemplate=comment_to_html_conversion_19:22:6 RawComment=[/// \tparam BBB Bbb\n/// \tparam AAA Aaa] RawCommentRange=[19:1 - 20:20] FullCommentAsHTML=[
AAA
Aaa
BBB
Bbb
] FullCommentAsXML=[comment_to_html_conversion_19c:@FT@>2#T#Tcomment_to_html_conversion_19#t0.0#t0.1#AAA0 AaaBBB1 Bbb -// CHECK: FunctionTemplate=comment_to_html_conversion_19:25:6 RawComment=[/// \tparam BBB Bbb\n/// \tparam AAA Aaa] RawCommentRange=[19:1 - 20:20] FullCommentAsHTML=[
PPP
Aaa
QQQ
Bbb
] FullCommentAsXML=[comment_to_html_conversion_19c:@FT@>2#T#Tcomment_to_html_conversion_19#t0.0#t0.1#PPP0 AaaQQQ1 Bbb +// CHECK: FunctionTemplate=comment_to_html_conversion_19:25:6 RawComment=[/// \tparam BBB Bbb\n/// \tparam AAA Aaa] RawCommentRange=[19:1 - 20:20] FullCommentAsHTML=[
PPP
Aaa
QQQ
Bbb
] FullCommentAsXML=[comment_to_html_conversion_19c:@FT@>2#T#Tcomment_to_html_conversion_19#t0.0#t0.1#PPP0 AaaQQQ1 Bbb // CHECK: FunctionTemplate=comment_to_html_conversion_20:32:6 RawComment=[/// \tparam BBB Bbb\n/// \tparam UUU Zzz\n/// \tparam CCC Ccc\n/// \tparam AAA Aaa] RawCommentRange=[27:1 - 30:20] FullCommentAsHTML=[
AAA
Aaa
BBB
Bbb
CCC
Ccc
UUU
Zzz
] FullCommentAsXML=[comment_to_html_conversion_20c:@FT@>3#T#T#NIcomment_to_html_conversion_20#t0.0#t0.1#AAA0 AaaBBB1 Bbb CCC2 Ccc UUU Zzz -// CHECK: FunctionTemplate=comment_to_html_conversion_20:35:6 RawComment=[/// \tparam BBB Bbb\n/// \tparam UUU Zzz\n/// \tparam CCC Ccc\n/// \tparam AAA Aaa] RawCommentRange=[27:1 - 30:20] FullCommentAsHTML=[
PPP
Aaa
QQQ
Bbb
RRR
Ccc
UUU
Zzz
] FullCommentAsXML=[comment_to_html_conversion_20c:@FT@>3#T#T#NIcomment_to_html_conversion_20#t0.0#t0.1#PPP0 AaaQQQ1 Bbb RRR2 Ccc UUU Zzz +// CHECK: FunctionTemplate=comment_to_html_conversion_20:35:6 RawComment=[/// \tparam BBB Bbb\n/// \tparam UUU Zzz\n/// \tparam CCC Ccc\n/// \tparam AAA Aaa] RawCommentRange=[27:1 - 30:20] FullCommentAsHTML=[
PPP
Aaa
QQQ
Bbb
RRR
Ccc
UUU
Zzz
] FullCommentAsXML=[comment_to_html_conversion_20c:@FT@>3#T#T#NIcomment_to_html_conversion_20#t0.0#t0.1#PPP0 AaaQQQ1 Bbb RRR2 Ccc UUU Zzz // CHECK: FunctionTemplate=comment_to_html_conversion_21:42:6 RawComment=[/// \tparam AAA Aaa\n/// \tparam BBB Bbb\n/// \tparam CCC Ccc\n/// \tparam DDD Ddd] RawCommentRange=[37:1 - 40:20] FullCommentAsHTML=[
AAA
Aaa
BBB
Bbb
CCC
Ccc
DDD
Ddd
] FullCommentAsXML=[comment_to_html_conversion_21c:@FT@>1#t>2#t>1#T#Tcomment_to_html_conversion_21#AAA0 Aaa BBB Bbb CCC Ccc DDD Ddd -// CHECK: FunctionTemplate=comment_to_html_conversion_21:45:6 RawComment=[/// \tparam AAA Aaa\n/// \tparam BBB Bbb\n/// \tparam CCC Ccc\n/// \tparam DDD Ddd] RawCommentRange=[37:1 - 40:20] FullCommentAsHTML=[
PPP
Aaa
QQQ
Bbb
RRR
Ccc
SSS
Ddd
] FullCommentAsXML=[comment_to_html_conversion_21c:@FT@>1#t>2#t>1#T#Tcomment_to_html_conversion_21#PPP0 Aaa QQQ Bbb RRR Ccc SSS Ddd +// CHECK: FunctionTemplate=comment_to_html_conversion_21:45:6 RawComment=[/// \tparam AAA Aaa\n/// \tparam BBB Bbb\n/// \tparam CCC Ccc\n/// \tparam DDD Ddd] RawCommentRange=[37:1 - 40:20] FullCommentAsHTML=[
PPP
Aaa
QQQ
Bbb
RRR
Ccc
SSS
Ddd
] FullCommentAsXML=[comment_to_html_conversion_21c:@FT@>1#t>2#t>1#T#Tcomment_to_html_conversion_21#PPP0 Aaa QQQ Bbb RRR Ccc SSS Ddd // CHECK: FunctionTemplate=comment_to_html_conversion_22:54:6 RawComment=[/// \tparam C1 Ccc 1\n/// \tparam AAA Zzz\n/// \tparam C2 Ccc 2\n/// \tparam C3 Ccc 3\n/// \tparam C4 Ccc 4\n/// \tparam BBB Bbb] RawCommentRange=[47:1 - 52:20] FullCommentAsHTML=[
C1
Ccc 1
AAA
Zzz
C2
Ccc 2
C3
Ccc 3
C4
Ccc 4
BBB
Bbb
] FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#C10 Ccc 1 AAA1 Zzz C2 Ccc 2 C3 Ccc 3 C4 Ccc 4 BBB Bbb -// CHECK: FunctionTemplate=comment_to_html_conversion_22:58:6 RawComment=[/// \tparam C1 Ccc 1\n/// \tparam AAA Zzz\n/// \tparam C2 Ccc 2\n/// \tparam C3 Ccc 3\n/// \tparam C4 Ccc 4\n/// \tparam BBB Bbb] RawCommentRange=[47:1 - 52:20] FullCommentAsHTML=[
CCC1
Ccc 1
PPP
Zzz
CCC2
Ccc 2
CCC3
Ccc 3
CCC4
Ccc 4
QQQ
Bbb
] FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_to_html_conversion_22#CCC10 Ccc 1 PPP1 Zzz CCC2 Ccc 2 CCC3 Ccc 3 CCC4 Ccc 4 QQQ Bbb +// CHECK: FunctionTemplate=comment_to_html_conversion_22:58:6 RawComment=[/// \tparam C1 Ccc 1\n/// \tparam AAA Zzz\n/// \tparam C2 Ccc 2\n/// \tparam C3 Ccc 3\n/// \tparam C4 Ccc 4\n/// \tparam BBB Bbb] RawCommentRange=[47:1 - 52:20] FullCommentAsHTML=[
CCC1
Ccc 1
PPP
Zzz
CCC2
Ccc 2
CCC3
Ccc 3
CCC4
Ccc 4
QQQ
Bbb
] FullCommentAsXML=[comment_to_html_conversion_22c:@FT@>2#T#t>2#T#t>2#T#Tcomment_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 c0aefb068d74..48d7522ad2ed 100644 --- a/clang/test/Index/overriding-method-comments.mm +++ b/clang/test/Index/overriding-method-comments.mm @@ -32,9 +32,9 @@ // CHECK: FullCommentAsHTML=[
AAA
ZZZ
] FullCommentAsXML=[METH:c:objc(cs)Root(im)METH:AAA0in ZZZ -// CHECK: FullCommentAsHTML=[
BBB
ZZZ
] FullCommentAsXML=[METH:c:objc(cs)Root(im)METH:BBB0in ZZZ +// CHECK: FullCommentAsHTML=[
BBB
ZZZ
] FullCommentAsXML=[METH:c:objc(cs)Root(im)METH:BBB0in ZZZ -// CHECK: FullCommentAsHTML=[
III
ZZZ
] FullCommentAsXML=[METH:c:objc(cs)Root(im)METH:III0in ZZZ +// CHECK: FullCommentAsHTML=[
III
ZZZ
] FullCommentAsXML=[METH:c:objc(cs)Root(im)METH:III0in ZZZ @interface Redec : Root @end @@ -54,7 +54,7 @@ // CHECK: FullCommentAsHTML=[
AAA
input value
BBB
2nd input value is double
CCC
output value is int
] FullCommentAsXML=[EXT_METH:::c:objc(cs)Redec(im)EXT_METH:::AAA0in input value BBB1in 2nd input value is double CCC2out output value is int -// CHECK: FullCommentAsHTML=[
PPP
input value
QQQ
2nd input value is double
RRR
output value is int
] FullCommentAsXML=[EXT_METH:::c:objc(cs)Redec(im)EXT_METH:::PPP0in input value QQQ1in 2nd input value is double RRR2out output value is int +// CHECK: FullCommentAsHTML=[
PPP
input value
QQQ
2nd input value is double
RRR
output value is int
] FullCommentAsXML=[EXT_METH:::c:objc(cs)Redec(im)EXT_METH:::PPP0in input value QQQ1in 2nd input value is double RRR2out output value is int struct Base { /// \brief Does something. @@ -96,19 +96,19 @@ void foo1(int TTT); // CHECK: FullCommentAsHTML=[

Does something.

CCC
argument to undefined virtual.
] FullCommentAsXML=[foo_outoflinec:@S@Base@F@foo_outofline#I# Does something. CCC0in argument to undefined virtual. -// CHECK: FullCommentAsHTML=[

Does something.

RRR
argument to undefined virtual.
] FullCommentAsXML=[foo_outoflinec:@S@Base@F@foo_outofline#I# Does something. RRR0in argument to undefined virtual. +// CHECK: FullCommentAsHTML=[

Does something.

RRR
argument to undefined virtual.
] FullCommentAsXML=[foo_outoflinec:@S@Base@F@foo_outofline#I# Does something. RRR0in argument to undefined virtual. -// CHECK: FullCommentAsHTML=[

Does something.

PPP
argument to foo_pure.
] FullCommentAsXML=[foo_purec:@S@Base@F@foo_pure#I# Does something. PPP0in argument to foo_pure. +// CHECK: FullCommentAsHTML=[

Does something.

PPP
argument to foo_pure.
] FullCommentAsXML=[foo_purec:@S@Base@F@foo_pure#I# Does something. PPP0in argument to foo_pure. -// CHECK: FullCommentAsHTML=[

Does something.

QQQ
argument to defined virtual.
] FullCommentAsXML=[foo_inlinec:@S@Base@F@foo_inline#I# Does something. QQQ0in argument to defined virtual. +// CHECK: FullCommentAsHTML=[

Does something.

QQQ
argument to defined virtual.
] FullCommentAsXML=[foo_inlinec:@S@Base@F@foo_inline#I# Does something. QQQ0in argument to defined virtual. // CHECK: FullCommentAsHTML=[

Does something.

DDD
a value.
] FullCommentAsXML=[fooc:@F@foo#I# Does something. DDD0in a value. -// CHECK: FullCommentAsHTML=[

Does something.

SSS
a value.
] FullCommentAsXML=[fooc:@F@foo#I# Does something. SSS0in a value. +// CHECK: FullCommentAsHTML=[

Does something.

SSS
a value.
] FullCommentAsXML=[fooc:@F@foo#I# Does something. SSS0in a value. // CHECK: FullCommentAsHTML=[

Does something.

EEE
argument to function decl.
] FullCommentAsXML=[foo1c:@F@foo1#I# Does something. EEE0in argument to function decl. -// CHECK: FullCommentAsHTML=[

Does something.

TTT
argument to function decl.
] FullCommentAsXML=[foo1c:@F@foo1#I# Does something. TTT0in argument to function decl. +// CHECK: FullCommentAsHTML=[

Does something.

TTT
argument to function decl.
] FullCommentAsXML=[foo1c:@F@foo1#I# Does something. TTT0in argument to function decl. /// \brief Documentation /// \tparam BBB The type, silly. @@ -121,4 +121,4 @@ void foo(PPP, QQQ); // CHECK: FullCommentAsHTML=[

Documentation

AAA
The type, silly as well.
BBB
The type, silly.
] FullCommentAsXML=[fooc:@FT@>2#T#Tfoo#t0.0#t0.1# Documentation AAA0 The type, silly as well.BBB1 The type, silly. -// CHECK: FullCommentAsHTML=[

Documentation

PPP
The type, silly as well.
QQQ
The type, silly.
] FullCommentAsXML=[fooc:@FT@>2#T#Tfoo#t0.0#t0.1# Documentation PPP0 The type, silly as well.QQQ1 The type, silly. +// CHECK: FullCommentAsHTML=[

Documentation

PPP
The type, silly as well.
QQQ
The type, silly.
] FullCommentAsXML=[fooc:@FT@>2#T#Tfoo#t0.0#t0.1# Documentation PPP0 The type, silly as well.QQQ1 The type, silly. diff --git a/clang/tools/libclang/CXComment.cpp b/clang/tools/libclang/CXComment.cpp index 00171ebe4709..5b722a5a1555 100644 --- a/clang/tools/libclang/CXComment.cpp +++ b/clang/tools/libclang/CXComment.cpp @@ -1096,7 +1096,7 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) { { // Print line and column number. - SourceLocation Loc = DI->CommentDecl->getLocation(); + SourceLocation Loc = DI->Loc; std::pair LocInfo = SM.getDecomposedLoc(Loc); FileID FID = LocInfo.first; unsigned FileOffset = LocInfo.second;