1 /*===-- CIndexDiagnostic.h - Diagnostics C Interface ------------*- C++ -*-===*\
3 |* The LLVM Compiler Infrastructure *|
5 |* This file is distributed under the University of Illinois Open Source *|
6 |* License. See LICENSE.TXT for details. *|
8 |*===----------------------------------------------------------------------===*|
10 |* Implements the diagnostic functions of the Clang C interface. *|
12 \*===----------------------------------------------------------------------===*/
13 #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CINDEXDIAGNOSTIC_H
14 #define LLVM_CLANG_TOOLS_LIBCLANG_CINDEXDIAGNOSTIC_H
16 #include "clang-c/Index.h"
23 class StoredDiagnostic;
24 class CXDiagnosticImpl;
26 class CXDiagnosticSetImpl {
27 std::vector<CXDiagnosticImpl *> Diagnostics;
28 const bool IsExternallyManaged;
30 CXDiagnosticSetImpl(bool isManaged = false)
31 : IsExternallyManaged(isManaged) {}
33 virtual ~CXDiagnosticSetImpl();
35 size_t getNumDiagnostics() const {
36 return Diagnostics.size();
39 CXDiagnosticImpl *getDiagnostic(unsigned i) const {
40 assert(i < getNumDiagnostics());
41 return Diagnostics[i];
44 void appendDiagnostic(CXDiagnosticImpl *D) {
45 Diagnostics.push_back(D);
49 return Diagnostics.empty();
52 bool isExternallyManaged() const { return IsExternallyManaged; }
55 class CXDiagnosticImpl {
57 enum Kind { StoredDiagnosticKind, LoadedDiagnosticKind,
58 CustomNoteDiagnosticKind };
60 virtual ~CXDiagnosticImpl();
62 /// \brief Return the severity of the diagnostic.
63 virtual CXDiagnosticSeverity getSeverity() const = 0;
65 /// \brief Return the location of the diagnostic.
66 virtual CXSourceLocation getLocation() const = 0;
68 /// \brief Return the spelling of the diagnostic.
69 virtual CXString getSpelling() const = 0;
71 /// \brief Return the text for the diagnostic option.
72 virtual CXString getDiagnosticOption(CXString *Disable) const = 0;
74 /// \brief Return the category of the diagnostic.
75 virtual unsigned getCategory() const = 0;
77 /// \brief Return the category string of the diagnostic.
78 virtual CXString getCategoryText() const = 0;
80 /// \brief Return the number of source ranges for the diagnostic.
81 virtual unsigned getNumRanges() const = 0;
83 /// \brief Return the source ranges for the diagnostic.
84 virtual CXSourceRange getRange(unsigned Range) const = 0;
86 /// \brief Return the number of FixIts.
87 virtual unsigned getNumFixIts() const = 0;
89 /// \brief Return the FixIt information (source range and inserted text).
90 virtual CXString getFixIt(unsigned FixIt,
91 CXSourceRange *ReplacementRange) const = 0;
93 Kind getKind() const { return K; }
95 CXDiagnosticSetImpl &getChildDiagnostics() {
100 CXDiagnosticImpl(Kind k) : K(k) {}
101 CXDiagnosticSetImpl ChildDiags;
103 void append(CXDiagnosticImpl *D) {
104 ChildDiags.appendDiagnostic(D);
111 /// \brief The storage behind a CXDiagnostic
112 struct CXStoredDiagnostic : public CXDiagnosticImpl {
113 const StoredDiagnostic &Diag;
114 const LangOptions &LangOpts;
116 CXStoredDiagnostic(const StoredDiagnostic &Diag,
117 const LangOptions &LangOpts)
118 : CXDiagnosticImpl(StoredDiagnosticKind),
119 Diag(Diag), LangOpts(LangOpts) { }
121 virtual ~CXStoredDiagnostic() {}
123 /// \brief Return the severity of the diagnostic.
124 CXDiagnosticSeverity getSeverity() const override;
126 /// \brief Return the location of the diagnostic.
127 CXSourceLocation getLocation() const override;
129 /// \brief Return the spelling of the diagnostic.
130 CXString getSpelling() const override;
132 /// \brief Return the text for the diagnostic option.
133 CXString getDiagnosticOption(CXString *Disable) const override;
135 /// \brief Return the category of the diagnostic.
136 unsigned getCategory() const override;
138 /// \brief Return the category string of the diagnostic.
139 CXString getCategoryText() const override;
141 /// \brief Return the number of source ranges for the diagnostic.
142 unsigned getNumRanges() const override;
144 /// \brief Return the source ranges for the diagnostic.
145 CXSourceRange getRange(unsigned Range) const override;
147 /// \brief Return the number of FixIts.
148 unsigned getNumFixIts() const override;
150 /// \brief Return the FixIt information (source range and inserted text).
151 CXString getFixIt(unsigned FixIt,
152 CXSourceRange *ReplacementRange) const override;
154 static bool classof(const CXDiagnosticImpl *D) {
155 return D->getKind() == StoredDiagnosticKind;
160 CXDiagnosticSetImpl *lazyCreateDiags(CXTranslationUnit TU,
161 bool checkIfChanged = false);
162 } // end namespace cxdiag
164 } // end namespace clang