mirror of
https://github.com/mappu/miqt.git
synced 2024-12-23 01:18:37 +00:00
genbindings: handle function overloads
This commit is contained in:
parent
8de91463f5
commit
4d94d4cd34
@ -60,6 +60,7 @@ func main() {
|
|||||||
|
|
||||||
// AST transforms on our IL
|
// AST transforms on our IL
|
||||||
astTransformOptional(parsed)
|
astTransformOptional(parsed)
|
||||||
|
astTransformOverloads(parsed)
|
||||||
|
|
||||||
// Emit 3 code files from the intermediate format
|
// Emit 3 code files from the intermediate format
|
||||||
outputName := filepath.Join(*outDir, "gen_"+strings.TrimSuffix(filepath.Base(*inputHeader), `.h`))
|
outputName := filepath.Join(*outDir, "gen_"+strings.TrimSuffix(filepath.Base(*inputHeader), `.h`))
|
||||||
|
45
cmd/genbindings/transformoverload.go
Normal file
45
cmd/genbindings/transformoverload.go
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// astTransformOverloads renames methods if another method exists with the same
|
||||||
|
// name.
|
||||||
|
func astTransformOverloads(parsed *CppParsedHeader) {
|
||||||
|
for i, c := range parsed.Classes {
|
||||||
|
|
||||||
|
anyChange := false
|
||||||
|
existing := map[string]struct{}{}
|
||||||
|
for j, m := range c.Methods {
|
||||||
|
|
||||||
|
if _, ok := existing[m.MethodName]; !ok {
|
||||||
|
existing[m.MethodName] = struct{}{}
|
||||||
|
continue // No collision
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collision - rename
|
||||||
|
anyChange = true
|
||||||
|
|
||||||
|
ctr := 2
|
||||||
|
var proposedName string
|
||||||
|
for {
|
||||||
|
proposedName = fmt.Sprintf("%s%d", m.MethodName, ctr)
|
||||||
|
if _, ok := existing[proposedName]; !ok {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
ctr++ // Loop until we have a non-colliding name available
|
||||||
|
}
|
||||||
|
|
||||||
|
existing[proposedName] = struct{}{}
|
||||||
|
m.OverrideMethodName = m.MethodName
|
||||||
|
m.MethodName = proposedName
|
||||||
|
c.Methods[j] = m
|
||||||
|
}
|
||||||
|
|
||||||
|
if anyChange {
|
||||||
|
parsed.Classes[i] = c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user