diff options
author | Erik Verbruggen <erik.verbruggen@nokia.com> | 2012-03-14 10:25:55 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@nokia.com> | 2012-03-14 11:46:24 +0100 |
commit | f1b2100e34c46c5102a584dfc70f2f89196b16d8 (patch) | |
tree | 7936e0ca57dd1e917820c4f962556ca1fea309a7 /src/libs/cplusplus | |
parent | b7304e2f2e533b767bcd1c02d8403e3d5fa63ddd (diff) | |
download | qt-creator-f1b2100e34c46c5102a584dfc70f2f89196b16d8.tar.gz |
Move the ModelManagerInterface out of the CPlusPlus library.
Change-Id: Iffaa18f848a22f6961b49dff048672b194570df6
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/libs/cplusplus')
-rw-r--r-- | src/libs/cplusplus/ModelManagerInterface.cpp | 99 | ||||
-rw-r--r-- | src/libs/cplusplus/ModelManagerInterface.h | 239 | ||||
-rw-r--r-- | src/libs/cplusplus/TypeHierarchyBuilder.cpp | 204 | ||||
-rw-r--r-- | src/libs/cplusplus/TypeHierarchyBuilder.h | 83 | ||||
-rw-r--r-- | src/libs/cplusplus/cplusplus-lib.pri | 8 |
5 files changed, 2 insertions, 631 deletions
diff --git a/src/libs/cplusplus/ModelManagerInterface.cpp b/src/libs/cplusplus/ModelManagerInterface.cpp deleted file mode 100644 index 18443186df..0000000000 --- a/src/libs/cplusplus/ModelManagerInterface.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#include "ModelManagerInterface.h" - -#include <QtCore/QSet> - -using namespace CPlusPlus; - -static CppModelManagerInterface *g_instance = 0; - -CppModelManagerInterface::CppModelManagerInterface(QObject *parent) - : QObject(parent) -{ - Q_ASSERT(! g_instance); - g_instance = this; -} - -CppModelManagerInterface::~CppModelManagerInterface() -{ - Q_ASSERT(g_instance == this); - g_instance = 0; -} - -CppModelManagerInterface *CppModelManagerInterface::instance() -{ - return g_instance; -} - - -void CppModelManagerInterface::ProjectInfo::clearProjectParts() -{ - m_projectParts.clear(); - m_includePaths.clear(); - m_frameworkPaths.clear(); - m_sourceFiles.clear(); - m_defines.clear(); -} - -void CppModelManagerInterface::ProjectInfo::appendProjectPart( - const CppModelManagerInterface::ProjectPart::Ptr &part) -{ - if (!part) - return; - - m_projectParts.append(part); - - // update include paths - QSet<QString> incs = QSet<QString>::fromList(m_includePaths); - foreach (const QString &ins, part->includePaths) - incs.insert(ins); - m_includePaths = incs.toList(); - - // update framework paths - QSet<QString> frms = QSet<QString>::fromList(m_frameworkPaths); - foreach (const QString &frm, part->frameworkPaths) - frms.insert(frm); - m_frameworkPaths = frms.toList(); - - // update source files - QSet<QString> srcs = QSet<QString>::fromList(m_sourceFiles); - foreach (const QString &src, part->sourceFiles) - srcs.insert(src); - m_sourceFiles = srcs.toList(); - - // update defines - if (!m_defines.isEmpty()) - m_defines.append('\n'); - m_defines.append(part->defines); -} diff --git a/src/libs/cplusplus/ModelManagerInterface.h b/src/libs/cplusplus/ModelManagerInterface.h deleted file mode 100644 index fdcfa7a66d..0000000000 --- a/src/libs/cplusplus/ModelManagerInterface.h +++ /dev/null @@ -1,239 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#ifndef CPPMODELMANAGERINTERFACE_H -#define CPPMODELMANAGERINTERFACE_H - -#include <cplusplus/CppDocument.h> -#include <languageutils/fakemetaobject.h> -#include <projectexplorer/project.h> -#include <projectexplorer/toolchain.h> - -#include <QObject> -#include <QHash> -#include <QPointer> -#include <QStringList> -#include <QFuture> - -namespace Core { - class IEditor; -} - -namespace CPlusPlus { - class LookupContext; -} - -namespace ProjectExplorer { - class Project; -} - -namespace CppTools { - class AbstractEditorSupport; - class CppCompletionSupport; - class CppCompletionAssistProvider; - class CppHighlightingSupport; - class CppHighlightingSupportFactory; -} - -namespace CPlusPlus { - -class CPLUSPLUS_EXPORT CppModelManagerInterface : public QObject -{ - Q_OBJECT - -public: - enum Language { CXX, OBJC }; - - class CPLUSPLUS_EXPORT ProjectPart - { - public: - ProjectPart() - : qtVersion(UnknownQt) - {} - - public: //attributes - QStringList sourceFiles; - QByteArray defines; - QStringList includePaths; - QStringList frameworkPaths; - QStringList precompiledHeaders; - Language language; - ProjectExplorer::ToolChain::CompilerFlags flags; - enum QtVersion { - UnknownQt = -1, - NoQt = 0, - Qt4 = 1, - Qt5 = 2 - }; - QtVersion qtVersion; - - bool cpp0xEnabled() const - { return flags == ProjectExplorer::ToolChain::STD_CXX11; } - - bool objcEnabled() const - { return language == CppModelManagerInterface::OBJC; } - - typedef QSharedPointer<ProjectPart> Ptr; - }; - - class CPLUSPLUS_EXPORT ProjectInfo - { - public: - ProjectInfo() - { } - - ProjectInfo(QWeakPointer<ProjectExplorer::Project> project) - : m_project(project) - { } - - operator bool() const - { return ! m_project.isNull(); } - - bool isValid() const - { return ! m_project.isNull(); } - - bool isNull() const - { return m_project.isNull(); } - - QWeakPointer<ProjectExplorer::Project> project() const - { return m_project; } - - const QList<ProjectPart::Ptr> projectParts() const - { return m_projectParts; } - - void clearProjectParts(); - void appendProjectPart(const ProjectPart::Ptr &part); - - const QStringList includePaths() const - { return m_includePaths; } - - const QStringList frameworkPaths() const - { return m_frameworkPaths; } - - const QStringList sourceFiles() const - { return m_sourceFiles; } - - const QByteArray defines() const - { return m_defines; } - - private: // attributes - QWeakPointer<ProjectExplorer::Project> m_project; - QList<ProjectPart::Ptr> m_projectParts; - // the attributes below are calculated from the project parts. - QStringList m_includePaths; - QStringList m_frameworkPaths; - QStringList m_sourceFiles; - QByteArray m_defines; - }; - - class CPLUSPLUS_EXPORT WorkingCopy - { - public: - void insert(const QString &fileName, const QString &source, unsigned revision = 0) - { _elements.insert(fileName, qMakePair(source, revision)); } - - bool contains(const QString &fileName) const - { return _elements.contains(fileName); } - - QString source(const QString &fileName) const - { return _elements.value(fileName).first; } - - QPair<QString, unsigned> get(const QString &fileName) const - { return _elements.value(fileName); } - - QHashIterator<QString, QPair<QString, unsigned> > iterator() const - { return QHashIterator<QString, QPair<QString, unsigned> >(_elements); } - - private: - typedef QHash<QString, QPair<QString, unsigned> > Table; - Table _elements; - }; - - enum ExtraDiagnosticKind - { - AllExtraDiagnostics = -1, - ExportedQmlTypesDiagnostic - }; - -public: - CppModelManagerInterface(QObject *parent = 0); - virtual ~CppModelManagerInterface(); - - static CppModelManagerInterface *instance(); - - virtual bool isCppEditor(Core::IEditor *editor) const = 0; - - virtual WorkingCopy workingCopy() const = 0; - virtual CPlusPlus::Snapshot snapshot() const = 0; - - virtual QList<ProjectInfo> projectInfos() const = 0; - virtual ProjectInfo projectInfo(ProjectExplorer::Project *project) const = 0; - virtual void updateProjectInfo(const ProjectInfo &pinfo) = 0; - virtual QList<ProjectPart::Ptr> projectPart(const QString &fileName) const = 0; - - virtual void addEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0; - virtual void removeEditorSupport(CppTools::AbstractEditorSupport *editorSupport) = 0; - - virtual QList<int> references(CPlusPlus::Symbol *symbol, - const CPlusPlus::LookupContext &context) = 0; - - virtual void renameUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context, - const QString &replacement = QString()) = 0; - virtual void findUsages(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context) = 0; - - virtual void findMacroUsages(const CPlusPlus::Macro ¯o) = 0; - - virtual void setExtraDiagnostics(const QString &fileName, int key, - const QList<CPlusPlus::Document::DiagnosticMessage> &diagnostics) = 0; - virtual QList<CPlusPlus::Document::DiagnosticMessage> extraDiagnostics( - const QString &fileName, int key = AllExtraDiagnostics) const = 0; - - virtual CppTools::CppCompletionSupport *completionSupport(Core::IEditor *editor) const = 0; - virtual void setCppCompletionAssistProvider(CppTools::CppCompletionAssistProvider *completionAssistProvider) = 0; - - virtual CppTools::CppHighlightingSupport *highlightingSupport(Core::IEditor *editor) const = 0; - virtual void setHighlightingSupportFactory(CppTools::CppHighlightingSupportFactory *highlightingFactory) = 0; - -Q_SIGNALS: - void documentUpdated(CPlusPlus::Document::Ptr doc); - void sourceFilesRefreshed(const QStringList &files); - void extraDiagnosticsUpdated(QString fileName); - -public Q_SLOTS: - virtual void updateModifiedSourceFiles() = 0; - virtual QFuture<void> updateSourceFiles(const QStringList &sourceFiles) = 0; - virtual void GC() = 0; -}; - -} // namespace CPlusPlus - -#endif // CPPMODELMANAGERINTERFACE_H diff --git a/src/libs/cplusplus/TypeHierarchyBuilder.cpp b/src/libs/cplusplus/TypeHierarchyBuilder.cpp deleted file mode 100644 index 73eba4dc85..0000000000 --- a/src/libs/cplusplus/TypeHierarchyBuilder.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#include "TypeHierarchyBuilder.h" -#include "FindUsages.h" -#include "Symbols.h" -#include "SymbolVisitor.h" -#include "DependencyTable.h" -#include "CppDocument.h" -#include "Literals.h" -#include "TranslationUnit.h" -#include "CoreTypes.h" - -using namespace CPlusPlus; - -namespace { - -QString unqualifyName(const QString &qualifiedName) -{ - const int index = qualifiedName.lastIndexOf(QLatin1String("::")); - if (index == -1) - return qualifiedName; - return qualifiedName.right(qualifiedName.length() - index - 2); -} - -class DerivedHierarchyVisitor : public SymbolVisitor -{ -public: - DerivedHierarchyVisitor(const QString &qualifiedName) - : _qualifiedName(qualifiedName) - , _unqualifiedName(unqualifyName(qualifiedName)) - {} - - void execute(const Document::Ptr &doc, const Snapshot &snapshot); - - virtual bool visit(Class *); - - const QList<Symbol *> &derived() { return _derived; } - const QStringList otherBases() { return _otherBases; } - -private: - LookupContext _context; - QString _qualifiedName; - QString _unqualifiedName; - Overview _overview; - QHash<Symbol *, QString> _actualBases; - QStringList _otherBases; - QList<Symbol *> _derived; -}; - -void DerivedHierarchyVisitor::execute(const Document::Ptr &doc, const Snapshot &snapshot) -{ - _derived.clear(); - _otherBases.clear(); - _context = LookupContext(doc, snapshot); - - for (unsigned i = 0; i < doc->globalSymbolCount(); ++i) - accept(doc->globalSymbolAt(i)); -} - -bool DerivedHierarchyVisitor::visit(Class *symbol) -{ - for (unsigned i = 0; i < symbol->baseClassCount(); ++i) { - BaseClass *baseSymbol = symbol->baseClassAt(i); - - QString baseName = _actualBases.value(baseSymbol); - if (baseName.isEmpty()) { - QList<LookupItem> items = _context.lookup(baseSymbol->name(), symbol->enclosingScope()); - if (items.isEmpty() || !items.first().declaration()) - continue; - - Symbol *actualBaseSymbol = items.first().declaration(); - if (actualBaseSymbol->isTypedef()) { - NamedType *namedType = actualBaseSymbol->type()->asNamedType(); - if (!namedType) { - // Anonymous aggregate such as: typedef struct {} Empty; - continue; - } - const QString &typeName = _overview.prettyName(namedType->name()); - if (typeName == _unqualifiedName || typeName == _qualifiedName) { - items = _context.lookup(namedType->name(), actualBaseSymbol->enclosingScope()); - if (items.isEmpty() || !items.first().declaration()) - continue; - actualBaseSymbol = items.first().declaration(); - } - } - - const QList<const Name *> &full = LookupContext::fullyQualifiedName(actualBaseSymbol); - baseName = _overview.prettyName(full); - _actualBases.insert(baseSymbol, baseName); - } - - if (_qualifiedName == baseName) - _derived.append(symbol); - else - _otherBases.append(baseName); - } - - return true; -} - -} - -TypeHierarchy::TypeHierarchy() : _symbol(0) -{} - -TypeHierarchy::TypeHierarchy(Symbol *symbol) : _symbol(symbol) -{} - -Symbol *TypeHierarchy::symbol() const -{ - return _symbol; -} - -const QList<TypeHierarchy> &TypeHierarchy::hierarchy() const -{ - return _hierarchy; -} - -TypeHierarchyBuilder::TypeHierarchyBuilder(Symbol *symbol, const Snapshot &snapshot) - : _symbol(symbol) - , _snapshot(snapshot) - , _dependencies(QString::fromUtf8(symbol->fileName(), symbol->fileNameLength())) -{ - DependencyTable dependencyTable; - dependencyTable.build(_snapshot); - _dependencies.append(dependencyTable.filesDependingOn(_dependencies.first())); -} - -void TypeHierarchyBuilder::reset() -{ - _visited.clear(); - _candidates.clear(); -} - -TypeHierarchy TypeHierarchyBuilder::buildDerivedTypeHierarchy() -{ - reset(); - TypeHierarchy hierarchy(_symbol); - buildDerived(&hierarchy); - return hierarchy; -} - -void TypeHierarchyBuilder::buildDerived(TypeHierarchy *typeHierarchy) -{ - Symbol *symbol = typeHierarchy->_symbol; - if (_visited.contains(symbol)) - return; - - _visited.insert(symbol); - - const QString &symbolName = _overview.prettyName(LookupContext::fullyQualifiedName(symbol)); - DerivedHierarchyVisitor visitor(symbolName); - - foreach (const QString &fileName, _dependencies) { - Document::Ptr doc = _snapshot.document(fileName); - if ((_candidates.contains(fileName) && !_candidates.value(fileName).contains(symbolName)) - || !doc->control()->findIdentifier(symbol->identifier()->chars(), - symbol->identifier()->size())) { - continue; - } - - visitor.execute(doc, _snapshot); - _candidates.insert(fileName, QSet<QString>()); - - foreach (const QString &candidate, visitor.otherBases()) - _candidates[fileName].insert(candidate); - - foreach (Symbol *s, visitor.derived()) { - TypeHierarchy derivedHierarchy(s); - buildDerived(&derivedHierarchy); - typeHierarchy->_hierarchy.append(derivedHierarchy); - } - } -} diff --git a/src/libs/cplusplus/TypeHierarchyBuilder.h b/src/libs/cplusplus/TypeHierarchyBuilder.h deleted file mode 100644 index 1fd8a82016..0000000000 --- a/src/libs/cplusplus/TypeHierarchyBuilder.h +++ /dev/null @@ -1,83 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** -** GNU Lesser General Public License Usage -** -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this file. -** Please review the following information to ensure the GNU Lesser General -** Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** Other Usage -** -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -**************************************************************************/ - -#ifndef FINDDERIVEDCLASSES_H -#define FINDDERIVEDCLASSES_H - -#include "CppDocument.h" -#include "ModelManagerInterface.h" -#include "Overview.h" - -#include <QList> -#include <QStringList> -#include <QSet> - -namespace CPlusPlus { - -class CPLUSPLUS_EXPORT TypeHierarchy -{ - friend class TypeHierarchyBuilder; - -public: - TypeHierarchy(); - TypeHierarchy(Symbol *symbol); - - Symbol *symbol() const; - const QList<TypeHierarchy> &hierarchy() const; - -private: - Symbol *_symbol; - QList<TypeHierarchy> _hierarchy; -}; - -class CPLUSPLUS_EXPORT TypeHierarchyBuilder -{ -public: - TypeHierarchyBuilder(Symbol *symbol, const Snapshot &snapshot); - - TypeHierarchy buildDerivedTypeHierarchy(); - -private: - void reset(); - void buildDerived(TypeHierarchy *typeHierarchy); - - Symbol *_symbol; - Snapshot _snapshot; - QStringList _dependencies; - QSet<Symbol *> _visited; - QHash<QString, QSet<QString> > _candidates; - Overview _overview; -}; - -} // CPlusPlus - -#endif // FINDDERIVEDCLASSES_H diff --git a/src/libs/cplusplus/cplusplus-lib.pri b/src/libs/cplusplus/cplusplus-lib.pri index 57b2e2ffdf..a48a23d11b 100644 --- a/src/libs/cplusplus/cplusplus-lib.pri +++ b/src/libs/cplusplus/cplusplus-lib.pri @@ -53,9 +53,7 @@ HEADERS += \ $$PWD/pp-engine.h \ $$PWD/pp-macro-expander.h \ $$PWD/pp-scanner.h \ - $$PWD/ModelManagerInterface.h \ - $$PWD/findcdbbreakpoint.h \ - $$PWD/TypeHierarchyBuilder.h + $$PWD/findcdbbreakpoint.h SOURCES += \ $$PWD/SimpleLexer.cpp \ @@ -82,8 +80,6 @@ SOURCES += \ $$PWD/pp-engine.cpp \ $$PWD/pp-macro-expander.cpp \ $$PWD/pp-scanner.cpp \ - $$PWD/ModelManagerInterface.cpp \ - $$PWD/findcdbbreakpoint.cpp \ - $$PWD/TypeHierarchyBuilder.cpp + $$PWD/findcdbbreakpoint.cpp RESOURCES += $$PWD/cplusplus.qrc |