summaryrefslogtreecommitdiffstats
path: root/src/tools/moc/generator.cpp
Commit message (Collapse)AuthorAgeFilesLines
* moc: Update comment above propertiesMårten Nordheim8 days1-1/+1
| | | | | | | | It was not matching up with the data there anymore, the notifyID and 'p.revision' was not mentioned Change-Id: I09f63e5137944e9ab96e0a70abb798895d4b7739 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc/QMetaProperty: Remove limitation on non-own-class notify signalsFabian Kosmale2024-01-261-6/+23
| | | | | | | | | | | | | | | | | | | | | | | | | The moc generated code does a sanity check that NOTIFY signals actually exist in the parent class when they cannot be found in the class moc currently runs on. The logic there was however too simplistic, and couldn't deal with signals taking a parameter. Fix this, and take the opportunity to use a proper static_assert instead of generating a "normal" compile error. We do not do any checks for the presence of QPrivateSignal, as the whole point of QPrivateSignal is that it should be private (and not e.g. protected). Moreover, we adjust QMetaProperty::notifySignalIndex to take single-argument notify methods into consideration as well when encontering an unresolved notify index. Fixes: QTBUG-115989 Pick-to: 6.7 Change-Id: I8a056a15777f3132691e207b4b9ab6c2c9b2126d Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: port from pair<> to a struct SuperClassMarc Mutz2023-12-131-4/+3
| | | | | | | | | | | | ... with properly-named members. This is in preparation of adding a new member in order to fix QTBUG-101141 (namespaced base classes). Pick-to: 6.7 6.6 6.5 Task-number: QTBUG-101141 Change-Id: I2309e425ac94ad275b54a898fd33a2891e5d1453 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Moc: don't make variables inside an unnamed namespace staticAhmad Samir2023-07-061-1/+1
| | | | | | | | | | | | | | | | Because an unnamed namespace, and variables inside it, have internal linkage[1]; and the variable is constexpr in this case so static redundant. This fixes a clang-tidy warning: readability-static-definition-in-anonymous-namespace [1] https://eel.is/c++draft/basic.link#4 Change-Id: I95600214cd51b03872ee22995d93d1b5658d5a18 Task-number: QTBUG-112870 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Moc: simplify codeAhmad Samir2023-06-221-3/+3
| | | | | | | | | | The concatenated byte array is already the "size" we want. Drive-by change: use QByteArray::sliced() Change-Id: Id0afb45ae1daf08bd125230eef0734770c645e1a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Moc: prevent potential unnecessary detachAhmad Samir2023-06-221-2/+2
| | | | | | | | | Change Generator::generateSignal() to take by const FunctionDef*, so that it can be called with the return of QList::at(). Change-Id: I5ffb0726a5ded6561e0000a2bea1973ada675152 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Moc: use a std::initializer_list<QList *> instead of copyingAhmad Samir2023-06-221-3/+3
| | | | | | | | No need to copy the 3 QLists to iterate over them. Change-Id: Id0fc7d39012bdaa78e51b1153565df77c7fb889a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Moc: simplify the logic of a for-loopAhmad Samir2023-06-221-6/+6
| | | | | | | | | | By handling the special case before entering the loop, then it can become a range-for, which fixes a narrowing conversion warning, and it becomes more readable. Change-Id: I6ce0181c95eae01a4f2bb7cd12fb5cbeba378586 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* MOC: use methods from QtMiscUtilsAhmad Samir2023-06-221-3/+5
| | | | | | Change-Id: I20600357841aff36f68bcc9a81bfb3e96bf6e264 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Moc: fix narrowing conversion warnings with range-for loopsAhmad Samir2023-06-201-4/+3
| | | | | | Pick-to: 6.6 6.5 Change-Id: I6dee1a6ae82c33bd6523734ee32ab4c83835f9d8 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Moc: fix narrowing conversion warnings by using iterator-based for-loopAhmad Samir2023-06-201-23/+36
| | | | | | | | | | | | | | The alternative would be to explicitly cast each list.size() to int. I think using iterators is a cleaner solution. Drive-by changes: - Give a std::pair's members better names than first/second, by using a structured binding - Port to qsizetype Pick-to: 6.6 6.5 Change-Id: Icff3126192f9813fba698d5722b209307011ca48 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Moc: fix generated code for nested enum class corner caseAhmad Samir2023-06-181-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes an issue with generated code where the name of an enclosing namespace is identical to an enum class type, when Q_ENUM_NS is used. Consider: namespace a { Q_NAMESPACE namespace b { enum class b { Key, Key2 }; Q_ENUM_NS(b); } } moc generated code such as: Q_CONSTINIT const QMetaObject a::b::staticMetaObject = { { ... qt_incomplete_metaTypeArray<qt_meta_stringdata_CLASSaSCOPEbENDCLASS_t, // enum 'TestEnum' QtPrivate::TypeAndForceComplete<b::b, std::true_type>, // Q_OBJECT / Q_GADGET QtPrivate::TypeAndForceComplete<void, std::true_type> >, nullptr } }; which confused the compiler: error: ‘b’ is not a member of ‘a::b::b 83 | QtPrivate::TypeAndForceComplete<b::b, std::true_type>, Fixes: QTBUG-112996 Pick-to: 6.6 Change-Id: I37aee83c32efe96cc9d6c2bd0bdb9ba80bb7b8a7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Moc: check sizes of specific member QLists are within INT_MAX rangeAhmad Samir2023-06-061-13/+25
| | | | | | | | | | | | | | Parts of the public API, e.g. QMetaMethod::methodIndex and similar functions return int, and other parts of the code expect int values, at least for Qt6 this can't be changed, so use qsizetype internally and assert the values fit in an int. As pointed out in code review, not many people will build moc in debug mode, so asserts aren't that useful here. Instead print error messages and exit, like is already done in other parts of the code. Change-Id: Id305165caa996c899f30770a757098fe2f9a96f6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Moc: pass a pointer to the parser to the GeneratorAhmad Samir2023-06-061-2/+3
| | | | | | | | | This way the Generator can use e.g. Parser::error() to print error messages (which will happen in a later commit). Change-Id: Id710d7b604a82ce6bb61999addad8c95c53e3226 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Moc: assert size of registered strings list is within INT_MAX rangeAhmad Samir2023-06-061-2/+2
| | | | | | | | | | | | | | Assert generator.strings.size() < INT_MAX after all strings have been registered. Parts of the public API, e.g. QMetaMethod::methodIndex and similar functions return int, and other parts of the code expect int values, at least for Qt6 this can't be changed, so use qsizetype internally and assert the values fit in an int. Change-Id: Ib226e9c19a578bbeaeb9bb767d756a9569fe57b3 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Moc/Generator: fix 64-to-32 narrowing conversion warnignsAhmad Samir2023-06-051-10/+10
| | | | | | Pick-to: 6.6 6.5 Change-Id: Id1094aaba284c51c3a840a8e107abd837a825593 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Moc: remove STRINGDATA fallback codeAhmad Samir2023-06-051-67/+2
| | | | | | | | | | | | | | | | If QT_MOC_HAS_STRINGDATA isn't defined, just put an '#error' directive in the generated code. Since the proposal of doing ±4 versions of tool compatibility hasn't been adopted, just remove the fallback string code. Requested by Thiago in code review. Drive-by changes: - Use "STRINGDATA" in comments too - Remove a now unused static helper Change-Id: I6dbdf427b7219b8b32076a9e0a41799c0a476ff9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Moc: port to qsizetypeAhmad Samir2023-05-281-6/+6
| | | | | | | | Simple s/int/qsizetype/. Fixes some narrowing conversion warnings. Pick-to: 6.5 Change-Id: Ied82e861298fa9763089cadc7eae6e536f1bb9ca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Moc: fix some narrowing conversion warnings by using range operationsAhmad Samir2023-05-181-55/+30
| | | | | | | | | | | | I.e. range-for and in one case QList::append(iterator, iterator). Drive-by changes: - Check a QByteArray isn't empty before using at() - Shorten a long line, QString::fromLocal8Bit() works with QByteArray Pick-to: 6.5 Change-Id: I7e54ce39f65ccb1fe5e60693ac98e239b9f0d794 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: Record types of enumerationsUlf Hermann2023-03-311-4/+13
| | | | | | | | | | | This will be helpful in a number of places, in particular in order to support enums of different sizes in QML. We record the type as string in the JSON output and as QMetaTypeInterface in the generated C++. Task-number: QTBUG-112180 Change-Id: I943fac67f8b25b013d3860301416cdd293c0c69e Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: Allow calling ctors on pre-allocated dataUlf Hermann2023-02-021-16/+28
| | | | | | | | | | | | When calling a ctor this way, an object is created in the memory pointed to by _a[0] using the other arguments for the ctor. This allows separate allocation and initialization of an object through the metaobject system. Fixes: QTBUG-108879 Change-Id: Ifb154373ee42faab281cfb62aa14334980ec6b7d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* MetaObject: Apply some cosmeticsUlf Hermann2023-01-311-1/+1
| | | | | | | | Add missing white space to moc output and list all the values of QMetaObject::Call in the internal documentation. Change-Id: I57d0c5b88bfaee4ca3f2d4604564751b6d0cbe51 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Moc: avoid double underscores in a generated identifierGiuseppe D'Angelo2023-01-091-2/+17
| | | | | | | | | | | | | | | | | | | | In order to generate metadata for a class `NS::Class`, moc will "mangle" its name by turning the colons into underscores. This however makes the generated name have a double underscore, and all names with double underscores are reserved. Instead, replace double colons with another string ("SCOPE"). We are then going to use this mangled name to create other identifiers. To do so, underscores may get appended and prepended to the mangled name (e.g. "qt_metadata_" + mangled_name + "_t"). This means that a leading or trailing underscore in the mangled name would also be problematic; avoid that as well. Pick-to: 6.5 Fixes: QTBUG-109851 Change-Id: I01391a57920545fc75f78ef4bfefaf6d3dd7b447 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Long live Q_UNREACHABLE_RETURN()!Marc Mutz2022-10-151-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a combination of Q_UNREACHABLE() with a return statement. ATM, the return statement is unconditionally included. If we notice that some compilers warn about return after __builtin_unreachable(), then we can map Q_UNREACHABLE_RETURN(...) to Q_UNREACHABLE() without having to touch all the code that uses explicit Q_UNREACHABLE() + return. The fact that Boost has BOOST_UNREACHABLE_RETURN() indicates that there are compilers that complain about a lack of return after Q_UNREACHABLE (we know that MSVC, ICC, and GHS are among them), as well as compilers that complained about a return being present (Coverity). Take this opportunity to properly adapt to Coverity, by leaving out the return statement on this compiler. Apply the macro around the code base, using a clang-tidy transformer rule: const std::string unr = "unr", val = "val", ret = "ret"; auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(", ifBound(val, cat(node(val)), cat("")), ")"); auto ignoringSwitchCases = [](auto stmt) { return anyOf(stmt, switchCase(subStmt(stmt))); }; makeRule( stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)), nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))), {changeTo(node(unr), cat(makeUnreachableReturn, ";")), // TODO: why is the ; lost w/o this? changeTo(node(ret), cat(""))}, cat("use ", makeUnreachableReturn)) ); where nextStmt() is copied from some upstream clang-tidy check's private implementation and subStmt() is a private matcher that gives access to SwitchCase's SubStmt. A.k.a. qt-use-unreachable-return. There were some false positives, suppressed them with NOLINTNEXTLINE. They're not really false positiives, it's just that Clang sees the world in one way and if conditonal compilation (#if) differs for other compilers, Clang doesn't know better. This is an artifact of matching two consecutive statements. I haven't figured out how to remove the empty line left by the deletion of the return statement, if it, indeed, was on a separate line, so post-processed the patch to remove all the lines matching ^\+ *$ from the diff: git commit -am meep git reset --hard HEAD^ git diff HEAD..HEAD@{1} | sed '/^\+ *$/d' | recountdiff - | patch -p1 [ChangeLog][QtCore][QtAssert] Added Q_UNREACHABLE_RETURN() macro. Change-Id: I9782939f16091c964f25b7826e1c0dbd13a71305 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-111-2/+2
| | | | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace, with manual unstaging of the actual definition and documentation in dist/, src/corelib/doc/ and src/corelib/global/. Task-number: QTBUG-99313 Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Port from container.count()/length() to size()Marc Mutz2022-10-041-55/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is semantic patch using ClangTidyTransformator: auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o) makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'. <classes> are: // sequential: "QByteArray", "QList", "QQueue", "QStack", "QString", "QVarLengthArray", "QVector", // associative: "QHash", "QMultiHash", "QMap", "QMultiMap", "QSet", // Qt has no QMultiSet Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* moc: use C++ constexpr to generate the meta object string dataThiago Macieira2022-08-041-0/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This avoids having to rely on moc precalculating everything and getting its sums right, as the main integer table only has a string index (unlike my original 5.0 plan which would have stored the offset). For example, for: struct Object : QObject { Q_OBJECT signals: void changed(const QVariant &v); } moc now generates: struct qt_meta_stringdata_Object_t {}; static constexpr auto qt_meta_stringdata_Object = QtMocHelpers::stringData( "Object", "foobar", "", "v" ); Notes on the implementation: * the old code is retained because we need moc 6.5 to generate code compatible with QtCore 6.2-6.4. It's marked for removal in Qt 6.9. * the struct qt_meta_stringdata_%s_t remains because we need a TU-specific type for QtPrivate::is_complete (via qt_incomplete_metaTypeArray). This can be cleaned up. * after this change, GDB complains while loading QtCore: warning: internal error: string "StringData<long sequence of numbers>" failed to be canonicalized but debugging does not appear to be impacted. It's just annoying because it shows up when QtTest detects a crash too. Change-Id: Id0fb9ab0089845ee8843fffd16f9d5493e9bd708 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: Allow writing properties through bindablesUlf Hermann2022-07-081-0/+6
| | | | | | | | | | | | | BINDABLE should generally behave the same as MEMBER if "WRITE default", except where it cannot. In particular we cannot know if any NOTIFY signal should be sent from the synthetic WRITE accessor. [ChangeLog][QtCore] moc will now synthesize WRITE accessors for properties with BINDABLE if you specify "WRITE default". Task-number: QTBUG-97249 Change-Id: I883c40ba0dda7989c840971860addaeaa75a8c83 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: fix GCC -Wuseless-cast warningsMarc Mutz2022-07-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When being queried for QMetaObject::IndexOfMethod, qt_static_metacall would compare the argument with each of the class' methods' addresses. Taking the address of an overloaded function is ambiguous unless you cast to the right type, which the moc-generated code did using explicit static_cast<>s. If the function is not overloaded, GCC would warn about the static_cast<> being "useless", which isn't wrong. Fix by using an implicit cast to a local variable of the correct type instead of an explicit cast. Since there's no explicit cast anymore, GCC doesn't warn. Code before the change: using _t = void(Counter::*)(int ); if (*reinterpret_cast<_t*>(_a[1]) == static_cast<_t>(&Counter::valueChanged)) { ^-------------------------------------- -Wuseless-cast *result = 0; return; } After: using _t = void(Counter::*)(int ); if (_t _q_method = &Counter::valueChanged; *reinterpret_cast<_t*>(_a[1]) == _q_method) { *result = 0; return; } Since we're using a C++17 construct, we can't pick to 5.15. Pick-to: 6.4 6.3 6.2 Fixes: QTBUG-71938 Change-Id: If6ba4bf17b3bf7f64e9662ba9d085273882fb460 Reviewed-by: Mate Barany <mate.barany@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* moc: fix const-init for WindowsThiago Macieira2022-06-281-4/+3
| | | | | | | | | | | | | | | | | | References to __declspec(dllimport) is not a constant expression on Windows, so we can't have a direct reference to a staticMetaObject. Commit 9b8493314dd77f3e96b353187816bb7ef4dedbb5 fixed the Q_OBJECT parent link (added in 5.14, kicked in for 6.0 with the ABI break), but commit 656d6f2a9b221dbd5adfc46262cb243e696d8d62 added links for Q_GADGETs too without taking the need for Windows DLLs into account. This change is a no-op everywhere but Windows. On Windows, since we store the pointer to the indirect getter function, now you may get non- null pointers from QMetaObject::superClass(). Pick-to: 6.4 Change-Id: I6d3880c7d99d4fc494c8fffd16fab51aa255106e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: move the qt_static_metacall below the staticMetaObjectThiago Macieira2022-06-281-10/+11
| | | | | | | | | Just so we have data structures and functions grouped together. Pick-to: 6.4 Change-Id: Id0fb9ab0089845ee8843fffd16fa171f6e1caf2b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* moc: Strip parentheses from RESET methods in JSON outputUlf Hermann2022-06-271-2/+2
| | | | | | | | | READ, WRITE, NOTIFY etc all come without parentheses. What we actually want to check in the generator is whether the reset method is empty. Task-number: QTBUG-104508 Change-Id: If8c70c7491b25e3c4d9a39dc2c0add0212e64dea Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* moc: put the qt_meta_stringdata_XXXX_t type in an unnamed namespaceThiago Macieira2022-06-241-1/+6
| | | | | | | | | | | Not all user code is compiled with hidden visibility, so make sure one of the types in the template parameters (the one that is supposed to be unique anyway) is local and therefore causes the full symbol for the inline variable not to be exported outside of the translation unit. Pick-to: 6.4 Change-Id: I6d3880c7d99d4fc494c8fffd16fb262a59b81283 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: remove the attempt to create one large string literalThiago Macieira2022-06-241-58/+30
| | | | | | | | | | | | | | | | | | | | | | | Commit dda9c9e2bc4fd2efe9e3fb0e451a8c3512f9a4d2 fixed some outstanding issues with moc's calculation of the maximum string length, but it missed one. This commit instead opts to remove the calculation entirely and instead have multiple char array members in the qt_meta_stringdata. We needed a single string back in Qt 4.0 when the stringdata *was* a single char array. Since 5.0, we've used a structure with multiple members and pointer arithmetic going past the end of the arrays, from the top of the object. That's UB, but since it's always been UB and can't be fixed until Qt 7 anyway, let's go full monty on it and have one char array per meta object string. The struct qt_meta_stringdata_Qt_t for namespace Qt now has 1217 stringdataXXX members. Pick-to: 6.2 6.3 6.4 Change-Id: I6d3880c7d99d4fc494c8fffd16fb0d1573e387dc Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: properly indent the output for the metatype arrayThiago Macieira2022-06-241-34/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 7ff7d73f6ac68227500fa95731ce0f04626e600b added the indentation, but there were a few mistakes and it was off by 4 spaces anyway. So re-do it and take the opportunity to add some comments to explain what we're seeing. Before: qt_incomplete_metaTypeArray<qt_meta_stringdata_QTimer_t, QtPrivate::TypeAndForceComplete<bool, std::true_type>, QtPrivate::TypeAndForceComplete<int, std::true_type>, QtPrivate::TypeAndForceComplete<int, std::true_type>, QtPrivate::TypeAndForceComplete<Qt::TimerType, std::true_type>, QtPrivate::TypeAndForceComplete<bool, std::true_type>, QtPrivate::TypeAndForceComplete<QTimer, std::true_type>, QtPrivate::TypeAndForceComplete<void, std::false_type> , QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<int, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<void, std::false_type> >, After: qt_incomplete_metaTypeArray<qt_meta_stringdata_QTimer_t, // property 'singleShot' QtPrivate::TypeAndForceComplete<bool, std::true_type>, // property 'interval' QtPrivate::TypeAndForceComplete<int, std::true_type>, // property 'remainingTime' QtPrivate::TypeAndForceComplete<int, std::true_type>, // property 'timerType' QtPrivate::TypeAndForceComplete<Qt::TimerType, std::true_type>, // property 'active' QtPrivate::TypeAndForceComplete<bool, std::true_type>, // Q_OBJECT / Q_GADGET QtPrivate::TypeAndForceComplete<QTimer, std::true_type>, // method 'timeout' QtPrivate::TypeAndForceComplete<void, std::false_type>, // method 'start' QtPrivate::TypeAndForceComplete<void, std::false_type>, QtPrivate::TypeAndForceComplete<int, std::false_type>, // method 'start' QtPrivate::TypeAndForceComplete<void, std::false_type>, // method 'stop' QtPrivate::TypeAndForceComplete<void, std::false_type> >, Pick-to: 6.4 Change-Id: Id0fb9ab0089845ee8843fffd16fa152d040ef922 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* moc: add Q_CONSTINIT to the static const variables we emitThiago Macieira2022-06-221-5/+7
| | | | | | | | | | | The macro was added to Qt 6.4, so we define it in each moc output to empty if it wasn't previously defined. Thus, moc retains compatibility with older Qt versions. Pick-to: 6.4 Change-Id: Id0fb9ab0089845ee8843fffd16f9c1539fa0368f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
* moc: replace offsetof with sizeofThiago Macieira2022-06-221-1/+1
| | | | | | | | | | It's the same thing since we have exactly one field in this structure before stringdata0. But there's a far smaller chance of producing a warning in user code. Pick-to: 6.2 6.3 6.4 Change-Id: Id0fb9ab0089845ee8843fffd16f9cdceec33017d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: fix use of escape sequence of more than one characterThiago Macieira2022-06-221-19/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We had the code to calculate the length, but were improperly using it only for the offset, not the length of the string or its containing array. That resulted in the generated moc output containing: QT_MOC_LITERAL(111, 5), // "\xffz" QT_MOC_LITERAL(114, 5), // "\0012" QT_MOC_LITERAL(117, 23), // "slotWithAReallyLongName" The two strings are described as occupying 5 bytes (length 4 + null terminator), which is incorrect. The offset was correct: 114 - 111 = 3 and 117 - 114 = 3. The new output is: QT_MOC_LITERAL(111, 2), // "\xffz" QT_MOC_LITERAL(114, 2), // "\0012" QT_MOC_LITERAL(117, 23), // "slotWithAReallyLongName" The effect of the array size calculation would only be felt if moc decided it needed a second string array (for strings over 65535 bytes), which would cause the offsets in the second array to be all wrong. There was no such test until now. Drive-by fixing of the newline, indentation, and the stale comment referring to QByteArrayData (Qt 5). Pick-to: 6.2 6.3 6.4 Change-Id: Id0fb9ab0089845ee8843fffd16f9cd01b3e0709a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: Allow reading property values through bindablesUlf Hermann2022-06-221-0/+3
| | | | | | | | | | | | | The behavior is similar to MEMBER: If the READ accessor is "default", synthesize it using the bindable. [ChangeLog][QtCore] You can now specify "READ default" in a Q_PROPERTY if you also specify a BINDABLE. moc will synthesize a READ accessor in that case. Task-number: QTBUG-97249 Change-Id: I4a275adabaed12df95dac505095f847c4be65dfe Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: rename the "offsetsAndSize" member to "offsetsAndSizes"Thiago Macieira2022-06-221-2/+2
| | | | | | | | | | | | | It contains more than one size. Drive-by drop the const from the structure, so it becomes properly trivial (though there's disagreement, see[1]). [1] https://conformance.godbolt.org/z/rK1xW669K Pick-to: 6.2 6.3 6.4 Change-Id: Id0fb9ab0089845ee8843fffd16f9cc69ffd90aa4 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* moc: Improve formatting of outputUlf Hermann2022-06-101-1/+1
| | | | | | | | If we are going to append an else clause, keep it on the same line as the closing brace. Change-Id: Idfa0eec49240086dc24268aebbf610d64a2f53d0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* moc: Add line breaks to the qt_incomplete_metaTypeArray<>Friedemann Kleint2022-05-181-11/+14
| | | | | | | | The code is hard to read due to the long line generated. Task-number: QTBUG-100145 Change-Id: I1d1a7a547db71cca1e710d39df809f079fc2dafe Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-29/+4
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Core: Remove 'properties' featureKai Köhne2022-02-141-6/+0
| | | | | | | | | | | | | Even QtCore alone cannot be built without the properties feature since Qt 5.5. While fixing this is easy, other modules like dbus, networking are also using QObject::property() and friends liberally. All in all I doubt that anybody will miss the feature (otherwise it would have been fixed in the last decade). Change-Id: Iaf3cc20bda54ee2ff3b809fac8fa82b94ecc88c0 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QMetaProperty: remove property auto-registration codeFabian Kosmale2022-02-091-0/+1
| | | | | | | | | | | | Qt 6 automatically registers all types used in properties. Thus, the functionality is mostly obsolete since Qt 6. We can simply return the stored metatype's id instead. The code in moc is kept in place for compatibility with older code, though there seem to be no remaining users of the metacall in Qt itself anymore. Change-Id: I3c654150988ae7780b4e9ea1f16191fdadf8d791 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QPlugin: move some of the logic from moc's output to qplugin.hThiago Macieira2021-10-041-47/+61
| | | | | | | | | | | | | | This will allow us to make changes in QtCore itself, without having to worry about moc compatibility. The output uses an #ifdef so this version of moc can still be used to compile earlier versions of Qt (usually, in cross-compilation environments). See discussion in the mailing list[1]. [1] https://lists.qt-project.org/pipermail/development/2021-September/041732.html Change-Id: I2de1b4dfacd443148279fffd16a39784c80c5f3b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* moc: Support BINDABLE for private propertiesAndrei Golubev2021-08-061-1/+8
| | | | | | | | Hopefully we won't need it but let's have it still at least for consistency Change-Id: I72289e65e5e5613174ad4d98cf8d614f9caae8e6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QMetaMethod: Store method constness in metaobject systemFabian Kosmale2021-05-071-1/+6
| | | | | | | | | [ChangeLog][QtCore][QMetaMethod] It is now possible to query the constness of a method with QMetaMethod::isConst. Change-Id: I8a94480b8074ef5b30555aeccd64937c4c6d97d4 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Introduce QMetaObject::metaTypeFabian Kosmale2021-03-251-49/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This function returns the metatype corresponding to the metaobject, or an invalid metatype for namespaces. This works as follows: First we increment the metaobject revision for new metaobjects. Metaobjects with older revisions are handled by doing a lookup by name. That fallback is also used for dynamic metaobjects (from QtDBUS and those created by QMetaObjectBuilder). For new metaobjects, we store the metatype in its metatype array, behind the property metatypes. This avoids any changes to the property and method metatype extraction logic: For properties, the metatype access does not change, as the new metatype is after their metatypes. For method metatypes, we already have an indirection layer (using offsets), so by adjusting those offsets by one, the same logic keeps working. To distinguish between namespaces and dynamic metaobjects, namespaces store the metatypeinterface pointer for void in the metatype array, whereas dynamic metaobjects store a nullptr. One nice additional benefit is that this simplifies the generator logic in moc, as the metatype array is now never empty. Task-number: QTBUG-92077 Change-Id: Id3f920f28553f12032a71a1a87dad29e5374dbe7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
* Make the QMultiHash(const QHash &) constructor explicitLars Knoll2020-11-031-1/+1
| | | | | | | | | And add a QMultiHash::unite(const QHash &) method to avoid a copy of the data when inserting a QHash into a multi hash. Change-Id: I864aa9d2b9b7b2c367c3c4d140a2ce2f5408ae09 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>