genbindings: accurate type alias tracking for static_cast<> overload resolution

This commit is contained in:
mappu 2024-08-20 20:16:13 +12:00
parent 1ea3f220e6
commit 7e78b73517
3 changed files with 24 additions and 26 deletions

View File

@ -555,6 +555,7 @@ func parseSingleTypeString(p string) CppParameter {
} else if tok == "WId" { } else if tok == "WId" {
// Transform typedef // Transform typedef
insert.TypeAlias = tok
insert.ParameterType += " uintptr_t" insert.ParameterType += " uintptr_t"
} else if tok == "Q_PID" { } else if tok == "Q_PID" {
@ -562,6 +563,7 @@ func parseSingleTypeString(p string) CppParameter {
// This is a uint64 PID on Linux/mac and a PROCESS_INFORMATION* on Windows // 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 // A uintptr should be tolerable for both cases until we do better
// @ref https://doc.qt.io/qt-5/qprocess.html#Q_PID-typedef // @ref https://doc.qt.io/qt-5/qprocess.html#Q_PID-typedef
insert.TypeAlias = tok
insert.ParameterType += " uintptr_t" insert.ParameterType += " uintptr_t"
} else if tok == "QStringList" { } else if tok == "QStringList" {
@ -571,6 +573,7 @@ func parseSingleTypeString(p string) CppParameter {
// 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
// Typedef e.g. QObjectList // Typedef e.g. QObjectList
insert.TypeAlias = tok
switch tok { switch tok {
case "QModelIndexList": case "QModelIndexList":
// These types are defined as a QList of values // These types are defined as a QList of values

View File

@ -70,23 +70,29 @@ func emitReturnTypeCabi(p CppParameter) string {
} }
} }
func (p CppParameter) RenderTypeQtCpp() string {
cppType := p.ParameterType
if len(p.TypeAlias) > 0 {
cppType = p.TypeAlias // replace
}
if p.Const {
cppType = "const " + cppType
}
if p.Pointer {
cppType += "*"
}
if p.ByRef {
cppType += "&"
}
return cppType
}
// emitParametersCpp emits the parameter definitions exactly how Qt C++ defines them. // emitParametersCpp emits the parameter definitions exactly how Qt C++ defines them.
func emitParametersCpp(m CppMethod) string { func emitParametersCpp(m CppMethod) string {
tmp := make([]string, 0, len(m.Parameters)) tmp := make([]string, 0, len(m.Parameters))
for _, p := range m.Parameters { for _, p := range m.Parameters {
tmp = append(tmp, p.RenderTypeQtCpp()+" "+p.ParameterName)
cppType := p.ParameterType
if p.Const {
cppType = "const " + cppType
}
if p.Pointer {
cppType += "*"
}
if p.ByRef {
cppType += "&"
}
tmp = append(tmp, cppType+" "+p.ParameterName)
} }
return strings.Join(tmp, `, `) return strings.Join(tmp, `, `)
@ -95,19 +101,7 @@ func emitParametersCpp(m CppMethod) string {
func emitParameterTypesCpp(m CppMethod) string { func emitParameterTypesCpp(m CppMethod) string {
tmp := make([]string, 0, len(m.Parameters)) tmp := make([]string, 0, len(m.Parameters))
for _, p := range m.Parameters { for _, p := range m.Parameters {
tmp = append(tmp, p.RenderTypeQtCpp())
cppType := p.ParameterType
if p.Const {
cppType = "const " + cppType
}
if p.Pointer {
cppType += "*"
}
if p.ByRef {
cppType += "&"
}
tmp = append(tmp, cppType)
} }
return strings.Join(tmp, `, `) return strings.Join(tmp, `, `)

View File

@ -8,6 +8,7 @@ import (
type CppParameter struct { type CppParameter struct {
ParameterName string ParameterName string
ParameterType string ParameterType string
TypeAlias string // If we rewrote QStringList->QList<String>, this field contains the original QStringList
Const bool Const bool
Pointer bool Pointer bool
ByRef bool ByRef bool