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" {
// Transform typedef
insert.TypeAlias = tok
insert.ParameterType += " uintptr_t"
} 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
// 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 tok == "QStringList" {
@ -571,6 +573,7 @@ func parseSingleTypeString(p string) CppParameter {
// Classes ending in --List are usually better represented as a QList
// type directly, so that the binding uses proper Go slices
// Typedef e.g. QObjectList
insert.TypeAlias = tok
switch tok {
case "QModelIndexList":
// 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.
func emitParametersCpp(m CppMethod) string {
tmp := make([]string, 0, len(m.Parameters))
for _, p := range m.Parameters {
cppType := p.ParameterType
if p.Const {
cppType = "const " + cppType
}
if p.Pointer {
cppType += "*"
}
if p.ByRef {
cppType += "&"
}
tmp = append(tmp, cppType+" "+p.ParameterName)
tmp = append(tmp, p.RenderTypeQtCpp()+" "+p.ParameterName)
}
return strings.Join(tmp, `, `)
@ -95,19 +101,7 @@ func emitParametersCpp(m CppMethod) string {
func emitParameterTypesCpp(m CppMethod) string {
tmp := make([]string, 0, len(m.Parameters))
for _, p := range m.Parameters {
cppType := p.ParameterType
if p.Const {
cppType = "const " + cppType
}
if p.Pointer {
cppType += "*"
}
if p.ByRef {
cppType += "&"
}
tmp = append(tmp, cppType)
tmp = append(tmp, p.RenderTypeQtCpp())
}
return strings.Join(tmp, `, `)

View File

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