LCOV - code coverage report
Current view: top level - gcc/fortran - cpp.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 51.1 % 560 286
Test Date: 2024-04-20 14:03:02 Functions: 56.8 % 37 21
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Copyright (C) 2008-2024 Free Software Foundation, Inc.
       2                 :             : 
       3                 :             : This file is part of GCC.
       4                 :             : 
       5                 :             : GCC is free software; you can redistribute it and/or modify it under
       6                 :             : the terms of the GNU General Public License as published by the Free
       7                 :             : Software Foundation; either version 3, or (at your option) any later
       8                 :             : version.
       9                 :             : 
      10                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13                 :             : for more details.
      14                 :             : 
      15                 :             : You should have received a copy of the GNU General Public License
      16                 :             : along with GCC; see the file COPYING3.  If not see
      17                 :             : <http://www.gnu.org/licenses/>.  */
      18                 :             : 
      19                 :             : #include "config.h"
      20                 :             : #include "system.h"
      21                 :             : #include "coretypes.h"
      22                 :             : 
      23                 :             : #define GCC_C_COMMON_C
      24                 :             : #include "options.h"  /* For cpp_reason_option_codes. */
      25                 :             : #undef GCC_C_COMMON_C
      26                 :             : 
      27                 :             : #include "target.h"
      28                 :             : #include "gfortran.h"
      29                 :             : #include "diagnostic.h"
      30                 :             : 
      31                 :             : #include "toplev.h"
      32                 :             : 
      33                 :             : #include "../../libcpp/internal.h"
      34                 :             : #include "cpp.h"
      35                 :             : #include "incpath.h"
      36                 :             : #include "cppbuiltin.h"
      37                 :             : #include "mkdeps.h"
      38                 :             : 
      39                 :             : #ifndef TARGET_SYSTEM_ROOT
      40                 :             : # define TARGET_SYSTEM_ROOT NULL
      41                 :             : #endif
      42                 :             : 
      43                 :             : #ifndef TARGET_CPU_CPP_BUILTINS
      44                 :             : # define TARGET_CPU_CPP_BUILTINS()
      45                 :             : #endif
      46                 :             : 
      47                 :             : #ifndef TARGET_OS_CPP_BUILTINS
      48                 :             : # define TARGET_OS_CPP_BUILTINS()
      49                 :             : #endif
      50                 :             : 
      51                 :             : #ifndef TARGET_OBJFMT_CPP_BUILTINS
      52                 :             : # define TARGET_OBJFMT_CPP_BUILTINS()
      53                 :             : #endif
      54                 :             : 
      55                 :             : 
      56                 :             : /* Holds switches parsed by gfc_cpp_handle_option (), but whose
      57                 :             :    handling is deferred to gfc_cpp_init ().  */
      58                 :             : typedef struct
      59                 :             : {
      60                 :             :     enum opt_code code;
      61                 :             :     const char *arg;
      62                 :             : }
      63                 :             : gfc_cpp_deferred_opt_t;
      64                 :             : 
      65                 :             : 
      66                 :             : /* Defined and undefined macros being queued for output with -dU at
      67                 :             :    the next newline.  */
      68                 :             : typedef struct gfc_cpp_macro_queue
      69                 :             : {
      70                 :             :   struct gfc_cpp_macro_queue *next;     /* Next macro in the list.  */
      71                 :             :   char *macro;                          /* The name of the macro if not
      72                 :             :                                            defined, the full definition if
      73                 :             :                                            defined.  */
      74                 :             : } gfc_cpp_macro_queue;
      75                 :             : static gfc_cpp_macro_queue *cpp_define_queue, *cpp_undefine_queue;
      76                 :             : 
      77                 :             : struct gfc_cpp_option_data
      78                 :             : {
      79                 :             :   /* Argument of -cpp, implied by SPEC;
      80                 :             :      if NULL, preprocessing disabled.  */
      81                 :             :   const char *temporary_filename;
      82                 :             : 
      83                 :             :   const char *output_filename;          /* -o <arg>  */
      84                 :             :   int preprocess_only;                  /* -E  */
      85                 :             :   int discard_comments;                 /* -C  */
      86                 :             :   int discard_comments_in_macro_exp;    /* -CC  */
      87                 :             :   int print_include_names;              /* -H  */
      88                 :             :   int no_line_commands;                 /* -P  */
      89                 :             :   char dump_macros;                     /* -d[DMNU]  */
      90                 :             :   int dump_includes;                    /* -dI  */
      91                 :             :   int working_directory;                /* -fworking-directory  */
      92                 :             :   int no_predefined;                    /* -undef */
      93                 :             :   int standard_include_paths;           /* -nostdinc */
      94                 :             :   int verbose;                          /* -v */
      95                 :             :   int deps;                             /* -M */
      96                 :             :   int deps_skip_system;                 /* -MM */
      97                 :             :   const char *deps_filename;            /* -M[M]D */
      98                 :             :   const char *deps_filename_user;       /* -MF <arg> */
      99                 :             :   int deps_missing_are_generated;       /* -MG */
     100                 :             :   int deps_phony;                       /* -MP */
     101                 :             :   int warn_date_time;                   /* -Wdate-time */
     102                 :             : 
     103                 :             :   const char *multilib;                 /* -imultilib <dir>  */
     104                 :             :   const char *prefix;                   /* -iprefix <dir>  */
     105                 :             :   const char *sysroot;                  /* -isysroot <dir>  */
     106                 :             : 
     107                 :             :   /* Options whose handling needs to be deferred until the
     108                 :             :      appropriate cpp-objects are created:
     109                 :             :       -A predicate=answer
     110                 :             :       -D <macro>[=<val>]
     111                 :             :       -U <macro>  */
     112                 :             :   gfc_cpp_deferred_opt_t *deferred_opt;
     113                 :             :   int deferred_opt_count;
     114                 :             : }
     115                 :             : gfc_cpp_option;
     116                 :             : 
     117                 :             : /* Structures used with libcpp:  */
     118                 :             : static cpp_options *cpp_option = NULL;
     119                 :             : static cpp_reader *cpp_in = NULL;
     120                 :             : 
     121                 :             : /* Encapsulates state used to convert a stream of cpp-tokens into
     122                 :             :    a text file.  */
     123                 :             : static struct
     124                 :             : {
     125                 :             :   FILE *outf;                   /* Stream to write to.  */
     126                 :             :   const cpp_token *prev;        /* Previous token.  */
     127                 :             :   const cpp_token *source;      /* Source token for spacing.  */
     128                 :             :   int src_line;                 /* Line number currently being written.  */
     129                 :             :   unsigned char printed;        /* Nonzero if something output at line.  */
     130                 :             :   bool first_time;              /* cb_file_change hasn't been called yet.  */
     131                 :             : } print;
     132                 :             : 
     133                 :             : /* General output routines.  */
     134                 :             : static void scan_translation_unit (cpp_reader *);
     135                 :             : static void scan_translation_unit_trad (cpp_reader *);
     136                 :             : 
     137                 :             : /* Callback routines for the parser. Most of these are active only
     138                 :             :    in specific modes.  */
     139                 :             : static void cb_file_change (cpp_reader *, const line_map_ordinary *);
     140                 :             : static void cb_line_change (cpp_reader *, const cpp_token *, int);
     141                 :             : static void cb_define (cpp_reader *, location_t, cpp_hashnode *);
     142                 :             : static void cb_undef (cpp_reader *, location_t, cpp_hashnode *);
     143                 :             : static void cb_def_pragma (cpp_reader *, location_t);
     144                 :             : static void cb_include (cpp_reader *, location_t, const unsigned char *,
     145                 :             :                         const char *, int, const cpp_token **);
     146                 :             : static void cb_ident (cpp_reader *, location_t, const cpp_string *);
     147                 :             : static void cb_used_define (cpp_reader *, location_t, cpp_hashnode *);
     148                 :             : static void cb_used_undef (cpp_reader *, location_t, cpp_hashnode *);
     149                 :             : static bool cb_cpp_diagnostic (cpp_reader *, enum cpp_diagnostic_level,
     150                 :             :                                enum cpp_warning_reason, rich_location *,
     151                 :             :                                const char *, va_list *)
     152                 :             :      ATTRIBUTE_GCC_DIAG(5,0);
     153                 :             : void pp_dir_change (cpp_reader *, const char *);
     154                 :             : 
     155                 :             : static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
     156                 :             : static void dump_queued_macros (cpp_reader *);
     157                 :             : 
     158                 :             : 
     159                 :             : static void
     160                 :        1101 : cpp_define_builtins (cpp_reader *pfile)
     161                 :             : {
     162                 :             :   /* Initialize CPP built-ins; '1' corresponds to 'flag_hosted'
     163                 :             :      in C, defines __STDC_HOSTED__?!  */
     164                 :        1101 :   cpp_init_builtins (pfile, 0);
     165                 :             : 
     166                 :             :   /* Initialize GFORTRAN specific builtins.
     167                 :             :      These are documented.  */
     168                 :        1101 :   define_language_independent_builtin_macros (pfile);
     169                 :        1101 :   cpp_define (pfile, "__GFORTRAN__=1");
     170                 :        1101 :   cpp_define (pfile, "_LANGUAGE_FORTRAN=1");
     171                 :             : 
     172                 :        1101 :   if (flag_openacc)
     173                 :         115 :     cpp_define (pfile, "_OPENACC=201711");
     174                 :             : 
     175                 :        1101 :   if (flag_openmp)
     176                 :          28 :     cpp_define (pfile, "_OPENMP=201511");
     177                 :             : 
     178                 :             :   /* The defines below are necessary for the TARGET_* macros.
     179                 :             : 
     180                 :             :      FIXME:  Note that builtin_define_std() actually is a function
     181                 :             :      in c-cppbuiltin.cc which uses flags undefined for Fortran.
     182                 :             :      Let's skip this for now. If needed, one needs to look into it
     183                 :             :      once more.  */
     184                 :             : 
     185                 :             : # define builtin_define(TXT) cpp_define (pfile, TXT)
     186                 :             : # define builtin_define_std(TXT)
     187                 :             : # define builtin_assert(TXT) cpp_assert (pfile, TXT)
     188                 :             : 
     189                 :             :   /* FIXME: Pandora's Box
     190                 :             :     Using the macros below results in multiple breakages:
     191                 :             :      - mingw will fail to compile this file as dependent macros
     192                 :             :        assume to be used in c-cppbuiltin.cc only. Further, they use
     193                 :             :        flags only valid/defined in C (same as noted above).
     194                 :             :        [config/i386/mingw32.h, config/i386/cygming.h]
     195                 :             :      - other platforms (not as popular) break similarly
     196                 :             :        [grep for 'builtin_define_with_int_value' in gcc/config/]
     197                 :             : 
     198                 :             :   TARGET_CPU_CPP_BUILTINS ();
     199                 :             :   TARGET_OS_CPP_BUILTINS ();
     200                 :             :   TARGET_OBJFMT_CPP_BUILTINS (); */
     201                 :             : 
     202                 :             : #undef builtin_define
     203                 :             : #undef builtin_define_std
     204                 :             : #undef builtin_assert
     205                 :        1101 : }
     206                 :             : 
     207                 :             : bool
     208                 :      207957 : gfc_cpp_enabled (void)
     209                 :             : {
     210                 :      207957 :   return gfc_cpp_option.temporary_filename != NULL;
     211                 :             : }
     212                 :             : 
     213                 :             : bool
     214                 :       62419 : gfc_cpp_preprocess_only (void)
     215                 :             : {
     216                 :       62419 :   return gfc_cpp_option.preprocess_only;
     217                 :             : }
     218                 :             : 
     219                 :             : bool
     220                 :       81309 : gfc_cpp_makedep (void)
     221                 :             : {
     222                 :       81309 :   return gfc_cpp_option.deps;
     223                 :             : }
     224                 :             : 
     225                 :             : void
     226                 :           0 : gfc_cpp_add_dep (const char *name, bool system)
     227                 :             : {
     228                 :           0 :   if (!gfc_cpp_option.deps_skip_system || !system)
     229                 :           0 :     if (mkdeps *deps = cpp_get_deps (cpp_in))
     230                 :           0 :       deps_add_dep (deps, name);
     231                 :           0 : }
     232                 :             : 
     233                 :             : void
     234                 :           0 : gfc_cpp_add_target (const char *name)
     235                 :             : {
     236                 :           0 :   if (mkdeps *deps = cpp_get_deps (cpp_in))
     237                 :           0 :     deps_add_target (deps, name, 0);
     238                 :           0 : }
     239                 :             : 
     240                 :             : 
     241                 :             : const char *
     242                 :        1089 : gfc_cpp_temporary_file (void)
     243                 :             : {
     244                 :        1089 :   return gfc_cpp_option.temporary_filename;
     245                 :             : }
     246                 :             : 
     247                 :             : static void
     248                 :        1101 : gfc_cpp_register_include_paths (bool verbose_missing_dir_warn)
     249                 :             : {
     250                 :        1101 :   int cxx_stdinc = 0;
     251                 :        2202 :   cpp_get_options (cpp_in)->warn_missing_include_dirs
     252                 :        2202 :     = (global_options.x_cpp_warn_missing_include_dirs
     253                 :        1101 :        && verbose_missing_dir_warn);
     254                 :        1101 :   register_include_chains (cpp_in, gfc_cpp_option.sysroot,
     255                 :             :                            gfc_cpp_option.prefix, gfc_cpp_option.multilib,
     256                 :             :                            gfc_cpp_option.standard_include_paths, cxx_stdinc,
     257                 :             :                            gfc_cpp_option.verbose);
     258                 :        1101 : }
     259                 :             : 
     260                 :             : void
     261                 :       29553 : gfc_cpp_init_options (unsigned int decoded_options_count,
     262                 :             :                       struct cl_decoded_option *decoded_options ATTRIBUTE_UNUSED)
     263                 :             : {
     264                 :             :   /* Do not create any objects from libcpp here. If no
     265                 :             :      preprocessing is requested, this would be wasted
     266                 :             :      time and effort.
     267                 :             : 
     268                 :             :      See gfc_cpp_post_options() instead.  */
     269                 :             : 
     270                 :       29553 :   gfc_cpp_option.temporary_filename = NULL;
     271                 :       29553 :   gfc_cpp_option.output_filename = NULL;
     272                 :       29553 :   gfc_cpp_option.preprocess_only = 0;
     273                 :       29553 :   gfc_cpp_option.discard_comments = 1;
     274                 :       29553 :   gfc_cpp_option.discard_comments_in_macro_exp = 1;
     275                 :       29553 :   gfc_cpp_option.print_include_names = 0;
     276                 :       29553 :   gfc_cpp_option.no_line_commands = 0;
     277                 :       29553 :   gfc_cpp_option.dump_macros = '\0';
     278                 :       29553 :   gfc_cpp_option.dump_includes = 0;
     279                 :       29553 :   gfc_cpp_option.working_directory = -1;
     280                 :       29553 :   gfc_cpp_option.no_predefined = 0;
     281                 :       29553 :   gfc_cpp_option.standard_include_paths = 1;
     282                 :       29553 :   gfc_cpp_option.verbose = 0;
     283                 :       29553 :   gfc_cpp_option.warn_date_time = 0;
     284                 :       29553 :   gfc_cpp_option.deps = 0;
     285                 :       29553 :   gfc_cpp_option.deps_skip_system = 0;
     286                 :       29553 :   gfc_cpp_option.deps_phony = 0;
     287                 :       29553 :   gfc_cpp_option.deps_missing_are_generated = 0;
     288                 :       29553 :   gfc_cpp_option.deps_filename = NULL;
     289                 :       29553 :   gfc_cpp_option.deps_filename_user = NULL;
     290                 :             : 
     291                 :       29553 :   gfc_cpp_option.multilib = NULL;
     292                 :       29553 :   gfc_cpp_option.prefix = NULL;
     293                 :       29553 :   gfc_cpp_option.sysroot = TARGET_SYSTEM_ROOT;
     294                 :             : 
     295                 :       29553 :   gfc_cpp_option.deferred_opt = XNEWVEC (gfc_cpp_deferred_opt_t,
     296                 :             :                                          decoded_options_count);
     297                 :       29553 :   gfc_cpp_option.deferred_opt_count = 0;
     298                 :       29553 : }
     299                 :             : 
     300                 :             : bool
     301                 :      197332 : gfc_cpp_handle_option (size_t scode, const char *arg, int value ATTRIBUTE_UNUSED)
     302                 :             : {
     303                 :      197332 :   bool result = true;
     304                 :      197332 :   enum opt_code code = (enum opt_code) scode;
     305                 :             : 
     306                 :      197332 :   switch (code)
     307                 :             :   {
     308                 :             :     default:
     309                 :             :       result = false;
     310                 :             :       break;
     311                 :             : 
     312                 :        1101 :     case OPT_cpp_:
     313                 :        1101 :       gfc_cpp_option.temporary_filename = arg;
     314                 :        1101 :       break;
     315                 :             : 
     316                 :           0 :     case OPT_nocpp:
     317                 :           0 :       gfc_cpp_option.temporary_filename = 0L;
     318                 :           0 :       break;
     319                 :             : 
     320                 :             :     case OPT_d:
     321                 :          14 :       for ( ; *arg; ++arg)
     322                 :           7 :         switch (*arg)
     323                 :             :         {
     324                 :           0 :           case 'D':
     325                 :           0 :           case 'M':
     326                 :           0 :           case 'N':
     327                 :           0 :           case 'U':
     328                 :           0 :             gfc_cpp_option.dump_macros = *arg;
     329                 :           0 :             break;
     330                 :             : 
     331                 :           0 :           case 'I':
     332                 :           0 :             gfc_cpp_option.dump_includes = 1;
     333                 :           0 :             break;
     334                 :             :         }
     335                 :             :       break;
     336                 :             : 
     337                 :           0 :     case OPT_fworking_directory:
     338                 :           0 :       gfc_cpp_option.working_directory = value;
     339                 :           0 :       break;
     340                 :             : 
     341                 :           3 :     case OPT_idirafter:
     342                 :           3 :       gfc_cpp_add_include_path_after (xstrdup(arg), true);
     343                 :           3 :       break;
     344                 :             : 
     345                 :         347 :     case OPT_imultilib:
     346                 :         347 :       gfc_cpp_option.multilib = arg;
     347                 :         347 :       break;
     348                 :             : 
     349                 :        1101 :     case OPT_iprefix:
     350                 :        1101 :       gfc_cpp_option.prefix = arg;
     351                 :        1101 :       break;
     352                 :             : 
     353                 :           0 :     case OPT_isysroot:
     354                 :           0 :       gfc_cpp_option.sysroot = arg;
     355                 :           0 :       break;
     356                 :             : 
     357                 :        4788 :     case OPT_iquote:
     358                 :        4788 :     case OPT_isystem:
     359                 :        4788 :       gfc_cpp_add_include_path (xstrdup(arg), true);
     360                 :        4788 :       break;
     361                 :             : 
     362                 :           0 :     case OPT_nostdinc:
     363                 :           0 :       gfc_cpp_option.standard_include_paths = value;
     364                 :           0 :       break;
     365                 :             : 
     366                 :       29553 :     case OPT_o:
     367                 :       29553 :       if (!gfc_cpp_option.output_filename)
     368                 :       29553 :         gfc_cpp_option.output_filename = arg;
     369                 :             :       else
     370                 :           0 :         gfc_fatal_error ("output filename specified twice");
     371                 :       29553 :       break;
     372                 :             : 
     373                 :           0 :     case OPT_undef:
     374                 :           0 :       gfc_cpp_option.no_predefined = value;
     375                 :           0 :       break;
     376                 :             : 
     377                 :           0 :     case OPT_v:
     378                 :           0 :       gfc_cpp_option.verbose = value;
     379                 :           0 :       break;
     380                 :             : 
     381                 :           1 :     case OPT_Wdate_time:
     382                 :           1 :       gfc_cpp_option.warn_date_time = value;
     383                 :           1 :       break;
     384                 :             : 
     385                 :        1086 :     case OPT_A:
     386                 :        1086 :     case OPT_D:
     387                 :        1086 :     case OPT_U:
     388                 :        1086 :       gfc_cpp_option.deferred_opt[gfc_cpp_option.deferred_opt_count].code = code;
     389                 :        1086 :       gfc_cpp_option.deferred_opt[gfc_cpp_option.deferred_opt_count].arg = arg;
     390                 :        1086 :       gfc_cpp_option.deferred_opt_count++;
     391                 :        1086 :       break;
     392                 :             : 
     393                 :           0 :     case OPT_C:
     394                 :           0 :       gfc_cpp_option.discard_comments = 0;
     395                 :           0 :       break;
     396                 :             : 
     397                 :           0 :     case OPT_CC:
     398                 :           0 :       gfc_cpp_option.discard_comments = 0;
     399                 :           0 :       gfc_cpp_option.discard_comments_in_macro_exp = 0;
     400                 :           0 :       break;
     401                 :             : 
     402                 :          12 :     case OPT_E:
     403                 :          12 :       gfc_cpp_option.preprocess_only = 1;
     404                 :          12 :       break;
     405                 :             : 
     406                 :           0 :     case OPT_H:
     407                 :           0 :       gfc_cpp_option.print_include_names = 1;
     408                 :           0 :       break;
     409                 :             : 
     410                 :           0 :     case OPT_MM:
     411                 :           0 :       gfc_cpp_option.deps_skip_system = 1;
     412                 :             :       /* fall through */
     413                 :             : 
     414                 :           0 :     case OPT_M:
     415                 :           0 :       gfc_cpp_option.deps = 1;
     416                 :           0 :       break;
     417                 :             : 
     418                 :           0 :     case OPT_MMD:
     419                 :           0 :       gfc_cpp_option.deps_skip_system = 1;
     420                 :             :       /* fall through */
     421                 :             : 
     422                 :           0 :     case OPT_MD:
     423                 :           0 :       gfc_cpp_option.deps = 1;
     424                 :           0 :       gfc_cpp_option.deps_filename = arg;
     425                 :           0 :       break;
     426                 :             : 
     427                 :           0 :     case OPT_MF:
     428                 :             :       /* If specified multiple times, last one wins.  */
     429                 :           0 :       gfc_cpp_option.deps_filename_user = arg;
     430                 :           0 :       break;
     431                 :             : 
     432                 :           0 :     case OPT_MG:
     433                 :           0 :       gfc_cpp_option.deps_missing_are_generated = 1;
     434                 :           0 :       break;
     435                 :             : 
     436                 :           0 :     case OPT_MP:
     437                 :           0 :       gfc_cpp_option.deps_phony = 1;
     438                 :           0 :       break;
     439                 :             : 
     440                 :           0 :     case OPT_MQ:
     441                 :           0 :     case OPT_MT:
     442                 :           0 :       gfc_cpp_option.deferred_opt[gfc_cpp_option.deferred_opt_count].code = code;
     443                 :           0 :       gfc_cpp_option.deferred_opt[gfc_cpp_option.deferred_opt_count].arg = arg;
     444                 :           0 :       gfc_cpp_option.deferred_opt_count++;
     445                 :           0 :       break;
     446                 :             : 
     447                 :           0 :     case OPT_P:
     448                 :           0 :       gfc_cpp_option.no_line_commands = 1;
     449                 :           0 :       break;
     450                 :             :   }
     451                 :             : 
     452                 :      197332 :   return result;
     453                 :             : }
     454                 :             : 
     455                 :             : /* This function needs to be called before gfc_cpp_register_include_paths
     456                 :             :    as the latter may diagnose missing include directories.  */
     457                 :             : static void
     458                 :        1101 : gfc_cpp_init_cb (void)
     459                 :             : {
     460                 :        1101 :   struct cpp_callbacks *cb;
     461                 :             : 
     462                 :        1101 :   cb = cpp_get_callbacks (cpp_in);
     463                 :        1101 :   cb->file_change = cb_file_change;
     464                 :        1101 :   cb->line_change = cb_line_change;
     465                 :        1101 :   cb->ident = cb_ident;
     466                 :        1101 :   cb->def_pragma = cb_def_pragma;
     467                 :        1101 :   cb->diagnostic = cb_cpp_diagnostic;
     468                 :             : 
     469                 :        1101 :   if (gfc_cpp_option.dump_includes)
     470                 :           0 :     cb->include = cb_include;
     471                 :             : 
     472                 :        1101 :   if ((gfc_cpp_option.dump_macros == 'D')
     473                 :        1101 :       || (gfc_cpp_option.dump_macros == 'N'))
     474                 :             :     {
     475                 :           0 :       cb->define = cb_define;
     476                 :           0 :       cb->undef  = cb_undef;
     477                 :             :     }
     478                 :             : 
     479                 :        1101 :   if (gfc_cpp_option.dump_macros == 'U')
     480                 :             :     {
     481                 :           0 :       cb->before_define = dump_queued_macros;
     482                 :           0 :       cb->used_define = cb_used_define;
     483                 :           0 :       cb->used_undef = cb_used_undef;
     484                 :             :     }
     485                 :        1101 : }
     486                 :             : 
     487                 :             : void
     488                 :       29552 : gfc_cpp_post_options (bool verbose_missing_dir_warn)
     489                 :             : {
     490                 :             :   /* Any preprocessing-related option without '-cpp' is considered
     491                 :             :      an error.  */
     492                 :       29552 :   if (!gfc_cpp_enabled ()
     493                 :       29552 :       && (gfc_cpp_preprocess_only ()
     494                 :       28451 :           || gfc_cpp_makedep ()
     495                 :       28451 :           || !gfc_cpp_option.discard_comments
     496                 :       28451 :           || !gfc_cpp_option.discard_comments_in_macro_exp
     497                 :       28451 :           || gfc_cpp_option.print_include_names
     498                 :             :           || gfc_cpp_option.no_line_commands
     499                 :       28451 :           || gfc_cpp_option.dump_macros
     500                 :       28451 :           || gfc_cpp_option.dump_includes))
     501                 :           0 :     gfc_fatal_error ("To enable preprocessing, use %<-cpp%>");
     502                 :             : 
     503                 :       29552 :   if (!gfc_cpp_enabled ())
     504                 :             :     return;
     505                 :             : 
     506                 :        1101 :   cpp_in = cpp_create_reader (CLK_GNUC89, NULL, line_table);
     507                 :        1101 :   gcc_assert (cpp_in);
     508                 :             : 
     509                 :             :   /* The cpp_options-structure defines far more flags than those set here.
     510                 :             :      If any other is implemented, see c-opt.c (sanitize_cpp_opts) for
     511                 :             :      inter-option dependencies that may need to be enforced.  */
     512                 :        1101 :   cpp_option = cpp_get_options (cpp_in);
     513                 :        1101 :   gcc_assert (cpp_option);
     514                 :             : 
     515                 :             :   /* TODO: allow non-traditional modes, e.g. by -cpp-std=...?  */
     516                 :        1101 :   cpp_option->traditional = 1;
     517                 :        1101 :   cpp_option->cplusplus_comments = 0;
     518                 :             : 
     519                 :        1101 :   cpp_option->cpp_pedantic = pedantic;
     520                 :             : 
     521                 :        1101 :   cpp_option->dollars_in_ident = flag_dollar_ok;
     522                 :        1101 :   cpp_option->discard_comments = gfc_cpp_option.discard_comments;
     523                 :        1101 :   cpp_option->discard_comments_in_macro_exp = gfc_cpp_option.discard_comments_in_macro_exp;
     524                 :        1101 :   cpp_option->print_include_names = gfc_cpp_option.print_include_names;
     525                 :        1101 :   cpp_option->preprocessed = gfc_option.flag_preprocessed;
     526                 :        1101 :   cpp_option->warn_date_time = gfc_cpp_option.warn_date_time;
     527                 :             : 
     528                 :        1101 :   if (gfc_cpp_makedep ())
     529                 :             :     {
     530                 :           0 :       cpp_option->deps.style = DEPS_USER;
     531                 :           0 :       cpp_option->deps.phony_targets = gfc_cpp_option.deps_phony;
     532                 :           0 :       cpp_option->deps.missing_files = gfc_cpp_option.deps_missing_are_generated;
     533                 :             : 
     534                 :             :       /* -MF <arg> overrides -M[M]D.  */
     535                 :           0 :       if (gfc_cpp_option.deps_filename_user)
     536                 :           0 :         gfc_cpp_option.deps_filename = gfc_cpp_option.deps_filename_user;
     537                 :             :   }
     538                 :             : 
     539                 :        1101 :   if (gfc_cpp_option.working_directory == -1)
     540                 :        1101 :     gfc_cpp_option.working_directory = (debug_info_level != DINFO_LEVEL_NONE);
     541                 :             : 
     542                 :        1101 :   cpp_post_options (cpp_in);
     543                 :             : 
     544                 :             : 
     545                 :             :   /* Let diagnostics infrastructure know how to convert input files the same
     546                 :             :      way libcpp will do it, namely, with no charset conversion but with
     547                 :             :      skipping of a UTF-8 BOM if present.  */
     548                 :        1101 :   diagnostic_initialize_input_context (global_dc, nullptr, true);
     549                 :        1101 :   gfc_cpp_init_cb ();
     550                 :             : 
     551                 :        1101 :   gfc_cpp_register_include_paths (verbose_missing_dir_warn);
     552                 :             : }
     553                 :             : 
     554                 :             : 
     555                 :             : void
     556                 :        1101 : gfc_cpp_init_0 (void)
     557                 :             : {
     558                 :             :   /* Initialize the print structure.  Setting print.src_line to -1 here is
     559                 :             :      a trick to guarantee that the first token of the file will cause
     560                 :             :      a linemarker to be output by maybe_print_line.  */
     561                 :        1101 :   print.src_line = -1;
     562                 :        1101 :   print.printed = 0;
     563                 :        1101 :   print.prev = 0;
     564                 :        1101 :   print.first_time = 1;
     565                 :             : 
     566                 :        1101 :   if (gfc_cpp_preprocess_only ())
     567                 :             :     {
     568                 :          12 :       if (gfc_cpp_option.output_filename)
     569                 :             :         {
     570                 :             :           /* This needs cheating: with "-E -o <file>", the user wants the
     571                 :             :              preprocessed output in <file>. However, if nothing is done
     572                 :             :              about it <file> is also used for assembler output. Hence, it
     573                 :             :              is necessary to redirect assembler output (actually nothing
     574                 :             :              as -E implies -fsyntax-only) to another file, otherwise the
     575                 :             :              output from preprocessing is lost.  */
     576                 :          12 :           asm_file_name = gfc_cpp_option.temporary_filename;
     577                 :             : 
     578                 :          12 :           print.outf = fopen (gfc_cpp_option.output_filename, "w");
     579                 :          12 :           if (print.outf == NULL)
     580                 :           0 :             gfc_fatal_error ("opening output file %qs: %s",
     581                 :             :                              gfc_cpp_option.output_filename,
     582                 :           0 :                              xstrerror (errno));
     583                 :             :         }
     584                 :             :       else
     585                 :           0 :         print.outf = stdout;
     586                 :             :     }
     587                 :             :   else
     588                 :             :     {
     589                 :        1089 :       print.outf = fopen (gfc_cpp_option.temporary_filename, "w");
     590                 :        1089 :       if (print.outf == NULL)
     591                 :           0 :         gfc_fatal_error ("opening output file %qs: %s",
     592                 :           0 :                          gfc_cpp_option.temporary_filename, xstrerror (errno));
     593                 :             :     }
     594                 :             : 
     595                 :        1101 :   gcc_assert(cpp_in);
     596                 :        1101 :   if (!cpp_read_main_file (cpp_in, gfc_source_file))
     597                 :           0 :     errorcount++;
     598                 :        1101 : }
     599                 :             : 
     600                 :             : void
     601                 :        1101 : gfc_cpp_init (void)
     602                 :             : {
     603                 :        1101 :   int i;
     604                 :             : 
     605                 :        1101 :   if (gfc_option.flag_preprocessed)
     606                 :             :     return;
     607                 :             : 
     608                 :        1101 :   cpp_change_file (cpp_in, LC_RENAME, special_fname_builtin ());
     609                 :        1101 :   if (!gfc_cpp_option.no_predefined)
     610                 :             :     {
     611                 :             :       /* Make sure all of the builtins about to be declared have
     612                 :             :         BUILTINS_LOCATION has their location_t.  */
     613                 :        1101 :       cpp_force_token_locations (cpp_in, BUILTINS_LOCATION);
     614                 :             : 
     615                 :        1101 :       cpp_define_builtins (cpp_in);
     616                 :             : 
     617                 :        1101 :       cpp_stop_forcing_token_locations (cpp_in);
     618                 :             :     }
     619                 :             : 
     620                 :             :   /* Handle deferred options from command-line.  */
     621                 :        1101 :   cpp_change_file (cpp_in, LC_RENAME, _("<command-line>"));
     622                 :             : 
     623                 :        2187 :   for (i = 0; i < gfc_cpp_option.deferred_opt_count; i++)
     624                 :             :     {
     625                 :        1086 :       gfc_cpp_deferred_opt_t *opt = &gfc_cpp_option.deferred_opt[i];
     626                 :             : 
     627                 :        1086 :       if (opt->code == OPT_D)
     628                 :        1086 :         cpp_define (cpp_in, opt->arg);
     629                 :           0 :       else if (opt->code == OPT_U)
     630                 :           0 :         cpp_undef (cpp_in, opt->arg);
     631                 :           0 :       else if (opt->code == OPT_A)
     632                 :             :         {
     633                 :           0 :           if (opt->arg[0] == '-')
     634                 :           0 :             cpp_unassert (cpp_in, opt->arg + 1);
     635                 :             :           else
     636                 :           0 :             cpp_assert (cpp_in, opt->arg);
     637                 :             :         }
     638                 :           0 :       else if (opt->code == OPT_MT || opt->code == OPT_MQ)
     639                 :           0 :         if (mkdeps *deps = cpp_get_deps (cpp_in))
     640                 :           0 :           deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
     641                 :             :     }
     642                 :             : 
     643                 :             :   /* Pre-defined macros for non-required INTEGER kind types.  */
     644                 :        6259 :   for (gfc_integer_info *itype = gfc_integer_kinds; itype->kind != 0; itype++)
     645                 :             :     {
     646                 :        5158 :       if (itype->kind == 1)
     647                 :        1101 :         cpp_define (cpp_in, "__GFC_INT_1__=1");
     648                 :        5158 :       if (itype->kind == 2)
     649                 :        1101 :         cpp_define (cpp_in, "__GFC_INT_2__=1");
     650                 :        5158 :       if (itype->kind == 8)
     651                 :        1101 :         cpp_define (cpp_in, "__GFC_INT_8__=1");
     652                 :        5158 :       if (itype->kind == 16)
     653                 :         754 :         cpp_define (cpp_in, "__GFC_INT_16__=1");
     654                 :             :     }
     655                 :             : 
     656                 :             :   /* Pre-defined macros for non-required REAL kind types.  */
     657                 :        5505 :   for (gfc_real_info *rtype = gfc_real_kinds; rtype->kind != 0; rtype++)
     658                 :             :     {
     659                 :        4404 :       if (rtype->kind == 10)
     660                 :        1101 :         cpp_define (cpp_in, "__GFC_REAL_10__=1");
     661                 :        4404 :       if (rtype->kind == 16)
     662                 :        1101 :         cpp_define (cpp_in, "__GFC_REAL_16__=1");
     663                 :             :     }
     664                 :             : 
     665                 :        1101 :   if (gfc_cpp_option.working_directory
     666                 :         750 :       && gfc_cpp_option.preprocess_only && !gfc_cpp_option.no_line_commands)
     667                 :           0 :     pp_dir_change (cpp_in, get_src_pwd ());
     668                 :             : }
     669                 :             : 
     670                 :             : bool
     671                 :        1101 : gfc_cpp_preprocess (const char *source_file)
     672                 :             : {
     673                 :        1101 :   if (!gfc_cpp_enabled ())
     674                 :             :     return false;
     675                 :             : 
     676                 :        1101 :   cpp_change_file (cpp_in, LC_RENAME, source_file);
     677                 :             : 
     678                 :        1101 :   if (cpp_option->traditional)
     679                 :        1101 :     scan_translation_unit_trad (cpp_in);
     680                 :             :   else
     681                 :           0 :     scan_translation_unit (cpp_in);
     682                 :             : 
     683                 :             :   /* -dM command line option.  */
     684                 :        1101 :   if (gfc_cpp_preprocess_only () &&
     685                 :          12 :       gfc_cpp_option.dump_macros == 'M')
     686                 :             :     {
     687                 :           0 :       putc ('\n', print.outf);
     688                 :           0 :       cpp_forall_identifiers (cpp_in, dump_macro, NULL);
     689                 :             :     }
     690                 :             : 
     691                 :        1101 :   putc ('\n', print.outf);
     692                 :             : 
     693                 :        1101 :   if (!gfc_cpp_preprocess_only ()
     694                 :        1101 :       || (gfc_cpp_preprocess_only () && gfc_cpp_option.output_filename))
     695                 :        1101 :     fclose (print.outf);
     696                 :             : 
     697                 :             :   return true;
     698                 :             : }
     699                 :             : 
     700                 :             : void
     701                 :       29535 : gfc_cpp_done (void)
     702                 :             : {
     703                 :       29535 :   if (!gfc_cpp_enabled ())
     704                 :             :     return;
     705                 :             : 
     706                 :        1101 :   gcc_assert (cpp_in);
     707                 :             : 
     708                 :        1101 :   if (gfc_cpp_makedep ())
     709                 :             :     {
     710                 :           0 :       if (gfc_cpp_option.deps_filename)
     711                 :             :         {
     712                 :           0 :           FILE *f = fopen (gfc_cpp_option.deps_filename, "w");
     713                 :           0 :           if (f)
     714                 :             :             {
     715                 :           0 :               cpp_finish (cpp_in, f);
     716                 :           0 :               fclose (f);
     717                 :             :             }
     718                 :             :           else
     719                 :           0 :             gfc_fatal_error ("opening output file %qs: %s",
     720                 :             :                              gfc_cpp_option.deps_filename,
     721                 :           0 :                              xstrerror (errno));
     722                 :             :         }
     723                 :             :       else
     724                 :           0 :         cpp_finish (cpp_in, stdout);
     725                 :             :     }
     726                 :             : 
     727                 :        1101 :   cpp_undef_all (cpp_in);
     728                 :        1101 :   cpp_clear_file_cache (cpp_in);
     729                 :             : }
     730                 :             : 
     731                 :             : /* PATH must be malloc-ed and NULL-terminated.  */
     732                 :             : void
     733                 :       55256 : gfc_cpp_add_include_path (char *path, bool user_supplied)
     734                 :             : {
     735                 :             :   /* CHAIN sets cpp_dir->sysp which differs from 0 if PATH is a system
     736                 :             :      include path. Fortran does not define any system include paths.  */
     737                 :       55256 :   int cxx_aware = 0;
     738                 :             : 
     739                 :       55256 :   add_path (path, INC_BRACKET, cxx_aware, user_supplied);
     740                 :       55256 : }
     741                 :             : 
     742                 :             : void
     743                 :           3 : gfc_cpp_add_include_path_after (char *path, bool user_supplied)
     744                 :             : {
     745                 :           3 :   int cxx_aware = 0;
     746                 :           3 :   add_path (path, INC_AFTER, cxx_aware, user_supplied);
     747                 :           3 : }
     748                 :             : 
     749                 :             : 
     750                 :             : static void scan_translation_unit_trad (cpp_reader *);
     751                 :             : static void account_for_newlines (const unsigned char *, size_t);
     752                 :             : 
     753                 :             : static void print_line (location_t, const char *);
     754                 :             : static void maybe_print_line (location_t);
     755                 :             : 
     756                 :             : 
     757                 :             : /* Writes out the preprocessed file, handling spacing and paste
     758                 :             :    avoidance issues.  */
     759                 :             : static void
     760                 :           0 : scan_translation_unit (cpp_reader *pfile)
     761                 :             : {
     762                 :           0 :   bool avoid_paste = false;
     763                 :             : 
     764                 :           0 :   print.source = NULL;
     765                 :           0 :   for (;;)
     766                 :             :     {
     767                 :           0 :       const cpp_token *token = cpp_get_token (pfile);
     768                 :             : 
     769                 :           0 :       if (token->type == CPP_PADDING)
     770                 :             :         {
     771                 :           0 :           avoid_paste = true;
     772                 :           0 :           if (print.source == NULL
     773                 :           0 :               || (!(print.source->flags & PREV_WHITE)
     774                 :           0 :                   && token->val.source == NULL))
     775                 :           0 :             print.source = token->val.source;
     776                 :           0 :           continue;
     777                 :             :         }
     778                 :             : 
     779                 :           0 :       if (token->type == CPP_EOF)
     780                 :             :         break;
     781                 :             : 
     782                 :             :       /* Subtle logic to output a space if and only if necessary.  */
     783                 :           0 :       if (avoid_paste)
     784                 :             :         {
     785                 :           0 :           if (print.source == NULL)
     786                 :           0 :             print.source = token;
     787                 :           0 :           if (print.source->flags & PREV_WHITE
     788                 :           0 :               || (print.prev
     789                 :           0 :                   && cpp_avoid_paste (pfile, print.prev, token))
     790                 :           0 :               || (print.prev == NULL && token->type == CPP_HASH))
     791                 :           0 :             putc (' ', print.outf);
     792                 :             :         }
     793                 :           0 :       else if (token->flags & PREV_WHITE)
     794                 :           0 :         putc (' ', print.outf);
     795                 :             : 
     796                 :           0 :       avoid_paste = false;
     797                 :           0 :       print.source = NULL;
     798                 :           0 :       print.prev = token;
     799                 :           0 :       cpp_output_token (token, print.outf);
     800                 :             : 
     801                 :           0 :       if (token->type == CPP_COMMENT)
     802                 :           0 :         account_for_newlines (token->val.str.text, token->val.str.len);
     803                 :             :     }
     804                 :           0 : }
     805                 :             : 
     806                 :             : /* Adjust print.src_line for newlines embedded in output.  */
     807                 :             : static void
     808                 :           0 : account_for_newlines (const unsigned char *str, size_t len)
     809                 :             : {
     810                 :           0 :   while (len--)
     811                 :           0 :     if (*str++ == '\n')
     812                 :           0 :       print.src_line++;
     813                 :           0 : }
     814                 :             : 
     815                 :             : /* Writes out a traditionally preprocessed file.  */
     816                 :             : static void
     817                 :        1101 : scan_translation_unit_trad (cpp_reader *pfile)
     818                 :             : {
     819                 :      682203 :   while (_cpp_read_logical_line_trad (pfile))
     820                 :             :     {
     821                 :      680001 :       size_t len = pfile->out.cur - pfile->out.base;
     822                 :      680001 :       maybe_print_line (pfile->out.first_line);
     823                 :      680001 :       fwrite (pfile->out.base, 1, len, print.outf);
     824                 :      680001 :       print.printed = 1;
     825                 :      680001 :       if (!CPP_OPTION (pfile, discard_comments))
     826                 :           0 :         account_for_newlines (pfile->out.base, len);
     827                 :             :     }
     828                 :        1101 : }
     829                 :             : 
     830                 :             : /* If the token read on logical line LINE needs to be output on a
     831                 :             :    different line to the current one, output the required newlines or
     832                 :             :    a line marker.  */
     833                 :             : static void
     834                 :      682092 : maybe_print_line (location_t src_loc)
     835                 :             : {
     836                 :      682092 :   const line_map_ordinary *map
     837                 :      682092 :     = linemap_check_ordinary (linemap_lookup (line_table, src_loc));
     838                 :      682092 :   int src_line = SOURCE_LINE (map, src_loc);
     839                 :             : 
     840                 :             :   /* End the previous line of text.  */
     841                 :      682092 :   if (print.printed)
     842                 :             :     {
     843                 :      678201 :       putc ('\n', print.outf);
     844                 :      678201 :       print.src_line++;
     845                 :      678201 :       print.printed = 0;
     846                 :             :     }
     847                 :             : 
     848                 :      682092 :   if (src_line >= print.src_line && src_line < print.src_line + 8)
     849                 :             :     {
     850                 :      941995 :       while (src_line > print.src_line)
     851                 :             :         {
     852                 :      259984 :           putc ('\n', print.outf);
     853                 :      259984 :           print.src_line++;
     854                 :             :         }
     855                 :             :     }
     856                 :             :   else
     857                 :          81 :     print_line (src_loc, "");
     858                 :      682092 : }
     859                 :             : 
     860                 :             : /* Output a line marker for logical line LINE.  Special flags are "1"
     861                 :             :    or "2" indicating entering or leaving a file.  */
     862                 :             : static void
     863                 :        8667 : print_line (location_t src_loc, const char *special_flags)
     864                 :             : {
     865                 :             :   /* End any previous line of text.  */
     866                 :        8667 :   if (print.printed)
     867                 :         727 :     putc ('\n', print.outf);
     868                 :        8667 :   print.printed = 0;
     869                 :             : 
     870                 :        8667 :   if (!gfc_cpp_option.no_line_commands)
     871                 :             :     {
     872                 :        8667 :       expanded_location loc;
     873                 :        8667 :       size_t to_file_len;
     874                 :        8667 :       unsigned char *to_file_quoted;
     875                 :        8667 :       unsigned char *p;
     876                 :        8667 :       int sysp;
     877                 :             : 
     878                 :        8667 :       loc = expand_location (src_loc);
     879                 :        8667 :       to_file_len = strlen (loc.file);
     880                 :        8667 :       to_file_quoted = (unsigned char *) alloca (to_file_len * 4 + 1);
     881                 :             : 
     882                 :        8667 :       print.src_line = loc.line;
     883                 :             : 
     884                 :             :       /* cpp_quote_string does not nul-terminate, so we have to do it
     885                 :             :          ourselves.  */
     886                 :        8667 :       p = cpp_quote_string (to_file_quoted,
     887                 :             :                             (const unsigned char *) loc.file, to_file_len);
     888                 :        8667 :       *p = '\0';
     889                 :        8667 :       fprintf (print.outf, "# %u \"%s\"%s",
     890                 :        8667 :                print.src_line == 0 ? 1 : print.src_line,
     891                 :             :                to_file_quoted, special_flags);
     892                 :             : 
     893                 :        8667 :       sysp = in_system_header_at (src_loc);
     894                 :        8667 :       if (sysp == 2)
     895                 :           0 :         fputs (" 3 4", print.outf);
     896                 :        8667 :       else if (sysp == 1)
     897                 :           0 :         fputs (" 3", print.outf);
     898                 :             : 
     899                 :        8667 :       putc ('\n', print.outf);
     900                 :             :     }
     901                 :        8667 : }
     902                 :             : 
     903                 :             : static void
     904                 :        9687 : cb_file_change (cpp_reader * ARG_UNUSED (pfile), const line_map_ordinary *map)
     905                 :             : {
     906                 :        9687 :   const char *flags = "";
     907                 :             : 
     908                 :        9687 :   if (gfc_cpp_option.no_line_commands)
     909                 :             :     return;
     910                 :             : 
     911                 :        9687 :   if (!map)
     912                 :             :     return;
     913                 :             : 
     914                 :        8586 :       if (print.first_time)
     915                 :             :         {
     916                 :             :           /* Avoid printing foo.i when the main file is foo.c.  */
     917                 :        1101 :           if (!cpp_get_options (cpp_in)->preprocessed)
     918                 :        1101 :             print_line (map->start_location, flags);
     919                 :        1101 :           print.first_time = 0;
     920                 :             :         }
     921                 :             :       else
     922                 :             :         {
     923                 :             :           /* Bring current file to correct line when entering a new file.  */
     924                 :        7485 :           if (map->reason == LC_ENTER)
     925                 :        2091 :             maybe_print_line (linemap_included_from (map));
     926                 :        7485 :           if (map->reason == LC_ENTER)
     927                 :             :             flags = " 1";
     928                 :        5394 :           else if (map->reason == LC_LEAVE)
     929                 :        2091 :             flags = " 2";
     930                 :        7485 :           print_line (map->start_location, flags);
     931                 :             :         }
     932                 :             : 
     933                 :             : }
     934                 :             : 
     935                 :             : /* Called when a line of output is started.  TOKEN is the first token
     936                 :             :    of the line, and at end of file will be CPP_EOF.  */
     937                 :             : static void
     938                 :           0 : cb_line_change (cpp_reader *pfile, const cpp_token *token,
     939                 :             :                 int parsing_args)
     940                 :             : {
     941                 :           0 :   location_t src_loc = token->src_loc;
     942                 :             : 
     943                 :           0 :   if (token->type == CPP_EOF || parsing_args)
     944                 :             :     return;
     945                 :             : 
     946                 :           0 :   maybe_print_line (src_loc);
     947                 :           0 :   print.prev = 0;
     948                 :           0 :   print.source = 0;
     949                 :             : 
     950                 :             :   /* Supply enough spaces to put this token in its original column,
     951                 :             :      one space per column greater than 2, since scan_translation_unit
     952                 :             :      will provide a space if PREV_WHITE.  Don't bother trying to
     953                 :             :      reconstruct tabs; we can't get it right in general, and nothing
     954                 :             :      ought to care.  Some things do care; the fault lies with them.  */
     955                 :           0 :   if (!CPP_OPTION (pfile, traditional))
     956                 :             :     {
     957                 :           0 :       const line_map_ordinary *map
     958                 :           0 :         = linemap_check_ordinary (linemap_lookup (line_table, src_loc));
     959                 :           0 :       int spaces = SOURCE_COLUMN (map, src_loc) - 2;
     960                 :           0 :       print.printed = 1;
     961                 :             : 
     962                 :           0 :       while (-- spaces >= 0)
     963                 :           0 :         putc (' ', print.outf);
     964                 :             :     }
     965                 :             : }
     966                 :             : 
     967                 :             : static void
     968                 :           0 : cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, location_t line,
     969                 :             :           const cpp_string *str)
     970                 :             : {
     971                 :           0 :   maybe_print_line (line);
     972                 :           0 :   fprintf (print.outf, "#ident %s\n", str->text);
     973                 :           0 :   print.src_line++;
     974                 :           0 : }
     975                 :             : 
     976                 :             : static void
     977                 :           0 : cb_define (cpp_reader *pfile ATTRIBUTE_UNUSED, location_t line,
     978                 :             :            cpp_hashnode *node ATTRIBUTE_UNUSED)
     979                 :             : {
     980                 :           0 :   maybe_print_line (line);
     981                 :           0 :   fputs ("#define ", print.outf);
     982                 :             : 
     983                 :             :   /* 'D' is whole definition; 'N' is name only.  */
     984                 :           0 :   if (gfc_cpp_option.dump_macros == 'D')
     985                 :           0 :     fputs ((const char *) cpp_macro_definition (pfile, node),
     986                 :             :            print.outf);
     987                 :             :   else
     988                 :           0 :     fputs ((const char *) NODE_NAME (node), print.outf);
     989                 :             : 
     990                 :           0 :   putc ('\n', print.outf);
     991                 :           0 :   if (LOCATION_LINE (line) != 0)
     992                 :           0 :     print.src_line++;
     993                 :           0 : }
     994                 :             : 
     995                 :             : static void
     996                 :           0 : cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, location_t line,
     997                 :             :           cpp_hashnode *node)
     998                 :             : {
     999                 :           0 :   maybe_print_line (line);
    1000                 :           0 :   fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
    1001                 :           0 :   print.src_line++;
    1002                 :           0 : }
    1003                 :             : 
    1004                 :             : static void
    1005                 :           0 : cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, location_t line,
    1006                 :             :             const unsigned char *dir, const char *header, int angle_brackets,
    1007                 :             :             const cpp_token **comments)
    1008                 :             : {
    1009                 :           0 :   maybe_print_line (line);
    1010                 :           0 :   if (angle_brackets)
    1011                 :           0 :     fprintf (print.outf, "#%s <%s>", dir, header);
    1012                 :             :   else
    1013                 :           0 :     fprintf (print.outf, "#%s \"%s\"", dir, header);
    1014                 :             : 
    1015                 :           0 :   if (comments != NULL)
    1016                 :             :     {
    1017                 :           0 :       while (*comments != NULL)
    1018                 :             :         {
    1019                 :           0 :           if ((*comments)->flags & PREV_WHITE)
    1020                 :           0 :             putc (' ', print.outf);
    1021                 :           0 :           cpp_output_token (*comments, print.outf);
    1022                 :           0 :           ++comments;
    1023                 :             :         }
    1024                 :             :     }
    1025                 :             : 
    1026                 :           0 :   putc ('\n', print.outf);
    1027                 :           0 :   print.src_line++;
    1028                 :           0 : }
    1029                 :             : 
    1030                 :             : /* Dump out the hash table.  */
    1031                 :             : static int
    1032                 :           0 : dump_macro (cpp_reader *pfile, cpp_hashnode *node, void *v ATTRIBUTE_UNUSED)
    1033                 :             : {
    1034                 :           0 :   if (cpp_user_macro_p (node))
    1035                 :             :     {
    1036                 :           0 :       fputs ("#define ", print.outf);
    1037                 :           0 :       fputs ((const char *) cpp_macro_definition (pfile, node),
    1038                 :             :              print.outf);
    1039                 :           0 :       putc ('\n', print.outf);
    1040                 :           0 :       print.src_line++;
    1041                 :             :     }
    1042                 :             : 
    1043                 :           0 :   return 1;
    1044                 :             : }
    1045                 :             : 
    1046                 :             : static void
    1047                 :           0 : cb_used_define (cpp_reader *pfile, location_t line ATTRIBUTE_UNUSED,
    1048                 :             :                 cpp_hashnode *node)
    1049                 :             : {
    1050                 :           0 :   gfc_cpp_macro_queue *q;
    1051                 :           0 :   q = XNEW (gfc_cpp_macro_queue);
    1052                 :           0 :   q->macro = xstrdup ((const char *) cpp_macro_definition (pfile, node));
    1053                 :           0 :   q->next = cpp_define_queue;
    1054                 :           0 :   cpp_define_queue = q;
    1055                 :           0 : }
    1056                 :             : 
    1057                 :             : /* Return the gcc option code associated with the reason for a cpp
    1058                 :             :    message, or 0 if none.  */
    1059                 :             : 
    1060                 :             : static int
    1061                 :          14 : cb_cpp_diagnostic_cpp_option (enum cpp_warning_reason reason)
    1062                 :             : {
    1063                 :          14 :   const struct cpp_reason_option_codes_t *entry;
    1064                 :             : 
    1065                 :         184 :   for (entry = cpp_reason_option_codes; entry->reason != CPP_W_NONE; entry++)
    1066                 :         183 :     if (entry->reason == reason)
    1067                 :          13 :       return entry->option_code;
    1068                 :             :   return 0;
    1069                 :             : }
    1070                 :             : 
    1071                 :             : 
    1072                 :             : /* Callback from cpp_error for PFILE to print diagnostics from the
    1073                 :             :    preprocessor.  The diagnostic is of type LEVEL, with REASON set
    1074                 :             :    to the reason code if LEVEL is represents a warning, at location
    1075                 :             :    RICHLOC; MSG is the translated message and AP the arguments.
    1076                 :             :    Returns true if a diagnostic was emitted, false otherwise.  */
    1077                 :             : 
    1078                 :             : static bool
    1079                 :          14 : cb_cpp_diagnostic (cpp_reader *pfile ATTRIBUTE_UNUSED,
    1080                 :             :                    enum cpp_diagnostic_level level,
    1081                 :             :                    enum cpp_warning_reason reason,
    1082                 :             :                    rich_location *richloc,
    1083                 :             :                    const char *msg, va_list *ap)
    1084                 :             : {
    1085                 :          14 :   diagnostic_info diagnostic;
    1086                 :          14 :   diagnostic_t dlevel;
    1087                 :          14 :   bool save_warn_system_headers = global_dc->m_warn_system_headers;
    1088                 :          14 :   bool ret;
    1089                 :             : 
    1090                 :          14 :   switch (level)
    1091                 :             :     {
    1092                 :           6 :     case CPP_DL_WARNING_SYSHDR:
    1093                 :           6 :       global_dc->m_warn_system_headers = 1;
    1094                 :             :       /* Fall through.  */
    1095                 :             :     case CPP_DL_WARNING:
    1096                 :             :       dlevel = DK_WARNING;
    1097                 :             :       break;
    1098                 :             :     case CPP_DL_PEDWARN:
    1099                 :             :       dlevel = DK_PEDWARN;
    1100                 :             :       break;
    1101                 :           1 :     case CPP_DL_ERROR:
    1102                 :           1 :       dlevel = DK_ERROR;
    1103                 :           1 :       break;
    1104                 :           0 :     case CPP_DL_ICE:
    1105                 :           0 :       dlevel = DK_ICE;
    1106                 :           0 :       break;
    1107                 :           0 :     case CPP_DL_NOTE:
    1108                 :           0 :       dlevel = DK_NOTE;
    1109                 :           0 :       break;
    1110                 :           0 :     case CPP_DL_FATAL:
    1111                 :           0 :       dlevel = DK_FATAL;
    1112                 :           0 :       break;
    1113                 :           0 :     default:
    1114                 :           0 :       gcc_unreachable ();
    1115                 :             :     }
    1116                 :          14 :   diagnostic_set_info_translated (&diagnostic, msg, ap,
    1117                 :             :                                   richloc, dlevel);
    1118                 :          28 :   diagnostic_override_option_index (&diagnostic,
    1119                 :             :                                     cb_cpp_diagnostic_cpp_option (reason));
    1120                 :          14 :   ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
    1121                 :          14 :   if (level == CPP_DL_WARNING_SYSHDR)
    1122                 :           6 :     global_dc->m_warn_system_headers = save_warn_system_headers;
    1123                 :          14 :   return ret;
    1124                 :          14 : }
    1125                 :             : 
    1126                 :             : /* Callback called when -fworking-director and -E to emit working
    1127                 :             :    directory in cpp output file.  */
    1128                 :             : 
    1129                 :             : void
    1130                 :           0 : pp_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
    1131                 :             : {
    1132                 :           0 :   size_t to_file_len = strlen (dir);
    1133                 :           0 :   unsigned char *to_file_quoted =
    1134                 :           0 :      (unsigned char *) alloca (to_file_len * 4 + 1);
    1135                 :           0 :   unsigned char *p;
    1136                 :             : 
    1137                 :             :   /* cpp_quote_string does not nul-terminate, so we have to do it ourselves.  */
    1138                 :           0 :   p = cpp_quote_string (to_file_quoted, (const unsigned char *) dir, to_file_len);
    1139                 :           0 :   *p = '\0';
    1140                 :           0 :   fprintf (print.outf, "# 1 \"%s//\"\n", to_file_quoted);
    1141                 :           0 : }
    1142                 :             : 
    1143                 :             : /* Copy a #pragma directive to the preprocessed output.  */
    1144                 :             : static void
    1145                 :           0 : cb_def_pragma (cpp_reader *pfile, location_t line)
    1146                 :             : {
    1147                 :           0 :   maybe_print_line (line);
    1148                 :           0 :   fputs ("#pragma ", print.outf);
    1149                 :           0 :   cpp_output_line (pfile, print.outf);
    1150                 :           0 :   print.src_line++;
    1151                 :           0 : }
    1152                 :             : 
    1153                 :             : static void
    1154                 :           0 : cb_used_undef (cpp_reader *pfile ATTRIBUTE_UNUSED,
    1155                 :             :                location_t line ATTRIBUTE_UNUSED,
    1156                 :             :                cpp_hashnode *node)
    1157                 :             : {
    1158                 :           0 :   gfc_cpp_macro_queue *q;
    1159                 :           0 :   q = XNEW (gfc_cpp_macro_queue);
    1160                 :           0 :   q->macro = xstrdup ((const char *) NODE_NAME (node));
    1161                 :           0 :   q->next = cpp_undefine_queue;
    1162                 :           0 :   cpp_undefine_queue = q;
    1163                 :           0 : }
    1164                 :             : 
    1165                 :             : static void
    1166                 :           0 : dump_queued_macros (cpp_reader *pfile ATTRIBUTE_UNUSED)
    1167                 :             : {
    1168                 :           0 :   gfc_cpp_macro_queue *q;
    1169                 :             : 
    1170                 :             :   /* End the previous line of text.  */
    1171                 :           0 :   if (print.printed)
    1172                 :             :     {
    1173                 :           0 :       putc ('\n', print.outf);
    1174                 :           0 :       print.src_line++;
    1175                 :           0 :       print.printed = 0;
    1176                 :             :     }
    1177                 :             : 
    1178                 :           0 :   for (q = cpp_define_queue; q;)
    1179                 :             :     {
    1180                 :           0 :       gfc_cpp_macro_queue *oq;
    1181                 :           0 :       fputs ("#define ", print.outf);
    1182                 :           0 :       fputs (q->macro, print.outf);
    1183                 :           0 :       putc ('\n', print.outf);
    1184                 :           0 :       print.src_line++;
    1185                 :           0 :       oq = q;
    1186                 :           0 :       q = q->next;
    1187                 :           0 :       free (oq->macro);
    1188                 :           0 :       free (oq);
    1189                 :             :     }
    1190                 :           0 :   cpp_define_queue = NULL;
    1191                 :           0 :   for (q = cpp_undefine_queue; q;)
    1192                 :             :     {
    1193                 :           0 :       gfc_cpp_macro_queue *oq;
    1194                 :           0 :       fprintf (print.outf, "#undef %s\n", q->macro);
    1195                 :           0 :       print.src_line++;
    1196                 :           0 :       oq = q;
    1197                 :           0 :       q = q->next;
    1198                 :           0 :       free (oq->macro);
    1199                 :           0 :       free (oq);
    1200                 :             :     }
    1201                 :           0 :   cpp_undefine_queue = NULL;
    1202                 :           0 : }
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.