From c6ca15dc15883ca4e58b46bf5e4a96645ab2350f Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sat, 22 Feb 2014 21:34:07 +0200 Subject: [PATCH] C++: Record macro uses in #if defined(MACRO) Change-Id: I4d99053f540073483c16ce842426bf8cd3def421 Reviewed-by: Nikolai Kosjar --- src/libs/cplusplus/pp-engine.cpp | 5 ++++- .../cplusplus/preprocessor/tst_preprocessor.cpp | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index d7f327f3e76..f001be2c69d 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -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); } diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index 808bd75a007..720bd1ea11b 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -588,6 +588,7 @@ void tst_Preprocessor::macro_uses_lines() QCOMPARE(client.macroUsesLine().value("NOTHING"), QList() << 13U); QCOMPARE(client.macroUsesLine().value("ENABLE"), QList() << 18U << 22U << 23U); QCOMPARE(client.macroUsesLine().value("ENABLE_COOL"), QList() << 21U); + QCOMPARE(client.definitionsResolvedFromLines().value("ENABLE_COOL"), QList() << 18U); QCOMPARE(client.expandedMacrosOffset(), QList() << 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(""), source); QHash > definitionsResolvedFromLines = client.definitionsResolvedFromLines(); - QCOMPARE(definitionsResolvedFromLines["X"], QList() << 3 << 7); - QCOMPARE(definitionsResolvedFromLines["Y"], QList() << 5 << 9); - QCOMPARE(client.unresolvedDefines(), QSet() << "ABSENT" << "ABSENT2"); + QCOMPARE(definitionsResolvedFromLines["X"], QList() << 3 << 7 << 17 << 19); + QCOMPARE(definitionsResolvedFromLines["Y"], QList() << 5 << 9 << 19); + QCOMPARE(client.unresolvedDefines(), QSet() << "ABSENT" << "ABSENT2" << "ABSENT3"); } void tst_Preprocessor::dont_eagerly_expand_data()