[clang] [Clang] Improve EmitClangAttrSpellingListIndex (PR #114899)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 7 14:29:25 PST 2024
================
@@ -153,12 +155,37 @@ std::string AttributeCommonInfo::getNormalizedFullName() const {
normalizeName(getAttrName(), getScopeName(), getSyntax()));
}
+// Sorted list of attribute scope names
+static constexpr std::pair<StringRef, AttributeCommonInfo::Scope> ScopeList[] =
+ {{"", AttributeCommonInfo::Scope::NONE},
+ {"clang", AttributeCommonInfo::Scope::CLANG},
+ {"gnu", AttributeCommonInfo::Scope::GNU},
+ {"gsl", AttributeCommonInfo::Scope::GSL},
+ {"hlsl", AttributeCommonInfo::Scope::HLSL},
+ {"msvc", AttributeCommonInfo::Scope::MSVC},
+ {"omp", AttributeCommonInfo::Scope::OMP},
+ {"riscv", AttributeCommonInfo::Scope::RISCV}};
+
+AttributeCommonInfo::Scope
+getScopeFromNormalizedScopeName(StringRef ScopeName) {
+ auto It = std::lower_bound(
+ std::begin(ScopeList), std::end(ScopeList), ScopeName,
+ [](const std::pair<StringRef, AttributeCommonInfo::Scope> &Element,
+ StringRef Value) { return Element.first < Value; });
+ assert(It != std::end(ScopeList) && It->first == ScopeName);
+
+ return It->second;
----------------
erichkeane wrote:
Ooof, yeah, you're right. This should jsut be a `StringSwitch`...
https://github.com/llvm/llvm-project/pull/114899
More information about the cfe-commits
mailing list