2024-08-16 23:25:06 +00:00
|
|
|
package main
|
|
|
|
|
2024-08-18 07:02:14 +00:00
|
|
|
import (
|
2024-08-19 07:42:34 +00:00
|
|
|
"path/filepath"
|
2024-08-18 07:02:14 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2024-08-19 07:14:47 +00:00
|
|
|
func AllowHeader(fullpath string) bool {
|
2024-08-19 07:42:34 +00:00
|
|
|
fname := filepath.Base(fullpath)
|
|
|
|
|
|
|
|
if strings.HasSuffix(fname, `_impl.h`) {
|
|
|
|
return false // Not meant to be imported
|
|
|
|
}
|
|
|
|
|
|
|
|
fname_lc := strings.ToLower(fname)
|
|
|
|
if strings.Contains(fname_lc, `opengl`) || strings.Contains(fname_lc, `vulkan`) {
|
|
|
|
return false // Too hard
|
|
|
|
}
|
|
|
|
|
|
|
|
switch fname {
|
2024-08-20 08:19:15 +00:00
|
|
|
case "qatomic_bootstrap.h",
|
2024-08-19 07:42:34 +00:00
|
|
|
"qatomic_cxx11.h",
|
|
|
|
"qatomic_msvc.h",
|
|
|
|
"qgenericatomic.h", // Clang error
|
|
|
|
"qt_windows.h", // Clang error
|
|
|
|
"qmaccocoaviewcontainer_mac.h", // Needs NSView* headers. TODO allow with darwin build tag
|
|
|
|
"qmacnativewidget_mac.h", // Needs NSView* headers. TODO allow with darwin build tag
|
|
|
|
"qstring.h", // QString does not exist in this binding
|
|
|
|
"qlist.h", // QList does not exist in this binding
|
|
|
|
"qvector.h": // QVector does not exist in this binding
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-08-19 07:14:47 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-08-18 07:02:14 +00:00
|
|
|
func ImportHeaderForClass(className string) bool {
|
|
|
|
if className[0] != 'Q' {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO this could be implict by checking if files exist in known header paths
|
|
|
|
|
|
|
|
if strings.HasPrefix(className, "QPlatform") {
|
|
|
|
// e.g. QPlatformPixmap, QPlatformWindow, QPlatformScreen
|
|
|
|
// These classes don't have a <> version to include
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
switch className {
|
|
|
|
case "QGraphicsEffectSource", // e.g. qgraphicseffect.h
|
2024-08-22 07:20:34 +00:00
|
|
|
"QAbstractConcatenable", // qstringbuilder.h
|
|
|
|
"QTextEngine", // qtextlayout.h
|
|
|
|
"QText": // e.g. qtextcursor.h
|
2024-08-18 07:02:14 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-08-19 07:12:13 +00:00
|
|
|
func AllowClass(className string) bool {
|
|
|
|
|
|
|
|
if strings.HasSuffix(className, "Private") {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-08-26 10:51:21 +00:00
|
|
|
if strings.Contains(className, "QPrivateSignal") {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-08-19 07:12:13 +00:00
|
|
|
switch className {
|
|
|
|
case
|
2024-08-19 07:42:34 +00:00
|
|
|
"QTextStreamManipulator", // Only seems to contain garbage methods
|
|
|
|
"QException", // Extends std::exception, too hard
|
2024-08-23 23:46:51 +00:00
|
|
|
"QUnhandledException", // As above (child class)
|
2024-08-19 07:42:34 +00:00
|
|
|
"QItemSelection", // Extends a QList<>, too hard
|
|
|
|
"QXmlStreamAttributes", // Extends a QList<>, too hard
|
|
|
|
"QPolygon", "QPolygonF": // Extends a QVector<QPoint> template class, too hard
|
2024-08-19 07:12:13 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-08-29 05:17:35 +00:00
|
|
|
func CheckComplexity(p CppParameter, isReturnType bool) error {
|
2024-08-16 23:25:06 +00:00
|
|
|
|
|
|
|
if p.QMapOf() {
|
|
|
|
return ErrTooComplex // Example???
|
|
|
|
}
|
2024-08-17 02:11:11 +00:00
|
|
|
if p.QPairOf() {
|
|
|
|
return ErrTooComplex // e.g. QGradientStop
|
2024-08-16 23:25:06 +00:00
|
|
|
}
|
2024-08-19 07:15:05 +00:00
|
|
|
if p.QSetOf() {
|
|
|
|
return ErrTooComplex // e.g. QStateMachine
|
|
|
|
}
|
2024-08-17 02:11:11 +00:00
|
|
|
if t, ok := p.QListOf(); ok {
|
2024-08-29 05:17:35 +00:00
|
|
|
if err := CheckComplexity(t, isReturnType); err != nil { // e.g. QGradientStops is a QVector<> (OK) of QGradientStop (not OK)
|
2024-08-17 02:11:11 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-08-16 23:25:06 +00:00
|
|
|
}
|
2024-08-17 02:11:11 +00:00
|
|
|
|
2024-08-27 08:05:50 +00:00
|
|
|
if strings.Contains(p.ParameterType, "(*)") { // Function pointer.
|
|
|
|
return ErrTooComplex // e.g. QAccessible_InstallFactory
|
|
|
|
}
|
2024-08-19 07:42:34 +00:00
|
|
|
if strings.HasPrefix(p.ParameterType, "StringResult<") {
|
|
|
|
return ErrTooComplex // e.g. qcborstreamreader.h
|
|
|
|
}
|
2024-08-27 07:12:29 +00:00
|
|
|
if strings.HasPrefix(p.ParameterType, "QGenericMatrix<") {
|
|
|
|
return ErrTooComplex // e.g. qmatrix4x4.h
|
|
|
|
}
|
2024-08-29 07:01:21 +00:00
|
|
|
if strings.HasPrefix(p.ParameterType, "QUrlTwoFlags<") {
|
|
|
|
return ErrTooComplex // e.g. qurl.h
|
|
|
|
}
|
2024-08-29 05:17:35 +00:00
|
|
|
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
|
2024-08-26 10:51:21 +00:00
|
|
|
}
|
2024-08-27 08:05:50 +00:00
|
|
|
if strings.Contains(p.ParameterType, `::reverse_iterator`) || strings.Contains(p.ParameterType, `::const_reverse_iterator`) {
|
|
|
|
return ErrTooComplex // e.g. qbytearray.h
|
|
|
|
}
|
2024-08-29 05:17:35 +00:00
|
|
|
if strings.Contains(p.ParameterType, `Iterator::value_type`) {
|
|
|
|
return ErrTooComplex // e.g. qcbormap
|
|
|
|
}
|
2024-08-26 10:51:21 +00:00
|
|
|
if strings.Contains(p.ParameterType, `::QPrivate`) {
|
|
|
|
return ErrTooComplex // e.g. QAbstractItemModel::QPrivateSignal
|
|
|
|
}
|
2024-08-19 07:42:34 +00:00
|
|
|
|
2024-08-29 05:38:34 +00:00
|
|
|
// Some QFoo constructors take a QFooPrivate
|
|
|
|
if p.ParameterType[0] == 'Q' && strings.HasSuffix(p.ParameterType, "Private") && !isReturnType {
|
|
|
|
return ErrTooComplex
|
|
|
|
}
|
|
|
|
|
2024-08-29 05:17:35 +00:00
|
|
|
// If any parameters are QString*, skip the method
|
2024-08-29 05:38:34 +00:00
|
|
|
// QDebug constructor
|
|
|
|
// QXmlStreamWriter constructor
|
2024-08-29 05:17:35 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2024-08-29 07:01:21 +00:00
|
|
|
if p.Pointer && p.PointerCount >= 2 { // Out-parameters
|
|
|
|
if p.ParameterType != "char" {
|
|
|
|
return ErrTooComplex // e.g. QGraphicsItem_IsBlockedByModalPanel1
|
|
|
|
}
|
|
|
|
if p.ParameterType == "char" && p.ParameterName == "xpm" {
|
|
|
|
// Array parameters:
|
|
|
|
// - QPixmap and QImage ctors from an xpm char*[]
|
|
|
|
// TODO support these
|
|
|
|
return ErrTooComplex
|
|
|
|
}
|
2024-08-29 05:17:35 +00:00
|
|
|
}
|
|
|
|
|
2024-08-17 02:11:11 +00:00
|
|
|
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
|
|
|
|
"QPolygon", "QPolygonF", // QPolygon extends a template type
|
2024-08-18 07:02:43 +00:00
|
|
|
"QGenericMatrix", "QMatrix3x3", // extends a template type
|
2024-08-17 02:11:11 +00:00
|
|
|
"QLatin1String", "QStringView", // e.g. QColor constructors and QColor::SetNamedColor() overloads. These are usually optional alternatives to QString
|
2024-08-18 07:02:43 +00:00
|
|
|
"QStringRef", // e.g. QLocale::toLongLong and similar overloads. As above
|
2024-08-17 02:11:11 +00:00
|
|
|
"QGradientStop", "QGradientStops", // QPair<>-related types, but we can't see through the typedef to block based on QPair alone
|
2024-08-19 07:42:34 +00:00
|
|
|
"void **", // e.g. qobjectdefs.h QMetaObject->Activate()
|
|
|
|
"QGraphicsItem **", // e.g. QGraphicsItem::IsBlockedByModalPanel() overload
|
|
|
|
"char *&", // e.g. QDataStream.operator<<()
|
|
|
|
"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
|
2024-08-23 23:46:51 +00:00
|
|
|
"wchar_t", // e.g. qstringview.h overloads, unnecessary
|
2024-08-29 05:38:34 +00:00
|
|
|
"QStringView::const_pointer", // e.g. qstringview.h data()
|
|
|
|
"QStringView::const_iterator", // e.g. qstringview.h
|
|
|
|
"QStringView::value_type", // e.g. qstringview.h
|
2024-08-26 10:51:21 +00:00
|
|
|
"FILE", // e.g. qfile.h constructors
|
|
|
|
"qInternalCallback", // e.g. qnamespace.h
|
2024-08-19 07:42:34 +00:00
|
|
|
"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
|
|
|
|
"QGraphicsEffectSource", // e.g. used by qgraphicseffect.h, but the definition is in ????
|
|
|
|
"QAbstractUndoItem", // e.g. Defined in qtextdocument.h
|
|
|
|
"QTextObjectInterface", // e.g. qabstracttextdocumentlayout.h
|
2024-08-29 07:01:21 +00:00
|
|
|
"QUrl::FormattingOptions", // e.g. QUrl.h. Typedef for a complex template type
|
2024-08-19 07:42:34 +00:00
|
|
|
"QXmlStreamEntityDeclarations", // e.g. qxmlstream.h. The class definition was blacklisted for ???? reason so don't allow it as a parameter either
|
|
|
|
"QXmlStreamNamespaceDeclarations", // e.g. qxmlstream.h. As above
|
|
|
|
"QXmlStreamNotationDeclarations", // e.g. qxmlstream.h. As above
|
2024-08-23 23:46:51 +00:00
|
|
|
"QXmlStreamAttributes", // e.g. qxmlstream.h
|
2024-08-19 07:42:34 +00:00
|
|
|
"QVariantMap", // e.g. qcbormap.h
|
|
|
|
"QVariantHash", // e.g. qcbormap.h
|
2024-08-20 08:19:15 +00:00
|
|
|
"QCborTag", // e.g. qcborstreamreader.h.TODO Needs support for enums
|
|
|
|
"QCborSimpleType", // e.g. qcborstreamreader.h TODO Needs support for enums
|
|
|
|
"QCborKnownTags", // e.g. qcborstreamreader.h TODO Needs support for enums
|
|
|
|
"QCborNegativeInteger", // e.g. qcborstreamreader.h TODO Needs support for enums
|
|
|
|
"QtMsgType", // e.g. qdebug.h TODO Needs support for enums
|
|
|
|
"QTextStreamFunction", // e.g. qdebug.h
|
|
|
|
"QFactoryInterface", // qfactoryinterface.h
|
2024-08-23 23:46:51 +00:00
|
|
|
"QItemSelection", // used by qabstractproxymodel.h, also blocked in AllowClass above, class extends a List<T>
|
|
|
|
"QTextStreamManipulator", // used by qdebug.h, also blocked in AllowClass above
|
|
|
|
"QException", // used by qfutureinterface.h, also blocked in AllowClass above
|
|
|
|
"QTextEngine", // used by qtextlayout.h, also blocked in ImportHeaderForClass above
|
|
|
|
"QVulkanInstance", // e.g. qwindow.h. Not tackling vulkan yet
|
|
|
|
"QPlatformBackingStore", // e.g. qbackingstore.h, as below
|
|
|
|
"QPlatformMenuBar", // e.g. qfutureinterface.h, as below
|
|
|
|
"QPlatformOffscreenSurface", // e.g. qoffscreensurface.h, as below
|
2024-08-19 07:42:34 +00:00
|
|
|
"QPlatformPixmap", // e.g. qpixmap.h. as below
|
|
|
|
"QPlatformScreen", // e.g. qscreen.h. as below
|
2024-08-23 23:46:51 +00:00
|
|
|
"QPlatformWindow", // e.g. qwindow.h, as below
|
2024-08-19 07:42:34 +00:00
|
|
|
"QPlatformSurface", // e.g. qsurface.h. as below
|
|
|
|
"QPlatformMenu": // e.g. QMenu_PlatformMenu. Defined in the QPA, could probably expose as uintptr
|
2024-08-17 02:11:11 +00:00
|
|
|
return ErrTooComplex
|
2024-08-16 23:25:06 +00:00
|
|
|
}
|
2024-08-17 02:11:11 +00:00
|
|
|
|
2024-08-16 23:25:06 +00:00
|
|
|
if p.ParameterType == "void" && p.Pointer {
|
2024-08-17 02:11:11 +00:00
|
|
|
return ErrTooComplex // e.g. qobjectdefs.h QMetaObject->InvokeOnGadget(). TODO represent as uintptr
|
2024-08-16 23:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Should be OK
|
|
|
|
return nil
|
|
|
|
}
|
2024-09-01 05:50:58 +00:00
|
|
|
|
|
|
|
// LinuxWindowsCompatCheck checks if the parameter is incompatible between the
|
|
|
|
// generated headers (generated on Linux) with other OSes such as Windows.
|
|
|
|
// These methods will be blocked on non-Linux OSes.
|
|
|
|
func LinuxWindowsCompatCheck(p CppParameter) bool {
|
|
|
|
if p.TypeAlias == "Q_PID" {
|
|
|
|
return true // int64 on Linux, _PROCESS_INFORMATION* on Windows
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.ParameterType == "QSocketDescriptor::DescriptorType" {
|
|
|
|
return true // uintptr_t-compatible on Linux, void* on Windows
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|