From 9055f6e2aec63e90a1b66a553a4116d002a58b78 Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 21 Sep 2024 10:29:20 +1200 Subject: [PATCH] genbindings: centralize AllowSignal/AllowMethod exceptions, block metacast signal --- cmd/genbindings/clang2il.go | 22 +++++++++------------- cmd/genbindings/exceptions.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/cmd/genbindings/clang2il.go b/cmd/genbindings/clang2il.go index 262591c0..c8bad7b9 100644 --- a/cmd/genbindings/clang2il.go +++ b/cmd/genbindings/clang2il.go @@ -442,22 +442,18 @@ nextMethod: return CppClass{}, err } - for _, p := range mm.Parameters { - if strings.HasSuffix(p.ParameterType, "Private") { - log.Printf("Skipping method %q taking Private type", mm.MethodName) + mm.IsSignal = isSignal && !mm.IsStatic && AllowSignal(mm) + + // Once all processing is complete, pass to exceptions for final decision + + if err := AllowMethod(mm); err != nil { + if errors.Is(err, ErrTooComplex) { + log.Printf("Skipping method %q with complex type", mm.MethodName) continue nextMethod } - } - if strings.HasSuffix(mm.ReturnType.ParameterType, "Private") { - log.Printf("Skipping method %q returning Private type", mm.MethodName) - continue nextMethod - } - mm.IsSignal = isSignal && !mm.IsStatic && mm.MethodName != `metaObject` - - if mm.IsReceiverMethod() { - log.Printf("Skipping method %q using non-projectable receiver pattern parameters", mm.MethodName) - continue nextMethod + // Real error + return CppClass{}, err } ret.Methods = append(ret.Methods, mm) diff --git a/cmd/genbindings/exceptions.go b/cmd/genbindings/exceptions.go index e090c6cb..27ddc6cb 100644 --- a/cmd/genbindings/exceptions.go +++ b/cmd/genbindings/exceptions.go @@ -103,6 +103,35 @@ func AllowClass(className string) bool { return true } +func AllowSignal(mm CppMethod) bool { + switch mm.MethodName { + case `metaObject`, `qt_metacast`: + return false + default: + return true + } +} + +func AllowMethod(mm CppMethod) error { + + for _, p := range mm.Parameters { + if strings.HasSuffix(p.ParameterType, "Private") { + return ErrTooComplex // Skip private type + } + } + if strings.HasSuffix(mm.ReturnType.ParameterType, "Private") { + return ErrTooComplex // Skip private type + } + + if mm.IsReceiverMethod() { + // Non-projectable receiver pattern parameters + return ErrTooComplex + } + + return nil // OK, allow + +} + func CheckComplexity(p CppParameter, isReturnType bool) error { if p.QMapOf() {