Mordante created this revision. Mordante added a reviewer: gribozavr. Mordante added a project: clang. Herald added a subscriber: arphaman.
I'm not sure it should be added to the `InlineComment` group. It's not entirely a markup. Do you think it should be a in a separate group? (I also have not yet posted code for `\emoji` which is also in the `InlineComment` group.) Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D69223 Files: clang/bindings/xml/comment-xml-schema.rng clang/include/clang-c/Documentation.h clang/include/clang/AST/Comment.h clang/include/clang/AST/CommentCommands.td clang/lib/AST/CommentSema.cpp clang/lib/AST/JSONNodeDumper.cpp clang/lib/AST/TextNodeDumper.cpp clang/lib/Index/CommentToXML.cpp clang/test/Index/Inputs/CommentXML/valid-function-02.xml clang/test/Index/comment-to-html-xml-conversion.cpp clang/test/Sema/warn-documentation.cpp clang/tools/c-index-test/c-index-test.c clang/tools/libclang/CXComment.cpp
Index: clang/tools/libclang/CXComment.cpp =================================================================== --- clang/tools/libclang/CXComment.cpp +++ clang/tools/libclang/CXComment.cpp @@ -159,6 +159,9 @@ case InlineCommandComment::RenderEmphasized: return CXCommentInlineCommandRenderKind_Emphasized; + + case InlineCommandComment::RenderAnchor: + return CXCommentInlineCommandRenderKind_Anchor; } llvm_unreachable("unknown InlineCommandComment::RenderKind"); } Index: clang/tools/c-index-test/c-index-test.c =================================================================== --- clang/tools/c-index-test/c-index-test.c +++ clang/tools/c-index-test/c-index-test.c @@ -497,6 +497,9 @@ case CXCommentInlineCommandRenderKind_Emphasized: printf(" RenderEmphasized"); break; + case CXCommentInlineCommandRenderKind_Anchor: + printf(" RenderAnchor"); + break; } for (i = 0, e = clang_InlineCommandComment_getNumArgs(Comment); i != e; ++i) { Index: clang/test/Sema/warn-documentation.cpp =================================================================== --- clang/test/Sema/warn-documentation.cpp +++ clang/test/Sema/warn-documentation.cpp @@ -1057,6 +1057,13 @@ /// \a A int test_inline_no_argument_a_good(int); +// expected-warning@+1 {{'\anchor' command does not have a valid word argument}} +/// \anchor +int test_inline_no_argument_anchor_bad(int); + +/// \anchor A +int test_inline_no_argument_anchor_good(int); + // expected-warning@+1 {{'@b' command does not have a valid word argument}} /// @b int test_inline_no_argument_b_bad(int); Index: clang/test/Index/comment-to-html-xml-conversion.cpp =================================================================== --- clang/test/Index/comment-to-html-xml-conversion.cpp +++ clang/test/Index/comment-to-html-xml-conversion.cpp @@ -734,6 +734,16 @@ // CHECK-NEXT: (CXComment_Text Text=[Aaa]) // CHECK-NEXT: (CXComment_HTMLEndTag Name=[h1])))] +/// \anchor A +void comment_to_html_conversion_37(); + +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_37:{{.*}} FullCommentAsHTML=[<p class="para-brief"> <a name="A"/></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>A</anchor></Para></Abstract></Function>] +// CHECK-NEXT: CommentAST=[ +// CHECK-NEXT: (CXComment_FullComment +// CHECK-NEXT: (CXComment_Paragraph +// CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace) +// CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] RenderAnchor Arg[0]=A)))] + /// Aaa. class comment_to_xml_conversion_01 { Index: clang/test/Index/Inputs/CommentXML/valid-function-02.xml =================================================================== --- clang/test/Index/Inputs/CommentXML/valid-function-02.xml +++ clang/test/Index/Inputs/CommentXML/valid-function-02.xml @@ -9,6 +9,7 @@ <rawHTML><eee></rawHTML> <rawHTML isMalformed="0"><fff></rawHTML> <rawHTML isMalformed="1"><ggg></rawHTML>. + <anchor>hhh</anchor> </Para> </Abstract> </Function> Index: clang/lib/Index/CommentToXML.cpp =================================================================== --- clang/lib/Index/CommentToXML.cpp +++ clang/lib/Index/CommentToXML.cpp @@ -297,6 +297,12 @@ appendToResultWithHTMLEscaping(Arg0); Result << "</em>"; return; + case InlineCommandComment::RenderAnchor: + assert(C->getNumArgs() == 1); + Result << "<a name=\""; + appendToResultWithHTMLEscaping(Arg0); + Result << "\"/>"; + return; } } @@ -641,6 +647,12 @@ appendToResultWithXMLEscaping(Arg0); Result << "</emphasized>"; return; + case InlineCommandComment::RenderAnchor: + assert(C->getNumArgs() == 1); + Result << "<anchor>"; + appendToResultWithXMLEscaping(Arg0); + Result << "</anchor>"; + return; } } Index: clang/lib/AST/TextNodeDumper.cpp =================================================================== --- clang/lib/AST/TextNodeDumper.cpp +++ clang/lib/AST/TextNodeDumper.cpp @@ -489,6 +489,9 @@ case comments::InlineCommandComment::RenderEmphasized: OS << " RenderEmphasized"; break; + case comments::InlineCommandComment::RenderAnchor: + OS << " RenderAnchor"; + break; } for (unsigned i = 0, e = C->getNumArgs(); i != e; ++i) Index: clang/lib/AST/JSONNodeDumper.cpp =================================================================== --- clang/lib/AST/JSONNodeDumper.cpp +++ clang/lib/AST/JSONNodeDumper.cpp @@ -1488,6 +1488,9 @@ case comments::InlineCommandComment::RenderMonospaced: JOS.attribute("renderKind", "monospaced"); break; + case comments::InlineCommandComment::RenderAnchor: + JOS.attribute("renderKind", "anchor"); + break; } llvm::json::Array Args; Index: clang/lib/AST/CommentSema.cpp =================================================================== --- clang/lib/AST/CommentSema.cpp +++ clang/lib/AST/CommentSema.cpp @@ -1127,6 +1127,7 @@ .Case("b", InlineCommandComment::RenderBold) .Cases("c", "p", InlineCommandComment::RenderMonospaced) .Cases("a", "e", "em", InlineCommandComment::RenderEmphasized) + .Case("anchor", InlineCommandComment::RenderAnchor) .Default(InlineCommandComment::RenderNormal); } Index: clang/include/clang/AST/CommentCommands.td =================================================================== --- clang/include/clang/AST/CommentCommands.td +++ clang/include/clang/AST/CommentCommands.td @@ -81,12 +81,13 @@ // InlineCommand //===----------------------------------------------------------------------===// -def B : InlineCommand<"b">; -def C : InlineCommand<"c">; -def P : InlineCommand<"p">; -def A : InlineCommand<"a">; -def E : InlineCommand<"e">; -def Em : InlineCommand<"em">; +def B : InlineCommand<"b">; +def C : InlineCommand<"c">; +def P : InlineCommand<"p">; +def A : InlineCommand<"a">; +def E : InlineCommand<"e">; +def Em : InlineCommand<"em">; +def Anchor : InlineCommand<"anchor">; //===----------------------------------------------------------------------===// // BlockCommand Index: clang/include/clang/AST/Comment.h =================================================================== --- clang/include/clang/AST/Comment.h +++ clang/include/clang/AST/Comment.h @@ -94,10 +94,11 @@ unsigned : NumInlineContentCommentBits; - unsigned RenderKind : 2; + unsigned RenderKind : 3; + unsigned CommandID : CommandInfo::NumCommandIDBits; }; - enum { NumInlineCommandCommentBits = NumInlineContentCommentBits + 2 + + enum { NumInlineCommandCommentBits = NumInlineContentCommentBits + 3 + CommandInfo::NumCommandIDBits }; class HTMLTagCommentBitfields { @@ -310,7 +311,8 @@ RenderNormal, RenderBold, RenderMonospaced, - RenderEmphasized + RenderEmphasized, + RenderAnchor }; protected: Index: clang/include/clang-c/Documentation.h =================================================================== --- clang/include/clang-c/Documentation.h +++ clang/include/clang-c/Documentation.h @@ -182,7 +182,13 @@ * Command argument should be rendered emphasized (typically italic * font). */ - CXCommentInlineCommandRenderKind_Emphasized + CXCommentInlineCommandRenderKind_Emphasized, + + /** + * Command argument should not be rendered (since it is a only defines + * an anchor). + */ + CXCommentInlineCommandRenderKind_Anchor }; /** Index: clang/bindings/xml/comment-xml-schema.rng =================================================================== --- clang/bindings/xml/comment-xml-schema.rng +++ clang/bindings/xml/comment-xml-schema.rng @@ -579,6 +579,12 @@ <param name="pattern">.*\S.*</param> </data> </element> + <element name="anchor"> + <!-- Non-empty text content. --> + <data type="string"> + <param name="pattern">.*\S.*</param> + </data> + </element> <element name="rawHTML"> <optional> <!-- If not specified, the default value is 'false'. -->
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits