indent: use line number of the token start in diagnostics
Previously, the line number of the end of the token was used, which was confusing in debug mode.
This commit is contained in:
parent
18692033dc
commit
1cdfe3a93c
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: indent.c,v 1.387 2023/06/27 04:41:23 rillig Exp $ */
|
||||
/* $NetBSD: indent.c,v 1.388 2023/12/03 21:03:58 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
|
@ -38,7 +38,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: indent.c,v 1.387 2023/06/27 04:41:23 rillig Exp $");
|
||||
__RCSID("$NetBSD: indent.c,v 1.388 2023/12/03 21:03:58 rillig Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <err.h>
|
||||
|
@ -80,7 +80,6 @@ struct buffer com;
|
|||
|
||||
bool found_err;
|
||||
bool had_eof;
|
||||
int line_no = 1;
|
||||
|
||||
static struct {
|
||||
struct parser_state *item;
|
||||
|
@ -158,7 +157,7 @@ diag(int level, const char *msg, ...)
|
|||
|
||||
va_start(ap, msg);
|
||||
fprintf(stderr, "%s: %s:%d: ",
|
||||
level == 0 ? "warning" : "error", in_name, line_no);
|
||||
level == 0 ? "warning" : "error", in_name, token_start_line_no);
|
||||
vfprintf(stderr, msg, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
|
@ -580,7 +579,7 @@ process_newline(void)
|
|||
output_line();
|
||||
|
||||
stay_in_line:
|
||||
line_no++;
|
||||
token_end_line_no++;
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -1109,7 +1108,8 @@ indent(void)
|
|||
lexer_symbol lsym = lexi();
|
||||
|
||||
debug_blank_line();
|
||||
debug_printf("line %d: %s", line_no, lsym_name[lsym]);
|
||||
debug_printf("line %d: %s",
|
||||
token_start_line_no, lsym_name[lsym]);
|
||||
debug_print_buf("token", &token);
|
||||
debug_buffers();
|
||||
debug_blank_line();
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: indent.h,v 1.204 2023/06/26 20:03:09 rillig Exp $ */
|
||||
/* $NetBSD: indent.h,v 1.205 2023/12/03 21:03:58 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
||||
|
@ -249,7 +249,8 @@ extern struct options {
|
|||
|
||||
extern bool found_err;
|
||||
extern bool had_eof; /* whether input is exhausted */
|
||||
extern int line_no; /* the current input line number */
|
||||
extern int token_start_line_no;
|
||||
extern int token_end_line_no;
|
||||
extern enum indent_enabled {
|
||||
indent_on,
|
||||
indent_off,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: io.c,v 1.232 2023/06/27 04:41:23 rillig Exp $ */
|
||||
/* $NetBSD: io.c,v 1.233 2023/12/03 21:03:58 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
|
@ -38,7 +38,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: io.c,v 1.232 2023/06/27 04:41:23 rillig Exp $");
|
||||
__RCSID("$NetBSD: io.c,v 1.233 2023/12/03 21:03:58 rillig Exp $");
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -46,6 +46,8 @@ __RCSID("$NetBSD: io.c,v 1.232 2023/06/27 04:41:23 rillig Exp $");
|
|||
|
||||
struct buffer inp;
|
||||
const char *inp_p;
|
||||
int token_start_line_no;
|
||||
int token_end_line_no = 1;
|
||||
|
||||
struct output_state out;
|
||||
enum indent_enabled indent_enabled;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: lexi.c,v 1.240 2023/12/03 20:42:31 rillig Exp $ */
|
||||
/* $NetBSD: lexi.c,v 1.241 2023/12/03 21:03:58 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
|
@ -38,7 +38,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: lexi.c,v 1.240 2023/12/03 20:42:31 rillig Exp $");
|
||||
__RCSID("$NetBSD: lexi.c,v 1.241 2023/12/03 21:03:58 rillig Exp $");
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -188,7 +188,7 @@ skip_line_continuation(void)
|
|||
if (inp_p[0] == '\\' && inp_p[1] == '\n') {
|
||||
inp_p++;
|
||||
inp_skip();
|
||||
line_no++;
|
||||
token_end_line_no++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -245,7 +245,7 @@ lex_char_or_string(void)
|
|||
|
||||
if (token.s[token.len - 1] == '\\') {
|
||||
if (*inp_p == '\n')
|
||||
line_no++;
|
||||
token_end_line_no++;
|
||||
token_add_char(inp_next());
|
||||
}
|
||||
}
|
||||
|
@ -524,7 +524,7 @@ lex_asterisk_unary(void)
|
|||
if (*inp_p == '*')
|
||||
token_add_char('*');
|
||||
if (*inp_p == '\n')
|
||||
line_no++;
|
||||
token_end_line_no++;
|
||||
inp_skip();
|
||||
}
|
||||
|
||||
|
@ -579,6 +579,7 @@ lexi(void)
|
|||
else
|
||||
break;
|
||||
}
|
||||
token_start_line_no = token_end_line_no;
|
||||
|
||||
lexer_symbol alnum_lsym = lexi_alnum();
|
||||
if (alnum_lsym != lsym_eof)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pr_comment.c,v 1.171 2023/06/23 20:59:04 rillig Exp $ */
|
||||
/* $NetBSD: pr_comment.c,v 1.172 2023/12/03 21:03:58 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
|
@ -38,7 +38,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: pr_comment.c,v 1.171 2023/06/23 20:59:04 rillig Exp $");
|
||||
__RCSID("$NetBSD: pr_comment.c,v 1.172 2023/12/03 21:03:58 rillig Exp $");
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
@ -227,7 +227,7 @@ copy_comment_wrap_newline(ssize_t *last_blank, bool seen_newline)
|
|||
com_add_char(' ');
|
||||
*last_blank = (int)com.len - 1;
|
||||
}
|
||||
line_no++;
|
||||
token_end_line_no++;
|
||||
|
||||
/* flush any blanks and/or tabs at start of next line */
|
||||
inp_skip(); /* '\n' */
|
||||
|
@ -299,6 +299,7 @@ copy_comment_wrap(int line_length, bool delim)
|
|||
return;
|
||||
|
||||
unterminated_comment:
|
||||
token_start_line_no = token_end_line_no;
|
||||
diag(1, "Unterminated comment");
|
||||
output_line();
|
||||
}
|
||||
|
@ -314,13 +315,14 @@ copy_comment_nowrap(void)
|
|||
return;
|
||||
|
||||
if (had_eof) {
|
||||
token_start_line_no = token_end_line_no;
|
||||
diag(1, "Unterminated comment");
|
||||
output_line();
|
||||
return;
|
||||
}
|
||||
|
||||
output_line();
|
||||
line_no++;
|
||||
token_end_line_no++;
|
||||
inp_skip();
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue