Skip to content

Commit ea7b933

Browse files
committed
Update XML output routine for Throws commands to fix XML validation
XML validation was failing due to the Exception XML being empty, since the actual exception type was being parsed as an argument instead of as a ParagraphComment. This was a result of the change we made to argument parsing. As a result, I updated the XML output to still output the argument text in the Para XML, as it was emitted before.
1 parent 7da378b commit ea7b933

File tree

2 files changed

+59
-17
lines changed

2 files changed

+59
-17
lines changed

clang/lib/Index/CommentToXML.cpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ class CommentASTToXMLConverter :
546546
void visitParagraphComment(const ParagraphComment *C);
547547

548548
void appendParagraphCommentWithKind(const ParagraphComment *C,
549-
StringRef Kind);
549+
StringRef ParagraphKind,
550+
StringRef PrependBodyText);
550551

551552
void visitBlockCommandComment(const BlockCommandComment *C);
552553
void visitParamCommandComment(const ParamCommandComment *C);
@@ -680,24 +681,27 @@ CommentASTToXMLConverter::visitHTMLEndTagComment(const HTMLEndTagComment *C) {
680681
Result << ">&lt;/" << C->getTagName() << "&gt;</rawHTML>";
681682
}
682683

683-
void
684-
CommentASTToXMLConverter::visitParagraphComment(const ParagraphComment *C) {
685-
appendParagraphCommentWithKind(C, StringRef());
684+
void CommentASTToXMLConverter::visitParagraphComment(
685+
const ParagraphComment *C) {
686+
appendParagraphCommentWithKind(C, StringRef(), StringRef());
686687
}
687688

688689
void CommentASTToXMLConverter::appendParagraphCommentWithKind(
689-
const ParagraphComment *C,
690-
StringRef ParagraphKind) {
691-
if (C->isWhitespace())
690+
const ParagraphComment *C, StringRef ParagraphKind,
691+
StringRef PrependBodyText) {
692+
if (C->isWhitespace() && PrependBodyText.empty())
692693
return;
693694

694695
if (ParagraphKind.empty())
695696
Result << "<Para>";
696697
else
697698
Result << "<Para kind=\"" << ParagraphKind << "\">";
698699

699-
for (Comment::child_iterator I = C->child_begin(), E = C->child_end();
700-
I != E; ++I) {
700+
if (!PrependBodyText.empty())
701+
Result << PrependBodyText << " ";
702+
703+
for (Comment::child_iterator I = C->child_begin(), E = C->child_end(); I != E;
704+
++I) {
701705
visit(*I);
702706
}
703707
Result << "</Para>";
@@ -706,8 +710,15 @@ void CommentASTToXMLConverter::appendParagraphCommentWithKind(
706710
void CommentASTToXMLConverter::visitBlockCommandComment(
707711
const BlockCommandComment *C) {
708712
StringRef ParagraphKind;
713+
StringRef ExceptionType;
709714

710-
switch (C->getCommandID()) {
715+
const unsigned CommandID = C->getCommandID();
716+
const CommandInfo *Info = Traits.getCommandInfo(CommandID);
717+
if (Info->IsThrowsCommand && C->getNumArgs() > 0) {
718+
ExceptionType = C->getArgText(0);
719+
}
720+
721+
switch (CommandID) {
711722
case CommandTraits::KCI_attention:
712723
case CommandTraits::KCI_author:
713724
case CommandTraits::KCI_authors:
@@ -732,7 +743,8 @@ void CommentASTToXMLConverter::visitBlockCommandComment(
732743
break;
733744
}
734745

735-
appendParagraphCommentWithKind(C->getParagraph(), ParagraphKind);
746+
appendParagraphCommentWithKind(C->getParagraph(), ParagraphKind,
747+
ExceptionType);
736748
}
737749

738750
void CommentASTToXMLConverter::visitParamCommandComment(

clang/test/Index/comment-to-html-xml-conversion.cpp

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ void comment_to_xml_conversion_todo_4();
10461046
/// Aaa.
10471047
/// \throws Bbb.
10481048
void comment_to_xml_conversion_exceptions_1();
1049-
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_1:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_1</Name><USR>c:@F@comment_to_xml_conversion_exceptions_1#</USR><Declaration>void comment_to_xml_conversion_exceptions_1()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions></Exceptions></Function>]
1049+
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_1:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_1</Name><USR>c:@F@comment_to_xml_conversion_exceptions_1#</USR><Declaration>void comment_to_xml_conversion_exceptions_1()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions><Para>Bbb. </Para></Exceptions></Function>]
10501050
// CHECK-NEXT: CommentAST=[
10511051
// CHECK-NEXT: (CXComment_FullComment
10521052
// CHECK-NEXT: (CXComment_Paragraph
@@ -1058,7 +1058,7 @@ void comment_to_xml_conversion_exceptions_1();
10581058
/// Aaa.
10591059
/// \throw Bbb.
10601060
void comment_to_xml_conversion_exceptions_2();
1061-
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_2:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_2</Name><USR>c:@F@comment_to_xml_conversion_exceptions_2#</USR><Declaration>void comment_to_xml_conversion_exceptions_2()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions></Exceptions></Function>]
1061+
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_2:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_2</Name><USR>c:@F@comment_to_xml_conversion_exceptions_2#</USR><Declaration>void comment_to_xml_conversion_exceptions_2()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions><Para>Bbb. </Para></Exceptions></Function>]
10621062
// CHECK-NEXT: CommentAST=[
10631063
// CHECK-NEXT: (CXComment_FullComment
10641064
// CHECK-NEXT: (CXComment_Paragraph
@@ -1070,7 +1070,7 @@ void comment_to_xml_conversion_exceptions_2();
10701070
/// Aaa.
10711071
/// \exception Bbb.
10721072
void comment_to_xml_conversion_exceptions_3();
1073-
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_3:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_3</Name><USR>c:@F@comment_to_xml_conversion_exceptions_3#</USR><Declaration>void comment_to_xml_conversion_exceptions_3()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions></Exceptions></Function>]
1073+
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_3:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_3</Name><USR>c:@F@comment_to_xml_conversion_exceptions_3#</USR><Declaration>void comment_to_xml_conversion_exceptions_3()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions><Para>Bbb. </Para></Exceptions></Function>]
10741074
// CHECK-NEXT: CommentAST=[
10751075
// CHECK-NEXT: (CXComment_FullComment
10761076
// CHECK-NEXT: (CXComment_Paragraph
@@ -1084,7 +1084,7 @@ void comment_to_xml_conversion_exceptions_3();
10841084
/// \throws Ccc.
10851085
/// \throws Ddd.
10861086
void comment_to_xml_conversion_exceptions_4();
1087-
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_4:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_4</Name><USR>c:@F@comment_to_xml_conversion_exceptions_4#</USR><Declaration>void comment_to_xml_conversion_exceptions_4()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions></Exceptions></Function>]
1087+
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_4:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_4</Name><USR>c:@F@comment_to_xml_conversion_exceptions_4#</USR><Declaration>void comment_to_xml_conversion_exceptions_4()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions><Para>Bbb. </Para><Para>Ccc. </Para><Para>Ddd. </Para></Exceptions></Function>]
10881088
// CHECK-NEXT: CommentAST=[
10891089
// CHECK-NEXT: (CXComment_FullComment
10901090
// CHECK-NEXT: (CXComment_Paragraph
@@ -1101,7 +1101,7 @@ void comment_to_xml_conversion_exceptions_4();
11011101
/// \throws Bbb.
11021102
/// \throw Ccc.
11031103
void comment_to_xml_conversion_exceptions_5();
1104-
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_5:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_5</Name><USR>c:@F@comment_to_xml_conversion_exceptions_5#</USR><Declaration>void comment_to_xml_conversion_exceptions_5()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions></Exceptions></Function>]
1104+
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_5:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_5</Name><USR>c:@F@comment_to_xml_conversion_exceptions_5#</USR><Declaration>void comment_to_xml_conversion_exceptions_5()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions><Para>Bbb. </Para><Para>Ccc. </Para></Exceptions></Function>]
11051105
// CHECK-NEXT: CommentAST=[
11061106
// CHECK-NEXT: (CXComment_FullComment
11071107
// CHECK-NEXT: (CXComment_Paragraph
@@ -1112,5 +1112,35 @@ void comment_to_xml_conversion_exceptions_5();
11121112
// CHECK-NEXT: (CXComment_BlockCommand CommandName=[throw] Arg[0]=Ccc.
11131113
// CHECK-NEXT: (CXComment_Paragraph IsWhitespace)))]
11141114

1115-
#endif
1115+
/// Aaa.
1116+
/// \throws Bbb subsequent arg text
1117+
void comment_to_xml_conversion_exceptions_6();
1118+
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_6:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_6</Name><USR>c:@F@comment_to_xml_conversion_exceptions_6#</USR><Declaration>void comment_to_xml_conversion_exceptions_6()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions><Para>Bbb subsequent arg text</Para></Exceptions></Function>]
1119+
// CHECK-NEXT: CommentAST=[
1120+
// CHECK-NEXT: (CXComment_FullComment
1121+
// CHECK-NEXT: (CXComment_Paragraph
1122+
// CHECK-NEXT: (CXComment_Text Text=[ Aaa.] HasTrailingNewline)
1123+
// CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace))
1124+
// CHECK-NEXT: (CXComment_BlockCommand CommandName=[throws] Arg[0]=Bbb
1125+
// CHECK-NEXT: (CXComment_Paragraph
1126+
// CHECK-NEXT: (CXComment_Text Text=[subsequent arg text]))))]
11161127

1128+
/// Aaa.
1129+
/// \throws Bbb subsequent arg text
1130+
/// \throw Ccc subsequent arg text
1131+
void comment_to_xml_conversion_exceptions_7();
1132+
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:6: FunctionDecl=comment_to_xml_conversion_exceptions_7:{{.*}} FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-1]]" column="6"><Name>comment_to_xml_conversion_exceptions_7</Name><USR>c:@F@comment_to_xml_conversion_exceptions_7#</USR><Declaration>void comment_to_xml_conversion_exceptions_7()</Declaration><Abstract><Para> Aaa. </Para></Abstract><Exceptions><Para>Bbb subsequent arg text </Para><Para>Ccc subsequent arg text</Para></Exceptions></Function>]
1133+
// CHECK-NEXT: CommentAST=[
1134+
// CHECK-NEXT: (CXComment_FullComment
1135+
// CHECK-NEXT: (CXComment_Paragraph
1136+
// CHECK-NEXT: (CXComment_Text Text=[ Aaa.] HasTrailingNewline)
1137+
// CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace))
1138+
// CHECK-NEXT: (CXComment_BlockCommand CommandName=[throws] Arg[0]=Bbb
1139+
// CHECK-NEXT: (CXComment_Paragraph
1140+
// CHECK-NEXT: (CXComment_Text Text=[subsequent arg text] HasTrailingNewline)
1141+
// CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)))
1142+
// CHECK-NEXT: (CXComment_BlockCommand CommandName=[throw] Arg[0]=Ccc
1143+
// CHECK-NEXT: (CXComment_Paragraph
1144+
// CHECK-NEXT: (CXComment_Text Text=[subsequent arg text]))))]
1145+
1146+
#endif

0 commit comments

Comments
 (0)