genbindings: more exceptions

This commit is contained in:
mappu 2024-08-26 22:51:21 +12:00
parent b84d816609
commit 9dac446a82
5 changed files with 42 additions and 7 deletions

View File

@ -633,6 +633,14 @@ func tokenizeMultipleParameters(p string) []string {
func parseSingleTypeString(p string) CppParameter {
if strings.HasPrefix(p, "QFlag<") {
return CppParameter{ParameterType: "int"}
}
if strings.Contains(p, "(*)") {
return CppParameter{ParameterType: "uintptr"} // Function pointer, nonrepresentible
}
tokens := strings.Split(strings.TrimSpace(p), " ")
insert := CppParameter{}
for _, tok := range tokens {
@ -648,6 +656,9 @@ func parseSingleTypeString(p string) CppParameter {
} else if tok == "&" { // U+0026
insert.ByRef = true
} else if tok == "signed" {
// continue
} else if tok == "*" {
insert.Pointer = true

View File

@ -41,6 +41,8 @@ func (p CppParameter) RenderTypeCabi() string {
ret = "intptr_t"
case "quintptr":
ret = "uintptr_t"
case "qptrdiff":
ret = "ptrdiff_t"
}
if strings.Contains(p.ParameterType, `::`) {
@ -238,6 +240,7 @@ func emitParametersCABI2CppForwarding(params []CppParameter) (preamble string, f
// Don't use RenderTypeCabi() since it canonicalizes some int types for CABI
castSrc := p.ParameterName
castType := p.RenderTypeQtCpp()
if p.ByRef { // e.g. QDataStream::operator>>() overloads
castSrc = "*" + castSrc
}
@ -465,13 +468,9 @@ func emitBindingCpp(src *CppParsedHeader, filename string) (string, error) {
ret.WriteString(`#include <` + ref + ">\n")
}
ret.WriteString(`#include "gen_` + filename + `"
#include "` + filename + `"
`)
ret.WriteString(`#include "` + filename + "\"\n\n")
ret.WriteString(`#include "gen_` + filename + "\"\n")
ret.WriteString(`
extern "C" {
extern void miqt_exec_callback(void* cb, int argc, void* argv);
}

View File

@ -71,7 +71,7 @@ func (p CppParameter) RenderTypeGo() string {
ret += "float32"
case "double", "qreal":
ret += "float64"
case "qsizetype", "size_t":
case "qsizetype", "size_t", "qptrdiff", "ptrdiff_t":
if C.sizeof_size_t == 4 {
ret += "uint32"
} else {

View File

@ -67,6 +67,10 @@ func AllowClass(className string) bool {
return false
}
if strings.Contains(className, "QPrivateSignal") {
return false
}
switch className {
case
"QTextStreamManipulator", // Only seems to contain garbage methods
@ -101,6 +105,12 @@ func CheckComplexity(p CppParameter) error {
if strings.HasPrefix(p.ParameterType, "StringResult<") {
return ErrTooComplex // e.g. qcborstreamreader.h
}
if strings.HasPrefix(p.ParameterType, "std::initializer") {
return ErrTooComplex // e.g. qcborarray.h
}
if strings.Contains(p.ParameterType, `::QPrivate`) {
return ErrTooComplex // e.g. QAbstractItemModel::QPrivateSignal
}
switch p.ParameterType {
case
@ -117,6 +127,8 @@ func CheckComplexity(p CppParameter) error {
"char16_t", // e.g. QChar() constructor overload, just unnecessary
"char32_t", // e.g. QDebug().operator<< overload, unnecessary
"wchar_t", // e.g. qstringview.h overloads, unnecessary
"FILE", // e.g. qfile.h constructors
"qInternalCallback", // e.g. qnamespace.h
"picture_io_handler", // e.g. QPictureIO::DefineIOHandler callback function
"QPlatformNativeInterface", // e.g. QGuiApplication::platformNativeInterface(). Private type, could probably expose as uintptr. n.b. Changes in Qt6
"QFunctionPointer", // e.g. QGuiApplication_PlatformFunction

View File

@ -116,6 +116,7 @@ func (p CppParameter) IntType() bool {
"longlong", "ulonglong", "qlonglong", "qulonglong", "qint64", "quint64", "int64_t", "uint64_t", "long long", "unsigned long long",
"qintptr", "quintptr", "uintptr_t", "intptr_t",
"qsizetype", "size_t",
"qptrdiff", "ptrdiff_t",
"double", "float", "qreal":
return true
@ -232,6 +233,16 @@ func (nm CppMethod) SafeMethodName() string {
return tmp
}
type CppEnumEntry struct {
EntryName string
EntryValue string
}
type CppEnum struct {
EnumName string
Entries []CppEnumEntry
}
type CppClass struct {
ClassName string
Abstract bool
@ -243,6 +254,7 @@ type CppClass struct {
ChildTypedefs []CppTypedef
ChildClassdefs []CppClass
ChildEnums []CppEnum
}
type CppTypedef struct {
@ -253,6 +265,7 @@ type CppTypedef struct {
type CppParsedHeader struct {
Filename string
Typedefs []CppTypedef
Enums []CppEnum
Classes []CppClass
}