mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-22 02:33:03 +00:00
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.
This commit is contained in:
@@ -46,11 +46,8 @@ add_column_width (int column, char const *buf, size_t bufsize)
|
|||||||
return column <= INT_MAX - width ? column + width : INT_MAX;
|
return column <= INT_MAX - width ? column + width : INT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set *LOC and adjust scanner cursor to account for token TOKEN of
|
static void
|
||||||
size SIZE. */
|
boundary_compute (boundary *cur, char const *token, size_t size)
|
||||||
|
|
||||||
void
|
|
||||||
location_compute (location *loc, boundary *cur, char const *token, size_t size)
|
|
||||||
{
|
{
|
||||||
int line = cur->line;
|
int line = cur->line;
|
||||||
int column = cur->column;
|
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 *p = token;
|
||||||
char const *lim = token + size;
|
char const *lim = token + size;
|
||||||
|
|
||||||
loc->start = *cur;
|
|
||||||
|
|
||||||
for (p = token; p < lim; ++p)
|
for (p = token; p < lim; ++p)
|
||||||
switch (*p)
|
switch (*p)
|
||||||
{
|
{
|
||||||
@@ -82,18 +77,29 @@ location_compute (location *loc, boundary *cur, char const *token, size_t size)
|
|||||||
byte += byte < INT_MAX;
|
byte += byte < INT_MAX;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
column = add_column_width (column, p0, p - p0);
|
||||||
|
|
||||||
cur->line = line;
|
cur->line = line;
|
||||||
cur->column = column = add_column_width (column, p0, p - p0);
|
cur->column = column;
|
||||||
cur->byte = byte;
|
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;
|
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"));
|
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"));
|
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"));
|
complain (loc, Wother, _("byte number overflow"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user