================ @@ -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; ---------------- nikic wrote:
This looks like exactly what `StringSwitch` is for... https://github.com/llvm/llvm-project/pull/114899 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits