From 5a1fa8860ca466bc109f1195e1e4b92c0c92018d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 3 Sep 2012 12:55:38 +0200 Subject: Generate includes for Qt containers used as auto-metatypes. Otherwise the containers might be forward declared in the moc file, and when the moc file is compiled in a standalone translation unit, the full definition of it would not be available. This results in odd compile errors, so instead generate the includes if required. Change-Id: Ie01c5a5d45314daad0b00dec03b3e1e18cdbae64 Reviewed-by: Thiago Macieira Reviewed-by: Volker Krause Reviewed-by: Olivier Goffart --- src/tools/moc/moc.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/tools/moc') diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index d7c08b4608..1693281c87 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -797,6 +797,38 @@ void Moc::parse() } } +static void findRequiredContainers(ClassDef *cdef, QSet *requiredQtContainers) +{ + static const QVector candidates = QVector() +#define STREAM_SMART_POINTER(SMART_POINTER) << #SMART_POINTER + QT_FOR_EACH_AUTOMATIC_TEMPLATE_SMART_POINTER(STREAM_SMART_POINTER) +#undef STREAM_SMART_POINTER +#define STREAM_1ARG_TEMPLATE(TEMPLATENAME) << #TEMPLATENAME + QT_FOR_EACH_AUTOMATIC_TEMPLATE_1ARG(STREAM_1ARG_TEMPLATE) +#undef STREAM_1ARG_TEMPLATE + ; + + for (int i = 0; i < cdef->propertyList.count(); ++i) { + const PropertyDef &p = cdef->propertyList.at(i); + foreach (const QByteArray candidate, candidates) { + if (p.type.contains(candidate + "<")) + requiredQtContainers->insert(candidate); + } + } + + QList allFunctions = cdef->slotList + cdef->signalList + cdef->methodList; + + for (int i = 0; i < allFunctions.count(); ++i) { + const FunctionDef &f = allFunctions.at(i); + foreach (const ArgumentDef &arg, f.arguments) { + foreach (const QByteArray candidate, candidates) { + if (arg.normalizedType.contains(candidate + "<")) + requiredQtContainers->insert(candidate); + } + } + } +} + void Moc::generate(FILE *out) { @@ -837,6 +869,16 @@ void Moc::generate(FILE *out) if (mustIncludeQPluginH) fprintf(out, "#include \n"); + QSet requiredQtContainers; + for (i = 0; i < classList.size(); ++i) { + findRequiredContainers(&classList[i], &requiredQtContainers); + } + + foreach (const QByteArray &qtContainer, requiredQtContainers) { + fprintf(out, "#include \n", qtContainer.constData()); + } + + fprintf(out, "#if !defined(Q_MOC_OUTPUT_REVISION)\n" "#error \"The header file '%s' doesn't include .\"\n", fn.constData()); fprintf(out, "#elif Q_MOC_OUTPUT_REVISION != %d\n", mocOutputRevision); -- cgit v1.2.3