genbindings: treat QRgb as unsigned int

This commit is contained in:
mappu 2024-08-17 11:27:02 +12:00
parent 5fa7bd37eb
commit 9a78d87e00
3 changed files with 56 additions and 40 deletions

View File

@ -31,6 +31,8 @@ func (p CppParameter) RenderTypeCpp() string {
ret = "uint64_t" ret = "uint64_t"
case "qfloat16": case "qfloat16":
ret = "_Float16" // No idea where this typedef comes from, but it exists ret = "_Float16" // No idea where this typedef comes from, but it exists
case "QRgb":
ret = "unsigned int"
} }
if p.Pointer || p.ByRef { if p.Pointer || p.ByRef {
@ -250,6 +252,9 @@ func getReferencedTypes(src *CppParsedHeader) []string {
if strings.HasPrefix(ft, "QList<") { if strings.HasPrefix(ft, "QList<") {
continue continue
} }
if ft == "QRgb" {
continue
}
foundTypesList = append(foundTypesList, ft) foundTypesList = append(foundTypesList, ft)
} }

View File

@ -21,44 +21,6 @@ func (p CppParameter) RenderTypeGo() string {
if p.Pointer && p.ParameterType == "char" { if p.Pointer && p.ParameterType == "char" {
return "string" 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" { if p.ParameterType == "char" {
return "byte" return "byte"
} }
@ -77,7 +39,55 @@ func (p CppParameter) RenderTypeGo() string {
if p.ByRef || p.Pointer { if p.ByRef || p.Pointer {
ret += "*" 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 return ret // ignore const
} }

View File

@ -14,7 +14,7 @@ type CppParameter struct {
} }
func (p CppParameter) QtClassType() bool { func (p CppParameter) QtClassType() bool {
return p.ParameterType[0] == 'Q' return (p.ParameterType[0] == 'Q') && p.ParameterType != "QRgb"
} }
func (p CppParameter) QListOf() (CppParameter, bool) { 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 // "char", "uchar", // Don't count char or char* as integer types that need cast assertions
"long", "unsigned long", "ulong", "qint32", "quint32", "long", "unsigned long", "ulong", "qint32", "quint32",
"longlong", "ulonglong", "qlonglong", "qulonglong", "qint64", "quint64", "int64_t", "uint64_t", "long long", "unsigned long long", "longlong", "ulonglong", "qlonglong", "qulonglong", "qint64", "quint64", "int64_t", "uint64_t", "long long", "unsigned long long",
"QRgb", // unsigned int
"double", "float", "qreal": "double", "float", "qreal":
return true return true
default: default: