genbindings: apply quirks to ctors, merge LinuxOnly into quirks

This commit is contained in:
mappu 2025-04-11 22:07:15 +12:00
parent c2e299d381
commit aff87f98a2
3 changed files with 14 additions and 23 deletions

View File

@ -398,6 +398,8 @@ nextMethod:
continue
}
ApplyQuirks(ret.ClassName, &mm)
ret.Ctors = append(ret.Ctors, mm)
case "CXXDestructorDecl":

View File

@ -632,21 +632,19 @@ func AllowType(p CppParameter, isReturnType bool) error {
return nil
}
// LinuxWindowsCompatCheck checks if the parameter is incompatible between the
// generated headers (generated on Linux) with other OSes such as Windows.
// These methods will be blocked on non-Linux OSes.
func LinuxWindowsCompatCheck(p CppParameter) bool {
if p.GetQtCppType().ParameterType == "Q_PID" {
return true // int64 on Linux, _PROCESS_INFORMATION* on Windows
}
if p.GetQtCppType().ParameterType == "QSocketDescriptor::DescriptorType" {
return true // uintptr_t-compatible on Linux, void* on Windows
}
return false
}
func ApplyQuirks(className string, mm *CppMethod) {
if mm.ReturnType.GetQtCppType().ParameterType == "Q_PID" {
// int64 on Linux, _PROCESS_INFORMATION* on Windows
mm.LinuxOnly = true
}
if mm.ReturnType.GetQtCppType().ParameterType == "QSocketDescriptor::DescriptorType" ||
(len(mm.Parameters) > 0 && mm.Parameters[0].GetQtCppType().ParameterType == "QSocketDescriptor::DescriptorType") {
// uintptr_t-compatible on Linux, void* on Windows
mm.LinuxOnly = true
}
if className == "QArrayData" && mm.MethodName == "needsDetach" && mm.IsConst {
mm.BecomesNonConstInVersion = addr("6.7")
}

View File

@ -68,18 +68,9 @@ func applyTypedefs_Method(m *CppMethod) {
for k, p := range m.Parameters {
transformed := applyTypedefs(p)
m.Parameters[k] = transformed
if LinuxWindowsCompatCheck(transformed) {
m.LinuxOnly = true
}
}
m.ReturnType = applyTypedefs(m.ReturnType)
// Also apply OS compatibility rules
if LinuxWindowsCompatCheck(m.ReturnType) {
m.LinuxOnly = true
}
}
// astTransformTypedefs replaces the ParameterType with any known typedef value.