Skip to content

Commit dd79d58

Browse files
committed
chore: Diagnostics in parseJavadoc
1 parent caf0347 commit dd79d58

File tree

7 files changed

+273
-47
lines changed

7 files changed

+273
-47
lines changed

docs/modules/ROOT/nav.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* xref:index.adoc[]
22
* xref:install.adoc[]
3-
* xref:design-notes.adoc[]
43
* xref:usage.adoc[]
4+
* xref:commands.adoc[]
5+
* xref:design-notes.adoc[]
56
* xref:contribute.adoc[]
67
* xref:license.adoc[]

docs/modules/ROOT/pages/commands.adoc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
= Commands
2+
3+
These are the Doxygen-style "@" commands recognized by MrDox:
4+
5+
== Italics / Emphasis
6+
[]
7+
----
8+
@a [word]
9+
@e [word]
10+
@em [word]
11+
12+
<em>[text]</em>
13+
----
14+

lib/AST/ASTVisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ class ASTVisitor
998998
// ASTContext::getCommentForDecl instead
999999
RawComment* RC =
10001000
D->getASTContext().getRawCommentForDeclNoCache(D);
1001-
parseJavadoc(javadoc, RC, D, config_);
1001+
parseJavadoc(javadoc, RC, D, config_, diags_);
10021002
}
10031003

10041004
//------------------------------------------------

lib/AST/ParseJavadoc.cpp

Lines changed: 249 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,215 @@
2929
#include <clang/Basic/SourceManager.h>
3030
#include <llvm/Support/JSON.h>
3131

32-
/*
33-
Comment Types
32+
/* Doxygen commands
33+
34+
Italics \a
35+
Italics \e
36+
Italics \em
37+
38+
\addindex
39+
\addtogroup
40+
\anchor
41+
\arg
42+
\attention
43+
\author
44+
\authors
45+
\b
46+
\brief
47+
\bug
48+
\c
49+
\callergraph
50+
\callgraph
51+
\category
52+
\cite
53+
\class
54+
\code
55+
\concept
56+
\cond
57+
\copybrief
58+
\copydetails
59+
\copydoc
60+
\copyright
61+
\date
62+
\def
63+
\defgroup
64+
\deprecated
65+
\details
66+
\diafile
67+
\dir
68+
\docbookinclude
69+
\docbookonly
70+
\dontinclude
71+
\dot
72+
\dotfile
73+
\doxyconfig
74+
\else
75+
\elseif
76+
\emoji
77+
\endcode
78+
\endcond
79+
\enddocbookonly
80+
\enddot
81+
\endhtmlonly
82+
\endif
83+
\endinternal
84+
\endlatexonly
85+
\endlink
86+
\endmanonly
87+
\endmsc
88+
\endparblock
89+
\endrtfonly
90+
\endsecreflist
91+
\endverbatim
92+
\enduml
93+
\endxmlonly
94+
\enum
95+
\example
96+
\exception
97+
\extends
98+
\f(
99+
\f)
100+
\f$
101+
\f[
102+
\f]
103+
\f{
104+
\f}
105+
\file
106+
\fileinfo
107+
\fn
108+
\headerfile
109+
\hidecallergraph
110+
\hidecallgraph
111+
\hiderefby
112+
\hiderefs
113+
\hideinitializer
114+
\htmlinclude
115+
\htmlonly
116+
\idlexcept
117+
\if
118+
\ifnot
119+
\image
120+
\implements
121+
\include
122+
\includedoc
123+
\includelineno
124+
\ingroup
125+
\internal
126+
\invariant
127+
\interface
128+
\latexinclude
129+
\latexonly
130+
\li
131+
\line
132+
\lineinfo
133+
\link
134+
\mainpage
135+
\maninclude
136+
\manonly
137+
\memberof
138+
\msc
139+
\mscfile
140+
\n
141+
\name
142+
\namespace
143+
\noop
144+
\nosubgrouping
145+
\note
146+
\overload
147+
\p
148+
\package
149+
\page
150+
\par
151+
\paragraph
152+
\param
153+
\parblock
154+
\post
155+
\pre
156+
\private
157+
\privatesection
158+
\property
159+
\protected
160+
\protectedsection
161+
\protocol
162+
\public
163+
\publicsection
164+
\pure
165+
\qualifier
166+
\raisewarning
167+
\ref
168+
\refitem
169+
\related
170+
\relates
171+
\relatedalso
172+
\relatesalso
173+
\remark
174+
\remarks
175+
\result
176+
\return
177+
\returns
178+
\retval
179+
\rtfinclude
180+
\rtfonly
181+
\sa
182+
\secreflist
183+
\section
184+
\see
185+
\short
186+
\showdate
187+
\showinitializer
188+
\showrefby
189+
\showrefs
190+
\since
191+
\skip
192+
\skipline
193+
\snippet
194+
\snippetdoc
195+
\snippetlineno
196+
\static
197+
\startuml
198+
\struct
199+
\subpage
200+
\subsection
201+
\subsubsection
202+
\tableofcontents
203+
\test
204+
\throw
205+
\throws
206+
\todo
207+
\tparam
208+
\typedef
209+
\union
210+
\until
211+
\var
212+
\verbatim
213+
\verbinclude
214+
\version
215+
\vhdlflow
216+
\warning
217+
\weakgroup
218+
\xmlinclude
219+
\xmlonly
220+
\xrefitem
221+
\$
222+
\@
223+
\\
224+
\&
225+
\~
226+
\<
227+
\=
228+
\>
229+
\#
230+
\%
231+
\"
232+
\.
233+
\::
234+
\|
235+
\--
236+
\---
237+
238+
--------------------------------------------------
239+
240+
AST Types
34241
35242
Comment
36243
abstract base for all comments
@@ -83,10 +290,10 @@
83290
84291
VerbatimBlockLineComment : Comment
85292
A line of text contained in a verbatim block.
86-
*/
87-
/*
293+
88294
BlockCommandComment
89295
Always has one child of type ParagraphComment child?
296+
90297
*/
91298

