Skip to content

Commit 5365e8b

Browse files
committed
[Support] Extend WithColor helpers
Although printing warnings and errors to stderr is by far the most common case, this patch makes it possible to specify any stream. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330094 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6823222 commit 5365e8b

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

include/llvm/Support/WithColor.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ class WithColor {
4444

4545
/// Convenience method for printing "error: " to stderr.
4646
static raw_ostream &error();
47-
4847
/// Convenience method for printing "warning: " to stderr.
4948
static raw_ostream &warning();
50-
5149
/// Convenience method for printing "note: " to stderr.
5250
static raw_ostream &note();
51+
52+
/// Convenience method for printing "error: " to the given stream.
53+
static raw_ostream &error(raw_ostream &OS);
54+
/// Convenience method for printing "warning: " to the given stream.
55+
static raw_ostream &warning(raw_ostream &OS);
56+
/// Convenience method for printing "note: " to the given stream.
57+
static raw_ostream &note(raw_ostream &OS);
5358
};
5459

5560
} // end namespace llvm

lib/DebugInfo/DWARF/DWARFVerifier.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,14 +1196,8 @@ bool DWARFVerifier::handleAccelTables() {
11961196
return NumErrors == 0;
11971197
}
11981198

1199-
raw_ostream &DWARFVerifier::error() const {
1200-
return WithColor(OS, HighlightColor::Error).get() << "error: ";
1201-
}
1199+
raw_ostream &DWARFVerifier::error() const { return WithColor::error(OS); }
12021200

1203-
raw_ostream &DWARFVerifier::warn() const {
1204-
return WithColor(OS, HighlightColor::Warning).get() << "warning: ";
1205-
}
1201+
raw_ostream &DWARFVerifier::warn() const { return WithColor::warning(OS); }
12061202

1207-
raw_ostream &DWARFVerifier::note() const {
1208-
return WithColor(OS, HighlightColor::Note).get() << "note: ";
1209-
}
1203+
raw_ostream &DWARFVerifier::note() const { return WithColor::note(OS); }

lib/Support/WithColor.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,22 @@ WithColor::WithColor(raw_ostream &OS, HighlightColor Color) : OS(OS) {
5959
}
6060
}
6161

62-
raw_ostream &WithColor::error() {
63-
return WithColor(errs(), HighlightColor::Error).get() << "error: ";
62+
raw_ostream &WithColor::error() { return error(errs()); }
63+
64+
raw_ostream &WithColor::warning() { return warning(errs()); }
65+
66+
raw_ostream &WithColor::note() { return note(errs()); }
67+
68+
raw_ostream &WithColor::error(raw_ostream &OS) {
69+
return WithColor(OS, HighlightColor::Error).get() << "error: ";
6470
}
6571

66-
raw_ostream &WithColor::warning() {
67-
return WithColor(errs(), HighlightColor::Warning).get() << "warning: ";
72+
raw_ostream &WithColor::warning(raw_ostream &OS) {
73+
return WithColor(OS, HighlightColor::Warning).get() << "warning: ";
6874
}
6975

70-
raw_ostream &WithColor::note() {
71-
return WithColor(errs(), HighlightColor::Note).get() << "note: ";
76+
raw_ostream &WithColor::note(raw_ostream &OS) {
77+
return WithColor(OS, HighlightColor::Note).get() << "note: ";
7278
}
7379

7480
WithColor::~WithColor() {

0 commit comments

Comments
 (0)