2024-08-27 06:44:10 +00:00
|
|
|
package main
|
|
|
|
|
2024-11-15 01:23:30 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-08-27 06:44:10 +00:00
|
|
|
// astTransformBlocklist filters out methods using too-complex parameter types,
|
|
|
|
// and entire classes that may be disallowed.
|
|
|
|
func astTransformBlocklist(parsed *CppParsedHeader) {
|
|
|
|
|
2024-10-25 23:08:36 +00:00
|
|
|
// Whole-classes
|
|
|
|
|
|
|
|
j := 0
|
|
|
|
for _, c := range parsed.Classes {
|
|
|
|
if !AllowClass(c.ClassName) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-11-23 06:34:05 +00:00
|
|
|
// If this class is abstract, but we return !AllowVirtualForClass, then
|
|
|
|
// delete its constructors
|
|
|
|
if c.Abstract && !AllowVirtualForClass(c.ClassName) {
|
|
|
|
c.Ctors = nil
|
|
|
|
}
|
|
|
|
|
2024-10-25 23:08:36 +00:00
|
|
|
// Keep
|
|
|
|
parsed.Classes[j] = c
|
|
|
|
j++
|
|
|
|
}
|
|
|
|
parsed.Classes = parsed.Classes[:j] // reslice
|
|
|
|
|
|
|
|
// For the kept classes, filter ctors and methods within the class, based
|
|
|
|
// on the parameter types and return types
|
|
|
|
|
2024-08-27 06:44:10 +00:00
|
|
|
for i, c := range parsed.Classes {
|
|
|
|
|
|
|
|
// Constructors
|
|
|
|
|
|
|
|
j := 0
|
|
|
|
nextCtor:
|
|
|
|
for _, m := range c.Ctors {
|
2024-11-15 01:23:30 +00:00
|
|
|
if !blocklist_MethodAllowed(&m) {
|
2024-08-27 06:44:10 +00:00
|
|
|
continue nextCtor
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep
|
|
|
|
c.Ctors[j] = m
|
|
|
|
j++
|
|
|
|
}
|
|
|
|
c.Ctors = c.Ctors[:j] // reslice
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
|
|
|
|
j = 0
|
|
|
|
nextMethod:
|
|
|
|
for _, m := range c.Methods {
|
2024-11-15 01:23:30 +00:00
|
|
|
if !blocklist_MethodAllowed(&m) {
|
2024-08-27 06:44:10 +00:00
|
|
|
continue nextMethod
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep
|
|
|
|
c.Methods[j] = m
|
|
|
|
j++
|
|
|
|
}
|
|
|
|
c.Methods = c.Methods[:j] // reslice
|
|
|
|
|
|
|
|
parsed.Classes[i] = c
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|