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 | // |
| 5 | // This file was developed by Bill Wendling and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 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 | |
| 22 | std::string TextDiagnostics::FormatDiagnostic(Diagnostic::Level Level, |
| 23 | diag::kind ID, |
| 24 | const std::string *Strs, |
| 25 | unsigned NumStrs) { |
| 26 | std::string Msg = Diagnostic::getDescription(ID); |
| 27 | |
| 28 | // Replace all instances of %0 in Msg with 'Extra'. |
| 29 | for (unsigned i = 0; i < Msg.size() - 1; ++i) { |
| 30 | if (Msg[i] == '%' && isdigit(Msg[i + 1])) { |
| 31 | unsigned StrNo = Msg[i + 1] - '0'; |
| 32 | Msg = std::string(Msg.begin(), Msg.begin() + i) + |
| 33 | (StrNo < NumStrs ? Strs[StrNo] : "<<<INTERNAL ERROR>>>") + |
| 34 | std::string(Msg.begin() + i + 2, Msg.end()); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return Msg; |
| 39 | } |
| 40 | |
| 41 | bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level, |
| 42 | SourceLocation Pos) { |
| 43 | if (Pos.isValid()) { |
| 44 | // If this is a warning or note, and if it a system header, suppress the |
| 45 | // diagnostic. |
| 46 | if (Level == Diagnostic::Warning || |
| 47 | Level == Diagnostic::Note) { |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 48 | if (const FileEntry *F = SourceMgr.getFileEntryForLoc(Pos)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 49 | DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F); |
| 50 | if (DirInfo == DirectoryLookup::SystemHeaderDir || |
| 51 | DirInfo == DirectoryLookup::ExternCSystemHeaderDir) |
| 52 | return true; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return false; |
| 58 | } |