genbindings/exceptions: more exceptions and overrides

This commit is contained in:
mappu 2024-08-29 17:17:35 +12:00
parent 97a56647b7
commit 421c229771
4 changed files with 43 additions and 36 deletions

View File

@ -171,6 +171,11 @@ func processClassType(node map[string]interface{}, addNamePrefix string) (CppCla
if nodename == "FromBase64Result" {
nodename = "QByteArray::FromBase64Result"
}
if nodename == "Connection" {
// qobject.h requires this, defined in qobjectdefs.h
// We produce a type named 'Connection' instead of 'QMetaObject::Connection' as expected, not sure why
nodename = "QMetaObject::Connection"
}
ret.ClassName = nodename
@ -439,27 +444,6 @@ nextMethod:
continue nextMethod
}
if ret.ClassName == "QFile" && mm.MethodName == "moveToTrash" && len(mm.Parameters) == 2 && mm.Parameters[1].ParameterType == "QString" && mm.Parameters[1].Pointer {
// @ref https://doc.qt.io/qt-6/qfile.html#moveToTrash-1
log.Printf("Skipping method %q using complex return type by pointer argument", mm.MethodName) // TODO support this
continue nextMethod
}
if ret.ClassName == "QLockFile" && mm.MethodName == "getLockInfo" && len(mm.Parameters) == 3 && mm.Parameters[1].ParameterType == "QString" && mm.Parameters[1].Pointer {
log.Printf("Skipping method %q using complex return type by pointer argument", mm.MethodName) // TODO support this
continue nextMethod
}
if ret.ClassName == "QTextDecoder" && mm.MethodName == "toUnicode" && len(mm.Parameters) == 3 && mm.Parameters[0].ParameterType == "QString" && mm.Parameters[0].Pointer {
log.Printf("Skipping method %q using complex return type by pointer argument", mm.MethodName) // TODO support this
continue nextMethod
}
if ret.ClassName == "QTextStream" && mm.MethodName == "readLineInto" && len(mm.Parameters) > 0 && mm.Parameters[0].ParameterType == "QString" && mm.Parameters[0].Pointer {
log.Printf("Skipping method %q using complex return type by pointer argument", mm.MethodName) // TODO support this
continue nextMethod
}
ret.Methods = append(ret.Methods, mm)
default:
@ -752,5 +736,9 @@ func parseSingleTypeString(p string) CppParameter {
}
insert.ParameterType = strings.TrimSpace(insert.ParameterType)
if strings.HasPrefix(insert.ParameterType, `::`) {
insert.ParameterType = insert.ParameterType[2:]
}
return insert
}

View File

