forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user