2015-08-31 16:28:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-08-31 16:28:26 +02:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:14 +01:00
|
|
|
** 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.
|
2015-08-31 16:28:26 +02:00
|
|
|
**
|
2016-01-15 14:57:14 +01:00
|
|
|
** 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.
|
2015-08-31 16:28:26 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "diagnostic.h"
|
|
|
|
|
|
|
|
|
|
#include "clangstring.h"
|
|
|
|
|
#include "diagnosticset.h"
|
|
|
|
|
#include "fixit.h"
|
|
|
|
|
#include "sourcelocation.h"
|
|
|
|
|
#include "sourcerange.h"
|
|
|
|
|
|
|
|
|
|
#include <diagnosticcontainer.h>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
namespace ClangBackEnd {
|
|
|
|
|
|
|
|
|
|
Diagnostic::Diagnostic(CXDiagnostic cxDiagnostic)
|
|
|
|
|
: cxDiagnostic(cxDiagnostic)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Diagnostic::~Diagnostic()
|
|
|
|
|
{
|
|
|
|
|
clang_disposeDiagnostic(cxDiagnostic);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Diagnostic::Diagnostic(Diagnostic &&other)
|
|
|
|
|
: cxDiagnostic(std::move(other.cxDiagnostic))
|
|
|
|
|
{
|
|
|
|
|
other.cxDiagnostic = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Diagnostic &Diagnostic::operator=(Diagnostic &&other)
|
|
|
|
|
{
|
|
|
|
|
if (this != &other) {
|
|
|
|
|
clang_disposeDiagnostic(cxDiagnostic);
|
|
|
|
|
cxDiagnostic = std::move(other.cxDiagnostic);
|
|
|
|
|
other.cxDiagnostic = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Diagnostic::isNull() const
|
|
|
|
|
{
|
|
|
|
|
return cxDiagnostic == nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utf8String Diagnostic::text() const
|
|
|
|
|
{
|
|
|
|
|
return ClangString(clang_formatDiagnostic(cxDiagnostic, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utf8String Diagnostic::category() const
|
|
|
|
|
{
|
|
|
|
|
return ClangString(clang_getDiagnosticCategoryText(cxDiagnostic));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::pair<Utf8String, Utf8String> Diagnostic::options() const
|
|
|
|
|
{
|
|
|
|
|
CXString disableString;
|
|
|
|
|
|
|
|
|
|
const Utf8String enableOption = ClangString(clang_getDiagnosticOption(cxDiagnostic, &disableString));
|
|
|
|
|
const Utf8String disableOption = ClangString(disableString);
|
|
|
|
|
|
|
|
|
|
return {enableOption, disableOption};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceLocation Diagnostic::location() const
|
|
|
|
|
{
|
|
|
|
|
return SourceLocation(clang_getDiagnosticLocation(cxDiagnostic));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DiagnosticSeverity Diagnostic::severity() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<DiagnosticSeverity>(clang_getDiagnosticSeverity(cxDiagnostic));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<SourceRange> Diagnostic::ranges() const
|
|
|
|
|
{
|
|
|
|
|
std::vector<SourceRange> ranges;
|
|
|
|
|
const uint rangesCount = clang_getDiagnosticNumRanges(cxDiagnostic);
|
|
|
|
|
ranges.reserve(rangesCount);
|
|
|
|
|
|
2015-11-02 10:39:08 +01:00
|
|
|
for (uint index = 0; index < rangesCount; ++index) {
|
|
|
|
|
const SourceRange sourceRange(clang_getDiagnosticRange(cxDiagnostic, index));
|
|
|
|
|
|
|
|
|
|
if (sourceRange.isValid())
|
2015-11-16 15:40:15 +01:00
|
|
|
ranges.push_back(std::move(sourceRange));
|
2015-11-02 10:39:08 +01:00
|
|
|
}
|
2015-08-31 16:28:26 +02:00
|
|
|
|
|
|
|
|
return ranges;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<FixIt> Diagnostic::fixIts() const
|
|
|
|
|
{
|
|
|
|
|
std::vector<FixIt> fixIts;
|
|
|
|
|
|
|
|
|
|
const uint fixItsCount = clang_getDiagnosticNumFixIts(cxDiagnostic);
|
|
|
|
|
|
|
|
|
|
fixIts.reserve(fixItsCount);
|
|
|
|
|
|
|
|
|
|
for (uint index = 0; index < fixItsCount; ++index)
|
|
|
|
|
fixIts.push_back(FixIt(cxDiagnostic, index));
|
|
|
|
|
|
|
|
|
|
return fixIts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DiagnosticSet Diagnostic::childDiagnostics() const
|
|
|
|
|
{
|
|
|
|
|
return DiagnosticSet(clang_getChildDiagnostics(cxDiagnostic));
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-29 17:17:18 +01:00
|
|
|
DiagnosticContainer Diagnostic::toDiagnosticContainer() const
|
2015-08-31 16:28:26 +02:00
|
|
|
{
|
|
|
|
|
return DiagnosticContainer(text(),
|
|
|
|
|
category(),
|
|
|
|
|
options(),
|
|
|
|
|
severity(),
|
|
|
|
|
location().toSourceLocationContainer(),
|
|
|
|
|
getSourceRangeContainers(),
|
|
|
|
|
getFixItContainers(),
|
2016-01-29 17:17:18 +01:00
|
|
|
childDiagnostics().toDiagnosticContainers());
|
2015-08-31 16:28:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<SourceRangeContainer> Diagnostic::getSourceRangeContainers() const
|
|
|
|
|
{
|
|
|
|
|
auto rangeVector = ranges();
|
|
|
|
|
|
|
|
|
|
QVector<SourceRangeContainer> sourceRangeContainers;
|
2016-07-08 09:43:39 +02:00
|
|
|
sourceRangeContainers.reserve(int(rangeVector.size()));
|
2015-08-31 16:28:26 +02:00
|
|
|
|
|
|
|
|
for (auto &&sourceRange : rangeVector)
|
|
|
|
|
sourceRangeContainers.push_back(sourceRange.toSourceRangeContainer());
|
|
|
|
|
|
|
|
|
|
return sourceRangeContainers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVector<FixItContainer> Diagnostic::getFixItContainers() const
|
|
|
|
|
{
|
|
|
|
|
auto fixItVector = fixIts();
|
|
|
|
|
|
|
|
|
|
QVector<FixItContainer> fixItContainers;
|
2016-07-08 09:43:39 +02:00
|
|
|
fixItContainers.reserve(int(fixItVector.size()));
|
2015-08-31 16:28:26 +02:00
|
|
|
|
|
|
|
|
for (auto &&fixIt : fixItVector)
|
|
|
|
|
fixItContainers.push_back(fixIt.toFixItContainer());
|
|
|
|
|
|
|
|
|
|
return fixItContainers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace ClangBackEnd
|
|
|
|
|
|