Commit d90264d6 authored by Leandro Melo's avatar Leandro Melo Committed by hjk
Browse files

C++: Also expand first token after macro define



It was previously beeing skipped.

Change-Id: Iadd9b03acbcf0ee0fb4db537b8597661cb93af3f
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 809a4ed9
......@@ -1257,16 +1257,22 @@ void Preprocessor::handleDefineDirective(PPToken *tk)
QVector<PPToken> bodyTokens;
PPToken firstBodyToken = *tk;
while (isValidToken(*tk)) {
tk->f.generated = true;
bodyTokens.push_back(*tk);
lex(tk);
if (eagerExpansion)
if (eagerExpansion) {
PPToken idTk = *tk;
while (tk->is(T_IDENTIFIER)
&& (!tk->newline() || tk->joined())
&& !isQtReservedWord(tk->asByteArrayRef())
&& handleIdentifier(tk)) {
lex(tk);
if (tk->asByteArrayRef() == macroName) {
*tk = idTk;
break;
}
}
}
tk->f.generated = true;
bodyTokens.push_back(*tk);
lex(tk);
}
if (isQtReservedWord(ByteArrayRef(&macroName))) {
......
......@@ -125,7 +125,7 @@ public:
{
m_expandedMacros.append(QByteArray(originalText.start(), originalText.length()));
m_expandedMacrosOffset.append(offset);
m_macroUsesLine.insert(macro.name(), m_env->currentLine);
m_macroUsesLine[macro.name()].append(m_env->currentLine);
}
virtual void stopExpandingMacro(unsigned /*offset*/, const Macro &/*macro*/) {}
......@@ -229,7 +229,7 @@ public:
QList<unsigned> definedMacrosLine() const
{ return m_definedMacrosLine; }
QHash<QByteArray, unsigned> macroUsesLine() const
QHash<QByteArray, QList<unsigned> > macroUsesLine() const
{ return m_macroUsesLine; }
private:
......@@ -244,7 +244,7 @@ private:
QList<unsigned> m_expandedMacrosOffset;
QList<QByteArray> m_definedMacros;
QList<unsigned> m_definedMacrosLine;
QHash<QByteArray, unsigned> m_macroUsesLine;
QHash<QByteArray, QList<unsigned> > m_macroUsesLine;
};
QT_BEGIN_NAMESPACE
......@@ -495,7 +495,9 @@ void tst_Preprocessor::macro_uses_lines()
"#if ENABLE(COOL)\n"
"class Cool {};\n"
"#endif\n"
"int cool = ENABLE_COOL;\n");
"int cool = ENABLE_COOL;\n"
"#define OTHER_ENABLE(FEATURE) ENABLE(FEATURE)\n"
"#define MORE(LESS) FOO ENABLE(LESS)\n");
QByteArray output;
Environment env;
......@@ -503,19 +505,22 @@ void tst_Preprocessor::macro_uses_lines()
Preprocessor preprocess(&client, &env);
preprocess.run(QLatin1String("<stdin>"), buffer);
QCOMPARE(client.macroUsesLine().value("FOO"), 2U);
QCOMPARE(client.macroUsesLine().value("HEADER"), 5U);
QCOMPARE(client.macroUsesLine().value("DECLARE"), 9U);
QCOMPARE(client.macroUsesLine().value("NOTHING"), 13U);
QCOMPARE(client.macroUsesLine().value("ENABLE"), 18U);
QCOMPARE(client.macroUsesLine().value("ENABLE_COOL"), 21U);
QCOMPARE(client.macroUsesLine().value("FOO"), QList<unsigned>() << 2U << 23U);
QCOMPARE(client.macroUsesLine().value("HEADER"), QList<unsigned>() << 5U);
QCOMPARE(client.macroUsesLine().value("DECLARE"), QList<unsigned>() << 9U);
QCOMPARE(client.macroUsesLine().value("NOTHING"), QList<unsigned>() << 13U);
QCOMPARE(client.macroUsesLine().value("ENABLE"), QList<unsigned>() << 18U << 22U << 23U);
QCOMPARE(client.macroUsesLine().value("ENABLE_COOL"), QList<unsigned>() << 21U);
QCOMPARE(client.expandedMacrosOffset(), QList<unsigned>()
<< buffer.lastIndexOf("FOO")
<< buffer.lastIndexOf("FOO\n")
<< buffer.lastIndexOf("HEADER")
<< buffer.lastIndexOf("DECLARE")
<< buffer.lastIndexOf("NOTHING")
<< buffer.lastIndexOf("ENABLE(COOL)")
<< buffer.lastIndexOf("ENABLE_COOL"));
<< buffer.lastIndexOf("ENABLE_COOL")
<< buffer.lastIndexOf("ENABLE(FEATURE)")
<< buffer.lastIndexOf("FOO ")
<< buffer.lastIndexOf("ENABLE(LESS)"));
}
void tst_Preprocessor::macro_definition_lineno()
......
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