forked from OSchip/llvm-project
Submitted by: Bill Wendling
Reviewed by: Chris Lattner - Make the counting of errors and diagnostic messages sane. Place them into the Diagnostic class instead of in the DiagnosticClient class. llvm-svn: 39615
This commit is contained in:
parent
7cf04d1653
commit
da0c8a9641
|
@ -59,6 +59,8 @@ Diagnostic::Diagnostic(DiagnosticClient &client) : Client(client) {
|
|||
memset(DiagMappings, 0, sizeof(DiagMappings));
|
||||
|
||||
ErrorOccurred = false;
|
||||
NumDiagnostics = 0;
|
||||
NumErrors = 0;
|
||||
}
|
||||
|
||||
/// isNoteWarningOrExtension - Return true if the unmapped diagnostic level of
|
||||
|
@ -128,8 +130,10 @@ void Diagnostic::Report(SourceLocation Pos, unsigned DiagID,
|
|||
if (DiagLevel == Diagnostic::Ignored)
|
||||
return;
|
||||
|
||||
if (DiagLevel >= Diagnostic::Error)
|
||||
if (DiagLevel >= Diagnostic::Error) {
|
||||
ErrorOccurred = true;
|
||||
++NumErrors;
|
||||
}
|
||||
|
||||
// Finally, report it.
|
||||
Client.HandleDiagnostic(DiagLevel, Pos, (diag::kind)DiagID, Strs, NumStrs,
|
||||
|
|
|
@ -47,7 +47,6 @@ PrintIncludeStack(SourceLocation Pos) {
|
|||
<< ":" << LineNo << ":\n";
|
||||
}
|
||||
|
||||
|
||||
/// HighlightRange - Given a SourceRange and a line number, highlight (with ~'s)
|
||||
/// any characters in LineNo that intersect the SourceRange.
|
||||
void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
|
||||
|
@ -101,7 +100,6 @@ void TextDiagnosticPrinter::HighlightRange(const SourceRange &R,
|
|||
CaratLine[i] = '~';
|
||||
}
|
||||
|
||||
|
||||
/// GetTokenLength - Given the source location of a token, determine its length.
|
||||
/// This is a fully general function that uses a lexer to relex the token.
|
||||
unsigned TextDiagnosticPrinter::GetTokenLength(SourceLocation Loc) {
|
||||
|
@ -123,7 +121,6 @@ unsigned TextDiagnosticPrinter::GetTokenLength(SourceLocation Loc) {
|
|||
return TheTok.getLength();
|
||||
}
|
||||
|
||||
|
||||
void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
|
||||
SourceLocation Pos,
|
||||
diag::kind ID,
|
||||
|
@ -185,11 +182,11 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
|
|||
|
||||
switch (Level) {
|
||||
default: assert(0 && "Unknown diagnostic type!");
|
||||
case Diagnostic::Note: cerr << "note: "; break;
|
||||
case Diagnostic::Warning: cerr << "warning: "; break;
|
||||
case Diagnostic::Error: ++NumErrors; cerr << "error: "; break;
|
||||
case Diagnostic::Fatal: ++NumErrors; cerr << "fatal error: "; break;
|
||||
case Diagnostic::Sorry: ++NumErrors; cerr << "sorry, unimplemented: ";
|
||||
case Diagnostic::Note: cerr << "note: "; break;
|
||||
case Diagnostic::Warning: cerr << "warning: "; break;
|
||||
case Diagnostic::Error: cerr << "error: "; break;
|
||||
case Diagnostic::Fatal: cerr << "fatal error: "; break;
|
||||
case Diagnostic::Sorry: cerr << "sorry, unimplemented: ";
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -252,6 +249,4 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
|
|||
cerr << SourceLine << "\n";
|
||||
cerr << CaratLine << "\n";
|
||||
}
|
||||
|
||||
++NumDiagnostics;
|
||||
}
|
||||
|
|
|
@ -808,7 +808,6 @@ static void ProcessInputFile(const std::string &InFile,
|
|||
if (File) MainFileID = SourceMgr.createFileID(File, SourceLocation());
|
||||
if (MainFileID == 0) {
|
||||
std::cerr << "Error reading '" << InFile << "'!\n";
|
||||
OurDiagnosticClient.incrNumErrors();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
@ -816,7 +815,6 @@ static void ProcessInputFile(const std::string &InFile,
|
|||
if (SB) MainFileID = SourceMgr.createFileIDForMemBuffer(SB);
|
||||
if (MainFileID == 0) {
|
||||
std::cerr << "Error reading standard input! Empty?\n";
|
||||
OurDiagnosticClient.incrNumErrors();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -951,9 +949,10 @@ int main(int argc, char **argv) {
|
|||
ProcessInputFile(InputFilenames[i], SourceMgr, Diags, OurDiagnosticClient,
|
||||
HeaderInfo, *Target, LangInfo);
|
||||
|
||||
if (OurDiagnosticClient.getNumDiagnostics())
|
||||
std::cerr << OurDiagnosticClient.getNumDiagnostics() << " diagnostic"
|
||||
<< (OurDiagnosticClient.getNumDiagnostics() == 1 ? "" : "s")
|
||||
unsigned NumDiagnostics = Diags.getNumDiagnostics();
|
||||
if (NumDiagnostics)
|
||||
std::cerr << NumDiagnostics << " diagnostic"
|
||||
<< (NumDiagnostics == 1 ? "" : "s")
|
||||
<< " generated.\n";
|
||||
|
||||
if (Stats) {
|
||||
|
@ -963,5 +962,5 @@ int main(int argc, char **argv) {
|
|||
std::cerr << "\n";
|
||||
}
|
||||
|
||||
return OurDiagnosticClient.getNumErrors() != 0;
|
||||
return Diags.getNumErrors() != 0;
|
||||
}
|
||||
|
|
|
@ -59,6 +59,9 @@ class Diagnostic {
|
|||
/// ErrorOccurred - This is set to true when an error is emitted, and is
|
||||
/// sticky.
|
||||
bool ErrorOccurred;
|
||||
|
||||
unsigned NumDiagnostics; // Number of diagnostics reported
|
||||
unsigned NumErrors; // Number of diagnostics that are errors
|
||||
public:
|
||||
explicit Diagnostic(DiagnosticClient &client);
|
||||
|
||||
|
@ -98,6 +101,9 @@ public:
|
|||
}
|
||||
|
||||
bool hasErrorOccurred() const { return ErrorOccurred; }
|
||||
|
||||
unsigned getNumErrors() const { return NumErrors; }
|
||||
unsigned getNumDiagnostics() const { return NumDiagnostics; }
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Diagnostic classification and reporting interfaces.
|
||||
|
@ -131,20 +137,10 @@ public:
|
|||
/// DiagnosticClient - This is an abstract interface implemented by clients of
|
||||
/// the front-end, which formats and prints fully processed diagnostics.
|
||||
class DiagnosticClient {
|
||||
protected:
|
||||
unsigned NumDiagnostics;
|
||||
unsigned NumErrors;
|
||||
public:
|
||||
DiagnosticClient() : NumDiagnostics(0), NumErrors(0) {}
|
||||
virtual ~DiagnosticClient();
|
||||
|
||||
unsigned getNumDiagnostics() const { return NumDiagnostics; }
|
||||
unsigned getNumErrors() const { return NumErrors; }
|
||||
|
||||
void incrNumDiagnostics() { ++NumDiagnostics; }
|
||||
void incrNumErrors() { ++NumErrors; }
|
||||
|
||||
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
|
||||
/// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
|
||||
/// capturing it to a log as needed.
|
||||
virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, SourceLocation Pos,
|
||||
diag::kind ID, const std::string *Strs,
|
||||
|
|
Loading…
Reference in New Issue