From 8f266f5202117a919fc8ff15d4c68aa6868ee302 Mon Sep 17 00:00:00 2001 From: mappu Date: Thu, 8 Aug 2024 19:06:31 +1200 Subject: [PATCH] genbindings: find all Qt types for PVOID typedefs, not just direct classes --- cmd/genbindings/emitcabi.go | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/cmd/genbindings/emitcabi.go b/cmd/genbindings/emitcabi.go index 3621eab8..f5376b55 100644 --- a/cmd/genbindings/emitcabi.go +++ b/cmd/genbindings/emitcabi.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "sort" "strings" ) @@ -80,8 +81,41 @@ extern "C" { `) + // Find all referenced Qt types in this file, and generate PVoid typedefs + // for them + foundTypes := map[string]struct{}{} + for _, c := range src.Classes { + foundTypes[c.ClassName] = struct{}{} + for _, ctor := range c.Ctors { + for _, p := range ctor.Parameters { + if p.QtClassType() { + foundTypes[p.ParameterType] = struct{}{} + } + } + } + for _, m := range c.Methods { + for _, p := range m.Parameters { + if p.QtClassType() { + foundTypes[p.ParameterType] = struct{}{} + } + } + if m.ReturnType.QtClassType() { + foundTypes[m.ReturnType.ParameterType] = struct{}{} + } + } + } + foundTypesList := make([]string, 0, len(foundTypes)) + for ft := range foundTypes { + foundTypesList = append(foundTypesList, ft) + } + sort.Strings(foundTypesList) + for _, ft := range foundTypesList { + ret.WriteString(`typedef void* P` + ft + ";\n") + } + + ret.WriteString("\n") + for _, c := range src.Classes { - ret.WriteString(`typedef void* P` + c.ClassName + ";\n\n") for i, ctor := range c.Ctors { ret.WriteString(fmt.Sprintf("P%s %s_new%s(%s);\n", c.ClassName, maybeSuffix(i), emitParametersCpp(ctor.Parameters, "")))