mirror of
https://github.com/mappu/miqt.git
synced 2025-04-27 15:40:21 +00:00
genbindings/transform: move "With" names outside the proposedName ctr
This commit is contained in:
parent
a5ae83b018
commit
c93eb2cd00
@ -29,39 +29,41 @@ func astTransformOverloads(parsed *CppParsedHeader) {
|
||||
// Collision - rename
|
||||
anyChange = true
|
||||
|
||||
ctr := 1
|
||||
for {
|
||||
proposedName = (func() (proposedName string) {
|
||||
|
||||
if ctr == 1 {
|
||||
// Fake special-case check
|
||||
// If this is a 1-argument function, try and name it FooFrom{Type}
|
||||
// e.g. NewVariantFromFloat
|
||||
if len(m.Parameters) == 1 {
|
||||
|
||||
// If the parameter has a proper name (i.e. not 'l' or 'param1')
|
||||
// then go with that
|
||||
if len(m.Parameters[0].ParameterName) > 1 && !strings.HasPrefix(m.Parameters[0].ParameterName, "param") {
|
||||
proposedName = originalProposal + "With" + titleCase(m.Parameters[0].ParameterName)
|
||||
} else {
|
||||
// Try the type instead
|
||||
proposedName = originalProposal + "With" + titleCase(m.Parameters[0].renderTypeForMethod())
|
||||
}
|
||||
if _, ok := existing[proposedName]; !ok {
|
||||
break
|
||||
}
|
||||
// Fake special-case check
|
||||
// If this is a 1-argument function, try and name it FooFrom{Type}
|
||||
// e.g. NewVariantFromFloat
|
||||
if len(m.Parameters) == 1 {
|
||||
|
||||
// If the parameter has a proper name (i.e. not 'l' or 'param1')
|
||||
// then go with that
|
||||
if len(m.Parameters[0].ParameterName) > 1 && !strings.HasPrefix(m.Parameters[0].ParameterName, "param") {
|
||||
proposedName = originalProposal + "With" + titleCase(m.Parameters[0].ParameterName)
|
||||
} else {
|
||||
// Try the type instead
|
||||
proposedName = originalProposal + "With" + titleCase(m.Parameters[0].renderTypeForMethod())
|
||||
}
|
||||
|
||||
} else {
|
||||
proposedName = fmt.Sprintf("%s%d", originalProposal, ctr)
|
||||
if _, ok := existing[proposedName]; !ok {
|
||||
break
|
||||
return proposedName
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ctr++ // Loop until we have a non-colliding name available
|
||||
}
|
||||
// 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)
|
||||
if _, ok := existing[proposedName]; !ok {
|
||||
return proposedName
|
||||
}
|
||||
|
||||
ctr++ // Loop until we have a non-colliding name available
|
||||
}
|
||||
})()
|
||||
|
||||
// We have identified a final replacement name
|
||||
existing[proposedName] = struct{}{}
|
||||
m.Rename(proposedName)
|
||||
c.Methods[j] = m
|
||||
|
Loading…
x
Reference in New Issue
Block a user