Commit 6d2c2047 by Zack Weinberg

cpplex.c (cpp_idcmp): New function.

	* cpplex.c (cpp_idcmp): New function.
	* cpplib.h: Prototype it.
	* scan_decls.c (scan_decls): Use it to inspect token names.
	* fix-header.c (read_scan_file): Likewise.  Set system_header_p on
	the file being run through the preprocessor.
	(check_macro_names): Provide length of token to cpp_defined.

	* Makefile.in: Remove stale warning message.

From-SVN: r33552
parent 638d694d
...@@ -2297,7 +2297,6 @@ fixhdr.ready: fix-header ...@@ -2297,7 +2297,6 @@ fixhdr.ready: fix-header
# The if statement is so that we don't run fixproto a second time # The if statement is so that we don't run fixproto a second time
# if it has already been run on the files in `include'. # if it has already been run on the files in `include'.
stmp-fixproto: fixhdr.ready fixproto stmp-int-hdrs stmp-fixproto: fixhdr.ready fixproto stmp-int-hdrs
@echo "Various warnings and error messages from fixproto are normal"
if [ -f include/fixed ] ; then true; \ if [ -f include/fixed ] ; then true; \
else \ else \
: This line works around a 'make' bug in BSDI 1.1.; \ : This line works around a 'make' bug in BSDI 1.1.; \
......
...@@ -2048,6 +2048,37 @@ _cpp_init_input_buffer (pfile) ...@@ -2048,6 +2048,37 @@ _cpp_init_input_buffer (pfile)
pfile->input_buffer_len = 8192; pfile->input_buffer_len = 8192;
} }
/* Utility routine:
Compares, in the manner of strcmp(3), the token beginning at TOKEN
and extending for LEN characters to the NUL-terminated string
STRING. Typical usage:
if (! cpp_idcmp (pfile->token_buffer + here, CPP_WRITTEN (pfile) - here,
"inline"))
{ ... }
*/
int
cpp_idcmp (token, len, string)
const U_CHAR *token;
size_t len;
const char *string;
{
size_t len2 = strlen (string);
int r;
if ((r = memcmp (token, string, MIN (len, len2))))
return r;
/* The longer of the two strings sorts after the shorter. */
if (len == len2)
return 0;
else if (len < len2)
return -1;
else
return 1;
}
#if 0 #if 0
/* Lexing algorithm. /* Lexing algorithm.
......
...@@ -655,8 +655,8 @@ extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *, ...@@ -655,8 +655,8 @@ extern cpp_buffer *cpp_push_buffer PARAMS ((cpp_reader *,
extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *)); extern cpp_buffer *cpp_pop_buffer PARAMS ((cpp_reader *));
extern void cpp_scan_buffer PARAMS ((cpp_reader *, cpp_printer *)); extern void cpp_scan_buffer PARAMS ((cpp_reader *, cpp_printer *));
extern void cpp_scan_buffer_nooutput PARAMS ((cpp_reader *)); extern void cpp_scan_buffer_nooutput PARAMS ((cpp_reader *));
extern int cpp_idcmp PARAMS ((const unsigned char *,
size_t, const char *));
/* In cpphash.c */ /* In cpphash.c */
extern int cpp_defined PARAMS ((cpp_reader *, extern int cpp_defined PARAMS ((cpp_reader *,
......
...@@ -602,11 +602,13 @@ check_macro_names (pfile, names) ...@@ -602,11 +602,13 @@ check_macro_names (pfile, names)
cpp_reader *pfile; cpp_reader *pfile;
namelist names; namelist names;
{ {
size_t len;
while (*names) while (*names)
{ {
if (cpp_defined (pfile, names, -1)) len = strlen (names);
if (cpp_defined (pfile, names, len))
recognized_macro (names); recognized_macro (names);
names += strlen (names) + 1; names += len + 1;
} }
} }
...@@ -637,6 +639,9 @@ read_scan_file (in_fname, argc, argv) ...@@ -637,6 +639,9 @@ read_scan_file (in_fname, argc, argv)
if (! cpp_start_read (&scan_in, 0, in_fname)) if (! cpp_start_read (&scan_in, 0, in_fname))
exit (FATAL_EXIT_CODE); exit (FATAL_EXIT_CODE);
/* We are scanning a system header, so mark it as such. */
CPP_BUFFER (&scan_in)->system_header_p = 1;
scan_decls (&scan_in, argc, argv); scan_decls (&scan_in, argc, argv);
for (cur_symbols = &symbol_table[0]; cur_symbols->names; cur_symbols++) for (cur_symbols = &symbol_table[0]; cur_symbols->names; cur_symbols++)
check_macro_names (&scan_in, cur_symbols->names); check_macro_names (&scan_in, cur_symbols->names);
...@@ -663,6 +668,8 @@ read_scan_file (in_fname, argc, argv) ...@@ -663,6 +668,8 @@ read_scan_file (in_fname, argc, argv)
{ {
enum cpp_ttype token = cpp_get_token (&scan_in); enum cpp_ttype token = cpp_get_token (&scan_in);
int length = CPP_WRITTEN (&scan_in) - old_written; int length = CPP_WRITTEN (&scan_in) - old_written;
unsigned char *id = scan_in.token_buffer + old_written;
CPP_SET_WRITTEN (&scan_in, old_written); CPP_SET_WRITTEN (&scan_in, old_written);
if (token == CPP_EOF) /* Should not happen ... */ if (token == CPP_EOF) /* Should not happen ... */
break; break;
...@@ -671,8 +678,7 @@ read_scan_file (in_fname, argc, argv) ...@@ -671,8 +678,7 @@ read_scan_file (in_fname, argc, argv)
cpp_pop_buffer (&scan_in); cpp_pop_buffer (&scan_in);
break; break;
} }
if (token == CPP_NAME && length == 7 if (token == CPP_NAME && cpp_idcmp (id, length, "_filbuf") == 0)
&& strcmp ("_filbuf", scan_in.token_buffer + old_written) == 0)
seen_filbuf++; seen_filbuf++;
} }
if (seen_filbuf) if (seen_filbuf)
...@@ -690,7 +696,7 @@ read_scan_file (in_fname, argc, argv) ...@@ -690,7 +696,7 @@ read_scan_file (in_fname, argc, argv)
SET_REQUIRED (fn); SET_REQUIRED (fn);
if (need_flsbuf) if (need_flsbuf)
SET_REQUIRED (flsbuf_fn); SET_REQUIRED (flsbuf_fn);
if (need_flsbuf + need_filbuf == 2) if (need_flsbuf && need_filbuf)
new_list = "_filbuf\0_flsbuf\0"; new_list = "_filbuf\0_flsbuf\0";
else if (need_flsbuf) else if (need_flsbuf)
new_list = "_flsbuf\0"; new_list = "_flsbuf\0";
......
...@@ -191,9 +191,7 @@ scan_decls (pfile, argc, argv) ...@@ -191,9 +191,7 @@ scan_decls (pfile, argc, argv)
maybe_handle_comma: maybe_handle_comma:
if (token != CPP_COMMA) if (token != CPP_COMMA)
goto new_statement; goto new_statement;
#if 0
handle_comma:
#endif
/* Handle multiple declarators in a single declaration, /* Handle multiple declarators in a single declaration,
as in: extern char *strcpy (), *strcat (), ... ; */ as in: extern char *strcpy (), *strcat (), ... ; */
if (declarator_start == 0) if (declarator_start == 0)
...@@ -202,12 +200,14 @@ scan_decls (pfile, argc, argv) ...@@ -202,12 +200,14 @@ scan_decls (pfile, argc, argv)
break; break;
case CPP_NAME: case CPP_NAME:
/* "inline" and "extern" are recognized but skipped */ /* "inline" and "extern" are recognized but skipped */
if (strcmp (pfile->token_buffer, "inline") == 0) if (!cpp_idcmp (pfile->token_buffer,
CPP_WRITTEN (pfile), "inline"))
{ {
saw_inline = 1; saw_inline = 1;
CPP_SET_WRITTEN (pfile, start_written); CPP_SET_WRITTEN (pfile, start_written);
} }
if (strcmp (pfile->token_buffer, "extern") == 0) else if (!cpp_idcmp (pfile->token_buffer,
CPP_WRITTEN (pfile), "extern"))
{ {
saw_extern = 1; saw_extern = 1;
CPP_SET_WRITTEN (pfile, start_written); CPP_SET_WRITTEN (pfile, start_written);
......
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