Skip to content

Commit 196554d

Browse files
committed
Comment parsing: Complete list of Doxygen commands
These should be all the commands from [1] except those that are marked obsolete, and "link" / "endlink", as that conflicts with the existing HeaderDoc pair "link / "/link". For some commands we don't have the ideal category, but it should work good enough for most cases. There seems to be no existing test for most commands (except the ones interpreted by -Wdocumentation), and to some extent such a test wouldn't look very interesting. But I added a test for the correct parsing of formulas, as they're a bit special. And I had to adapt comment-lots-of-unknown-commands.c because typo correction was kicking in and recognizing some of the commands. This should fix a couple of reported bugs: PR17437, PR19581, PR24062 (partially, no diagnostic for matching cond/endcond), PR32909, PR37813, PR44243 (partially, [email protected] must be addressed separately). [1] https://www.doxygen.nl/manual/commands.html Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D111190
1 parent 68072a7 commit 196554d

File tree

6 files changed

+145
-15
lines changed

6 files changed

+145
-15
lines changed

clang/include/clang/AST/CommentCommands.td

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,21 @@ def P : InlineCommand<"p">;
8787
def A : InlineCommand<"a">;
8888
def E : InlineCommand<"e">;
8989
def Em : InlineCommand<"em">;
90-
def Ref : InlineCommand<"ref">;
91-
def Anchor : InlineCommand<"anchor">;
90+
def Emoji : InlineCommand<"emoji">;
91+
92+
def Anchor : InlineCommand<"anchor">;
93+
def Ref : InlineCommand<"ref">;
94+
def RefItem : InlineCommand<"refitem">;
95+
def Cite : InlineCommand<"cite">;
96+
97+
def CopyBrief : InlineCommand<"copybrief">;
98+
def CopyDetails : InlineCommand<"copydetails">;
99+
def CopyDoc : InlineCommand<"copydoc">;
100+
101+
// Typically not used inline, but they take a single word.
102+
def Extends : InlineCommand<"extends">;
103+
def Implements : InlineCommand<"implements">;
104+
def MemberOf : InlineCommand<"memberof">;
92105

93106
//===----------------------------------------------------------------------===//
94107
// BlockCommand
@@ -145,9 +158,11 @@ def Retval : BlockCommand<"retval">;
145158
def Sa : BlockCommand<"sa">;
146159
def See : BlockCommand<"see">;
147160
def Since : BlockCommand<"since">;
161+
def Test : BlockCommand<"test">;
148162
def Todo : BlockCommand<"todo">;
149163
def Version : BlockCommand<"version">;
150164
def Warning : BlockCommand<"warning">;
165+
def XRefItem : BlockCommand<"xrefitem">;
151166
// HeaderDoc commands
152167
def Abstract : BlockCommand<"abstract"> { let IsBriefCommand = 1; }
153168
def ClassDesign : RecordLikeDetailCommand<"classdesign">;
@@ -170,6 +185,8 @@ def SuperClass : RecordLikeDetailCommand<"superclass">;
170185

171186
defm Code : VerbatimBlockCommand<"code", "endcode">;
172187
defm Verbatim : VerbatimBlockCommand<"verbatim", "endverbatim">;
188+
189+
defm DocbookOnly : VerbatimBlockCommand<"docbookonly", "enddocbookonly">;
173190
defm Htmlonly : VerbatimBlockCommand<"htmlonly", "endhtmlonly">;
174191
defm Latexonly : VerbatimBlockCommand<"latexonly", "endlatexonly">;
175192
defm Xmlonly : VerbatimBlockCommand<"xmlonly", "endxmlonly">;
@@ -178,10 +195,19 @@ defm Rtfonly : VerbatimBlockCommand<"rtfonly", "endrtfonly">;
178195

179196
defm Dot : VerbatimBlockCommand<"dot", "enddot">;
180197
defm Msc : VerbatimBlockCommand<"msc", "endmsc">;
198+
defm Uml : VerbatimBlockCommand<"startuml", "enduml">;
199+
200+
// Actually not verbatim blocks, we should also parse commands within them.
201+
defm Internal : VerbatimBlockCommand<"internal", "endinternal">;
202+
// TODO: conflicts with HeaderDoc link, /link.
203+
//defm Link : VerbatimBlockCommand<"link", "endlink">;
204+
defm ParBlock : VerbatimBlockCommand<"parblock", "endparblock">;
205+
defm SecRefList : VerbatimBlockCommand<"secreflist", "endsecreflist">;
181206

182207
// These three commands have special support in CommentLexer to recognize their
183208
// names.
184209
def FDollar : VerbatimBlockCommand<"f$">; // Inline LaTeX formula
210+
defm FParen : VerbatimBlockCommand<"f(", "f)">; // Inline LaTeX text
185211
defm FBracket : VerbatimBlockCommand<"f[", "f]">; // Displayed LaTeX formula
186212
defm FBrace : VerbatimBlockCommand<"f{", "f}">; // LaTeX environment
187213

@@ -199,11 +225,18 @@ def Addtogroup : VerbatimLineCommand<"addtogroup">;
199225
def Weakgroup : VerbatimLineCommand<"weakgroup">;
200226
def Name : VerbatimLineCommand<"name">;
201227

228+
// These actually take a single word, but it's optional.
229+
// And they're used on a separate line typically, not inline.
230+
def Dir : VerbatimLineCommand<"dir">;
231+
def File : VerbatimLineCommand<"file">;
232+
202233
def Section : VerbatimLineCommand<"section">;
203234
def Subsection : VerbatimLineCommand<"subsection">;
204235
def Subsubsection : VerbatimLineCommand<"subsubsection">;
205236
def Paragraph : VerbatimLineCommand<"paragraph">;
237+
def TableOfContents : VerbatimLineCommand<"tableofcontents">;
206238

239+
def Page : VerbatimLineCommand<"page">;
207240
def Mainpage : VerbatimLineCommand<"mainpage">;
208241
def Subpage : VerbatimLineCommand<"subpage">;
209242

@@ -212,13 +245,79 @@ def Related : VerbatimLineCommand<"related">;
212245
def RelatesAlso : VerbatimLineCommand<"relatesalso">;
213246
def RelatedAlso : VerbatimLineCommand<"relatedalso">;
214247

