[Support] Add convenience functions to WithColor. NFC.

Create convenience functions for printing error, warning and note to
stdout. Previously we had similar functions being used in dsymutil, but
given that this pattern is so common it makes sense to make it available
globally.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330091 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jonas Devlieghere
2018-04-14 21:36:42 +00:00
parent 851a7606e9
commit 5baab4c85c
8 changed files with 78 additions and 88 deletions
+12
View File
@@ -59,6 +59,18 @@ WithColor::WithColor(raw_ostream &OS, HighlightColor Color) : OS(OS) {
}
}
raw_ostream &WithColor::error() {
return WithColor(errs(), HighlightColor::Error).get() << "error: ";
}
raw_ostream &WithColor::warning() {
return WithColor(errs(), HighlightColor::Warning).get() << "warning: ";
}
raw_ostream &WithColor::note() {
return WithColor(errs(), HighlightColor::Note).get() << "note: ";
}
WithColor::~WithColor() {
if (colorsEnabled(OS))
OS.resetColor();