92299
namespace clang {
@@ -106,6 +313,7 @@ class JavadocVisitor
106313
SourceManager const& sm_;
107314
FullComment const* FC_;
108315
Javadoc jd_;
316+
Diagnostics& diags_;
109317
doc::List<doc::Param> params_;
110318
doc::Paragraph* paragraph_ = nullptr;
111319
std::size_t htmlTagNesting_ = 0;
@@ -117,7 +325,8 @@ class JavadocVisitor
117325

118326
public:
119327
JavadocVisitor(
120-
RawComment const*, Decl const*, Config const&);
328+
RawComment const*, Decl const*,
329+
Config const&, Diagnostics&);
121330
Javadoc build();
122331

123332
void visitComment(Comment const* C);
@@ -201,11 +410,13 @@ JavadocVisitor::
201410
JavadocVisitor(
202411
RawComment const* RC,
203412
Decl const* D,
204-
Config const& config)
413+
Config const& config,
414+
Diagnostics& diags)
205415
: config_(config)
206416
, ctx_(D->getASTContext())
207417
, sm_(ctx_.getSourceManager())
208418
, FC_(RC->parse(D->getASTContext(), nullptr, D))
419+
, diags_(diags)
209420
{
210421
}
211422

@@ -331,6 +542,20 @@ JavadocVisitor::
331542
visitInlineCommandComment(
332543
InlineCommandComment const* C)
333544
{
545+
auto const* cmd = ctx_
546+
.getCommentCommandTraits()
547+
.getCommandInfo(C->getCommandID());
548+
549+
if( cmd->getID() == CommandTraits::KCI_copybrief ||
550+
cmd->getID() == CommandTraits::KCI_copydetails ||
551+
cmd->getID() == CommandTraits::KCI_copydoc)
552+
{
553+
if(C->getNumArgs() != 1)
554+
{
555+
// throw an error
556+
}
557+
}
558+
334559
doc::Style style(doc::Style::none);
335560
switch (C->getRenderKind())
336561
{
@@ -420,7 +645,7 @@ visitBlockCommandComment(
420645
jd_.emplace_back(std::move(returns));
421646
return;
422647
}
423-
if(cmd->getID() == CommandTraits::KCI_note)
648+
if(cmd->getID() == CommandTraits::KCI_note)
424649
{
425650
doc::Admonition paragraph(doc::Admonish::note);
426651
Scope scope(paragraph, paragraph_);
@@ -714,23 +939,27 @@ parseJavadoc(
714939
std::unique_ptr<Javadoc>& jd,
715940
RawComment* RC,
716941
Decl const* D,
717-
Config const& config)
942+
Config const& config,
943+
Diagnostics& diags)
718944
{
719-
if(RC)
945+
if(! RC)
720946
{
721-
RC->setAttached();
947+
MRDOX_ASSERT(! jd);
948+
return;
949+
}
722950

723-
auto result = JavadocVisitor(RC, D, config).build();
951+
RC->setAttached();
724952

725-
if(jd == nullptr)
726-
{
727-
jd = std::make_unique<Javadoc>(std::move(result));
728-
}
729-
else if(*jd != result)
730-
{
731-
// merge
732-
jd->append(std::move(result));
733-
}
953+
auto result = JavadocVisitor(RC, D, config, diags).build();
954+
955+
if(jd == nullptr)
956+
{
957+
jd = std::make_unique<Javadoc>(std::move(result));
958+
}
959+
else if(*jd != result)
960+
{
961+
// merge
962+
jd->append(std::move(result));
734963
}
735964
}
736965

lib/AST/ParseJavadoc.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef MRDOX_TOOL_AST_PARSEJAVADOC_HPP
1313
#define MRDOX_TOOL_AST_PARSEJAVADOC_HPP
1414

15+
#include "Lib/Diagnostics.hpp"
1516
#include <mrdox/Platform.hpp>
1617
#include <mrdox/Config.hpp>
1718
#include <mrdox/Metadata/Javadoc.hpp>
@@ -40,7 +41,8 @@ parseJavadoc(
4041
std::unique_ptr<Javadoc>& jd,
4142
RawComment* RC,
4243
Decl const* D,
43-
Config const& config);
44+
Config const& config,
45+
Diagnostics& diags);
4446

4547
} // mrdox
4648
} // clang

test-files/adoc/test.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
/** brief
2-
3-
desc
4-
5-
@warning caution
6-
*/
7-
void f();
1+
struct T {};

0 commit comments

Comments
 (0)