248+
def AddIndex : VerbatimLineCommand<"addindex">;
249+
250+
// These take a single argument mostly, but since they include a file they'll
251+
// typically be on their own line.
252+
def DocbookInclude : VerbatimLineCommand<"docbookinclude">;
253+
def DontInclude : VerbatimLineCommand<"dontinclude">;
254+
def Example : VerbatimLineCommand<"example">;
255+
def HtmlInclude : VerbatimLineCommand<"htmlinclude">;
256+
def Include : VerbatimLineCommand<"include">;
257+
def ManInclude : VerbatimLineCommand<"maninclude">;
258+
def LatexInclude : VerbatimLineCommand<"latexinclude">;
259+
def RtfInclude : VerbatimLineCommand<"rtfinclude">;
260+
def Snippet : VerbatimLineCommand<"snippet">;
261+
def VerbInclude : VerbatimLineCommand<"verbinclude">;
262+
def XmlInclude : VerbatimLineCommand<"xmlinclude">;
263+
264+
def Image : VerbatimLineCommand<"image">;
265+
def DotFile : VerbatimLineCommand<"dotfile">;
266+
def MscFile : VerbatimLineCommand<"mscfile">;
267+
def DiaFile : VerbatimLineCommand<"diafile">;
268+
269+
def Line : VerbatimLineCommand<"line">;
270+
def Skip : VerbatimLineCommand<"skip">;
271+
def SkipLine : VerbatimLineCommand<"skipline">;
272+
def Until : VerbatimLineCommand<"until">;
273+
274+
def NoOp : VerbatimLineCommand<"noop">;
275+
276+
// These have actually no arguments, but we can treat them as line commands.
277+
def CallGraph : VerbatimLineCommand<"callgraph">;
278+
def HideCallGraph : VerbatimLineCommand<"hidecallgraph">;
279+
def CallerGraph : VerbatimLineCommand<"callergraph">;
280+
def HideCallerGraph : VerbatimLineCommand<"hidecallergraph">;
281+
def ShowInitializer : VerbatimLineCommand<"showinitializer">;
282+
def HideInitializer : VerbatimLineCommand<"hideinitializer">;
283+
def ShowRefBy : VerbatimLineCommand<"showrefby">;
284+
def HideRefBy : VerbatimLineCommand<"hiderefby">;
285+
def ShowRefs : VerbatimLineCommand<"showrefs">;
286+
def HideRefs : VerbatimLineCommand<"hiderefs">;
287+
288+
// These also have no argument.
289+
def Private : VerbatimLineCommand<"private">;
290+
def Protected : VerbatimLineCommand<"protected">;
291+
def Public : VerbatimLineCommand<"public">;
292+
def Pure : VerbatimLineCommand<"pure">;
293+
def Static : VerbatimLineCommand<"static">;
294+
295+
// These also have no argument.
296+
def NoSubgrouping : VerbatimLineCommand<"nosubgrouping">;
297+
def PrivateSection : VerbatimLineCommand<"privatesection">;
298+
def ProtectedSection : VerbatimLineCommand<"protectedsection">;
299+
def PublicSection : VerbatimLineCommand<"publicsection">;
300+
301+
// We might also build proper support for if/ifnot/else/elseif/endif.
302+
def If : VerbatimLineCommand<"if">;
303+
def IfNot : VerbatimLineCommand<"ifnot">;
304+
def Else : VerbatimLineCommand<"else">;
305+
def ElseIf : VerbatimLineCommand<"elseif">;
306+
def Endif : VerbatimLineCommand<"endif">;
307+
308+
// Not treated as VerbatimBlockCommand because it spans multiple comments.
309+
def Cond : VerbatimLineCommand<"cond">;
310+
def EndCond : VerbatimLineCommand<"endcond">;
311+
215312
//===----------------------------------------------------------------------===//
216313
// DeclarationVerbatimLineCommand
217314
//===----------------------------------------------------------------------===//
218315

219316
// Doxygen commands.
317+
def Concept : DeclarationVerbatimLineCommand<"concept">;
220318
def Def : DeclarationVerbatimLineCommand<"def">;
221319
def Fn : DeclarationVerbatimLineCommand<"fn">;
320+
def IDLExcept : DeclarationVerbatimLineCommand<"idlexcept">;
222321
def Namespace : DeclarationVerbatimLineCommand<"namespace">;
223322
def Overload : DeclarationVerbatimLineCommand<"overload">;
224323
def Property : DeclarationVerbatimLineCommand<"property">;

