summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan@kdab.com>2016-08-23 22:32:11 +0300
committerBogDan Vatra <bogdan@kdab.com>2016-09-06 10:29:21 +0000
commit21b7661a797ecf77fbcad4380e6dcb2ade929a18 (patch)
tree0536792e237d686e3cae1b35ebd0ad4dca834393
parent23ef3b04ebfc0c7a87800b4ff09444c854e31fdb (diff)
Parse namespaces only for current file, add Q_NAMESPACE support to qmake
Parsing the other files will (re)generate the same metaobject info in two places Change-Id: I8984ed30751a7587de870f55dd427f067d1b2495 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r--qmake/generators/makefiledeps.cpp13
-rw-r--r--src/tools/moc/moc.cpp3
-rw-r--r--tests/auto/tools/moc/moc.pro3
-rw-r--r--tests/auto/tools/moc/namespace.h7
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp1
5 files changed, 22 insertions, 5 deletions
diff --git a/qmake/generators/makefiledeps.cpp b/qmake/generators/makefiledeps.cpp
index 57cb0ea854..67c8219d4b 100644
--- a/qmake/generators/makefiledeps.cpp
+++ b/qmake/generators/makefiledeps.cpp
@@ -911,9 +911,10 @@ bool QMakeSourceFileInfo::findMocs(SourceFile *file)
debug_msg(2, "findMocs: %s", file->file.local().toLatin1().constData());
int line_count = 1;
- bool ignore[2] = { false, false }; // [0] for Q_OBJECT, [1] for Q_GADGET
+ bool ignore[3] = { false, false, false }; // [0] for Q_OBJECT, [1] for Q_GADGET, [2] for Q_NAMESPACE
/* qmake ignore Q_GADGET */
/* qmake ignore Q_OBJECT */
+ /* qmake ignore Q_NAMESPACE */
for(int x = 0; x < buffer_len; x++) {
#define SKIP_BSNL(pos) skipEscapedLineEnds(buffer, buffer_len, (pos), &line_count)
x = SKIP_BSNL(x);
@@ -946,6 +947,12 @@ bool QMakeSourceFileInfo::findMocs(SourceFile *file)
file->file.real().toLatin1().constData(), line_count);
x += 20;
ignore[1] = true;
+ } else if (buffer_len >= (x + 23) &&
+ !strncmp(buffer + x + 1, "make ignore Q_NAMESPACE", 23)) {
+ debug_msg(2, "Mocgen: %s:%d Found \"qmake ignore Q_NAMESPACE\"",
+ file->file.real().toLatin1().constData(), line_count);
+ x += 23;
+ ignore[2] = true;
}
} else if (buffer[x] == '*') {
extralines = 0;
@@ -973,8 +980,8 @@ bool QMakeSourceFileInfo::findMocs(SourceFile *file)
int morelines = 0;
int y = skipEscapedLineEnds(buffer, buffer_len, x + 1, &morelines);
if (buffer[y] == 'Q') {
- static const char interesting[][9] = { "Q_OBJECT", "Q_GADGET" };
- for (int interest = 0; interest < 2; ++interest) {
+ static const char interesting[][12] = { "Q_OBJECT", "Q_GADGET", "Q_NAMESPACE"};
+ for (int interest = 0; interest < 3; ++interest) {
if (ignore[interest])
continue;
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp
index 22207a9030..eda410783c 100644
--- a/src/tools/moc/moc.cpp
+++ b/src/tools/moc/moc.cpp
@@ -560,7 +560,8 @@ void Moc::parse()
until(RBRACE);
def.end = index;
index = def.begin + 1;
- while (inNamespace(&def) && hasNext()) {
+ const bool parseNamespace = currentFilenames.size() <= 1;
+ while (parseNamespace && inNamespace(&def) && hasNext()) {
switch (next()) {
case Q_NAMESPACE_TOKEN:
def.hasQNamespace = true;
diff --git a/tests/auto/tools/moc/moc.pro b/tests/auto/tools/moc/moc.pro
index 688799048f..d2b750bdc5 100644
--- a/tests/auto/tools/moc/moc.pro
+++ b/tests/auto/tools/moc/moc.pro
@@ -28,7 +28,8 @@ HEADERS += using-namespaces.h no-keywords.h task87883.h c-comments.h backslash-n
qtbug-35657-gadget.h \
non-gadget-parent-class.h grand-parent-gadget-class.h \
related-metaobjects-in-gadget.h \
- related-metaobjects-name-conflict.h
+ related-metaobjects-name-conflict.h \
+ namespace.h
if(*-g++*|*-icc*|*-clang*|*-llvm):!irix-*:!win32-*: HEADERS += os9-newlines.h win-newlines.h
diff --git a/tests/auto/tools/moc/namespace.h b/tests/auto/tools/moc/namespace.h
new file mode 100644
index 0000000000..2bb1d8e958
--- /dev/null
+++ b/tests/auto/tools/moc/namespace.h
@@ -0,0 +1,7 @@
+#pragma once
+
+#include <QObject>
+
+namespace FooNamespace {
+ Q_NAMESPACE
+}
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 714ae19a10..56d6939102 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -69,6 +69,7 @@
#include "non-gadget-parent-class.h"
#include "grand-parent-gadget-class.h"
+#include "namespace.h"
#ifdef Q_MOC_RUN
// check that moc can parse these constructs, they are being used in Windows winsock2.h header