This patch is mostly cleanups, sorry for the churn. The next one will be far more interesting.
The next patch in this series will use a function gfc_warning_now_2 that works exactly like gfc_warning_now but uses the common diagnostics machinery. My original idea was that this new function will take an explicit location like the ones in the C FE. However, I realised that this will be too disruptive. At the end, the new gfc_warning_now_2 is actually a duplicate of gfc_warning_cmdline. Thus, this patch renames gfc_warning_cmdline as gfc_warning_now_2 (and the same for the _error_ variants). In addition, I add more uses of the "new" function in several new places (places where the name gfc_warning_cmdline does not really make sense). This patch also cleans up the trailing space when building the locus and adds the space only when needed (to separate locus and prefix). Boot®tested on x86_64-linux-gnu. OK? gcc/fortran/ChangeLog: 2014-10-16 Manuel López-Ibáñez <m...@gcc.gnu.org> PR fortran/44054 * gfortran.h (gfc_warning_cmdline): Rename as gfc_warning_now_2. (gfc_error_cmdline): Rename as gfc_error_now_2. * error.c (gfc_diagnostic_build_locus_prefix): Remove trailing space. (gfc_diagnostic_starter): Add space between locus and prefix. (gfc_warning_now_2): Renamed from gfc_warning_cmdline. (gfc_error_now_2): Renamed from gfc_error_cmdline. * scanner.c (add_path_to_list): Use gfc_warning_now_2. (load_line): Likewise. (load_file): Likewise. * options.c (gfc_post_options): Update all renamed functions.
Index: gcc/fortran/gfortran.h =================================================================== --- gcc/fortran/gfortran.h (revision 216234) +++ gcc/fortran/gfortran.h (working copy) @@ -2696,19 +2696,19 @@ void gfc_buffer_error (int); const char *gfc_print_wide_char (gfc_char_t); void gfc_warning (const char *, ...) ATTRIBUTE_GCC_GFC(1,2); void gfc_warning_now (const char *, ...) ATTRIBUTE_GCC_GFC(1,2); -bool gfc_warning_cmdline (const char *gmsgid, ...) ATTRIBUTE_GCC_GFC(1,2); -bool gfc_warning_cmdline (int opt, const char *gmsgid, ...) ATTRIBUTE_GCC_GFC(2,3); +bool gfc_warning_now_2 (const char *gmsgid, ...) ATTRIBUTE_GCC_GFC(1,2); +bool gfc_warning_now_2 (int opt, const char *gmsgid, ...) ATTRIBUTE_GCC_GFC(2,3); void gfc_clear_warning (void); void gfc_warning_check (void); void gfc_error (const char *, ...) ATTRIBUTE_GCC_GFC(1,2); -void gfc_error_cmdline (const char *gmsgid, ...) ATTRIBUTE_GCC_GFC(1,2); void gfc_error_now (const char *, ...) ATTRIBUTE_GCC_GFC(1,2); +void gfc_error_now_2 (const char *gmsgid, ...) ATTRIBUTE_GCC_GFC(1,2); void gfc_fatal_error (const char *, ...) ATTRIBUTE_NORETURN ATTRIBUTE_GCC_GFC(1,2); void gfc_internal_error (const char *, ...) ATTRIBUTE_NORETURN ATTRIBUTE_GCC_GFC(1,2); void gfc_clear_error (void); int gfc_error_check (void); int gfc_error_flag_test (void); Index: gcc/fortran/error.c =================================================================== --- gcc/fortran/error.c (revision 216234) +++ gcc/fortran/error.c (working copy) @@ -1002,17 +1002,17 @@ gfc_diagnostic_build_locus_prefix (diagn expanded_location s = expand_location_to_spelling_point (diagnostic->location); if (diagnostic->override_column) s.column = diagnostic->override_column; return (s.file == NULL - ? build_message_string ("%s%s:%s ", locus_cs, progname, locus_ce ) + ? build_message_string ("%s%s:%s", locus_cs, progname, locus_ce ) : !strcmp (s.file, N_("<built-in>")) - ? build_message_string ("%s%s:%s ", locus_cs, s.file, locus_ce) + ? build_message_string ("%s%s:%s", locus_cs, s.file, locus_ce) : context->show_column - ? build_message_string ("%s%s:%d:%d:%s ", locus_cs, s.file, s.line, + ? build_message_string ("%s%s:%d:%d:%s", locus_cs, s.file, s.line, s.column, locus_ce) - : build_message_string ("%s%s:%d:%s ", locus_cs, s.file, s.line, locus_ce)); + : build_message_string ("%s%s:%d:%s", locus_cs, s.file, s.line, locus_ce)); } static void gfc_diagnostic_starter (diagnostic_context *context, diagnostic_info *diagnostic) @@ -1036,11 +1036,11 @@ gfc_diagnostic_starter (diagnostic_conte } else { /* Otherwise, start again. */ pp_clear_output_area(context->printer); - pp_set_prefix (context->printer, concat (locus_prefix, prefix, NULL)); + pp_set_prefix (context->printer, concat (locus_prefix, " ", prefix, NULL)); free (prefix); } free (locus_prefix); } @@ -1050,14 +1050,14 @@ gfc_diagnostic_finalizer (diagnostic_con { pp_destroy_prefix (context->printer); pp_newline_and_flush (context->printer); } -/* Give a warning about the command-line. */ +/* Immediate warning (i.e. do not buffer the warning). */ bool -gfc_warning_cmdline (int opt, const char *gmsgid, ...) +gfc_warning_now_2 (int opt, const char *gmsgid, ...) { va_list argp; diagnostic_info diagnostic; bool ret; @@ -1068,15 +1068,14 @@ gfc_warning_cmdline (int opt, const char ret = report_diagnostic (&diagnostic); va_end (argp); return ret; } - -/* Give a warning about the command-line. */ +/* Immediate warning (i.e. do not buffer the warning). */ bool -gfc_warning_cmdline (const char *gmsgid, ...) +gfc_warning_now_2 (const char *gmsgid, ...) { va_list argp; diagnostic_info diagnostic; bool ret; @@ -1087,14 +1086,14 @@ gfc_warning_cmdline (const char *gmsgid, va_end (argp); return ret; } -/* Give an error about the command-line. */ +/* Immediate error (i.e. do not buffer). */ void -gfc_error_cmdline (const char *gmsgid, ...) +gfc_error_now_2 (const char *gmsgid, ...) { va_list argp; diagnostic_info diagnostic; va_start (argp, gmsgid); Index: gcc/fortran/scanner.c =================================================================== --- gcc/fortran/scanner.c (revision 216234) +++ gcc/fortran/scanner.c (working copy) @@ -322,20 +322,20 @@ add_path_to_list (gfc_directorylist **li q[i--] = '\0'; if (stat (q, &st)) { if (errno != ENOENT) - gfc_warning_cmdline ("Include directory %qs: %s", path, - xstrerror(errno)); + gfc_warning_now_2 ("Include directory %qs: %s", path, + xstrerror(errno)); else if (warn) - gfc_warning_cmdline (OPT_Wmissing_include_dirs, - "Nonexistent include directory %qs", path); + gfc_warning_now_2 (OPT_Wmissing_include_dirs, + "Nonexistent include directory %qs", path); return; } else if (!S_ISDIR (st.st_mode)) { - gfc_warning_cmdline ("%qs is not a directory", path); + gfc_warning_now_2 ("%qs is not a directory", path); return; } if (head || *list == NULL) { @@ -1474,15 +1474,15 @@ load_line (FILE *input, gfc_char_t **pbu /* Check for illegal use of ampersand. See F95 Standard 3.3.1.3. */ if (gfc_current_form == FORM_FREE && !seen_printable && seen_ampersand) { if (pedantic) - gfc_error_now ("'&' not allowed by itself in line %d", - current_line); + gfc_error_now_2 ("%<&%> not allowed by itself in line %d", + current_line); else - gfc_warning_now ("'&' not allowed by itself in line %d", - current_line); + gfc_warning_now_2 ("%<&%> not allowed by itself in line %d", + current_line); } break; } if (c == '\r' || c == '\0') @@ -1536,12 +1536,12 @@ load_line (FILE *input, gfc_char_t **pbu if (!gfc_option.warn_tabs && seen_comment == 0 && current_line != linenum) { linenum = current_line; - gfc_warning_now ("Nonconforming tab character in column %d " - "of line %d", i+1, linenum); + gfc_warning_now_2 ("Nonconforming tab character in column %d " + "of line %d", i+1, linenum); } while (i < 6) { *buffer++ = ' '; @@ -1920,11 +1920,11 @@ load_file (const char *realfilename, con } else input = gfc_open_file (realfilename); if (input == NULL) { - gfc_error_cmdline ("Can't open file %qs", filename); + gfc_error_now_2 ("Can't open file %qs", filename); return false; } } else { Index: gcc/fortran/options.c =================================================================== --- gcc/fortran/options.c (revision 216234) +++ gcc/fortran/options.c (working copy) @@ -360,24 +360,24 @@ gfc_post_options (const char **pfilename gfc_current_form = form_from_filename (filename); if (gfc_current_form == FORM_UNKNOWN) { gfc_current_form = FORM_FREE; - gfc_warning_cmdline ("Reading file %qs as free form", - (filename[0] == '\0') ? "<stdin>" : filename); + gfc_warning_now_2 ("Reading file %qs as free form", + (filename[0] == '\0') ? "<stdin>" : filename); } } /* If the user specified -fd-lines-as-{code|comments} verify that we're in fixed form. */ if (gfc_current_form == FORM_FREE) { if (gfc_option.flag_d_lines == 0) - gfc_warning_cmdline ("%<-fd-lines-as-comments%> has no effect " - "in free form"); + gfc_warning_now_2 ("%<-fd-lines-as-comments%> has no effect " + "in free form"); else if (gfc_option.flag_d_lines == 1) - gfc_warning_cmdline ("%<-fd-lines-as-code%> has no effect in free form"); + gfc_warning_now_2 ("%<-fd-lines-as-code%> has no effect in free form"); } /* If -pedantic, warn about the use of GNU extensions. */ if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0) gfc_option.warn_std |= GFC_STD_GNU; @@ -391,25 +391,25 @@ gfc_post_options (const char **pfilename if (gfc_option.flag_second_underscore == -1) gfc_option.flag_second_underscore = gfc_option.flag_f2c; if (!gfc_option.flag_automatic && gfc_option.flag_max_stack_var_size != -2 && gfc_option.flag_max_stack_var_size != 0) - gfc_warning_cmdline ("Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>", - gfc_option.flag_max_stack_var_size); + gfc_warning_now_2 ("Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>", + gfc_option.flag_max_stack_var_size); else if (!gfc_option.flag_automatic && gfc_option.flag_recursive) - gfc_warning_cmdline ("Flag %<-fno-automatic%> overwrites %<-frecursive%>"); + gfc_warning_now_2 ("Flag %<-fno-automatic%> overwrites %<-frecursive%>"); else if (!gfc_option.flag_automatic && gfc_option.gfc_flag_openmp) - gfc_warning_cmdline ("Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by " - "%<-fopenmp%>"); + gfc_warning_now_2 ("Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by " + "%<-fopenmp%>"); else if (gfc_option.flag_max_stack_var_size != -2 && gfc_option.flag_recursive) - gfc_warning_cmdline ("Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>", - gfc_option.flag_max_stack_var_size); + gfc_warning_now_2 ("Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>", + gfc_option.flag_max_stack_var_size); else if (gfc_option.flag_max_stack_var_size != -2 && gfc_option.gfc_flag_openmp) - gfc_warning_cmdline ("Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> " - "implied by %<-fopenmp%>", + gfc_warning_now_2 ("Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> " + "implied by %<-fopenmp%>", gfc_option.flag_max_stack_var_size); /* Implement -frecursive as -fmax-stack-var-size=-1. */ if (gfc_option.flag_recursive) gfc_option.flag_max_stack_var_size = -1;