mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 08:58:37 +00:00
genbindings: reorder ctors to put (QWidget* parent) version first
This commit is contained in:
parent
2a8b59eb76
commit
ecab4f1d09
@ -161,6 +161,7 @@ func generate(packageName string, srcDirs []string, clangBin, cflagsCombined, ou
|
||||
astTransformChildClasses(parsed) // must be first
|
||||
astTransformOptional(parsed)
|
||||
astTransformOverloads(parsed)
|
||||
astTransformConstructorOrder(parsed)
|
||||
atr.Process(parsed)
|
||||
|
||||
// Update global state tracker (AFTER astTransformChildClasses)
|
||||
|
38
cmd/genbindings/transformctors.go
Normal file
38
cmd/genbindings/transformctors.go
Normal file
@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
// astTransformConstructorOrder creates a canonical ordering for constructors
|
||||
// where the 0th entry is any entry taking solely a QWidget* parameter.
|
||||
// This is so that UIC can safely assume this for types.
|
||||
// @ref https://github.com/mappu/miqt/issues/46
|
||||
func astTransformConstructorOrder(parsed *CppParsedHeader) {
|
||||
|
||||
// QFoo(QWidget* parent);
|
||||
checkIsDefaultCtor := func(candidate CppMethod) bool {
|
||||
return len(candidate.Parameters) == 1 &&
|
||||
candidate.Parameters[0].ParameterType == "QWidget" &&
|
||||
candidate.Parameters[0].Pointer
|
||||
}
|
||||
|
||||
// Iterate all classes
|
||||
for i, c := range parsed.Classes {
|
||||
|
||||
// Sort
|
||||
sort.SliceStable(c.Ctors, func(i, j int) bool {
|
||||
ic := checkIsDefaultCtor(c.Ctors[i])
|
||||
jc := checkIsDefaultCtor(c.Ctors[j])
|
||||
|
||||
if ic && !jc {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
// Persist mutation
|
||||
parsed.Classes[i] = c
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user