genbindings/blocklist: refactor extract single method helper

This commit is contained in:
mappu 2024-11-15 14:23:30 +13:00
parent d9bfece505
commit 0ffb24d11a

View File

@ -1,5 +1,20 @@
package main
func blocklist_MethodAllowed(m *CppMethod) bool {
if err := AllowType(m.ReturnType, true); err != nil {
return false
}
for _, p := range m.Parameters {
if err := AllowType(p, false); err != nil {
return false
}
}
// Nothing was blocked
return true
}
// astTransformBlocklist filters out methods using too-complex parameter types,
// and entire classes that may be disallowed.
func astTransformBlocklist(parsed *CppParsedHeader) {
@ -28,16 +43,10 @@ func astTransformBlocklist(parsed *CppParsedHeader) {
j := 0
nextCtor:
for _, m := range c.Ctors {
if err := AllowType(m.ReturnType, true); err != nil {
if !blocklist_MethodAllowed(&m) {
continue nextCtor
}
for _, p := range m.Parameters {
if err := AllowType(p, false); err != nil {
continue nextCtor
}
}
// Keep
c.Ctors[j] = m
j++
@ -49,16 +58,10 @@ func astTransformBlocklist(parsed *CppParsedHeader) {
j = 0
nextMethod:
for _, m := range c.Methods {
if err := AllowType(m.ReturnType, true); err != nil {
if !blocklist_MethodAllowed(&m) {
continue nextMethod
}
for _, p := range m.Parameters {
if err := AllowType(p, false); err != nil {
continue nextMethod
}
}
// Keep
c.Methods[j] = m
j++