genbindings/qflags: emit qflags as inner type

This commit is contained in:
mappu 2024-09-19 19:39:17 +12:00
parent 286cfa90c9
commit 869e316715
3 changed files with 28 additions and 18 deletions

View File

@ -70,8 +70,12 @@ func (p CppParameter) RenderTypeCabi() string {
ret = "const " + ret
}
if p.IsFlagType() {
ret = "int"
if ft, ok := p.QFlagsOf(); ok {
if e, ok := KnownEnums[ft.ParameterType]; ok {
ret = e.UnderlyingType.RenderTypeCabi()
} else {
ret = "int"
}
} else if e, ok := KnownEnums[p.ParameterType]; ok {
ret = e.UnderlyingType.RenderTypeCabi()
@ -216,7 +220,7 @@ func emitCABI2CppForwarding(p CppParameter, indent string) (preamble string, for
preamble += indent + "}\n"
return preamble, nameprefix + "_QList"
} else if p.IntType() || p.IsFlagType() || p.IsKnownEnum() {
} else if p.IsFlagType() || p.IntType() || p.IsKnownEnum() {
castSrc := p.ParameterName
castType := p.RenderTypeQtCpp()

View File

@ -86,8 +86,8 @@ func (p CppParameter) RenderTypeGo() string {
ret += "uintptr"
default:
if p.IsFlagType() {
ret += "int"
if ft, ok := p.QFlagsOf(); ok {
ret += cabiClassName(ft.ParameterType)
} else if p.IsKnownEnum() {
ret += cabiClassName(p.ParameterType)

View File

@ -65,22 +65,28 @@ func (p *CppParameter) GetQtCppType() *CppParameter {
return p
}
func (p CppParameter) IsFlagType() bool {
if strings.HasPrefix(p.ParameterType, `QFlags<`) ||
strings.HasPrefix(p.GetQtCppType().ParameterType, `QFlags<`) {
return true // This catches most cases through the typedef system
func (p CppParameter) QFlagsOf() (CppParameter, bool) {
if strings.HasPrefix(p.ParameterType, `QFlags<`) {
ret := parseSingleTypeString(p.ParameterType[7 : len(p.ParameterType)-1])
ret.ParameterName = p.ParameterName + "_qf"
return ret, true
}
switch p.ParameterType {
case "QTouchEvent::TouchPoint::InfoFlags",
"QFile::Permissions",
"QWizard::WizardButton",
"QFormLayout::ItemRole",
"QFormLayout::RowWrapPolicy":
return true
default:
return false
if under := p.QtCppOriginalType; under != nil {
if strings.HasPrefix(under.ParameterType, `QFlags<`) {
ret := parseSingleTypeString(under.ParameterType[7 : len(under.ParameterType)-1])
ret.ParameterName = under.ParameterName + "_qf"
return ret, true
}
}
return CppParameter{}, false
}
func (p CppParameter) IsFlagType() bool {
_, ok := p.QFlagsOf()
return ok
}
func (p CppParameter) QtClassType() bool {