@@ -3848,9 +3848,9 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper &Records,
3848
3848
// If there are none or one spelling to check, resort to the default
3849
3849
// behavior of returning index as 0.
3850
3850
if (Spellings.size () <= 1 ) {
3851
- OS << " return 0;\n " ;
3852
- OS << " break;\n " ;
3853
- OS << " }\n " ;
3851
+ OS << " return 0;\n "
3852
+ << " break;\n "
3853
+ << " }\n " ;
3854
3854
continue ;
3855
3855
}
3856
3856
@@ -3869,22 +3869,26 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper &Records,
3869
3869
// syntax and scope.
3870
3870
if (HasSingleUniqueSpellingName) {
3871
3871
for (const auto &[Idx, S] : enumerate(SpellingMap[FirstName])) {
3872
- OS << " if (getSyntax() == AttributeCommonInfo::AS_" << S->variety ();
3872
+ OS << " if (getSyntax() == AttributeCommonInfo::AS_" << S->variety ()
3873
+ << " && ComputedScope == " ;
3873
3874
3874
- std::string ScopeStr = " AttributeCommonInfo::SC_" ;
3875
3875
if (S->nameSpace () == " " )
3876
- ScopeStr += " NONE " ;
3876
+ OS << " AttributeCommonInfo::SC_NONE " ;
3877
3877
else
3878
- ScopeStr += S->nameSpace ().upper ();
3878
+ OS << " AttributeCommonInfo::SC_ " + S->nameSpace ().upper ();
3879
3879
3880
- OS << " && ComputedScope == " << ScopeStr << " )\n "
3880
+ OS << " )\n "
3881
3881
<< " return " << Idx << " ;\n " ;
3882
3882
}
3883
3883
} else {
3884
3884
size_t Idx = 0 ;
3885
- for (const auto &MapEntry : SpellingMap) {
3886
- StringRef Name = MapEntry.first ();
3887
- const std::vector<const FlattenedSpelling *> &Cases = SpellingMap[Name];
3885
+ StringMap<bool > Completed;
3886
+ for (const auto &Spell : Spellings) {
3887
+ if (Completed.contains (Spell.name ()))
3888
+ continue ;
3889
+
3890
+ const std::vector<const FlattenedSpelling *> &Cases =
3891
+ SpellingMap[Spell.name ()];
3888
3892
3889
3893
if (Cases.size () > 1 ) {
3890
3894
// For names with multiple possible cases, emit an enclosing if such
@@ -3896,17 +3900,17 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper &Records,
3896
3900
// return 0;
3897
3901
// ...
3898
3902
// }
3899
- OS << " if (Name == \" " << Name << " \" ) {\n " ;
3900
- for (const auto &S : SpellingMap[Name ]) {
3903
+ OS << " if (Name == \" " << Spell. name () << " \" ) {\n " ;
3904
+ for (const auto &S : SpellingMap[Spell. name () ]) {
3901
3905
OS << " if (getSyntax() == AttributeCommonInfo::AS_"
3902
- << S->variety ();
3903
- std::string ScopeStr = " AttributeCommonInfo::SC_ " ;
3906
+ << S->variety () << " && ComputedScope == " ;
3907
+
3904
3908
if (S->nameSpace () == " " )
3905
- ScopeStr += " NONE " ;
3909
+ OS << " AttributeCommonInfo::SC_NONE " ;
3906
3910
else
3907
- ScopeStr += S->nameSpace ().upper ();
3911
+ OS << " AttributeCommonInfo::SC_ " + S->nameSpace ().upper ();
3908
3912
3909
- OS << " && ComputedScope == " << ScopeStr << " )\n "
3913
+ OS << " )\n "
3910
3914
<< " return " << Idx << " ;\n " ;
3911
3915
Idx++;
3912
3916
}
@@ -3920,27 +3924,30 @@ void EmitClangAttrSpellingListIndex(const RecordKeeper &Records,
3920
3924
// && ComputedScope == AttributeCommonInfo::SC_NONE)
3921
3925
// return 5;
3922
3926
const FlattenedSpelling *S = Cases.front ();
3923
- OS << " if (Name == \" " << Name << " \" " ;
3924
- OS << " && getSyntax() == AttributeCommonInfo::AS_" << S->variety ();
3927
+ OS << " if (Name == \" " << Spell.name () << " \" "
3928
+ << " && getSyntax() == AttributeCommonInfo::AS_" << S->variety ()
3929
+ << " && ComputedScope == " ;
3930
+
3925
3931
std::string ScopeStr = " AttributeCommonInfo::SC_" ;
3926
3932
if (S->nameSpace () == " " )
3927
- ScopeStr += " NONE " ;
3933
+ OS << " AttributeCommonInfo::SC_NONE " ;
3928
3934
else
3929
- ScopeStr += S->nameSpace ().upper ();
3935
+ OS << " AttributeCommonInfo::SC_ " + S->nameSpace ().upper ();
3930
3936
3931
- OS << " && ComputedScope == " << ScopeStr << " )\n "
3937
+ OS << " )\n "
3932
3938
<< " return " << Idx << " ;\n " ;
3933
3939
Idx++;
3934
3940
}
3941
+ Completed[Spell.name ()] = true ;
3935
3942
}
3936
3943
}
3937
3944
3938
- OS << " break;\n " ;
3939
- OS << " }\n " ;
3945
+ OS << " break;\n "
3946
+ << " }\n " ;
3940
3947
}
3941
3948
3942
- OS << " }\n " ;
3943
- OS << " return 0;\n " ;
3949
+ OS << " }\n "
3950
+ << " return 0;\n " ;
3944
3951
}
3945
3952
3946
3953
// Emits code used by RecursiveASTVisitor to visit attributes
0 commit comments