diff options
author | Leandro Melo <leandro.melo@nokia.com> | 2012-01-20 14:43:21 +0100 |
---|---|---|
committer | Leandro Melo <leandro.melo@nokia.com> | 2012-01-23 11:34:44 +0100 |
commit | 466ea4842cf3c84d1aaf43e717cbc66838c63f14 (patch) | |
tree | d63cf59727eaeb1daee76de38055d0233561714e /src/plugins/cpptools/symbolfinder.h | |
parent | 271ec63a100681151c235d6d75e3121f3c22f4c7 (diff) |
C++: Improve file accuracy when finding symbols
This patch introduces a priority-based mechanism when searching for certains
symbols in the snapshot. The priority corresponds to how similar the file path
from the "reference" symbol is to the file path from the "candidate" symbol.
This solves a variety of issues when matching "equivalent" symbols but that
are in another file/project, such as when following a function declaration,
a forward class declaration, or adding a definition through a quickfix.
There's now a symbol finder which will compute the "best" search order and cache
the most recent results. A consequence is that following symbols in some cases
is slower, but not apparently significatly.
Note: The "find" functions were moved from the Snapshot to the new SymbolFinder
class.
Task-number: QTCREATORBUG-6697
Task-number: QTCREATORBUG-6792
Change-Id: Ia518f014275fec1f4d0cb3224bd4e06a9df6d557
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/plugins/cpptools/symbolfinder.h')
-rw-r--r-- | src/plugins/cpptools/symbolfinder.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/plugins/cpptools/symbolfinder.h b/src/plugins/cpptools/symbolfinder.h new file mode 100644 index 00000000000..80330e98c68 --- /dev/null +++ b/src/plugins/cpptools/symbolfinder.h @@ -0,0 +1,55 @@ +#ifndef SYMBOLFINDER_H +#define SYMBOLFINDER_H + +#include "cpptools_global.h" + +#include <CppDocument.h> +#include <CPlusPlusForwardDeclarations.h> + +#include <QtCore/QHash> +#include <QtCore/QStringList> +#include <QtCore/QQueue> +#include <QtCore/QMultiMap> + +namespace CppTools { + +class CPPTOOLS_EXPORT SymbolFinder +{ +public: + SymbolFinder(const QString &referenceFileName); + SymbolFinder(const char *referenceFileName, unsigned referenceFileLength); + + CPlusPlus::Symbol *findMatchingDefinition(CPlusPlus::Symbol *symbol, + const CPlusPlus::Snapshot &snapshot, + bool strict = false); + + CPlusPlus::Class *findMatchingClassDeclaration(CPlusPlus::Symbol *declaration, + const CPlusPlus::Snapshot &snapshot); + + void findMatchingDeclaration(const CPlusPlus::LookupContext &context, + CPlusPlus::Function *functionType, + QList<CPlusPlus::Declaration *> *typeMatch, + QList<CPlusPlus::Declaration *> *argumentCountMatch, + QList<CPlusPlus::Declaration *> *nameMatch); + + QList<CPlusPlus::Declaration *> findMatchingDeclaration(const CPlusPlus::LookupContext &context, + CPlusPlus::Function *functionType); + +private: + QStringList fileIterationOrder(const CPlusPlus::Snapshot &snapshot); + + void checkCacheConsistency(const CPlusPlus::Snapshot &snapshot); + void clear(const QString &comparingFile); + void insert(const QString &comparingFile); + + static int computeKey(const QString &referenceFile, const QString &comparingFile); + + QMultiMap<int, QString> m_filePriorityCache; + QSet<QString> m_fileMetaCache; + QString m_referenceFile; +}; + +} // namespace CppTools + +#endif // SYMBOLFINDER_H + |