mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 08:58:37 +00:00
genbindings: centralize handling of flag types
This commit is contained in:
parent
daff305d36
commit
050d668765
@ -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 = "
|
||||
|
@ -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, `::`) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user