mirror of
https://github.com/mappu/miqt.git
synced 2025-04-27 15:40:21 +00:00
genbindings: move applyQuirks into a transform pass, isolate packageName
This commit is contained in:
parent
9c8338b7ec
commit
329ea18df8
@ -398,8 +398,6 @@ nextMethod:
|
||||
continue
|
||||
}
|
||||
|
||||
ApplyQuirks(ret.ClassName, &mm)
|
||||
|
||||
ret.Ctors = append(ret.Ctors, mm)
|
||||
|
||||
case "CXXDestructorDecl":
|
||||
@ -493,8 +491,6 @@ nextMethod:
|
||||
return CppClass{}, err
|
||||
}
|
||||
|
||||
ApplyQuirks(ret.ClassName, &mm)
|
||||
|
||||
ret.Methods = append(ret.Methods, mm)
|
||||
|
||||
default:
|
||||
|
@ -631,7 +631,9 @@ func AllowType(p CppParameter, isReturnType bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ApplyQuirks(className string, mm *CppMethod) {
|
||||
// ApplyQuirks adds flags to methods that require special handling.
|
||||
// This is evaluated early, before optional arguments are expanded.
|
||||
func ApplyQuirks(packageName, className string, mm *CppMethod) {
|
||||
|
||||
if mm.ReturnType.GetQtCppType().ParameterType == "Q_PID" {
|
||||
// int64 on Linux, _PROCESS_INFORMATION* on Windows
|
||||
@ -648,11 +650,11 @@ func ApplyQuirks(className string, mm *CppMethod) {
|
||||
mm.BecomesNonConstInVersion = addr("6.7")
|
||||
}
|
||||
|
||||
if className == "QObjectData" && mm.MethodName == "dynamicMetaObject" {
|
||||
if packageName == "qt6" && className == "QObjectData" && mm.MethodName == "dynamicMetaObject" {
|
||||
mm.ReturnType.BecomesConstInVersion = addr("6.9")
|
||||
}
|
||||
|
||||
if className == "QFileDialog" && mm.MethodName == "saveFileContent" && mm.IsStatic {
|
||||
if className == "QFileDialog" && mm.MethodName == "saveFileContent" && mm.IsStatic && len(mm.Parameters) > 1 {
|
||||
// The prototype was changed from
|
||||
// [Qt 5 - 6.6] void QFileDialog::saveFileContent(const QByteArray &fileContent, const QString &fileNameHint = QString())
|
||||
// [Qt 6.7] void QFileDialog::saveFileContent(const QByteArray &fileContent, const QString &fileNameHint, QWidget *parent = nullptr)
|
||||
|
@ -864,7 +864,7 @@ extern "C" {
|
||||
continue // Can't call directly, have to go through our wrapper
|
||||
}
|
||||
|
||||
if m.ReturnType.BecomesConstInVersion != nil && packageName == "qt6" {
|
||||
if m.ReturnType.BecomesConstInVersion != nil {
|
||||
ret.WriteString(fmt.Sprintf("// This method's return type was changed from non-const to const in Qt "+*m.ReturnType.BecomesConstInVersion) + "\n" +
|
||||
"#if QT_VERSION >= QT_VERSION_CHECK(" + strings.Replace(*m.ReturnType.BecomesConstInVersion, `.`, `,`, -1) + ",0)\n" +
|
||||
fmt.Sprintf("%s %s(%s);\n", "const "+m.ReturnType.RenderTypeCabi(), cabiMethodName(c, m), emitParametersCabi(m, ifv(m.IsConst, "const ", "")+className+"*")) +
|
||||
@ -1270,7 +1270,7 @@ extern "C" {
|
||||
"\n",
|
||||
)
|
||||
|
||||
} else if m.ReturnType.BecomesConstInVersion != nil && strings.Contains(src.Filename, "qt6") {
|
||||
} else if m.ReturnType.BecomesConstInVersion != nil {
|
||||
|
||||
ret.WriteString("" +
|
||||
"// This method's return type was changed from non-const to const in Qt " + *m.ReturnType.BecomesConstInVersion + "\n" +
|
||||
|
@ -157,7 +157,8 @@ func generate(packageName string, srcDirs []string, allowHeaderFn func(string) b
|
||||
parsed.Filename = inputHeader // Stash
|
||||
|
||||
// AST transforms on our IL
|
||||
astTransformChildClasses(parsed) // must be first
|
||||
astTransformChildClasses(parsed) // must be first
|
||||
astTransformApplyQuirks(packageName, parsed) // must be before optional/overload expansion
|
||||
astTransformOptional(parsed)
|
||||
astTransformOverloads(parsed)
|
||||
astTransformConstructorOrder(parsed)
|
||||
|
21
cmd/genbindings/transformquirks.go
Normal file
21
cmd/genbindings/transformquirks.go
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
// astTransformApplyQuirks applies quirk flags to the class/method.
|
||||
func astTransformApplyQuirks(packageName string, parsed *CppParsedHeader) {
|
||||
|
||||
for i, c := range parsed.Classes {
|
||||
|
||||
// Constructors
|
||||
|
||||
for j, _ := range c.Ctors {
|
||||
ApplyQuirks(packageName, c.ClassName, &parsed.Classes[i].Ctors[j])
|
||||
}
|
||||
|
||||
// Methods
|
||||
|
||||
for j, _ := range c.Methods {
|
||||
ApplyQuirks(packageName, c.ClassName, &parsed.Classes[i].Methods[j])
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user