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" |
| 15 | #include "CXSourceLocation.h" |
| 16 | |
Benjamin Kramer | b846deb | 2010-04-12 19:45:50 +0000 | [diff] [blame] | 17 | #include "clang/Frontend/ASTUnit.h" |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 18 | #include "clang/Frontend/FrontendDiagnostic.h" |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/SmallString.h" |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Twine.h" |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 21 | #include "llvm/Support/MemoryBuffer.h" |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 22 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 23 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | using namespace clang::cxloc; |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 26 | using namespace clang::cxstring; |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 27 | using namespace llvm; |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 28 | |
| 29 | //----------------------------------------------------------------------------- |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 30 | // C Interface Routines |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 31 | //----------------------------------------------------------------------------- |
| 32 | extern "C" { |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 33 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 34 | unsigned clang_getNumDiagnostics(CXTranslationUnit Unit) { |
| 35 | ASTUnit *CXXUnit = static_cast<ASTUnit *>(Unit); |
Douglas Gregor | 405634b | 2010-04-05 18:10:21 +0000 | [diff] [blame] | 36 | return CXXUnit? CXXUnit->stored_diag_size() : 0; |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | CXDiagnostic clang_getDiagnostic(CXTranslationUnit Unit, unsigned Index) { |
| 40 | ASTUnit *CXXUnit = static_cast<ASTUnit *>(Unit); |
Douglas Gregor | 405634b | 2010-04-05 18:10:21 +0000 | [diff] [blame] | 41 | if (!CXXUnit || Index >= CXXUnit->stored_diag_size()) |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 42 | return 0; |
| 43 | |
Douglas Gregor | 405634b | 2010-04-05 18:10:21 +0000 | [diff] [blame] | 44 | return new CXStoredDiagnostic(CXXUnit->stored_diag_begin()[Index], |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 45 | CXXUnit->getASTContext().getLangOptions()); |
| 46 | } |
| 47 | |
| 48 | void clang_disposeDiagnostic(CXDiagnostic Diagnostic) { |
| 49 | CXStoredDiagnostic *Stored = static_cast<CXStoredDiagnostic *>(Diagnostic); |
| 50 | delete Stored; |
| 51 | } |
| 52 | |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 53 | CXString clang_formatDiagnostic(CXDiagnostic Diagnostic, unsigned Options) { |
| 54 | if (!Diagnostic) |
| 55 | return createCXString(""); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 56 | |
| 57 | CXDiagnosticSeverity Severity = clang_getDiagnosticSeverity(Diagnostic); |
| 58 | |
| 59 | // Ignore diagnostics that should be ignored. |
| 60 | if (Severity == CXDiagnostic_Ignored) |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 61 | return createCXString(""); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 62 | |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 63 | llvm::SmallString<256> Str; |
| 64 | llvm::raw_svector_ostream Out(Str); |
| 65 | |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 66 | if (Options & CXDiagnostic_DisplaySourceLocation) { |
| 67 | // Print source location (file:line), along with optional column |
| 68 | // and source ranges. |
| 69 | CXFile File; |
| 70 | unsigned Line, Column; |
| 71 | clang_getInstantiationLocation(clang_getDiagnosticLocation(Diagnostic), |
| 72 | &File, &Line, &Column, 0); |
| 73 | if (File) { |
| 74 | CXString FName = clang_getFileName(File); |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 75 | Out << clang_getCString(FName) << ":" << Line << ":"; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 76 | clang_disposeString(FName); |
| 77 | if (Options & CXDiagnostic_DisplayColumn) |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 78 | Out << Column << ":"; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 79 | |
| 80 | if (Options & CXDiagnostic_DisplaySourceRanges) { |
| 81 | unsigned N = clang_getDiagnosticNumRanges(Diagnostic); |
| 82 | bool PrintedRange = false; |
| 83 | for (unsigned I = 0; I != N; ++I) { |
| 84 | CXFile StartFile, EndFile; |
| 85 | CXSourceRange Range = clang_getDiagnosticRange(Diagnostic, I); |
| 86 | |
| 87 | unsigned StartLine, StartColumn, EndLine, EndColumn; |
| 88 | clang_getInstantiationLocation(clang_getRangeStart(Range), |
| 89 | &StartFile, &StartLine, &StartColumn, |
| 90 | 0); |
| 91 | clang_getInstantiationLocation(clang_getRangeEnd(Range), |
| 92 | &EndFile, &EndLine, &EndColumn, 0); |
| 93 | |
| 94 | if (StartFile != EndFile || StartFile != File) |
| 95 | continue; |
| 96 | |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 97 | Out << "{" << StartLine << ":" << StartColumn << "-" |
| 98 | << EndLine << ":" << EndColumn << "}"; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 99 | PrintedRange = true; |
| 100 | } |
| 101 | if (PrintedRange) |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 102 | Out << ":"; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 106 | Out << " "; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /* Print warning/error/etc. */ |
| 110 | switch (Severity) { |
| 111 | case CXDiagnostic_Ignored: assert(0 && "impossible"); break; |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 112 | case CXDiagnostic_Note: Out << "note: "; break; |
| 113 | case CXDiagnostic_Warning: Out << "warning: "; break; |
| 114 | case CXDiagnostic_Error: Out << "error: "; break; |
| 115 | case CXDiagnostic_Fatal: Out << "fatal error: "; break; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | CXString Text = clang_getDiagnosticSpelling(Diagnostic); |
| 119 | if (clang_getCString(Text)) |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 120 | Out << clang_getCString(Text); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 121 | else |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 122 | Out << "<no diagnostic text>"; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 123 | clang_disposeString(Text); |
Douglas Gregor | 274f190 | 2010-02-22 23:17:23 +0000 | [diff] [blame] | 124 | return createCXString(Out.str(), true); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | unsigned clang_defaultDiagnosticDisplayOptions() { |
| 128 | return CXDiagnostic_DisplaySourceLocation | CXDiagnostic_DisplayColumn; |
| 129 | } |
| 130 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 131 | enum CXDiagnosticSeverity clang_getDiagnosticSeverity(CXDiagnostic Diag) { |
| 132 | CXStoredDiagnostic *StoredDiag = static_cast<CXStoredDiagnostic *>(Diag); |
| 133 | if (!StoredDiag) |
| 134 | return CXDiagnostic_Ignored; |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 135 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 136 | switch (StoredDiag->Diag.getLevel()) { |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 137 | case Diagnostic::Ignored: return CXDiagnostic_Ignored; |
| 138 | case Diagnostic::Note: return CXDiagnostic_Note; |
| 139 | case Diagnostic::Warning: return CXDiagnostic_Warning; |
| 140 | case Diagnostic::Error: return CXDiagnostic_Error; |
| 141 | case Diagnostic::Fatal: return CXDiagnostic_Fatal; |
| 142 | } |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 143 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 144 | llvm_unreachable("Invalid diagnostic level"); |
| 145 | return CXDiagnostic_Ignored; |
| 146 | } |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 147 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 148 | CXSourceLocation clang_getDiagnosticLocation(CXDiagnostic Diag) { |
| 149 | CXStoredDiagnostic *StoredDiag = static_cast<CXStoredDiagnostic *>(Diag); |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 150 | if (!StoredDiag || StoredDiag->Diag.getLocation().isInvalid()) |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 151 | return clang_getNullLocation(); |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 152 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 153 | return translateSourceLocation(StoredDiag->Diag.getLocation().getManager(), |
| 154 | StoredDiag->LangOpts, |
| 155 | StoredDiag->Diag.getLocation()); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | CXString clang_getDiagnosticSpelling(CXDiagnostic Diag) { |
| 159 | CXStoredDiagnostic *StoredDiag = static_cast<CXStoredDiagnostic *>(Diag); |
| 160 | if (!StoredDiag) |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 161 | return createCXString(""); |
| 162 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 163 | return createCXString(StoredDiag->Diag.getMessage(), false); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 166 | unsigned clang_getDiagnosticNumRanges(CXDiagnostic Diag) { |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 167 | CXStoredDiagnostic *StoredDiag = static_cast<CXStoredDiagnostic *>(Diag); |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 168 | if (!StoredDiag || StoredDiag->Diag.getLocation().isInvalid()) |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 169 | return 0; |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 170 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 171 | return StoredDiag->Diag.range_size(); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 172 | } |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 173 | |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 174 | CXSourceRange clang_getDiagnosticRange(CXDiagnostic Diag, unsigned Range) { |
| 175 | CXStoredDiagnostic *StoredDiag = static_cast<CXStoredDiagnostic *>(Diag); |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 176 | if (!StoredDiag || Range >= StoredDiag->Diag.range_size() || |
| 177 | StoredDiag->Diag.getLocation().isInvalid()) |
Douglas Gregor | a3890ba | 2010-02-08 23:11:56 +0000 | [diff] [blame] | 178 | return clang_getNullRange(); |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 179 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 180 | return translateSourceRange(StoredDiag->Diag.getLocation().getManager(), |
| 181 | StoredDiag->LangOpts, |
| 182 | StoredDiag->Diag.range_begin()[Range]); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | unsigned clang_getDiagnosticNumFixIts(CXDiagnostic Diag) { |
| 186 | CXStoredDiagnostic *StoredDiag = static_cast<CXStoredDiagnostic *>(Diag); |
| 187 | if (!StoredDiag) |
| 188 | return 0; |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 189 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 190 | return StoredDiag->Diag.fixit_size(); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Douglas Gregor | 473d701 | 2010-02-19 18:16:06 +0000 | [diff] [blame] | 193 | CXString clang_getDiagnosticFixIt(CXDiagnostic Diagnostic, unsigned FixIt, |
| 194 | CXSourceRange *ReplacementRange) { |
| 195 | CXStoredDiagnostic *StoredDiag |
| 196 | = static_cast<CXStoredDiagnostic *>(Diagnostic); |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 197 | if (!StoredDiag || FixIt >= StoredDiag->Diag.fixit_size() || |
| 198 | StoredDiag->Diag.getLocation().isInvalid()) { |
Douglas Gregor | 473d701 | 2010-02-19 18:16:06 +0000 | [diff] [blame] | 199 | if (ReplacementRange) |
| 200 | *ReplacementRange = clang_getNullRange(); |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 201 | |
| 202 | return createCXString(""); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 203 | } |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 204 | |
Douglas Gregor | 849b243 | 2010-03-31 17:46:05 +0000 | [diff] [blame] | 205 | const FixItHint &Hint = StoredDiag->Diag.fixit_begin()[FixIt]; |
Douglas Gregor | 473d701 | 2010-02-19 18:16:06 +0000 | [diff] [blame] | 206 | if (ReplacementRange) { |
| 207 | if (Hint.RemoveRange.isInvalid()) { |
| 208 | // Create an empty range that refers to a single source |
| 209 | // location (which is the insertion point). |
| 210 | CXSourceRange Range = { |
| 211 | { (void *)&StoredDiag->Diag.getLocation().getManager(), |
| 212 | (void *)&StoredDiag->LangOpts }, |
| 213 | Hint.InsertionLoc.getRawEncoding(), |
| 214 | Hint.InsertionLoc.getRawEncoding() |
| 215 | }; |
| 216 | |
| 217 | *ReplacementRange = Range; |
| 218 | } else { |
| 219 | // Create a range that covers the entire replacement (or |
| 220 | // removal) range, adjusting the end of the range to point to |
| 221 | // the end of the token. |
| 222 | *ReplacementRange |
| 223 | = translateSourceRange(StoredDiag->Diag.getLocation().getManager(), |
| 224 | StoredDiag->LangOpts, |
| 225 | Hint.RemoveRange); |
| 226 | } |
| 227 | } |
| 228 | |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 229 | return createCXString(Hint.CodeToInsert); |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 230 | } |
Ted Kremenek | ee4db4f | 2010-02-17 00:41:08 +0000 | [diff] [blame] | 231 | |
Douglas Gregor | 5352ac0 | 2010-01-28 00:27:43 +0000 | [diff] [blame] | 232 | } // end extern "C" |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 233 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 234 | void clang::LoadSerializedDiagnostics(const llvm::sys::Path &DiagnosticsPath, |
| 235 | unsigned num_unsaved_files, |
| 236 | struct CXUnsavedFile *unsaved_files, |
| 237 | FileManager &FileMgr, |
| 238 | SourceManager &SourceMgr, |
| 239 | SmallVectorImpl<StoredDiagnostic> &Diags) { |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 240 | using llvm::MemoryBuffer; |
| 241 | using llvm::StringRef; |
| 242 | MemoryBuffer *F = MemoryBuffer::getFile(DiagnosticsPath.c_str()); |
| 243 | if (!F) |
| 244 | return; |
| 245 | |
| 246 | // Enter the unsaved files into the file manager. |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 247 | for (unsigned I = 0; I != num_unsaved_files; ++I) { |
| 248 | const FileEntry *File = FileMgr.getVirtualFile(unsaved_files[I].Filename, |
| 249 | unsaved_files[I].Length, |
| 250 | 0); |
| 251 | if (!File) { |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 252 | // FIXME: Hard to localize when we have no diagnostics engine! |
| 253 | Diags.push_back(StoredDiagnostic(Diagnostic::Fatal, |
| 254 | (Twine("could not remap from missing file ") + |
| 255 | unsaved_files[I].Filename).str())); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 256 | delete F; |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 257 | return; |
| 258 | } |
| 259 | |
| 260 | MemoryBuffer *Buffer |
| 261 | = MemoryBuffer::getMemBuffer(unsaved_files[I].Contents, |
| 262 | unsaved_files[I].Contents + unsaved_files[I].Length); |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 263 | if (!Buffer) { |
| 264 | delete F; |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 265 | return; |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 268 | SourceMgr.overrideFileContents(File, Buffer); |
Douglas Gregor | f7353c0 | 2010-03-24 21:04:06 +0000 | [diff] [blame] | 269 | SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User); |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | // Parse the diagnostics, emitting them one by one until we've |
| 273 | // exhausted the data. |
| 274 | StringRef Buffer = F->getBuffer(); |
| 275 | const char *Memory = Buffer.data(), *MemoryEnd = Memory + Buffer.size(); |
| 276 | while (Memory != MemoryEnd) { |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 277 | StoredDiagnostic Stored = StoredDiagnostic::Deserialize(FileMgr, SourceMgr, |
| 278 | Memory, MemoryEnd); |
| 279 | if (!Stored) |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 280 | break; |
Daniel Dunbar | 35b8440 | 2010-01-30 23:31:40 +0000 | [diff] [blame] | 281 | |
Douglas Gregor | a88084b | 2010-02-18 18:08:43 +0000 | [diff] [blame] | 282 | Diags.push_back(Stored); |
| 283 | } |
Douglas Gregor | 0a812cf | 2010-02-18 23:07:20 +0000 | [diff] [blame] | 284 | delete F; |
Douglas Gregor | d93256e | 2010-01-28 06:00:51 +0000 | [diff] [blame] | 285 | } |