Commit a73ac7a5 by Zack Weinberg Committed by Zack Weinberg

cppfiles.c (find_position): Drop 'colp' argument, return the new line base.

	* cppfiles.c (find_position): Drop 'colp' argument, return the
	new line base.
	(read_and_prescan): Adjust to match.  Don't ever manipulate
	line or line_base except via find_position.

From-SVN: r31700
parent bb4cd708
2000-01-30 Zack Weinberg <zack@wolery.cumb.org>
* cppfiles.c (find_position): Drop 'colp' argument, return the
new line base.
(read_and_prescan): Adjust to match. Don't ever manipulate
line or line_base except via find_position.
2000-01-29 Zack Weinberg <zack@wolery.cumb.org> 2000-01-29 Zack Weinberg <zack@wolery.cumb.org>
* c-parse.in: Apply Ulrich's changes from c-parse.y. * c-parse.in: Apply Ulrich's changes from c-parse.y.
......
...@@ -34,23 +34,22 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -34,23 +34,22 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static struct include_hash *redundant_include_p static struct include_hash *redundant_include_p
PARAMS ((cpp_reader *, PARAMS ((cpp_reader *,
struct include_hash *, struct include_hash *,
struct file_name_list *)); struct file_name_list *));
static struct file_name_map *read_name_map PARAMS ((cpp_reader *, static struct file_name_map *read_name_map
const char *)); PARAMS ((cpp_reader *, const char *));
static char *read_filename_string PARAMS ((int, FILE *)); static char *read_filename_string PARAMS ((int, FILE *));
static char *remap_filename PARAMS ((cpp_reader *, char *, static char *remap_filename PARAMS ((cpp_reader *, char *,
struct file_name_list *)); struct file_name_list *));
static long read_and_prescan PARAMS ((cpp_reader *, cpp_buffer *, static long read_and_prescan PARAMS ((cpp_reader *, cpp_buffer *,
int, size_t)); int, size_t));
static struct file_name_list *actual_directory PARAMS ((cpp_reader *, static struct file_name_list *actual_directory
const char *)); PARAMS ((cpp_reader *, const char *));
static void initialize_input_buffer PARAMS ((cpp_reader *, int, static void initialize_input_buffer PARAMS ((cpp_reader *, int,
struct stat *)); struct stat *));
static int file_cleanup PARAMS ((cpp_buffer *, cpp_reader *)); static int file_cleanup PARAMS ((cpp_buffer *, cpp_reader *));
static void find_position PARAMS ((U_CHAR *, U_CHAR *, static U_CHAR *find_position PARAMS ((U_CHAR *, U_CHAR *,
unsigned long *, unsigned long *));
unsigned long *));
#if 0 #if 0
static void hack_vms_include_specification PARAMS ((char *)); static void hack_vms_include_specification PARAMS ((char *));
...@@ -772,23 +771,25 @@ actual_directory (pfile, fname) ...@@ -772,23 +771,25 @@ actual_directory (pfile, fname)
} }
/* Determine the current line and column. Used only by read_and_prescan. */ /* Determine the current line and column. Used only by read_and_prescan. */
static void static U_CHAR *
find_position (start, limit, linep, colp) find_position (start, limit, linep)
U_CHAR *start; U_CHAR *start;
U_CHAR *limit; U_CHAR *limit;
unsigned long *linep; unsigned long *linep;
unsigned long *colp;
{ {
unsigned long line = *linep, col = 0; unsigned long line = *linep;
U_CHAR *lbase = start;
while (start < limit) while (start < limit)
{ {
U_CHAR ch = *start++; U_CHAR ch = *start++;
if (ch == '\n' || ch == '\r') if (ch == '\n' || ch == '\r')
line++, col = 1; {
else line++;
col++; lbase = start;
}
} }
*linep = line, *colp = col; *linep = line;
return lbase;
} }
/* Read the entire contents of file DESC into buffer BUF. LEN is how /* Read the entire contents of file DESC into buffer BUF. LEN is how
...@@ -950,8 +951,6 @@ read_and_prescan (pfile, fp, desc, len) ...@@ -950,8 +951,6 @@ read_and_prescan (pfile, fp, desc, len)
*op++ = '\r'; *op++ = '\r';
else else
deferred_newlines++; deferred_newlines++;
line++;
line_base = op;
} }
else if (*ip == '\r') else if (*ip == '\r')
{ {
...@@ -967,8 +966,6 @@ read_and_prescan (pfile, fp, desc, len) ...@@ -967,8 +966,6 @@ read_and_prescan (pfile, fp, desc, len)
*op++ = '\r'; *op++ = '\r';
else else
deferred_newlines++; deferred_newlines++;
line++;
line_base = op;
} }
else else
*op++ = '\\'; *op++ = '\\';
...@@ -1023,10 +1020,14 @@ read_and_prescan (pfile, fp, desc, len) ...@@ -1023,10 +1020,14 @@ read_and_prescan (pfile, fp, desc, len)
if (CPP_OPTIONS (pfile)->warn_trigraphs) if (CPP_OPTIONS (pfile)->warn_trigraphs)
{ {
unsigned long col; unsigned long col;
find_position (line_base, op, &line, &col); line_base = find_position (line_base, op, &line);
line_base = op - col; col = op - line_base + 1;
cpp_warning_with_line (pfile, line, col, if (CPP_OPTIONS (pfile)->trigraphs)
"trigraph ??%c encountered", d); cpp_warning_with_line (pfile, line, col,
"trigraph ??%c converted to %c", d, t);
else
cpp_warning_with_line (pfile, line, col,
"trigraph ??%c ignored", d);
} }
if (CPP_OPTIONS (pfile)->trigraphs) if (CPP_OPTIONS (pfile)->trigraphs)
{ {
...@@ -1075,7 +1076,8 @@ read_and_prescan (pfile, fp, desc, len) ...@@ -1075,7 +1076,8 @@ read_and_prescan (pfile, fp, desc, len)
if (op[-1] != '\n') if (op[-1] != '\n')
{ {
unsigned long col; unsigned long col;
find_position (line_base, op, &line, &col); line_base = find_position (line_base, op, &line);
col = op - line_base + 1;
cpp_warning_with_line (pfile, line, col, "no newline at end of file\n"); cpp_warning_with_line (pfile, line, col, "no newline at end of file\n");
if (offset + 1 > len) if (offset + 1 > len)
{ {
......
/* Regression test for trigraph warnings. Under certain conditions we
got the line numbers wrong.
Originally exposed by XEmacs and reported by Martin Buchholz
<martin@xemacs.org>; this test case is synthetic. */
/* { dg-do preprocess } */
/* { dg-options -Wall } */
#define some_macro \
blah \
blah \
blah \
blah
??> /* { dg-warning "trigraph ..." "trigraph encountered" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment