Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- TextDiagnostics.cpp - Text Diagnostics Parent Class --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is the parent class for all text diagnostics. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "TextDiagnostics.h" |
| 15 | #include "clang/Basic/SourceLocation.h" |
| 16 | #include "clang/Basic/SourceManager.h" |
| 17 | #include "clang/Lex/HeaderSearch.h" |
| 18 | using namespace clang; |
| 19 | |
| 20 | TextDiagnostics:: ~TextDiagnostics() {} |
| 21 | |
Chris Lattner | 0750618 | 2007-11-30 22:53:43 +0000 | [diff] [blame] | 22 | std::string TextDiagnostics::FormatDiagnostic(Diagnostic &Diags, |
| 23 | Diagnostic::Level Level, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 24 | diag::kind ID, |
| 25 | const std::string *Strs, |
| 26 | unsigned NumStrs) { |
Chris Lattner | 0750618 | 2007-11-30 22:53:43 +0000 | [diff] [blame] | 27 | std::string Msg = Diags.getDescription(ID); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 28 | |
| 29 | // Replace all instances of %0 in Msg with 'Extra'. |
| 30 | for (unsigned i = 0; i < Msg.size() - 1; ++i) { |
| 31 | if (Msg[i] == '%' && isdigit(Msg[i + 1])) { |
| 32 | unsigned StrNo = Msg[i + 1] - '0'; |
| 33 | Msg = std::string(Msg.begin(), Msg.begin() + i) + |
| 34 | (StrNo < NumStrs ? Strs[StrNo] : "<<<INTERNAL ERROR>>>") + |
| 35 | std::string(Msg.begin() + i + 2, Msg.end()); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | return Msg; |
| 40 | } |
| 41 | |
Chris Lattner | 7097d91 | 2008-02-03 09:00:04 +0000 | [diff] [blame] | 42 | bool TextDiagnostics::isInSystemHeader(FullSourceLoc Pos) const { |
| 43 | if (!Pos.isValid()) return false; |
| 44 | |
| 45 | if (const FileEntry *F = Pos.getFileEntryForLoc()) { |
| 46 | DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F); |
| 47 | if (DirInfo == DirectoryLookup::SystemHeaderDir || |
| 48 | DirInfo == DirectoryLookup::ExternCSystemHeaderDir) |
| 49 | return true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | return false; |
| 53 | } |