Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 1 | /*===-- CIndexDiagnostics.cpp - 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 | #include "CIndexDiagnostic.h" |
| 14 | #include "CIndexer.h" |
Ted Kremenek | 0a90d32 | 2010-11-17 23:24:11 +0000 | [diff] [blame] | 15 | #include "CXTranslationUnit.h" |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 16 | #include "CXSourceLocation.h" |
Ted Kremenek | ed12273 | 2010-11-16 01:56:27 +0000 | [diff] [blame] | 17 | #include "CXString.h" |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 18 | |
Benjamin Kramer | b846deb | 2010-04-12 19:45:50 +0000 | [diff] [blame] | 19 | #include "clang/Frontend/ASTUnit.h" |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 20 | #include "clang/Frontend/FrontendDiagnostic.h" |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallString.h" |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/Twine.h" |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 23 | #include "llvm/Support/MemoryBuffer.h" |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 25 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 26 | using namespace clang; |
| 27 | using namespace clang::cxloc; |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 28 | using namespace clang::cxstring; |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 29 | using namespace llvm; |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 30 | |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 31 | |
| 32 | CXDiagnosticSetImpl::~CXDiagnosticSetImpl() { |
| 33 | for (std::vector<CXDiagnosticImpl *>::iterator it = Diagnostics.begin(), |
| 34 | et = Diagnostics.end(); |
| 35 | it != et; ++it) { |
| 36 | delete *it; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | CXDiagnosticImpl::~CXDiagnosticImpl() {} |
| 41 | |
Argyrios Kyrtzidis | 220b45c | 2011-11-16 02:34:55 +0000 | [diff] [blame^] | 42 | static CXDiagnosticSetImpl *lazyCreateDiags(CXTranslationUnit TU, |
| 43 | bool checkIfChanged = false) { |
| 44 | ASTUnit *AU = static_cast<ASTUnit *>(TU->TUData); |
| 45 | |
| 46 | if (TU->Diagnostics && checkIfChanged) { |
| 47 | CXDiagnosticSetImpl * |
| 48 | Set = static_cast<CXDiagnosticSetImpl*>(TU->Diagnostics); |
| 49 | if (AU->stored_diag_size() != Set->getNumDiagnostics()) { |
| 50 | // Diagnostics in the ASTUnit were updated, reset the associated |
| 51 | // diagnostics. |
| 52 | delete Set; |
| 53 | TU->Diagnostics = 0; |
| 54 | } |
| 55 | } |
| 56 | |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 57 | if (!TU->Diagnostics) { |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 58 | CXDiagnosticSetImpl *Set = new CXDiagnosticSetImpl(); |
| 59 | TU->Diagnostics = Set; |
| 60 | |
| 61 | for (ASTUnit::stored_diag_iterator it = AU->stored_diag_begin(), |
| 62 | ei = AU->stored_diag_end(); it != ei; ++it) { |
| 63 | CXStoredDiagnostic *D = |
| 64 | new CXStoredDiagnostic(*it, AU->getASTContext().getLangOptions()); |
| 65 | Set->appendDiagnostic(D); |
| 66 | } |
| 67 | } |
| 68 | return static_cast<CXDiagnosticSetImpl*>(TU->Diagnostics); |
| 69 | } |
| 70 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 71 | //----------------------------------------------------------------------------- |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 72 | // C Interface Routines |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 73 | //----------------------------------------------------------------------------- |
| 74 | extern "C" { |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 75 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 76 | unsigned clang_getNumDiagnostics(CXTranslationUnit Unit) { |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 77 | if (!Unit->TUData) |
| 78 | return 0; |
Argyrios Kyrtzidis | 220b45c | 2011-11-16 02:34:55 +0000 | [diff] [blame^] | 79 | return lazyCreateDiags(Unit, /*checkIfChanged=*/true)->getNumDiagnostics(); |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, unsigned Index) { |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 83 | if (!Unit->TUData) |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 84 | return 0; |
| 85 | |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 86 | CXDiagnosticSetImpl *Diags = lazyCreateDiags(Unit); |
| 87 | if (Index >= Diags->getNumDiagnostics()) |
| 88 | return 0; |
| 89 | |
| 90 | return Diags->getDiagnostic(Index); |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void clang_disposeDiagnostic(CXDiagnostic Diagnostic) { |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 94 | // No-op. Kept as a legacy API. CXDiagnostics are now managed |
| 95 | // by the enclosing CXDiagnosticSet. |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 98 | CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, unsigned Options) { |
| 99 | if (!Diagnostic) |
| 100 | return createCXString(""); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 101 | |
| 102 | CXDiagnosticSeverity Severity = clang_getDiagnosticSeverity(Diagnostic); |
| 103 | |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 104 | llvm::SmallString<256> Str; |
| 105 | llvm::raw_svector_ostream Out(Str); |
| 106 | |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 107 | if (Options & CXDiagnostic_DisplaySourceLocation) { |
| 108 | // Print source location (file:line), along with optional column |
| 109 | // and source ranges. |
| 110 | CXFile File; |
| 111 | unsigned Line, Column; |
Douglas Gregor | a9b06d4 | 2010-11-09 06:24:54 +0000 | [diff] [blame] | 112 | clang_getSpellingLocation(clang_getDiagnosticLocation(Diagnostic), |
| 113 | &File, &Line, &Column, 0); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 114 | if (File) { |
| 115 | CXString FName = clang_getFileName(File); |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 116 | Out << clang_getCString(FName) << ":" << Line << ":"; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 117 | clang_disposeString(FName); |
| 118 | if (Options & CXDiagnostic_DisplayColumn) |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 119 | Out << Column << ":"; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 120 | |
| 121 | if (Options & CXDiagnostic_DisplaySourceRanges) { |
| 122 | unsigned N = clang_getDiagnosticNumRanges(Diagnostic); |
| 123 | bool PrintedRange = false; |
| 124 | for (unsigned I = 0; I != N; ++I) { |
| 125 | CXFile StartFile, EndFile; |
| 126 | CXSourceRange Range = clang_getDiagnosticRange(Diagnostic, I); |
| 127 | |
| 128 | unsigned StartLine, StartColumn, EndLine, EndColumn; |
Douglas Gregor | a9b06d4 | 2010-11-09 06:24:54 +0000 | [diff] [blame] | 129 | clang_getSpellingLocation(clang_getRangeStart(Range), |
| 130 | &StartFile, &StartLine, &StartColumn, |
| 131 | 0); |
| 132 | clang_getSpellingLocation(clang_getRangeEnd(Range), |
| 133 | &EndFile, &EndLine, &EndColumn, 0); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 134 | |
| 135 | if (StartFile != EndFile || StartFile != File) |
| 136 | continue; |
| 137 | |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 138 | Out << "{" << StartLine << ":" << StartColumn << "-" |
| 139 | << EndLine << ":" << EndColumn << "}"; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 140 | PrintedRange = true; |
| 141 | } |
| 142 | if (PrintedRange) |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 143 | Out << ":"; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 144 | } |
Douglas Gregor | 4cd912a | 2010-10-12 00:50:20 +0000 | [diff] [blame] | 145 | |
| 146 | Out << " "; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 147 | } |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /* Print warning/error/etc. */ |
| 151 | switch (Severity) { |
David Blaikie | eb2d1f1 | 2011-09-23 20:26:49 +0000 | [diff] [blame] | 152 | case CXDiagnostic_Ignored: llvm_unreachable("impossible"); |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 153 | case CXDiagnostic_Note: Out << "note: "; break; |
| 154 | case CXDiagnostic_Warning: Out << "warning: "; break; |
| 155 | case CXDiagnostic_Error: Out << "error: "; break; |
| 156 | case CXDiagnostic_Fatal: Out << "fatal error: "; break; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | CXString Text = clang_getDiagnosticSpelling(Diagnostic); |
| 160 | if (clang_getCString(Text)) |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 161 | Out << clang_getCString(Text); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 162 | else |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 163 | Out << "<no diagnostic text>"; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 164 | clang_disposeString(Text); |
Douglas Gregor | aa5f135 | 2010-11-19 16:18:16 +0000 | [diff] [blame] | 165 | |
| 166 | if (Options & (CXDiagnostic_DisplayOption | CXDiagnostic_DisplayCategoryId | |
| 167 | CXDiagnostic_DisplayCategoryName)) { |
| 168 | bool NeedBracket = true; |
| 169 | bool NeedComma = false; |
| 170 | |
| 171 | if (Options & CXDiagnostic_DisplayOption) { |
| 172 | CXString OptionName = clang_getDiagnosticOption(Diagnostic, 0); |
| 173 | if (const char *OptionText = clang_getCString(OptionName)) { |
| 174 | if (OptionText[0]) { |
| 175 | Out << " [" << OptionText; |
| 176 | NeedBracket = false; |
| 177 | NeedComma = true; |
| 178 | } |
| 179 | } |
| 180 | clang_disposeString(OptionName); |
| 181 | } |
| 182 | |
| 183 | if (Options & (CXDiagnostic_DisplayCategoryId | |
| 184 | CXDiagnostic_DisplayCategoryName)) { |
| 185 | if (unsigned CategoryID = clang_getDiagnosticCategory(Diagnostic)) { |
| 186 | if (Options & CXDiagnostic_DisplayCategoryId) { |
| 187 | if (NeedBracket) |
| 188 | Out << " ["; |
| 189 | if (NeedComma) |
| 190 | Out << ", "; |
| 191 | Out << CategoryID; |
| 192 | NeedBracket = false; |
| 193 | NeedComma = true; |
| 194 | } |
| 195 | |
| 196 | if (Options & CXDiagnostic_DisplayCategoryName) { |
| 197 | CXString CategoryName = clang_getDiagnosticCategoryName(CategoryID); |
| 198 | if (NeedBracket) |
| 199 | Out << " ["; |
| 200 | if (NeedComma) |
| 201 | Out << ", "; |
| 202 | Out << clang_getCString(CategoryName); |
| 203 | NeedBracket = false; |
| 204 | NeedComma = true; |
| 205 | clang_disposeString(CategoryName); |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | if (!NeedBracket) |
| 211 | Out << "]"; |
| 212 | } |
| 213 | |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 214 | return createCXString(Out.str(), true); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | unsigned clang_defaultDiagnosticDisplayOptions() { |
Douglas Gregor | aa5f135 | 2010-11-19 16:18:16 +0000 | [diff] [blame] | 218 | return CXDiagnostic_DisplaySourceLocation | CXDiagnostic_DisplayColumn | |
| 219 | CXDiagnostic_DisplayOption; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 222 | enum CXDiagnosticSeverity clang_getDiagnosticSeverity(CXDiagnostic Diag) { |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 223 | if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl*>(Diag)) |
| 224 | return D->getSeverity(); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 225 | return CXDiagnostic_Ignored; |
| 226 | } |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 227 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 228 | CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic Diag) { |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 229 | if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl*>(Diag)) |
| 230 | return D->getLocation(); |
| 231 | return clang_getNullLocation(); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | CXString clang_getDiagnosticSpelling(CXDiagnostic Diag) { |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 235 | if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag)) |
| 236 | return D->getSpelling(); |
| 237 | return createCXString(""); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Douglas Gregor | aa5f135 | 2010-11-19 16:18:16 +0000 | [diff] [blame] | 240 | CXString clang_getDiagnosticOption(CXDiagnostic Diag, CXString *Disable) { |
| 241 | if (Disable) |
| 242 | *Disable = createCXString(""); |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 243 | |
| 244 | if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag)) |
| 245 | return D->getDiagnosticOption(Disable); |
Douglas Gregor | aa5f135 | 2010-11-19 16:18:16 +0000 | [diff] [blame] | 246 | |
| 247 | return createCXString(""); |
| 248 | } |
| 249 | |
| 250 | unsigned clang_getDiagnosticCategory(CXDiagnostic Diag) { |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 251 | if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag)) |
| 252 | return D->getCategory(); |
| 253 | return 0; |
Douglas Gregor | aa5f135 | 2010-11-19 16:18:16 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | CXString clang_getDiagnosticCategoryName(unsigned Category) { |
| 257 | return createCXString(DiagnosticIDs::getCategoryNameFromID(Category)); |
| 258 | } |
| 259 | |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 260 | unsigned clang_getDiagnosticNumRanges(CXDiagnostic Diag) { |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 261 | if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag)) |
| 262 | return D->getNumRanges(); |
| 263 | return 0; |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 264 | } |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 265 | |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 266 | CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diag, unsigned Range) { |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 267 | CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag); |
| 268 | if (!D || Range >= D->getNumRanges()) |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 269 | return clang_getNullRange(); |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 270 | return D->getRange(Range); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diag) { |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 274 | if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag)) |
| 275 | return D->getNumFixIts(); |
| 276 | return 0; |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 279 | CXString clang_getDiagnosticFixIt(CXDiagnostic Diag, unsigned FixIt, |
Douglas Gregor | 473d701 | 2010-02-19 18:16:06 +0000 | [diff] [blame] | 280 | CXSourceRange *ReplacementRange) { |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 281 | CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag); |
| 282 | if (!D || FixIt >= D->getNumFixIts()) { |
Douglas Gregor | 473d701 | 2010-02-19 18:16:06 +0000 | [diff] [blame] | 283 | if (ReplacementRange) |
| 284 | *ReplacementRange = clang_getNullRange(); |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 285 | return createCXString(""); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 286 | } |
Ted Kremenek | 1edabbc | 2011-10-31 21:40:19 +0000 | [diff] [blame] | 287 | return D->getFixIt(FixIt, ReplacementRange); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 288 | } |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 289 | |
Ted Kremenek | 1532217 | 2011-11-10 08:43:12 +0000 | [diff] [blame] | 290 | void clang_disposeDiagnosticSet(CXDiagnosticSet Diags) { |
| 291 | CXDiagnosticSetImpl *D = static_cast<CXDiagnosticSetImpl*>(Diags); |
| 292 | if (D->isExternallyManaged()) |
| 293 | delete D; |
| 294 | } |
| 295 | |
| 296 | CXDiagnostic clang_getDiagnosticInSet(CXDiagnosticSet Diags, |
| 297 | unsigned Index) { |
| 298 | if (CXDiagnosticSetImpl *D = static_cast<CXDiagnosticSetImpl*>(Diags)) |
| 299 | if (Index < D->getNumDiagnostics()) |
| 300 | return D->getDiagnostic(Index); |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | CXDiagnosticSet clang_getChildDiagnostics(CXDiagnostic Diag) { |
| 305 | if (CXDiagnosticImpl *D = static_cast<CXDiagnosticImpl *>(Diag)) { |
| 306 | CXDiagnosticSetImpl &ChildDiags = D->getChildDiagnostics(); |
| 307 | return ChildDiags.empty() ? 0 : (CXDiagnosticSet) &ChildDiags; |
| 308 | } |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | unsigned clang_getNumDiagnosticsInSet(CXDiagnosticSet Diags) { |
| 313 | if (CXDiagnosticSetImpl *D = static_cast<CXDiagnosticSetImpl*>(Diags)) |
| 314 | return D->getNumDiagnostics(); |
| 315 | return 0; |
| 316 | } |
| 317 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 318 | } // end extern "C" |