Clang: Add clang query

Clang query is mechanism to use AST matcher to search for code. Think
about regular expression but in the context of AST. So you get a semantic
search tool for C++.

Change-Id: I72e882c5b53a0c52f352a3664847c4c3e4f6fc2e
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Tim Jenssen
2016-11-15 15:38:12 +01:00
parent 96187594b5
commit 9c7ff5199f
99 changed files with 4603 additions and 246 deletions

View File

@@ -57,7 +57,16 @@ SOURCES += $$PWD/clangcodemodelserverinterface.cpp \
$$PWD/sourcelocationcontainerv2.cpp \
$$PWD/sourcelocationsforrenamingmessage.cpp \
$$PWD/requestsourcelocationforrenamingmessage.cpp \
$$PWD/filepath.cpp
$$PWD/filepath.cpp \
$$PWD/sourcerangescontainer.cpp \
$$PWD/sourcerangecontainerv2.cpp \
$$PWD/dynamicastmatcherdiagnosticcontainer.cpp \
$$PWD/dynamicastmatcherdiagnosticcontextcontainer.cpp \
$$PWD/dynamicastmatcherdiagnosticmessagecontainer.cpp \
$$PWD/requestsourcerangesanddiagnosticsforquerymessage.cpp \
$$PWD/sourcerangesanddiagnosticsforquerymessage.cpp \
$$PWD/sourcerangewithtextcontainer.cpp \
$$PWD/filecontainerv2.cpp
HEADERS += \
$$PWD/clangcodemodelserverinterface.h \
@@ -110,6 +119,17 @@ HEADERS += \
$$PWD/sourcelocationcontainerv2.h \
$$PWD/sourcelocationsforrenamingmessage.h \
$$PWD/requestsourcelocationforrenamingmessage.h \
$$PWD/filepath.h
$$PWD/filepath.h \
$$PWD/sourcerangescontainer.h \
$$PWD/sourcefilepathcontainerbase.h \
$$PWD/sourcerangecontainerv2.h \
$$PWD/dynamicmatcherdiagnostics.h \
$$PWD/dynamicastmatcherdiagnosticcontainer.h \
$$PWD/dynamicastmatcherdiagnosticcontextcontainer.h \
$$PWD/dynamicastmatcherdiagnosticmessagecontainer.h \
$$PWD/requestsourcerangesanddiagnosticsforquerymessage.h \
$$PWD/sourcerangesanddiagnosticsforquerymessage.h \
$$PWD/sourcerangewithtextcontainer.h \
$$PWD/filecontainerv2.h
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols

View File

