genbindings: centralize AllowSignal/AllowMethod exceptions, block metacast signal

This commit is contained in:
mappu 2024-09-21 10:29:20 +12:00
parent aadc37eb2d
commit 9055f6e2ae
2 changed files with 38 additions and 13 deletions

View File

@ -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)

View File

@ -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() {