Skip to content

Commit 6c6ffc9

Browse files
committed
unify logic to populate attributes
#refactor
1 parent 1e1012a commit 6c6ffc9

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/lib/AST/ASTVisitor.cpp

+25-19
Original file line numberDiff line numberDiff line change
@@ -1112,17 +1112,7 @@ populate(
11121112
populate(I.Requires, TRC);
11131113
}
11141114

1115-
if (D->hasAttrs())
1116-
{
1117-
for (AttrVec& attrs = D->getAttrs();
1118-
Attr const* attr: attrs)
1119-
{
1120-
if (IdentifierInfo const* II = attr->getAttrName())
1121-
{
1122-
I.Attributes.emplace_back(II->getName());
1123-
}
1124-
}
1125-
}
1115+
populateAttributes(I, D);
11261116
}
11271117

11281118
void
@@ -1234,14 +1224,7 @@ populate(
12341224
I.HasNoUniqueAddress = D->hasAttr<NoUniqueAddressAttr>();
12351225
I.IsDeprecated = D->hasAttr<DeprecatedAttr>();
12361226
I.IsMaybeUnused = D->hasAttr<UnusedAttr>();
1237-
if (D->hasAttrs())
1238-
{
1239-
for (AttrVec& attrs = D->getAttrs();
1240-
Attr const* attr: attrs)
1241-
{
1242-
I.Attributes.emplace_back(attr->getAttrName()->getName());
1243-
}
1244-
}
1227+
populateAttributes(I, D);
12451228
}
12461229

12471230
void
@@ -1673,6 +1656,29 @@ populate(
16731656
}));
16741657
}
16751658

1659+
template <std::derived_from<Info> InfoTy>
1660+
void
1661+
ASTVisitor::
1662+
populateAttributes(InfoTy& I, const Decl* D)
1663+
{
1664+
if constexpr (requires { I.Attributes; })
1665+
{
1666+
MRDOCS_CHECK_OR(D->hasAttrs());
1667+
for (Attr const* attr: D->getAttrs())
1668+
{
1669+
IdentifierInfo const* II = attr->getAttrName();
1670+
if (!II)
1671+
{
1672+
continue;
1673+
}
1674+
if (std::ranges::find(I.Attributes, II->getName()) == I.Attributes.end())
1675+
{
1676+
I.Attributes.emplace_back(II->getName());
1677+
}
1678+
}
1679+
}
1680+
}
1681+
16761682
std::string
16771683
ASTVisitor::
16781684
extractName(NamedDecl const* D)

src/lib/AST/ASTVisitor.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,11 @@ class ASTVisitor
560560
std::vector<std::unique_ptr<TArg>>& result,
561561
const ASTTemplateArgumentListInfo* args);
562562

563+
template <std::derived_from<Info> InfoTy>
564+
static
565+
void
566+
populateAttributes(InfoTy& I, const Decl* D);
567+
563568
// =================================================
564569
// Populate function helpers
565570
// =================================================

0 commit comments

Comments
 (0)