clang/lib/AST/CommentLexer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,11 @@ void Lexer::lexCommentText(Token &T) {
392392
unsigned Length = TokenPtr - (BufferPtr + 1);
393393

394394
// Hardcoded support for lexing LaTeX formula commands
395-
// \f$ \f[ \f] \f{ \f} as a single command.
395+
// \f$ \f( \f) \f[ \f] \f{ \f} as a single command.
396396
if (Length == 1 && TokenPtr[-1] == 'f' && TokenPtr != CommentEnd) {
397397
C = *TokenPtr;
398-
if (C == '$' || C == '[' || C == ']' || C == '{' || C == '}') {
398+
if (C == '$' || C == '(' || C == ')' || C == '[' || C == ']' ||
399+
C == '{' || C == '}') {
399400
TokenPtr++;
400401
Length++;
401402
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,22 @@ int Test_HTMLTagComment;
7676
/// \verbatim
7777
/// Aaa
7878
/// \endverbatim
79+
/// \f$ a \f$
80+
/// \f( b \f)
81+
/// \f[ c \f]
82+
/// \f{env}{ c \f}
7983
int Test_VerbatimBlockComment;
8084
// CHECK: VarDecl{{.*}}Test_VerbatimBlockComment
8185
// CHECK: VerbatimBlockComment{{.*}} Name="verbatim" CloseName="endverbatim"
8286
// CHECK-NEXT: VerbatimBlockLineComment{{.*}} Text=" Aaa"
87+
// CHECK: VerbatimBlockComment{{.*}} Name="f$" CloseName="f$"
88+
// CHECK-NEXT: VerbatimBlockLineComment{{.*}} Text=" a "
89+
// CHECK: VerbatimBlockComment{{.*}} Name="f(" CloseName="f)"
90+
// CHECK-NEXT: VerbatimBlockLineComment{{.*}} Text=" b "
91+
// CHECK: VerbatimBlockComment{{.*}} Name="f[" CloseName="f]"
92+
// CHECK-NEXT: VerbatimBlockLineComment{{.*}} Text=" c "
93+
// CHECK: VerbatimBlockComment{{.*}} Name="f{" CloseName="f}"
94+
// CHECK-NEXT: VerbatimBlockLineComment{{.*}} Text="env}{ c "
8395

8496
/// \param ... More arguments
8597
template<typename T>

clang/test/Index/comment-lots-of-unknown-commands.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
@ien
4040
@fr
4141
@en
42-
@tet
42+
@teq
4343
@le
4444
@L
4545
@os
@@ -77,7 +77,7 @@
7777
@rU
7878
@ar
7979
@eD
80-
@iE
80+
@iEx
8181
@se
8282
@st1
8383
@rr
@@ -106,15 +106,15 @@
106106
@hd
107107
@be
108108
@It
109-
@id
109+
@idz
110110
@cm
111111
@ua
112112
@fs
113113
@Al
114114
@axn
115115
@rt
116116
@to
117-
@is
117+
@isj
118118
@fo
119119
@i
120120
@an
@@ -185,7 +185,7 @@ void f();
185185
// CHECK: (CXComment_InlineCommand CommandName=[ien] RenderNormal HasTrailingNewline)
186186
// CHECK: (CXComment_InlineCommand CommandName=[fr] RenderNormal HasTrailingNewline)
187187
// CHECK: (CXComment_InlineCommand CommandName=[en] RenderNormal HasTrailingNewline)
188-
// CHECK: (CXComment_InlineCommand CommandName=[tet] RenderNormal HasTrailingNewline)
188+
// CHECK: (CXComment_InlineCommand CommandName=[teq] RenderNormal HasTrailingNewline)
189189
// CHECK: (CXComment_InlineCommand CommandName=[le] RenderNormal HasTrailingNewline)
190190
// CHECK: (CXComment_InlineCommand CommandName=[L] RenderNormal HasTrailingNewline)
191191
// CHECK: (CXComment_InlineCommand CommandName=[os] RenderNormal HasTrailingNewline)
@@ -223,7 +223,7 @@ void f();
223223
// CHECK: (CXComment_InlineCommand CommandName=[rU] RenderNormal HasTrailingNewline)
224224
// CHECK: (CXComment_InlineCommand CommandName=[ar] RenderNormal HasTrailingNewline)
225225
// CHECK: (CXComment_InlineCommand CommandName=[eD] RenderNormal HasTrailingNewline)
226-
// CHECK: (CXComment_InlineCommand CommandName=[iE] RenderNormal HasTrailingNewline)
226+
// CHECK: (CXComment_InlineCommand CommandName=[iEx] RenderNormal HasTrailingNewline)
227227
// CHECK: (CXComment_InlineCommand CommandName=[se] RenderNormal HasTrailingNewline)
228228
// CHECK: (CXComment_InlineCommand CommandName=[st1] RenderNormal HasTrailingNewline)
229229
// CHECK: (CXComment_InlineCommand CommandName=[rr] RenderNormal HasTrailingNewline)
@@ -252,15 +252,15 @@ void f();
252252
// CHECK: (CXComment_InlineCommand CommandName=[hd] RenderNormal HasTrailingNewline)
253253
// CHECK: (CXComment_InlineCommand CommandName=[be] RenderNormal HasTrailingNewline)
254254
// CHECK: (CXComment_InlineCommand CommandName=[It] RenderNormal HasTrailingNewline)
255-
// CHECK: (CXComment_InlineCommand CommandName=[id] RenderNormal HasTrailingNewline)
255+
// CHECK: (CXComment_InlineCommand CommandName=[idz] RenderNormal HasTrailingNewline)
256256
// CHECK: (CXComment_InlineCommand CommandName=[cm] RenderNormal HasTrailingNewline)
257257
// CHECK: (CXComment_InlineCommand CommandName=[ua] RenderNormal HasTrailingNewline)
258258
// CHECK: (CXComment_InlineCommand CommandName=[fs] RenderNormal HasTrailingNewline)
259259
// CHECK: (CXComment_InlineCommand CommandName=[Al] RenderNormal HasTrailingNewline)
260260
// CHECK: (CXComment_InlineCommand CommandName=[axn] RenderNormal HasTrailingNewline)
261261
// CHECK: (CXComment_InlineCommand CommandName=[rt] RenderNormal HasTrailingNewline)
262262
// CHECK: (CXComment_InlineCommand CommandName=[to] RenderNormal HasTrailingNewline)
263-
// CHECK: (CXComment_InlineCommand CommandName=[is] RenderNormal HasTrailingNewline)
263+
// CHECK: (CXComment_InlineCommand CommandName=[isj] RenderNormal HasTrailingNewline)
264264
// CHECK: (CXComment_InlineCommand CommandName=[fo] RenderNormal HasTrailingNewline)
265265
// CHECK: (CXComment_InlineCommand CommandName=[i] RenderNormal HasTrailingNewline)
266266
// CHECK: (CXComment_InlineCommand CommandName=[an] RenderNormal HasTrailingNewline)

clang/unittests/AST/CommentLexer.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,12 +836,12 @@ TEST_F(CommentLexerTest, VerbatimBlock8) {
836836
// LaTeX verbatim blocks.
837837
TEST_F(CommentLexerTest, VerbatimBlock9) {
838838
const char *Source =
839-
"/// \\f$ Aaa \\f$ \\f[ Bbb \\f] \\f{ Ccc \\f}";
839+
"/// \\f$ Aaa \\f$ \\f[ Bbb \\f] \\f{ Ccc \\f} \\f( Ddd \\f)";
840840
std::vector<Token> Toks;
841841

842842
lexString(Source, Toks);
843843

844-
ASSERT_EQ(13U, Toks.size());
844+
ASSERT_EQ(17U, Toks.size());
845845

846846
ASSERT_EQ(tok::text, Toks[0].getKind());
847847
ASSERT_EQ(StringRef(" "), Toks[0].getText());
@@ -879,7 +879,19 @@ TEST_F(CommentLexerTest, VerbatimBlock9) {
879879
ASSERT_EQ(tok::verbatim_block_end, Toks[11].getKind());
880880
ASSERT_EQ(StringRef("f}"), getVerbatimBlockName(Toks[11]));
881881

882-
ASSERT_EQ(tok::newline, Toks[12].getKind());
882+
ASSERT_EQ(tok::text, Toks[12].getKind());
883+
ASSERT_EQ(StringRef(" "), Toks[12].getText());
884+
885+
ASSERT_EQ(tok::verbatim_block_begin, Toks[13].getKind());
886+
ASSERT_EQ(StringRef("f("), getVerbatimBlockName(Toks[13]));
887+
888+
ASSERT_EQ(tok::verbatim_block_line, Toks[14].getKind());
889+
ASSERT_EQ(StringRef(" Ddd "), Toks[14].getVerbatimBlockText());
890+
891+
ASSERT_EQ(tok::verbatim_block_end, Toks[15].getKind());
892+
ASSERT_EQ(StringRef("f)"), getVerbatimBlockName(Toks[15]));
893+
894+
ASSERT_EQ(tok::newline, Toks[16].getKind());
883895
}
884896

885897
// Empty verbatim line.

clang/utils/TableGen/ClangCommentCommandInfoEmitter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ static std::string MangleName(StringRef Str) {
8383
default:
8484
Mangled += Str[i];
8585
break;
86+
case '(':
87+
Mangled += "lparen";
88+
break;
89+
case ')':
90+
Mangled += "rparen";
91+
break;
8692
case '[':
8793
Mangled += "lsquare";
8894
break;

0 commit comments

Comments
 (0)