genbindings/transform: come up with better overload names

This commit is contained in:
mappu 2024-08-17 11:25:20 +12:00
parent aeb667d780
commit 4ee89b157f
1 changed files with 9 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"strings"
) )
// astTransformOverloads renames methods if another method exists with the same // astTransformOverloads renames methods if another method exists with the same
@ -36,7 +37,14 @@ func astTransformOverloads(parsed *CppParsedHeader) {
// e.g. NewVariantFromFloat // e.g. NewVariantFromFloat
if len(m.Parameters) == 1 { 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 = rootMethodName + "With" + titleCase(m.Parameters[0].ParameterName) proposedName = rootMethodName + "With" + titleCase(m.Parameters[0].ParameterName)
} else {
// Try the type instead
proposedName = rootMethodName + "With" + titleCase(strings.Replace(m.Parameters[0].ParameterType, " ", "", -1))
}
if _, ok := existing[proposedName]; !ok { if _, ok := existing[proposedName]; !ok {
break break
} }