Commit 941e09b6 by Zack Weinberg Committed by Dave Brolley

cpplib.c: Make all directive handlers read their own arguments.

1998-12-14 00:56 -0500  Zack Weinberg  <zack@rabi.phys.columbia.edu>
	* cpplib.c: Make all directive handlers read their own
          arguments.
	  (struct directive): Remove last two arguments from FUNC
          member prototype. Remove `command_reads_line' member
          entirely.
	  (directive_table): Remove initializations of
          command_reads_line flag.  Pretty-print.
	  (eval_if_expression, do_define, do_line, do_include,
          do_undef, do_error, do_pragma, do_ident, do_if, do_xifdef,
          do_else, do_elif, do_sccs, do_assert, do_unassert,
          do_warning): Take only two args.
	  (cpp_define): Call do_define with two args and the text to
	  define stuffed into a buffer.
	  (make_assertion): Call do_assert with two args.
	  (handle_directive): Call do_line with two args. Call
	  kt->func with two args.  Remove command_reads_line
	  processing.
	  (do_define, do_undef, do_error, do_warning, do_pragma,
	  do_sccs): Read the rest of the line here.
	  (do_ident): Gobble rest of line, as cccp does.
	  (cpp_undef): New function.
	  (cpp_start_read): Call cpp_undef instead of do_undef.

From-SVN: r24326
parent 7061aa5a
1998-12-15 Zack Weinberg <zack@rabi.phys.columbia.edu> 1998-12-15 Zack Weinberg <zack@rabi.phys.columbia.edu>
* cpplib.c: Make all directive handlers read their own
arguments.
(struct directive): Remove last two arguments from FUNC
member prototype. Remove `command_reads_line' member
entirely.
(directive_table): Remove initializations of
command_reads_line flag. Pretty-print.
(eval_if_expression, do_define, do_line, do_include,
do_undef, do_error, do_pragma, do_ident, do_if, do_xifdef,
do_else, do_elif, do_sccs, do_assert, do_unassert,
do_warning): Take only two args.
(cpp_define): Call do_define with two args and the text to
define stuffed into a buffer.
(make_assertion): Call do_assert with two args.
(handle_directive): Call do_line with two args. Call
kt->func with two args. Remove command_reads_line
processing.
(do_define, do_undef, do_error, do_warning, do_pragma,
do_sccs): Read the rest of the line here.
(do_ident): Gobble rest of line, as cccp does.
(cpp_undef): New function.
(cpp_start_read): Call cpp_undef instead of do_undef.
1998-12-15 Zack Weinberg <zack@rabi.phys.columbia.edu>
* cpphash.h (union hash_value): Remove `keydef' member, add a * cpphash.h (union hash_value): Remove `keydef' member, add a
`struct hashnode *aschain' member for #assert. `struct hashnode *aschain' member for #assert.
......
...@@ -159,7 +159,7 @@ extern void fancy_abort (); ...@@ -159,7 +159,7 @@ extern void fancy_abort ();
static int check_macro_name PROTO ((cpp_reader *, U_CHAR *, char *)); static int check_macro_name PROTO ((cpp_reader *, U_CHAR *, char *));
static int compare_defs PROTO ((cpp_reader *, static int compare_defs PROTO ((cpp_reader *,
DEFINITION *, DEFINITION *)); DEFINITION *, DEFINITION *));
static HOST_WIDE_INT eval_if_expression PROTO ((cpp_reader *, U_CHAR *, int)); static HOST_WIDE_INT eval_if_expression PROTO ((cpp_reader *));
static int change_newlines PROTO ((U_CHAR *, int)); static int change_newlines PROTO ((U_CHAR *, int));
static void push_macro_expansion PARAMS ((cpp_reader *, static void push_macro_expansion PARAMS ((cpp_reader *,
U_CHAR *, int, HASHNODE *)); U_CHAR *, int, HASHNODE *));
...@@ -243,34 +243,33 @@ static struct default_include { ...@@ -243,34 +243,33 @@ static struct default_include {
struct directive { struct directive {
int length; /* Length of name */ int length; /* Length of name */
int (*func) /* Function to handle directive */ int (*func) /* Function to handle directive */
PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); PARAMS ((cpp_reader *, struct directive *));
char *name; /* Name of directive */ char *name; /* Name of directive */
enum node_type type; /* Code which describes which directive. */ enum node_type type; /* Code which describes which directive. */
char command_reads_line; /* One if rest of line is read by func. */
}; };
/* These functions are declared to return int instead of void since they /* These functions are declared to return int instead of void since they
are going to be placed in a table and some old compilers have trouble with are going to be placed in a table and some old compilers have trouble with
pointers to functions returning void. */ pointers to functions returning void. */
static int do_define PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_define PARAMS ((cpp_reader *, struct directive *));
static int do_line PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_line PARAMS ((cpp_reader *, struct directive *));
static int do_include PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_include PARAMS ((cpp_reader *, struct directive *));
static int do_undef PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_undef PARAMS ((cpp_reader *, struct directive *));
static int do_error PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_error PARAMS ((cpp_reader *, struct directive *));
static int do_pragma PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_pragma PARAMS ((cpp_reader *, struct directive *));
static int do_ident PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_ident PARAMS ((cpp_reader *, struct directive *));
static int do_if PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_if PARAMS ((cpp_reader *, struct directive *));
static int do_xifdef PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_xifdef PARAMS ((cpp_reader *, struct directive *));
static int do_else PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_else PARAMS ((cpp_reader *, struct directive *));
static int do_elif PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_elif PARAMS ((cpp_reader *, struct directive *));
static int do_endif PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_endif PARAMS ((cpp_reader *, struct directive *));
#ifdef SCCS_DIRECTIVE #ifdef SCCS_DIRECTIVE
static int do_sccs PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_sccs PARAMS ((cpp_reader *, struct directive *));
#endif #endif
static int do_assert PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_assert PARAMS ((cpp_reader *, struct directive *));
static int do_unassert PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_unassert PARAMS ((cpp_reader *, struct directive *));
static int do_warning PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHAR *)); static int do_warning PARAMS ((cpp_reader *, struct directive *));
#define IS_INCLUDE_DIRECTIVE_TYPE(t) \ #define IS_INCLUDE_DIRECTIVE_TYPE(t) \
((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT) ((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT)
...@@ -279,28 +278,28 @@ static int do_warning PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHA ...@@ -279,28 +278,28 @@ static int do_warning PARAMS ((cpp_reader *, struct directive *, U_CHAR *, U_CHA
The initialize_builtins function assumes #define is the very first. */ The initialize_builtins function assumes #define is the very first. */
static struct directive directive_table[] = { static struct directive directive_table[] = {
{ 6, do_define, "define", T_DEFINE, 0}, { 6, do_define, "define", T_DEFINE },
{ 5, do_xifdef, "ifdef", T_IFDEF, 1}, { 5, do_xifdef, "ifdef", T_IFDEF },
{ 6, do_xifdef, "ifndef", T_IFNDEF, 1}, { 6, do_xifdef, "ifndef", T_IFNDEF },
{ 7, do_include, "include", T_INCLUDE, 1}, { 7, do_include, "include", T_INCLUDE },
{ 12, do_include, "include_next", T_INCLUDE_NEXT, 1}, { 12, do_include, "include_next", T_INCLUDE_NEXT },
{ 6, do_include, "import", T_IMPORT, 1}, { 6, do_include, "import", T_IMPORT },
{ 5, do_endif, "endif", T_ENDIF, 1}, { 5, do_endif, "endif", T_ENDIF },
{ 4, do_else, "else", T_ELSE, 1}, { 4, do_else, "else", T_ELSE },
{ 2, do_if, "if", T_IF, 1}, { 2, do_if, "if", T_IF },
{ 4, do_elif, "elif", T_ELIF, 1}, { 4, do_elif, "elif", T_ELIF },
{ 5, do_undef, "undef", T_UNDEF, 0}, { 5, do_undef, "undef", T_UNDEF },
{ 5, do_error, "error", T_ERROR, 0}, { 5, do_error, "error", T_ERROR },
{ 7, do_warning, "warning", T_WARNING, 0}, { 7, do_warning, "warning", T_WARNING },
{ 6, do_pragma, "pragma", T_PRAGMA, 0}, { 6, do_pragma, "pragma", T_PRAGMA },
{ 4, do_line, "line", T_LINE, 1}, { 4, do_line, "line", T_LINE },
{ 5, do_ident, "ident", T_IDENT, 1}, { 5, do_ident, "ident", T_IDENT },
#ifdef SCCS_DIRECTIVE #ifdef SCCS_DIRECTIVE
{ 4, do_sccs, "sccs", T_SCCS, 0}, { 4, do_sccs, "sccs", T_SCCS },
#endif #endif
{ 6, do_assert, "assert", T_ASSERT, 1}, { 6, do_assert, "assert", T_ASSERT },
{ 8, do_unassert, "unassert", T_UNASSERT, 1}, { 8, do_unassert, "unassert", T_UNASSERT },
{ -1, 0, "", T_UNUSED, 0}, { -1, 0, "", T_UNUSED }
}; };
/* table to tell if char can be part of a C identifier. */ /* table to tell if char can be part of a C identifier. */
...@@ -467,7 +466,11 @@ cpp_define (pfile, str) ...@@ -467,7 +466,11 @@ cpp_define (pfile, str)
*q = 0; *q = 0;
} }
do_define (pfile, NULL, buf, buf + strlen (buf)); if (cpp_push_buffer (pfile, buf, strlen (buf)) != NULL)
{
do_define (pfile, NULL);
cpp_pop_buffer (pfile);
}
} }
/* Process the string STR as if it appeared as the body of a #assert. /* Process the string STR as if it appeared as the body of a #assert.
...@@ -508,10 +511,10 @@ make_assertion (pfile, option, str) ...@@ -508,10 +511,10 @@ make_assertion (pfile, option, str)
cpp_error (pfile, "malformed option `%s %s'", option, str); cpp_error (pfile, "malformed option `%s %s'", option, str);
return; return;
} }
if (cpp_push_buffer (pfile, buf, strlen (buf)) != NULL) if (cpp_push_buffer (pfile, buf, strlen (buf)) != NULL)
{ {
do_assert (pfile, NULL, NULL, NULL); do_assert (pfile, NULL);
cpp_pop_buffer (pfile); cpp_pop_buffer (pfile);
} }
} }
...@@ -793,8 +796,7 @@ handle_directive (pfile) ...@@ -793,8 +796,7 @@ handle_directive (pfile)
{ int c; { int c;
register struct directive *kt; register struct directive *kt;
int ident_length; int ident_length;
long after_ident; U_CHAR *ident;
U_CHAR *ident, *line_end;
long old_written = CPP_WRITTEN (pfile); long old_written = CPP_WRITTEN (pfile);
cpp_skip_hspace (pfile); cpp_skip_hspace (pfile);
...@@ -805,7 +807,7 @@ handle_directive (pfile) ...@@ -805,7 +807,7 @@ handle_directive (pfile)
/* Handle # followed by a line number. */ /* Handle # followed by a line number. */
if (CPP_PEDANTIC (pfile)) if (CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "`#' followed by integer"); cpp_pedwarn (pfile, "`#' followed by integer");
do_line (pfile, NULL, NULL, NULL); do_line (pfile, NULL);
goto done_a_directive; goto done_a_directive;
} }
...@@ -851,40 +853,23 @@ handle_directive (pfile) ...@@ -851,40 +853,23 @@ handle_directive (pfile)
for (kt = directive_table; ; kt++) { for (kt = directive_table; ; kt++) {
if (kt->length <= 0) if (kt->length <= 0)
goto not_a_directive; goto not_a_directive;
if (kt->length == ident_length && !strncmp (kt->name, ident, ident_length)) if (kt->length == ident_length
&& !strncmp (kt->name, ident, ident_length))
break; break;
} }
if (kt->command_reads_line)
after_ident = 0;
else
{
/* Nonzero means do not delete comments within the directive.
#define needs this when -traditional. */
int comments = CPP_TRADITIONAL (pfile) && kt->type == T_DEFINE;
int save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
CPP_OPTIONS (pfile)->put_out_comments = comments;
after_ident = CPP_WRITTEN (pfile);
copy_rest_of_line (pfile);
CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
}
/* We may want to pass through #define, #pragma, and #include. /* We may want to pass through #define, #pragma, and #include.
Other directives may create output, but we don't want the directive Other directives may create output, but we don't want the directive
itself out, so we pop it now. For example conditionals may emit itself out, so we pop it now. For example conditionals may emit
#failed ... #endfailed stuff. But note that popping the buffer #failed ... #endfailed stuff. */
means the parameters to kt->func may point after pfile->limit
so these parameters are invalid as soon as something gets appended
to the token_buffer. */
line_end = CPP_PWRITTEN (pfile);
if (! (kt->type == T_DEFINE if (! (kt->type == T_DEFINE
|| kt->type == T_PRAGMA || kt->type == T_PRAGMA
|| (IS_INCLUDE_DIRECTIVE_TYPE (kt->type) || (IS_INCLUDE_DIRECTIVE_TYPE (kt->type)
&& CPP_OPTIONS (pfile)->dump_includes))) && CPP_OPTIONS (pfile)->dump_includes)))
CPP_SET_WRITTEN (pfile, old_written); CPP_SET_WRITTEN (pfile, old_written);
(*kt->func) (pfile, kt, pfile->token_buffer + after_ident, line_end); (*kt->func) (pfile, kt);
if (kt->type == T_DEFINE) if (kt->type == T_DEFINE)
{ {
...@@ -911,7 +896,7 @@ handle_directive (pfile) ...@@ -911,7 +896,7 @@ handle_directive (pfile)
/* Pass a directive through to the output file. /* Pass a directive through to the output file.
BUF points to the contents of the directive, as a contiguous string. BUF points to the contents of the directive, as a contiguous string.
LIMIT points to the first character past the end of the directive. m LIMIT points to the first character past the end of the directive.
KEYWORD is the keyword-table entry for the directive. */ KEYWORD is the keyword-table entry for the directive. */
static void static void
...@@ -1533,28 +1518,44 @@ comp_def_part (first, beg1, len1, beg2, len2, last) ...@@ -1533,28 +1518,44 @@ comp_def_part (first, beg1, len1, beg2, len2, last)
} }
/* Process a #define command. /* Process a #define command.
BUF points to the contents of the #define command, as a contiguous string.
LIMIT points to the first character past the end of the definition.
KEYWORD is the keyword-table entry for #define, KEYWORD is the keyword-table entry for #define,
or NULL for a "predefined" macro. */ or NULL for a "predefined" macro. */
static int static int
do_define (pfile, keyword, buf, limit) do_define (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword; struct directive *keyword;
U_CHAR *buf, *limit;
{ {
int hashcode; int hashcode;
MACRODEF mdef; MACRODEF mdef;
HASHNODE *hp; HASHNODE *hp;
int save_put_out_comments;
long here;
U_CHAR *macro, *buf, *end;
here = CPP_WRITTEN (pfile);
save_put_out_comments = CPP_OPTIONS (pfile)->put_out_comments;
CPP_OPTIONS (pfile)->put_out_comments = CPP_TRADITIONAL (pfile);
copy_rest_of_line (pfile);
CPP_OPTIONS (pfile)->put_out_comments = save_put_out_comments;
/* Copy out the line so we can pop the token buffer. */
buf = pfile->token_buffer + here;
end = CPP_PWRITTEN (pfile);
macro = alloca (end - buf + 1);
bcopy (buf, macro, end - buf + 1);
end = macro + (end - buf);
CPP_SET_WRITTEN (pfile, here);
#if 0 #if 0
/* If this is a precompiler run (with -pcp) pass thru #define commands. */ /* If this is a precompiler run (with -pcp) pass thru #define commands. */
if (pcp_outfile && keyword) if (pcp_outfile && keyword)
pass_thru_directive (buf, limit, pfile, keyword); pass_thru_directive (macro, end, pfile, keyword);
#endif #endif
mdef = create_definition (buf, limit, pfile, keyword == NULL); mdef = create_definition (macro, end, pfile, keyword == NULL);
if (mdef.defn == 0) if (mdef.defn == 0)
goto nope; goto nope;
...@@ -1580,7 +1581,7 @@ do_define (pfile, keyword, buf, limit) ...@@ -1580,7 +1581,7 @@ do_define (pfile, keyword, buf, limit)
/* If we are passing through #define and #undef directives, do /* If we are passing through #define and #undef directives, do
that for this re-definition now. */ that for this re-definition now. */
if (CPP_OPTIONS (pfile)->debug_output && keyword) if (CPP_OPTIONS (pfile)->debug_output && keyword)
pass_thru_directive (buf, limit, pfile, keyword); pass_thru_directive (macro, end, pfile, keyword);
msg = (U_CHAR *) alloca (mdef.symlen + 22); msg = (U_CHAR *) alloca (mdef.symlen + 22);
*msg = '`'; *msg = '`';
...@@ -1600,7 +1601,7 @@ do_define (pfile, keyword, buf, limit) ...@@ -1600,7 +1601,7 @@ do_define (pfile, keyword, buf, limit)
/* If we are passing through #define and #undef directives, do /* If we are passing through #define and #undef directives, do
that for this new definition now. */ that for this new definition now. */
if (CPP_OPTIONS (pfile)->debug_output && keyword) if (CPP_OPTIONS (pfile)->debug_output && keyword)
pass_thru_directive (buf, limit, pfile, keyword); pass_thru_directive (macro, end, pfile, keyword);
install (mdef.symnam, mdef.symlen, T_MACRO, 0, install (mdef.symnam, mdef.symlen, T_MACRO, 0,
(char *) mdef.defn, hashcode); (char *) mdef.defn, hashcode);
} }
...@@ -2871,10 +2872,9 @@ get_directive_token (pfile) ...@@ -2871,10 +2872,9 @@ get_directive_token (pfile)
This is safe. */ This is safe. */
static int static int
do_include (pfile, keyword, unused1, unused2) do_include (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword; struct directive *keyword;
U_CHAR *unused1 ATTRIBUTE_UNUSED, *unused2 ATTRIBUTE_UNUSED;
{ {
int importing = (keyword->type == T_IMPORT); int importing = (keyword->type == T_IMPORT);
int skip_dirs = (keyword->type == T_INCLUDE_NEXT); int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
...@@ -3147,10 +3147,9 @@ convert_string (pfile, result, in, limit, handle_escapes) ...@@ -3147,10 +3147,9 @@ convert_string (pfile, result, in, limit, handle_escapes)
#define FNAME_HASHSIZE 37 #define FNAME_HASHSIZE 37
static int static int
do_line (pfile, keyword, unused1, unused2) do_line (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *unused1 ATTRIBUTE_UNUSED, *unused2 ATTRIBUTE_UNUSED;
{ {
cpp_buffer *ip = CPP_BUFFER (pfile); cpp_buffer *ip = CPP_BUFFER (pfile);
int new_lineno; int new_lineno;
...@@ -3278,14 +3277,43 @@ do_line (pfile, keyword, unused1, unused2) ...@@ -3278,14 +3277,43 @@ do_line (pfile, keyword, unused1, unused2)
*/ */
static int static int
do_undef (pfile, keyword, buf, limit) do_undef (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword; struct directive *keyword;
U_CHAR *buf, *limit;
{ {
int sym_length; int sym_length;
HASHNODE *hp; HASHNODE *hp;
U_CHAR *orig_buf = buf; U_CHAR *buf, *name, *limit;
int c;
long here = CPP_WRITTEN (pfile);
enum cpp_token token;
cpp_skip_hspace (pfile);
c = GETC();
if (! is_idstart[c])
{
cpp_error (pfile, "token after #undef is not an identifier");
skip_rest_of_line (pfile);
return 1;
}
parse_name (pfile, c);
buf = pfile->token_buffer + here;
limit = CPP_PWRITTEN(pfile);
/* Copy out the token so we can pop the token buffer. */
name = alloca (limit - buf + 1);
bcopy(buf, name, limit - buf);
name[limit - buf] = '\0';
token = get_directive_token (pfile);
if (token != CPP_VSPACE)
{
cpp_pedwarn (pfile, "junk on line after #undef");
skip_rest_of_line (pfile);
}
CPP_SET_WRITTEN (pfile, here);
#if 0 #if 0
/* If this is a precompiler run (with -pcp) pass thru #undef commands. */ /* If this is a precompiler run (with -pcp) pass thru #undef commands. */
...@@ -3293,28 +3321,35 @@ do_undef (pfile, keyword, buf, limit) ...@@ -3293,28 +3321,35 @@ do_undef (pfile, keyword, buf, limit)
pass_thru_directive (buf, limit, pfile, keyword); pass_thru_directive (buf, limit, pfile, keyword);
#endif #endif
SKIP_WHITE_SPACE (buf); sym_length = check_macro_name (pfile, name, "macro");
sym_length = check_macro_name (pfile, buf, "macro");
while ((hp = cpp_lookup (pfile, buf, sym_length, -1)) != NULL) while ((hp = cpp_lookup (pfile, name, sym_length, -1)) != NULL)
{ {
/* If we are generating additional info for debugging (with -g) we /* If we are generating additional info for debugging (with -g) we
need to pass through all effective #undef commands. */ need to pass through all effective #undef commands. */
if (CPP_OPTIONS (pfile)->debug_output && keyword) if (CPP_OPTIONS (pfile)->debug_output && keyword)
pass_thru_directive (orig_buf, limit, pfile, keyword); pass_thru_directive (name, name+sym_length, pfile, keyword);
if (hp->type != T_MACRO) if (hp->type != T_MACRO)
cpp_warning (pfile, "undefining `%s'", hp->name); cpp_warning (pfile, "undefining `%s'", hp->name);
delete_macro (hp); delete_macro (hp);
} }
if (CPP_PEDANTIC (pfile)) {
buf += sym_length;
SKIP_WHITE_SPACE (buf);
if (buf != limit)
cpp_pedwarn (pfile, "garbage after `#undef' directive");
}
return 0; return 0;
} }
/* Wrap do_undef for -U processing. */
static void
cpp_undef (pfile, macro)
cpp_reader *pfile;
U_CHAR *macro;
{
if (cpp_push_buffer (pfile, macro, strlen(macro)))
{
do_undef (pfile, NULL);
cpp_pop_buffer (pfile);
}
}
/* /*
* Report an error detected by the program we are processing. * Report an error detected by the program we are processing.
...@@ -3323,77 +3358,78 @@ do_undef (pfile, keyword, buf, limit) ...@@ -3323,77 +3358,78 @@ do_undef (pfile, keyword, buf, limit)
*/ */
static int static int
do_error (pfile, keyword, buf, limit) do_error (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *buf, *limit;
{ {
int length = limit - buf; long here = CPP_WRITTEN (pfile);
U_CHAR *copy = (U_CHAR *) alloca (length + 1); U_CHAR *text;
bcopy (buf, copy, length); copy_rest_of_line (pfile);
copy[length] = 0; text = pfile->token_buffer + here;
SKIP_WHITE_SPACE (copy); SKIP_WHITE_SPACE(text);
cpp_error (pfile, "#error %s", copy);
cpp_error (pfile, "#error %s", text);
CPP_SET_WRITTEN (pfile, here);
return 0; return 0;
} }
/* /*
* Report a warning detected by the program we are processing. * Report a warning detected by the program we are processing.
* Use the text of the line in the warning message, then continue. * Use the text of the line in the warning message, then continue.
* (We use error because it prints the filename & line#.)
*/ */
static int static int
do_warning (pfile, keyword, buf, limit) do_warning (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *buf, *limit;
{ {
int length = limit - buf; U_CHAR *text;
U_CHAR *copy = (U_CHAR *) alloca (length + 1); long here = CPP_WRITTEN(pfile);
bcopy (buf, copy, length); copy_rest_of_line (pfile);
copy[length] = 0; text = pfile->token_buffer + here;
SKIP_WHITE_SPACE (copy); SKIP_WHITE_SPACE(text);
if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p) if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
cpp_pedwarn (pfile, "ANSI C does not allow `#warning'"); cpp_pedwarn (pfile, "ANSI C does not allow `#warning'");
/* Use `pedwarn' not `warning', because #warning isn't in the C Standard; /* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
if -pedantic-errors is given, #warning should cause an error. */ if -pedantic-errors is given, #warning should cause an error. */
cpp_pedwarn (pfile, "#warning %s", copy); cpp_pedwarn (pfile, "#warning %s", text);
CPP_SET_WRITTEN (pfile, here);
return 0; return 0;
} }
/* Report program identification. */ /* Report program identification. */
static int static int
do_ident (pfile, keyword, buf, limit) do_ident (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
{ {
/* long old_written = CPP_WRITTEN (pfile);*/
/* Allow #ident in system headers, since that's not user's fault. */ /* Allow #ident in system headers, since that's not user's fault. */
if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p) if (CPP_PEDANTIC (pfile) && !CPP_BUFFER (pfile)->system_header_p)
cpp_pedwarn (pfile, "ANSI C does not allow `#ident'"); cpp_pedwarn (pfile, "ANSI C does not allow `#ident'");
/* Leave rest of line to be read by later calls to cpp_get_token. */ skip_rest_of_line (pfile); /* Correct? Appears to match cccp. */
return 0; return 0;
} }
/* #pragma and its argument line have already been copied to the output file. /* Just check for some recognized pragmas that need validation here,
Just check for some recognized pragmas that need validation here. */ and leave the text in the token buffer to be output. */
static int static int
do_pragma (pfile, keyword, buf, limit) do_pragma (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *buf, *limit ATTRIBUTE_UNUSED;
{ {
while (*buf == ' ' || *buf == '\t') long here = CPP_WRITTEN (pfile);
buf++; U_CHAR *buf;
copy_rest_of_line (pfile);
buf = pfile->token_buffer + here;
SKIP_WHITE_SPACE (buf);
if (!strncmp (buf, "once", 4)) if (!strncmp (buf, "once", 4))
{ {
cpp_buffer *ip = NULL; cpp_buffer *ip = NULL;
...@@ -3444,44 +3480,17 @@ do_pragma (pfile, keyword, buf, limit) ...@@ -3444,44 +3480,17 @@ do_pragma (pfile, keyword, buf, limit)
return 0; return 0;
} }
#if 0
/* This was a fun hack, but #pragma seems to start to be useful.
By failing to recognize it, we pass it through unchanged to cc1. */
/*
* the behavior of the #pragma directive is implementation defined.
* this implementation defines it as follows.
*/
static int
do_pragma ()
{
close (0);
if (open ("/dev/tty", O_RDONLY, 0666) != 0)
goto nope;
close (1);
if (open ("/dev/tty", O_WRONLY, 0666) != 1)
goto nope;
execl ("/usr/games/hack", "#pragma", 0);
execl ("/usr/games/rogue", "#pragma", 0);
execl ("/usr/new/emacs", "-f", "hanoi", "9", "-kill", 0);
execl ("/usr/local/emacs", "-f", "hanoi", "9", "-kill", 0);
nope:
fatal ("You are in a maze of twisty compiler features, all different");
}
#endif
#ifdef SCCS_DIRECTIVE #ifdef SCCS_DIRECTIVE
/* Just ignore #sccs, on systems where we define it at all. */ /* Just ignore #sccs, on systems where we define it at all. */
static int static int
do_sccs (pfile, keyword, buf, limit) do_sccs (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
{ {
if (CPP_PEDANTIC (pfile)) if (CPP_PEDANTIC (pfile))
cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'"); cpp_pedwarn (pfile, "ANSI C does not allow `#sccs'");
skip_rest_of_line (pfile);
return 0; return 0;
} }
#endif #endif
...@@ -3500,12 +3509,11 @@ do_sccs (pfile, keyword, buf, limit) ...@@ -3500,12 +3509,11 @@ do_sccs (pfile, keyword, buf, limit)
*/ */
static int static int
do_if (pfile, keyword, buf, limit) do_if (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *buf, *limit;
{ {
HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf); HOST_WIDE_INT value = eval_if_expression (pfile);
conditional_skip (pfile, value == 0, T_IF, NULL_PTR); conditional_skip (pfile, value == 0, T_IF, NULL_PTR);
return 0; return 0;
} }
...@@ -3516,10 +3524,9 @@ do_if (pfile, keyword, buf, limit) ...@@ -3516,10 +3524,9 @@ do_if (pfile, keyword, buf, limit)
*/ */
static int static int
do_elif (pfile, keyword, buf, limit) do_elif (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *buf, *limit;
{ {
if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) { if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack) {
cpp_error (pfile, "`#elif' not within a conditional"); cpp_error (pfile, "`#elif' not within a conditional");
...@@ -3542,7 +3549,7 @@ do_elif (pfile, keyword, buf, limit) ...@@ -3542,7 +3549,7 @@ do_elif (pfile, keyword, buf, limit)
if (pfile->if_stack->if_succeeded) if (pfile->if_stack->if_succeeded)
skip_if_group (pfile, 0); skip_if_group (pfile, 0);
else { else {
HOST_WIDE_INT value = eval_if_expression (pfile, buf, limit - buf); HOST_WIDE_INT value = eval_if_expression (pfile);
if (value == 0) if (value == 0)
skip_if_group (pfile, 0); skip_if_group (pfile, 0);
else { else {
...@@ -3559,10 +3566,8 @@ do_elif (pfile, keyword, buf, limit) ...@@ -3559,10 +3566,8 @@ do_elif (pfile, keyword, buf, limit)
*/ */
static HOST_WIDE_INT static HOST_WIDE_INT
eval_if_expression (pfile, buf, length) eval_if_expression (pfile)
cpp_reader *pfile; cpp_reader *pfile;
U_CHAR *buf ATTRIBUTE_UNUSED;
int length ATTRIBUTE_UNUSED;
{ {
HASHNODE *save_defined; HASHNODE *save_defined;
HOST_WIDE_INT value; HOST_WIDE_INT value;
...@@ -3587,10 +3592,9 @@ eval_if_expression (pfile, buf, length) ...@@ -3587,10 +3592,9 @@ eval_if_expression (pfile, buf, length)
*/ */
static int static int
do_xifdef (pfile, keyword, unused1, unused2) do_xifdef (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword; struct directive *keyword;
U_CHAR *unused1 ATTRIBUTE_UNUSED, *unused2 ATTRIBUTE_UNUSED;
{ {
int skip; int skip;
cpp_buffer *ip = CPP_BUFFER (pfile); cpp_buffer *ip = CPP_BUFFER (pfile);
...@@ -3868,10 +3872,9 @@ skip_if_group (pfile, any) ...@@ -3868,10 +3872,9 @@ skip_if_group (pfile, any)
*/ */
static int static int
do_else (pfile, keyword, buf, limit) do_else (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
{ {
cpp_buffer *ip = CPP_BUFFER (pfile); cpp_buffer *ip = CPP_BUFFER (pfile);
...@@ -3911,10 +3914,9 @@ do_else (pfile, keyword, buf, limit) ...@@ -3911,10 +3914,9 @@ do_else (pfile, keyword, buf, limit)
*/ */
static int static int
do_endif (pfile, keyword, buf, limit) do_endif (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
{ {
if (CPP_PEDANTIC (pfile)) if (CPP_PEDANTIC (pfile))
validate_else (pfile, "#endif"); validate_else (pfile, "#endif");
...@@ -4830,7 +4832,7 @@ cpp_start_read (pfile, fname) ...@@ -4830,7 +4832,7 @@ cpp_start_read (pfile, fname)
case 'U': case 'U':
if (opts->debug_output) if (opts->debug_output)
output_line_command (pfile, 0, same_file); output_line_command (pfile, 0, same_file);
do_undef (pfile, NULL, pend->arg, pend->arg + strlen (pend->arg)); cpp_undef (pfile, pend->arg);
break; break;
case 'D': case 'D':
if (opts->debug_output) if (opts->debug_output)
...@@ -6006,10 +6008,9 @@ parse_assertion (pfile) ...@@ -6006,10 +6008,9 @@ parse_assertion (pfile)
} }
static int static int
do_assert (pfile, keyword, buf, limit) do_assert (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
{ {
char *sym; char *sym;
int ret, c; int ret, c;
...@@ -6073,10 +6074,9 @@ do_assert (pfile, keyword, buf, limit) ...@@ -6073,10 +6074,9 @@ do_assert (pfile, keyword, buf, limit)
} }
static int static int
do_unassert (pfile, keyword, buf, limit) do_unassert (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
struct directive *keyword ATTRIBUTE_UNUSED; struct directive *keyword ATTRIBUTE_UNUSED;
U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
{ {
int c, ret; int c, ret;
char *sym; char *sym;
...@@ -6569,9 +6569,6 @@ cpp_perror_with_name (pfile, name) ...@@ -6569,9 +6569,6 @@ cpp_perror_with_name (pfile, name)
* *
* Possibly different enum token codes for each C/C++ token. * Possibly different enum token codes for each C/C++ token.
* *
* Should clean up remaining directives to that do_XXX functions
* only take two arguments and all have command_reads_line.
*
* Find and cleanup remaining uses of static variables, * Find and cleanup remaining uses of static variables,
* *
* Support for trigraphs. * Support for trigraphs.
......
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