From 52107f0189292525686d74cf8c463a41de0efb24 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Sat, 21 Apr 2018 21:36:11 +0000 Subject: [PATCH] [Support] Add optional prefix to convenience helpers in WithColor. Several tools prefix the error/warning/note output with the name of the tool. One such tool is LLD for example. This commit adds as an optional 'Prefix' argument to the convenience helpers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330526 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/WithColor.h | 8 +++++--- lib/Support/WithColor.cpp | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/llvm/Support/WithColor.h b/include/llvm/Support/WithColor.h index 59f05ecc3c3..ee1e05cda32 100644 --- a/include/llvm/Support/WithColor.h +++ b/include/llvm/Support/WithColor.h @@ -10,6 +10,8 @@ #ifndef LLVM_SUPPORT_WITHCOLOR_H #define LLVM_SUPPORT_WITHCOLOR_H +#include "llvm/ADT/StringRef.h" + namespace llvm { class raw_ostream; @@ -50,11 +52,11 @@ public: static raw_ostream ¬e(); /// Convenience method for printing "error: " to the given stream. - static raw_ostream &error(raw_ostream &OS); + static raw_ostream &error(raw_ostream &OS, StringRef Prefix = ""); /// Convenience method for printing "warning: " to the given stream. - static raw_ostream &warning(raw_ostream &OS); + static raw_ostream &warning(raw_ostream &OS, StringRef Prefix = ""); /// Convenience method for printing "note: " to the given stream. - static raw_ostream ¬e(raw_ostream &OS); + static raw_ostream ¬e(raw_ostream &OS, StringRef Prefix = ""); }; } // end namespace llvm diff --git a/lib/Support/WithColor.cpp b/lib/Support/WithColor.cpp index 5a1364ff3cb..c3ab35bd891 100644 --- a/lib/Support/WithColor.cpp +++ b/lib/Support/WithColor.cpp @@ -65,15 +65,18 @@ raw_ostream &WithColor::warning() { return warning(errs()); } raw_ostream &WithColor::note() { return note(errs()); } -raw_ostream &WithColor::error(raw_ostream &OS) { +raw_ostream &WithColor::error(raw_ostream &OS, StringRef Prefix) { + OS << Prefix; return WithColor(OS, HighlightColor::Error).get() << "error: "; } -raw_ostream &WithColor::warning(raw_ostream &OS) { +raw_ostream &WithColor::warning(raw_ostream &OS, StringRef Prefix) { + OS << Prefix; return WithColor(OS, HighlightColor::Warning).get() << "warning: "; } -raw_ostream &WithColor::note(raw_ostream &OS) { +raw_ostream &WithColor::note(raw_ostream &OS, StringRef Prefix) { + OS << Prefix; return WithColor(OS, HighlightColor::Note).get() << "note: "; }