Commit 3fb25b28 authored by Marco Bubke's avatar Marco Bubke

Clang: Cleanup IPC code

Change-Id: I29571801b4093337e2c7cc1eec51cfcd07b3bdc5
Reviewed-by: Ivan Donchevskii's avatarIvan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent f97875a8
......@@ -38,9 +38,9 @@ QDebug operator<<(QDebug debug, const CancelMessage &)
return debug;
}
void PrintTo(const CancelMessage &, ::std::ostream* os)
std::ostream &operator<<(std::ostream &os, const CancelMessage &/*message*/)
{
*os << "CancelMessage()";
return os << "()";
}
} // namespace ClangBackEnd
......@@ -49,7 +49,7 @@ public:
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CancelMessage &message);
void PrintTo(const CancelMessage &message, ::std::ostream* os);
std::ostream &operator<<(std::ostream &os, const CancelMessage &message);
DECLARE_MESSAGE(CancelMessage)
} // namespace ClangBackEnd
......@@ -95,15 +95,15 @@ Utf8String debugId(const FileContainer &fileContainer)
}
VerboseScopeDurationTimer::VerboseScopeDurationTimer(const char *id)
: id(id)
: m_id(id)
{
if (timersLog().isDebugEnabled())
timer.start();
m_timer.start();
}
VerboseScopeDurationTimer::~VerboseScopeDurationTimer()
{
qCDebug(timersLog) << id << "needed" << timer.elapsed() << "ms";
qCDebug(timersLog) << m_id << "needed" << m_timer.elapsed() << "ms";
}
} // namespace ClangBackEnd
......@@ -44,8 +44,8 @@ public:
~VerboseScopeDurationTimer();
private:
const char * const id;
QElapsedTimer timer;
const char * const m_id;
QElapsedTimer m_timer;
};
} // namespace ClangBackEnd
......
......@@ -44,72 +44,72 @@
namespace ClangBackEnd {
ClangCodeModelClientProxy::ClangCodeModelClientProxy(ClangCodeModelServerInterface *server, QIODevice *ioDevice)
: writeMessageBlock(ioDevice),
readMessageBlock(ioDevice),
server(server),
ioDevice(ioDevice)
: m_writeMessageBlock(ioDevice),
m_readMessageBlock(ioDevice),
m_server(server),
m_ioDevice(ioDevice)
{
QObject::connect(ioDevice, &QIODevice::readyRead, [this] () {ClangCodeModelClientProxy::readMessages();});
QObject::connect(m_ioDevice, &QIODevice::readyRead, [this] () {ClangCodeModelClientProxy::readMessages();});
}
ClangCodeModelClientProxy::ClangCodeModelClientProxy(ClangCodeModelClientProxy &&other)
: writeMessageBlock(std::move(other.writeMessageBlock)),
readMessageBlock(std::move(other.readMessageBlock)),
server(std::move(other.server)),
ioDevice(std::move(other.ioDevice))
: m_writeMessageBlock(std::move(other.m_writeMessageBlock)),
m_readMessageBlock(std::move(other.m_readMessageBlock)),
m_server(std::move(other.m_server)),
m_ioDevice(std::move(other.m_ioDevice))
{
}
ClangCodeModelClientProxy &ClangCodeModelClientProxy::operator=(ClangCodeModelClientProxy &&other)
{
writeMessageBlock = std::move(other.writeMessageBlock);
readMessageBlock = std::move(other.readMessageBlock);
server = std::move(other.server);
ioDevice = std::move(other.ioDevice);
m_writeMessageBlock = std::move(other.m_writeMessageBlock);
m_readMessageBlock = std::move(other.m_readMessageBlock);
m_server = std::move(other.m_server);
m_ioDevice = std::move(other.m_ioDevice);
return *this;
}
void ClangCodeModelClientProxy::alive()
{
writeMessageBlock.write(AliveMessage());
m_writeMessageBlock.write(AliveMessage());
}
void ClangCodeModelClientProxy::echo(const EchoMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelClientProxy::codeCompleted(const CodeCompletedMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelClientProxy::translationUnitDoesNotExist(const TranslationUnitDoesNotExistMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelClientProxy::projectPartsDoNotExist(const ProjectPartsDoNotExistMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelClientProxy::documentAnnotationsChanged(const DocumentAnnotationsChangedMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelClientProxy::readMessages()
{
for (const MessageEnvelop &message : readMessageBlock.readAll())
server->dispatch(message);
for (const MessageEnvelop &message : m_readMessageBlock.readAll())
m_server->dispatch(message);
}
bool ClangCodeModelClientProxy::isUsingThatIoDevice(QIODevice *ioDevice) const
bool ClangCodeModelClientProxy::isUsingThatIoDevice(QIODevice *m_ioDevice) const
{
return this->ioDevice == ioDevice;
return this->m_ioDevice == m_ioDevice;
}
} // namespace ClangBackEnd
......
......@@ -63,10 +63,10 @@ public:
bool isUsingThatIoDevice(QIODevice *ioDevice) const;
private:
ClangBackEnd::WriteMessageBlock writeMessageBlock;
ClangBackEnd::ReadMessageBlock readMessageBlock;
ClangCodeModelServerInterface *server = nullptr;
QIODevice *ioDevice = nullptr;
ClangBackEnd::WriteMessageBlock m_writeMessageBlock;
ClangBackEnd::ReadMessageBlock m_readMessageBlock;
ClangCodeModelServerInterface *m_server = nullptr;
QIODevice *m_ioDevice = nullptr;
};
} // namespace ClangBackEnd
......@@ -47,78 +47,78 @@
namespace ClangBackEnd {
ClangCodeModelServerProxy::ClangCodeModelServerProxy(ClangCodeModelClientInterface *client, QIODevice *ioDevice)
: writeMessageBlock(ioDevice),
readMessageBlock(ioDevice),
client(client)
: m_writeMessageBlock(ioDevice),
m_readMessageBlock(ioDevice),
m_client(client)
{
QObject::connect(ioDevice, &QIODevice::readyRead, [this] () {ClangCodeModelServerProxy::readMessages();});
}
void ClangCodeModelServerProxy::readMessages()
{
for (const auto &message : readMessageBlock.readAll())
client->dispatch(message);
for (const auto &message : m_readMessageBlock.readAll())
m_client->dispatch(message);
}
void ClangCodeModelServerProxy::resetCounter()
{
writeMessageBlock.resetCounter();
readMessageBlock.resetCounter();
m_writeMessageBlock.resetCounter();
m_readMessageBlock.resetCounter();
}
void ClangCodeModelServerProxy::end()
{
writeMessageBlock.write(EndMessage());
m_writeMessageBlock.write(EndMessage());
}
void ClangCodeModelServerProxy::registerTranslationUnitsForEditor(const RegisterTranslationUnitForEditorMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelServerProxy::updateTranslationUnitsForEditor(const ClangBackEnd::UpdateTranslationUnitsForEditorMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelServerProxy::unregisterTranslationUnitsForEditor(const UnregisterTranslationUnitsForEditorMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelServerProxy::registerProjectPartsForEditor(const RegisterProjectPartsForEditorMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelServerProxy::unregisterProjectPartsForEditor(const UnregisterProjectPartsForEditorMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangBackEnd::ClangCodeModelServerProxy::registerUnsavedFilesForEditor(const ClangBackEnd::RegisterUnsavedFilesForEditorMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangBackEnd::ClangCodeModelServerProxy::unregisterUnsavedFilesForEditor(const ClangBackEnd::UnregisterUnsavedFilesForEditorMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelServerProxy::completeCode(const CompleteCodeMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelServerProxy::requestDocumentAnnotations(const RequestDocumentAnnotationsMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
void ClangCodeModelServerProxy::updateVisibleTranslationUnits(const UpdateVisibleTranslationUnitsMessage &message)
{
writeMessageBlock.write(message);
m_writeMessageBlock.write(message);
}
} // namespace ClangBackEnd
......
......@@ -66,9 +66,9 @@ public:
void resetCounter();
private:
ClangBackEnd::WriteMessageBlock writeMessageBlock;
ClangBackEnd::ReadMessageBlock readMessageBlock;
ClangCodeModelClientInterface *client;
ClangBackEnd::WriteMessageBlock m_writeMessageBlock;
ClangBackEnd::ReadMessageBlock m_readMessageBlock;
ClangCodeModelClientInterface *m_client;
};
} // namespace ClangBackEnd
......@@ -27,6 +27,8 @@
#include <QDebug>
#include <ostream>
namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const AliveMessage &/*message*/)
......@@ -34,4 +36,9 @@ QDebug operator<<(QDebug debug, const AliveMessage &/*message*/)
return debug.nospace() << "AliveMessage()";
}
std::ostream &operator<<(std::ostream &os, const AliveMessage &/*message*/)
{
return os << "()";
}
}
......@@ -29,6 +29,8 @@
#include <QDataStream>
#include <iosfwd>
namespace ClangBackEnd {
class AliveMessage
......@@ -51,6 +53,7 @@ public:
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const AliveMessage &message);
std::ostream &operator<<(std::ostream &os, const AliveMessage &message);
DECLARE_MESSAGE(AliveMessage)
}
......@@ -46,23 +46,25 @@ QDebug operator<<(QDebug debug, const CodeCompletedMessage &message)
{
debug.nospace() << "CodeCompletedMessage(";
debug.nospace() << message.codeCompletions_ << ", "
debug.nospace() << message.m_codeCompletions << ", "
<< completionCorrectionToText(message.neededCorrection()) << ", "
<< message.ticketNumber_;
<< message.m_ticketNumber;
debug.nospace() << ")";
return debug;
}
void PrintTo(const CodeCompletedMessage &message, ::std::ostream* os)
std::ostream &operator<<(std::ostream &os, const CodeCompletedMessage &message)
{
QString output;
QDebug debug(&output);
os << "("
<< message.m_codeCompletions << ", "
<< completionCorrectionToText(message.neededCorrection()) << ", "
<< message.m_ticketNumber
debug << message;
<< ")";
*os << output.toUtf8().constData();
return os;
}
} // namespace ClangBackEnd
......
......@@ -27,8 +27,9 @@
#include "codecompletion.h"
#include <utf8stringvector.h>
#include <QDataStream>
#include <QVector>
namespace ClangBackEnd {
......@@ -39,32 +40,32 @@ public:
CodeCompletedMessage(const CodeCompletions &codeCompletions,
CompletionCorrection neededCorrection,
quint64 ticketNumber)
: codeCompletions_(codeCompletions),
ticketNumber_(ticketNumber),
neededCorrection_(neededCorrection)
: m_codeCompletions(codeCompletions),
m_ticketNumber(ticketNumber),
m_neededCorrection(neededCorrection)
{
}
const CodeCompletions &codeCompletions() const
{
return codeCompletions_;
return m_codeCompletions;
}
CompletionCorrection neededCorrection() const
{
return neededCorrection_;
return m_neededCorrection;
}
quint64 ticketNumber() const
{
return ticketNumber_;
return m_ticketNumber;
}
friend QDataStream &operator<<(QDataStream &out, const CodeCompletedMessage &message)
{
out << message.codeCompletions_;
out << static_cast<quint32>(message.neededCorrection_);
out << message.ticketNumber_;
out << message.m_codeCompletions;
out << static_cast<quint32>(message.m_neededCorrection);
out << message.m_ticketNumber;
return out;
}
......@@ -73,29 +74,29 @@ public:
{
quint32 neededCorrection;
in >> message.codeCompletions_;
in >> message.m_codeCompletions;
in >> neededCorrection;
in >> message.ticketNumber_;
in >> message.m_ticketNumber;
message.neededCorrection_ = static_cast<CompletionCorrection>(neededCorrection);
message.m_neededCorrection = static_cast<CompletionCorrection>(neededCorrection);
return in;
}
friend bool operator==(const CodeCompletedMessage &first, const CodeCompletedMessage &second)
{
return first.ticketNumber_ == second.ticketNumber_
&& first.neededCorrection_ == second.neededCorrection_
&& first.codeCompletions_ == second.codeCompletions_;
return first.m_ticketNumber == second.m_ticketNumber
&& first.m_neededCorrection == second.m_neededCorrection
&& first.m_codeCompletions == second.m_codeCompletions;
}
friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CodeCompletedMessage &message);
friend void PrintTo(const CodeCompletedMessage &message, ::std::ostream* os);
friend std::ostream &operator<<(std::ostream &os, const CodeCompletedMessage &message);
private:
CodeCompletions codeCompletions_;
quint64 ticketNumber_ = 0;
CompletionCorrection neededCorrection_ = CompletionCorrection::NoCorrection;
CodeCompletions m_codeCompletions;
quint64 m_ticketNumber = 0;
CompletionCorrection m_neededCorrection = CompletionCorrection::NoCorrection;
};
DECLARE_MESSAGE(CodeCompletedMessage)
......
......@@ -37,28 +37,29 @@ QDebug operator<<(QDebug debug, const CompleteCodeMessage &message)
{
debug.nospace() << "CompleteCodeMessage(";
debug.nospace() << message.filePath_ << ", ";
debug.nospace() << message.line_<< ", ";
debug.nospace() << message.column_<< ", ";
debug.nospace() << message.projectPartId_ << ", ";
debug.nospace() << message.ticketNumber_;
debug.nospace() << message.m_filePath << ", ";
debug.nospace() << message.m_line << ", ";
debug.nospace() << message.m_column << ", ";
debug.nospace() << message.m_projectPartId << ", ";
debug.nospace() << message.m_ticketNumber;
debug.nospace() << ")";
return debug;
}
void PrintTo(const CompleteCodeMessage &message, ::std::ostream* os)
std::ostream &operator<<(std::ostream &os, const CompleteCodeMessage &message)
{
*os << "CompleteCodeMessage(";
os << "("
<< message.m_filePath.constData() << ", "
<< message.m_line << ", "
<< message.m_column << ", "
<< message.m_projectPartId.constData() << ", "
<< message.m_ticketNumber
*os << message.filePath_.constData() << ", ";
*os << message.line_ << ", ";
*os << message.column_ << ", ";
*os << message.projectPartId_.constData() << ", ";
*os << message.ticketNumber_;
<< ")";
*os << ")";
return os;
}
} // namespace ClangBackEnd
......
......@@ -42,80 +42,80 @@ public:
quint32 line,
quint32 column,
const Utf8String &projectPartId)
: filePath_(filePath),
projectPartId_(projectPartId),
ticketNumber_(++ticketCounter),
line_(line),
column_(column)
: m_filePath(filePath),
m_projectPartId(projectPartId),
m_ticketNumber(++ticketCounter),
m_line(line),
m_column(column)
{
}
const Utf8String &filePath() const
{
return filePath_;
return m_filePath;
}
const Utf8String &projectPartId() const
{
return projectPartId_;
return m_projectPartId;
}
quint32 line() const
{
return line_;
return m_line;
}
quint32 column() const
{
return column_;
return m_column;
}
quint64 ticketNumber() const
{
return ticketNumber_;
return m_ticketNumber;
}
friend QDataStream &operator<<(QDataStream &out, const CompleteCodeMessage &message)
{
out << message.filePath_;
out << message.projectPartId_;
out << message.ticketNumber_;
out << message.line_;
out << message.column_;
out << message.m_filePath;
out << message.m_projectPartId;
out << message.m_ticketNumber;
out << message.m_line;
out << message.m_column;
return out;
}
friend QDataStream &operator>>(QDataStream &in, CompleteCodeMessage &message)
{
in >> message.filePath_;
in >> message.projectPartId_;
in >> message.ticketNumber_;
in >> message.line_;
in >> message.column_;
in >> message.m_filePath;
in >> message.m_projectPartId;
in >> message.m_ticketNumber;
in >> message.m_line;
in >> message.m_column;
return in;
}
friend bool operator==(const CompleteCodeMessage &first, const CompleteCodeMessage &second)
{
return first.ticketNumber_ == second.ticketNumber_
&& first.filePath_ == second.filePath_
&& first.projectPartId_ == second.projectPartId_
&& first.line_ == second.line_
&& first.column_ == second.column_;
return first.m_ticketNumber == second.m_ticketNumber
&& first.m_filePath == second.m_filePath
&& first.m_projectPartId == second.m_projectPartId
&& first.m_line == second.m_line
&& first.m_column == second.m_column;
}
friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const CompleteCodeMessage &message);
friend void PrintTo(const CompleteCodeMessage &message, ::std::ostream* os);
friend std::ostream &operator<<(std::ostream &os, const CompleteCodeMessage &message);
private:
Utf8String filePath_;
Utf8String projectPartId_;
Utf8String m_filePath;
Utf8String m_projectPartId;
static CMBIPC_EXPORT quint64 ticketCounter;
quint64 ticketNumber_ = 0;
quint32 line_ = 0;
quint32 column_ = 0;
quint64 m_ticketNumber = 0;
quint32 m_line = 0;
quint32 m_column = 0;
};
DECLARE_MESSAGE(CompleteCodeMessage);
......
......@@ -36,9 +36,9 @@ QDebug operator<<(QDebug debug, const EchoMessage &)
return debug.nospace() << "EchoMessage()";
}
void PrintTo(const EchoMessage &, ::std::ostream* os)
std::ostream &operator<<(std::ostream &os, const EchoMessage &/*message*/)
{
*os << "EchoMessage()";
return os << "()";
}
} // namespace ClangBackEnd
......
......@@ -29,6 +29,8 @@
#include "messageenvelop.h"
#include <iosfwd>
namespace ClangBackEnd {
class EchoMessage
......@@ -36,13 +38,13 @@ class EchoMessage
public:
EchoMessage() = default;
explicit EchoMessage(const MessageEnvelop &message)
: message_(message)
: m_message(message)
{
}
const MessageEnvelop &message() const
{
return message_;
return m_message;
}
friend QDataStream &operator<<(QDataStream &out, const EchoMessage &message)
......@@ -54,22 +56,22 @@ public: