static bool parseDiagnosticLevelMask(StringRef FlagName,
const std::vector<std::string> &Levels,
- DiagnosticsEngine *Diags,
+ DiagnosticsEngine &Diags,
DiagnosticLevelMask &M) {
bool Success = true;
for (const auto &Level : Levels) {
.Default(DiagnosticLevelMask::None);
if (PM == DiagnosticLevelMask::None) {
Success = false;
- if (Diags)
- Diags->Report(diag::err_drv_invalid_value) << FlagName << Level;
+ Diags.Report(diag::err_drv_invalid_value) << FlagName << Level;
}
M = M | PM;
}
}
static bool checkVerifyPrefixes(const std::vector<std::string> &VerifyPrefixes,
- DiagnosticsEngine *Diags) {
+ DiagnosticsEngine &Diags) {
bool Success = true;
for (const auto &Prefix : VerifyPrefixes) {
// Every prefix must start with a letter and contain only alphanumeric
});
if (BadChar != Prefix.end() || !isLetter(Prefix[0])) {
Success = false;
- if (Diags) {
- Diags->Report(diag::err_drv_invalid_value) << "-verify=" << Prefix;
- Diags->Report(diag::note_drv_verify_prefix_spelling);
- }
+ Diags.Report(diag::err_drv_invalid_value) << "-verify=" << Prefix;
+ Diags.Report(diag::note_drv_verify_prefix_spelling);
}
}
return Success;
bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
DiagnosticsEngine *Diags,
bool DefaultDiagColor) {
+ Optional<DiagnosticsEngine> IgnoringDiags;
+ if (!Diags) {
+ IgnoringDiags.emplace(new DiagnosticIDs(), new DiagnosticOptions(),
+ new IgnoringDiagConsumer());
+ Diags = &*IgnoringDiags;
+ }
+
bool Success = true;
Opts.DiagnosticLogFile =
Opts.setShowOverloads(Ovl_All);
else {
Success = false;
- if (Diags)
- Diags->Report(diag::err_drv_invalid_value)
- << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args)
- << ShowOverloads;
+ Diags->Report(diag::err_drv_invalid_value)
+ << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args)
+ << ShowOverloads;
}
StringRef ShowCategory =
Opts.ShowCategories = 2;
else {
Success = false;
- if (Diags)
- Diags->Report(diag::err_drv_invalid_value)
- << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args)
- << ShowCategory;
+ Diags->Report(diag::err_drv_invalid_value)
+ << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args)
+ << ShowCategory;
}
StringRef Format =
Opts.setFormat(DiagnosticOptions::Vi);
else {
Success = false;
- if (Diags)
- Diags->Report(diag::err_drv_invalid_value)
- << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args)
- << Format;
+ Diags->Report(diag::err_drv_invalid_value)
+ << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args)
+ << Format;
}
Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info);
Opts.VerifyPrefixes.push_back("expected");
// Keep VerifyPrefixes in its original order for the sake of diagnostics, and
// then sort it to prepare for fast lookup using std::binary_search.
- if (!checkVerifyPrefixes(Opts.VerifyPrefixes, Diags)) {
+ if (!checkVerifyPrefixes(Opts.VerifyPrefixes, *Diags)) {
Opts.VerifyDiagnostics = false;
Success = false;
}
DiagnosticLevelMask DiagMask = DiagnosticLevelMask::None;
Success &= parseDiagnosticLevelMask("-verify-ignore-unexpected=",
Args.getAllArgValues(OPT_verify_ignore_unexpected_EQ),
- Diags, DiagMask);
+ *Diags, DiagMask);
if (Args.hasArg(OPT_verify_ignore_unexpected))
DiagMask = DiagnosticLevelMask::All;
Opts.setVerifyIgnoreUnexpected(DiagMask);
DiagnosticOptions::DefaultTabStop, Diags);
if (Opts.TabStop == 0 || Opts.TabStop > DiagnosticOptions::MaxTabStop) {
Opts.TabStop = DiagnosticOptions::DefaultTabStop;
- if (Diags)
- Diags->Report(diag::warn_ignoring_ftabstop_value)
- << Opts.TabStop << DiagnosticOptions::DefaultTabStop;
+ Diags->Report(diag::warn_ignoring_ftabstop_value)
+ << Opts.TabStop << DiagnosticOptions::DefaultTabStop;
}
Opts.MessageLength =
getLastArgIntValue(Args, OPT_fmessage_length_EQ, 0, Diags);