This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: patch for cpplib: -include


Hi Zack,

I have only one comment and it's a nit, but I think the options in toplev.c should
be kept alphabetically within each section (disregarding any 'no' prefix). It looks
like the single letter ones go first followed by the longer ones. I know that
-remap is out of order already and it should be fixed too.

Other than that, I approve of this patch.

Dave

Zack Weinberg wrote:

> This patch fixes a number of bugs in cpplib's handling of the -include
> and -imacros switches.  Specifically:  the files were processed in the
> wrong order, #line directives in the output were incorrect, and cc1's
> option parsing didn't know about the switches.
>
> zw
>
> 1998-09-25 19:49 -0400  Zack Weinberg  <zack@rabi.phys.columbia.edu>
>
>         * toplev.c (documented_lang_options): Recognize -include,
>         -imacros, -iwithprefix, -iwithprefixbefore.
>         * cpplib.c (cpp_start_read): Process -imacros and -include
>         switches at the same time and in command-line order, after
>         initializing the dependency-output code.  Emit properly nested
>         #line directives for them.  Emit a #line for the main file
>         before processing these switches, and don't do it again
>         afterward.
>
> ============================================================
> Index: gcc/toplev.c
> --- gcc/toplev.c        1998/09/21 14:11:35     1.97
> +++ gcc/toplev.c        1998/09/25 23:46:01
> @@ -1040,8 +1040,12 @@
>    { "-D", "" },
>    { "-I", "" },
>    { "-U", "" },
> +  { "-include", "" },
> +  { "-imacros", "" },
>    { "-idirafter", "" },
>    { "-iprefix", "" },
> +  { "-iwithprefix", "" },
> +  { "-iwithprefixbefore", "" },
>    { "-isystem", "" },
>    { "-lang-c", "" },
>    { "-lang-c89", "" },
> ============================================================
> Index: gcc/cpplib.c
> --- gcc/cpplib.c        1998/09/21 00:56:46     1.32
> +++ gcc/cpplib.c        1998/09/25 23:46:02
> @@ -5972,29 +5972,6 @@
>      fprintf (stderr, "End of search list.\n");
>    }
>
> -  /* Scan the -imacros files before the main input.
> -     Much like #including them, but with no_output set
> -     so that only their macro definitions matter.  */
> -
> -  opts->no_output++; pfile->no_record_file++;
> -  for (pend = opts->pending;  pend;  pend = pend->next)
> -    {
> -      if (pend->cmd != NULL && strcmp (pend->cmd, "-imacros") == 0)
> -       {
> -         int fd = open (pend->arg, O_RDONLY, 0666);
> -         if (fd < 0)
> -           {
> -             cpp_perror_with_name (pfile, pend->arg);
> -             return 0;
> -           }
> -         if (!cpp_push_buffer (pfile, NULL, 0))
> -             return 0;
> -         finclude (pfile, fd, pend->arg, 0, NULL_PTR);
> -         cpp_scan_buffer (pfile);
> -       }
> -    }
> -  opts->no_output--; pfile->no_record_file--;
> -
>    /* Copy the entire contents of the main input file into
>       the stacked input buffer previously allocated for it.  */
>    if (fname == NULL || *fname == 0) {
> @@ -6139,24 +6116,48 @@
>      trigraph_pcp (fp);
>  #endif
>
> -  /* Scan the -include files before the main input.
> -   We push these in reverse order, so that the first one is handled first.  */
> +  /* Avoid a #line 0 if -include files are present. */
> +  CPP_BUFFER (pfile)->lineno = 1;
> +  output_line_command (pfile, 0, same_file);
> +
> +  /* Scan the -include and -imacros files before the main input. */
>
>    pfile->no_record_file++;
> -  opts->pending = nreverse_pending (opts->pending);
>    for (pend = opts->pending;  pend;  pend = pend->next)
>      {
> -      if (pend->cmd != NULL && strcmp (pend->cmd, "-include") == 0)
> -       {
> -         int fd = open (pend->arg, O_RDONLY, 0666);
> -         if (fd < 0)
> +      if (pend->cmd != NULL)
> +        {
> +         if (strcmp (pend->cmd, "-include") == 0)
> +           {
> +             int fd = open (pend->arg, O_RDONLY, 0666);
> +             if (fd < 0)
> +               {
> +                 cpp_perror_with_name (pfile, pend->arg);
> +                 return 0;
> +               }
> +             if (!cpp_push_buffer (pfile, NULL, 0))
> +               return 0;
> +             if (finclude (pfile, fd, pend->arg, 0, NULL_PTR))
> +               {
> +                 output_line_command (pfile, 0, enter_file);
> +                 cpp_scan_buffer (pfile);
> +               }
> +           }
> +         else if (strcmp (pend->cmd, "-imacros") == 0)
>             {
> -             cpp_perror_with_name (pfile, pend->arg);
> -             return 0;
> +             int fd = open (pend->arg, O_RDONLY, 0666);
> +             if (fd < 0)
> +               {
> +                 cpp_perror_with_name (pfile, pend->arg);
> +                 return 0;
> +               }
> +             opts->no_output++;
> +             if (!cpp_push_buffer (pfile, NULL, 0))
> +               return 0;
> +             if (finclude (pfile, fd, pend->arg, 0, NULL_PTR))
> +               cpp_scan_buffer (pfile);
> +             opts->no_output--;
>             }
> -         if (!cpp_push_buffer (pfile, NULL, 0))
> -           return 0;
> -         finclude (pfile, fd, pend->arg, 0, NULL_PTR);
>         }
>      }
>    pfile->no_record_file--;
> @@ -6182,8 +6183,7 @@
>      pedwarn ("file does not end in newline");
>
>  #endif
> -  if (finclude (pfile, f, fname, 0, NULL_PTR))
> -    output_line_command (pfile, 0, same_file);
> +  finclude (pfile, f, fname, 0, NULL_PTR);
>    return 1;
>  }





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]