Commit 1458476c authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Some cleanup in the diagnostic client.

parent 91c90912
......@@ -50,8 +50,7 @@
#define CPLUSPLUS_DIAGNOSTICCLIENT_H
#include "CPlusPlusForwardDeclarations.h"
#include "stdarg.h"
#include <cstdarg>
namespace CPlusPlus {
......
......@@ -389,7 +389,7 @@ bool TranslationUnit::blockErrors(bool block)
return previous;
}
void TranslationUnit::warning(unsigned index, const char *format, ...)
void TranslationUnit::message(DiagnosticClient::Level level, unsigned index, const char *format, va_list args)
{
if (f._blockErrors)
return;
......@@ -401,54 +401,50 @@ void TranslationUnit::warning(unsigned index, const char *format, ...)
getTokenPosition(index, &line, &column, &fileName);
if (DiagnosticClient *client = control()->diagnosticClient()) {
va_list args;
va_start(args, format);
client->report(DiagnosticClient::Warning, fileName, line, column,
format, args);
va_end(args);
client->report(level, fileName, line, column, format, args);
} else {
fprintf(stderr, "%s:%d: ", fileName->chars(), line);
fprintf(stderr, "warning: ");
const char *l = "error";
if (level == DiagnosticClient::Warning)
l = "warning";
else if (level == DiagnosticClient::Fatal)
l = "fatal";
fprintf(stderr, "%s: ", l);
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fputc('\n', stderr);
showErrorLine(index, column, stderr);
}
if (level == DiagnosticClient::Fatal)
exit(EXIT_FAILURE);
}
void TranslationUnit::error(unsigned index, const char *format, ...)
void TranslationUnit::warning(unsigned index, const char *format, ...)
{
if (f._blockErrors)
return;
index = std::min(index, tokenCount() - 1);
unsigned line = 0, column = 0;
const StringLiteral *fileName = 0;
getTokenPosition(index, &line, &column, &fileName);
if (DiagnosticClient *client = control()->diagnosticClient()) {
va_list args;
va_start(args, format);
client->report(DiagnosticClient::Error, fileName, line, column,
format, args);
va_end(args);
} else {
fprintf(stderr, "%s:%d: ", fileName->chars(), line);
fprintf(stderr, "error: ");
va_list args, ap;
va_start(args, format);
va_copy(ap, args);
message(DiagnosticClient::Fatal, index, format, args);
va_end(ap);
va_end(args);
}
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fputc('\n', stderr);
void TranslationUnit::error(unsigned index, const char *format, ...)
{
if (f._blockErrors)
return;
showErrorLine(index, column, stderr);
}
va_list args, ap;
va_start(args, format);
va_copy(ap, args);
message(DiagnosticClient::Error, index, format, args);
va_end(ap);
va_end(args);
}
void TranslationUnit::fatal(unsigned index, const char *format, ...)
......@@ -456,32 +452,12 @@ void TranslationUnit::fatal(unsigned index, const char *format, ...)
if (f._blockErrors)
return;
index = std::min(index, tokenCount() - 1);
unsigned line = 0, column = 0;
const StringLiteral *fileName = 0;
getTokenPosition(index, &line, &column, &fileName);
if (DiagnosticClient *client = control()->diagnosticClient()) {
va_list args;
va_start(args, format);
client->report(DiagnosticClient::Fatal, fileName, line, column,
format, args);
va_end(args);
} else {
fprintf(stderr, "%s:%d: ", fileName->chars(), line);
fprintf(stderr, "fatal: ");
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fputc('\n', stderr);
showErrorLine(index, column, stderr);
}
exit(EXIT_FAILURE);
va_list args, ap;
va_start(args, format);
va_copy(ap, args);
message(DiagnosticClient::Fatal, index, format, args);
va_end(ap);
va_end(args);
}
unsigned TranslationUnit::findPreviousLineOffset(unsigned tokenIndex) const
......
......@@ -52,6 +52,7 @@
#include "CPlusPlusForwardDeclarations.h"
#include "ASTfwd.h"
#include "Token.h"
#include "DiagnosticClient.h"
#include <cstdio>
#include <vector>
......@@ -108,6 +109,9 @@ public:
void error(unsigned index, const char *fmt, ...);
void fatal(unsigned index, const char *fmt, ...);
void message(DiagnosticClient::Level level, unsigned index,
const char *format, va_list ap);
bool isTokenized() const;
void tokenize();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment