Clang: Use built-in follow symbol for virtual methods

ClangCodeModel currently does not provide a list of overrides.
Therefore it makes sense to use ClangCodeModel result for
virtual method only if built-in code model does not find anything.

Task-number: QTCREATORBUG-20584
Change-Id: I5b4fac7974f990e741d3438ab61827670a8ce8d8
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Ivan Donchevskii
2018-06-07 14:23:07 +02:00
parent 75cda95039
commit e1111d4570
7 changed files with 18 additions and 17 deletions

View File

@@ -33,7 +33,7 @@ QDebug operator<<(QDebug debug, const FollowSymbolResult &result)
{ {
debug.nospace() << "FollowSymbolResult(" debug.nospace() << "FollowSymbolResult("
<< result.range << result.range
<< ", " << result.isPureDeclarationForUsage; << ", " << result.isResultOnlyForFallBack;
debug.nospace() << ")"; debug.nospace() << ")";

View File

@@ -40,15 +40,15 @@ public:
FollowSymbolResult(SourceRangeContainer range) FollowSymbolResult(SourceRangeContainer range)
: range(std::move(range)) : range(std::move(range))
{} {}
FollowSymbolResult(SourceRangeContainer range, bool isPureDeclarationForUsage) FollowSymbolResult(SourceRangeContainer range, bool isResultOnlyForFallBack)
: range(std::move(range)) : range(std::move(range))
, isPureDeclarationForUsage(isPureDeclarationForUsage) , isResultOnlyForFallBack(isResultOnlyForFallBack)
{} {}
friend QDataStream &operator<<(QDataStream &out, const FollowSymbolResult &container) friend QDataStream &operator<<(QDataStream &out, const FollowSymbolResult &container)
{ {
out << container.range; out << container.range;
out << container.isPureDeclarationForUsage; out << container.isResultOnlyForFallBack;
return out; return out;
} }
@@ -56,7 +56,7 @@ public:
friend QDataStream &operator>>(QDataStream &in, FollowSymbolResult &container) friend QDataStream &operator>>(QDataStream &in, FollowSymbolResult &container)
{ {
in >> container.range; in >> container.range;
in >> container.isPureDeclarationForUsage; in >> container.isResultOnlyForFallBack;
return in; return in;
} }
@@ -64,11 +64,11 @@ public:
friend bool operator==(const FollowSymbolResult &first, const FollowSymbolResult &second) friend bool operator==(const FollowSymbolResult &first, const FollowSymbolResult &second)
{ {
return first.range == second.range return first.range == second.range
&& first.isPureDeclarationForUsage == second.isPureDeclarationForUsage; && first.isResultOnlyForFallBack == second.isResultOnlyForFallBack;
} }
SourceRangeContainer range; SourceRangeContainer range;
bool isPureDeclarationForUsage = false; bool isResultOnlyForFallBack = false;
}; };
class FollowSymbolMessage class FollowSymbolMessage

View File

@@ -265,7 +265,7 @@ CppTools::SymbolInfo toSymbolInfo(const FollowSymbolMessage &message)
result.endColumn = static_cast<int>(end.column); result.endColumn = static_cast<int>(end.column);
result.fileName = start.filePath; result.fileName = start.filePath;
result.isPureDeclarationForUsage = message.result.isPureDeclarationForUsage; result.isResultOnlyForFallBack = message.result.isResultOnlyForFallBack;
return result; return result;
} }

View File

@@ -145,7 +145,7 @@ static ::Utils::ProcessLinkCallback extendedCallback(::Utils::ProcessLinkCallbac
{ {
// If globalFollowSymbol finds nothing follow to the declaration. // If globalFollowSymbol finds nothing follow to the declaration.
return [original_callback = std::move(callback), result](const ::Utils::Link &link) { return [original_callback = std::move(callback), result](const ::Utils::Link &link) {
if (!link.hasValidTarget() && result.isPureDeclarationForUsage) { if (link.linkTextStart < 0 && result.isResultOnlyForFallBack) {
return original_callback(::Utils::Link(result.fileName, result.startLine, return original_callback(::Utils::Link(result.fileName, result.startLine,
result.startColumn - 1)); result.startColumn - 1));
} }
@@ -198,7 +198,7 @@ void ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data,
return callback(Utils::Link()); return callback(Utils::Link());
CppTools::SymbolInfo result = m_watcher->result(); CppTools::SymbolInfo result = m_watcher->result();
// We did not fail but the result is empty // We did not fail but the result is empty
if (result.fileName.isEmpty() || result.isPureDeclarationForUsage) { if (result.fileName.isEmpty() || result.isResultOnlyForFallBack) {
const CppTools::RefactoringEngineInterface &refactoringEngine const CppTools::RefactoringEngineInterface &refactoringEngine
= *CppTools::CppModelManager::instance(); = *CppTools::CppModelManager::instance();
refactoringEngine.globalFollowSymbol(data, refactoringEngine.globalFollowSymbol(data,

View File

@@ -39,7 +39,7 @@ public:
int endLine = 0; int endLine = 0;
int endColumn = 0; int endColumn = 0;
QString fileName; QString fileName;
bool isPureDeclarationForUsage = false; bool isResultOnlyForFallBack = false;
}; };
} // namespace CppTools } // namespace CppTools

View File

@@ -152,14 +152,15 @@ FollowSymbolResult FollowSymbol::followSymbol(CXTranslationUnit tu,
if (!cursor.isDeclaration()) { if (!cursor.isDeclaration()) {
// This is the symbol usage // This is the symbol usage
// We want to return definition // We want to return definition
FollowSymbolResult result;
cursor = cursor.referenced(); cursor = cursor.referenced();
if (cursor.isNull()) if (cursor.isNull())
return SourceRangeContainer(); return SourceRangeContainer();
if (!cursor.isDefinition()) {
// We can't find definition in this TU FollowSymbolResult result;
result.isPureDeclarationForUsage = true; // We can't find definition in this TU or it's a virtual method call
} if (!cursor.isDefinition() || cursor.isVirtualMethod())
result.isResultOnlyForFallBack = true;
result.range = extractMatchingTokenRange(cursor, tokenSpelling); result.range = extractMatchingTokenRange(cursor, tokenSpelling);
return result; return result;
} }

View File

@@ -241,7 +241,7 @@ std::ostream &operator<<(std::ostream &os, const FollowSymbolResult &result)
{ {
os << "(" os << "("
<< result.range << result.range
<< ", " << result.isPureDeclarationForUsage << ", " << result.isResultOnlyForFallBack
<< ")"; << ")";
return os; return os;