genbindings: add explicit int casts when calling, to select overload

This commit is contained in:
mappu 2024-08-14 18:33:47 +12:00
parent 89f4024951
commit 3dcdfbd594
2 changed files with 23 additions and 0 deletions

View File

@ -106,6 +106,15 @@ func emitParametersCABI2CppForwarding(params []CppParameter) (preamble string, f
preamble += "\t}\n"
tmp = append(tmp, p.ParameterName+"_QList")
} else if p.IntType() {
// Use the raw ParameterType to select an explicit integer overload
// Don't use RenderTypeCpp() since it canonicalizes some int types for CABI
castType := p.ParameterType
if p.Pointer {
castType += "*"
}
tmp = append(tmp, "static_cast<"+castType+">("+p.ParameterName+")")
} else if p.ByRef {
// We changed RenderTypeCpp() to render this as a pointer
// Need to dereference so we can pass as reference to the actual Qt C++ function

View File

@ -25,6 +25,20 @@ func (p CppParameter) QListOf() (CppParameter, bool) {
return CppParameter{}, false
}
func (p CppParameter) IntType() bool {
switch p.ParameterType {
case "int", "uint",
"short", "ushort",
// "char", "uchar", // Don't count char or char* as integer types that need cast assertions
"long", "ulong",
"longlong", "ulonglong", "qlonglong", "qulonglong", "int64_t", "uint64_t",
"double", "float", "qreal":
return true
default:
return false
}
}
type CppProperty struct {
PropertyName string
PropertyType string