mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 08:58:37 +00:00
genbindings: improved uintptr handling for enum types
This commit is contained in:
parent
a0812831e7
commit
a0b51bef8e
@ -49,12 +49,11 @@ func (p CppParameter) RenderTypeCabi() string {
|
||||
ret = "int"
|
||||
|
||||
} else if strings.Contains(p.ParameterType, `::`) {
|
||||
if _, ok := KnownClassnames[p.ParameterType]; ok {
|
||||
if p.IsEnum() {
|
||||
ret = "uintptr_t"
|
||||
} else {
|
||||
// Inner class
|
||||
ret = cabiClassName(p.ParameterType)
|
||||
} else {
|
||||
// Enum
|
||||
ret = "uintptr_t"
|
||||
}
|
||||
}
|
||||
|
||||
@ -602,6 +601,12 @@ extern "C" {
|
||||
|
||||
} else if m.ReturnType.Const {
|
||||
shouldReturn += "(" + emitReturnTypeCabi(m.ReturnType) + ") "
|
||||
|
||||
} else if m.ReturnType.IsEnum() {
|
||||
// Needs an explicit uintptr cast
|
||||
shouldReturn = m.ReturnType.RenderTypeQtCpp() + " ret = "
|
||||
afterCall += "\treturn static_cast<uintptr_t>(ret);\n"
|
||||
|
||||
}
|
||||
|
||||
preamble, forwarding := emitParametersCABI2CppForwarding(m.Parameters)
|
||||
|
@ -85,12 +85,11 @@ func (p CppParameter) RenderTypeGo() string {
|
||||
ret += "int"
|
||||
|
||||
} else if strings.Contains(p.ParameterType, `::`) {
|
||||
if _, ok := KnownClassnames[p.ParameterType]; ok {
|
||||
if p.IsEnum() {
|
||||
ret += "uintptr"
|
||||
} else {
|
||||
// Inner class
|
||||
ret += cabiClassName(p.ParameterType)
|
||||
} else {
|
||||
// Enum
|
||||
ret += "uintptr"
|
||||
}
|
||||
} else {
|
||||
// Do not transform this type
|
||||
|
@ -47,6 +47,12 @@ func (p *CppParameter) CopyWithAlias(alias CppParameter) CppParameter {
|
||||
ret := *p // copy
|
||||
ret.ParameterName = alias.ParameterName
|
||||
ret.TypeAlias = alias.ParameterType
|
||||
|
||||
// If this was a pointer to a typedef'd type, or a typedef of a pointer type, we need to preserve that
|
||||
// WARNING: This can't work for double indirection
|
||||
ret.Const = ret.Const || alias.Const
|
||||
ret.Pointer = ret.Pointer || alias.Pointer
|
||||
ret.ByRef = ret.ByRef || alias.ByRef
|
||||
return ret
|
||||
}
|
||||
|
||||
@ -76,6 +82,21 @@ func (p CppParameter) QtClassType() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (p CppParameter) IsEnum() bool {
|
||||
if strings.Contains(p.ParameterType, `::`) {
|
||||
if _, ok := KnownClassnames[p.ParameterType]; ok {
|
||||
// It's an inner class
|
||||
return false
|
||||
} else {
|
||||
// Enum
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Top-level enums aren't supported yet
|
||||
return false
|
||||
}
|
||||
|
||||
func (p CppParameter) QListOf() (CppParameter, bool) {
|
||||
if strings.HasPrefix(p.ParameterType, "QList<") && strings.HasSuffix(p.ParameterType, `>`) {
|
||||
return parseSingleTypeString(p.ParameterType[6 : len(p.ParameterType)-1]), true
|
||||
@ -103,7 +124,7 @@ func (p CppParameter) QSetOf() bool {
|
||||
|
||||
func (p CppParameter) IntType() bool {
|
||||
|
||||
if strings.Contains(p.ParameterType, `::`) {
|
||||
if p.IsEnum() {
|
||||
return true
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user