Skip to content

Commit

Permalink
unify logic to populate attributes
Browse files Browse the repository at this point in the history
#refactor
  • Loading branch information
alandefreitas committed Jan 13, 2025
1 parent 1e1012a commit 6c6ffc9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/lib/AST/ASTVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,17 +1112,7 @@ populate(
populate(I.Requires, TRC);
}

if (D->hasAttrs())
{
for (AttrVec& attrs = D->getAttrs();
Attr const* attr: attrs)
{
if (IdentifierInfo const* II = attr->getAttrName())
{
I.Attributes.emplace_back(II->getName());
}
}
}
populateAttributes(I, D);
}

void
Expand Down Expand Up @@ -1234,14 +1224,7 @@ populate(
I.HasNoUniqueAddress = D->hasAttr<NoUniqueAddressAttr>();
I.IsDeprecated = D->hasAttr<DeprecatedAttr>();
I.IsMaybeUnused = D->hasAttr<UnusedAttr>();
if (D->hasAttrs())
{
for (AttrVec& attrs = D->getAttrs();
Attr const* attr: attrs)
{
I.Attributes.emplace_back(attr->getAttrName()->getName());
}
}
populateAttributes(I, D);
}

void
Expand Down Expand Up @@ -1673,6 +1656,29 @@ populate(
}));
}

template <std::derived_from<Info> InfoTy>
void
ASTVisitor::
populateAttributes(InfoTy& I, const Decl* D)
{
if constexpr (requires { I.Attributes; })
{
MRDOCS_CHECK_OR(D->hasAttrs());
for (Attr const* attr: D->getAttrs())
{
IdentifierInfo const* II = attr->getAttrName();
if (!II)
{
continue;
}
if (std::ranges::find(I.Attributes, II->getName()) == I.Attributes.end())
{
I.Attributes.emplace_back(II->getName());
}
}
}
}

std::string
ASTVisitor::
extractName(NamedDecl const* D)
Expand Down
5 changes: 5 additions & 0 deletions src/lib/AST/ASTVisitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ class ASTVisitor
std::vector<std::unique_ptr<TArg>>& result,
const ASTTemplateArgumentListInfo* args);

template <std::derived_from<Info> InfoTy>
static
void
populateAttributes(InfoTy& I, const Decl* D);

// =================================================
// Populate function helpers
// =================================================
Expand Down

0 comments on commit 6c6ffc9

Please sign in to comment.