diff --git a/src/plugins/cpptools/cppsemanticsearch.cpp b/src/plugins/cpptools/cppsemanticsearch.cpp deleted file mode 100644 index bc8510625bbe0c834a5dc61d802896a890ff441e..0000000000000000000000000000000000000000 --- a/src/plugins/cpptools/cppsemanticsearch.cpp +++ /dev/null @@ -1,314 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#include "cppsemanticsearch.h" -#include "cppmodelmanager.h" - -#include <AST.h> -#include <Literals.h> -#include <TranslationUnit.h> - -#include <QtCore/QDir> -#include <QtCore/QPointer> -#include <QtCore/QtConcurrentRun> -#include <QtCore/QFutureSynchronizer> -#include <qtconcurrent/runextensions.h> - -using namespace CppTools::Internal; -using namespace CPlusPlus; - -namespace { - -class SearchClass: public SemanticSearch -{ - QString _text; - QTextDocument::FindFlags _findFlags; - -public: - SearchClass(QFutureInterface<Utils::FileSearchResult> &future, - Document::Ptr doc, Snapshot snapshot) - : SemanticSearch(future, doc, snapshot) - { } - - void setText(const QString &text) - { _text = text; } - - void setFindFlags(QTextDocument::FindFlags findFlags) - { _findFlags = findFlags; } - - virtual void run(AST *ast) - { accept(ast); } - -protected: - using ASTVisitor::visit; - - bool match(NameAST *name) - { - if (! name) - return false; - - else if (SimpleNameAST *simpleName = name->asSimpleName()) { - if (Identifier *id = identifier(simpleName->identifier_token)) { - Qt::CaseSensitivity cs = Qt::CaseInsensitive; - - if (_findFlags & QTextDocument::FindCaseSensitively) - cs = Qt::CaseSensitive; - - QString s = QString::fromUtf8(id->chars(), id->size()); - int index = s.indexOf(_text, 0, cs); - if (index != -1) { - reportResult(simpleName->identifier_token, index, _text.length()); - return true; - } - } - } - - else if (QualifiedNameAST *q = name->asQualifiedName()) { - return match(q->unqualified_name); - } - - return false; - } - - virtual bool visit(ElaboratedTypeSpecifierAST *ast) - { - if (tokenKind(ast->classkey_token) != T_ENUM) { - match(ast->name); - } - - return true; - } - - virtual bool visit(ClassSpecifierAST *ast) - { - match(ast->name); - return true; - } -}; - -class SearchFunctionCall: public SemanticSearch -{ - QString _text; - QTextDocument::FindFlags _findFlags; - -public: - SearchFunctionCall(QFutureInterface<Utils::FileSearchResult> &future, - Document::Ptr doc, Snapshot snapshot) - : SemanticSearch(future, doc, snapshot) - { } - - void setText(const QString &text) - { _text = text; } - - void setFindFlags(QTextDocument::FindFlags findFlags) - { _findFlags = findFlags; } - - virtual void run(AST *ast) - { accept(ast); } - -protected: - using ASTVisitor::visit; - - bool match(NameAST *name) - { - if (! name) - return false; - - else if (SimpleNameAST *simpleName = name->asSimpleName()) { - if (Identifier *id = identifier(simpleName->identifier_token)) { - Qt::CaseSensitivity cs = Qt::CaseInsensitive; - - if (_findFlags & QTextDocument::FindCaseSensitively) - cs = Qt::CaseSensitive; - - QString s = QString::fromUtf8(id->chars(), id->size()); - int index = s.indexOf(_text, 0, cs); - if (index != -1) { - reportResult(simpleName->identifier_token, index, _text.length()); - return true; - } - } - } - - else if (QualifiedNameAST *q = name->asQualifiedName()) { - return match(q->unqualified_name); - } - - return false; - } - - virtual bool visit(PostfixExpressionAST *ast) - { - NameAST *name = 0; - - if (ast->base_expression) - name = ast->base_expression->asName(); - - for (PostfixAST *fx = ast->postfix_expressions; fx; fx = fx->next) { - if (fx->asCall() != 0) { - match(name); - } else if (MemberAccessAST *mem = fx->asMemberAccess()) { - name = mem->member_name; - } - } - - return true; - } -}; - -} // end of anonymous namespace - -SemanticSearch::SemanticSearch(QFutureInterface<Utils::FileSearchResult> &future, - Document::Ptr doc, - Snapshot snapshot) - : ASTVisitor(doc->control()), - _future(future), - _doc(doc), - _snapshot(snapshot) -{ - _thisDocument = _snapshot.value(_doc->fileName()); -} - -SemanticSearch::~SemanticSearch() -{ } - -const QByteArray &SemanticSearch::source() const -{ return _source; } - -void SemanticSearch::setSource(const QByteArray &source) -{ _source = source; } - -QString SemanticSearch::matchingLine(const Token &tk) const -{ - const char *beg = _source.constData(); - const char *cp = beg + tk.offset; - for (; cp != beg - 1; --cp) { - if (*cp == '\n') - break; - } - - ++cp; - - const char *lineEnd = cp + 1; - for (; *lineEnd; ++lineEnd) { - if (*lineEnd == '\n') - break; - } - - const QString matchingLine = QString::fromUtf8(cp, lineEnd - cp); - return matchingLine; -} - -void SemanticSearch::reportResult(unsigned tokenIndex, int offset, int len) -{ - const Token &tk = tokenAt(tokenIndex); - const QString lineText = matchingLine(tk); - - unsigned line, col; - getTokenStartPosition(tokenIndex, &line, &col); - - if (col) - --col; // adjust the column position. - - _future.reportResult(Utils::FileSearchResult(QDir::toNativeSeparators(_doc->fileName()), - line, lineText, col + offset, len)); -} - -SemanticSearch *SearchClassDeclarationsFactory::create(QFutureInterface<Utils::FileSearchResult> &future, - Document::Ptr doc, - Snapshot snapshot) -{ - SearchClass *search = new SearchClass(future, doc, snapshot); - search->setText(_text); - search->setFindFlags(_findFlags); - return search; -} - -SemanticSearch *SearchFunctionCallFactory::create(QFutureInterface<Utils::FileSearchResult> &future, - Document::Ptr doc, - Snapshot snapshot) -{ - SearchFunctionCall *search = new SearchFunctionCall(future, doc, snapshot); - search->setText(_text); - search->setFindFlags(_findFlags); - return search; -} - -static void semanticSearch_helper(QFutureInterface<Utils::FileSearchResult> &future, - QPointer<CppModelManager> modelManager, - QMap<QString, QString> wl, - SemanticSearchFactory::Ptr factory) -{ - const Snapshot snapshot = modelManager->snapshot(); - - future.setProgressRange(0, snapshot.size()); - future.setProgressValue(0); - - int progress = 0; - foreach (Document::Ptr doc, snapshot) { - if (future.isPaused()) - future.waitForResume(); - - if (future.isCanceled()) - break; - - const QString fileName = doc->fileName(); - - QByteArray source; - - if (wl.contains(fileName)) - source = snapshot.preprocessedCode(wl.value(fileName), fileName); - else { - QFile file(fileName); - if (! file.open(QFile::ReadOnly)) - continue; - - const QString contents = QTextStream(&file).readAll(); // ### FIXME - source = snapshot.preprocessedCode(contents, fileName); - } - - Document::Ptr newDoc = snapshot.documentFromSource(source, fileName); - newDoc->parse(); - - if (SemanticSearch *search = factory->create(future, newDoc, snapshot)) { - search->setSource(source); - search->run(newDoc->translationUnit()->ast()); - delete search; - } - - future.setProgressValue(++progress); - } -} - -QFuture<Utils::FileSearchResult> CppTools::Internal::semanticSearch(QPointer<CppModelManager> modelManager, - SemanticSearchFactory::Ptr factory) -{ - return QtConcurrent::run(&semanticSearch_helper, modelManager, - modelManager->buildWorkingCopyList(), factory); -} diff --git a/src/plugins/cpptools/cppsemanticsearch.h b/src/plugins/cpptools/cppsemanticsearch.h deleted file mode 100644 index b0ff968b4d841796134d04c689a664dd43724aa7..0000000000000000000000000000000000000000 --- a/src/plugins/cpptools/cppsemanticsearch.h +++ /dev/null @@ -1,126 +0,0 @@ -/************************************************************************** -** -** This file is part of Qt Creator -** -** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -** -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** Commercial Usage -** -** Licensees holding valid Qt Commercial licenses may use this file in -** accordance with the Qt Commercial License Agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Nokia. -** -** GNU Lesser General Public License Usage -** -** Alternatively, 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. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at http://qt.nokia.com/contact. -** -**************************************************************************/ - -#ifndef CPPSEMANTICSEARCH_H -#define CPPSEMANTICSEARCH_H - -#include <ASTVisitor.h> -#include <cplusplus/CppDocument.h> - -#include <utils/filesearch.h> - -#include <QtCore/QFutureInterface> -#include <QtCore/QPointer> -#include <QtCore/QSharedPointer> -#include <QtGui/QTextDocument> - -namespace CppTools { -namespace Internal { - -class CppModelManager; -class SemanticSearchFactory; - -class SemanticSearch: protected CPlusPlus::ASTVisitor -{ - QFutureInterface<Utils::FileSearchResult> &_future; - CPlusPlus::Document::Ptr _doc; - CPlusPlus::Snapshot _snapshot; - CPlusPlus::Document::Ptr _thisDocument; - QByteArray _source; - -public: - SemanticSearch(QFutureInterface<Utils::FileSearchResult> &future, - CPlusPlus::Document::Ptr doc, - CPlusPlus::Snapshot snapshot); - - virtual ~SemanticSearch(); - - virtual void run(CPlusPlus::AST *ast) = 0; - - const QByteArray &source() const; - void setSource(const QByteArray &source); - -protected: - QString matchingLine(const CPlusPlus::Token &tk) const; - void reportResult(unsigned tokenIndex, int offset, int len); -}; - -class SemanticSearchFactory -{ - Q_DISABLE_COPY(SemanticSearchFactory) - -public: - typedef QSharedPointer<SemanticSearchFactory> Ptr; - - SemanticSearchFactory() {} - virtual ~SemanticSearchFactory() {} - - virtual SemanticSearch *create(QFutureInterface<Utils::FileSearchResult> &future, - CPlusPlus::Document::Ptr doc, - CPlusPlus::Snapshot snapshot) = 0; -}; - -class SearchClassDeclarationsFactory: public SemanticSearchFactory -{ - QString _text; - QTextDocument::FindFlags _findFlags; - -public: - SearchClassDeclarationsFactory(const QString &text, QTextDocument::FindFlags findFlags) - : _text(text), _findFlags(findFlags) - { } - - virtual SemanticSearch *create(QFutureInterface<Utils::FileSearchResult> &future, - CPlusPlus::Document::Ptr doc, - CPlusPlus::Snapshot snapshot); -}; - -class SearchFunctionCallFactory: public SemanticSearchFactory -{ - QString _text; - QTextDocument::FindFlags _findFlags; - -public: - SearchFunctionCallFactory(const QString &text, QTextDocument::FindFlags findFlags) - : _text(text), _findFlags(findFlags) - { } - - virtual SemanticSearch *create(QFutureInterface<Utils::FileSearchResult> &future, - CPlusPlus::Document::Ptr doc, - CPlusPlus::Snapshot snapshot); -}; - -QFuture<Utils::FileSearchResult> semanticSearch(QPointer<CppModelManager> modelManager, - SemanticSearchFactory::Ptr factory); - - -} // end of namespace Internal -} // end of namespace CppTools - -#endif // CPPSEMANTICSEARCH_H diff --git a/src/plugins/cpptools/cpptools.pro b/src/plugins/cpptools/cpptools.pro index 00e335432fd26216e7a0ed9478530d6f2af6d38f..8751f0f88d286972b4949410121288c7a7e01aca 100644 --- a/src/plugins/cpptools/cpptools.pro +++ b/src/plugins/cpptools/cpptools.pro @@ -23,7 +23,6 @@ HEADERS += completionsettingspage.h \ searchsymbols.h \ cppdoxygen.h \ cppfilesettingspage.h \ - cppsemanticsearch.h \ cppfindreferences.h SOURCES += completionsettingspage.cpp \ @@ -39,7 +38,6 @@ SOURCES += completionsettingspage.cpp \ cppdoxygen.cpp \ cppfilesettingspage.cpp \ abstracteditorsupport.cpp \ - cppsemanticsearch.cpp \ cppfindreferences.cpp FORMS += completionsettingspage.ui \ diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp index c3f09a98f1b5351dbf2a6120e95a358521ebc3db..3b24b91f163b4a6f1dcb6d9e82e3c06cdde14320 100644 --- a/src/plugins/cpptools/cpptoolsplugin.cpp +++ b/src/plugins/cpptools/cpptoolsplugin.cpp @@ -37,7 +37,6 @@ #include "cppmodelmanager.h" #include "cpptoolsconstants.h" #include "cppquickopenfilter.h" -#include "cppsemanticsearch.h" #include <extensionsystem/pluginmanager.h> @@ -75,113 +74,6 @@ enum { debug = 0 }; CppToolsPlugin *CppToolsPlugin::m_instance = 0; -FindClassDeclarations::FindClassDeclarations(CppModelManager *modelManager) - : _modelManager(modelManager), - _resultWindow(ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>()) -{ - m_watcher.setPendingResultsLimit(1); - connect(&m_watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int))); - connect(&m_watcher, SIGNAL(finished()), this, SLOT(searchFinished())); -} - -void FindClassDeclarations::findAll(const QString &text, QTextDocument::FindFlags findFlags) -{ - Find::SearchResult *search = _resultWindow->startNewSearch(); - connect(search, SIGNAL(activated(Find::SearchResultItem)), - this, SLOT(openEditor(Find::SearchResultItem))); - - _resultWindow->popup(true); - - Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager(); - - SemanticSearchFactory::Ptr factory(new SearchClassDeclarationsFactory(text, findFlags)); - - QFuture<Utils::FileSearchResult> result = semanticSearch(_modelManager, factory); - - m_watcher.setFuture(result); - - Core::FutureProgress *progress = progressManager->addTask(result, tr("Search class"), - CppTools::Constants::TASK_INDEX, - Core::ProgressManager::CloseOnSuccess); - - connect(progress, SIGNAL(clicked()), _resultWindow, SLOT(popup())); -} - -void FindClassDeclarations::displayResult(int index) -{ - Utils::FileSearchResult result = m_watcher.future().resultAt(index); - _resultWindow->addResult(result.fileName, - result.lineNumber, - result.matchingLine, - result.matchStart, - result.matchLength); -} - -void FindClassDeclarations::searchFinished() -{ - emit changed(); -} - -void FindClassDeclarations::openEditor(const Find::SearchResultItem &item) -{ - TextEditor::BaseTextEditor::openEditorAt(item.fileName, item.lineNumber, item.searchTermStart); -} - -////// -FindFunctionCalls::FindFunctionCalls(CppModelManager *modelManager) - : _modelManager(modelManager), - _resultWindow(ExtensionSystem::PluginManager::instance()->getObject<Find::SearchResultWindow>()) -{ - m_watcher.setPendingResultsLimit(1); - connect(&m_watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int))); - connect(&m_watcher, SIGNAL(finished()), this, SLOT(searchFinished())); -} - -void FindFunctionCalls::findAll(const QString &text, QTextDocument::FindFlags findFlags) -{ - Find::SearchResult *search = _resultWindow->startNewSearch(); - connect(search, SIGNAL(activated(Find::SearchResultItem)), - this, SLOT(openEditor(Find::SearchResultItem))); - - _resultWindow->popup(true); - - Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager(); - - SemanticSearchFactory::Ptr factory(new SearchFunctionCallFactory(text, findFlags)); - - QFuture<Utils::FileSearchResult> result = semanticSearch(_modelManager, factory); - - m_watcher.setFuture(result); - - Core::FutureProgress *progress = progressManager->addTask(result, tr("Search functions"), - CppTools::Constants::TASK_INDEX, - Core::ProgressManager::CloseOnSuccess); - - connect(progress, SIGNAL(clicked()), _resultWindow, SLOT(popup())); -} - -void FindFunctionCalls::displayResult(int index) -{ - Utils::FileSearchResult result = m_watcher.future().resultAt(index); - _resultWindow->addResult(result.fileName, - result.lineNumber, - result.matchingLine, - result.matchStart, - result.matchLength); -} - -void FindFunctionCalls::searchFinished() -{ - emit changed(); -} - -void FindFunctionCalls::openEditor(const Find::SearchResultItem &item) -{ - TextEditor::BaseTextEditor::openEditorAt(item.fileName, item.lineNumber, item.searchTermStart); -} - - - CppToolsPlugin::CppToolsPlugin() : m_context(-1), m_modelManager(0), @@ -221,9 +113,6 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error) addAutoReleasedObject(new CompletionSettingsPage(m_completion)); addAutoReleasedObject(new CppFileSettingsPage(m_fileSettings)); - addAutoReleasedObject(new FindClassDeclarations(m_modelManager)); - addAutoReleasedObject(new FindFunctionCalls(m_modelManager)); - // Menus Core::ActionContainer *mtools = am->actionContainer(Core::Constants::M_TOOLS); Core::ActionContainer *mcpptools = am->createMenu(CppTools::Constants::M_TOOLS_CPP); diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h index a78bf260c0ebf8c2957f34600a3e2f4b33e7ed02..7d1ef676bcbb1e4df03dcdbe8345e4ff3436f26a 100644 --- a/src/plugins/cpptools/cpptoolsplugin.h +++ b/src/plugins/cpptools/cpptoolsplugin.h @@ -47,15 +47,6 @@ class QFileInfo; class QDir; QT_END_NAMESPACE -namespace CPlusPlus { -class Snapshot; -} - -namespace Find { -class SearchResultWindow; -struct SearchResultItem; -} - namespace CppTools { namespace Internal { @@ -63,56 +54,6 @@ class CppCodeCompletion; class CppModelManager; struct CppFileSettings; -class FindClassDeclarations: public Find::IFindFilter -{ - Q_OBJECT - -public: - FindClassDeclarations(CppModelManager *modelManager); - - // Find::IFindFilter - virtual QString id() const { return QLatin1String("CppTools.Find.ClassDeclarations"); } - virtual QString name() const { return tr("Class Declarations"); } - virtual bool isEnabled() const { return true; } - virtual QKeySequence defaultShortcut() const { return QKeySequence(); } - virtual void findAll(const QString &txt, QTextDocument::FindFlags findFlags); - -protected Q_SLOTS: - void displayResult(int); - void searchFinished(); - void openEditor(const Find::SearchResultItem &item); - -private: - QPointer<CppModelManager> _modelManager; - Find::SearchResultWindow *_resultWindow; - QFutureWatcher<Utils::FileSearchResult> m_watcher; -}; - -class FindFunctionCalls: public Find::IFindFilter // ### share code with FindClassDeclarations -{ - Q_OBJECT - -public: - FindFunctionCalls(CppModelManager *modelManager); - - // Find::IFindFilter - virtual QString id() const { return QLatin1String("CppTools.Find.FunctionCalls"); } - virtual QString name() const { return tr("Function calls"); } - virtual bool isEnabled() const { return true; } - virtual QKeySequence defaultShortcut() const { return QKeySequence(); } - virtual void findAll(const QString &txt, QTextDocument::FindFlags findFlags); - -protected Q_SLOTS: - void displayResult(int); - void searchFinished(); - void openEditor(const Find::SearchResultItem &item); - -private: - QPointer<CppModelManager> _modelManager; - Find::SearchResultWindow *_resultWindow; - QFutureWatcher<Utils::FileSearchResult> m_watcher; -}; - class CppToolsPlugin : public ExtensionSystem::IPlugin { Q_DISABLE_COPY(CppToolsPlugin)