From cf2585416f9400e00ed80f2bc0f2b7810b387451 Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 18 Aug 2024 19:02:14 +1200 Subject: [PATCH] genbindings/exceptions: move header imports to exceptions.go --- cmd/genbindings/emitcabi.go | 7 +------ cmd/genbindings/exceptions.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/cmd/genbindings/emitcabi.go b/cmd/genbindings/emitcabi.go index dbf9212..c6b9480 100644 --- a/cmd/genbindings/emitcabi.go +++ b/cmd/genbindings/emitcabi.go @@ -420,12 +420,7 @@ func emitBindingCpp(src *CppParsedHeader, filename string) (string, error) { `) for _, ref := range getReferencedTypes(src) { - if ref[0] != 'Q' { - continue - } - if strings.HasPrefix(ref, "QPlatform") { - // e.g. QPlatformPixmap, QPlatformWindow, QPlatformScreen - // These classes don't have a <> version to include + if !ImportHeaderForClass(ref) { continue } diff --git a/cmd/genbindings/exceptions.go b/cmd/genbindings/exceptions.go index 5c9aaf6..cad1f2f 100644 --- a/cmd/genbindings/exceptions.go +++ b/cmd/genbindings/exceptions.go @@ -1,5 +1,9 @@ package main +import ( + "strings" +) + func AllowDelete(c CppClass) bool { switch c.ClassName { case "QClipboard": @@ -8,6 +12,28 @@ func AllowDelete(c CppClass) bool { return true } +func ImportHeaderForClass(className string) bool { + if className[0] != 'Q' { + return false + } + + // TODO this could be implict by checking if files exist in known header paths + + if strings.HasPrefix(className, "QPlatform") { + // e.g. QPlatformPixmap, QPlatformWindow, QPlatformScreen + // These classes don't have a <> version to include + return false + } + + switch className { + case "QGraphicsEffectSource", // e.g. qgraphicseffect.h + "QText": // e.g. qtextcursor.h + return false + } + + return true +} + func CheckComplexity(p CppParameter) error { if p.QMapOf() {