Skip to content

Commit be1a9b3

Browse files
committedDec 21, 2019
[Wdocumentation] Implement \anchor
Differential revision: https://reviews.llvm.org/D69223
1 parent 2947da9 commit be1a9b3

15 files changed

+80
-10
lines changed
 

‎clang/bindings/xml/comment-xml-schema.rng

+8
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,14 @@
579579
<param name="pattern">.*\S.*</param>
580580
</data>
581581
</element>
582+
<element name="anchor">
583+
<attribute name="id">
584+
<data type="string">
585+
<!-- Non-empty text content without whitespace. -->
586+
<param name="pattern">\S+</param>
587+
</data>
588+
</attribute>
589+
</element>
582590
<element name="rawHTML">
583591
<optional>
584592
<!-- If not specified, the default value is 'false'. -->

‎clang/include/clang-c/Documentation.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ enum CXCommentInlineCommandRenderKind {
181181
* Command argument should be rendered emphasized (typically italic
182182
* font).
183183
*/
184-
CXCommentInlineCommandRenderKind_Emphasized
184+
CXCommentInlineCommandRenderKind_Emphasized,
185+
186+
/**
187+
* Command argument should not be rendered (since it only defines an anchor).
188+
*/
189+
CXCommentInlineCommandRenderKind_Anchor
185190
};
186191

