fix md include file/line tracking
Richard Henderson
rth@redhat.com
Sun May 19 18:55:00 GMT 2002
I finally got annoyed by includes messing up the error messages.
r~
* gensupport.c (init_include_reader): Merge into ...
(process_include): ... here. Simplify composite path creation.
Plug memory leaks. Fix file/line number tracking. Do not
process_define_cond_exec. Return void.
(process_rtx): Don't check process_include return value.
Index: gensupport.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gensupport.c,v
retrieving revision 1.30
diff -c -p -d -r1.30 gensupport.c
*** gensupport.c 12 May 2002 18:43:33 -0000 1.30
--- gensupport.c 20 May 2002 01:13:51 -0000
*************** static const char *alter_output_for_insn
*** 97,105 ****
int, int));
static void process_one_cond_exec PARAMS ((struct queue_elem *));
static void process_define_cond_exec PARAMS ((void));
! static int process_include PARAMS ((rtx, int));
static char *save_string PARAMS ((const char *, int));
- static int init_include_reader PARAMS ((FILE *));
void
message_with_line VPARAMS ((int lineno, const char *msg, ...))
--- 97,104 ----
int, int));
static void process_one_cond_exec PARAMS ((struct queue_elem *));
static void process_define_cond_exec PARAMS ((void));
! static void process_include PARAMS ((rtx, int));
static char *save_string PARAMS ((const char *, int));
void
message_with_line VPARAMS ((int lineno, const char *msg, ...))
*************** remove_constraints (part)
*** 179,320 ****
}
}
- /* The entry point for initializing the reader. */
-
- static int
- init_include_reader (inf)
- FILE *inf;
- {
- int c;
-
- errors = 0;
-
- /* Read the entire file. */
- while (1)
- {
- rtx desc;
- int lineno;
-
- c = read_skip_spaces (inf);
- if (c == EOF)
- break;
-
- ungetc (c, inf);
- lineno = read_rtx_lineno;
- desc = read_rtx (inf);
- process_rtx (desc, lineno);
- }
- fclose (inf);
-
- /* Process define_cond_exec patterns. */
- if (define_cond_exec_queue != NULL)
- process_define_cond_exec ();
-
- return errors ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE;
- }
-
/* Process an include file assuming that it lives in gcc/config/{target}/
! if the include looks line (include "file" ) */
! static int
process_include (desc, lineno)
rtx desc;
int lineno;
{
const char *filename = XSTR (desc, 0);
! char *pathname = NULL;
FILE *input_file;
- char *fname = NULL;
- struct file_name_list *stackp;
- int flen;
-
- stackp = first_dir_md_include;
! /* If specified file name is absolute, just open it. */
! if (IS_ABSOLUTE_PATHNAME (filename) || !stackp)
{
! if (base_dir)
! {
! pathname = xmalloc (strlen (base_dir) + strlen (filename) + 1);
! pathname = strcpy (pathname, base_dir);
! strcat (pathname, filename);
! strcat (pathname, "\0");
! }
! else
! {
! pathname = xstrdup (filename);
! }
! read_rtx_filename = pathname;
! input_file = fopen (pathname, "r");
! if (input_file == 0)
{
! perror (pathname);
! return FATAL_EXIT_CODE;
}
}
- else if (stackp)
- {
-
- flen = strlen (filename);
! fname = (char *) xmalloc (max_include_len + flen + 2);
!
! /* + 2 above for slash and terminating null. */
! /* Search directory path, trying to open the file.
! Copy each filename tried into FNAME. */
! for (; stackp; stackp = stackp->next)
! {
! if (stackp->fname)
! {
! strcpy (fname, stackp->fname);
! strcat (fname, "/");
! fname[strlen (fname) + flen] = 0;
! }
! else
! {
! fname[0] = 0;
! }
! strncat (fname, (const char *) filename, flen);
! read_rtx_filename = fname;
! input_file = fopen (fname, "r");
! if (input_file != NULL)
! break;
! }
! if (stackp == NULL)
! {
! if (strchr (fname, '/') == NULL || strchr (fname, '\\' ) || base_dir)
! {
! if (base_dir)
! {
! pathname =
! xmalloc (strlen (base_dir) + strlen (filename) + 1);
! pathname = strcpy (pathname, base_dir);
! strcat (pathname, filename);
! strcat (pathname, "\0");
! }
! else
! pathname = xstrdup (filename);
! }
! read_rtx_filename = pathname;
! input_file = fopen (pathname, "r");
! if (input_file == 0)
! {
! perror (filename);
! return FATAL_EXIT_CODE;
! }
! }
}
! if (init_include_reader (input_file) == FATAL_EXIT_CODE)
! message_with_line (lineno, "read errors found in include file %s\n", pathname);
! if (fname)
! free (fname);
! return SUCCESS_EXIT_CODE;
}
/* Process a top level rtx in some way, queueing as appropriate. */
--- 178,258 ----
}
}
/* Process an include file assuming that it lives in gcc/config/{target}/
! if the include looks line (include "file"). */
!
! static void
process_include (desc, lineno)
rtx desc;
int lineno;
{
const char *filename = XSTR (desc, 0);
! const char *old_filename;
! int old_lineno;
! char *pathname;
FILE *input_file;
! /* If specified file name is absolute, skip the include stack. */
! if (! IS_ABSOLUTE_PATHNAME (filename))
{
! struct file_name_list *stackp;
! /* Search directory path, trying to open the file. */
! for (stackp = first_dir_md_include; stackp; stackp = stackp->next)
{
! static const char sep[2] = { DIR_SEPARATOR, '\0' };
!
! pathname = concat (stackp->fname, sep, filename, NULL);
! input_file = fopen (pathname, "r");
! if (input_file != NULL)
! goto success;
! free (pathname);
}
}
! if (base_dir)
! pathname = concat (base_dir, filename, NULL);
! else
! pathname = xstrdup (filename);
! input_file = fopen (pathname, "r");
! if (input_file == NULL)
! {
! free (pathname);
! message_with_line (lineno, "include file `%s' not found", filename);
! errors = 1;
! return;
! }
! success:
! /* Save old cursor; setup new for the new file. Note that "lineno" the
! argument to this function is the beginning of the include statement,
! while read_rtx_lineno has already been advanced. */
! old_filename = read_rtx_filename;
! old_lineno = read_rtx_lineno;
! read_rtx_filename = pathname;
! read_rtx_lineno = 1;
! /* Read the entire file. */
! while (1)
! {
! rtx desc;
! int c;
! c = read_skip_spaces (input_file);
! if (c == EOF)
! break;
+ ungetc (c, input_file);
+ lineno = read_rtx_lineno;
+ desc = read_rtx (input_file);
+ process_rtx (desc, lineno);
}
! read_rtx_filename = old_filename;
! read_rtx_lineno = old_lineno;
! fclose (input_file);
! free (pathname);
}
/* Process a top level rtx in some way, queueing as appropriate. */
*************** process_rtx (desc, lineno)
*** 339,350 ****
break;
case INCLUDE:
! if (process_include (desc, lineno) == FATAL_EXIT_CODE)
! {
! const char *filename = XSTR (desc, 0);
! message_with_line (lineno, "include file at %s not found\n",
! filename);
! }
break;
case DEFINE_INSN_AND_SPLIT:
--- 277,283 ----
break;
case INCLUDE:
! process_include (desc, lineno);
break;
case DEFINE_INSN_AND_SPLIT:
More information about the Gcc-patches
mailing list