2007-06-14 01:45:37 +08:00
|
|
|
//===--- TextDiagnostics.cpp - Text Diagnostics Parent Class --------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-14 01:45:37 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This is the parent class for all text diagnostics.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "TextDiagnostics.h"
|
|
|
|
#include "clang/Basic/SourceLocation.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
|
|
|
#include "clang/Lex/HeaderSearch.h"
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
TextDiagnostics:: ~TextDiagnostics() {}
|
|
|
|
|
2007-12-01 06:53:43 +08:00
|
|
|
std::string TextDiagnostics::FormatDiagnostic(Diagnostic &Diags,
|
|
|
|
Diagnostic::Level Level,
|
2007-06-14 01:45:37 +08:00
|
|
|
diag::kind ID,
|
|
|
|
const std::string *Strs,
|
|
|
|
unsigned NumStrs) {
|
2007-12-01 06:53:43 +08:00
|
|
|
std::string Msg = Diags.getDescription(ID);
|
2007-06-14 01:45:37 +08:00
|
|
|
|
|
|
|
// Replace all instances of %0 in Msg with 'Extra'.
|
|
|
|
for (unsigned i = 0; i < Msg.size() - 1; ++i) {
|
|
|
|
if (Msg[i] == '%' && isdigit(Msg[i + 1])) {
|
|
|
|
unsigned StrNo = Msg[i + 1] - '0';
|
|
|
|
Msg = std::string(Msg.begin(), Msg.begin() + i) +
|
|
|
|
(StrNo < NumStrs ? Strs[StrNo] : "<<<INTERNAL ERROR>>>") +
|
|
|
|
std::string(Msg.begin() + i + 2, Msg.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Msg;
|
|
|
|
}
|
|
|
|
|
2008-02-03 17:00:04 +08:00
|
|
|
bool TextDiagnostics::isInSystemHeader(FullSourceLoc Pos) const {
|
|
|
|
if (!Pos.isValid()) return false;
|
|
|
|
|
|
|
|
if (const FileEntry *F = Pos.getFileEntryForLoc()) {
|
|
|
|
DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
|
|
|
|
if (DirInfo == DirectoryLookup::SystemHeaderDir ||
|
|
|
|
DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
|
|
|
|
return true;
|
2007-06-14 01:45:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|