@@ -29,6 +29,10 @@
#include <QtCore/qglobal.h>
#ifdef UNIT_TESTS
#include <gtest/gtest.h>
#endif
#if defined(CLANGBACKENDIPC_BUILD_LIB)
# define CMBIPC_EXPORT Q_DECL_EXPORT
#elif defined(CLANGBACKENDIPC_BUILD_STATIC_LIB)
@@ -41,6 +45,12 @@
# define CLANGBACKENDPROCESSPATH ""
#endif
namespace Utils {
template<uint Size>
class BasicSmallString;
using SmallString = BasicSmallString<31>;
}
namespace ClangBackEnd {
enum class DiagnosticSeverity : quint32 // one to one mapping of the clang enum numbers
@@ -109,7 +119,10 @@ enum class MessageType : quint8 {
ProjectPartsDoNotExistMessage,
SourceLocationsForRenamingMessage,
RequestSourceLocationsForRenamingMessage
RequestSourceLocationsForRenamingMessage,
RequestSourceRangesAndDiagnosticsForQueryMessage,
SourceRangesAndDiagnosticsForQueryMessage
};
template<MessageType messageEnumeration>

View File

@@ -0,0 +1,59 @@
/****************************************************************************
**
** 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 "dynamicastmatcherdiagnosticcontainer.h"
namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticContainer &container)
{
debug.nospace() << "DynamicASTMatcherDiagnosticContextContainer("
<< container.messages() << ", "
<< container.contexts()
<< ")";
return debug;
}
void PrintTo(const DynamicASTMatcherDiagnosticContainer &container, ::std::ostream* os)
{
*os << "{[";
for (const auto &message : container.messages()) {
PrintTo(message, os);
*os << ", ";
}
*os << "], [";
for (const auto &context : container.contexts()) {
PrintTo(context, os);
*os << ", ";
}
*os << "]}";
}
} // namespace ClangBackEnd

View File

@@ -0,0 +1,103 @@
/****************************************************************************
**
** 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 "dynamicastmatcherdiagnosticmessagecontainer.h"
#include "dynamicastmatcherdiagnosticcontextcontainer.h"
namespace ClangBackEnd {
class DynamicASTMatcherDiagnosticContainer
{
public:
DynamicASTMatcherDiagnosticContainer() = default;
DynamicASTMatcherDiagnosticContainer(std::vector<DynamicASTMatcherDiagnosticMessageContainer> &&messages,
std::vector<DynamicASTMatcherDiagnosticContextContainer> &&contexts)
: messages_(std::move(messages)),
contexts_(std::move(contexts))
{
}
const std::vector<DynamicASTMatcherDiagnosticMessageContainer> &messages() const
{
return messages_;
}
const std::vector<DynamicASTMatcherDiagnosticContextContainer> &contexts() const
{
return contexts_;
}
void insertMessage(V2::SourceRangeContainer &&sourceRange,
ClangQueryDiagnosticErrorType errorType,
Utils::SmallStringVector &&arguments) {
messages_.emplace_back(std::move(sourceRange), errorType, std::move(arguments));
}
void insertContext(V2::SourceRangeContainer &&sourceRange,
ClangQueryDiagnosticContextType contextType,
Utils::SmallStringVector &&arguments) {
contexts_.emplace_back(std::move(sourceRange), contextType, std::move(arguments));
}
friend QDataStream &operator<<(QDataStream &out, const DynamicASTMatcherDiagnosticContainer &container)
{
out << container.messages_;
out << container.contexts_;
return out;
}
friend QDataStream &operator>>(QDataStream &in, DynamicASTMatcherDiagnosticContainer &container)
{
in >> container.messages_;
in >> container.contexts_;
return in;
}
friend bool operator==(const DynamicASTMatcherDiagnosticContainer &first,
const DynamicASTMatcherDiagnosticContainer &second)
{
return first.messages_ == second.messages_
&& first.contexts_ == second.contexts_;
}
DynamicASTMatcherDiagnosticContainer clone() const
{
return DynamicASTMatcherDiagnosticContainer(Utils::clone(messages_),
Utils::clone(contexts_));
}
private:
std::vector<DynamicASTMatcherDiagnosticMessageContainer> messages_;
std::vector<DynamicASTMatcherDiagnosticContextContainer> contexts_;
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticContainer &container);
void PrintTo(const DynamicASTMatcherDiagnosticContainer &container, ::std::ostream* os);
} // namespace ClangBackEnd

View File

@@ -0,0 +1,73 @@
/****************************************************************************
**
** 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 "dynamicastmatcherdiagnosticcontextcontainer.h"
namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticContextContainer &container)
{
debug.nospace() << "DynamicASTMatcherDiagnosticContextContainer("
<< container.sourceRange() << ", "
<< container.contextTypeText() << ", "
<< container.arguments()
<< ")";
return debug;
}
void PrintTo(const DynamicASTMatcherDiagnosticContextContainer &container, ::std::ostream* os)
{
*os << "{"
<< container.contextTypeText() << ": ";
PrintTo(container.sourceRange(), os);
*os << ", [";
for (const auto &argument : container.arguments()) {
PrintTo(argument, os);
*os << ", ";
}
*os << "]}";
}
#define RETURN_CASE(name) \
case ClangQueryDiagnosticContextType::name: return #name;
Utils::SmallString DynamicASTMatcherDiagnosticContextContainer::contextTypeText() const
{
switch (contextType_) {
RETURN_CASE(MatcherArg)
RETURN_CASE(MatcherConstruct)
}
Q_UNREACHABLE();
}
} // namespace ClangBackEnd

View File

@@ -0,0 +1,111 @@
/****************************************************************************
**
** 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 "dynamicmatcherdiagnostics.h"
#include "sourcerangecontainerv2.h"
#include <utils/smallstringio.h>
namespace ClangBackEnd {
class DynamicASTMatcherDiagnosticContextContainer
{
public:
DynamicASTMatcherDiagnosticContextContainer() = default;
DynamicASTMatcherDiagnosticContextContainer(V2::SourceRangeContainer &&sourceRange,
ClangQueryDiagnosticContextType contextType,
Utils::SmallStringVector &&arguments)
: sourceRange_(sourceRange),
contextType_(contextType),
arguments_(std::move(arguments))
{
}
const V2::SourceRangeContainer &sourceRange() const
{
return sourceRange_;
}
ClangQueryDiagnosticContextType contextType() const
{
return contextType_;
}
Utils::SmallString contextTypeText() const;
const Utils::SmallStringVector &arguments() const
{
return arguments_;
}
friend QDataStream &operator<<(QDataStream &out, const DynamicASTMatcherDiagnosticContextContainer &container)
{
out << container.sourceRange_;
out << quint32(container.contextType_);
out << container.arguments_;
return out;
}
friend QDataStream &operator>>(QDataStream &in, DynamicASTMatcherDiagnosticContextContainer &container)
{
quint32 contextType;
in >> container.sourceRange_;
in >> contextType;
in >> container.arguments_;
container.contextType_ = static_cast<ClangQueryDiagnosticContextType>(contextType);
return in;
}
friend bool operator==(const DynamicASTMatcherDiagnosticContextContainer &first,
const DynamicASTMatcherDiagnosticContextContainer &second)
{
return first.contextType_ == second.contextType_
&& first.sourceRange_ == second.sourceRange_
&& first.arguments_ == second.arguments_;
}
DynamicASTMatcherDiagnosticContextContainer clone() const
{
return DynamicASTMatcherDiagnosticContextContainer(sourceRange_.clone(),
contextType_,
arguments_.clone());
}
private:
V2::SourceRangeContainer sourceRange_;
ClangQueryDiagnosticContextType contextType_;
Utils::SmallStringVector arguments_;
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticContextContainer &container);
void PrintTo(const DynamicASTMatcherDiagnosticContextContainer &container, ::std::ostream* os);
} // namespace ClangBackEnd

View File

@@ -0,0 +1,87 @@
/****************************************************************************
**
** 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 "dynamicastmatcherdiagnosticmessagecontainer.h"
#define RETURN_CASE(name) \
case ClangQueryDiagnosticErrorType::name: return #name;
namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticMessageContainer &container)
{
debug.nospace() << "DynamicASTMatcherDiagnosticMessageContainer("
<< container.sourceRange() << ", "
<< container.errorTypeText() << ", "
<< container.arguments()
<< ")";
return debug;
}
void PrintTo(const DynamicASTMatcherDiagnosticMessageContainer &container, ::std::ostream* os)
{
*os << "{"
<< container.errorTypeText() << ": ";
PrintTo(container.sourceRange(), os);
*os << ", [";
for (const auto &argument : container.arguments()) {
PrintTo(argument, os);
*os << ", ";
}
*os << "]}";
}
Utils::SmallString DynamicASTMatcherDiagnosticMessageContainer::errorTypeText() const
{
switch (errorType_) {
RETURN_CASE(None)
RETURN_CASE(RegistryMatcherNotFound)
RETURN_CASE(RegistryWrongArgCount)
RETURN_CASE(RegistryWrongArgType)
RETURN_CASE(RegistryNotBindable)
RETURN_CASE(RegistryAmbiguousOverload)
RETURN_CASE(RegistryValueNotFound)
RETURN_CASE(ParserStringError)
RETURN_CASE(ParserNoOpenParen)
RETURN_CASE(ParserNoCloseParen)
RETURN_CASE(ParserNoComma)
RETURN_CASE(ParserNoCode)
RETURN_CASE(ParserNotAMatcher)
RETURN_CASE(ParserInvalidToken)
RETURN_CASE(ParserMalformedBindExpr)
RETURN_CASE(ParserTrailingCode)
RETURN_CASE(ParserUnsignedError)
RETURN_CASE(ParserOverloadedType)
}
Q_UNREACHABLE();
}
} // namespace ClangBackEnd

View File

@@ -0,0 +1,111 @@
/****************************************************************************
**
** 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 "dynamicmatcherdiagnostics.h"
#include "sourcerangecontainerv2.h"
#include <utils/smallstringio.h>
namespace ClangBackEnd {
class DynamicASTMatcherDiagnosticMessageContainer
{
public:
DynamicASTMatcherDiagnosticMessageContainer() = default;
DynamicASTMatcherDiagnosticMessageContainer(V2::SourceRangeContainer &&sourceRange,
ClangQueryDiagnosticErrorType errorType,
Utils::SmallStringVector &&arguments)
: sourceRange_(sourceRange),
errorType_(errorType),
arguments_(std::move(arguments))
{
}
const V2::SourceRangeContainer &sourceRange() const
{
return sourceRange_;
}
ClangQueryDiagnosticErrorType errorType() const
{
return errorType_;
}
Utils::SmallString errorTypeText() const;
const Utils::SmallStringVector &arguments() const
{
return arguments_;
}
friend QDataStream &operator<<(QDataStream &out, const DynamicASTMatcherDiagnosticMessageContainer &container)
{
out << container.sourceRange_;
out << quint32(container.errorType_);
out << container.arguments_;
return out;
}
friend QDataStream &operator>>(QDataStream &in, DynamicASTMatcherDiagnosticMessageContainer &container)
{
quint32 errorType;
in >> container.sourceRange_;
in >> errorType;
in >> container.arguments_;
container.errorType_ = static_cast<ClangQueryDiagnosticErrorType>(errorType);
return in;
}
friend bool operator==(const DynamicASTMatcherDiagnosticMessageContainer &first,
const DynamicASTMatcherDiagnosticMessageContainer &second)
{
return first.errorType_ == second.errorType_
&& first.sourceRange_ == second.sourceRange_
&& first.arguments_ == second.arguments_;
}
DynamicASTMatcherDiagnosticMessageContainer clone() const
{
return DynamicASTMatcherDiagnosticMessageContainer(sourceRange_.clone(),
errorType_,
arguments_.clone());
}
private:
V2::SourceRangeContainer sourceRange_;
ClangQueryDiagnosticErrorType errorType_;
Utils::SmallStringVector arguments_;
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const DynamicASTMatcherDiagnosticMessageContainer &container);
void PrintTo(const DynamicASTMatcherDiagnosticMessageContainer &container, ::std::ostream* os);
} // namespace ClangBackEnd

View File

@@ -0,0 +1,58 @@
/****************************************************************************
**
** 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
namespace ClangBackEnd {
enum class ClangQueryDiagnosticContextType {
MatcherArg,
MatcherConstruct
};
enum class ClangQueryDiagnosticErrorType {
None,
RegistryMatcherNotFound,
RegistryWrongArgCount,
RegistryWrongArgType,
RegistryNotBindable,
RegistryAmbiguousOverload,
RegistryValueNotFound,
ParserStringError,
ParserNoOpenParen,
ParserNoCloseParen,
ParserNoComma,
ParserNoCode,
ParserNotAMatcher,
ParserInvalidToken,
ParserMalformedBindExpr,
ParserTrailingCode,
ParserUnsignedError,
ParserOverloadedType
};
} // namespace ClangBackEnd

View File

@@ -0,0 +1,58 @@
/****************************************************************************
**
** 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 "filecontainerv2.h"
namespace ClangBackEnd {
namespace V2 {
QDebug operator<<(QDebug debug, const FileContainer &container)
{
debug.nospace() << "FileContainer("
<< container.filePath() << ", "
<< container.commandLineArguments() << ", "
<< container.documentRevision();
debug.nospace() << ")";
return debug;
}
void PrintTo(const FileContainer &container, ::std::ostream* os)
{
*os << "("
<< container.filePath() << ", "
<< container.commandLineArguments() << ", "
<< container.documentRevision();
if (container.unsavedFileContent().hasContent())
*os << ", \""
<< container.unsavedFileContent();
*os << "\")";
}
} // namespace V2
} // namespace ClangBackEnd

View File

@@ -0,0 +1,127 @@
/****************************************************************************
**
** 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"
#include "filepath.h"
namespace ClangBackEnd {
namespace V2 {
class FileContainer
{
public:
FileContainer() = default;
FileContainer(FilePath &&filePath,
Utils::SmallString &&unsavedFileContent,
Utils::SmallStringVector &&commandLineArguments,
quint32 documentRevision = 0)
: filePath_(std::move(filePath)),
unsavedFileContent_(std::move(unsavedFileContent)),
commandLineArguments_(std::move(commandLineArguments)),
documentRevision_(documentRevision)
{
}
const FilePath &filePath() const
{
return filePath_;
}
const Utils::SmallStringVector &commandLineArguments() const
{
return commandLineArguments_;
}
Utils::SmallStringVector takeCommandLineArguments()
{
return std::move(commandLineArguments_);
}
const Utils::SmallString &unsavedFileContent() const
{
return unsavedFileContent_;
}
Utils::SmallString takeUnsavedFileContent()
{
return std::move(unsavedFileContent_);
}
quint32 documentRevision() const
{
return documentRevision_;
}
friend QDataStream &operator<<(QDataStream &out, const FileContainer &container)
{
out << container.filePath_;
out << container.commandLineArguments_;
out << container.unsavedFileContent_;
out << container.documentRevision_;
return out;
}
friend QDataStream &operator>>(QDataStream &in, FileContainer &container)
{
in >> container.filePath_;
in >> container.commandLineArguments_;
in >> container.unsavedFileContent_;
in >> container.documentRevision_;
return in;
}
friend bool operator==(const FileContainer &first, const FileContainer &second)
{
return first.filePath_ == second.filePath_
&& first.commandLineArguments_ == second.commandLineArguments_;
}
FileContainer clone() const
{
return FileContainer(filePath_.clone(),
unsavedFileContent_.clone(),
commandLineArguments_.clone(),
documentRevision_);
}
private:
FilePath filePath_;
Utils::SmallString unsavedFileContent_;
Utils::SmallStringVector commandLineArguments_;
quint32 documentRevision_ = 0;
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const FileContainer &container);
void PrintTo(const FileContainer &container, ::std::ostream* os);
} // namespace V2
} // namespace ClangBackEnd

View File

@@ -27,15 +27,31 @@
#include "clangbackendipc_global.h"
#include <utils/smallstring.h>
#include <utils/smallstringio.h>
#include <QDataStream>
namespace ClangBackEnd {
struct FilePath
class FilePath
{
public:
FilePath() = default;
explicit FilePath(const QString &filePath)
{
Utils::SmallString utf8FilePath = filePath;
auto foundReverse = std::find(utf8FilePath.rbegin(), utf8FilePath.rend(), '/');
auto found = foundReverse.base();
Utils::SmallString fileName(found, utf8FilePath.end());
if (foundReverse != utf8FilePath.rend())
utf8FilePath.resize(std::size_t(std::distance(utf8FilePath.begin(), --found)));
directory_ = std::move(utf8FilePath);
name_ = std::move(fileName);
}
FilePath(Utils::SmallString &&directory, Utils::SmallString &&name)
: directory_(std::move(directory)),
name_(std::move(name))
@@ -46,11 +62,21 @@ public:
return directory_;
}
Utils::SmallString takeDirectory()
{
return std::move(directory_);
}
const Utils::SmallString &name() const
{
return name_;
}
Utils::SmallString takeName()
{
return std::move(name_);
}
friend QDataStream &operator<<(QDataStream &out, const FilePath &filePath)
{
out << filePath.directory_;
@@ -67,6 +93,13 @@ public:
return in;
}
friend std::ostream &operator<<(std::ostream &out, const FilePath &filePath)
{
out << filePath.directory() << "/" << filePath.name();
return out;
}
friend bool operator==(const FilePath &first, const FilePath &second)
{
return first.directory_ == second.directory_

View File

@@ -27,6 +27,7 @@
#include "messageenvelop.h"
#include "sourcelocationsforrenamingmessage.h"
#include "sourcerangesanddiagnosticsforquerymessage.h"
#include <QDebug>
@@ -41,6 +42,9 @@ void RefactoringClientInterface::dispatch(const MessageEnvelop &messageEnvelop)
case MessageType::SourceLocationsForRenamingMessage:
sourceLocationsForRenamingMessage(messageEnvelop.message<SourceLocationsForRenamingMessage>());
break;
case MessageType::SourceRangesAndDiagnosticsForQueryMessage:
sourceRangesAndDiagnosticsForQueryMessage(messageEnvelop.message<SourceRangesAndDiagnosticsForQueryMessage>());
break;
default:
qWarning() << "Unknown IpcClientMessage";
}

View File

@@ -32,6 +32,7 @@
namespace ClangBackEnd {
class SourceLocationsForRenamingMessage;
class SourceRangesAndDiagnosticsForQueryMessage;
class SourceLocationsContainer;
class CMBIPC_EXPORT RefactoringClientInterface : public IpcClientInterface
@@ -45,6 +46,7 @@ public:
virtual void alive() = 0;
virtual void sourceLocationsForRenamingMessage(SourceLocationsForRenamingMessage &&message) = 0;
virtual void sourceRangesAndDiagnosticsForQueryMessage(SourceRangesAndDiagnosticsForQueryMessage &&message) = 0;
virtual void setLocalRenamingCallback(RenameCallback &&localRenamingCallback) = 0;
};

View File

@@ -29,6 +29,7 @@
#include "messageenvelop.h"
#include "refactoringserverinterface.h"
#include "sourcelocationsforrenamingmessage.h"
#include "sourcerangesanddiagnosticsforquerymessage.h"
#include <QDebug>
#include <QIODevice>
@@ -79,4 +80,9 @@ void RefactoringClientProxy::sourceLocationsForRenamingMessage(SourceLocationsFo
writeMessageBlock.write(message);
}
void RefactoringClientProxy::sourceRangesAndDiagnosticsForQueryMessage(SourceRangesAndDiagnosticsForQueryMessage &&message)
{
writeMessageBlock.write(message);
}
} // namespace ClangBackEnd

View File

@@ -50,6 +50,7 @@ public:
void alive() override;
void sourceLocationsForRenamingMessage(SourceLocationsForRenamingMessage &&message) override;
void sourceRangesAndDiagnosticsForQueryMessage(SourceRangesAndDiagnosticsForQueryMessage &&message);
void setLocalRenamingCallback(RenameCallback &&) final {}

View File

@@ -27,6 +27,7 @@
#include "messageenvelop.h"
#include "requestsourcelocationforrenamingmessage.h"
#include "requestsourcerangesanddiagnosticsforquerymessage.h"
#include <QDebug>
@@ -41,6 +42,9 @@ void RefactoringServerInterface::dispatch(const MessageEnvelop &messageEnvelop)
case MessageType::RequestSourceLocationsForRenamingMessage:
requestSourceLocationsForRenamingMessage(messageEnvelop.message<RequestSourceLocationsForRenamingMessage>());
break;
case MessageType::RequestSourceRangesAndDiagnosticsForQueryMessage:
requestSourceRangesAndDiagnosticsForQueryMessage(messageEnvelop.message<RequestSourceRangesAndDiagnosticsForQueryMessage>());
break;
default:
qWarning() << "Unknown IpcClientMessage";
}

View File

@@ -33,6 +33,7 @@ namespace ClangBackEnd {
class RefactoringClientInterface;
class RequestSourceLocationsForRenamingMessage;
class RequestSourceRangesAndDiagnosticsForQueryMessage;
class CMBIPC_EXPORT RefactoringServerInterface : public IpcServerInterface<RefactoringClientInterface>
{
@@ -41,6 +42,19 @@ public:
virtual void end() = 0;
virtual void requestSourceLocationsForRenamingMessage(RequestSourceLocationsForRenamingMessage &&message) = 0;
virtual void requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message) = 0;
bool isUsable() const
{
return isUsable_;
}
void setUsable(bool isUsable)
{
isUsable_ = isUsable;
}
private:
bool isUsable_ = false;
};
} // namespace ClangBackEnd

View File

@@ -29,6 +29,7 @@
#include "messageenvelop.h"
#include "refactoringclientinterface.h"
#include "requestsourcelocationforrenamingmessage.h"
#include "requestsourcerangesanddiagnosticsforquerymessage.h"
#include <QIODevice>
#include <QVector>
@@ -50,7 +51,12 @@ void RefactoringServerProxy::end()
void RefactoringServerProxy::requestSourceLocationsForRenamingMessage(RequestSourceLocationsForRenamingMessage &&message)
{
writeMessageBlock.write(message);
writeMessageBlock.write(message);
}
void RefactoringServerProxy::requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message)
{
writeMessageBlock.write(message);
}
void RefactoringServerProxy::readMessages()

View File

@@ -51,6 +51,7 @@ public:
void end() override;
void requestSourceLocationsForRenamingMessage(ClangBackEnd::RequestSourceLocationsForRenamingMessage &&message) override;
void requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message);
void readMessages();

View File

@@ -40,15 +40,17 @@ QDebug operator<<(QDebug debug, const RequestSourceLocationsForRenamingMessage &
void PrintTo(const RequestSourceLocationsForRenamingMessage &message, ::std::ostream* os)
{
*os << "RequestSourceLocationsForRenamingMessage(";
PrintTo(message.filePath(), os);
*os << ", "
Q_UNUSED(message)
Q_UNUSED(os)
#ifdef UNIT_TESTS
*os << "RequestSourceLocationsForRenamingMessage("
<< ::testing::PrintToString(message.filePath()) << ", ("
<< message.line() << ", "
<< message.column() << ", ";
PrintTo(message.unsavedContent(), os);
*os << ", ";
PrintTo(message.commandLine(), os);
*os << ")";
<< message.column() << "), "
<< message.unsavedContent() << ", "
<< message.commandLine()
<< ")";
#endif
}
} // namespace ClangBackEnd

View File

@@ -0,0 +1,51 @@
/****************************************************************************
**
** 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 "requestsourcerangesanddiagnosticsforquerymessage.h"
namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const RequestSourceRangesAndDiagnosticsForQueryMessage &message)
{
debug.nospace() << "RequestSourceRangesAndDiagnosticsForQuery("
<< message.query() << ", "
<< message.fileContainers() << ")";
return debug;
}
void PrintTo(const RequestSourceRangesAndDiagnosticsForQueryMessage &message, ::std::ostream* os)
{
Q_UNUSED(message)
Q_UNUSED(os)
#ifdef UNIT_TESTS
*os << "RequestSourceRangesAndDiagnosticsForQuery("
<< message.query() << ", "
<< message.fileContainers()
<< ")";
#endif
}
} // namespace ClangBackEnd

View File

@@ -0,0 +1,104 @@
/****************************************************************************
**
** 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"
#include "filecontainerv2.h"
namespace ClangBackEnd {
class CMBIPC_EXPORT RequestSourceRangesAndDiagnosticsForQueryMessage
{
public:
RequestSourceRangesAndDiagnosticsForQueryMessage() = default;
RequestSourceRangesAndDiagnosticsForQueryMessage(Utils::SmallString &&query,
std::vector<V2::FileContainer> &&fileContainers)
: query_(std::move(query)),
fileContainers_(std::move(fileContainers))
{}
const std::vector<V2::FileContainer> &fileContainers() const
{
return fileContainers_;
}
std::vector<V2::FileContainer> takeFileContainers()
{
return std::move(fileContainers_);
}
const Utils::SmallString &query() const
{
return query_;
}
Utils::SmallString takeQuery()
{
return std::move(query_);
}
friend QDataStream &operator<<(QDataStream &out, const RequestSourceRangesAndDiagnosticsForQueryMessage &message)
{
out << message.query_;
out << message.fileContainers_;
return out;
}
friend QDataStream &operator>>(QDataStream &in, RequestSourceRangesAndDiagnosticsForQueryMessage &message)
{
in >> message.query_;
in >> message.fileContainers_;
return in;
}
friend bool operator==(const RequestSourceRangesAndDiagnosticsForQueryMessage &first,
const RequestSourceRangesAndDiagnosticsForQueryMessage &second)
{
return first.query_ == second.query_
&& first.fileContainers_ == second.fileContainers_;
}
RequestSourceRangesAndDiagnosticsForQueryMessage clone() const
{
return RequestSourceRangesAndDiagnosticsForQueryMessage(query_.clone(),
Utils::clone(fileContainers_));
}
private:
Utils::SmallString query_;
std::vector<V2::FileContainer> fileContainers_;
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const RequestSourceRangesAndDiagnosticsForQueryMessage &message);
void PrintTo(const RequestSourceRangesAndDiagnosticsForQueryMessage &message, ::std::ostream* os);
DECLARE_MESSAGE(RequestSourceRangesAndDiagnosticsForQueryMessage)
} // namespace ClangBackEnd

View File

@@ -0,0 +1,66 @@
/****************************************************************************
**
** 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 "filepath.h"
#include <unordered_map>
namespace ClangBackEnd {
using FilePathDict = std::unordered_map<uint, FilePath>;
class SourceFilePathContainerBase
{
public:
SourceFilePathContainerBase() = default;
SourceFilePathContainerBase(std::unordered_map<uint, FilePath> &&filePathHash)
: filePathHash(std::move(filePathHash))
{
}
void insertFilePath(uint fileId, Utils::SmallString &&fileDirectory, Utils::SmallString &&fileName)
{
filePathHash.emplace(std::piecewise_construct,
std::forward_as_tuple(fileId),
std::forward_as_tuple(std::move(fileDirectory), std::move(fileName)));
}
void reserve(std::size_t size)
{
filePathHash.reserve(size / 3);
}
const FilePathDict &filePaths() const
{
return filePathHash;
}
protected:
FilePathDict filePathHash;
};
} // namespace ClangBackEnd

View File

@@ -35,20 +35,22 @@ namespace V2 {
QDebug operator<<(QDebug debug, const SourceLocationContainer &container)
{
debug.nospace() << "SourceLocationContainer("
<< container.fileHash() << ", "
<< container.line() << ", "
<< container.column()
<< container.column() << ", "
<< container.offset() << ", "
<< container.fileHash()
<< ")";
return debug;
}
void PrintTo(const SourceLocationContainer &container, ::std::ostream* os)
{
*os << "["
<< container.fileHash() << ", "
*os << "("
<< container.line() << ", "
<< container.column()
<< "]";
<< container.column() << ", "
<< container.offset() << ", "
<< container.fileHash()
<< ")";
}
} // namespace V2

View File

@@ -39,10 +39,12 @@ public:
SourceLocationContainer() = default;
SourceLocationContainer(uint fileHash,
uint line,
uint column)
uint column,
uint offset)
: fileHash_(fileHash),
line_(line),
column_(column)
column_(column),
offset_(offset)
{
}
@@ -61,11 +63,17 @@ public:
return column_;
}
uint offset() const
{
return offset_;
}
friend QDataStream &operator<<(QDataStream &out, const SourceLocationContainer &container)
{
out << container.fileHash_;
out << container.line_;
out << container.column_;
out << container.offset_;
return out;
}
@@ -75,6 +83,7 @@ public:
in >> container.fileHash_;
in >> container.line_;
in >> container.column_;
in >> container.offset_;
return in;
}
@@ -88,18 +97,20 @@ public:
{
return first.line_ != second.line_
|| first.column_ != second.column_
|| first.fileHash_ != second.fileHash_;
|| first.fileHash_ != second.fileHash_
|| first.offset_ != second.offset_;
}
SourceLocationContainer clone() const
{
return SourceLocationContainer(fileHash_, line_, column_);
return SourceLocationContainer(fileHash_, line_, column_, offset_);
}
private:
uint fileHash_ = 0;
uint line_ = 1;
uint column_ = 1;
uint offset_ = 0;
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const SourceLocationContainer &container);

View File

@@ -46,12 +46,12 @@ QDebug operator<<(QDebug debug, const SourceLocationsContainer &container)
void PrintTo(const SourceLocationsContainer &container, ::std::ostream* os)
{
*os << "SourceLocationsContainer(";
*os << "(";
for (const auto &sourceLocation: container.sourceLocationContainers()) {
*os << "["
*os << "("
<< container.filePathForSourceLocation(sourceLocation).name() << ","
<< sourceLocation.line() << ","
<< sourceLocation.column() << "], ";
<< sourceLocation.column() << "), ";
}
*os << ")";
}

View File

@@ -25,22 +25,20 @@
#pragma once
#include "filepath.h"
#include "sourcefilepathcontainerbase.h"
#include "sourcelocationcontainerv2.h"
#include <utils/smallstringvector.h>
#include <unordered_map>
namespace ClangBackEnd {
class SourceLocationsContainer
class SourceLocationsContainer : public SourceFilePathContainerBase
{
public:
SourceLocationsContainer() = default;
SourceLocationsContainer(std::unordered_map<uint, FilePath> &&filePathHash,
std::vector<V2::SourceLocationContainer> &&sourceLocationContainers)
: filePathHash(std::move(filePathHash)),
: SourceFilePathContainerBase(std::move(filePathHash)),
sourceLocationContainers_(std::move(sourceLocationContainers))
{}
@@ -61,21 +59,14 @@ public:
return !sourceLocationContainers_.empty();
}
void insertFilePath(uint fileId, Utils::SmallString &&fileDirectory, Utils::SmallString &&fileName)
void insertSourceLocation(uint fileId, uint line, uint column, uint offset)
{
filePathHash.emplace(std::piecewise_construct,
std::forward_as_tuple(fileId),
std::forward_as_tuple(std::move(fileDirectory), std::move(fileName)));
}
void insertSourceLocation(uint fileId, uint line, uint column)
{
sourceLocationContainers_.emplace_back(fileId, line, column);
sourceLocationContainers_.emplace_back(fileId, line, column, offset);
}
void reserve(std::size_t size)
{
filePathHash.reserve(size / 3);
SourceFilePathContainerBase::reserve(size);
sourceLocationContainers_.reserve(size);
}
@@ -105,14 +96,6 @@ public:
return SourceLocationsContainer(Utils::clone(filePathHash), Utils::clone(sourceLocationContainers_));
}
const std::unordered_map<uint, FilePath> &filePathsForTestOnly() const
{
return filePathHash;
}
private:
std::unordered_map<uint, FilePath> filePathHash;
std::vector<V2::SourceLocationContainer> sourceLocationContainers_;
};

View File

@@ -93,7 +93,7 @@ public:
private:
Utils::SmallString symbolName_;
SourceLocationsContainer sourceLocationContainer;
int revision;
int revision = 0;
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const SourceLocationsForRenamingMessage &message);

View File

@@ -0,0 +1,56 @@
/****************************************************************************
**
** 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 "sourcerangecontainerv2.h"
#include <QDebug>
#include <ostream>
namespace ClangBackEnd {
namespace V2 {
QDebug operator<<(QDebug debug, const SourceRangeContainer &container)
{
debug.nospace() << "SourceRangeContainer("
<< container.start() << ", "
<< container.end()
<< ")";
return debug;
}
void PrintTo(const SourceRangeContainer &container, ::std::ostream* os)
{
*os << "(("
<< container.start().line() << ", "
<< container.start().column() << "), ("
<< container.end().line() << ", "
<< container.end().column()
<< "))";
}
} // namespace V2
} // namespace ClangBackEnd

View File

@@ -0,0 +1,105 @@
/****************************************************************************
**
** 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 "sourcelocationcontainerv2.h"
namespace ClangBackEnd {
namespace V2 {
class SourceRangeContainer
{
public:
SourceRangeContainer() = default;
SourceRangeContainer(SourceLocationContainer start,
SourceLocationContainer end)
: start_(start),
end_(end)
{
}
SourceRangeContainer(uint fileHash,
uint startLine,
uint startColumn,
uint startOffset,
uint endLine,
uint endColumn,
uint endOffset)
: start_(fileHash, startLine, startColumn, startOffset),
end_(fileHash, endLine, endColumn, endOffset)
{
}
SourceLocationContainer start() const
{
return start_;
}
SourceLocationContainer end() const
{
return end_;
}
uint fileHash() const
{
return start_.fileHash();
}
friend QDataStream &operator<<(QDataStream &out, const SourceRangeContainer &container)
{
out << container.start_;
out << container.end_;
return out;
}
friend QDataStream &operator>>(QDataStream &in, SourceRangeContainer &container)
{
in >> container.start_;
in >> container.end_;
return in;
}
friend bool operator==(const SourceRangeContainer &first, const SourceRangeContainer &second)
{
return first.start_ == second.start_ && first.end_ == second.end_;
}
SourceRangeContainer clone() const
{
return SourceRangeContainer(start_.clone(), end_.clone());
}
private:
SourceLocationContainer start_;
SourceLocationContainer end_;
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const SourceRangeContainer &container);
void PrintTo(const SourceRangeContainer &container, ::std::ostream* os);
} // namespace V2
} // namespace ClangBackEnd

View File

@@ -0,0 +1,50 @@
/****************************************************************************
**
** 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 "sourcerangesanddiagnosticsforquerymessage.h"
namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const SourceRangesAndDiagnosticsForQueryMessage &message)
{
debug.nospace() << "SourceRangesAndDiagnosticsForQueryMessage("
<< message.sourceRanges() << ", "
<< message.diagnostics() << ")";
return debug;
}
void PrintTo(const SourceRangesAndDiagnosticsForQueryMessage &message, ::std::ostream* os)
{
Q_UNUSED(message)
Q_UNUSED(os)
#ifdef UNIT_TESTS
*os << "SourceRangesAndDiagnosticsForQueryMessage("
<< testing::PrintToString(message.sourceRanges()) << ", "
<< testing::PrintToString(message.diagnostics()) << ")";
#endif
}
} // namespace ClangBackEnd

View File

@@ -0,0 +1,93 @@
/****************************************************************************
**
** 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 "sourcerangescontainer.h"
#include "dynamicastmatcherdiagnosticcontainer.h"
#include <utils/smallstring.h>
namespace ClangBackEnd {
class SourceRangesAndDiagnosticsForQueryMessage
{
public:
SourceRangesAndDiagnosticsForQueryMessage() = default;
SourceRangesAndDiagnosticsForQueryMessage(SourceRangesContainer &&sourceRangesContainer,
std::vector<DynamicASTMatcherDiagnosticContainer> &&diagnosticContainers)
: sourceRangesContainer(std::move(sourceRangesContainer)),
diagnosticContainers(std::move(diagnosticContainers))
{}
const SourceRangesContainer &sourceRanges() const
{
return sourceRangesContainer;
}
const std::vector<DynamicASTMatcherDiagnosticContainer> &diagnostics() const
{
return diagnosticContainers;
}
friend QDataStream &operator<<(QDataStream &out, const SourceRangesAndDiagnosticsForQueryMessage &message)
{
out << message.sourceRangesContainer;
out << message.diagnosticContainers;
return out;
}
friend QDataStream &operator>>(QDataStream &in, SourceRangesAndDiagnosticsForQueryMessage &message)
{
in >> message.sourceRangesContainer;
in >> message.diagnosticContainers;
return in;
}
friend bool operator==(const SourceRangesAndDiagnosticsForQueryMessage &first, const SourceRangesAndDiagnosticsForQueryMessage &second)
{
return first.sourceRangesContainer == second.sourceRangesContainer
&& first.diagnosticContainers == second.diagnosticContainers;
}
SourceRangesAndDiagnosticsForQueryMessage clone() const
{
return SourceRangesAndDiagnosticsForQueryMessage(sourceRangesContainer.clone(),
Utils::clone(diagnosticContainers));
}
private:
SourceRangesContainer sourceRangesContainer;
std::vector<DynamicASTMatcherDiagnosticContainer> diagnosticContainers;
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const SourceRangesAndDiagnosticsForQueryMessage &message);
void PrintTo(const SourceRangesAndDiagnosticsForQueryMessage &message, ::std::ostream* os);
DECLARE_MESSAGE(SourceRangesAndDiagnosticsForQueryMessage)
} // namespace ClangBackEnd

View File

@@ -0,0 +1,61 @@
/****************************************************************************
**
** 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 "sourcerangescontainer.h"
namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const SourceRangesContainer &container)
{
debug.nospace() << "SourceRangesContainer([";
for (const auto &sourceRangeWithText: container.sourceRangeWithTextContainers()) {
debug.nospace() << "["
<< container.filePathForSourceRange(sourceRangeWithText).name() << ", ("
<< sourceRangeWithText.start().line() << ","
<< sourceRangeWithText.start().column() << "), ("
<< sourceRangeWithText.end().line() << ","
<< sourceRangeWithText.end().column() << ")], ";
}
debug.nospace() << "])";
return debug;
}
void PrintTo(const SourceRangesContainer &container, ::std::ostream* os)
{
*os << "SourceRangesContainer(";
for (const auto &sourceRangeWithText: container.sourceRangeWithTextContainers()) {
*os << "["
<< container.filePathForSourceRange(sourceRangeWithText).name() << ","
<< sourceRangeWithText.start().line() << ","
<< sourceRangeWithText.start().column() << "), ("
<< sourceRangeWithText.end().line() << ","
<< sourceRangeWithText.end().column() << ")], ";
}
*os << ")";
}
} // namespace ClangBackEnd

View File

@@ -0,0 +1,125 @@
/****************************************************************************
**
** 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 "sourcefilepathcontainerbase.h"
#include "sourcerangewithtextcontainer.h"
#include <utils/smallstringvector.h>
namespace ClangBackEnd {
class SourceRangesContainer : public SourceFilePathContainerBase
{
public:
SourceRangesContainer() = default;
SourceRangesContainer(std::unordered_map<uint, FilePath> &&filePathHash,
std::vector<SourceRangeWithTextContainer> &&sourceRangeWithTextContainers)
: SourceFilePathContainerBase(std::move(filePathHash)),
sourceRangeWithTextContainers_(std::move(sourceRangeWithTextContainers))
{}
const FilePath &filePathForSourceRange(const SourceRangeWithTextContainer &sourceRange) const
{
auto found = filePathHash.find(sourceRange.fileHash());
return found->second;
}
const std::vector<SourceRangeWithTextContainer> &sourceRangeWithTextContainers() const
{
return sourceRangeWithTextContainers_;
}
std::vector<SourceRangeWithTextContainer> takeSourceRangeWithTextContainers()
{
return std::move(sourceRangeWithTextContainers_);
}
bool hasContent() const
{
return !sourceRangeWithTextContainers_.empty();
}
void insertSourceRange(uint fileId,
uint startLine,
uint startColumn,
uint startOffset,
uint endLine,
uint endColumn,
uint endOffset,
Utils::SmallString &&text)
{
sourceRangeWithTextContainers_.emplace_back(fileId,
startLine,
startColumn,
startOffset,
endLine,
endColumn,
endOffset,
std::move(text));
}
void reserve(std::size_t size)
{
SourceFilePathContainerBase::reserve(size);
sourceRangeWithTextContainers_.reserve(size);
}
friend QDataStream &operator<<(QDataStream &out, const SourceRangesContainer &container)
{
out << container.filePathHash;
out << container.sourceRangeWithTextContainers_;
return out;
}
friend QDataStream &operator>>(QDataStream &in, SourceRangesContainer &container)
{
in >> container.filePathHash;
in >> container.sourceRangeWithTextContainers_;
return in;
}
friend bool operator==(const SourceRangesContainer &first, const SourceRangesContainer &second)
{
return first.sourceRangeWithTextContainers_ == second.sourceRangeWithTextContainers_;
}
SourceRangesContainer clone() const
{
return SourceRangesContainer(Utils::clone(filePathHash), Utils::clone(sourceRangeWithTextContainers_));
}
std::vector<SourceRangeWithTextContainer> sourceRangeWithTextContainers_;
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const SourceRangesContainer &container);
void PrintTo(const SourceRangesContainer &container, ::std::ostream* os);
} // namespace ClangBackEnd

View File

@@ -0,0 +1,51 @@
/****************************************************************************
**
** 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 "sourcerangewithtextcontainer.h"
namespace ClangBackEnd {
QDebug operator<<(QDebug debug, const SourceRangeWithTextContainer &container)
{
debug.nospace() << "SourceRangeWithTextContainer("
<< container.start() << ", "
<< container.end() << ", "
<< container.text()
<< ")";
return debug;
}
void PrintTo(const SourceRangeWithTextContainer &container, ::std::ostream* os)
{
*os << "(("
<< container.start().line() << ", "
<< container.start().column() << "), ("
<< container.end().line() << ", "
<< container.end().column() << ", "
<< "\"" << container.text() << "\""
<< "))";
}
} // namespace ClangBackEnd

View File

@@ -0,0 +1,115 @@
/****************************************************************************
**
** 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 <sourcerangecontainerv2.h>
#include <utils/smallstringio.h>
namespace ClangBackEnd {
class SourceRangeWithTextContainer : V2::SourceRangeContainer
{
public:
SourceRangeWithTextContainer() = default;
SourceRangeWithTextContainer(uint fileHash,
uint startLine,
uint startColumn,
uint startOffset,
uint endLine,
uint endColumn,
uint endOffset,
Utils::SmallString &&text)
: V2::SourceRangeContainer(fileHash,
startLine,
startColumn,
startOffset,
endLine,
endColumn,
endOffset),
text_(std::move(text))
{}
SourceRangeWithTextContainer(V2::SourceRangeContainer &&base,
Utils::SmallString &&text)
: V2::SourceRangeContainer(std::move(base)),
text_(std::move(text))
{
}
const Utils::SmallString &text() const
{
return text_;
}
using V2::SourceRangeContainer::start;
using V2::SourceRangeContainer::end;
using V2::SourceRangeContainer::fileHash;
friend QDataStream &operator<<(QDataStream &out, const SourceRangeWithTextContainer &container)
{
out << container.base();
out << container.text_;
return out;
}
friend QDataStream &operator>>(QDataStream &in, SourceRangeWithTextContainer &container)
{
in >> container.base();
in >> container.text_;
return in;
}
friend bool operator==(const SourceRangeWithTextContainer &first,
const SourceRangeWithTextContainer &second)
{
return first.base() == second.base() && first.text_ == second.text_;
}
V2::SourceRangeContainer &base()
{
return *this;
}
const V2::SourceRangeContainer &base() const
{
return *this;
}
SourceRangeWithTextContainer clone() const
{
return SourceRangeWithTextContainer(base().clone(), text_.clone());
}
private:
Utils::SmallString text_;
};
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const SourceRangeWithTextContainer &container);
void PrintTo(const SourceRangeWithTextContainer &container, ::std::ostream* os);
} // namespace ClangBackEnd