blob: cc00cfe3469890d6aba326f4127ff9ea247adee0 [file] [log] [blame]
Douglas Gregord93256e2010-01-28 06:00:51 +00001/*===-- CIndexDiagnostic.h - Diagnostics C Interface ------------*- C++ -*-===*\
Douglas Gregor5352ac02010-01-28 00:27:43 +00002|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
5|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* Implements the diagnostic functions of the Clang C interface. *|
11|* *|
12\*===----------------------------------------------------------------------===*/
13#ifndef LLVM_CLANG_CINDEX_DIAGNOSTIC_H
14#define LLVM_CLANG_CINDEX_DIAGNOSTIC_H
15
Ted Kremenek1edabbc2011-10-31 21:40:19 +000016#include "clang-c/Index.h"
Ted Kremenek15322172011-11-10 08:43:12 +000017#include <vector>
18#include <assert.h>
Ted Kremenek1edabbc2011-10-31 21:40:19 +000019
Douglas Gregor5352ac02010-01-28 00:27:43 +000020namespace clang {
21
Daniel Dunbar35b84402010-01-30 23:31:40 +000022class LangOptions;
Benjamin Kramerb846deb2010-04-12 19:45:50 +000023class StoredDiagnostic;
Ted Kremenek15322172011-11-10 08:43:12 +000024class CXDiagnosticImpl;
25
26class CXDiagnosticSetImpl {
27 std::vector<CXDiagnosticImpl *> Diagnostics;
28 const bool IsExternallyManaged;
29public:
30 CXDiagnosticSetImpl(bool isManaged = false)
31 : IsExternallyManaged(isManaged) {}
32
33 virtual ~CXDiagnosticSetImpl();
34
35 size_t getNumDiagnostics() const {
36 return Diagnostics.size();
37 }
38
39 CXDiagnosticImpl *getDiagnostic(unsigned i) const {
40 assert(i < getNumDiagnostics());
41 return Diagnostics[i];
42 }
43
44 void appendDiagnostic(CXDiagnosticImpl *D) {
45 Diagnostics.push_back(D);
46 }
47
48 bool empty() const {
49 return Diagnostics.empty();
50 }
51
52 bool isExternallyManaged() const { return IsExternallyManaged; }
53};
Daniel Dunbar49146122010-01-30 23:31:49 +000054
Ted Kremenek1edabbc2011-10-31 21:40:19 +000055class CXDiagnosticImpl {
56public:
Ted Kremenek15322172011-11-10 08:43:12 +000057 enum Kind { StoredDiagnosticKind, LoadedDiagnosticKind };
Ted Kremenek1edabbc2011-10-31 21:40:19 +000058
59 virtual ~CXDiagnosticImpl();
60
61 /// \brief Return the severity of the diagnostic.
62 virtual CXDiagnosticSeverity getSeverity() const = 0;
63
64 /// \brief Return the location of the diagnostic.
65 virtual CXSourceLocation getLocation() const = 0;
66
67 /// \brief Return the spelling of the diagnostic.
68 virtual CXString getSpelling() const = 0;
69
70 /// \brief Return the text for the diagnostic option.
71 virtual CXString getDiagnosticOption(CXString *Disable) const = 0;
72
73 /// \brief Return the category of the diagnostic.
74 virtual unsigned getCategory() const = 0;
75
76 /// \brief Return the number of source ranges for the diagnostic.
77 virtual unsigned getNumRanges() const = 0;
78
79 /// \brief Return the source ranges for the diagnostic.
80 virtual CXSourceRange getRange(unsigned Range) const = 0;
81
82 /// \brief Return the number of FixIts.
83 virtual unsigned getNumFixIts() const = 0;
84
85 /// \brief Return the FixIt information (source range and inserted text).
86 virtual CXString getFixIt(unsigned FixIt,
87 CXSourceRange *ReplacementRange) const = 0;
88
89 Kind getKind() const { return K; }
Ted Kremenek15322172011-11-10 08:43:12 +000090
91 CXDiagnosticSetImpl &getChildDiagnostics() {
92 return ChildDiags;
93 }
94
Ted Kremenek1edabbc2011-10-31 21:40:19 +000095protected:
96 CXDiagnosticImpl(Kind k) : K(k) {}
Ted Kremenek15322172011-11-10 08:43:12 +000097 CXDiagnosticSetImpl ChildDiags;
98
99 void append(CXDiagnosticImpl *D) {
100 ChildDiags.appendDiagnostic(D);
101 }
Ted Kremenek1edabbc2011-10-31 21:40:19 +0000102
103private:
104 Kind K;
105};
106
Douglas Gregora88084b2010-02-18 18:08:43 +0000107/// \brief The storage behind a CXDiagnostic
Ted Kremenek1edabbc2011-10-31 21:40:19 +0000108struct CXStoredDiagnostic : public CXDiagnosticImpl {
Douglas Gregora88084b2010-02-18 18:08:43 +0000109 const StoredDiagnostic &Diag;
110 const LangOptions &LangOpts;
111
112 CXStoredDiagnostic(const StoredDiagnostic &Diag,
113 const LangOptions &LangOpts)
Ted Kremenek1edabbc2011-10-31 21:40:19 +0000114 : CXDiagnosticImpl(StoredDiagnosticKind),
115 Diag(Diag), LangOpts(LangOpts) { }
116
117 virtual ~CXStoredDiagnostic() {}
118
119 /// \brief Return the severity of the diagnostic.
120 virtual CXDiagnosticSeverity getSeverity() const;
121
122 /// \brief Return the location of the diagnostic.
123 virtual CXSourceLocation getLocation() const;
124
125 /// \brief Return the spelling of the diagnostic.
126 virtual CXString getSpelling() const;
127
128 /// \brief Return the text for the diagnostic option.
129 virtual CXString getDiagnosticOption(CXString *Disable) const;
130
131 /// \brief Return the category of the diagnostic.
132 virtual unsigned getCategory() const;
133
134 /// \brief Return the number of source ranges for the diagnostic.
135 virtual unsigned getNumRanges() const;
136
137 /// \brief Return the source ranges for the diagnostic.
138 virtual CXSourceRange getRange(unsigned Range) const;
139
140 /// \brief Return the number of FixIts.
141 virtual unsigned getNumFixIts() const;
142
143 /// \brief Return the FixIt information (source range and inserted text).
144 virtual CXString getFixIt(unsigned FixIt,
145 CXSourceRange *ReplacementRange) const;
146
147 static bool classof(const CXDiagnosticImpl *D) {
148 return D->getKind() == StoredDiagnosticKind;
149 }
Douglas Gregor5352ac02010-01-28 00:27:43 +0000150};
Douglas Gregord93256e2010-01-28 06:00:51 +0000151
Douglas Gregor5352ac02010-01-28 00:27:43 +0000152} // end namespace clang
153
154#endif // LLVM_CLANG_CINDEX_DIAGNOSTIC_H