From 9a78d87e003639c6673e0e0dde21d5627691ba12 Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 17 Aug 2024 11:27:02 +1200 Subject: [PATCH] genbindings: treat QRgb as unsigned int --- cmd/genbindings/emitcabi.go | 5 ++ cmd/genbindings/emitgo.go | 88 ++++++++++++++++++--------------- cmd/genbindings/intermediate.go | 3 +- 3 files changed, 56 insertions(+), 40 deletions(-) diff --git a/cmd/genbindings/emitcabi.go b/cmd/genbindings/emitcabi.go index 49706c93..734ddc51 100644 --- a/cmd/genbindings/emitcabi.go +++ b/cmd/genbindings/emitcabi.go @@ -31,6 +31,8 @@ func (p CppParameter) RenderTypeCpp() string { ret = "uint64_t" case "qfloat16": ret = "_Float16" // No idea where this typedef comes from, but it exists + case "QRgb": + ret = "unsigned int" } if p.Pointer || p.ByRef { @@ -250,6 +252,9 @@ func getReferencedTypes(src *CppParsedHeader) []string { if strings.HasPrefix(ft, "QList<") { continue } + if ft == "QRgb" { + continue + } foundTypesList = append(foundTypesList, ft) } diff --git a/cmd/genbindings/emitgo.go b/cmd/genbindings/emitgo.go index 0f947a35..28089cf3 100644 --- a/cmd/genbindings/emitgo.go +++ b/cmd/genbindings/emitgo.go @@ -21,44 +21,6 @@ func (p CppParameter) RenderTypeGo() string { if p.Pointer && p.ParameterType == "char" { return "string" } - if !p.Pointer && p.IntType() { - switch p.ParameterType { - case "char", "qint8": - return "byte" - case "unsigned char", "quint8": - return "byte" - case "short", "qint16": - return "int16" - case "ushort", "quint16": - return "uint16" - case "long": - // Windows ILP32 - 32-bits - // Linux LP64 - 64-bits - if C.sizeof_long == 4 { - return "int32" - } else { - return "int64" - } - case "ulong", "unsigned long": - if C.sizeof_long == 4 { - return "uint32" - } else { - return "uint64" - } - case "qint32": - return "int32" - case "quint32": - return "uint32" - case "qlonglong", "qint64": - return "int64" - case "qulonglong", "quint64": - return "uint64" - case "float": - return "float32" - case "double": - return "float64" - } - } if p.ParameterType == "char" { return "byte" } @@ -77,7 +39,55 @@ func (p CppParameter) RenderTypeGo() string { if p.ByRef || p.Pointer { ret += "*" } - ret += p.ParameterType + + switch p.ParameterType { + case "char", "qint8": + ret += "byte" + case "unsigned char", "quint8": + ret += "byte" + case "short", "qint16": + ret += "int16" + case "ushort", "quint16": + ret += "uint16" + case "long": + // Windows ILP32 - 32-bits + // Linux LP64 - 64-bits + if C.sizeof_long == 4 { + ret += "int32" + } else { + ret += "int64" + } + case "ulong", "unsigned long": + if C.sizeof_long == 4 { + ret += "uint32" + } else { + ret += "uint64" + } + case "QRgb": + if C.sizeof_int == 4 { + ret += "uint32" + } else { + ret += "uint64" + } + + case "qint32": + ret += "int32" + case "quint32": + ret += "uint32" + case "qlonglong", "qint64": + ret += "int64" + case "qulonglong", "quint64": + ret += "uint64" + case "float": + ret += "float32" + case "double": + ret += "float64" + default: + // Do not transform this type + ret += p.ParameterType + + } + return ret // ignore const } diff --git a/cmd/genbindings/intermediate.go b/cmd/genbindings/intermediate.go index be0355df..9413034b 100644 --- a/cmd/genbindings/intermediate.go +++ b/cmd/genbindings/intermediate.go @@ -14,7 +14,7 @@ type CppParameter struct { } func (p CppParameter) QtClassType() bool { - return p.ParameterType[0] == 'Q' + return (p.ParameterType[0] == 'Q') && p.ParameterType != "QRgb" } func (p CppParameter) QListOf() (CppParameter, bool) { @@ -38,6 +38,7 @@ func (p CppParameter) IntType() bool { // "char", "uchar", // Don't count char or char* as integer types that need cast assertions "long", "unsigned long", "ulong", "qint32", "quint32", "longlong", "ulonglong", "qlonglong", "qulonglong", "qint64", "quint64", "int64_t", "uint64_t", "long long", "unsigned long long", + "QRgb", // unsigned int "double", "float", "qreal": return true default: