20
20
#include < clang/AST/CommentCommandTraits.h>
21
21
#include < clang/AST/ASTContext.h>
22
22
#include < clang/AST/RawCommentList.h>
23
+ #include < clang/Lex/Lexer.h>
24
+ #include < clang/Basic/SourceLocation.h>
23
25
#ifdef _MSC_VER
24
26
#pragma warning(push)
25
27
#pragma warning(disable: 5054) // C5054: operator '+': deprecated between enumerations of different types
33
35
#include < llvm/Support/JSON.h>
34
36
#include < ranges>
35
37
38
+ #ifdef NDEBUG
39
+ #define MRDOCS_COMMENT_TRACE (D, C )
40
+ #else
41
+
42
+ # define MRDOCS_COMMENT_TRACE_MERGE_ (a, b ) a##b
43
+ # define MRDOCS_COMMENT_TRACE_LABEL_ (a ) MRDOCS_COMMENT_TRACE_MERGE_(comment_content_, a)
44
+ # define MRDOCS_COMMENT_TRACE_UNIQUE_NAME MRDOCS_COMMENT_TRACE_LABEL_ (__LINE__)
45
+
46
+ namespace detail {
47
+ template <class T >
48
+ void
49
+ dumpCommentContent (T const * C, clang::ASTContext const & Ctx, llvm::SmallString<1024 >& contents)
50
+ {
51
+ if (!C)
52
+ {
53
+ return ;
54
+ }
55
+ llvm::raw_svector_ostream os (contents);
56
+ if constexpr (std::derived_from<T, clang::comments::Comment>)
57
+ {
58
+ auto const * CC = static_cast <clang::comments::Comment const *>(C);
59
+ clang::SourceRange const R = CC->getSourceRange ();
60
+ clang::SourceManager const & SM = Ctx.getSourceManager ();
61
+ contents = clang::Lexer::getSourceText (
62
+ clang::CharSourceRange::getTokenRange (R),
63
+ SM,
64
+ Ctx.getLangOpts ());
65
+ }
66
+ }
67
+
68
+ template <class T >
69
+ requires (!std::is_pointer_v<T>)
70
+ void
71
+ dumpCommentContent (T const & C, clang::ASTContext const & Ctx, llvm::SmallString<1024 >& contents)
72
+ {
73
+ dumpCommentContent (&C, Ctx, contents);
74
+ }
75
+ } // namespace detail
76
+
77
+ #define MRDOCS_COMMENT_TRACE (D, C ) \
78
+ SmallString<1024 > MRDOCS_COMMENT_TRACE_UNIQUE_NAME; \
79
+ ::detail::dumpCommentContent (D, C, MRDOCS_COMMENT_TRACE_UNIQUE_NAME); \
80
+ report::debug (" {}" , std::string_view(MRDOCS_COMMENT_TRACE_UNIQUE_NAME.str()))
81
+ #endif
82
+
83
+
36
84
/* AST Types
37
85
38
86
Comment
@@ -509,10 +557,12 @@ JavadocVisitor::
509
557
visitChildren (
510
558
Comment const * C)
511
559
{
560
+ MRDOCS_COMMENT_TRACE (C, ctx_);
512
561
ScopeExitRestore s1 (it_, C->child_begin ());
513
562
ScopeExitRestore s2 (end_, C->child_end ());
514
563
while (it_ != end_)
515
564
{
565
+ MRDOCS_COMMENT_TRACE (*it_, ctx_);
516
566
visit (*it_);
517
567
++it_; // must happen after
518
568
}
@@ -597,6 +647,7 @@ Javadoc
597
647
JavadocVisitor::
598
648
build ()
599
649
{
650
+ MRDOCS_COMMENT_TRACE (FC_, ctx_);
600
651
visit (FC_);
601
652
return std::move (jd_);
602
653
}
@@ -606,6 +657,7 @@ JavadocVisitor::
606
657
visitComment (
607
658
Comment const * C)
608
659
{
660
+ MRDOCS_COMMENT_TRACE (C, ctx_);
609
661
visitChildren (C);
610
662
}
611
663
@@ -620,6 +672,7 @@ JavadocVisitor::
620
672
visitTextComment (
621
673
TextComment const * C)
622
674
{
675
+ MRDOCS_COMMENT_TRACE (C, ctx_);
623
676
llvm::StringRef s = C->getText ();
624
677
// If this is the first text comment in the
625
678
// paragraph then remove all the leading space.
@@ -642,6 +695,7 @@ Expected<JavadocVisitor::TagComponents>
642
695
JavadocVisitor::
643
696
parseHTMLTag (HTMLStartTagComment const * C)
644
697
{
698
+ MRDOCS_COMMENT_TRACE (C, ctx_);
645
699
TagComponents res;
646
700
res.tag = C->getTagName ().str ();
647
701
@@ -700,6 +754,7 @@ JavadocVisitor::
700
754
visitHTMLStartTagComment (
701
755
HTMLStartTagComment const * C)
702
756
{
757
+ MRDOCS_COMMENT_TRACE (C, ctx_);
703
758
MRDOCS_ASSERT (C->child_begin () == C->child_end ());
704
759
PresumedLoc const loc = sm_.getPresumedLoc (C->getBeginLoc ());
705
760
auto filename = files::makePosixStyle (loc.getFilename ());
@@ -766,6 +821,7 @@ JavadocVisitor::
766
821
visitHTMLEndTagComment (
767
822
HTMLEndTagComment const * C)
768
823
{
824
+ MRDOCS_COMMENT_TRACE (C, ctx_);
769
825
MRDOCS_ASSERT (C->child_begin () == C->child_end ());
770
826
--htmlTagNesting_;
771
827
}
@@ -923,6 +979,7 @@ JavadocVisitor::
923
979
visitInlineCommandComment (
924
980
InlineCommandComment const * C)
925
981
{
982
+ MRDOCS_COMMENT_TRACE (C, ctx_);
926
983
auto const * cmd = ctx_
927
984
.getCommentCommandTraits ()
928
985
.getCommandInfo (C->getCommandID ());
@@ -1074,6 +1131,7 @@ JavadocVisitor::
1074
1131
visitParagraphComment (
1075
1132
ParagraphComment const * C)
1076
1133
{
1134
+ MRDOCS_COMMENT_TRACE (C, ctx_);
1077
1135
if (block_)
1078
1136
return visitChildren (C);
1079
1137
doc::Paragraph paragraph;
@@ -1089,6 +1147,7 @@ JavadocVisitor::
1089
1147
visitBlockCommandComment (
1090
1148
BlockCommandComment const * C)
1091
1149
{
1150
+ MRDOCS_COMMENT_TRACE (C, ctx_);
1092
1151
auto const * cmd = ctx_
1093
1152
.getCommentCommandTraits ()
1094
1153
.getCommandInfo (C->getCommandID ());
@@ -1451,6 +1510,7 @@ JavadocVisitor::
1451
1510
visitParamCommandComment (
1452
1511
ParamCommandComment const * C)
1453
1512
{
1513
+ MRDOCS_COMMENT_TRACE (C, ctx_);
1454
1514
doc::Param param;
1455
1515
if (C->hasParamName ())
1456
1516
{
@@ -1494,6 +1554,7 @@ JavadocVisitor::
1494
1554
visitTParamCommandComment (
1495
1555
TParamCommandComment const * C)
1496
1556
{
1557
+ MRDOCS_COMMENT_TRACE (C, ctx_);
1497
1558
doc::TParam tparam;
1498
1559
if (C->hasParamName ())
1499
1560
{
@@ -1534,6 +1595,7 @@ JavadocVisitor::
1534
1595
visitVerbatimBlockComment (
1535
1596
VerbatimBlockComment const * C)
1536
1597
{
1598
+ MRDOCS_COMMENT_TRACE (C, ctx_);
1537
1599
doc::Code code;
1538
1600
auto scope = enterScope (code);
1539
1601
// if(C->hasNonWhitespaceParagraph())
@@ -1546,6 +1608,7 @@ JavadocVisitor::
1546
1608
visitVerbatimLineComment (
1547
1609
VerbatimLineComment const * C)
1548
1610
{
1611
+ MRDOCS_COMMENT_TRACE (C, ctx_);
1549
1612
// VFALCO This doesn't seem to be used
1550
1613
// in any of my codebases, follow up
1551
1614
}
@@ -1555,6 +1618,7 @@ JavadocVisitor::
1555
1618
visitVerbatimBlockLineComment (
1556
1619
VerbatimBlockLineComment const * C)
1557
1620
{
1621
+ MRDOCS_COMMENT_TRACE (C, ctx_);
1558
1622
emplaceText<doc::Text>(true , C->getText ().str ());
1559
1623
}
1560
1624
@@ -1565,6 +1629,7 @@ JavadocVisitor::
1565
1629
goodArgCount (std::size_t n,
1566
1630
InlineCommandComment const & C)
1567
1631
{
1632
+ MRDOCS_COMMENT_TRACE (C, ctx_);
1568
1633
if (C.getNumArgs () != n)
1569
1634
{
1570
1635
auto loc = sm_.getPresumedLoc (C.getBeginLoc ());
@@ -1611,7 +1676,9 @@ parseJavadoc(
1611
1676
Config const & config,
1612
1677
Diagnostics& diags)
1613
1678
{
1614
- auto result = JavadocVisitor (FC, D, config, diags).build ();
1679
+ MRDOCS_COMMENT_TRACE (FC, D->getASTContext ());
1680
+ JavadocVisitor visitor (FC, D, config, diags);
1681
+ auto result = visitor.build ();
1615
1682
if (jd == nullptr )
1616
1683
{
1617
1684
// Do not create javadocs which have no nodes
0 commit comments