CIndexDiagnostic.h revision 153221717e39ce41323d5bc6b8b8bf130923c1bd
1/*===-- CIndexDiagnostic.h - Diagnostics C Interface ------------*- C++ -*-===*\ 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 16#include "clang-c/Index.h" 17#include <vector> 18#include <assert.h> 19 20namespace clang { 21 22class LangOptions; 23class StoredDiagnostic; 24class 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}; 54 55class CXDiagnosticImpl { 56public: 57 enum Kind { StoredDiagnosticKind, LoadedDiagnosticKind }; 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; } 90 91 CXDiagnosticSetImpl &getChildDiagnostics() { 92 return ChildDiags; 93 } 94 95protected: 96 CXDiagnosticImpl(Kind k) : K(k) {} 97 CXDiagnosticSetImpl ChildDiags; 98 99 void append(CXDiagnosticImpl *D) { 100 ChildDiags.appendDiagnostic(D); 101 } 102 103private: 104 Kind K; 105}; 106 107/// \brief The storage behind a CXDiagnostic 108struct CXStoredDiagnostic : public CXDiagnosticImpl { 109 const StoredDiagnostic &Diag; 110 const LangOptions &LangOpts; 111 112 CXStoredDiagnostic(const StoredDiagnostic &Diag, 113 const LangOptions &LangOpts) 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 } 150}; 151 152} // end namespace clang 153 154#endif // LLVM_CLANG_CINDEX_DIAGNOSTIC_H 155