[clang] [Clang] Improve EmitClangAttrSpellingListIndex (PR #114899)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 7 06:37:35 PST 2024
================
@@ -3843,19 +3844,60 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper &Records,
const Record &R = *I.second;
std::vector<FlattenedSpelling> Spellings = GetFlattenedSpellings(R);
OS << " case AT_" << I.first << ": {\n";
- for (unsigned I = 0; I < Spellings.size(); ++ I) {
- OS << " if (Name == \"" << Spellings[I].name() << "\" && "
- << "getSyntax() == AttributeCommonInfo::AS_" << Spellings[I].variety()
- << " && Scope == \"" << Spellings[I].nameSpace() << "\")\n"
- << " return " << I << ";\n";
+
+ // If there are none or one spelling to check, resort to the default
+ // behavior of returning index as 0.
+ if (Spellings.size() <= 1) {
+ OS << " return 0;\n"
+ << " break;\n"
+ << " }\n";
+ continue;
}
- OS << " break;\n";
- OS << " }\n";
+ std::vector<StringRef> Names;
+ llvm::transform(Spellings, std::back_inserter(Names),
+ [](const FlattenedSpelling &FS) { return FS.name(); });
+ llvm::sort(Names);
+ Names.erase(llvm::unique(Names), Names.end());
+
+ for (const auto &[Idx, FS] : enumerate(Spellings)) {
+ if (Names.size() == 1) {
+ OS << " if (";
----------------
erichkeane wrote:
As a nit, I'd suggest printing this unconditionally above this 'if', then inverting it for the 'else' condition (since 3873 and 3879 are both printing this too).
https://github.com/llvm/llvm-project/pull/114899
More information about the cfe-commits
mailing list