blob: 46e535de903d7ccf52bfd589ae0658aa37f42a48 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- 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"
18using namespace clang;
19
20TextDiagnostics:: ~TextDiagnostics() {}
21
Chris Lattner07506182007-11-30 22:53:43 +000022std::string TextDiagnostics::FormatDiagnostic(Diagnostic &Diags,
23 Diagnostic::Level Level,
Reid Spencer5f016e22007-07-11 17:01:13 +000024 diag::kind ID,
25 const std::string *Strs,
26 unsigned NumStrs) {
Chris Lattner07506182007-11-30 22:53:43 +000027 std::string Msg = Diags.getDescription(ID);
Reid Spencer5f016e22007-07-11 17:01:13 +000028
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
42bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level,
Ted Kremenek7a9d49f2007-12-11 21:27:55 +000043 SourceLocation Pos,
44 SourceManager& SourceMgr) {
Reid Spencer5f016e22007-07-11 17:01:13 +000045 if (Pos.isValid()) {
46 // If this is a warning or note, and if it a system header, suppress the
47 // diagnostic.
Chris Lattner07506182007-11-30 22:53:43 +000048 if (Level == Diagnostic::Warning || Level == Diagnostic::Note) {
Chris Lattner9dc1f532007-07-20 16:37:10 +000049 if (const FileEntry *F = SourceMgr.getFileEntryForLoc(Pos)) {
Reid Spencer5f016e22007-07-11 17:01:13 +000050 DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
51 if (DirInfo == DirectoryLookup::SystemHeaderDir ||
52 DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
53 return true;
54 }
55 }
56 }
57
58 return false;
59}