mirror of
https://github.com/mappu/miqt.git
synced 2025-02-02 03:20:25 +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)
|
tmp := replacer.Replace(nm.MethodName)
|
||||||
|
|
||||||
// Also make the first letter uppercase so it becomes public in Go
|
// 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 {
|
type CppClass struct {
|
||||||
|
@ -26,13 +26,29 @@ func astTransformOverloads(parsed *CppParsedHeader) {
|
|||||||
rootMethodName = m.MethodName
|
rootMethodName = m.MethodName
|
||||||
}
|
}
|
||||||
|
|
||||||
ctr := 2
|
ctr := 1
|
||||||
var proposedName string
|
var proposedName string
|
||||||
for {
|
for {
|
||||||
|
|
||||||
|
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)
|
proposedName = fmt.Sprintf("%s%d", rootMethodName, ctr)
|
||||||
if _, ok := existing[proposedName]; !ok {
|
if _, ok := existing[proposedName]; !ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ctr++ // Loop until we have a non-colliding name available
|
ctr++ // Loop until we have a non-colliding name available
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func maybeSuffix(counter int) string {
|
func maybeSuffix(counter int) string {
|
||||||
@ -11,3 +12,7 @@ func maybeSuffix(counter int) string {
|
|||||||
|
|
||||||
return fmt.Sprintf("%d", counter+1)
|
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