187192
/**

‎clang/include/clang/AST/Comment.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ class Comment {
9494

9595
unsigned : NumInlineContentCommentBits;
9696

97-
unsigned RenderKind : 2;
97+
unsigned RenderKind : 3;
98+
9899
unsigned CommandID : CommandInfo::NumCommandIDBits;
99100
};
100-
enum { NumInlineCommandCommentBits = NumInlineContentCommentBits + 2 +
101+
enum { NumInlineCommandCommentBits = NumInlineContentCommentBits + 3 +
101102
CommandInfo::NumCommandIDBits };
102103

103104
class HTMLTagCommentBitfields {
@@ -310,7 +311,8 @@ class InlineCommandComment : public InlineContentComment {
310311
RenderNormal,
311312
RenderBold,
312313
RenderMonospaced,
313-
RenderEmphasized
314+
RenderEmphasized,
315+
RenderAnchor
314316
};
315317

316318
protected:

‎clang/include/clang/AST/CommentCommands.td

+7-6
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ class RecordLikeDeclarationVerbatimLineCommand<string name> :
8181
// InlineCommand
8282
//===----------------------------------------------------------------------===//
8383

84-
def B : InlineCommand<"b">;
85-
def C : InlineCommand<"c">;
86-
def P : InlineCommand<"p">;
87-
def A : InlineCommand<"a">;
88-
def E : InlineCommand<"e">;
89-
def Em : InlineCommand<"em">;
84+
def B : InlineCommand<"b">;
85+
def C : InlineCommand<"c">;
86+
def P : InlineCommand<"p">;
87+
def A : InlineCommand<"a">;
88+
def E : InlineCommand<"e">;
89+
def Em : InlineCommand<"em">;
90+
def Anchor : InlineCommand<"anchor">;
9091

9192
//===----------------------------------------------------------------------===//
9293
// BlockCommand

‎clang/lib/AST/CommentSema.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ Sema::getInlineCommandRenderKind(StringRef Name) const {
11431143
.Case("b", InlineCommandComment::RenderBold)
11441144
.Cases("c", "p", InlineCommandComment::RenderMonospaced)
11451145
.Cases("a", "e", "em", InlineCommandComment::RenderEmphasized)
1146+
.Case("anchor", InlineCommandComment::RenderAnchor)
11461147
.Default(InlineCommandComment::RenderNormal);
11471148
}
11481149

‎clang/lib/AST/JSONNodeDumper.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,9 @@ void JSONNodeDumper::visitInlineCommandComment(
15181518
case comments::InlineCommandComment::RenderMonospaced:
15191519
JOS.attribute("renderKind", "monospaced");
15201520
break;
1521+
case comments::InlineCommandComment::RenderAnchor:
1522+
JOS.attribute("renderKind", "anchor");
1523+
break;
15211524
}
15221525

15231526
llvm::json::Array Args;

‎clang/lib/AST/TextNodeDumper.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@ void TextNodeDumper::visitInlineCommandComment(
489489
case comments::InlineCommandComment::RenderEmphasized:
490490
OS << " RenderEmphasized";
491491
break;
492+
case comments::InlineCommandComment::RenderAnchor:
493+
OS << " RenderAnchor";
494+
break;
492495
}
493496

494497
for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i)

‎clang/lib/Index/CommentToXML.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ void CommentASTToHTMLConverter::visitInlineCommandComment(
297297
appendToResultWithHTMLEscaping(Arg0);
298298
Result << "</em>";
299299
return;
300+
case InlineCommandComment::RenderAnchor:
301+
assert(C->getNumArgs() == 1);
302+
Result << "<span id=\"" << Arg0 << "\"></span>";
303+
return;
300304
}
301305
}
302306

@@ -641,6 +645,10 @@ void CommentASTToXMLConverter::visitInlineCommandComment(
641645
appendToResultWithXMLEscaping(Arg0);
642646
Result << "</emphasized>";
643647
return;
648+
case InlineCommandComment::RenderAnchor:
649+
assert(C->getNumArgs() == 1);
650+
Result << "<anchor id=\"" << Arg0 << "\"></anchor>";
651+
return;
644652
}
645653
}
646654

‎clang/test/AST/ast-dump-comment.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ int Test_InlineCommandComment;
4747
// CHECK: VarDecl{{.*}}Test_InlineCommandComment
4848
// CHECK: InlineCommandComment{{.*}} Name="c" RenderMonospaced Arg[0]="Aaa"
4949

50+
/// \anchor Aaa
51+
int Test_InlineCommandCommentAnchor;
52+
// CHECK: VarDecl{{.*}}Test_InlineCommandComment
53+
// CHECK: InlineCommandComment{{.*}} Name="anchor" RenderAnchor Arg[0]="Aaa"
54+
5055
/// <a>Aaa</a>
5156
/// <br/>
5257
int Test_HTMLTagComment;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Namespace>
3+
<Name>aaa</Name>
4+
<Abstract>
5+
<Para>
6+
<anchor id="aaa"></anchor>
7+
</Para>
8+
</Abstract>
9+
</Namespace>

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

+10
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,16 @@ void comment_to_html_conversion_36();
734734
// CHECK-NEXT: (CXComment_Text Text=[Aaa])
735735
// CHECK-NEXT: (CXComment_HTMLEndTag Name=[h1])))]
736736

737+
/// \anchor A
738+
void comment_to_html_conversion_37();
739+
740+
// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_37:{{.*}} FullCommentAsHTML=[<p class="para-brief"> <span id="A"></span></p>] FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="6"><Name>comment_to_html_conversion_37</Name><USR>c:@F@comment_to_html_conversion_37#</USR><Declaration>void comment_to_html_conversion_37()</Declaration><Abstract><Para> <anchor id="A"></anchor></Para></Abstract></Function>]
741+
// CHECK-NEXT: CommentAST=[
742+
// CHECK-NEXT: (CXComment_FullComment
743+
// CHECK-NEXT: (CXComment_Paragraph
744+
// CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace)
745+
// CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] RenderAnchor Arg[0]=A)))]
746+
737747

738748
/// Aaa.
739749
class comment_to_xml_conversion_01 {

‎clang/test/Index/comment-xml-schema.c

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
// RUN: xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/valid-enum-01.xml
3434
//
3535
// RUN: xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/valid-para-kind-01.xml
36+
//
37+
// RUN: xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/valid-inline-command-01.xml
3638

3739
// RUN: not xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/invalid-function-01.xml 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID
3840
// RUN: not xmllint --noout --relaxng %S/../../bindings/xml/comment-xml-schema.rng %S/Inputs/CommentXML/invalid-function-02.xml 2>&1 | FileCheck %s -check-prefix=CHECK-INVALID

‎clang/test/Sema/warn-documentation.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,13 @@ int test_inline_no_argument_a_bad(int);
11021102
/// \a A
11031103
int test_inline_no_argument_a_good(int);
11041104

1105+
// expected-warning@+1 {{'\anchor' command does not have a valid word argument}}
1106+
/// \anchor
1107+
int test_inline_no_argument_anchor_bad(int);
1108+
1109+
/// \anchor A
1110+
int test_inline_no_argument_anchor_good(int);
1111+
11051112
// expected-warning@+1 {{'@b' command does not have a valid word argument}}
11061113
/// @b
11071114
int test_inline_no_argument_b_bad(int);

‎clang/tools/c-index-test/c-index-test.c

+3
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ static void DumpCXCommentInternal(struct CommentASTDumpingContext *Ctx,
497497
case CXCommentInlineCommandRenderKind_Emphasized:
498498
printf(" RenderEmphasized");
499499
break;
500+
case CXCommentInlineCommandRenderKind_Anchor:
501+
printf(" RenderAnchor");
502+
break;
500503
}
501504
for (i = 0, e = clang_InlineCommandComment_getNumArgs(Comment);
502505
i != e; ++i) {

‎clang/tools/libclang/CXComment.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ clang_InlineCommandComment_getRenderKind(CXComment CXC) {
159159

160160
case InlineCommandComment::RenderEmphasized:
161161
return CXCommentInlineCommandRenderKind_Emphasized;
162+
163+
case InlineCommandComment::RenderAnchor:
164+
return CXCommentInlineCommandRenderKind_Anchor;
162165
}
163166
llvm_unreachable("unknown InlineCommandComment::RenderKind");
164167
}

0 commit comments

Comments
 (0)
Please sign in to comment.