genbindings: centralize handling of flag types

This commit is contained in:
mappu 2024-08-29 17:16:36 +12:00
parent daff305d36
commit 050d668765
3 changed files with 24 additions and 2 deletions

View File

@ -45,7 +45,7 @@ func (p CppParameter) RenderTypeCabi() string {
ret = "ptrdiff_t"
}
if strings.HasPrefix(p.ParameterType, `QFlags<`) {
if p.IsFlagType() {
ret = "int"
} else if strings.Contains(p.ParameterType, `::`) {
@ -613,6 +613,11 @@ extern "C" {
} else if m.ReturnType.Const {
shouldReturn += "(" + emitReturnTypeCabi(m.ReturnType) + ") "
} else if m.ReturnType.IsFlagType() {
// Needs an explicit int cast
shouldReturn = m.ReturnType.RenderTypeQtCpp() + " ret = "
afterCall += "\treturn static_cast<int>(ret);\n"
} else if m.ReturnType.IsEnum() {
// Needs an explicit uintptr cast
shouldReturn = m.ReturnType.RenderTypeQtCpp() + " ret = "

View File

@ -81,7 +81,7 @@ func (p CppParameter) RenderTypeGo() string {
ret += "uintptr"
default:
if strings.HasPrefix(p.ParameterType, `QFlags<`) {
if p.IsFlagType() {
ret += "int"
} else if strings.Contains(p.ParameterType, `::`) {

View File

@ -24,6 +24,7 @@ func init() {
// 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 {
@ -66,6 +67,22 @@ func (p *CppParameter) UnderlyingType() string {
return p.ParameterType
}
func (p CppParameter) IsFlagType() bool {
if strings.HasPrefix(p.ParameterType, `QFlags<`) {
return true // This catches most cases through the typedef system
}
switch p.ParameterType {
case "QTouchEvent::TouchPoint::InfoFlags",
"QFile::Permissions",
"QFormLayout::ItemRole",
"QFormLayout::RowWrapPolicy":
return true
default:
return false
}
}
func (p CppParameter) QtClassType() bool {
// Maybe if it's an inner class