From 2274c34e91a9a80a32d2a43ffe35b923f07088a4 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 18 Sep 2019 18:06:24 +0200 Subject: [PATCH] diagnostics: extract boundary_compute from location_compute The handling of the contributions of the tabulations in the columns is burried inside location_compute. We will soon be willing to use the boundary part of the computation (to compute the current column number each time we read a multibyte char). * src/location.c (boundary_compute): New, extracted from... (location_compute): here. --- src/location.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/location.c b/src/location.c index 5b54e44d..593260a6 100644 --- a/src/location.c +++ b/src/location.c @@ -46,11 +46,8 @@ add_column_width (int column, char const *buf, size_t bufsize) return column <= INT_MAX - width ? column + width : INT_MAX; } -/* Set *LOC and adjust scanner cursor to account for token TOKEN of - size SIZE. */ - -void -location_compute (location *loc, boundary *cur, char const *token, size_t size) +static void +boundary_compute (boundary *cur, char const *token, size_t size) { int line = cur->line; int column = cur->column; @@ -59,8 +56,6 @@ location_compute (location *loc, boundary *cur, char const *token, size_t size) char const *p = token; char const *lim = token + size; - loc->start = *cur; - for (p = token; p < lim; ++p) switch (*p) { @@ -82,18 +77,29 @@ location_compute (location *loc, boundary *cur, char const *token, size_t size) byte += byte < INT_MAX; break; } + column = add_column_width (column, p0, p - p0); cur->line = line; - cur->column = column = add_column_width (column, p0, p - p0); + cur->column = column; cur->byte = byte; +} + +/* Set *LOC and adjust scanner cursor to account for token TOKEN of + size SIZE. */ + +void +location_compute (location *loc, boundary *cur, char const *token, size_t size) +{ + loc->start = *cur; + boundary_compute (cur, token, size); loc->end = *cur; - if (line == INT_MAX && loc->start.line != INT_MAX) + if (loc->end.line == INT_MAX && loc->start.line != INT_MAX) complain (loc, Wother, _("line number overflow")); - if (column == INT_MAX && loc->start.column != INT_MAX) + if (loc->end.column == INT_MAX && loc->start.column != INT_MAX) complain (loc, Wother, _("column number overflow")); - if (byte == INT_MAX && loc->start.byte != INT_MAX) + if (loc->end.byte == INT_MAX && loc->start.byte != INT_MAX) complain (loc, Wother, _("byte number overflow")); }