@@ -3854,91 +3854,55 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper &Records,
3854
3854
continue ;
3855
3855
}
3856
3856
3857
- bool HasSingleUniqueSpellingName = true ;
3858
- StringMap<std::vector<const FlattenedSpelling *>> SpellingMap;
3859
-
3860
- StringRef FirstName = Spellings.front ().name ();
3861
- for (const auto &S : Spellings) {
3862
- StringRef Name = S.name ();
3863
- if (Name != FirstName)
3864
- HasSingleUniqueSpellingName = false ;
3865
- SpellingMap[Name].push_back (&S);
3866
- }
3867
-
3868
- // If parsed attribute has only one possible spelling name, only compare
3869
- // syntax and scope.
3870
- if (HasSingleUniqueSpellingName) {
3871
- for (const auto &[Idx, S] : enumerate(SpellingMap[FirstName])) {
3872
- OS << " if (getSyntax() == AttributeCommonInfo::AS_" << S->variety ()
3857
+ std::vector<StringRef> Names;
3858
+ llvm::transform (Spellings, std::back_inserter (Names),
3859
+ [](const FlattenedSpelling &FS) { return FS.name (); });
3860
+ llvm::sort (Names);
3861
+ Names.erase (llvm::unique (Names), Names.end ());
3862
+
3863
+ for (const auto &[Idx, FS] : enumerate(Spellings)) {
3864
+ if (Names.size () == 1 ) {
3865
+ OS << " if (getSyntax() == AttributeCommonInfo::AS_" << FS.variety ()
3873
3866
<< " && ComputedScope == " ;
3874
3867
3875
- if (S-> nameSpace () == " " )
3876
- OS << " AttributeCommonInfo::SC_NONE " ;
3868
+ if (FS. nameSpace () == " " )
3869
+ OS << " AttributeCommonInfo::Scope::NONE " ;
3877
3870
else
3878
- OS << " AttributeCommonInfo::SC_ " + S-> nameSpace ().upper ();
3871
+ OS << " AttributeCommonInfo::Scope:: " + FS. nameSpace ().upper ();
3879
3872
3880
3873
OS << " )\n "
3881
3874
<< " return " << Idx << " ;\n " ;
3882
- }
3883
- } else {
3884
- size_t Idx = 0 ;
3885
- StringMap<bool > Completed;
3886
- for (const auto &Spell : Spellings) {
3887
- if (Completed.contains (Spell.name ()))
3888
- continue ;
3875
+ } else {
3876
+ SmallVector<StringRef, 6 > SameLenNames;
3877
+ llvm::copy_if (
3878
+ Names, std::back_inserter (SameLenNames),
3879
+ [&](StringRef N) { return N.size () == FS.name ().size (); });
3880
+
3881
+ if (SameLenNames.size () == 1 ) {
3882
+ OS << " if (Name.size() == " << FS.name ().size ()
3883
+ << " && getSyntax() == AttributeCommonInfo::AS_" << FS.variety ()
3884
+ << " && ComputedScope == " ;
3889
3885
3890
- const std::vector<const FlattenedSpelling *> &Cases =
3891
- SpellingMap[Spell.name ()];
3892
-
3893
- if (Cases.size () > 1 ) {
3894
- // For names with multiple possible cases, emit an enclosing if such
3895
- // that the name is compared against only once. Eg:
3896
- //
3897
- // if (Name == "always_inline") {
3898
- // if (getSyntax() == AttributeCommonInfo::AS_GNU &&
3899
- // ComputedScope == AttributeCommonInfo::SC_None)
3900
- // return 0;
3901
- // ...
3902
- // }
3903
- OS << " if (Name == \" " << Spell.name () << " \" ) {\n " ;
3904
- for (const auto &S : SpellingMap[Spell.name ()]) {
3905
- OS << " if (getSyntax() == AttributeCommonInfo::AS_"
3906
- << S->variety () << " && ComputedScope == " ;
3907
-
3908
- if (S->nameSpace () == " " )
3909
- OS << " AttributeCommonInfo::SC_NONE" ;
3910
- else
3911
- OS << " AttributeCommonInfo::SC_" + S->nameSpace ().upper ();
3912
-
3913
- OS << " )\n "
3914
- << " return " << Idx << " ;\n " ;
3915
- Idx++;
3916
- }
3917
- OS << " }\n " ;
3886
+ if (FS.nameSpace () == " " )
3887
+ OS << " AttributeCommonInfo::Scope::NONE" ;
3888
+ else
3889
+ OS << " AttributeCommonInfo::Scope::" + FS.nameSpace ().upper ();
3890
+
3891
+ OS << " )\n "
3892
+ << " return " << Idx << " ;\n " ;
3918
3893
} else {
3919
- // If there is only possible case for the spelling name, no need of
3920
- // enclosing if. Eg.
3921
- //
3922
- // if (Name == "__forceinline" &&
3923
- // getSyntax() == AttributeCommonInfo::AS_Keyword
3924
- // && ComputedScope == AttributeCommonInfo::SC_NONE)
3925
- // return 5;
3926
- const FlattenedSpelling *S = Cases.front ();
3927
- OS << " if (Name == \" " << Spell.name () << " \" "
3928
- << " && getSyntax() == AttributeCommonInfo::AS_" << S->variety ()
3894
+ OS << " if (Name == \" " << FS.name () << " \" "
3895
+ << " && getSyntax() == AttributeCommonInfo::AS_" << FS.variety ()
3929
3896
<< " && ComputedScope == " ;
3930
3897
3931
- std::string ScopeStr = " AttributeCommonInfo::SC_" ;
3932
- if (S->nameSpace () == " " )
3933
- OS << " AttributeCommonInfo::SC_NONE" ;
3898
+ if (FS.nameSpace () == " " )
3899
+ OS << " AttributeCommonInfo::Scope::NONE" ;
3934
3900
else
3935
- OS << " AttributeCommonInfo::SC_ " + S-> nameSpace ().upper ();
3901
+ OS << " AttributeCommonInfo::Scope:: " + FS. nameSpace ().upper ();
3936
3902
3937
3903
OS << " )\n "
3938
- << " return " << Idx << " ;\n " ;
3939
- Idx++;
3904
+ << " return " << Idx << " ;\n " ;
3940
3905
}
3941
- Completed[Spell.name ()] = true ;
3942
3906
}
3943
3907
}
3944
3908
0 commit comments