summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@theqtcompany.com>2015-12-09 10:27:58 +0100
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-12-17 13:47:33 +0000
commitd6efc0aab30c5dc927aa8a0c743ab0c3775321a4 (patch)
tree17d66f0cc27ae85d870b7edede8b0bb9d1f36bf2
parent879409fd0ffa2466dbd9f7274a4417b34ed18360 (diff)
qmake: teach findMocs to handle backslash-newline gracefully.
Change-Id: Id71352c0cf71ab84bd81d4f3d11bb19dc7965903 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
-rw-r--r--qmake/generators/makefiledeps.cpp83
-rw-r--r--tests/auto/tools/qmake/testdata/findMocs/findMocs.pro3
-rw-r--r--tests/auto/tools/qmake/testdata/findMocs/main.cpp5
-rw-r--r--tests/auto/tools/qmake/testdata/findMocs/object1.h4
-rw-r--r--tests/auto/tools/qmake/testdata/findMocs/object2.h4
-rw-r--r--tests/auto/tools/qmake/testdata/findMocs/object3.h4
-rw-r--r--tests/auto/tools/qmake/testdata/findMocs/object4.h3
-rw-r--r--tests/auto/tools/qmake/testdata/findMocs/object8.h50
-rw-r--r--tests/auto/tools/qmake/testdata/findMocs/object9.h41
9 files changed, 150 insertions, 47 deletions
diff --git a/qmake/generators/makefiledeps.cpp b/qmake/generators/makefiledeps.cpp
index 037ad06ad3..1f94a53c81 100644
--- a/qmake/generators/makefiledeps.cpp
+++ b/qmake/generators/makefiledeps.cpp
@@ -902,13 +902,24 @@ bool QMakeSourceFileInfo::findMocs(SourceFile *file)
/* qmake ignore Q_GADGET */
/* qmake ignore Q_OBJECT */
for(int x = 0; x < buffer_len; x++) {
+#define SKIP_BSNL(pos) skipEscapedLineEnds(buffer, buffer_len, (pos), &line_count)
+ x = SKIP_BSNL(x);
if (buffer[x] == '/') {
- ++x;
- if(buffer_len >= x) {
- if (buffer[x] == '/') { // C++-style comment
- for (; x < buffer_len && !qmake_endOfLine(buffer[x]); ++x) {} // skip
- } else if (buffer[x] == '*') { // C-style comment
- for(++x; x < buffer_len; ++x) {
+ int extralines = 0;
+ int y = skipEscapedLineEnds(buffer, buffer_len, x + 1, &extralines);
+ if (buffer_len > y) {
+ // If comment, advance to the character that ends it:
+ if (buffer[y] == '/') { // C++-style comment
+ line_count += extralines;
+ x = y;
+ do {
+ x = SKIP_BSNL(x + 1);
+ } while (x < buffer_len && !qmake_endOfLine(buffer[x]));
+
+ } else if (buffer[y] == '*') { // C-style comment
+ line_count += extralines;
+ x = SKIP_BSNL(y + 1);
+ for (; x < buffer_len; x = SKIP_BSNL(x + 1)) {
if (buffer[x] == 't' || buffer[x] == 'q') { // ignore
if(buffer_len >= (x + 20) &&
!strncmp(buffer + x + 1, "make ignore Q_OBJECT", 20)) {
@@ -924,58 +935,58 @@ bool QMakeSourceFileInfo::findMocs(SourceFile *file)
ignore_qgadget = true;
}
} else if (buffer[x] == '*') {
- if (buffer_len >= x + 1 && buffer[x + 1] == '/') {
- ++x;
+ extralines = 0;
+ y = skipEscapedLineEnds(buffer, buffer_len, x + 1, &extralines);
+ if (buffer_len > y && buffer[y] == '/') {
+ line_count += extralines;
+ x = y;
break;
}
} else if (Option::debug_level && qmake_endOfLine(buffer[x])) {
++line_count;
}
}
- } else { // not a comment, in fact; undo the extra x++ we did.
- x--;
}
+ // else: don't update x, buffer[x] is just the division operator.
}
} else if (buffer[x] == '\'' || buffer[x] == '"') {
x = scanPastString(buffer, buffer_len, x, &line_count);
// Leaves us on closing quote; for loop's x++ steps us past it.
}
- if (Option::debug_level && qmake_endOfLine(buffer[x]))
+ if (x < buffer_len && Option::debug_level && qmake_endOfLine(buffer[x]))
++line_count;
- if (buffer_len > x + 2 && buffer[x + 1] == 'Q' &&
- buffer[x + 2] == '_' && !isCWordChar(buffer[x])) {
- ++x;
- int match = 0;
- static const char *interesting[] = { "OBJECT", "GADGET" };
- for (int interest = 0, m1, m2; interest < 2; ++interest) {
+ if (buffer_len > x + 8 && !isCWordChar(buffer[x])) {
+ 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) {
if(interest == 0 && ignore_qobject)
continue;
else if(interest == 1 && ignore_qgadget)
continue;
- for (m1 = 0, m2 = 0; interesting[interest][m1]; ++m1) {
- if (interesting[interest][m1] != buffer[x + 2 + m1]) {
- m2 = -1;
- break;
+
+ int matchlen = 0, extralines = 0;
+ if (matchWhileUnsplitting(buffer, buffer_len, y,
+ interesting[interest],
+ strlen(interesting[interest]),
+ &matchlen, &extralines)
+ && y + matchlen < buffer_len
+ && !isCWordChar(buffer[y + matchlen])) {
+ if (Option::debug_level) {
+ buffer[y + matchlen] = '\0';
+ debug_msg(2, "Mocgen: %s:%d Found MOC symbol %s",
+ file->file.real().toLatin1().constData(),
+ line_count + morelines, buffer + y);
+ }
+ file->mocable = true;
+ return true;
}
- ++m2;
- }
- if(m1 == m2) {
- match = m2 + 2;
- break;
}
}
- if (match && !isCWordChar(buffer[x + match])) {
- if (Option::debug_level) {
- buffer[x + match] = '\0';
- debug_msg(2, "Mocgen: %s:%d Found MOC symbol %s",
- file->file.real().toLatin1().constData(),
- line_count, buffer + x);
- }
- file->mocable = true;
- return true;
- }
}
+#undef SKIP_BSNL
}
return true;
}
diff --git a/tests/auto/tools/qmake/testdata/findMocs/findMocs.pro b/tests/auto/tools/qmake/testdata/findMocs/findMocs.pro
index a4a7dc987d..af672c2621 100644
--- a/tests/auto/tools/qmake/testdata/findMocs/findMocs.pro
+++ b/tests/auto/tools/qmake/testdata/findMocs/findMocs.pro
@@ -1,4 +1,5 @@
DESTDIR = ./
-HEADERS += object1.h object2.h object3.h object4.h object5.h object6.h object7.h
+HEADERS += object1.h object2.h object3.h object4.h \
+ object5.h object6.h object7.h object8.h object9.h
SOURCES += main.cpp
diff --git a/tests/auto/tools/qmake/testdata/findMocs/main.cpp b/tests/auto/tools/qmake/testdata/findMocs/main.cpp
index 8e0ef9fc41..3f566c4af4 100644
--- a/tests/auto/tools/qmake/testdata/findMocs/main.cpp
+++ b/tests/auto/tools/qmake/testdata/findMocs/main.cpp
@@ -39,6 +39,7 @@
#include <moc_object5.cpp>
#include <moc_object6.cpp>
#include <moc_object7.cpp>
+#include "object8.h"
+#include <moc_object9.cpp>
-int main () {}
-
+int main() { return 0; }
diff --git a/tests/auto/tools/qmake/testdata/findMocs/object1.h b/tests/auto/tools/qmake/testdata/findMocs/object1.h
index e0857f4297..1fcac5f511 100644
--- a/tests/auto/tools/qmake/testdata/findMocs/object1.h
+++ b/tests/auto/tools/qmake/testdata/findMocs/object1.h
@@ -37,6 +37,6 @@
class Object1 : public QObject
{
- Q_OBJECT
+ Q\
+_OBJECT
};
-
diff --git a/tests/auto/tools/qmake/testdata/findMocs/object2.h b/tests/auto/tools/qmake/testdata/findMocs/object2.h
index cc60269cd3..a52489b44c 100644
--- a/tests/auto/tools/qmake/testdata/findMocs/object2.h
+++ b/tests/auto/tools/qmake/testdata/findMocs/object2.h
@@ -36,6 +36,6 @@
class Object2 : public QObject
{
- Q_OBJECT
+ Q_\
+OBJECT
};
-
diff --git a/tests/auto/tools/qmake/testdata/findMocs/object3.h b/tests/auto/tools/qmake/testdata/findMocs/object3.h
index c66edee6e1..c481a0796d 100644
--- a/tests/auto/tools/qmake/testdata/findMocs/object3.h
+++ b/tests/auto/tools/qmake/testdata/findMocs/object3.h
@@ -37,6 +37,6 @@
class Object3 : public QObject
{
- Q_OBJECT
+ Q_OBJ\
+ECT
};
-
diff --git a/tests/auto/tools/qmake/testdata/findMocs/object4.h b/tests/auto/tools/qmake/testdata/findMocs/object4.h
index 73bf9cdaa3..eb38652f14 100644
--- a/tests/auto/tools/qmake/testdata/findMocs/object4.h
+++ b/tests/auto/tools/qmake/testdata/findMocs/object4.h
@@ -44,10 +44,9 @@ class Object4 : public QObject
Comment ends there --> /*/
// Now we poison moc, just to make sure this doesn't get moc'ed :)
-class NonMocObject
+class NonMocObject4
/* : QObject */
{
/* qmake ignore Q_OBJECT */
Q_OBJECT
};
-
diff --git a/tests/auto/tools/qmake/testdata/findMocs/object8.h b/tests/auto/tools/qmake/testdata/findMocs/object8.h
new file mode 100644
index 0000000000..51096e4c27
--- /dev/null
+++ b/tests/auto/tools/qmake/testdata/findMocs/object8.h
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QObject>
+#define Q_OBJECTOID_THING // empty
+
+class Object8 : public QObject
+{
+ Q_OBJECT\
+OID_THING
+};
+
+// Now we poison moc, just to make sure this doesn't get moc'ed :)
+class NonMocObject8
+/* : QObject */
+{
+ /* qmake ignore Q_OBJECT */
+ Q_OBJECT
+};
diff --git a/tests/auto/tools/qmake/testdata/findMocs/object9.h b/tests/auto/tools/qmake/testdata/findMocs/object9.h
new file mode 100644
index 0000000000..bda50355d9
--- /dev/null
+++ b/tests/auto/tools/qmake/testdata/findMocs/object9.h
@@ -0,0 +1,41 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QObject>
+#define juxtaposed "lorem ""ipsum /*"
+
+class Object9 : public QObject
+{
+ Q_OBJECT
+};