summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2023-07-25 10:33:25 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2023-07-28 12:23:53 +0200
commitf0039bd5170ad84d972a023316e8d153b89f841a (patch)
tree10b958c3d8e20312539b0636256373724ecfb1fd
parenta2ec43b8ebcbf8462928800a7db4f6af7e482b18 (diff)
moc: handle "L" integer suffix
This commit adds some initial support for handling the 'L' suffix after numbers. This one is especially important given that the __cplusplus define is using it. Other suffixes will be handled in some later commit, which should also unify the already divergent parse behavior between DIGIT and PP_DIGIT parsing (e.g. when it comes to byte prefixes). Task-number: QTBUG-83160 Task-number: QTBUG-115558 Pick-to: 6.6 6.5 6.2 Change-Id: Ie61eae49c468abfaee80e7e4f7097917a254dc0e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/tools/moc/preprocessor.cpp12
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp5
2 files changed, 14 insertions, 3 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp
index 8a0061a9bd..49df66baf7 100644
--- a/src/tools/moc/preprocessor.cpp
+++ b/src/tools/moc/preprocessor.cpp
@@ -225,7 +225,8 @@ Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocesso
++data;
while (isHexDigit(*data) || *data == '\'')
++data;
- }
+ } else if (*data == 'L') // TODO: handle other suffixes
+ ++data;
break;
}
token = FLOATING_LITERAL;
@@ -402,7 +403,8 @@ Symbols Preprocessor::tokenize(const QByteArray& input, int lineNum, Preprocesso
++data;
while (isHexDigit(*data) || *data == '\'')
++data;
- }
+ } else if (*data == 'L') // TODO: handle other suffixes
+ ++data;
break;
}
token = PP_FLOATING_LITERAL;
@@ -932,7 +934,11 @@ int PP_Expression::primary_expression()
test(PP_RPAREN);
} else {
next();
- value = lexem().toInt(nullptr, 0);
+ const QByteArray &lex = lexem();
+ auto lexView = QByteArrayView(lex);
+ if (lex.endsWith('L'))
+ lexView.chop(1);
+ value = lexView.toInt(nullptr, 0);
}
return value;
}
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index 1929ad3fba..0cd33288fc 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -638,6 +638,10 @@ private slots:
QT_WARNING_POP
+// quick test to verify that moc handles the L suffix
+// correctly in the preprocessor
+#if 2000L < 1
+#else
class PropertyTestClass : public QObject
{
Q_OBJECT
@@ -647,6 +651,7 @@ public:
Q_ENUM(TestEnum)
};
+#endif
class PropertyUseClass : public QObject
{