2010-01-28 14:00:51 +08:00
|
|
|
/*===-- CIndexDiagnostic.h - Diagnostics C Interface ------------*- C++ -*-===*\
|
2010-01-28 08:27:43 +08:00
|
|
|
|* *|
|
2019-01-19 16:50:56 +08:00
|
|
|
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM *|
|
|
|
|
|* Exceptions. *|
|
|
|
|
|* See https://llvm.org/LICENSE.txt for license information. *|
|
|
|
|
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception *|
|
2010-01-28 08:27:43 +08:00
|
|
|
|* *|
|
|
|
|
|*===----------------------------------------------------------------------===*|
|
|
|
|
|* *|
|
|
|
|
|* Implements the diagnostic functions of the Clang C interface. *|
|
|
|
|
|* *|
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_LIBCLANG_CINDEXDIAGNOSTIC_H
|
|
|
|
#define LLVM_CLANG_TOOLS_LIBCLANG_CINDEXDIAGNOSTIC_H
|
2010-01-28 08:27:43 +08:00
|
|
|
|
2011-11-01 05:40:19 +08:00
|
|
|
#include "clang-c/Index.h"
|
2014-08-30 02:43:24 +08:00
|
|
|
#include <memory>
|
2011-11-10 16:43:12 +08:00
|
|
|
#include <vector>
|
|
|
|
#include <assert.h>
|
2011-11-01 05:40:19 +08:00
|
|
|
|
2010-01-28 08:27:43 +08:00
|
|
|
namespace clang {
|
|
|
|
|
2010-01-31 07:31:40 +08:00
|
|
|
class LangOptions;
|
2010-04-13 03:45:50 +08:00
|
|
|
class StoredDiagnostic;
|
2011-11-10 16:43:12 +08:00
|
|
|
class CXDiagnosticImpl;
|
|
|
|
|
|
|
|
class CXDiagnosticSetImpl {
|
2014-08-30 02:43:24 +08:00
|
|
|
std::vector<std::unique_ptr<CXDiagnosticImpl>> Diagnostics;
|
2011-11-10 16:43:12 +08:00
|
|
|
const bool IsExternallyManaged;
|
|
|
|
public:
|
|
|
|
CXDiagnosticSetImpl(bool isManaged = false)
|
|
|
|
: IsExternallyManaged(isManaged) {}
|
|
|
|
|
|
|
|
virtual ~CXDiagnosticSetImpl();
|
2014-08-30 02:43:24 +08:00
|
|
|
|
2011-11-10 16:43:12 +08:00
|
|
|
size_t getNumDiagnostics() const {
|
|
|
|
return Diagnostics.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
CXDiagnosticImpl *getDiagnostic(unsigned i) const {
|
|
|
|
assert(i < getNumDiagnostics());
|
2014-08-30 02:43:24 +08:00
|
|
|
return Diagnostics[i].get();
|
2011-11-10 16:43:12 +08:00
|
|
|
}
|
2014-08-30 02:43:24 +08:00
|
|
|
|
|
|
|
void appendDiagnostic(std::unique_ptr<CXDiagnosticImpl> D);
|
|
|
|
|
2011-11-10 16:43:12 +08:00
|
|
|
bool empty() const {
|
|
|
|
return Diagnostics.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isExternallyManaged() const { return IsExternallyManaged; }
|
|
|
|
};
|
2010-01-31 07:31:49 +08:00
|
|
|
|
2011-11-01 05:40:19 +08:00
|
|
|
class CXDiagnosticImpl {
|
|
|
|
public:
|
2012-02-14 10:46:03 +08:00
|
|
|
enum Kind { StoredDiagnosticKind, LoadedDiagnosticKind,
|
|
|
|
CustomNoteDiagnosticKind };
|
2011-11-01 05:40:19 +08:00
|
|
|
|
|
|
|
virtual ~CXDiagnosticImpl();
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the severity of the diagnostic.
|
2011-11-01 05:40:19 +08:00
|
|
|
virtual CXDiagnosticSeverity getSeverity() const = 0;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the location of the diagnostic.
|
2011-11-01 05:40:19 +08:00
|
|
|
virtual CXSourceLocation getLocation() const = 0;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the spelling of the diagnostic.
|
2011-11-01 05:40:19 +08:00
|
|
|
virtual CXString getSpelling() const = 0;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the text for the diagnostic option.
|
2011-11-01 05:40:19 +08:00
|
|
|
virtual CXString getDiagnosticOption(CXString *Disable) const = 0;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the category of the diagnostic.
|
2011-11-01 05:40:19 +08:00
|
|
|
virtual unsigned getCategory() const = 0;
|
2012-04-12 08:03:31 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the category string of the diagnostic.
|
2012-04-12 08:03:31 +08:00
|
|
|
virtual CXString getCategoryText() const = 0;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the number of source ranges for the diagnostic.
|
2011-11-01 05:40:19 +08:00
|
|
|
virtual unsigned getNumRanges() const = 0;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the source ranges for the diagnostic.
|
2011-11-01 05:40:19 +08:00
|
|
|
virtual CXSourceRange getRange(unsigned Range) const = 0;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the number of FixIts.
|
2011-11-01 05:40:19 +08:00
|
|
|
virtual unsigned getNumFixIts() const = 0;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the FixIt information (source range and inserted text).
|
2011-11-01 05:40:19 +08:00
|
|
|
virtual CXString getFixIt(unsigned FixIt,
|
|
|
|
CXSourceRange *ReplacementRange) const = 0;
|
|
|
|
|
|
|
|
Kind getKind() const { return K; }
|
2011-11-10 16:43:12 +08:00
|
|
|
|
|
|
|
CXDiagnosticSetImpl &getChildDiagnostics() {
|
|
|
|
return ChildDiags;
|
|
|
|
}
|
|
|
|
|
2011-11-01 05:40:19 +08:00
|
|
|
protected:
|
|
|
|
CXDiagnosticImpl(Kind k) : K(k) {}
|
2011-11-10 16:43:12 +08:00
|
|
|
CXDiagnosticSetImpl ChildDiags;
|
2014-08-30 02:43:24 +08:00
|
|
|
|
|
|
|
void append(std::unique_ptr<CXDiagnosticImpl> D) {
|
|
|
|
ChildDiags.appendDiagnostic(std::move(D));
|
2011-11-10 16:43:12 +08:00
|
|
|
}
|
2011-11-01 05:40:19 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
Kind K;
|
|
|
|
};
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// The storage behind a CXDiagnostic
|
2011-11-01 05:40:19 +08:00
|
|
|
struct CXStoredDiagnostic : public CXDiagnosticImpl {
|
2010-02-19 02:08:43 +08:00
|
|
|
const StoredDiagnostic &Diag;
|
|
|
|
const LangOptions &LangOpts;
|
|
|
|
|
|
|
|
CXStoredDiagnostic(const StoredDiagnostic &Diag,
|
|
|
|
const LangOptions &LangOpts)
|
2011-11-01 05:40:19 +08:00
|
|
|
: CXDiagnosticImpl(StoredDiagnosticKind),
|
|
|
|
Diag(Diag), LangOpts(LangOpts) { }
|
2015-04-11 10:00:23 +08:00
|
|
|
|
2015-10-20 21:23:58 +08:00
|
|
|
~CXStoredDiagnostic() override {}
|
2015-04-11 10:00:23 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the severity of the diagnostic.
|
2014-03-15 15:47:46 +08:00
|
|
|
CXDiagnosticSeverity getSeverity() const override;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the location of the diagnostic.
|
2014-03-15 15:47:46 +08:00
|
|
|
CXSourceLocation getLocation() const override;
|
2011-11-01 05:40:19 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the spelling of the diagnostic.
|
2014-03-15 15:47:46 +08:00
|
|
|
CXString getSpelling() const override;
|
2011-11-01 05:40:19 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the text for the diagnostic option.
|
2014-03-15 15:47:46 +08:00
|
|
|
CXString getDiagnosticOption(CXString *Disable) const override;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the category of the diagnostic.
|
2014-03-15 15:47:46 +08:00
|
|
|
unsigned getCategory() const override;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the category string of the diagnostic.
|
2014-03-15 15:47:46 +08:00
|
|
|
CXString getCategoryText() const override;
|
2012-04-12 08:03:31 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the number of source ranges for the diagnostic.
|
2014-03-15 15:47:46 +08:00
|
|
|
unsigned getNumRanges() const override;
|
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the source ranges for the diagnostic.
|
2014-03-15 15:47:46 +08:00
|
|
|
CXSourceRange getRange(unsigned Range) const override;
|
2011-11-01 05:40:19 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the number of FixIts.
|
2014-03-15 15:47:46 +08:00
|
|
|
unsigned getNumFixIts() const override;
|
2011-11-01 05:40:19 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Return the FixIt information (source range and inserted text).
|
2014-03-15 15:47:46 +08:00
|
|
|
CXString getFixIt(unsigned FixIt,
|
|
|
|
CXSourceRange *ReplacementRange) const override;
|
2011-11-01 05:40:19 +08:00
|
|
|
|
|
|
|
static bool classof(const CXDiagnosticImpl *D) {
|
|
|
|
return D->getKind() == StoredDiagnosticKind;
|
|
|
|
}
|
2010-01-28 08:27:43 +08:00
|
|
|
};
|
2010-01-28 14:00:51 +08:00
|
|
|
|
2011-12-01 10:42:50 +08:00
|
|
|
namespace cxdiag {
|
|
|
|
CXDiagnosticSetImpl *lazyCreateDiags(CXTranslationUnit TU,
|
|
|
|
bool checkIfChanged = false);
|
|
|
|
} // end namespace cxdiag
|
|
|
|
|
2010-01-28 08:27:43 +08:00
|
|
|
} // end namespace clang
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#endif
|