Commit 7f757884 authored by Tim Jenssen's avatar Tim Jenssen
Browse files

Clang: Extend clang query



It's a first step to introduce clang query.

Change-Id: I4d001a8883f56066765ce6bc561fa3f49611c0a4
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 52fc4a4e
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "cancelmessage.h"
#include <QDebug>
namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const CancelMessage &)
{
debug.nospace() << "CancelMessage()";
return debug;
}
void PrintTo(const CancelMessage &, ::std::ostream* os)
{
*os << "CancelMessage()";
}
} // namespace ClangBackEnd
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "clangbackendipc_global.h"
namespace ClangBackEnd {
class CancelMessage
{
public:
friend QDataStream &operator<<(QDataStream &out, const CancelMessage &/*message*/)
{
return out;
}
friend QDataStream &operator>>(QDataStream &in, CancelMessage &/*message*/)
{
return in;
}
friend bool operator==(const CancelMessage &/*first*/, const CancelMessage &/*second*/)
{
return true;
}
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CancelMessage &message);
void PrintTo(const CancelMessage &message, ::std::ostream* os);
DECLARE_MESSAGE(CancelMessage)
} // namespace ClangBackEnd
...@@ -59,6 +59,7 @@ SOURCES += $$PWD/clangcodemodelserverinterface.cpp \ ...@@ -59,6 +59,7 @@ SOURCES += $$PWD/clangcodemodelserverinterface.cpp \
$$PWD/requestsourcelocationforrenamingmessage.cpp \ $$PWD/requestsourcelocationforrenamingmessage.cpp \
$$PWD/filepath.cpp \ $$PWD/filepath.cpp \
$$PWD/sourcerangescontainer.cpp \ $$PWD/sourcerangescontainer.cpp \
$$PWD/sourcefilepathcontainerbase.cpp \
$$PWD/sourcerangecontainerv2.cpp \ $$PWD/sourcerangecontainerv2.cpp \
$$PWD/dynamicastmatcherdiagnosticcontainer.cpp \ $$PWD/dynamicastmatcherdiagnosticcontainer.cpp \
$$PWD/dynamicastmatcherdiagnosticcontextcontainer.cpp \ $$PWD/dynamicastmatcherdiagnosticcontextcontainer.cpp \
...@@ -66,7 +67,8 @@ SOURCES += $$PWD/clangcodemodelserverinterface.cpp \ ...@@ -66,7 +67,8 @@ SOURCES += $$PWD/clangcodemodelserverinterface.cpp \
$$PWD/requestsourcerangesanddiagnosticsforquerymessage.cpp \ $$PWD/requestsourcerangesanddiagnosticsforquerymessage.cpp \
$$PWD/sourcerangesanddiagnosticsforquerymessage.cpp \ $$PWD/sourcerangesanddiagnosticsforquerymessage.cpp \
$$PWD/sourcerangewithtextcontainer.cpp \ $$PWD/sourcerangewithtextcontainer.cpp \
$$PWD/filecontainerv2.cpp $$PWD/filecontainerv2.cpp \
$$PWD/cancelmessage.cpp
HEADERS += \ HEADERS += \
$$PWD/clangcodemodelserverinterface.h \ $$PWD/clangcodemodelserverinterface.h \
...@@ -130,6 +132,7 @@ HEADERS += \ ...@@ -130,6 +132,7 @@ HEADERS += \
$$PWD/requestsourcerangesanddiagnosticsforquerymessage.h \ $$PWD/requestsourcerangesanddiagnosticsforquerymessage.h \
$$PWD/sourcerangesanddiagnosticsforquerymessage.h \ $$PWD/sourcerangesanddiagnosticsforquerymessage.h \
$$PWD/sourcerangewithtextcontainer.h \ $$PWD/sourcerangewithtextcontainer.h \
$$PWD/filecontainerv2.h $$PWD/filecontainerv2.h \
$$PWD/cancelmessage.h
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#endif #endif
namespace Utils { namespace Utils {
template<uint Size> template <uint Size>
class BasicSmallString; class BasicSmallString;
using SmallString = BasicSmallString<31>; using SmallString = BasicSmallString<31>;
} }
...@@ -122,7 +122,9 @@ enum class MessageType : quint8 { ...@@ -122,7 +122,9 @@ enum class MessageType : quint8 {
RequestSourceLocationsForRenamingMessage, RequestSourceLocationsForRenamingMessage,
RequestSourceRangesAndDiagnosticsForQueryMessage, RequestSourceRangesAndDiagnosticsForQueryMessage,
SourceRangesAndDiagnosticsForQueryMessage SourceRangesAndDiagnosticsForQueryMessage,
CancelMessage
}; };
template<MessageType messageEnumeration> template<MessageType messageEnumeration>
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "messageenvelop.h" #include "messageenvelop.h"
#include "requestsourcelocationforrenamingmessage.h" #include "requestsourcelocationforrenamingmessage.h"
#include "requestsourcerangesanddiagnosticsforquerymessage.h" #include "requestsourcerangesanddiagnosticsforquerymessage.h"
#include "cancelmessage.h"
#include <QDebug> #include <QDebug>
...@@ -45,6 +46,9 @@ void RefactoringServerInterface::dispatch(const MessageEnvelop &messageEnvelop) ...@@ -45,6 +46,9 @@ void RefactoringServerInterface::dispatch(const MessageEnvelop &messageEnvelop)
case MessageType::RequestSourceRangesAndDiagnosticsForQueryMessage: case MessageType::RequestSourceRangesAndDiagnosticsForQueryMessage:
requestSourceRangesAndDiagnosticsForQueryMessage(messageEnvelop.message<RequestSourceRangesAndDiagnosticsForQueryMessage>()); requestSourceRangesAndDiagnosticsForQueryMessage(messageEnvelop.message<RequestSourceRangesAndDiagnosticsForQueryMessage>());
break; break;
case MessageType::CancelMessage:
cancel();
break;
default: default:
qWarning() << "Unknown IpcClientMessage"; qWarning() << "Unknown IpcClientMessage";
} }
......
...@@ -34,6 +34,7 @@ namespace ClangBackEnd { ...@@ -34,6 +34,7 @@ namespace ClangBackEnd {
class RefactoringClientInterface; class RefactoringClientInterface;
class RequestSourceLocationsForRenamingMessage; class RequestSourceLocationsForRenamingMessage;
class RequestSourceRangesAndDiagnosticsForQueryMessage; class RequestSourceRangesAndDiagnosticsForQueryMessage;
class CancelMessage;
class CMBIPC_EXPORT RefactoringServerInterface : public IpcServerInterface<RefactoringClientInterface> class CMBIPC_EXPORT RefactoringServerInterface : public IpcServerInterface<RefactoringClientInterface>
{ {
...@@ -43,6 +44,7 @@ public: ...@@ -43,6 +44,7 @@ public:
virtual void end() = 0; virtual void end() = 0;
virtual void requestSourceLocationsForRenamingMessage(RequestSourceLocationsForRenamingMessage &&message) = 0; virtual void requestSourceLocationsForRenamingMessage(RequestSourceLocationsForRenamingMessage &&message) = 0;
virtual void requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message) = 0; virtual void requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message) = 0;
virtual void cancel() = 0;
bool isUsable() const bool isUsable() const
{ {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "refactoringserverproxy.h" #include "refactoringserverproxy.h"
#include "cancelmessage.h"
#include "cmbendmessage.h" #include "cmbendmessage.h"
#include "messageenvelop.h" #include "messageenvelop.h"
#include "refactoringclientinterface.h" #include "refactoringclientinterface.h"
...@@ -59,6 +60,11 @@ void RefactoringServerProxy::requestSourceRangesAndDiagnosticsForQueryMessage(Re ...@@ -59,6 +60,11 @@ void RefactoringServerProxy::requestSourceRangesAndDiagnosticsForQueryMessage(Re
writeMessageBlock.write(message); writeMessageBlock.write(message);
} }
void RefactoringServerProxy::cancel()
{
writeMessageBlock.write(CancelMessage());
}
void RefactoringServerProxy::readMessages() void RefactoringServerProxy::readMessages()
{ {
for (const auto &message : readMessageBlock.readAll()) for (const auto &message : readMessageBlock.readAll())
......
...@@ -42,7 +42,7 @@ namespace ClangBackEnd { ...@@ -42,7 +42,7 @@ namespace ClangBackEnd {
class RefactoringClientInterface; class RefactoringClientInterface;
class CMBIPC_EXPORT RefactoringServerProxy : public RefactoringServerInterface class CMBIPC_EXPORT RefactoringServerProxy final : public RefactoringServerInterface
{ {
public: public:
explicit RefactoringServerProxy(RefactoringClientInterface *client, QIODevice *ioDevice); explicit RefactoringServerProxy(RefactoringClientInterface *client, QIODevice *ioDevice);
...@@ -50,8 +50,9 @@ public: ...@@ -50,8 +50,9 @@ public:
const RefactoringServerProxy &operator=(const RefactoringServerProxy&) = delete; const RefactoringServerProxy &operator=(const RefactoringServerProxy&) = delete;
void end() override; void end() override;
void requestSourceLocationsForRenamingMessage(ClangBackEnd::RequestSourceLocationsForRenamingMessage &&message) override; void requestSourceLocationsForRenamingMessage(RequestSourceLocationsForRenamingMessage &&message) override;
void requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message); void requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message) override;
void cancel() override;
void readMessages(); void readMessages();
......
...@@ -25,13 +25,11 @@ ...@@ -25,13 +25,11 @@
#pragma once #pragma once
#include "clangbackendipc_global.h"
#include "filecontainerv2.h" #include "filecontainerv2.h"
namespace ClangBackEnd { namespace ClangBackEnd {
class CMBIPC_EXPORT RequestSourceRangesAndDiagnosticsForQueryMessage class RequestSourceRangesAndDiagnosticsForQueryMessage
{ {
public: public:
RequestSourceRangesAndDiagnosticsForQueryMessage() = default; RequestSourceRangesAndDiagnosticsForQueryMessage() = default;
......
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "sourcefilepathcontainerbase.h"
namespace ClangBackEnd {
} // namespace ClangBackEnd
...@@ -44,9 +44,11 @@ public: ...@@ -44,9 +44,11 @@ public:
void insertFilePath(uint fileId, Utils::SmallString &&fileDirectory, Utils::SmallString &&fileName) void insertFilePath(uint fileId, Utils::SmallString &&fileDirectory, Utils::SmallString &&fileName)
{ {
filePathHash.emplace(std::piecewise_construct, if (filePathHash.find(fileId) == filePathHash.end()) {
std::forward_as_tuple(fileId), filePathHash.emplace(std::piecewise_construct,
std::forward_as_tuple(std::move(fileDirectory), std::move(fileName))); std::forward_as_tuple(fileId),
std::forward_as_tuple(std::move(fileDirectory), std::move(fileName)));
}
} }
void reserve(std::size_t size) void reserve(std::size_t size)
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
#include "sourcerangewithtextcontainer.h" #include "sourcerangewithtextcontainer.h"
#ifdef UNIT_TESTS
#include <gtest/gtest.h>
#endif
namespace ClangBackEnd { namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const SourceRangeWithTextContainer &container) QDebug operator<<(QDebug debug, const SourceRangeWithTextContainer &container)
...@@ -40,12 +44,18 @@ QDebug operator<<(QDebug debug, const SourceRangeWithTextContainer &container) ...@@ -40,12 +44,18 @@ QDebug operator<<(QDebug debug, const SourceRangeWithTextContainer &container)
void PrintTo(const SourceRangeWithTextContainer &container, ::std::ostream* os) void PrintTo(const SourceRangeWithTextContainer &container, ::std::ostream* os)
{ {
Q_UNUSED(container)
Q_UNUSED(os)
#ifdef UNIT_TESTS
*os << "((" *os << "(("
<< container.start().line() << ", " << container.start().line() << ", "
<< container.start().column() << "), (" << container.start().column() << ", "
<< container.start().offset() << "), ("
<< container.end().line() << ", " << container.end().line() << ", "
<< container.end().column() << ", " << container.end().column() << ", "
<< "\"" << container.text() << "\"" << container.end().offset() << "), "
<< "))"; << testing::PrintToString(container.text())
<< ")";
#endif
} }
} // namespace ClangBackEnd } // namespace ClangBackEnd
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "clangquerycurrentfilefindfilter.h"
#include "projectpartutilities.h"
#include "refactoringclient.h"
#include "refactoringcompileroptionsbuilder.h"
#include "searchinterface.h"
#include <refactoringserverinterface.h>
#include <requestsourcerangesanddiagnosticsforquerymessage.h>
namespace ClangRefactoring {
ClangQueryCurrentFileFindFilter::ClangQueryCurrentFileFindFilter(
ClangBackEnd::RefactoringServerInterface &server,
SearchInterface &searchInterface,
RefactoringClient &refactoringClient)
: server(server),
searchInterface(searchInterface),
refactoringClient(refactoringClient)
{
}
QString ClangQueryCurrentFileFindFilter::id() const
{
return QStringLiteral("Clang Query Current File");
}
QString ClangQueryCurrentFileFindFilter::displayName() const
{
return tr("Clang Query Current File");
}
bool ClangQueryCurrentFileFindFilter::isEnabled() const
{
return true;
}
void ClangQueryCurrentFileFindFilter::findAll(const QString &queryText, Core::FindFlags)
{
searchHandle = searchInterface.startNewSearch(tr("Clang Query"), queryText);
refactoringClient.setSearchHandle(searchHandle.get());
server.requestSourceRangesAndDiagnosticsForQueryMessage(createMessage(queryText));
}
Core::FindFlags ClangQueryCurrentFileFindFilter::supportedFindFlags() const
{
return 0;
}
void ClangQueryCurrentFileFindFilter::setCurrentDocumentFilePath(const QString &filePath)
{
currentDocumentFilePath = filePath;
}
void ClangQueryCurrentFileFindFilter::setUnsavedDocumentContent(const QString &unsavedContent)
{
unsavedDocumentContent = unsavedContent;
}
void ClangQueryCurrentFileFindFilter::setProjectPart(const CppTools::ProjectPart::Ptr &projectPart)
{
this->projectPart = projectPart;
}
void ClangQueryCurrentFileFindFilter::setUsable(bool isUsable)
{
server.setUsable(isUsable);
}
bool ClangQueryCurrentFileFindFilter::isUsable() const
{
return server.isUsable();
}
ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage
ClangQueryCurrentFileFindFilter::createMessage(const QString &queryText) const
{
std::vector<ClangBackEnd::V2::FileContainer> fileContainers;
fileContainers.emplace_back(ClangBackEnd::FilePath(currentDocumentFilePath),
unsavedDocumentContent,
createCommandLine());
return ClangBackEnd::RequestSourceRangesAndDiagnosticsForQueryMessage(
Utils::SmallString(queryText),
std::move(fileContainers));
}
Utils::SmallStringVector ClangQueryCurrentFileFindFilter::createCommandLine() const
{
using ClangRefactoring::RefactoringCompilerOptionsBuilder;
auto commandLine = RefactoringCompilerOptionsBuilder::build(
projectPart.data(),
fileKindInProjectPart(projectPart.data(), currentDocumentFilePath),
RefactoringCompilerOptionsBuilder::PchUsage::None);
commandLine.push_back(currentDocumentFilePath);
return commandLine;
}
} // namespace ClangRefactoring
...@@ -25,10 +25,13 @@ ...@@ -25,10 +25,13 @@
#include "clangqueryprojectsfindfilter.h" #include "clangqueryprojectsfindfilter.h"
#include "projectpartutilities.h"
#include "refactoringclient.h" #include "refactoringclient.h"
#include "refactoringcompileroptionsbuilder.h"
#include "searchinterface.h" #include "searchinterface.h"
#include <refactoringserverinterface.h> #include <refactoringserverinterface.h>
#include <requestsourcerangesanddiagnosticsforquerymessage.h>
namespace ClangRefactoring { namespace ClangRefactoring {
...@@ -61,9 +64,15 @@ void ClangQueryProjectsFindFilter::findAll(const QString &queryText, Core::FindF ...@@ -61,9 +64,15 @@ void ClangQueryProjectsFindFilter::findAll(const QString &queryText, Core::FindF
{ {
searchHandle = searchInterface.startNewSearch(tr("Clang Query"), queryText); searchHandle = searchInterface.startNewSearch(tr("Clang Query"), queryText);
searchHandle->setRefactoringServer(&server);
refactoringClient.setSearchHandle(searchHandle.get()); refactoringClient.setSearchHandle(searchHandle.get());
//server.requestSourceRangesAndDiagnosticsForQueryMessage(createMessage(queryText)); auto message = createMessage(queryText);
refactoringClient.setExpectedResultCount(message.fileContainers().size());
server.requestSourceRangesAndDiagnosticsForQueryMessage(std::move(message));
} }