Created
July 26, 2021 11:54
-
-
Save DimanNe/02bfcf58cff2a73f0de87e34affb5f56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/plugins/cpptools/typehierarchybuilder.cpp b/src/plugins/cpptools/typehierarchybuilder.cpp | |
index 67f4e6a1ab..b60784ac4f 100644 | |
--- a/src/plugins/cpptools/typehierarchybuilder.cpp | |
+++ b/src/plugins/cpptools/typehierarchybuilder.cpp | |
@@ -30,10 +30,69 @@ | |
using namespace CPlusPlus; | |
using namespace CppTools; | |
+QString myToString(const CPlusPlus::Symbol *s) | |
+{ | |
+ QString str; | |
+ { | |
+ QTextStream out(&str); | |
+ if (s == nullptr) { | |
+ out << "nullptr symbol"; | |
+ } else { | |
+ out << s->sourceLocation() << " " << s->line() << " " << s->fileName(); | |
+ } | |
+ } | |
+ return str; | |
+} | |
+QString myToString(const TypeHierarchy *h) | |
+{ | |
+ QString str; | |
+ { | |
+ QTextStream out(&str); | |
+ if (h == nullptr) { | |
+ out << "nullptr TypeHierarchy"; | |
+ } else { | |
+ for (TypeHierarchy th : h->hierarchy()) | |
+ out << myToString(th.symbol()); | |
+ } | |
+ } | |
+ return str; | |
+} | |
+QString myToString(const Name *s) | |
+{ | |
+ QString str; | |
+ { | |
+ QTextStream out(&str); | |
+ if (s == nullptr) { | |
+ out << "nullptr Name"; | |
+ } else { | |
+ const Identifier *i = s->identifier(); | |
+ if (i == nullptr) | |
+ out << "nullptr i in symbolName"; | |
+ else | |
+ out << i->chars(); | |
+ } | |
+ } | |
+ return str; | |
+} | |
+QString myToString(const Document::Ptr &d) | |
+{ | |
+ QString str; | |
+ { | |
+ QTextStream out(&str); | |
+ if (d == nullptr) { | |
+ out << "nullptr doc"; | |
+ } else { | |
+ out << d->fileName(); | |
+ } | |
+ } | |
+ return str; | |
+} | |
+ | |
namespace { | |
QString unqualifyName(const QString &qualifiedName) | |
{ | |
+ qDebug() << "unqualifyName: qualifiedName: " << qualifiedName; | |
const int index = qualifiedName.lastIndexOf(QLatin1String("::")); | |
if (index == -1) | |
return qualifiedName; | |
@@ -43,7 +102,8 @@ QString unqualifyName(const QString &qualifiedName) | |
class DerivedHierarchyVisitor : public SymbolVisitor | |
{ | |
public: | |
- explicit DerivedHierarchyVisitor(const QString &qualifiedName, QHash<QString, QHash<QString, QString>> &cache) | |
+ explicit DerivedHierarchyVisitor(const QString &qualifiedName, | |
+ QHash<QString, QHash<QString, QString>> &cache) | |
: _qualifiedName(qualifiedName) | |
, _unqualifiedName(unqualifyName(qualifiedName)) | |
, _cache(cache) | |
@@ -69,9 +129,9 @@ private: | |
QList<Symbol *> _derived; | |
}; | |
-void DerivedHierarchyVisitor::execute(const Document::Ptr &doc, | |
- const Snapshot &snapshot) | |
+void DerivedHierarchyVisitor::execute(const Document::Ptr &doc, const Snapshot &snapshot) | |
{ | |
+ qDebug() << "DerivedHierarchyVisitor::execute: doc: " << myToString(doc); | |
_derived.clear(); | |
_otherBases.clear(); | |
_context = LookupContext(doc, snapshot); | |
@@ -82,8 +142,10 @@ void DerivedHierarchyVisitor::execute(const Document::Ptr &doc, | |
bool DerivedHierarchyVisitor::visit(Class *symbol) | |
{ | |
- const QList<const Name *> &fullScope | |
- = LookupContext::fullyQualifiedName(symbol->enclosingScope()); | |
+ qDebug() << "DerivedHierarchyVisitor::visit: symbol: " << myToString(symbol); | |
+ | |
+ const QList<const Name *> &fullScope = LookupContext::fullyQualifiedName( | |
+ symbol->enclosingScope()); | |
const QString fullScopeName = _overview.prettyName(fullScope); | |
for (int i = 0; i < symbol->baseClassCount(); ++i) { | |
@@ -93,12 +155,13 @@ bool DerivedHierarchyVisitor::visit(Class *symbol) | |
QString fullBaseName = _cache.value(fullScopeName).value(baseName); | |
if (fullBaseName.isEmpty()) { | |
Symbol *actualBaseSymbol = TypeHierarchyBuilder::followTypedef(_context, | |
- baseSymbol->name(), symbol->enclosingScope()).declaration(); | |
+ baseSymbol->name(), | |
+ symbol->enclosingScope()) | |
+ .declaration(); | |
if (!actualBaseSymbol) | |
continue; | |
- const QList<const Name *> &full | |
- = LookupContext::fullyQualifiedName(actualBaseSymbol); | |
+ const QList<const Name *> &full = LookupContext::fullyQualifiedName(actualBaseSymbol); | |
fullBaseName = _overview.prettyName(full); | |
_cache[fullScopeName].insert(baseName, fullBaseName); | |
} | |
@@ -115,7 +178,8 @@ bool DerivedHierarchyVisitor::visit(Class *symbol) | |
TypeHierarchy::TypeHierarchy() = default; | |
-TypeHierarchy::TypeHierarchy(Symbol *symbol) : _symbol(symbol) | |
+TypeHierarchy::TypeHierarchy(Symbol *symbol) | |
+ : _symbol(symbol) | |
{} | |
Symbol *TypeHierarchy::symbol() const | |
@@ -131,6 +195,7 @@ const QList<TypeHierarchy> &TypeHierarchy::hierarchy() const | |
TypeHierarchy TypeHierarchyBuilder::buildDerivedTypeHierarchy(Symbol *symbol, | |
const Snapshot &snapshot) | |
{ | |
+ qDebug() << "TypeHierarchyBuilder::buildDerivedTypeHierarchy 1: symbol: " << myToString(symbol); | |
QFutureInterfaceBase dummy; | |
return TypeHierarchyBuilder::buildDerivedTypeHierarchy(dummy, symbol, snapshot); | |
} | |
@@ -139,6 +204,7 @@ TypeHierarchy TypeHierarchyBuilder::buildDerivedTypeHierarchy(QFutureInterfaceBa | |
Symbol *symbol, | |
const Snapshot &snapshot) | |
{ | |
+ qDebug() << "TypeHierarchyBuilder::buildDerivedTypeHierarchy: symbol: " << myToString(symbol); | |
TypeHierarchy hierarchy(symbol); | |
TypeHierarchyBuilder builder; | |
QHash<QString, QHash<QString, QString>> cache; | |
@@ -146,8 +212,12 @@ TypeHierarchy TypeHierarchyBuilder::buildDerivedTypeHierarchy(QFutureInterfaceBa | |
return hierarchy; | |
} | |
-LookupItem TypeHierarchyBuilder::followTypedef(const LookupContext &context, const Name *symbolName, Scope *enclosingScope) | |
+LookupItem TypeHierarchyBuilder::followTypedef(const LookupContext &context, | |
+ const Name *symbolName, | |
+ Scope *enclosingScope) | |
{ | |
+ qDebug() << "TypeHierarchyBuilder::followTypedef: enclosingScope: " | |
+ << myToString(enclosingScope) << "symbolName: " << myToString(symbolName); | |
QList<LookupItem> items = context.lookup(symbolName, enclosingScope); | |
Symbol *actualBaseSymbol = nullptr; | |
@@ -179,14 +249,16 @@ LookupItem TypeHierarchyBuilder::followTypedef(const LookupContext &context, con | |
return matchingItem; | |
} | |
-static Utils::FilePaths filesDependingOn(const Snapshot &snapshot, | |
- Symbol *symbol) | |
+static Utils::FilePaths filesDependingOn(const Snapshot &snapshot, Symbol *symbol) | |
{ | |
+ qDebug() << "filesDependingOn: symbol: " << myToString(symbol); | |
+ | |
if (!symbol) | |
return Utils::FilePaths(); | |
- const Utils::FilePath file = Utils::FilePath::fromUtf8(symbol->fileName(), symbol->fileNameLength()); | |
- return Utils::FilePaths { file } + snapshot.filesDependingOn(file); | |
+ const Utils::FilePath file = Utils::FilePath::fromUtf8(symbol->fileName(), | |
+ symbol->fileNameLength()); | |
+ return Utils::FilePaths{file} + snapshot.filesDependingOn(file); | |
} | |
void TypeHierarchyBuilder::buildDerived(QFutureInterfaceBase &futureInterface, | |
@@ -195,6 +267,8 @@ void TypeHierarchyBuilder::buildDerived(QFutureInterfaceBase &futureInterface, | |
QHash<QString, QHash<QString, QString>> &cache, | |
int depth) | |
{ | |
+ qDebug() << "TypeHierarchyBuilder::buildDerived: typeHierarchy: " << myToString(typeHierarchy) | |
+ << "depth: " << depth; | |
Symbol *symbol = typeHierarchy->_symbol; | |
if (_visited.contains(symbol)) | |
return; | |
@@ -216,8 +290,8 @@ void TypeHierarchyBuilder::buildDerived(QFutureInterfaceBase &futureInterface, | |
futureInterface.setProgressValue(++i); | |
Document::Ptr doc = snapshot.document(fileName); | |
if ((_candidates.contains(fileName) && !_candidates.value(fileName).contains(symbolName)) | |
- || !doc->control()->findIdentifier(symbol->identifier()->chars(), | |
- symbol->identifier()->size())) { | |
+ || !doc->control()->findIdentifier(symbol->identifier()->chars(), | |
+ symbol->identifier()->size())) { | |
continue; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment