Commit c6ca15dc authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

C++: Record macro uses in #if defined(MACRO)

Change-Id: I4d99053f540073483c16ce842426bf8cd3def421
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent b41b25a3
......@@ -829,8 +829,11 @@ void Preprocessor::handleDefined(PPToken *tk)
pushToken(tk);
QByteArray result(1, '0');
if (m_env->resolve(idToken.asByteArrayRef()))
const ByteArrayRef macroName = idToken.asByteArrayRef();
if (macroDefinition(macroName, idToken.offset + m_state.m_offsetRef,
idToken.lineno, m_env, m_client)) {
result[0] = '1';
}
*tk = generateToken(T_NUMERIC_LITERAL, result.constData(), result.size(), lineno, false);
}
......
......@@ -588,6 +588,7 @@ void tst_Preprocessor::macro_uses_lines()
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.definitionsResolvedFromLines().value("ENABLE_COOL"), QList<unsigned>() << 18U);
QCOMPARE(client.expandedMacrosOffset(), QList<unsigned>()
<< buffer.lastIndexOf("FOO\n")
<< buffer.lastIndexOf("HEADER")
......@@ -1098,13 +1099,19 @@ void tst_Preprocessor::defined_usage()
"#endif\n"
"#ifndef ABSENT2\n"
"#endif\n"
"#if defined(ABSENT3)\n"
"#endif\n"
"#if defined(X)\n"
"#endif\n"
"#if defined(X) || defined(Y)\n"
"#endif\n"
;
pp.run(QLatin1String("<stdin>"), source);
QHash<QByteArray, QList<unsigned> > definitionsResolvedFromLines =
client.definitionsResolvedFromLines();
QCOMPARE(definitionsResolvedFromLines["X"], QList<unsigned>() << 3 << 7);
QCOMPARE(definitionsResolvedFromLines["Y"], QList<unsigned>() << 5 << 9);
QCOMPARE(client.unresolvedDefines(), QSet<QByteArray>() << "ABSENT" << "ABSENT2");
QCOMPARE(definitionsResolvedFromLines["X"], QList<unsigned>() << 3 << 7 << 17 << 19);
QCOMPARE(definitionsResolvedFromLines["Y"], QList<unsigned>() << 5 << 9 << 19);
QCOMPARE(client.unresolvedDefines(), QSet<QByteArray>() << "ABSENT" << "ABSENT2" << "ABSENT3");
}
void tst_Preprocessor::dont_eagerly_expand_data()
......
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