From 6cae25044a92709544cf8f84d01bfce8c39799ad Mon Sep 17 00:00:00 2001 From: zack Date: Wed, 2 Aug 2000 01:13:45 +0000 Subject: * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@35415 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cpperror.c | 169 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 89 insertions(+), 80 deletions(-) (limited to 'gcc/cpperror.c') diff --git a/gcc/cpperror.c b/gcc/cpperror.c index a2769b6dbda..66921668b88 100644 --- a/gcc/cpperror.c +++ b/gcc/cpperror.c @@ -32,10 +32,9 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void print_containing_files PARAMS ((cpp_reader *, cpp_buffer *)); static void print_file_and_line PARAMS ((const char *, unsigned int, unsigned int)); -static void v_message PARAMS ((cpp_reader *, int, - const char *, - unsigned int, unsigned int, - const char *, va_list)); + +#define v_message(msgid, ap) \ +do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0) /* Print the file names and line numbers of the #include commands which led to the current file. */ @@ -92,70 +91,101 @@ print_file_and_line (filename, line, column) const char *filename; unsigned int line, column; { - if (filename == 0 || *filename == '\0') - filename = ""; if (line == 0) fputs (_(": "), stderr); - else if (column > 0) - fprintf (stderr, "%s:%u:%u: ", filename, line, column); else - fprintf (stderr, "%s:%u: ", filename, line); + { + if (filename == 0 || *filename == '\0') + filename = ""; + if (column > 0) + fprintf (stderr, "%s:%u:%u: ", filename, line, column); + else + fprintf (stderr, "%s:%u: ", filename, line); + } } -/* IS_ERROR is 3 for ICE, 2 for merely "fatal" error, - 1 for error, 0 for warning. */ +/* Set up for an error message: print the file and line, bump the error + counter, etc. + If it returns 0, this error has been suppressed. */ -static void -v_message (pfile, is_error, file, line, col, msg, ap) +int +_cpp_begin_message (pfile, code, file, line, col) cpp_reader *pfile; - int is_error; + enum error_type code; const char *file; unsigned int line; unsigned int col; - const char *msg; - va_list ap; { cpp_buffer *ip = CPP_BUFFER (pfile); + int is_warning = 0; - if (ip) + switch (code) { - if (file == NULL) - file = ip->nominal_fname; - if (line == 0) - line = _cpp_get_line (pfile, &col); - print_containing_files (pfile, ip); - print_file_and_line (file, line, - CPP_OPTION (pfile, show_column) ? col : 0); - } - else - fprintf (stderr, "%s: ", progname); - - switch (is_error) - { - case 0: + case WARNING: if (! CPP_OPTION (pfile, warnings_are_errors)) { - fprintf (stderr, _("warning: ")); - break; + if (CPP_OPTION (pfile, inhibit_warnings)) + return 0; + is_warning = 1; + } + else + { + if (CPP_OPTION (pfile, inhibit_errors)) + return 0; + if (pfile->errors < CPP_FATAL_LIMIT) + pfile->errors++; + } + break; + + case PEDWARN: + if (! CPP_OPTION (pfile, pedantic_errors)) + { + if (CPP_OPTION (pfile, inhibit_warnings)) + return 0; + is_warning = 1; } - /* else fall through */ - case 1: + else + { + if (CPP_OPTION (pfile, inhibit_errors)) + return 0; + if (pfile->errors < CPP_FATAL_LIMIT) + pfile->errors++; + } + break; + + case ERROR: + if (CPP_OPTION (pfile, inhibit_errors)) + return 0; if (pfile->errors < CPP_FATAL_LIMIT) pfile->errors++; break; - case 2: + /* Fatal errors cannot be inhibited. */ + case FATAL: pfile->errors = CPP_FATAL_LIMIT; break; - case 3: + case ICE: fprintf (stderr, _("internal error: ")); pfile->errors = CPP_FATAL_LIMIT; break; - default: - cpp_ice (pfile, "bad is_error(%d) in v_message", is_error); } - vfprintf (stderr, _(msg), ap); - putc ('\n', stderr); + if (ip) + { + if (file == NULL) + file = ip->nominal_fname; + if (line == 0) + line = _cpp_get_line (pfile, &col); + print_containing_files (pfile, ip); + print_file_and_line (file, line, + CPP_OPTION (pfile, show_column) ? col : 0); + } + else + fprintf (stderr, "%s: ", progname); + + if (is_warning) + fputs (_("warning: "), stderr); + + return 1; } /* Exported interface. */ @@ -179,7 +209,8 @@ cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...)) msgid = va_arg (ap, const char *); #endif - v_message (pfile, 3, NULL, 0, 0, msgid, ap); + if (_cpp_begin_message (pfile, ICE, NULL, 0, 0)) + v_message (msgid, ap); va_end(ap); } @@ -205,7 +236,8 @@ cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...)) msgid = va_arg (ap, const char *); #endif - v_message (pfile, 2, NULL, 0, 0, msgid, ap); + if (_cpp_begin_message (pfile, FATAL, NULL, 0, 0)) + v_message (msgid, ap); va_end(ap); } @@ -225,10 +257,8 @@ cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...)) msgid = va_arg (ap, const char *); #endif - if (CPP_OPTION (pfile, inhibit_errors)) - return; - - v_message (pfile, 1, NULL, 0, 0, msgid, ap); + if (_cpp_begin_message (pfile, ERROR, NULL, 0, 0)) + v_message (msgid, ap); va_end(ap); } @@ -253,10 +283,8 @@ cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column, msgid = va_arg (ap, const char *); #endif - if (CPP_OPTION (pfile, inhibit_errors)) - return; - - v_message (pfile, 1, NULL, line, column, msgid, ap); + if (_cpp_begin_message (pfile, ERROR, NULL, line, column)) + v_message (msgid, ap); va_end(ap); } @@ -285,10 +313,8 @@ cpp_warning VPARAMS ((cpp_reader * pfile, const char *msgid, ...)) msgid = va_arg (ap, const char *); #endif - if (CPP_OPTION (pfile, inhibit_warnings)) - return; - - v_message (pfile, 0, NULL, 0, 0, msgid, ap); + if (_cpp_begin_message (pfile, WARNING, NULL, 0, 0)) + v_message (msgid, ap); va_end(ap); } @@ -313,10 +339,8 @@ cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column, msgid = va_arg (ap, const char *); #endif - if (CPP_OPTION (pfile, inhibit_warnings)) - return; - - v_message (pfile, 0, NULL, line, column, msgid, ap); + if (_cpp_begin_message (pfile, WARNING, NULL, line, column)) + v_message (msgid, ap); va_end(ap); } @@ -336,13 +360,8 @@ cpp_pedwarn VPARAMS ((cpp_reader * pfile, const char *msgid, ...)) msgid = va_arg (ap, const char *); #endif - if (CPP_OPTION (pfile, pedantic_errors) - ? CPP_OPTION (pfile, inhibit_errors) - : CPP_OPTION (pfile, inhibit_warnings)) - return; - - v_message (pfile, CPP_OPTION (pfile, pedantic_errors), - NULL, 0, 0, msgid, ap); + if (_cpp_begin_message (pfile, PEDWARN, NULL, 0, 0)) + v_message (msgid, ap); va_end(ap); } @@ -367,13 +386,8 @@ cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column, msgid = va_arg (ap, const char *); #endif - if (CPP_OPTION (pfile, pedantic_errors) - ? CPP_OPTION (pfile, inhibit_errors) - : CPP_OPTION (pfile, inhibit_warnings)) - return; - - v_message (pfile, CPP_OPTION (pfile, pedantic_errors), - NULL, line, column, msgid, ap); + if (_cpp_begin_message (pfile, PEDWARN, NULL, line, column)) + v_message (msgid, ap); va_end(ap); } @@ -404,13 +418,8 @@ cpp_pedwarn_with_file_and_line VPARAMS ((cpp_reader *pfile, msgid = va_arg (ap, const char *); #endif - if (CPP_OPTION (pfile, pedantic_errors) - ? CPP_OPTION (pfile, inhibit_errors) - : CPP_OPTION (pfile, inhibit_warnings)) - return; - - v_message (pfile, CPP_OPTION (pfile, pedantic_errors), - file, line, col, msgid, ap); + if (_cpp_begin_message (pfile, PEDWARN, file, line, col)) + v_message (msgid, ap); va_end(ap); } -- cgit v1.2.1