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