mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-23 04:42:32 +00:00
Move the diagnostic functions into their own file.
This commit is contained in:
parent
d618e51dc8
commit
0624408317
26 changed files with 261 additions and 153 deletions
54
tools/qfcc/include/diagnostic.h
Normal file
54
tools/qfcc/include/diagnostic.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
diagnostic.h
|
||||
|
||||
Diagnostic messages.
|
||||
|
||||
Copyright (C) 2011 Bill Currie <bill@taniwha.org>
|
||||
|
||||
Author: Bill Currie <bill@taniwha.org>
|
||||
Date: 2011/01/24
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
$Id$
|
||||
*/
|
||||
|
||||
#ifndef __diagnostic_h
|
||||
#define __diagnostic_h
|
||||
|
||||
#include "QF/pr_comp.h"
|
||||
|
||||
/** \defgroup qfcc_diagnostic Diagnostic Messages
|
||||
\ingroup qfcc
|
||||
*/
|
||||
//@{
|
||||
|
||||
struct expr_s *error (struct expr_s *e, const char *fmt, ...)
|
||||
__attribute__ ((format (printf, 2, 3)));
|
||||
void
|
||||
internal_error (struct expr_s *e, const char *fmt, ...)
|
||||
__attribute__ ((format (printf, 2, 3), noreturn));
|
||||
struct expr_s *warning (struct expr_s *e, const char *fmt, ...)
|
||||
__attribute__ ((format (printf, 2, 3)));
|
||||
struct expr_s *notice (struct expr_s *e, const char *fmt, ...)
|
||||
__attribute__ ((format (printf, 2, 3)));
|
||||
|
||||
//@}
|
||||
|
||||
#endif//__diagnostic_h
|
|
@ -547,16 +547,6 @@ expr_t *cast_expr (struct type_s *t, expr_t *e);
|
|||
|
||||
void init_elements (struct def_s *def, expr_t *eles);
|
||||
|
||||
expr_t *error (expr_t *e, const char *fmt, ...)
|
||||
__attribute__ ((format (printf, 2, 3)));
|
||||
void
|
||||
internal_error (expr_t *e, const char *fmt, ...)
|
||||
__attribute__ ((format (printf, 2, 3), noreturn));
|
||||
expr_t *warning (expr_t *e, const char *fmt, ...)
|
||||
__attribute__ ((format (printf, 2, 3)));
|
||||
expr_t *notice (expr_t *e, const char *fmt, ...)
|
||||
__attribute__ ((format (printf, 2, 3)));
|
||||
|
||||
const char *get_op_string (int op);
|
||||
|
||||
extern int lineno_base;
|
||||
|
|
|
@ -52,8 +52,8 @@ bin_SCRIPTS= $(qfpreqcc)
|
|||
EXTRA_PROGRAMS= qfcc qfpc qfprogs
|
||||
|
||||
common_src=\
|
||||
class.c codespace.c constfold.c cpp.c debug.c def.c defspace.c dot_expr.c \
|
||||
dot_flow.c emit.c \
|
||||
class.c codespace.c constfold.c cpp.c debug.c def.c defspace.c \
|
||||
diagnostic.c dot_expr.c dot_flow.c emit.c \
|
||||
expr.c function.c grab.c idstuff.c immediate.c linker.c method.c \
|
||||
obj_stub.c opcodes.c options.c qfcc.c reloc.c statements.c strpool.c \
|
||||
struct.c switch.c symtab.c type.c
|
||||
|
|
|
@ -53,6 +53,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "class.h"
|
||||
#include "def.h"
|
||||
#include "defspace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "emit.h"
|
||||
#include "expr.h"
|
||||
#include "immediate.h"
|
||||
|
|
|
@ -45,6 +45,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include <QF/dstring.h>
|
||||
#include <QF/mathlib.h>
|
||||
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "options.h"
|
||||
#include "qc-parse.h"
|
||||
|
|
|
@ -46,6 +46,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "QF/pr_comp.h"
|
||||
|
||||
#include "debug.h"
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "immediate.h"
|
||||
#include "qfcc.h"
|
||||
|
|
|
@ -50,6 +50,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "qfcc.h"
|
||||
#include "def.h"
|
||||
#include "defspace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "immediate.h"
|
||||
#include "options.h"
|
||||
|
|
|
@ -47,6 +47,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
|||
|
||||
#include "qfcc.h"
|
||||
#include "defspace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "immediate.h"
|
||||
#include "options.h"
|
||||
|
|
182
tools/qfcc/source/diagnostic.c
Normal file
182
tools/qfcc/source/diagnostic.c
Normal file
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
diagnostic.c
|
||||
|
||||
Diagnostic messages.
|
||||
|
||||
Copyright (C) 2011 Bill Currie <bill@taniwha.org>
|
||||
|
||||
Author: Bill Currie <bill@taniwha.org>
|
||||
Date: 2011/01/24
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to:
|
||||
|
||||
Free Software Foundation, Inc.
|
||||
59 Temple Place - Suite 330
|
||||
Boston, MA 02111-1307, USA
|
||||
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
||||
|
||||
#include <QF/dstring.h>
|
||||
|
||||
#include "qfcc.h"
|
||||
#include "class.h"
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "function.h"
|
||||
#include "options.h"
|
||||
#include "strpool.h"
|
||||
|
||||
static void
|
||||
report_function (expr_t *e)
|
||||
{
|
||||
static function_t *last_func = (function_t *)-1L;
|
||||
static string_t last_file;
|
||||
string_t file = pr.source_file;
|
||||
srcline_t *srcline;
|
||||
|
||||
if (e)
|
||||
file = e->file;
|
||||
|
||||
if (file != last_file) {
|
||||
for (srcline = pr.srcline_stack; srcline; srcline = srcline->next)
|
||||
fprintf (stderr, "In file included from %s:%d:\n",
|
||||
GETSTR (srcline->source_file), srcline->source_line);
|
||||
}
|
||||
last_file = file;
|
||||
if (current_func != last_func) {
|
||||
if (current_func) {
|
||||
fprintf (stderr, "%s: In function `%s':\n", GETSTR (file),
|
||||
current_func->name);
|
||||
} else if (current_class) {
|
||||
fprintf (stderr, "%s: In class `%s':\n", GETSTR (file),
|
||||
get_class_name (current_class, 1));
|
||||
} else {
|
||||
fprintf (stderr, "%s: At top level:\n", GETSTR (file));
|
||||
}
|
||||
}
|
||||
last_func = current_func;
|
||||
}
|
||||
|
||||
static void
|
||||
_warning (expr_t *e, const char *fmt, va_list args)
|
||||
{
|
||||
string_t file = pr.source_file;
|
||||
int line = pr.source_line;
|
||||
|
||||
report_function (e);
|
||||
if (options.warnings.promote) {
|
||||
options.warnings.promote = 0; // want to do this only once
|
||||
fprintf (stderr, "%s: warnings treated as errors\n", "qfcc");
|
||||
pr.error_count++;
|
||||
}
|
||||
|
||||
if (e) {
|
||||
file = e->file;
|
||||
line = e->line;
|
||||
}
|
||||
fprintf (stderr, "%s:%d: warning: ", GETSTR (file), line);
|
||||
vfprintf (stderr, fmt, args);
|
||||
fputs ("\n", stderr);
|
||||
}
|
||||
|
||||
expr_t *
|
||||
notice (expr_t *e, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (options.notices.silent)
|
||||
return e;
|
||||
|
||||
va_start (args, fmt);
|
||||
if (options.notices.promote) {
|
||||
_warning (e, fmt, args);
|
||||
} else {
|
||||
string_t file = pr.source_file;
|
||||
int line = pr.source_line;
|
||||
|
||||
report_function (e);
|
||||
if (e) {
|
||||
file = e->file;
|
||||
line = e->line;
|
||||
}
|
||||
fprintf (stderr, "%s:%d: notice: ", GETSTR (file), line);
|
||||
vfprintf (stderr, fmt, args);
|
||||
fputs ("\n", stderr);
|
||||
}
|
||||
va_end (args);
|
||||
return e;
|
||||
}
|
||||
|
||||
expr_t *
|
||||
warning (expr_t *e, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
_warning (e, fmt, args);
|
||||
va_end (args);
|
||||
return e;
|
||||
}
|
||||
|
||||
static void
|
||||
_error (expr_t *e, const char *err, const char *fmt, va_list args)
|
||||
{
|
||||
string_t file = pr.source_file;
|
||||
int line = pr.source_line;
|
||||
|
||||
report_function (e);
|
||||
|
||||
if (e) {
|
||||
file = e->file;
|
||||
line = e->line;
|
||||
}
|
||||
fprintf (stderr, "%s:%d: %s%s", GETSTR (file), line, err,
|
||||
fmt ? ": " : "");
|
||||
if (fmt)
|
||||
vfprintf (stderr, fmt, args);
|
||||
fputs ("\n", stderr);
|
||||
pr.error_count++;
|
||||
}
|
||||
|
||||
void
|
||||
internal_error (expr_t *e, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
_error (e, "internal error", fmt, args);
|
||||
va_end (args);
|
||||
abort ();
|
||||
}
|
||||
|
||||
expr_t *
|
||||
error (expr_t *e, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
_error (e, "error", fmt, args);
|
||||
va_end (args);
|
||||
|
||||
if (!e)
|
||||
e = new_expr ();
|
||||
e->type = ex_error;
|
||||
return e;
|
||||
}
|
|
@ -51,6 +51,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "class.h"
|
||||
#include "def.h"
|
||||
#include "defspace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "emit.h"
|
||||
#include "expr.h"
|
||||
#include "function.h"
|
||||
|
@ -2478,141 +2479,3 @@ sizeof_expr (expr_t *expr, struct type_s *type)
|
|||
expr = new_integer_expr (type_size (type));
|
||||
return expr;
|
||||
}
|
||||
|
||||
static void
|
||||
report_function (expr_t *e)
|
||||
{
|
||||
static function_t *last_func = (function_t *)-1L;
|
||||
static string_t last_file;
|
||||
string_t file = pr.source_file;
|
||||
srcline_t *srcline;
|
||||
|
||||
if (e)
|
||||
file = e->file;
|
||||
|
||||
if (file != last_file) {
|
||||
for (srcline = pr.srcline_stack; srcline; srcline = srcline->next)
|
||||
fprintf (stderr, "In file included from %s:%d:\n",
|
||||
GETSTR (srcline->source_file), srcline->source_line);
|
||||
}
|
||||
last_file = file;
|
||||
if (current_func != last_func) {
|
||||
if (current_func) {
|
||||
fprintf (stderr, "%s: In function `%s':\n", GETSTR (file),
|
||||
current_func->name);
|
||||
} else if (current_class) {
|
||||
fprintf (stderr, "%s: In class `%s':\n", GETSTR (file),
|
||||
get_class_name (current_class, 1));
|
||||
} else {
|
||||
fprintf (stderr, "%s: At top level:\n", GETSTR (file));
|
||||
}
|
||||
}
|
||||
last_func = current_func;
|
||||
}
|
||||
|
||||
static void
|
||||
_warning (expr_t *e, const char *fmt, va_list args)
|
||||
{
|
||||
string_t file = pr.source_file;
|
||||
int line = pr.source_line;
|
||||
|
||||
report_function (e);
|
||||
if (options.warnings.promote) {
|
||||
options.warnings.promote = 0; // want to do this only once
|
||||
fprintf (stderr, "%s: warnings treated as errors\n", "qfcc");
|
||||
pr.error_count++;
|
||||
}
|
||||
|
||||
if (e) {
|
||||
file = e->file;
|
||||
line = e->line;
|
||||
}
|
||||
fprintf (stderr, "%s:%d: warning: ", GETSTR (file), line);
|
||||
vfprintf (stderr, fmt, args);
|
||||
fputs ("\n", stderr);
|
||||
}
|
||||
|
||||
expr_t *
|
||||
notice (expr_t *e, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (options.notices.silent)
|
||||
return e;
|
||||
|
||||
va_start (args, fmt);
|
||||
if (options.notices.promote) {
|
||||
_warning (e, fmt, args);
|
||||
} else {
|
||||
string_t file = pr.source_file;
|
||||
int line = pr.source_line;
|
||||
|
||||
report_function (e);
|
||||
if (e) {
|
||||
file = e->file;
|
||||
line = e->line;
|
||||
}
|
||||
fprintf (stderr, "%s:%d: notice: ", GETSTR (file), line);
|
||||
vfprintf (stderr, fmt, args);
|
||||
fputs ("\n", stderr);
|
||||
}
|
||||
va_end (args);
|
||||
return e;
|
||||
}
|
||||
|
||||
expr_t *
|
||||
warning (expr_t *e, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
_warning (e, fmt, args);
|
||||
va_end (args);
|
||||
return e;
|
||||
}
|
||||
|
||||
static void
|
||||
_error (expr_t *e, const char *err, const char *fmt, va_list args)
|
||||
{
|
||||
string_t file = pr.source_file;
|
||||
int line = pr.source_line;
|
||||
|
||||
report_function (e);
|
||||
|
||||
if (e) {
|
||||
file = e->file;
|
||||
line = e->line;
|
||||
}
|
||||
fprintf (stderr, "%s:%d: %s%s", GETSTR (file), line, err,
|
||||
fmt ? ": " : "");
|
||||
if (fmt)
|
||||
vfprintf (stderr, fmt, args);
|
||||
fputs ("\n", stderr);
|
||||
pr.error_count++;
|
||||
}
|
||||
|
||||
void
|
||||
internal_error (expr_t *e, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
_error (e, "internal error", fmt, args);
|
||||
va_end (args);
|
||||
abort ();
|
||||
}
|
||||
|
||||
expr_t *
|
||||
error (expr_t *e, const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, fmt);
|
||||
_error (e, "error", fmt, args);
|
||||
va_end (args);
|
||||
|
||||
if (!e)
|
||||
e = new_expr ();
|
||||
e->type = ex_error;
|
||||
return e;
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "debug.h"
|
||||
#include "def.h"
|
||||
#include "defspace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "emit.h"
|
||||
#include "expr.h"
|
||||
#include "function.h"
|
||||
|
|
|
@ -44,6 +44,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
|||
|
||||
#include "QF/hash.h"
|
||||
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "grab.h"
|
||||
#include "options.h"
|
||||
|
|
|
@ -47,6 +47,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
|
||||
#include "def.h"
|
||||
#include "defspace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "qfcc.h"
|
||||
#include "expr.h"
|
||||
#include "idstuff.h"
|
||||
|
|
|
@ -58,6 +58,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
|||
#include "codespace.h"
|
||||
#include "def.h"
|
||||
#include "defspace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "emit.h"
|
||||
#include "expr.h"
|
||||
#include "immediate.h"
|
||||
|
|
|
@ -53,6 +53,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "class.h"
|
||||
#include "def.h"
|
||||
#include "defspace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "emit.h"
|
||||
#include "immediate.h"
|
||||
#include "method.h"
|
||||
|
|
|
@ -50,6 +50,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
|
||||
#include "class.h"
|
||||
#include "debug.h"
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "grab.h"
|
||||
#include "immediate.h"
|
||||
|
|
|
@ -49,6 +49,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "class.h"
|
||||
#include "debug.h"
|
||||
#include "def.h"
|
||||
#include "diagnostic.h"
|
||||
#include "emit.h"
|
||||
#include "expr.h"
|
||||
#include "function.h"
|
||||
|
|
|
@ -37,6 +37,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
|||
#include "QF/hash.h"
|
||||
|
||||
#include "debug.h"
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "grab.h"
|
||||
#include "qfcc.h"
|
||||
|
|
|
@ -44,6 +44,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
|||
#include "QF/dstring.h"
|
||||
|
||||
#include "codespace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "function.h"
|
||||
#include "qfcc.h"
|
||||
|
|
|
@ -45,6 +45,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "codespace.h"
|
||||
#include "def.h"
|
||||
#include "defspace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "emit.h"
|
||||
#include "expr.h"
|
||||
#include "function.h"
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "options.h"
|
||||
#include "qc-parse.h"
|
||||
|
|
|
@ -46,7 +46,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include "QF/dstring.h"
|
||||
#include "QF/hash.h"
|
||||
|
||||
#include "expr.h"
|
||||
#include "diagnostic.h"
|
||||
#include "options.h"
|
||||
#include "strpool.h"
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
|
||||
#include "def.h"
|
||||
#include "defspace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "emit.h"
|
||||
#include "expr.h"
|
||||
#include "immediate.h"
|
||||
|
|
|
@ -46,6 +46,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#include <QF/sys.h>
|
||||
|
||||
#include "def.h"
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "opcodes.h"
|
||||
#include "options.h"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "class.h"
|
||||
#include "def.h"
|
||||
#include "defspace.h"
|
||||
#include "diagnostic.h"
|
||||
#include "function.h"
|
||||
#include "qfcc.h"
|
||||
#include "strpool.h"
|
||||
|
|
|
@ -50,6 +50,7 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
|
||||
#include "class.h"
|
||||
#include "def.h"
|
||||
#include "diagnostic.h"
|
||||
#include "expr.h"
|
||||
#include "function.h"
|
||||
#include "options.h"
|
||||
|
@ -166,8 +167,7 @@ types_same (type_t *a, type_t *b)
|
|||
return 0;
|
||||
return 1;
|
||||
}
|
||||
error (0, "we be broke");
|
||||
abort ();
|
||||
internal_error (0, "we be broke");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue