Skip to content

Commit 9decbdb

Browse files
committed
ASTVisitor handles source info independently from javadoc
#improvement
1 parent 113a57e commit 9decbdb

File tree

2 files changed

+73
-42
lines changed

2 files changed

+73
-42
lines changed

src/lib/AST/ASTVisitor.cpp

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,24 @@ void
531531
ASTVisitor::
532532
populate(Info& I, bool const isNew, DeclTy const* D)
533533
{
534-
// Populate the documentation
535-
bool const isDocumented = generateJavadoc(I.javadoc, D);
534+
populate(I.javadoc, D);
535+
populate(dynamic_cast<SourceInfo&>(I), D);
536536

537-
// Populate the source info
537+
// All other information is redundant if the symbol is not new
538+
MRDOCS_CHECK_OR(isNew);
539+
540+
// These should already have been populated by traverseImpl
541+
MRDOCS_ASSERT(I.id);
542+
MRDOCS_ASSERT(I.Kind != InfoKind::None);
543+
544+
I.Name = extractName(D);
545+
}
546+
547+
template <std::derived_from<Decl> DeclTy>
548+
void
549+
ASTVisitor::
550+
populate(SourceInfo& I, DeclTy const* D)
551+
{
538552
clang::SourceLocation Loc = D->getBeginLoc();
539553
if (Loc.isInvalid())
540554
{
@@ -544,17 +558,26 @@ populate(Info& I, bool const isNew, DeclTy const* D)
544558
{
545559
populate(
546560
dynamic_cast<SourceInfo&>(I),
547-
Loc, isDefinition(D), isDocumented);
561+
Loc,
562+
isDefinition(D),
563+
D->getASTContext().getRawCommentForDeclNoCache(D));
548564
}
565+
}
549566

550-
// All other information is redundant if the symbol is not new
551-
MRDOCS_CHECK_OR(isNew);
552-
553-
// These should already have been populated by traverseImpl
554-
MRDOCS_ASSERT(I.id);
555-
MRDOCS_ASSERT(I.Kind != InfoKind::None);
556-
557-
I.Name = extractName(D);
567+
bool
568+
ASTVisitor::
569+
populate(
570+
std::optional<Javadoc>& javadoc,
571+
Decl const* D)
572+
{
573+
RawComment const* RC =
574+
D->getASTContext().getRawCommentForDeclNoCache(D);
575+
MRDOCS_CHECK_OR(RC, false);
576+
comments::FullComment* FC =
577+
RC->parse(D->getASTContext(), &sema_.getPreprocessor(), D);
578+
MRDOCS_CHECK_OR(FC, false);
579+
parseJavadoc(javadoc, FC, D, config_, diags_);
580+
return true;
558581
}
559582

560583
void
@@ -686,6 +709,13 @@ populate(RecordInfo& I, ClassTemplateSpecializationDecl const* D)
686709
populate(I, cast<CXXRecordDecl>(D));
687710
}
688711

712+
void
713+
ASTVisitor::
714+
populate(RecordInfo& I, ClassTemplatePartialSpecializationDecl const* D)
715+
{
716+
populate(I, dynamic_cast<ClassTemplateSpecializationDecl const*>(D));
717+
}
718+
689719
void
690720
ASTVisitor::
691721
populate(
@@ -1023,6 +1053,13 @@ populate(VariableInfo& I, VarTemplateSpecializationDecl const* D)
10231053
populate(I, cast<VarDecl>(D));
10241054
}
10251055

1056+
void
1057+
ASTVisitor::
1058+
populate(VariableInfo& I, VarTemplatePartialSpecializationDecl const* D)
1059+
{
1060+
populate(I, dynamic_cast<VarTemplateSpecializationDecl const*>(D));
1061+
}
1062+
10261063
void
10271064
ASTVisitor::
10281065
populate(
@@ -1883,22 +1920,6 @@ qualifiedName(NamedDecl const* ND) const
18831920
return name;
18841921
}
18851922

1886-
bool
1887-
ASTVisitor::
1888-
generateJavadoc(
1889-
std::optional<Javadoc>& javadoc,
1890-
Decl const* D)
1891-
{
1892-
RawComment const* RC =
1893-
D->getASTContext().getRawCommentForDeclNoCache(D);
1894-
MRDOCS_CHECK_OR(RC, false);
1895-
comments::FullComment* FC =
1896-
RC->parse(D->getASTContext(), &sema_.getPreprocessor(), D);
1897-
MRDOCS_CHECK_OR(FC, false);
1898-
parseJavadoc(javadoc, FC, D, config_, diags_);
1899-
return true;
1900-
}
1901-
19021923
Polymorphic<TypeInfo>
19031924
ASTVisitor::
19041925
toTypeInfo(QualType const qt, TraversalMode const mode)

src/lib/AST/ASTVisitor.hpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,24 @@ class ASTVisitor
484484
void
485485
populate(Info& I, bool isNew, DeclTy const* D);
486486

487+
template <std::derived_from<Decl> DeclTy>
488+
void
489+
populate(SourceInfo& I, DeclTy const* D);
490+
491+
/* Parse the comments above a declaration as Javadoc
492+
493+
This function will parse the comments above a declaration
494+
as Javadoc, and store the results in the `javadoc` input
495+
parameter.
496+
497+
@return true if the comments were successfully parsed as
498+
Javadoc, and false otherwise.
499+
*/
500+
bool
501+
populate(
502+
std::optional<Javadoc>& javadoc,
503+
Decl const* D);
504+
487505
void
488506
populate(SourceInfo& I, clang::SourceLocation loc, bool definition, bool documented);
489507

@@ -503,6 +521,9 @@ class ASTVisitor
503521
void
504522
populate(RecordInfo& I, ClassTemplateSpecializationDecl const* D);
505523

524+
void
525+
populate(RecordInfo& I, ClassTemplatePartialSpecializationDecl const* D);
526+
506527
void
507528
populate(FunctionInfo& I, FunctionDecl const* D);
508529

@@ -548,6 +569,9 @@ class ASTVisitor
548569
void
549570
populate(VariableInfo& I, VarTemplateSpecializationDecl const* D);
550571

572+
void
573+
populate(VariableInfo& I, VarTemplatePartialSpecializationDecl const* D);
574+
551575
void
552576
populate(FieldInfo& I, FieldDecl const* D);
553577

@@ -718,20 +742,6 @@ class ASTVisitor
718742
void
719743
addMember(std::vector<SymbolID>& container, Info const& Member) const;
720744

721-
/* Parse the comments above a declaration as Javadoc
722-
723-
This function will parse the comments above a declaration
724-
as Javadoc, and store the results in the `javadoc` input
725-
parameter.
726-
727-
@return true if the comments were successfully parsed as
728-
Javadoc, and false otherwise.
729-
*/
730-
bool
731-
generateJavadoc(
732-
std::optional<Javadoc>& javadoc,
733-
Decl const* D);
734-
735745
Polymorphic<TypeInfo>
736746
toTypeInfo(QualType qt, TraversalMode mode);
737747

0 commit comments

Comments
 (0)