summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2013-09-25 21:36:15 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-17 01:36:37 +0100
commit55659fb5a4efd3fee813627350287c0b45a6dc9c (patch)
tree14756bd173ed3251483e65cac76d135b36d842f7
parent39262323d32306fb8f3bd0f5543b406a786c088e (diff)
moc: Fix parsing of complex defines defined via command line
Since now in Qt5 the moc does full macro substitution, it needs to handle the defines passed is command argument, even if they span over multiple tokens, or if they do not have any token. Example: moc '-DCOMPLEX=QVector<int>' '-DEMPTY=' foo.h [ChangeLog][moc] Fixed passing -D of a macro defined to something more complex than a single identifier. Task-number: QTBUG-33668 Change-Id: Ie8131de215f1659a24af4778d52ee40cda19759f Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
-rw-r--r--src/tools/moc/main.cpp3
-rw-r--r--src/tools/moc/preprocessor.cpp3
-rw-r--r--src/tools/moc/preprocessor.h2
-rw-r--r--tests/auto/tools/moc/moc.pro3
-rw-r--r--tests/auto/tools/moc/parse-defines.h12
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp3
6 files changed, 22 insertions, 4 deletions
diff --git a/src/tools/moc/main.cpp b/src/tools/moc/main.cpp
index 3ae6445093..0a5f6ec241 100644
--- a/src/tools/moc/main.cpp
+++ b/src/tools/moc/main.cpp
@@ -343,7 +343,8 @@ int runMoc(int argc, char **argv)
parser.showHelp(1);
}
Macro macro;
- macro.symbols += Symbol(0, PP_IDENTIFIER, value);
+ macro.symbols = Preprocessor::tokenize(value, 1, Preprocessor::TokenizeDefine);
+ macro.symbols.removeLast(); // remove the EOF symbol
pp.macros.insert(name, macro);
}
foreach (const QString &arg, parser.values(undefineOption)) {
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp
index 3615262b67..2de495f010 100644
--- a/src/tools/moc/preprocessor.cpp
+++ b/src/tools/moc/preprocessor.cpp
@@ -158,8 +158,7 @@ bool Preprocessor::skipBranch()
}
-enum TokenizeMode { TokenizeCpp, TokenizePreprocessor, PreparePreprocessorStatement, TokenizePreprocessorStatement, TokenizeInclude, PrepareDefine, TokenizeDefine };
-static Symbols tokenize(const QByteArray &input, int lineNum = 1, TokenizeMode mode = TokenizeCpp)
+Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocessor::TokenizeMode mode)
{
Symbols symbols;
const char *begin = input.constData();
diff --git a/src/tools/moc/preprocessor.h b/src/tools/moc/preprocessor.h
index dc7c98de85..6403955c1b 100644
--- a/src/tools/moc/preprocessor.h
+++ b/src/tools/moc/preprocessor.h
@@ -89,6 +89,8 @@ public:
int evaluateCondition();
+ enum TokenizeMode { TokenizeCpp, TokenizePreprocessor, PreparePreprocessorStatement, TokenizePreprocessorStatement, TokenizeInclude, PrepareDefine, TokenizeDefine };
+ static Symbols tokenize(const QByteArray &input, int lineNum = 1, TokenizeMode mode = TokenizeCpp);
private:
void until(Token);
diff --git a/tests/auto/tools/moc/moc.pro b/tests/auto/tools/moc/moc.pro
index 779e992881..9a3fee38f0 100644
--- a/tests/auto/tools/moc/moc.pro
+++ b/tests/auto/tools/moc/moc.pro
@@ -42,3 +42,6 @@ DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
# Ensure that plugin_metadata.h are moc-ed with some extra -M arguments:
QMAKE_MOC_OPTIONS += -Muri=com.company.app -Muri=com.company.app.private
+# Define macro on the command lines used in parse-defines.h
+QMAKE_MOC_OPTIONS += "-DDEFINE_CMDLINE_EMPTY=" "\"-DDEFINE_CMDLINE_SIGNAL=void cmdlineSignal(const QMap<int, int> &i)\""
+
diff --git a/tests/auto/tools/moc/parse-defines.h b/tests/auto/tools/moc/parse-defines.h
index aaadcef601..35934853f0 100644
--- a/tests/auto/tools/moc/parse-defines.h
+++ b/tests/auto/tools/moc/parse-defines.h
@@ -79,9 +79,16 @@
#define PD_ADD_SUFFIX(x) PD_DEFINE1(x,_SUFFIX)
#define PD_DEFINE_ITSELF PD_ADD_SUFFIX(PD_DEFINE_ITSELF)
+#ifndef Q_MOC_RUN
+// macro defined on the command line (in tst_moc.pro)
+#define DEFINE_CMDLINE_EMPTY
+#define DEFINE_CMDLINE_SIGNAL void cmdlineSignal(const QMap<int, int> &i)
+#endif
+
PD_BEGIN_NAMESPACE
-class PD_CLASSNAME : public QObject
+class DEFINE_CMDLINE_EMPTY PD_CLASSNAME DEFINE_CMDLINE_EMPTY
+ : public DEFINE_CMDLINE_EMPTY QObject DEFINE_CMDLINE_EMPTY
{
Q_OBJECT
Q_CLASSINFO("TestString", PD_STRINGIFY(PD_CLASSNAME))
@@ -140,6 +147,9 @@ public slots:
void PD_DEFINE_ITSELF(int) {}
+signals:
+ DEFINE_CMDLINE_SIGNAL;
+
};
#undef QString
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 7fae29e5ca..8ce55cbdf5 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -3037,6 +3037,9 @@ void tst_Moc::parseDefines()
index = mo->indexOfSlot("PD_DEFINE_ITSELF_SUFFIX(int)");
QVERIFY(index != -1);
+
+ index = mo->indexOfSignal("cmdlineSignal(QMap<int,int>)");
+ QVERIFY(index != -1);
}
void tst_Moc::preprocessorOnly()