genbindings/transform: overload disambiguation must be based on go names

This commit is contained in:
mappu 2024-08-22 19:20:12 +12:00
parent cd16ed9028
commit cf430b6cc5
2 changed files with 15 additions and 14 deletions

View File

@ -68,8 +68,8 @@ type CppProperty struct {
} }
type CppMethod struct { type CppMethod struct {
MethodName string MethodName string // C++ method name, unless OverrideMethodName is set, in which case a nice alternative name
OverrideMethodName string // Present only if we changed the target OverrideMethodName string // C++ method name, present only if we changed the target
ReturnType CppParameter // Name not used ReturnType CppParameter // Name not used
Parameters []CppParameter Parameters []CppParameter
IsStatic bool IsStatic bool

View File

@ -14,21 +14,18 @@ func astTransformOverloads(parsed *CppParsedHeader) {
existing := map[string]struct{}{} existing := map[string]struct{}{}
for j, m := range c.Methods { for j, m := range c.Methods {
if _, ok := existing[m.MethodName]; !ok { originalProposal := m.SafeMethodName()
existing[m.MethodName] = struct{}{} proposedName := originalProposal
if _, ok := existing[proposedName]; !ok {
existing[proposedName] = struct{}{}
continue // No collision continue // No collision
} }
// Collision - rename // Collision - rename
anyChange = true anyChange = true
rootMethodName := m.OverrideMethodName
if rootMethodName == "" {
rootMethodName = m.MethodName
}
ctr := 1 ctr := 1
var proposedName string
for { for {
if ctr == 1 { if ctr == 1 {
@ -40,10 +37,10 @@ func astTransformOverloads(parsed *CppParsedHeader) {
// If the parameter has a proper name (i.e. not 'l' or 'param1') // If the parameter has a proper name (i.e. not 'l' or 'param1')
// then go with that // then go with that
if len(m.Parameters[0].ParameterName) > 1 && !strings.HasPrefix(m.Parameters[0].ParameterName, "param") { if len(m.Parameters[0].ParameterName) > 1 && !strings.HasPrefix(m.Parameters[0].ParameterName, "param") {
proposedName = rootMethodName + "With" + titleCase(m.Parameters[0].ParameterName) proposedName = originalProposal + "With" + titleCase(m.Parameters[0].ParameterName)
} else { } else {
// Try the type instead // Try the type instead
proposedName = rootMethodName + "With" + titleCase(strings.Replace(m.Parameters[0].ParameterType, " ", "", -1)) proposedName = originalProposal + "With" + titleCase(strings.Replace(m.Parameters[0].ParameterType, " ", "", -1))
} }
if _, ok := existing[proposedName]; !ok { if _, ok := existing[proposedName]; !ok {
break break
@ -52,7 +49,7 @@ func astTransformOverloads(parsed *CppParsedHeader) {
} }
} else { } else {
proposedName = fmt.Sprintf("%s%d", rootMethodName, ctr) proposedName = fmt.Sprintf("%s%d", originalProposal, ctr)
if _, ok := existing[proposedName]; !ok { if _, ok := existing[proposedName]; !ok {
break break
} }
@ -62,7 +59,11 @@ func astTransformOverloads(parsed *CppParsedHeader) {
} }
existing[proposedName] = struct{}{} existing[proposedName] = struct{}{}
m.OverrideMethodName = rootMethodName if m.OverrideMethodName == "" {
m.OverrideMethodName = m.MethodName
} else {
// If it was already set, we're already a level of overload resolution deep - preserve it
}
m.MethodName = proposedName m.MethodName = proposedName
c.Methods[j] = m c.Methods[j] = m
} }