genbindings/typedefs: replace hardcoded exceptions with dynamic ones

This commit is contained in:
mappu 2024-08-26 22:50:35 +12:00
parent 0aa312c424
commit b84d816609
4 changed files with 11 additions and 25 deletions

View File

@ -651,19 +651,6 @@ func parseSingleTypeString(p string) CppParameter {
} else if tok == "*" { } else if tok == "*" {
insert.Pointer = true 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") { } else if len(tok) > 4 && strings.HasSuffix(tok, "List") {
// Classes ending in --List are usually better represented as a QList // Classes ending in --List are usually better represented as a QList
// type directly, so that the binding uses proper Go slices // type directly, so that the binding uses proper Go slices

View File

@ -41,8 +41,6 @@ func (p CppParameter) RenderTypeCabi() string {
ret = "intptr_t" ret = "intptr_t"
case "quintptr": case "quintptr":
ret = "uintptr_t" ret = "uintptr_t"
case "QRgb":
ret = "unsigned int"
} }
if strings.Contains(p.ParameterType, `::`) { if strings.Contains(p.ParameterType, `::`) {
@ -339,9 +337,6 @@ func getReferencedTypes(src *CppParsedHeader) []string {
if strings.HasSuffix(ft, "Private") { // qbrush.h finds QGradientPrivate if strings.HasSuffix(ft, "Private") { // qbrush.h finds QGradientPrivate
continue continue
} }
if ft == "QRgb" {
continue
}
foundTypesList = append(foundTypesList, ft) foundTypesList = append(foundTypesList, ft)
} }

View File

@ -56,12 +56,6 @@ func (p CppParameter) RenderTypeGo() string {
} else { } else {
ret += "uint64" ret += "uint64"
} }
case "QRgb":
if C.sizeof_int == 4 {
ret += "uint32"
} else {
ret += "uint64"
}
case "unsigned int": case "unsigned int":
ret += "uint" ret += "uint"

View File

@ -13,6 +13,17 @@ var (
func init() { func init() {
KnownClassnames = make(map[string]struct{}) KnownClassnames = make(map[string]struct{})
KnownTypedefs = make(map[string]CppTypedef) 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 { type CppParameter struct {
@ -103,7 +114,6 @@ func (p CppParameter) IntType() bool {
"unsigned char", "uchar", "unsigned char", "uchar",
"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", // QRgb is an unsigned int
"qintptr", "quintptr", "uintptr_t", "intptr_t", "qintptr", "quintptr", "uintptr_t", "intptr_t",
"qsizetype", "size_t", "qsizetype", "size_t",
"double", "float", "qreal": "double", "float", "qreal":