Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 1 | /*===-- CIndexDiagnostic.h - Diagnostics C Interface ------------*- C++ -*-===*\ |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 2 | |* *| |
| 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 Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 16 | #include "clang-c/Index.h" |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 17 | #include <vector> |
| 18 | #include <assert.h> |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 19 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 20 | namespace clang { |
| 21 | |
Daniel Dunbar | 35b8440 | 2010-01-30 23:31:40 +0000 | [diff] [blame] | 22 | class LangOptions; |
Benjamin Kramer | b846deb | 2010-04-12 19:45:50 +0000 | [diff] [blame] | 23 | class StoredDiagnostic; |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 24 | class CXDiagnosticImpl; |
| 25 | |
| 26 | class CXDiagnosticSetImpl { |
| 27 | std::vector<CXDiagnosticImpl *> Diagnostics; |
| 28 | const bool IsExternallyManaged; |
| 29 | public: |
| 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 Dunbar | 4914612 | 2010-01-30 23:31:49 +0000 | [diff] [blame] | 54 | |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 55 | class CXDiagnosticImpl { |
| 56 | public: |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 57 | enum Kind { StoredDiagnosticKind, LoadedDiagnosticKind }; |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 58 | |
| 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 Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 90 | |
| 91 | CXDiagnosticSetImpl &getChildDiagnostics() { |
| 92 | return ChildDiags; |
| 93 | } |
| 94 | |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 95 | protected: |
| 96 | CXDiagnosticImpl(Kind k) : K(k) {} |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 97 | CXDiagnosticSetImpl ChildDiags; |
| 98 | |
| 99 | void append(CXDiagnosticImpl *D) { |
| 100 | ChildDiags.appendDiagnostic(D); |
| 101 | } |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 102 | |
| 103 | private: |
| 104 | Kind K; |
| 105 | }; |
| 106 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 107 | /// \brief The storage behind a CXDiagnostic |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 108 | struct CXStoredDiagnostic : public CXDiagnosticImpl { |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 109 | const StoredDiagnostic &Diag; |
| 110 | const LangOptions &LangOpts; |
| 111 | |
| 112 | CXStoredDiagnostic(const StoredDiagnostic &Diag, |
| 113 | const LangOptions &LangOpts) |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 114 | : 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 Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 150 | }; |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 151 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 152 | } // end namespace clang |
| 153 | |
| 154 | #endif // LLVM_CLANG_CINDEX_DIAGNOSTIC_H |