genbindings/transform: move "With" names outside the proposedName ctr

This commit is contained in:
mappu 2025-04-11 22:20:20 +12:00
parent a5ae83b018
commit c93eb2cd00

View File

@ -29,10 +29,8 @@ func astTransformOverloads(parsed *CppParsedHeader) {
// Collision - rename // Collision - rename
anyChange = true anyChange = true
ctr := 1 proposedName = (func() (proposedName string) {
for {
if ctr == 1 {
// Fake special-case check // Fake special-case check
// If this is a 1-argument function, try and name it FooFrom{Type} // If this is a 1-argument function, try and name it FooFrom{Type}
// e.g. NewVariantFromFloat // e.g. NewVariantFromFloat
@ -47,21 +45,25 @@ func astTransformOverloads(parsed *CppParsedHeader) {
proposedName = originalProposal + "With" + titleCase(m.Parameters[0].renderTypeForMethod()) proposedName = originalProposal + "With" + titleCase(m.Parameters[0].renderTypeForMethod())
} }
if _, ok := existing[proposedName]; !ok { if _, ok := existing[proposedName]; !ok {
break return proposedName
} }
} }
} else { // No special naming, have to use a numeric overload
// Numbers start with 2 since the "original" is the first
ctr := 2
for {
proposedName = fmt.Sprintf("%s%d", originalProposal, ctr) proposedName = fmt.Sprintf("%s%d", originalProposal, ctr)
if _, ok := existing[proposedName]; !ok { if _, ok := existing[proposedName]; !ok {
break return proposedName
}
} }
ctr++ // Loop until we have a non-colliding name available ctr++ // Loop until we have a non-colliding name available
} }
})()
// We have identified a final replacement name
existing[proposedName] = struct{}{} existing[proposedName] = struct{}{}
m.Rename(proposedName) m.Rename(proposedName)
c.Methods[j] = m c.Methods[j] = m