diff options
author | Leandro Melo <leandro.melo@nokia.com> | 2012-05-29 12:37:55 +0200 |
---|---|---|
committer | hjk <qthjk@ovi.com> | 2012-06-01 14:28:03 +0200 |
commit | ca7ac8c0358efb0067c47f3135b22f26ea66b2a1 (patch) | |
tree | efcd1f3be7736c2a2da80ed038830770939388a3 /tests/auto/cplusplus/preprocessor | |
parent | 356d5cab238faa942efd6f8ed1dcd129ecebbc9d (diff) | |
download | qt-creator-ca7ac8c0358efb0067c47f3135b22f26ea66b2a1.tar.gz |
C++: Fix macro uses line info
Make sure the environment line is consistent during preprocessor
directives and identifier handling so clients can rely on consistent
information. Particularly important for macro usages.
New tests also added.
Change-Id: I962a39a86cd17b8d945d2959c2c95e2d258ea3e6
Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'tests/auto/cplusplus/preprocessor')
-rw-r--r-- | tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp index a6775f6b6b..0dc116072d 100644 --- a/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp +++ b/tests/auto/cplusplus/preprocessor/tst_preprocessor.cpp @@ -32,6 +32,7 @@ #include <QtTest> #include <pp.h> +#include <QHash> //TESTED_COMPONENT=src/libs/cplusplus using namespace CPlusPlus; @@ -117,13 +118,14 @@ public: virtual void failedMacroDefinitionCheck(unsigned /*offset*/, const ByteArrayRef &/*name*/) {} virtual void startExpandingMacro(unsigned offset, - const Macro &/*macro*/, + const Macro ¯o, const ByteArrayRef &originalText, const QVector<MacroArgumentReference> &/*actuals*/ = QVector<MacroArgumentReference>()) { m_expandedMacros.append(QByteArray(originalText.start(), originalText.length())); m_expandedMacrosOffset.append(offset); + m_macroUsesLine.insert(macro.name(), m_env->currentLine); } virtual void stopExpandingMacro(unsigned /*offset*/, const Macro &/*macro*/) {} @@ -227,6 +229,9 @@ public: QList<unsigned> definedMacrosLine() const { return m_definedMacrosLine; } + QHash<QByteArray, unsigned> macroUsesLine() const + { return m_macroUsesLine; } + private: Environment *m_env; QByteArray *m_output; @@ -239,6 +244,7 @@ private: QList<unsigned> m_expandedMacrosOffset; QList<QByteArray> m_definedMacros; QList<unsigned> m_definedMacrosLine; + QHash<QByteArray, unsigned> m_macroUsesLine; }; QT_BEGIN_NAMESPACE @@ -304,6 +310,7 @@ private slots: void objmacro_expanding_as_fnmacro_notification(); void macro_definition_lineno(); void macro_uses(); + void macro_uses_lines(); void macro_arguments_notificatin(); void unfinished_function_like_macro_call(); void nasty_macro_expansion(); @@ -466,6 +473,51 @@ void tst_Preprocessor::macro_uses() QCOMPARE(client.definedMacrosLine(), QList<unsigned>() << 2 << 3); } +void tst_Preprocessor::macro_uses_lines() +{ + QByteArray buffer("#define FOO\n" + "FOO\n" + "\n" + "#define HEADER <test>\n" + "#include HEADER\n" + "\n" + "#define DECLARE(C, V) struct C {}; C V;\n" + "#define ABC X\n" + "DECLARE(Test, test)\n" + "\n" + "int abc;\n" + "#define NOTHING(C)\n" + "NOTHING(abc)\n" + "\n" + "#define ENABLE(FEATURE) (defined ENABLE_##FEATURE && ENABLE_##FEATURE)\n" + "#define ENABLE_COOL 1\n" + "void fill();\n" + "#if ENABLE(COOL)\n" + "class Cool {};\n" + "#endif\n" + "int cool = ENABLE_COOL;\n"); + + QByteArray output; + Environment env; + MockClient client(&env, &output); + 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.expandedMacrosOffset(), QList<unsigned>() + << buffer.lastIndexOf("FOO") + << buffer.lastIndexOf("HEADER") + << buffer.lastIndexOf("DECLARE") + << buffer.lastIndexOf("NOTHING") + << buffer.lastIndexOf("ENABLE(COOL)") + << buffer.lastIndexOf("ENABLE_COOL")); +} + void tst_Preprocessor::macro_definition_lineno() { Client *client = 0; // no client. |