diff options
author | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-07-30 18:15:07 +0200 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-07-31 11:01:02 +0000 |
commit | 892cb154b2a781e9056d6754f3d24a3912d9ca17 (patch) | |
tree | a67d0581bc3f015f94a96584ffe51afd81a105b0 /tests | |
parent | e3fbe7e93a2ac7926b41ea0963ad12aaab0c0f00 (diff) | |
download | qt-creator-892cb154b2a781e9056d6754f3d24a3912d9ca17.tar.gz |
C++: Do not let ASTPath calculate line/column for generated tokens
ASTPath uses TranslationUnit::getPosition(), which returns reasonable
results for:
1. non-expanded tokens
2. expanded but not generated tokens
The expanded *and* generated tokens case is not handled since there is
no reasonable mapping from generated tokens to a continuous line/column
information. Consider:
#define DECLARE_FOO int foo; // Multiple generated tokens
DECLARE_FOO // ...can be mapped to this line, but to which columns?
Since the result where not valid for the expanded and generated case,
ASTPath took the wrong branches. Avoid this by skipping generated
tokens.
Change-Id: I33a2e0f62917f87d691b19feaeef67b09ea8d563
Task-number: QTCREATORBUG-13386
Task-number: QTCREATORBUG-13390
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/cplusplus/misc/tst_misc.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/cplusplus/misc/tst_misc.cpp b/tests/auto/cplusplus/misc/tst_misc.cpp index 70914ca42d..c349761396 100644 --- a/tests/auto/cplusplus/misc/tst_misc.cpp +++ b/tests/auto/cplusplus/misc/tst_misc.cpp @@ -28,6 +28,7 @@ ** ****************************************************************************/ +#include <cplusplus/ASTPath.h> #include <cplusplus/CppDocument.h> #include <cplusplus/findcdbbreakpoint.h> @@ -48,6 +49,8 @@ private slots: void findBreakpoints(); void findBreakpoints2(); void findBreakpoints3(); + + void astPathOnGeneratedTokens(); }; void tst_Misc::diagnosticClient_error() @@ -202,5 +205,44 @@ void tst_Misc::findBreakpoints3() QCOMPARE(findBreakpoint(7), 7U); } +static Document::Ptr documentCreatedWithFastPreprocessor(const QByteArray source) +{ + Snapshot snapshot; + auto document = snapshot.preprocessedDocument(source, QLatin1String("test.cpp")); + document->check(); + return document; +} + +void tst_Misc::astPathOnGeneratedTokens() +{ + const QByteArray source = + "#define INT int\n" + "#define S ;\n" + "INT x S\n"; + const auto document = documentCreatedWithFastPreprocessor(source); + ASTPath astPath(document); + + // Check start + auto paths = astPath(3, 1); + QCOMPARE(paths.size(), 0); + + // Check middle + paths = astPath(3, 5); + QCOMPARE(paths.size(), 5); + QVERIFY(paths.at(0)->asTranslationUnit()); + QVERIFY(paths.at(1)->asSimpleDeclaration()); + QVERIFY(paths.at(2)->asDeclarator()); + QVERIFY(paths.at(3)->asDeclaratorId()); + QVERIFY(paths.at(4)->asSimpleName()); + + // Check end + for (auto i : { 7, 8, 9 }) { + paths = astPath(3, i); + QCOMPARE(paths.size(), 2); + QVERIFY(paths.at(0)->asTranslationUnit()); + QVERIFY(paths.at(1)->asSimpleDeclaration()); + } +} + QTEST_MAIN(tst_Misc) #include "tst_misc.moc" |