qmake: teach findMocs to handle backslash-newline gracefully.

Change-Id: Id71352c0cf71ab84bd81d4f3d11bb19dc7965903
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
This commit is contained in:
Edward Welbourne 2015-12-09 10:27:58 +01:00 committed by Simon Hausmann
parent 879409fd0f
commit d6efc0aab3
9 changed files with 150 additions and 47 deletions

View File

@ -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,59 +935,59 @@ 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;
}
++m2;
}
if(m1 == m2) {
match = m2 + 2;
break;
}
}
if (match && !isCWordChar(buffer[x + match])) {
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[x + match] = '\0';
buffer[y + matchlen] = '\0';
debug_msg(2, "Mocgen: %s:%d Found MOC symbol %s",
file->file.real().toLatin1().constData(),
line_count, buffer + x);
line_count + morelines, buffer + y);
}
file->mocable = true;
return true;
}
}
}
}
#undef SKIP_BSNL
}
return true;
}

View File

@ -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

View File

@ -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; }

View File

@ -37,6 +37,6 @@
class Object1 : public QObject
{
Q_OBJECT
Q\
_OBJECT
};

View File

@ -36,6 +36,6 @@
class Object2 : public QObject
{
Q_OBJECT
Q_\
OBJECT
};

View File

@ -37,6 +37,6 @@
class Object3 : public QObject
{
Q_OBJECT
Q_OBJ\
ECT
};

View File

@ -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
};

View File

@ -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
};

View File

@ -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
};