Commit ab14ac7c authored by Milian Wolff's avatar Milian Wolff
Browse files

properly handle l, lu, ul integers in our preprocessor

this finally fixes parsing of gcc 4.7 headers

thanks again to Ivan Shapovalov for this patch, which
I cleaned up a bit and added a unit test

the question now: how should ll, ull, llu integers be
handled by a c++11 compliant preprocessor?

BUG: 297604
REVIEW: 104498
parent c33000b0
......@@ -1170,10 +1170,18 @@ int pp::next_token (Stream& input)
base = 8;
}
if (number.endsWith('u', Qt::CaseInsensitive)) {
if (number.endsWith("lu", Qt::CaseInsensitive) || number.endsWith("ul", Qt::CaseInsensitive)) {
number.chop(2);
token_uvalue = number.toULong(0, base);
nextToken = TOKEN_UNUMBER;
} else if (number.endsWith('l', Qt::CaseInsensitive)) {
number.chop(1);
token_value = number.toLong(0, base);
nextToken = TOKEN_NUMBER;
} else if (number.endsWith('u', Qt::CaseInsensitive)) {
number.chop(1);
token_uvalue = number.toULong(0, base);
nextToken = TOKEN_UNUMBER;
} else {
token_value = number.toLong(0, base);
nextToken = TOKEN_NUMBER;
......
......@@ -479,7 +479,17 @@ void TestParser::testPreprocessor() {
QCOMPARE(preprocess("#define MM(x) NN\n#define OO(NN) MM(NN)\nOO(2)\n").trimmed(), QString("NN"));
QCOMPARE(preprocess("#define OOO(x) x x x\n#define OOOO(x) O##x(2)\nOOOO(OO)\n").replace(QRegExp("[\n\t ]+"), " ").trimmed(), QString("2 2 2"));
QCOMPARE(preprocess("#define OOO(x) x x x\n#define OOOO(x) O##x(2)\nOOOO(OOO)\n").replace(QRegExp("[\n\t ]+"), ""), QString("OOOO(2)"));
QCOMPARE(preprocess("#if 1\n #define N 10\n#else\n#define N 20\n#endif\nN\n").trimmed(), QString("10"));
QCOMPARE(preprocess("#if 1u\n #define N 10\n#else\n#define N 20\n#endif\nN\n").trimmed(), QString("10"));
QCOMPARE(preprocess("#if 1l\n #define N 10\n#else\n#define N 20\n#endif\nN\n").trimmed(), QString("10"));
QCOMPARE(preprocess("#if 1lu\n #define N 10\n#else\n#define N 20\n#endif\nN\n").trimmed(), QString("10"));
QCOMPARE(preprocess("#if 1ul\n #define N 10\n#else\n#define N 20\n#endif\nN\n").trimmed(), QString("10"));
QEXPECT_FAIL("", "not yet handled", Continue);
QCOMPARE(preprocess("#if 1ll\n #define N 10\n#else\n#define N 20\n#endif\nN\n").trimmed(), QString("10"));
QEXPECT_FAIL("", "not yet handled", Continue);
QCOMPARE(preprocess("#if 1llu\n #define N 10\n#else\n#define N 20\n#endif\nN\n").trimmed(), QString("10"));
QCOMPARE(preprocess("#ifdef\n"), QString("*ERROR*"));
QEXPECT_FAIL("", "Backslash incorrectly handled", Continue);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment