From 6c6ffc9af8edc180036011bb0db3fb805fd8b478 Mon Sep 17 00:00:00 2001 From: alandefreitas Date: Mon, 13 Jan 2025 15:10:04 -0300 Subject: [PATCH] unify logic to populate attributes #refactor --- src/lib/AST/ASTVisitor.cpp | 44 ++++++++++++++++++++++---------------- src/lib/AST/ASTVisitor.hpp | 5 +++++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/lib/AST/ASTVisitor.cpp b/src/lib/AST/ASTVisitor.cpp index 6459396d7..1416a3e3e 100644 --- a/src/lib/AST/ASTVisitor.cpp +++ b/src/lib/AST/ASTVisitor.cpp @@ -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 @@ -1234,14 +1224,7 @@ populate( I.HasNoUniqueAddress = D->hasAttr(); I.IsDeprecated = D->hasAttr(); I.IsMaybeUnused = D->hasAttr(); - if (D->hasAttrs()) - { - for (AttrVec& attrs = D->getAttrs(); - Attr const* attr: attrs) - { - I.Attributes.emplace_back(attr->getAttrName()->getName()); - } - } + populateAttributes(I, D); } void @@ -1673,6 +1656,29 @@ populate( })); } +template 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) diff --git a/src/lib/AST/ASTVisitor.hpp b/src/lib/AST/ASTVisitor.hpp index 3f469651d..41ac5a40b 100644 --- a/src/lib/AST/ASTVisitor.hpp +++ b/src/lib/AST/ASTVisitor.hpp @@ -560,6 +560,11 @@ class ASTVisitor std::vector>& result, const ASTTemplateArgumentListInfo* args); + template InfoTy> + static + void + populateAttributes(InfoTy& I, const Decl* D); + // ================================================= // Populate function helpers // =================================================