mirror of
https://github.com/mappu/miqt.git
synced 2025-04-27 23:50:22 +00:00
genbindings/transform: sort QVariant(QVariantList) ctor to end
This commit is contained in:
parent
b3b783f3d6
commit
a58ac873a2
@ -4,30 +4,56 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
// astTransformConstructorOrder creates a canonical ordering for constructors
|
// 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) {
|
func astTransformConstructorOrder(parsed *CppParsedHeader) {
|
||||||
|
|
||||||
// QFoo(QWidget* parent);
|
// QFoo(QWidget* parent);
|
||||||
checkIsDefaultCtor := func(candidate CppMethod) bool {
|
checkIsDefaultCtor := func(candidate *CppMethod) bool {
|
||||||
return len(candidate.Parameters) == 1 &&
|
return len(candidate.Parameters) == 1 &&
|
||||||
candidate.Parameters[0].ParameterType == "QWidget" &&
|
candidate.Parameters[0].ParameterType == "QWidget" &&
|
||||||
candidate.Parameters[0].Pointer
|
candidate.Parameters[0].Pointer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QFoo(QVariantList);
|
||||||
|
checkIsQVariantListCtor := func(candidate *CppMethod) bool {
|
||||||
|
if len(candidate.Parameters) != 1 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if t, _, ok := candidate.Parameters[0].QListOf(); ok && t.ParameterType == "QVariant" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Iterate all classes
|
// Iterate all classes
|
||||||
for i, c := range parsed.Classes {
|
for i, c := range parsed.Classes {
|
||||||
|
|
||||||
// Sort
|
// Sort
|
||||||
sort.SliceStable(c.Ctors, func(i, j int) bool {
|
sort.SliceStable(c.Ctors, func(i, j int) bool {
|
||||||
ic := checkIsDefaultCtor(c.Ctors[i])
|
// Case 1: Default ctors are moved to front,
|
||||||
jc := checkIsDefaultCtor(c.Ctors[j])
|
// so 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
|
||||||
|
ic := checkIsDefaultCtor(&c.Ctors[i])
|
||||||
|
jc := checkIsDefaultCtor(&c.Ctors[j])
|
||||||
|
|
||||||
if ic && !jc {
|
if ic && !jc {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Case 2: QVariantList overload is moved to end
|
||||||
|
// This softens a compatibility break churning all the QVariant
|
||||||
|
// constructor ordinals when QVariantList was unblocked.
|
||||||
|
// @ref https://github.com/mappu/miqt/issues/188
|
||||||
|
ic = checkIsQVariantListCtor(&c.Ctors[i])
|
||||||
|
jc = checkIsQVariantListCtor(&c.Ctors[j])
|
||||||
|
|
||||||
|
if !ic && jc {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Case 3: Normal
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user