Moc: remove STRINGDATA fallback code

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>
bb10
Ahmad Samir 2023-05-23 23:33:54 +03:00 committed by Thiago Macieira
parent 4b4d384f3e
commit 58329bbd2b
2 changed files with 3 additions and 77 deletions

View File

@ -93,19 +93,6 @@ static inline int lengthOfEscapeSequence(const QByteArray &s, int i)
return i - startPos;
}
static inline uint lengthOfEscapedString(const QByteArray &str)
{
int extra = 0;
for (int j = 0; j < str.size(); ++j) {
if (str.at(j) == '\\') {
int cnt = lengthOfEscapeSequence(str, j) - 1;
extra += cnt;
j += cnt;
}
}
return str.size() - extra;
}
// Prints \a s to \a out, breaking it into lines of at most ColumnWidth. The
// opening and closing quotes are NOT included (it's up to the caller).
static void printStringWithIndentation(FILE *out, const QByteArray &s)
@ -288,61 +275,9 @@ void Generator::generateCode()
}
}
fprintf(out, "\n);\n"
"#else // !QT_MOC_HAS_STRING_DATA\n");
#if QT_VERSION >= QT_VERSION_CHECK(6, 9, 0)
"#else // !QT_MOC_HAS_STRINGDATA\n");
fprintf(out, "#error \"qtmochelpers.h not found or too old.\"\n");
#else
//
// Build stringdata struct
//
fprintf(out, "struct qt_meta_stringdata_%s_t {\n", qualifiedClassNameIdentifier.constData());
fprintf(out, " uint offsetsAndSizes[%d];\n", int(strings.size() * 2));
for (int i = 0; i < strings.size(); ++i) {
int thisLength = lengthOfEscapedString(strings.at(i)) + 1;
fprintf(out, " char stringdata%d[%d];\n", i, thisLength);
}
fprintf(out, "};\n");
// Macro that simplifies the string data listing. The offset is calculated
// from the top of the stringdata object (i.e., past the uints).
fprintf(out, "#define QT_MOC_LITERAL(ofs, len) \\\n"
" uint(sizeof(qt_meta_stringdata_%s_t::offsetsAndSizes) + ofs), len \n",
qualifiedClassNameIdentifier.constData());
fprintf(out, "Q_CONSTINIT static const qt_meta_stringdata_%s_t qt_meta_stringdata_%s = {\n",
qualifiedClassNameIdentifier.constData(), qualifiedClassNameIdentifier.constData());
fprintf(out, " {");
{
int idx = 0;
for (int i = 0; i < strings.size(); ++i) {
const QByteArray &str = strings.at(i);
const QByteArray comment = str.size() > 32 ? str.left(29) + "..." : str;
const char *comma = (i != strings.size() - 1 ? "," : " ");
int len = lengthOfEscapedString(str);
fprintf(out, "\n QT_MOC_LITERAL(%d, %d)%s // \"%s\"", idx, len, comma,
comment.constData());
idx += len + 1;
}
fprintf(out, "\n }");
}
//
// Build stringdata arrays
//
for (const QByteArray &s : std::as_const(strings)) {
fputc(',', out);
printStringWithIndentation(out, s);
}
// Terminate stringdata struct
fprintf(out, "\n};\n");
fprintf(out, "#undef QT_MOC_LITERAL\n");
#endif // Qt 6.9
fprintf(out, "#endif // !QT_MOC_HAS_STRING_DATA\n");
fprintf(out, "#endif // !QT_MOC_HAS_STRINGDATA\n");
fprintf(out, "} // unnamed namespace\n\n");
//

View File

@ -1111,16 +1111,7 @@ void Moc::generate(FILE *out, FILE *jsonOutput)
for (const QByteArray &qtContainer : qtContainers)
fprintf(out, "#include <QtCore/%s>\n", qtContainer.constData());
fprintf(out, "\n%s#include <QtCore/qtmochelpers.h>\n%s\n",
#if QT_VERSION <= QT_VERSION_CHECK(6, 9, 0)
"#if __has_include(<QtCore/qtmochelpers.h>)\n",
"#else\n"
"QT_BEGIN_MOC_NAMESPACE\n"
"#endif\n"
#else
"", ""
#endif
);
fprintf(out, "\n#include <QtCore/qtmochelpers.h>\n");
fprintf(out, "\n#include <memory>\n\n"); // For std::addressof