Commit b278dc87 authored by Marco Bubke's avatar Marco Bubke

Clang: Add diagnostics

Diagnostics are now moved to the clang backend process. Fixits are
supported too.

Change-Id: I20faacf466bbf78dec479220c3d7b336a47bc453
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent 8dfa9a5d
......@@ -37,7 +37,13 @@ SOURCES += $$PWD/ipcserverinterface.cpp \
$$PWD/projectpartcontainer.cpp \
$$PWD/projectpartsdonotexistmessage.cpp \
$$PWD/lineprefixer.cpp \
$$PWD/clangbackendipcdebugutils.cpp
$$PWD/clangbackendipcdebugutils.cpp \
$$PWD/diagnosticschangedmessage.cpp \
$$PWD/diagnosticcontainer.cpp \
$$PWD/sourcerangecontainer.cpp \
$$PWD/sourcelocationcontainer.cpp \
$$PWD/fixitcontainer.cpp \
$$PWD/requestdiagnosticsmessage.cpp
HEADERS += \
$$PWD/ipcserverinterface.h \
......@@ -69,6 +75,12 @@ HEADERS += \
$$PWD/container_common.h \
$$PWD/clangbackendipc_global.h \
$$PWD/lineprefixer.h \
$$PWD/clangbackendipcdebugutils.h
$$PWD/clangbackendipcdebugutils.h \
$$PWD/diagnosticschangedmessage.h \
$$PWD/diagnosticcontainer.h \
$$PWD/sourcerangecontainer.h \
$$PWD/sourcelocationcontainer.h \
$$PWD/fixitcontainer.h \
$$PWD/requestdiagnosticsmessage.h
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols
......@@ -45,6 +45,14 @@
namespace ClangBackEnd {
CMBIPC_EXPORT void registerTypes();
}
enum class DiagnosticSeverity // one to one mapping of the clang enum numbers
{
Ignored = 0,
Note = 1,
Warning = 2,
Error = 3,
Fatal = 4
};
}
#endif // CLANGBACKENDIPC_GLOBAL_H
......@@ -39,7 +39,12 @@
#include "cmbunregisterprojectsforcodecompletionmessage.h"
#include "cmbcompletecodemessage.h"
#include "cmbcodecompletedmessage.h"
#include "diagnosticcontainer.h"
#include "diagnosticschangedmessage.h"
#include "requestdiagnosticsmessage.h"
#include "projectpartsdonotexistmessage.h"
#include "sourcelocationcontainer.h"
#include "sourcerangecontainer.h"
#include "translationunitdoesnotexistmessage.h"
#include <QDataStream>
......@@ -102,6 +107,26 @@ void Messages::registerMessages()
qRegisterMetaType<ProjectPartsDoNotExistMessage>();
qRegisterMetaTypeStreamOperators<ProjectPartsDoNotExistMessage>();
QMetaType::registerComparators<ProjectPartsDoNotExistMessage>();
qRegisterMetaType<DiagnosticsChangedMessage>();
qRegisterMetaTypeStreamOperators<DiagnosticsChangedMessage>();
QMetaType::registerComparators<DiagnosticsChangedMessage>();
qRegisterMetaType<DiagnosticContainer>();
qRegisterMetaTypeStreamOperators<DiagnosticContainer>();
QMetaType::registerComparators<DiagnosticContainer>();
qRegisterMetaType<SourceLocationContainer>();
qRegisterMetaTypeStreamOperators<SourceLocationContainer>();
QMetaType::registerComparators<SourceLocationContainer>();
qRegisterMetaType<SourceRangeContainer>();
qRegisterMetaTypeStreamOperators<SourceRangeContainer>();
QMetaType::registerComparators<SourceRangeContainer>();
qRegisterMetaType<RequestDiagnosticsMessage>();
qRegisterMetaTypeStreamOperators<RequestDiagnosticsMessage>();
QMetaType::registerComparators<RequestDiagnosticsMessage>();
}
} // namespace ClangBackEnd
......
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "diagnosticcontainer.h"
#include <QDataStream>
#include <QDebug>
namespace ClangBackEnd {
DiagnosticContainer::DiagnosticContainer(const Utf8String &text,
const Utf8String &category,
const std::pair<Utf8String,Utf8String> &options,
DiagnosticSeverity severity,
const SourceLocationContainer &location,
const QVector<SourceRangeContainer> &ranges,
const QVector<FixItContainer> &fixIts,
const QVector<DiagnosticContainer> &children)
: location_(location),
ranges_(ranges),
text_(text),
category_(category),
enableOption_(options.first),
disableOption_(options.second),
children_(children),
fixIts_(fixIts),
severity_(severity)
{
}
const Utf8String &DiagnosticContainer::text() const
{
return text_;
}
const Utf8String &DiagnosticContainer::category() const
{
return category_;
}
const Utf8String &DiagnosticContainer::enableOption() const
{
return enableOption_;
}
const Utf8String &DiagnosticContainer::disableOption() const
{
return disableOption_;
}
const SourceLocationContainer &DiagnosticContainer::location() const
{
return location_;
}
const QVector<SourceRangeContainer> &DiagnosticContainer::ranges() const
{
return ranges_;
}
DiagnosticSeverity DiagnosticContainer::severity() const
{
return severity_;
}
const QVector<FixItContainer> &DiagnosticContainer::fixIts() const
{
return fixIts_;
}
const QVector<DiagnosticContainer> &DiagnosticContainer::children() const
{
return children_;
}
quint32 &DiagnosticContainer::severityAsInt()
{
return reinterpret_cast<quint32&>(severity_);
}
QDataStream &operator<<(QDataStream &out, const DiagnosticContainer &container)
{
out << container.text_;
out << container.category_;
out << container.enableOption_;
out << container.disableOption_;
out << container.location_;
out << quint32(container.severity_);
out << container.ranges_;
out << container.fixIts_;
out << container.children_;
return out;
}
QDataStream &operator>>(QDataStream &in, DiagnosticContainer &container)
{
in >> container.text_;
in >> container.category_;
in >> container.enableOption_;
in >> container.disableOption_;
in >> container.location_;
in >> container.severityAsInt();
in >> container.ranges_;
in >> container.fixIts_;
in >> container.children_;
return in;
}
bool operator==(const DiagnosticContainer &first, const DiagnosticContainer &second)
{
return first.text_ == second.text_
&& first.location_ == second.location_;
}
bool operator<(const DiagnosticContainer &first, const DiagnosticContainer &second)
{
return first.text_ < second.text_
|| (first.text_ == second.text_ && first.location_ < second.location_);
}
static const char *severityToText(DiagnosticSeverity severity)
{
switch (severity) {
case DiagnosticSeverity::Ignored: return "Ignored";
case DiagnosticSeverity::Note: return "Note";
case DiagnosticSeverity::Warning: return "Warning";
case DiagnosticSeverity::Error: return "Error";
case DiagnosticSeverity::Fatal: return "Fatal";
}
Q_UNREACHABLE();
}
QDebug operator<<(QDebug debug, const DiagnosticContainer &container)
{
debug.nospace() << "DiagnosticContainer("
<< container.text() << ", "
<< container.category() << ", "
<< container.enableOption() << ", "
<< container.disableOption() << ", "
<< container.location() << ", "
<< container.ranges() << ", "
<< container.fixIts() << ", "
<< container.children()
<< ")";
return debug;
}
void PrintTo(const DiagnosticContainer &container, ::std::ostream* os)
{
*os << severityToText(container.severity()) << ": "
<< container.text().constData() << ", "
<< container.category().constData() << ", "
<< container.enableOption().constData() << ", ";
PrintTo(container.location(), os);
*os << "[";
for (const auto &range : container.ranges())
PrintTo(range, os);
*os << "], ";
*os << "[";
for (const auto &fixIt : container.fixIts())
PrintTo(fixIt, os);
*os << "], ";
*os << "[";
for (const auto &child : container.children())
PrintTo(child, os);
*os << "], ";
*os << ")";
}
} // namespace ClangBackEnd
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CLANGBACKEND_DIAGNOSTICCONTAINER_H
#define CLANGBACKEND_DIAGNOSTICCONTAINER_H
#include "sourcerangecontainer.h"
#include "fixitcontainer.h"
#include <QVector>
#include <utility>
namespace ClangBackEnd {
class CMBIPC_EXPORT DiagnosticContainer
{
friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const DiagnosticContainer &container);
friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, DiagnosticContainer &container);
friend CMBIPC_EXPORT bool operator==(const DiagnosticContainer &first, const DiagnosticContainer &second);
friend CMBIPC_EXPORT bool operator<(const DiagnosticContainer &first, const DiagnosticContainer &second);
public:
DiagnosticContainer() = default;
DiagnosticContainer(const Utf8String &text,
const Utf8String &category,
const std::pair<Utf8String,Utf8String> &options,
DiagnosticSeverity severity,
const SourceLocationContainer &location,
const QVector<SourceRangeContainer> &ranges,
const QVector<FixItContainer> &fixIts,
const QVector<DiagnosticContainer> &children);
const Utf8String &text() const;
const Utf8String &category() const;
const Utf8String &enableOption() const;
const Utf8String &disableOption() const;
const SourceLocationContainer &location() const;
const QVector<SourceRangeContainer> &ranges() const;
DiagnosticSeverity severity() const;
const QVector<FixItContainer> &fixIts() const;
const QVector<DiagnosticContainer> &children() const;
private:
quint32 &severityAsInt();
private:
SourceLocationContainer location_;
QVector<SourceRangeContainer> ranges_;
Utf8String text_;
Utf8String category_;
Utf8String enableOption_;
Utf8String disableOption_;
QVector<DiagnosticContainer> children_;
QVector<FixItContainer> fixIts_;
DiagnosticSeverity severity_;
};
CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const DiagnosticContainer &container);
CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, DiagnosticContainer &container);
CMBIPC_EXPORT bool operator==(const DiagnosticContainer &first, const DiagnosticContainer &second);
CMBIPC_EXPORT bool operator<(const DiagnosticContainer &first, const DiagnosticContainer &second);
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const DiagnosticContainer &container);
void PrintTo(const DiagnosticContainer &container, ::std::ostream* os);
} // namespace ClangBackEnd
Q_DECLARE_METATYPE(ClangBackEnd::DiagnosticContainer)
#endif // CLANGBACKEND_DIAGNOSTICCONTAINER_H
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "diagnosticschangedmessage.h"
#include "container_common.h"
#include <QDataStream>
#include <QDebug>
namespace ClangBackEnd {
DiagnosticsChangedMessage::DiagnosticsChangedMessage(const FileContainer &file,
const QVector<DiagnosticContainer> &diagnostics,
quint32 documentRevision)
: file_(file),
diagnostics_(diagnostics),
documentRevision_(documentRevision)
{
}
const FileContainer &DiagnosticsChangedMessage::file() const
{
return file_;
}
const QVector<DiagnosticContainer> &DiagnosticsChangedMessage::diagnostics() const
{
return diagnostics_;
}
quint32 DiagnosticsChangedMessage::documentRevision() const
{
return documentRevision_;
}
QDataStream &operator<<(QDataStream &out, const DiagnosticsChangedMessage &message)
{
out << message.file_;
out << message.diagnostics_;
out << message.documentRevision_;
return out;
}
QDataStream &operator>>(QDataStream &in, DiagnosticsChangedMessage &message)
{
in >> message.file_;
in >> message.diagnostics_;
in >> message.documentRevision_;
return in;
}
bool operator==(const DiagnosticsChangedMessage &first, const DiagnosticsChangedMessage &second)
{
return first.file_ == second.file_
&& first.diagnostics_ == second.diagnostics_;
}
bool operator<(const DiagnosticsChangedMessage &first, const DiagnosticsChangedMessage &second)
{
return first.file_ < second.file_
&& compareContainer(first.diagnostics_, second.diagnostics_);
}
QDebug operator<<(QDebug debug, const DiagnosticsChangedMessage &message)
{
debug.nospace() << "DiagnosticsChangedMessage("
<< message.file_ << QStringLiteral(", ")
<< message.documentRevision_
<< ")";
return debug;
}
void PrintTo(const DiagnosticsChangedMessage &message, ::std::ostream* os)
{
*os << "DiagnosticsChangedMessage(";
PrintTo(message.file(), os);
*os << ")";
}
} // namespace ClangBackEnd
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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 http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CLANGBACKEND_DIAGNOSTICSCHANGEDMESSAGE_H
#define CLANGBACKEND_DIAGNOSTICSCHANGEDMESSAGE_H
#include "clangbackendipc_global.h"
#include "diagnosticcontainer.h"
#include "filecontainer.h"
#include <QVector>
namespace ClangBackEnd {
class CMBIPC_EXPORT DiagnosticsChangedMessage
{
friend CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const DiagnosticsChangedMessage &message);
friend CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, DiagnosticsChangedMessage &message);
friend CMBIPC_EXPORT bool operator==(const DiagnosticsChangedMessage &first, const DiagnosticsChangedMessage &second);
friend CMBIPC_EXPORT bool operator<(const DiagnosticsChangedMessage &first, const DiagnosticsChangedMessage &second);
friend CMBIPC_EXPORT QDebug operator<<(QDebug debug, const DiagnosticsChangedMessage &message);
friend void PrintTo(const DiagnosticsChangedMessage &message, ::std::ostream* os);
public:
DiagnosticsChangedMessage() = default;
DiagnosticsChangedMessage(const FileContainer &file,
const QVector<DiagnosticContainer> &diagnostics,
quint32 documentRevision);
const FileContainer &file() const;
const QVector<DiagnosticContainer> &diagnostics() const;
quint32 documentRevision() const;
private:
FileContainer file_;
QVector<DiagnosticContainer> diagnostics_;
quint32 documentRevision_;
};
CMBIPC_EXPORT QDataStream &operator<<(QDataStream &out, const DiagnosticsChangedMessage &message);
CMBIPC_EXPORT QDataStream &operator>>(QDataStream &in, DiagnosticsChangedMessage &message);
CMBIPC_EXPORT bool operator==(const DiagnosticsChangedMessage &first, const DiagnosticsChangedMessage &second);
CMBIPC_EXPORT bool operator<(const DiagnosticsChangedMessage &first, const DiagnosticsChangedMessage &second);
CMBIPC_EXPORT QDebug operator<<(QDebug debug, const DiagnosticsChangedMessage &message);
void PrintTo(const DiagnosticsChangedMessage &message, ::std::ostream* os);
} // namespace ClangBackEnd
Q_DECLARE_METATYPE(ClangBackEnd::DiagnosticsChangedMessage)
#endif // CLANGBACKEND_DIAGNOSTICSCHANGEDMESSAGE_H
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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