summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpprefactoringchanges.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-10-28 11:10:34 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2020-11-02 09:08:21 +0000
commit76ae5780c4ada9a44e35103fcc1247ff2b7fc53d (patch)
tree630dd086e3d83170b92e2b19921782b3b70110a8 /src/plugins/cpptools/cpprefactoringchanges.cpp
parent0f786153f037f29c5dc2b746056e86b3fc64df4a (diff)
downloadqt-creator-76ae5780c4ada9a44e35103fcc1247ff2b7fc53d.tar.gz
CppTools: Fix function decl/def look-up
... in the presence of macros. For instance, renaming a parameter of a function preceded by some sort of DLL_EXPORT macro would not offer to apply the change to the definition, because the macro gets expanded and the respective tokens have bogus offsets derived from the place where the macro is defined. Luckily, such tokens are marked as "generated" and we can skip them for the purposes of retrieving the actual location of the function. Fixes: QTCREATORBUG-24739 Change-Id: If5db355b1c301060a17a687c2b5582fa1ef17d3f Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/cpptools/cpprefactoringchanges.cpp')
-rw-r--r--src/plugins/cpptools/cpprefactoringchanges.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/plugins/cpptools/cpprefactoringchanges.cpp b/src/plugins/cpptools/cpprefactoringchanges.cpp
index a86dd6451b..e0ca3111b9 100644
--- a/src/plugins/cpptools/cpprefactoringchanges.cpp
+++ b/src/plugins/cpptools/cpprefactoringchanges.cpp
@@ -227,7 +227,11 @@ int CppRefactoringFile::startOf(unsigned index) const
int CppRefactoringFile::startOf(const AST *ast) const
{
- return startOf(ast->firstToken());
+ int firstToken = ast->firstToken();
+ const int lastToken = ast->lastToken();
+ while (tokenAt(firstToken).generated() && firstToken < lastToken)
+ ++firstToken;
+ return startOf(firstToken);
}
int CppRefactoringFile::endOf(unsigned index) const
@@ -239,9 +243,12 @@ int CppRefactoringFile::endOf(unsigned index) const
int CppRefactoringFile::endOf(const AST *ast) const
{
- int end = ast->lastToken();
- QTC_ASSERT(end > 0, return -1);
- return endOf(end - 1);
+ int lastToken = ast->lastToken() - 1;
+ QTC_ASSERT(lastToken >= 0, return -1);
+ const int firstToken = ast->firstToken();
+ while (tokenAt(lastToken).generated() && lastToken > firstToken)
+ --lastToken;
+ return endOf(lastToken);
}
void CppRefactoringFile::startAndEndOf(unsigned index, int *start, int *end) const