mirror of
https://github.com/mappu/miqt.git
synced 2025-01-21 22:20:38 +00:00
genbindings: try to invent better names for function overloads
This commit is contained in:
parent
2ccc11f57d
commit
b89aeb2aa7
@ -88,7 +88,7 @@ func (nm CppMethod) SafeMethodName() string {
|
||||
tmp := replacer.Replace(nm.MethodName)
|
||||
|
||||
// Also make the first letter uppercase so it becomes public in Go
|
||||
return strings.ToUpper(tmp[0:1]) + tmp[1:]
|
||||
return titleCase(tmp)
|
||||
}
|
||||
|
||||
type CppClass struct {
|
||||
|
@ -26,12 +26,28 @@ func astTransformOverloads(parsed *CppParsedHeader) {
|
||||
rootMethodName = m.MethodName
|
||||
}
|
||||
|
||||
ctr := 2
|
||||
ctr := 1
|
||||
var proposedName string
|
||||
for {
|
||||
proposedName = fmt.Sprintf("%s%d", rootMethodName, ctr)
|
||||
if _, ok := existing[proposedName]; !ok {
|
||||
break
|
||||
|
||||
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 {
|
||||
|
||||
proposedName = rootMethodName + "With" + titleCase(m.Parameters[0].ParameterName)
|
||||
if _, ok := existing[proposedName]; !ok {
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
proposedName = fmt.Sprintf("%s%d", rootMethodName, ctr)
|
||||
if _, ok := existing[proposedName]; !ok {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
ctr++ // Loop until we have a non-colliding name available
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func maybeSuffix(counter int) string {
|
||||
@ -11,3 +12,7 @@ func maybeSuffix(counter int) string {
|
||||
|
||||
return fmt.Sprintf("%d", counter+1)
|
||||
}
|
||||
|
||||
func titleCase(s string) string {
|
||||
return strings.ToUpper(s[0:1]) + s[1:]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user