Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: when debugging the parser, write m...
details: https://anonhg.NetBSD.org/src/rev/37883bc83a2b
branches: trunk
changeset: 377403:37883bc83a2b
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Jul 10 19:58:47 2023 +0000
description:
lint: when debugging the parser, write messages on stderr
This way, all messages (regular debug, yacc debug, lint diagnostics)
occur in the correct order.
diffstat:
usr.bin/xlint/lint1/cgram.y | 12 ++++++---
usr.bin/xlint/lint1/err.c | 55 +++++++++++++++++++++++++-------------------
2 files changed, 39 insertions(+), 28 deletions(-)
diffs (179 lines):
diff -r a1793c6e7071 -r 37883bc83a2b usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Mon Jul 10 19:47:12 2023 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Mon Jul 10 19:58:47 2023 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.451 2023/07/10 19:47:12 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.452 2023/07/10 19:58:47 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.451 2023/07/10 19:47:12 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.452 2023/07/10 19:58:47 rillig Exp $");
#endif
#include <limits.h>
@@ -160,7 +160,7 @@ is_either(const char *s, const char *a,
else
fprintf(yyo, "%Lg", $$->u.floating);
} <y_val>
-%printer { fprintf(yyo, "'%s'", $$->sb_name); } <y_name>
+%printer { fprintf(yyo, "'%s'", $$ != NULL ? $$->sb_name : "<null>"); } <y_name>
%printer { debug_sym("", $$, ""); } <y_sym>
%printer { fprintf(yyo, "%s", op_name($$)); } <y_op>
%printer { fprintf(yyo, "%s", scl_name($$)); } <y_scl>
@@ -168,7 +168,11 @@ is_either(const char *s, const char *a,
%printer { fprintf(yyo, "%s", tqual_name($$)); } <y_tqual>
%printer { fprintf(yyo, "%s", type_name($$)); } <y_type>
%printer {
- fprintf(yyo, "%s '%s'", op_name($$->tn_op), type_name($$->tn_type));
+ if ($$ == NULL)
+ fprintf(yyo, "<null>");
+ else
+ fprintf(yyo, "%s '%s'",
+ op_name($$->tn_op), type_name($$->tn_type));
} <y_tnode>
%printer { fprintf(yyo, "%zu to %zu", $$.lo, $$.hi); } <y_range>
%printer { fprintf(yyo, "length %zu", $$->st_len); } <y_string>
diff -r a1793c6e7071 -r 37883bc83a2b usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Mon Jul 10 19:47:12 2023 +0000
+++ b/usr.bin/xlint/lint1/err.c Mon Jul 10 19:58:47 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.209 2023/07/09 12:04:08 rillig Exp $ */
+/* $NetBSD: err.c,v 1.210 2023/07/10 19:58:47 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
-__RCSID("$NetBSD: err.c,v 1.209 2023/07/09 12:04:08 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.210 2023/07/10 19:58:47 rillig Exp $");
#endif
#include <limits.h>
@@ -517,18 +517,24 @@ lbasename(const char *path)
return base;
}
+static FILE *
+output_channel(void)
+{
+ return yflag ? stderr : stdout;
+}
+
static void
verror_at(int msgid, const pos_t *pos, va_list ap)
{
- const char *fn;
if (is_suppressed[msgid])
return;
- fn = lbasename(pos->p_file);
- (void)printf("%s(%d): error: ", fn, pos->p_line);
- (void)vprintf(msgs[msgid], ap);
- (void)printf(" [%d]\n", msgid);
+ FILE *out = output_channel();
+ (void)fprintf(out, "%s(%d): error: ",
+ lbasename(pos->p_file), pos->p_line);
+ (void)vfprintf(out, msgs[msgid], ap);
+ (void)fprintf(out, " [%d]\n", msgid);
seen_error = true;
print_stack_trace();
}
@@ -536,7 +542,6 @@ verror_at(int msgid, const pos_t *pos, v
static void
vwarning_at(int msgid, const pos_t *pos, va_list ap)
{
- const char *fn;
if (is_suppressed[msgid])
return;
@@ -546,10 +551,11 @@ vwarning_at(int msgid, const pos_t *pos,
/* this warning is suppressed by a LINTED comment */
return;
- fn = lbasename(pos->p_file);
- (void)printf("%s(%d): warning: ", fn, pos->p_line);
- (void)vprintf(msgs[msgid], ap);
- (void)printf(" [%d]\n", msgid);
+ FILE *out = output_channel();
+ (void)fprintf(out, "%s(%d): warning: ",
+ lbasename(pos->p_file), pos->p_line);
+ (void)vfprintf(out, msgs[msgid], ap);
+ (void)fprintf(out, " [%d]\n", msgid);
seen_warning = true;
print_stack_trace();
}
@@ -557,15 +563,15 @@ vwarning_at(int msgid, const pos_t *pos,
static void
vmessage_at(int msgid, const pos_t *pos, va_list ap)
{
- const char *fn;
if (is_suppressed[msgid])
return;
- fn = lbasename(pos->p_file);
- (void)printf("%s(%d): ", fn, pos->p_line);
- (void)vprintf(msgs[msgid], ap);
- (void)printf(" [%d]\n", msgid);
+ FILE *out = output_channel();
+ (void)fprintf(out, "%s(%d): ",
+ lbasename(pos->p_file), pos->p_line);
+ (void)vfprintf(out, msgs[msgid], ap);
+ (void)fprintf(out, " [%d]\n", msgid);
print_stack_trace();
}
@@ -592,7 +598,6 @@ void
void
assert_failed(const char *file, int line, const char *func, const char *cond)
{
- const char *fn;
/*
* After encountering a parse error in the grammar, lint often does
@@ -607,11 +612,11 @@ assert_failed(const char *file, int line
if (sytxerr > 0)
norecover();
- fn = lbasename(curr_pos.p_file);
(void)fflush(stdout);
(void)fprintf(stderr,
"lint: assertion \"%s\" failed in %s at %s:%d near %s:%d\n",
- cond, func, file, line, fn, curr_pos.p_line);
+ cond, func, file, line,
+ lbasename(curr_pos.p_file), curr_pos.p_line);
print_stack_trace();
(void)fflush(stdout);
abort();
@@ -731,16 +736,18 @@ static bool is_query_enabled[sizeof(quer
void
(query_message)(int query_id, ...)
{
- va_list ap;
if (!is_query_enabled[query_id])
return;
- (void)printf("%s(%d): ", lbasename(curr_pos.p_file), curr_pos.p_line);
+ va_list ap;
+ FILE *out = output_channel();
+ (void)fprintf(out, "%s(%d): ",
+ lbasename(curr_pos.p_file), curr_pos.p_line);
va_start(ap, query_id);
- (void)vprintf(queries[query_id], ap);
+ (void)vfprintf(out, queries[query_id], ap);
va_end(ap);
- (void)printf(" [Q%d]\n", query_id);
+ (void)fprintf(out, " [Q%d]\n", query_id);
print_stack_trace();
}
Home |
Main Index |
Thread Index |
Old Index