From b84d816609c3de52b81abe243e9298e283de9bea Mon Sep 17 00:00:00 2001 From: mappu Date: Mon, 26 Aug 2024 22:50:35 +1200 Subject: [PATCH] genbindings/typedefs: replace hardcoded exceptions with dynamic ones --- cmd/genbindings/clang2il.go | 13 ------------- cmd/genbindings/emitcabi.go | 5 ----- cmd/genbindings/emitgo.go | 6 ------ cmd/genbindings/intermediate.go | 12 +++++++++++- 4 files changed, 11 insertions(+), 25 deletions(-) diff --git a/cmd/genbindings/clang2il.go b/cmd/genbindings/clang2il.go index 6e01bd70..db7559c3 100644 --- a/cmd/genbindings/clang2il.go +++ b/cmd/genbindings/clang2il.go @@ -651,19 +651,6 @@ func parseSingleTypeString(p string) CppParameter { } else if tok == "*" { insert.Pointer = true - } else if tok == "WId" { - // Transform typedef - insert.TypeAlias = tok - insert.ParameterType += " uintptr_t" - - } else if tok == "Q_PID" { - // Transform typedef - // This is a uint64 PID on Linux/mac and a PROCESS_INFORMATION* on Windows - // A uintptr should be tolerable for both cases until we do better - // @ref https://doc.qt.io/qt-5/qprocess.html#Q_PID-typedef - insert.TypeAlias = tok - insert.ParameterType += " uintptr_t" - } else if len(tok) > 4 && strings.HasSuffix(tok, "List") { // Classes ending in --List are usually better represented as a QList // type directly, so that the binding uses proper Go slices diff --git a/cmd/genbindings/emitcabi.go b/cmd/genbindings/emitcabi.go index 73b3cb4d..b573c5a4 100644 --- a/cmd/genbindings/emitcabi.go +++ b/cmd/genbindings/emitcabi.go @@ -41,8 +41,6 @@ func (p CppParameter) RenderTypeCabi() string { ret = "intptr_t" case "quintptr": ret = "uintptr_t" - case "QRgb": - ret = "unsigned int" } if strings.Contains(p.ParameterType, `::`) { @@ -339,9 +337,6 @@ func getReferencedTypes(src *CppParsedHeader) []string { if strings.HasSuffix(ft, "Private") { // qbrush.h finds QGradientPrivate continue } - if ft == "QRgb" { - continue - } foundTypesList = append(foundTypesList, ft) } diff --git a/cmd/genbindings/emitgo.go b/cmd/genbindings/emitgo.go index 69c098cb..5bd3d4d2 100644 --- a/cmd/genbindings/emitgo.go +++ b/cmd/genbindings/emitgo.go @@ -56,12 +56,6 @@ func (p CppParameter) RenderTypeGo() string { } else { ret += "uint64" } - case "QRgb": - if C.sizeof_int == 4 { - ret += "uint32" - } else { - ret += "uint64" - } case "unsigned int": ret += "uint" diff --git a/cmd/genbindings/intermediate.go b/cmd/genbindings/intermediate.go index e71beacb..d39efa3b 100644 --- a/cmd/genbindings/intermediate.go +++ b/cmd/genbindings/intermediate.go @@ -13,6 +13,17 @@ var ( func init() { KnownClassnames = make(map[string]struct{}) KnownTypedefs = make(map[string]CppTypedef) + + // Seed well-known typedefs + + KnownTypedefs["QRgb"] = CppTypedef{"QRgb", parseSingleTypeString("unsigned int")} + + KnownTypedefs["WId"] = CppTypedef{"WId", parseSingleTypeString("uintptr_t")} + + // This is a uint64 PID on Linux/mac and a PROCESS_INFORMATION* on Windows + // A uintptr should be tolerable for both cases until we do better + // @ref https://doc.qt.io/qt-5/qprocess.html#Q_PID-typedef + KnownTypedefs["Q_PID"] = CppTypedef{"WId", parseSingleTypeString("uintptr_t")} } type CppParameter struct { @@ -103,7 +114,6 @@ func (p CppParameter) IntType() bool { "unsigned char", "uchar", "long", "unsigned long", "ulong", "qint32", "quint32", "longlong", "ulonglong", "qlonglong", "qulonglong", "qint64", "quint64", "int64_t", "uint64_t", "long long", "unsigned long long", - "QRgb", // QRgb is an unsigned int "qintptr", "quintptr", "uintptr_t", "intptr_t", "qsizetype", "size_t", "double", "float", "qreal":