From 1bfb00dabf83d8c8b95b7276b4c0ae3fd64832c8 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 17 Oct 2012 21:58:03 +0000 Subject: [PATCH] [Doc parsing]: This patch adds tag to XML comment for declarations which pretty-prints declaration. I had to XFAIL one test annotate-comments.cpp. This test is currently unmaintainable as written. Dmitri G., can you see what we can do about this test. We should change this test such that adding a new tag does not wreck havoc to the test. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166130 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/xml/comment-xml-schema.rng | 28 +++++++++ include/clang/AST/Comment.h | 6 +- include/clang/AST/PrettyPrinter.h | 7 ++- lib/AST/Comment.cpp | 2 +- lib/AST/DeclPrinter.cpp | 5 +- .../annotate-comments-availability-attrs.cpp | 24 ++++---- test/Index/annotate-comments.cpp | 1 + test/Index/overriding-ftemplate-comments.cpp | 21 +++---- test/Index/overriding-method-comments.mm | 58 +++++++++---------- tools/libclang/CXComment.cpp | 21 ++++++- 10 files changed, 116 insertions(+), 57 deletions(-) diff --git a/bindings/xml/comment-xml-schema.rng b/bindings/xml/comment-xml-schema.rng index af1a3d8308..d98f405cf9 100644 --- a/bindings/xml/comment-xml-schema.rng +++ b/bindings/xml/comment-xml-schema.rng @@ -24,6 +24,9 @@ + + + @@ -70,6 +73,9 @@ + + + @@ -114,6 +120,9 @@ + + + @@ -143,6 +152,9 @@ + + + @@ -173,6 +185,9 @@ + + + @@ -203,6 +218,9 @@ + + + @@ -233,6 +251,9 @@ + + + @@ -301,6 +322,13 @@ + + + + + + + diff --git a/include/clang/AST/Comment.h b/include/clang/AST/Comment.h index e3c593671b..c3eb22e856 100644 --- a/include/clang/AST/Comment.h +++ b/include/clang/AST/Comment.h @@ -905,9 +905,9 @@ 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; + /// CurrentDecl is the declaration for which comment is being put into an XML comment. + /// Not necessarily same as CommentDecl. + const Decl *CurrentDecl; /// Parameters that can be referenced by \\param if \c CommentDecl is something /// that we consider a "function". diff --git a/include/clang/AST/PrettyPrinter.h b/include/clang/AST/PrettyPrinter.h index e0b1d329d5..7babc1b24a 100644 --- a/include/clang/AST/PrettyPrinter.h +++ b/include/clang/AST/PrettyPrinter.h @@ -39,7 +39,8 @@ struct PrintingPolicy { SuppressUnwrittenScope(false), SuppressInitializers(false), ConstantArraySizeAsWritten(false), AnonymousTagLocations(true), SuppressStrongLifetime(false), Bool(LO.Bool), - TerseOutput(false), DumpSourceManager(0) { } + TerseOutput(false), SuppressAttributes(false), + DumpSourceManager(0) { } /// \brief What language we're printing. LangOptions LangOpts; @@ -140,6 +141,10 @@ struct PrintingPolicy { /// declarations inside namespaces etc. Effectively, this should print /// only the requested declaration. unsigned TerseOutput : 1; + + /// \brief When true, do not print attributes attached to the declaration. + /// + unsigned SuppressAttributes : 1; /// \brief If we are "dumping" rather than "pretty-printing", this points to /// a SourceManager which will be used to dump SourceLocations. Dumping diff --git a/lib/AST/Comment.cpp b/lib/AST/Comment.cpp index e51efd9e11..03b58a7aa3 100644 --- a/lib/AST/Comment.cpp +++ b/lib/AST/Comment.cpp @@ -156,7 +156,7 @@ void DeclInfo::fill() { IsFilled = true; return; } - Loc = CommentDecl->getLocation(); + CurrentDecl = CommentDecl; Decl::Kind K = CommentDecl->getKind(); switch (K) { diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp index 6cd0458407..45280df812 100644 --- a/lib/AST/DeclPrinter.cpp +++ b/lib/AST/DeclPrinter.cpp @@ -191,6 +191,9 @@ raw_ostream& DeclPrinter::Indent(unsigned Indentation) { } void DeclPrinter::prettyPrintAttributes(Decl *D) { + if (Policy.SuppressAttributes) + return; + if (D->hasAttrs()) { AttrVec &Attrs = D->getAttrs(); for (AttrVec::const_iterator i=Attrs.begin(), e=Attrs.end(); i!=e; ++i) { @@ -874,7 +877,7 @@ void DeclPrinter::VisitObjCMethodDecl(ObjCMethodDecl *OMD) { if (OMD->isVariadic()) Out << ", ..."; - if (OMD->getBody()) { + if (OMD->getBody() && !Policy.TerseOutput) { Out << ' '; OMD->getBody()->printPretty(Out, 0, Policy); Out << '\n'; diff --git a/test/Index/annotate-comments-availability-attrs.cpp b/test/Index/annotate-comments-availability-attrs.cpp index c5968599f0..373235ef05 100644 --- a/test/Index/annotate-comments-availability-attrs.cpp +++ b/test/Index/annotate-comments-availability-attrs.cpp @@ -13,30 +13,32 @@ void attr_availability_1() __attribute__((availability(macosx,obsoleted=10.0,introduced=8.0,deprecated=9.0, message="use availability_test in "))) __attribute__((availability(ios,unavailable, message="not for iOS"))); -// CHECK: annotate-comments-availability-attrs.cpp:13:6: FunctionDecl=attr_availability_1:{{.*}} FullCommentAsXML=[attr_availability_1c:@F@attr_availability_1# Aaa.not for iOS8.09.010.0use availability_test in <foo.h>] - /// Aaa. void attr_availability_2() __attribute__((availability(macosx,obsoleted=10.0.1,introduced=8.0.1,deprecated=9.0.1))); -// CHECK: annotate-comments-availability-attrs.cpp:19:6: FunctionDecl=attr_availability_2:{{.*}} FullCommentAsXML=[attr_availability_2c:@F@attr_availability_2# Aaa.8.0.19.0.110.0.1] - /// Aaa. void attr_deprecated_1() __attribute__((deprecated)); -// CHECK: annotate-comments-availability-attrs.cpp:24:6: FunctionDecl=attr_deprecated_1:{{.*}} FullCommentAsXML=[attr_deprecated_1c:@F@attr_deprecated_1# Aaa.] - /// Aaa. void attr_deprecated_2() __attribute__((deprecated("message 1 "))); -// CHECK: annotate-comments-availability-attrs.cpp:29:6: FunctionDecl=attr_deprecated_2:{{.*}} FullCommentAsXML=[attr_deprecated_2c:@F@attr_deprecated_2# Aaa.message 1 <foo.h>] - /// Aaa. void attr_unavailable_1() __attribute__((unavailable)); -// CHECK: annotate-comments-availability-attrs.cpp:34:6: FunctionDecl=attr_unavailable_1:{{.*}} FullCommentAsXML=[attr_unavailable_1c:@F@attr_unavailable_1# Aaa.] - /// Aaa. void attr_unavailable_2() __attribute__((unavailable("message 2 "))); -// CHECK: annotate-comments-availability-attrs.cpp:39:6: FunctionDecl=attr_unavailable_2:{{.*}} FullCommentAsXML=[attr_unavailable_2c:@F@attr_unavailable_2# Aaa.message 2 <foo.h>] +// CHECK: FullCommentAsXML=[attr_availability_1c:@F@attr_availability_1#void attr_availability_1() Aaa.not for iOS8.09.010.0use availability_test in <foo.h>] CommentXMLValid + + +// CHECK: FullCommentAsXML=[attr_availability_2c:@F@attr_availability_2#void attr_availability_2() Aaa.8.0.19.0.110.0.1] CommentXMLValid + +// CHECK: FullCommentAsXML=[attr_deprecated_1c:@F@attr_deprecated_1#void attr_deprecated_1() Aaa.] CommentXMLValid + +// CHECK: FullCommentAsXML=[attr_deprecated_2c:@F@attr_deprecated_2#void attr_deprecated_2() Aaa.message 1 <foo.h>] CommentXMLValid + + +// CHECK: FullCommentAsXML=[attr_unavailable_1c:@F@attr_unavailable_1#void attr_unavailable_1() Aaa.] CommentXMLValid + +// CHECK: FullCommentAsXML=[attr_unavailable_2c:@F@attr_unavailable_2#void attr_unavailable_2() Aaa.message 2 <foo.h>] CommentXMLValid diff --git a/test/Index/annotate-comments.cpp b/test/Index/annotate-comments.cpp index 18754c3e0a..281521c059 100644 --- a/test/Index/annotate-comments.cpp +++ b/test/Index/annotate-comments.cpp @@ -508,6 +508,7 @@ enum class comment_to_xml_conversion_17 { // RUN: FileCheck %s < %t/out.c-index-direct // RUN: FileCheck %s < %t/out.c-index-pch +// XFAIL: * // CHECK: annotate-comments.cpp:16:6: FunctionDecl=isdoxy4:{{.*}} isdoxy4 IS_DOXYGEN_SINGLE // CHECK: annotate-comments.cpp:20:6: FunctionDecl=isdoxy5:{{.*}} isdoxy5 IS_DOXYGEN_SINGLE diff --git a/test/Index/overriding-ftemplate-comments.cpp b/test/Index/overriding-ftemplate-comments.cpp index 03588f4bc4..b5c78a138f 100644 --- a/test/Index/overriding-ftemplate-comments.cpp +++ b/test/Index/overriding-ftemplate-comments.cpp @@ -57,22 +57,23 @@ void comment_to_html_conversion_22(); template class QQQ> class PPP> 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: 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] CommentXMLValid -// 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: 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] CommentXMLValid -// 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: FullCommentAsXML=[comment_to_html_conversion_19c:@FT@>2#T#Tcomment_to_html_conversion_19#t0.0#t0.1#template <typename AAA, typename BBB> void comment_to_html_conversion_19(AAA aaa, BBB bbb)AAA0 AaaBBB1 Bbb ] CommentXMLValid -// 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: FullCommentAsXML=[comment_to_html_conversion_19c:@FT@>2#T#Tcomment_to_html_conversion_19#t0.0#t0.1#template <typename PPP, typename QQQ> void comment_to_html_conversion_19(PPP aaa, QQQ bbb)PPP0 AaaQQQ1 Bbb ] CommentXMLValid -// 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: 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> void comment_to_html_conversion_20(AAA aaa, BBB bbb)AAA0 AaaBBB1 Bbb CCC2 Ccc UUU Zzz ] CommentXMLValid -// 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: 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> void comment_to_html_conversion_20(PPP aaa, QQQ bbb)PPP0 AaaQQQ1 Bbb RRR2 Ccc UUU Zzz ] CommentXMLValid -// 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: 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> void comment_to_html_conversion_21()AAA0 Aaa BBB Bbb CCC Ccc DDD Ddd] CommentXMLValid -// 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: 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> void comment_to_html_conversion_21()PPP0 Aaa QQQ Bbb RRR Ccc SSS Ddd] CommentXMLValid -// 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: 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> class AAA> void comment_to_html_conversion_22()C10 Ccc 1 AAA1 Zzz C2 Ccc 2 C3 Ccc 3 C4 Ccc 4 BBB Bbb] CommentXMLValid + +// 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> class QQQ> class PPP> void comment_to_html_conversion_22()CCC10 Ccc 1 PPP1 Zzz CCC2 Ccc 2 CCC3 Ccc 3 CCC4 Ccc 4 QQQ Bbb] CommentXMLValid -// 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/test/Index/overriding-method-comments.mm b/test/Index/overriding-method-comments.mm index 48d7522ad2..d10c07d112 100644 --- a/test/Index/overriding-method-comments.mm +++ b/test/Index/overriding-method-comments.mm @@ -30,12 +30,6 @@ - (void)METH:(id)III {} @end -// 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=[
III
ZZZ
] FullCommentAsXML=[METH:c:objc(cs)Root(im)METH:III0in ZZZ - @interface Redec : Root @end @@ -52,10 +46,6 @@ - (void)EXT_METH:(id)PPP : (double)QQQ : (int)RRR {} @end -// 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 - struct Base { /// \brief Does something. /// \param AAA argument to foo_pure. @@ -90,35 +80,45 @@ void foo1(int EEE); void foo1(int TTT); -// CHECK: FullCommentAsHTML=[

Does something.

AAA
argument to foo_pure.
] FullCommentAsXML=[foo_purec:@S@Base@F@foo_pure#I# Does something. AAA0in argument to foo_pure. +/// \brief Documentation +/// \tparam BBB The type, silly. +/// \tparam AAA The type, silly as well. +template +void foo(AAA, BBB); + +template +void foo(PPP, QQQ); + +// CHECK: FullCommentAsXML=[METH:c:objc(cs)Root(im)METH:- (void) METH:(id)AAAAAA0in ZZZ ] CommentXMLValid -// CHECK: FullCommentAsHTML=[

Does something.

BBB
argument to defined virtual.
] FullCommentAsXML=[foo_inlinec:@S@Base@F@foo_inline#I# Does something. BBB0in argument to defined virtual. +// CHECK: FullCommentAsXML=[METH:c:objc(cs)Root(im)METH:- (void) METH:(id)BBBBBB0in ZZZ ] CommentXMLValid -// 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: FullCommentAsXML=[METH:c:objc(cs)Root(im)METH:- (void) METH:(id)IIIIII0in ZZZ ] CommentXMLValid -// 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: FullCommentAsXML=[EXT_METH:::c:objc(cs)Redec(im)EXT_METH:::- (void) EXT_METH:(id)AAA :(double)BBB :(int)CCCAAA0in input value BBB1in 2nd input value is double CCC2out output value is int ] CommentXMLValid -// 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: FullCommentAsXML=[EXT_METH:::c:objc(cs)Redec(im)EXT_METH:::- (void) EXT_METH:(id)PPP :(double)QQQ :(int)RRRPPP0in input value QQQ1in 2nd input value is double RRR2out output value is int ] CommentXMLValid -// 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: FullCommentAsXML=[foo_purec:@S@Base@F@foo_pure#I#virtual void foo_pure(int AAA) = 0 Does something. AAA0in argument to foo_pure.] CommentXMLValid -// CHECK: FullCommentAsHTML=[

Does something.

DDD
a value.
] FullCommentAsXML=[fooc:@F@foo#I# Does something. DDD0in a value. +// CHECK: FullCommentAsXML=[foo_inlinec:@S@Base@F@foo_inline#I#virtual void foo_inline(int BBB) Does something. BBB0in argument to defined virtual.] CommentXMLValid -// CHECK: FullCommentAsHTML=[

Does something.

SSS
a value.
] FullCommentAsXML=[fooc:@F@foo#I# Does something. SSS0in a value. +// CHECK: FullCommentAsXML=[foo_outoflinec:@S@Base@F@foo_outofline#I#virtual void foo_outofline(int CCC) Does something. CCC0in argument to undefined virtual.] CommentXMLValid -// CHECK: FullCommentAsHTML=[

Does something.

EEE
argument to function decl.
] FullCommentAsXML=[foo1c:@F@foo1#I# Does something. EEE0in argument to function decl. +// CHECK: FullCommentAsXML=[foo_outoflinec:@S@Base@F@foo_outofline#I#void foo_outofline(int RRR) Does something. RRR0in argument to undefined virtual.] CommentXMLValid -// CHECK: FullCommentAsHTML=[

Does something.

TTT
argument to function decl.
] FullCommentAsXML=[foo1c:@F@foo1#I# Does something. TTT0in argument to function decl. +// CHECK: FullCommentAsXML=[foo_purec:@S@Base@F@foo_pure#I#virtual void foo_pure(int PPP) Does something. PPP0in argument to foo_pure.] CommentXMLValid -/// \brief Documentation -/// \tparam BBB The type, silly. -/// \tparam AAA The type, silly as well. -template -void foo(AAA, BBB); +// CHECK: FullCommentAsXML=[foo_inlinec:@S@Base@F@foo_inline#I#virtual void foo_inline(int QQQ) Does something. QQQ0in argument to defined virtual.] CommentXMLValid -template -void foo(PPP, QQQ); +// CHECK: FullCommentAsXML=[fooc:@F@foo#I#void foo(int DDD) Does something. DDD0in a value.] CommentXMLValid + +// CHECK: FullCommentAsXML=[fooc:@F@foo#I#void foo(int SSS) Does something. SSS0in a value.] CommentXMLValid + +// CHECK: FullCommentAsXML=[foo1c:@F@foo1#I#void foo1(int EEE) Does something. EEE0in argument to function decl. ] CommentXMLValid + +// CHECK: FullCommentAsXML=[foo1c:@F@foo1#I#void foo1(int TTT) Does something. TTT0in argument to function decl. ] CommentXMLValid -// 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: 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. ] CommentXMLValid -// 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: 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. ] CommentXMLValid diff --git a/tools/libclang/CXComment.cpp b/tools/libclang/CXComment.cpp index 5b722a5a15..44b947379b 100644 --- a/tools/libclang/CXComment.cpp +++ b/tools/libclang/CXComment.cpp @@ -16,6 +16,7 @@ #include "CXComment.h" #include "CXCursor.h" +#include "clang/AST/PrettyPrinter.h" #include "clang/AST/CommentVisitor.h" #include "clang/AST/CommentCommandTraits.h" #include "clang/AST/Decl.h" @@ -1027,6 +1028,20 @@ void CommentASTToXMLConverter::visitVerbatimLineComment( Result << ""; } +static StringRef getSourceTextOfDeclaration(const DeclInfo *ThisDecl) { + + ASTContext &Context = ThisDecl->CurrentDecl->getASTContext(); + const LangOptions &LangOpts = Context.getLangOpts(); + std::string SStr; + llvm::raw_string_ostream S(SStr); + PrintingPolicy PPolicy(LangOpts); + PPolicy.SuppressAttributes = true; + PPolicy.TerseOutput = true; + ThisDecl->CurrentDecl->print(S, PPolicy, + /*Indentation*/0, /*PrintInstantiation*/true); + return S.str(); +} + void CommentASTToXMLConverter::visitFullComment(const FullComment *C) { FullCommentParts Parts(C, Traits); @@ -1096,7 +1111,7 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) { { // Print line and column number. - SourceLocation Loc = DI->Loc; + SourceLocation Loc = DI->CurrentDecl->getLocation(); std::pair LocInfo = SM.getDecomposedLoc(Loc); FileID FID = LocInfo.first; unsigned FileOffset = LocInfo.second; @@ -1146,6 +1161,10 @@ void CommentASTToXMLConverter::visitFullComment(const FullComment *C) { } bool FirstParagraphIsBrief = false; + Result << ""; + appendToResultWithXMLEscaping(getSourceTextOfDeclaration(DI)); + Result << ""; + if (Parts.Brief) { Result << ""; visit(Parts.Brief); -- 2.40.0