Skip to content

Commit 887c332

Browse files
committed
isDefinition and isDocumented are clang helpers
#refactor
1 parent b2bafb8 commit 887c332

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

src/lib/AST/ASTVisitor.cpp

+2-19
Original file line numberDiff line numberDiff line change
@@ -509,23 +509,6 @@ generateID(Decl const* D) const
509509
return id;
510510
}
511511

512-
namespace
513-
{
514-
template <class DeclTy>
515-
bool
516-
isDefinition(DeclTy* D)
517-
{
518-
if constexpr (requires {D->isThisDeclarationADefinition();})
519-
{
520-
return D->isThisDeclarationADefinition();
521-
}
522-
else
523-
{
524-
return false;
525-
}
526-
}
527-
}
528-
529512
template <std::derived_from<Decl> DeclTy>
530513
void
531514
ASTVisitor::
@@ -560,7 +543,7 @@ populate(SourceInfo& I, DeclTy const* D)
560543
dynamic_cast<SourceInfo&>(I),
561544
Loc,
562545
isDefinition(D),
563-
D->getASTContext().getRawCommentForDeclNoCache(D));
546+
isDocumented(D));
564547
}
565548
}
566549

@@ -3366,7 +3349,7 @@ checkUndocumented(
33663349
// Check if the symbol is documented, ensure this symbol is not in the set
33673350
// of undocumented symbols in this translation unit and return
33683351
// without an error if it is
3369-
if (D->getASTContext().getRawCommentForDeclNoCache(D))
3352+
if (isDocumented(D))
33703353
{
33713354
if (config_->warnIfUndocumented)
33723355
{

src/lib/AST/ClangHelpers.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ isVirtualMember(Decl const* D)
355355
}
356356

357357
bool
358-
isAnonymousNamespace(const Decl *D)
358+
isAnonymousNamespace(Decl const* D)
359359
{
360360
if (auto const* ND = dyn_cast<NamespaceDecl>(D))
361361
{
@@ -365,7 +365,7 @@ isAnonymousNamespace(const Decl *D)
365365
}
366366

367367
bool
368-
isStaticFileLevelMember(const Decl *D)
368+
isStaticFileLevelMember(Decl const* D)
369369
{
370370
if (const auto *VD = dyn_cast<VarDecl>(D)) {
371371
return VD->getStorageClass() == SC_Static && VD->getDeclContext()->isFileContext();
@@ -376,5 +376,11 @@ isStaticFileLevelMember(const Decl *D)
376376
return false;
377377
}
378378

379+
bool
380+
isDocumented(Decl const* D)
381+
{
382+
return D->getASTContext().getRawCommentForDeclNoCache(D);
383+
}
384+
379385

380386
} // clang::mrdocs

src/lib/AST/ClangHelpers.hpp

+18
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,24 @@ MRDOCS_DECL
844844
bool
845845
isStaticFileLevelMember(Decl const *D);
846846

847+
MRDOCS_DECL
848+
bool
849+
isDocumented(Decl const *D);
850+
851+
template <class DeclTy>
852+
bool
853+
isDefinition(DeclTy* D)
854+
{
855+
if constexpr (requires {D->isThisDeclarationADefinition();})
856+
{
857+
return D->isThisDeclarationADefinition();
858+
}
859+
else
860+
{
861+
return false;
862+
}
863+
}
864+
847865
#ifdef NDEBUG
848866
#define MRDOCS_SYMBOL_TRACE(D, C)
849867
#else

0 commit comments

Comments
 (0)