@ -400,12 +400,6 @@ extern "C" {
// Forward declarations of inner classes are not yet supported in C++
// @ref https://stackoverflow.com/q/1021793
// ret.WriteString(`class ` + ft + ";\n")
//parent, child, _ := strings.Cut(ft, `::`)
//ret.WriteString(`namespace ` + parent + ` { class ` + child + "; }\n")
//ret.WriteString(`typedef ` + ft + " " + cabiClassName(ft) + ";\n")
ret.WriteString(`#if defined(WORKAROUND_INNER_CLASS_DEFINITION_` + cabiClassName(ft) + ")\n")
ret.WriteString(`typedef ` + ft + " " + cabiClassName(ft) + ";\n")
ret.WriteString("#else\n")

View File

@ -82,7 +82,7 @@ func AllowClass(className string) bool {
return true
}
func CheckComplexity(p CppParameter) error {
func CheckComplexity(p CppParameter, isReturnType bool) error {
if p.QMapOf() {
return ErrTooComplex // Example???
@ -94,7 +94,7 @@ func CheckComplexity(p CppParameter) error {
return ErrTooComplex // e.g. QStateMachine
}
if t, ok := p.QListOf(); ok {
if err := CheckComplexity(t); err != nil { // e.g. QGradientStops is a QVector<> (OK) of QGradientStop (not OK)
if err := CheckComplexity(t, isReturnType); err != nil { // e.g. QGradientStops is a QVector<> (OK) of QGradientStop (not OK)
return err
}
}
@ -108,16 +108,42 @@ func CheckComplexity(p CppParameter) error {
if strings.HasPrefix(p.ParameterType, "QGenericMatrix<") {
return ErrTooComplex // e.g. qmatrix4x4.h
}
if strings.HasPrefix(p.ParameterType, "std::initializer") {
return ErrTooComplex // e.g. qcborarray.h
if strings.HasPrefix(p.ParameterType, "std::") {
// std::initializer e.g. qcborarray.h
// std::string QByteArray->toStdString(). There are QString overloads already
// std::nullptr_t Qcborstreamwriter
// std::chrono::nanoseconds QDeadlineTimer_RemainingTimeAsDuration
// std::seed_seq QRandom
return ErrTooComplex
}
if strings.Contains(p.ParameterType, `::reverse_iterator`) || strings.Contains(p.ParameterType, `::const_reverse_iterator`) {
return ErrTooComplex // e.g. qbytearray.h
}
if strings.Contains(p.ParameterType, `Iterator::value_type`) {
return ErrTooComplex // e.g. qcbormap
}
if strings.Contains(p.ParameterType, `::QPrivate`) {
return ErrTooComplex // e.g. QAbstractItemModel::QPrivateSignal
}
// If any parameters are QString*, skip the method
// QFile::moveToTrash
// QLockFile::getLockInfo
// QTextDecoder::toUnicode
// QTextStream::readLineInto
// QFileDialog::getOpenFileName selectedFilter* param
if p.ParameterType == "QString" && p.Pointer && !isReturnType { // Out-parameters
return ErrTooComplex
}
if p.IsFlagType() && p.Pointer && !isReturnType {
return ErrTooComplex // e.g. qformlayout. The cast doesn't survive through a pointer parameter
}
if p.ParameterType != "char" && p.Pointer && p.PointerCount >= 2 { // Out-parameters
return ErrTooComplex // e.g. QGraphicsItem_IsBlockedByModalPanel1
}
switch p.ParameterType {
case
"QList<QVariant>", // e.g. QVariant constructor - this has a deleted copy-constructor so we can't get it over the CABI boundary by value
@ -129,7 +155,6 @@ func CheckComplexity(p CppParameter) error {
"void **", // e.g. qobjectdefs.h QMetaObject->Activate()
"QGraphicsItem **", // e.g. QGraphicsItem::IsBlockedByModalPanel() overload
"char *&", // e.g. QDataStream.operator<<()
"std::string", // e.g. QByteArray->toStdString(). There are QString overloads already
"qfloat16", // e.g. QDataStream - there is no such half-float type in C or Go
"char16_t", // e.g. QChar() constructor overload, just unnecessary
"char32_t", // e.g. QDebug().operator<< overload, unnecessary

View File

@ -11,12 +11,12 @@ func astTransformBlocklist(parsed *CppParsedHeader) {
j := 0
nextCtor:
for _, m := range c.Ctors {
if err := CheckComplexity(m.ReturnType); err != nil {
if err := CheckComplexity(m.ReturnType, true); err != nil {
continue nextCtor
}
for _, p := range m.Parameters {
if err := CheckComplexity(p); err != nil {
if err := CheckComplexity(p, false); err != nil {
continue nextCtor
}
}
@ -32,12 +32,12 @@ func astTransformBlocklist(parsed *CppParsedHeader) {
j = 0
nextMethod:
for _, m := range c.Methods {
if err := CheckComplexity(m.ReturnType); err != nil {
if err := CheckComplexity(m.ReturnType, true); err != nil {
continue nextMethod
}
for _, p := range m.Parameters {
if err := CheckComplexity(p); err != nil {
if err := CheckComplexity(p, false); err != nil {
continue nextMethod
}
}