forked from OSchip/llvm-project
Rewrite the printing of diagnostic options, categories, etc to actually
use the ostream interface and avoid lots of temporary strings. llvm-svn: 140494
This commit is contained in:
parent
b5784324b3
commit
0059a9bee0
|
@ -1095,54 +1095,49 @@ static void PrintDiagnosticOptions(raw_ostream &OS,
|
||||||
DiagnosticsEngine::Level Level,
|
DiagnosticsEngine::Level Level,
|
||||||
const Diagnostic &Info,
|
const Diagnostic &Info,
|
||||||
const DiagnosticOptions &DiagOpts) {
|
const DiagnosticOptions &DiagOpts) {
|
||||||
std::string OptionName;
|
bool Started = false;
|
||||||
if (DiagOpts.ShowOptionNames) {
|
if (DiagOpts.ShowOptionNames) {
|
||||||
|
// Handle special cases for non-warnings early.
|
||||||
|
if (Info.getID() == diag::fatal_too_many_errors) {
|
||||||
|
OS << " [-ferror-limit=]";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Was this a warning mapped to an error using -Werror or pragma?
|
// Was this a warning mapped to an error using -Werror or pragma?
|
||||||
if (Level == DiagnosticsEngine::Error &&
|
if (Level == DiagnosticsEngine::Error &&
|
||||||
DiagnosticIDs::isBuiltinWarningOrExtension(Info.getID())) {
|
DiagnosticIDs::isBuiltinWarningOrExtension(Info.getID())) {
|
||||||
diag::Mapping mapping = diag::MAP_IGNORE;
|
diag::Mapping mapping = diag::MAP_IGNORE;
|
||||||
Info.getDiags()->getDiagnosticLevel(Info.getID(), Info.getLocation(),
|
Info.getDiags()->getDiagnosticLevel(Info.getID(), Info.getLocation(),
|
||||||
&mapping);
|
&mapping);
|
||||||
if (mapping == diag::MAP_WARNING)
|
if (mapping == diag::MAP_WARNING) {
|
||||||
OptionName += "-Werror";
|
OS << " [-Werror";
|
||||||
|
Started = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the diagnostic is an extension diagnostic and not enabled by default
|
||||||
|
// then it must have been turned on with -pedantic.
|
||||||
|
bool EnabledByDefault;
|
||||||
|
if (DiagnosticIDs::isBuiltinExtensionDiag(Info.getID(),
|
||||||
|
EnabledByDefault) &&
|
||||||
|
!EnabledByDefault) {
|
||||||
|
OS << (Started ? "," : " [") << "-pedantic";
|
||||||
|
Started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringRef Opt = DiagnosticIDs::getWarningOptionForDiag(Info.getID());
|
StringRef Opt = DiagnosticIDs::getWarningOptionForDiag(Info.getID());
|
||||||
if (!Opt.empty()) {
|
if (!Opt.empty()) {
|
||||||
if (!OptionName.empty())
|
OS << (Started ? "," : " [") << "-W" << Opt;
|
||||||
OptionName += ',';
|
Started = true;
|
||||||
OptionName += "-W";
|
|
||||||
OptionName += Opt;
|
|
||||||
} else if (Info.getID() == diag::fatal_too_many_errors) {
|
|
||||||
OptionName = "-ferror-limit=";
|
|
||||||
} else {
|
|
||||||
// If the diagnostic is an extension diagnostic and not enabled by default
|
|
||||||
// then it must have been turned on with -pedantic.
|
|
||||||
bool EnabledByDefault;
|
|
||||||
if (DiagnosticIDs::isBuiltinExtensionDiag(Info.getID(),
|
|
||||||
EnabledByDefault) &&
|
|
||||||
!EnabledByDefault)
|
|
||||||
OptionName = "-pedantic";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user wants to see category information, include it too.
|
|
||||||
unsigned DiagCategory = 0;
|
|
||||||
if (DiagOpts.ShowCategories)
|
|
||||||
DiagCategory = DiagnosticIDs::getCategoryNumberForDiag(Info.getID());
|
|
||||||
|
|
||||||
// If there is any categorization information, include it.
|
// If the user wants to see category information, include it too.
|
||||||
if (!OptionName.empty() || DiagCategory != 0) {
|
if (DiagOpts.ShowCategories) {
|
||||||
bool NeedsComma = false;
|
unsigned DiagCategory =
|
||||||
OS << " [";
|
DiagnosticIDs::getCategoryNumberForDiag(Info.getID());
|
||||||
|
|
||||||
if (!OptionName.empty()) {
|
|
||||||
OS << OptionName;
|
|
||||||
NeedsComma = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DiagCategory) {
|
if (DiagCategory) {
|
||||||
if (NeedsComma) OS << ',';
|
OS << (Started ? "," : " [");
|
||||||
if (DiagOpts.ShowCategories == 1)
|
if (DiagOpts.ShowCategories == 1)
|
||||||
OS << llvm::utostr(DiagCategory);
|
OS << llvm::utostr(DiagCategory);
|
||||||
else {
|
else {
|
||||||
|
@ -1150,9 +1145,8 @@ static void PrintDiagnosticOptions(raw_ostream &OS,
|
||||||
OS << DiagnosticIDs::getCategoryNameFromID(DiagCategory);
|
OS << DiagnosticIDs::getCategoryNameFromID(DiagCategory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OS << "]";
|
|
||||||
}
|
}
|
||||||
|
OS << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
|
void TextDiagnosticPrinter::HandleDiagnostic(DiagnosticsEngine::Level Level,
|
||||||
|
|
Loading…
Reference in New Issue