2010-01-28 14:00:51 +08:00
|
|
|
/*===-- CIndexDiagnostic.h - Diagnostics C Interface ------------*- C++ -*-===*\
|
2010-01-28 08:27:43 +08:00
|
|
|
|* *|
|
|
|
|
|* The LLVM Compiler Infrastructure *|
|
|
|
|
|* *|
|
|
|
|
|* This file is distributed under the University of Illinois Open Source *|
|
|
|
|
|* License. See LICENSE.TXT for details. *|
|
|
|
|
|* *|
|
|
|
|
|*===----------------------------------------------------------------------===*|
|
|
|
|
|* *|
|
|
|
|
|* Implements the diagnostic functions of the Clang C interface. *|
|
|
|
|
|* *|
|
|
|
|
\*===----------------------------------------------------------------------===*/
|
|
|
|
#ifndef LLVM_CLANG_CINDEX_DIAGNOSTIC_H
|
|
|
|
#define LLVM_CLANG_CINDEX_DIAGNOSTIC_H
|
|
|
|
|
2011-11-01 05:40:19 +08:00
|
|
|
#include "clang-c/Index.h"
|
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 {
|
|
|
|
std::vector<CXDiagnosticImpl *> Diagnostics;
|
|
|
|
const bool IsExternallyManaged;
|
|
|
|
public:
|
|
|
|
CXDiagnosticSetImpl(bool isManaged = false)
|
|
|
|
: IsExternallyManaged(isManaged) {}
|
|
|
|
|
|
|
|
virtual ~CXDiagnosticSetImpl();
|
|
|
|
|
|
|
|
size_t getNumDiagnostics() const {
|
|
|
|
return Diagnostics.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
CXDiagnosticImpl *getDiagnostic(unsigned i) const {
|
|
|
|
assert(i < getNumDiagnostics());
|
|
|
|
return Diagnostics[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
void appendDiagnostic(CXDiagnosticImpl *D) {
|
|
|
|
Diagnostics.push_back(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2011-11-10 16:43:12 +08:00
|
|
|
enum Kind { StoredDiagnosticKind, LoadedDiagnosticKind };
|
2011-11-01 05:40:19 +08:00
|
|
|
|
|
|
|
virtual ~CXDiagnosticImpl();
|
|
|
|
|
|
|
|
/// \brief Return the severity of the diagnostic.
|
|
|
|
virtual CXDiagnosticSeverity getSeverity() const = 0;
|
|
|
|
|
|
|
|
/// \brief Return the location of the diagnostic.
|
|
|
|
virtual CXSourceLocation getLocation() const = 0;
|
|
|
|
|
|
|
|
/// \brief Return the spelling of the diagnostic.
|
|
|
|
virtual CXString getSpelling() const = 0;
|
|
|
|
|
|
|
|
/// \brief Return the text for the diagnostic option.
|
|
|
|
virtual CXString getDiagnosticOption(CXString *Disable) const = 0;
|
|
|
|
|
|
|
|
/// \brief Return the category of the diagnostic.
|
|
|
|
virtual unsigned getCategory() const = 0;
|
|
|
|
|
|
|
|
/// \brief Return the number of source ranges for the diagnostic.
|
|
|
|
virtual unsigned getNumRanges() const = 0;
|
|
|
|
|
|
|
|
/// \brief Return the source ranges for the diagnostic.
|
|
|
|
virtual CXSourceRange getRange(unsigned Range) const = 0;
|
|
|
|
|
|
|
|
/// \brief Return the number of FixIts.
|
|
|
|
virtual unsigned getNumFixIts() const = 0;
|
|
|
|
|
|
|
|
/// \brief Return the FixIt information (source range and inserted text).
|
|
|
|
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;
|
|
|
|
|
|
|
|
void append(CXDiagnosticImpl *D) {
|
|
|
|
ChildDiags.appendDiagnostic(D);
|
|
|
|
}
|
2011-11-01 05:40:19 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
Kind K;
|
|
|
|
};
|
|
|
|
|
2010-02-19 02:08:43 +08:00
|
|
|
/// \brief 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) { }
|
|
|
|
|
|
|
|
virtual ~CXStoredDiagnostic() {}
|
|
|
|
|
|
|
|
/// \brief Return the severity of the diagnostic.
|
|
|
|
virtual CXDiagnosticSeverity getSeverity() const;
|
|
|
|
|
|
|
|
/// \brief Return the location of the diagnostic.
|
|
|
|
virtual CXSourceLocation getLocation() const;
|
|
|
|
|
|
|
|
/// \brief Return the spelling of the diagnostic.
|
|
|
|
virtual CXString getSpelling() const;
|
|
|
|
|
|
|
|
/// \brief Return the text for the diagnostic option.
|
|
|
|
virtual CXString getDiagnosticOption(CXString *Disable) const;
|
|
|
|
|
|
|
|
/// \brief Return the category of the diagnostic.
|
|
|
|
virtual unsigned getCategory() const;
|
|
|
|
|
|
|
|
/// \brief Return the number of source ranges for the diagnostic.
|
|
|
|
virtual unsigned getNumRanges() const;
|
|
|
|
|
|
|
|
/// \brief Return the source ranges for the diagnostic.
|
|
|
|
virtual CXSourceRange getRange(unsigned Range) const;
|
|
|
|
|
|
|
|
/// \brief Return the number of FixIts.
|
|
|
|
virtual unsigned getNumFixIts() const;
|
|
|
|
|
|
|
|
/// \brief Return the FixIt information (source range and inserted text).
|
|
|
|
virtual CXString getFixIt(unsigned FixIt,
|
|
|
|
CXSourceRange *ReplacementRange) const;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_CINDEX_DIAGNOSTIC_H
|