summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/Driver/TextDiagnosticPrinter.cpp34
-rw-r--r--clang/Driver/TextDiagnosticPrinter.h16
-rw-r--r--clang/Driver/TextDiagnostics.cpp61
-rw-r--r--clang/Driver/TextDiagnostics.h55
4 files changed, 120 insertions, 46 deletions
diff --git a/clang/Driver/TextDiagnosticPrinter.cpp b/clang/Driver/TextDiagnosticPrinter.cpp
index 38290823084..8478c58e898 100644
--- a/clang/Driver/TextDiagnosticPrinter.cpp
+++ b/clang/Driver/TextDiagnosticPrinter.cpp
@@ -121,27 +121,6 @@ unsigned TextDiagnosticPrinter::GetTokenLength(SourceLocation Loc) {
return TheTok.getLength();
}
-bool TextDiagnosticPrinter::IgnoreDiagnostic(Diagnostic::Level Level,
- SourceLocation Pos) {
- if (Pos.isValid()) {
- // If this is a warning or note, and if it a system header, suppress the
- // diagnostic.
- if (Level == Diagnostic::Warning ||
- Level == Diagnostic::Note) {
- SourceLocation PhysLoc = SourceMgr.getPhysicalLoc(Pos);
- const FileEntry *F = SourceMgr.getFileEntryForFileID(PhysLoc.getFileID());
- if (F) {
- DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
- if (DirInfo == DirectoryLookup::SystemHeaderDir ||
- DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
- return true;
- }
- }
- }
-
- return false;
-}
-
void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
SourceLocation Pos,
diag::kind ID,
@@ -197,18 +176,7 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
break;
}
- std::string Msg = Diagnostic::getDescription(ID);
-
- // 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());
- }
- }
- cerr << Msg << "\n";
+ cerr << FormatDiagnostic(Level, ID, Strs, NumStrs) << "\n";
if (!NoCaretDiagnostics && Pos.isValid()) {
// Get the line of the source file.
diff --git a/clang/Driver/TextDiagnosticPrinter.h b/clang/Driver/TextDiagnosticPrinter.h
index fd18d33590a..a10224e78b6 100644
--- a/clang/Driver/TextDiagnosticPrinter.h
+++ b/clang/Driver/TextDiagnosticPrinter.h
@@ -15,26 +15,18 @@
#ifndef TEXT_DIAGNOSTIC_PRINTER_H_
#define TEXT_DIAGNOSTIC_PRINTER_H_
-#include "clang/Basic/Diagnostic.h"
+#include "TextDiagnostics.h"
#include "clang/Basic/SourceLocation.h"
namespace llvm {
namespace clang {
class SourceManager;
- class HeaderSearch;
- class Preprocessor;
- class TextDiagnosticPrinter : public DiagnosticClient {
- SourceManager &SourceMgr;
+ class TextDiagnosticPrinter : public TextDiagnostics {
SourceLocation LastWarningLoc;
- HeaderSearch *TheHeaderSearch;
- Preprocessor *ThePreprocessor;
public:
TextDiagnosticPrinter(SourceManager &sourceMgr)
- : SourceMgr(sourceMgr) {}
-
- void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; }
- void setPreprocessor(Preprocessor &P) { ThePreprocessor = &P; }
+ : TextDiagnostics(sourceMgr) {}
void PrintIncludeStack(SourceLocation Pos);
void HighlightRange(const SourceRange &R, unsigned LineNo,
@@ -42,8 +34,6 @@ namespace llvm {
const std::string &SourceLine);
unsigned GetTokenLength(SourceLocation Loc);
- virtual bool IgnoreDiagnostic(Diagnostic::Level Level,
- SourceLocation Pos);
virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
SourceLocation Pos,
diag::kind ID, const std::string *Strs,
diff --git a/clang/Driver/TextDiagnostics.cpp b/clang/Driver/TextDiagnostics.cpp
new file mode 100644
index 00000000000..cab53b75e64
--- /dev/null
+++ b/clang/Driver/TextDiagnostics.cpp
@@ -0,0 +1,61 @@
+//===--- TextDiagnostics.cpp - Text Diagnostics Parent Class --------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Bill Wendling and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// 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 llvm;
+using namespace clang;
+
+TextDiagnostics:: ~TextDiagnostics() {}
+
+std::string TextDiagnostics::FormatDiagnostic(Diagnostic::Level Level,
+ diag::kind ID,
+ const std::string *Strs,
+ unsigned NumStrs) {
+ std::string Msg = Diagnostic::getDescription(ID);
+
+ // 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;
+}
+
+bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level,
+ SourceLocation Pos) {
+ if (Pos.isValid()) {
+ // If this is a warning or note, and if it a system header, suppress the
+ // diagnostic.
+ if (Level == Diagnostic::Warning ||
+ Level == Diagnostic::Note) {
+ SourceLocation PhysLoc = SourceMgr.getPhysicalLoc(Pos);
+ const FileEntry *F = SourceMgr.getFileEntryForFileID(PhysLoc.getFileID());
+ if (F) {
+ DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
+ if (DirInfo == DirectoryLookup::SystemHeaderDir ||
+ DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
diff --git a/clang/Driver/TextDiagnostics.h b/clang/Driver/TextDiagnostics.h
new file mode 100644
index 00000000000..7e937a89966
--- /dev/null
+++ b/clang/Driver/TextDiagnostics.h
@@ -0,0 +1,55 @@
+//===--- TextDiagnostics.h - Text Diagnostics Checkers ----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Bill Wendling and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This is the parent class for all text diagnostics.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TEXT_DIAGNOSTICS_H_
+#define TEXT_DIAGNOSTICS_H_
+
+#include "clang/Basic/Diagnostic.h"
+
+namespace llvm {
+ namespace clang {
+ class SourceManager;
+ class HeaderSearch;
+ class Preprocessor;
+
+ class TextDiagnostics : public DiagnosticClient {
+ HeaderSearch *TheHeaderSearch;
+ protected:
+ SourceManager &SourceMgr;
+ Preprocessor *ThePreprocessor;
+
+ std::string FormatDiagnostic(Diagnostic::Level Level,
+ diag::kind ID,
+ const std::string *Strs,
+ unsigned NumStrs);
+ public:
+ TextDiagnostics(SourceManager &sourceMgr) : SourceMgr(sourceMgr) {}
+ virtual ~TextDiagnostics();
+
+ void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; }
+ void setPreprocessor(Preprocessor &P) { ThePreprocessor = &P; }
+
+ virtual bool IgnoreDiagnostic(Diagnostic::Level Level,
+ SourceLocation Pos);
+ virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
+ SourceLocation Pos,
+ diag::kind ID, const std::string *Strs,
+ unsigned NumStrs,
+ const SourceRange *Ranges,
+ unsigned NumRanges) = 0;
+ };
+
+ } // end namspace clang
+} // end namespace llvm
+
+#endif
OpenPOWER on IntegriCloud