Commit 22bbceaf by Per Bothner

Bunch of little fixes. See ChangeLog.

From-SVN: r9360
parent 6272a449
...@@ -296,6 +296,7 @@ static void free_token_list (); ...@@ -296,6 +296,7 @@ static void free_token_list ();
static int safe_read (); static int safe_read ();
static void push_macro_expansion PARAMS ((cpp_reader *, static void push_macro_expansion PARAMS ((cpp_reader *,
U_CHAR*, int, HASHNODE*)); U_CHAR*, int, HASHNODE*));
static struct cpp_pending *nreverse_pending PARAMS ((struct cpp_pending*));
extern char *xrealloc (); extern char *xrealloc ();
extern char *xcalloc (); extern char *xcalloc ();
static char *savestring (); static char *savestring ();
...@@ -1958,10 +1959,10 @@ cpp_push_buffer (pfile, buffer, length) ...@@ -1958,10 +1959,10 @@ cpp_push_buffer (pfile, buffer, length)
long length; long length;
{ {
#ifdef STATIC_BUFFERS #ifdef STATIC_BUFFERS
register cpp_buffer *buf; register cpp_buffer *buf = CPP_BUFFER (pfile);
if (buf == pfile->buffer_stack) if (buf == pfile->buffer_stack)
fatal ("macro or `#include' recursion too deep"); fatal ("macro or `#include' recursion too deep");
buf = CPP_BUFFER (pfile) - 1; buf--;
bzero ((char *) buf, sizeof (cpp_buffer)); bzero ((char *) buf, sizeof (cpp_buffer));
CPP_BUFFER (pfile) = buf; CPP_BUFFER (pfile) = buf;
#else #else
...@@ -2139,9 +2140,9 @@ cpp_buffer* ...@@ -2139,9 +2140,9 @@ cpp_buffer*
cpp_file_buffer (pfile) cpp_file_buffer (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cpp_buffer *ip; cpp_buffer *ip = CPP_BUFFER (pfile);
for (ip = CPP_BUFFER (pfile); ip != NULL; ip = CPP_PREV_BUFFER (ip)) for ( ; ip != CPP_NULL_BUFFER (pfile); ip = CPP_PREV_BUFFER (ip))
if (ip->fname != NULL) if (ip->fname != NULL)
return ip; return ip;
return NULL; return NULL;
...@@ -3580,6 +3581,7 @@ do_include (pfile, keyword, unused1, unused2) ...@@ -3580,6 +3581,7 @@ do_include (pfile, keyword, unused1, unused2)
#endif #endif
/* Actually process the file */ /* Actually process the file */
cpp_push_buffer (pfile, NULL, 0);
if (finclude (pfile, f, fname, is_system_include (pfile, fname), if (finclude (pfile, f, fname, is_system_include (pfile, fname),
searchptr != dsp ? searchptr : SELF_DIR_DUMMY)) searchptr != dsp ? searchptr : SELF_DIR_DUMMY))
{ {
...@@ -4639,7 +4641,7 @@ validate_else (pfile, directive) ...@@ -4639,7 +4641,7 @@ validate_else (pfile, directive)
"text following `%s' violates ANSI standard", directive); "text following `%s' violates ANSI standard", directive);
} }
/* Get the next token, and add it to the tex in pfile->token_buffer. /* Get the next token, and add it to the text in pfile->token_buffer.
Return the kind of token we got. */ Return the kind of token we got. */
...@@ -5622,7 +5624,9 @@ open_include_file (filename, searchptr) ...@@ -5622,7 +5624,9 @@ open_include_file (filename, searchptr)
function above). function above).
DIRPTR is the link in the dir path through which this file was found, DIRPTR is the link in the dir path through which this file was found,
or 0 if the file name was absolute or via the current directory. or 0 if the file name was absolute or via the current directory.
Return 1 on success, 0 on failure. */ Return 1 on success, 0 on failure.
The caller is responsible for the cpp_push_buffer. */
static int static int
finclude (pfile, f, fname, system_header_p, dirptr) finclude (pfile, f, fname, system_header_p, dirptr)
...@@ -5639,18 +5643,15 @@ finclude (pfile, f, fname, system_header_p, dirptr) ...@@ -5639,18 +5643,15 @@ finclude (pfile, f, fname, system_header_p, dirptr)
cpp_buffer *fp; /* For input stack frame */ cpp_buffer *fp; /* For input stack frame */
int missing_newline = 0; int missing_newline = 0;
#if 0
CHECK_DEPTH (return 0;);
#endif
if (file_size_and_mode (f, &st_mode, &st_size) < 0) if (file_size_and_mode (f, &st_mode, &st_size) < 0)
{ {
cpp_perror_with_name (pfile, fname); cpp_perror_with_name (pfile, fname);
close (f); close (f);
cpp_pop_buffer (pfile);
return 0; return 0;
} }
fp = cpp_push_buffer (pfile, NULL, 0); fp = CPP_BUFFER (pfile);
fp->nominal_fname = fp->fname = fname; fp->nominal_fname = fp->fname = fname;
#if 0 #if 0
fp->length = 0; fp->length = 0;
...@@ -5755,6 +5756,7 @@ push_parse_file (pfile, fname) ...@@ -5755,6 +5756,7 @@ push_parse_file (pfile, fname)
struct cpp_pending *pend; struct cpp_pending *pend;
char *p; char *p;
int f; int f;
cpp_buffer *fp;
/* The code looks at the defaults through this pointer, rather than through /* The code looks at the defaults through this pointer, rather than through
the constant structure above. This pointer gets changed if an environment the constant structure above. This pointer gets changed if an environment
...@@ -5774,16 +5776,13 @@ push_parse_file (pfile, fname) ...@@ -5774,16 +5776,13 @@ push_parse_file (pfile, fname)
/* Now that dollars_in_ident is known, initialize is_idchar. */ /* Now that dollars_in_ident is known, initialize is_idchar. */
initialize_char_syntax (opts); initialize_char_syntax (opts);
#if 0
/* Do partial setup of input buffer for the sake of generating /* Do partial setup of input buffer for the sake of generating
early #line directives (when -g is in effect). */ early #line directives (when -g is in effect). */
fp = cpp_push_buffer (pfile, NULL, 0);
fp = &instack[++indepth]; if (opts->in_fname == NULL)
if (in_fname == NULL) opts->in_fname = "";
in_fname = ""; fp->nominal_fname = fp->fname = opts->in_fname;
fp->nominal_fname = fp->fname = in_fname;
fp->lineno = 0; fp->lineno = 0;
#endif
/* Install __LINE__, etc. Must follow initialize_char_syntax /* Install __LINE__, etc. Must follow initialize_char_syntax
and option processing. */ and option processing. */
...@@ -5865,40 +5864,30 @@ push_parse_file (pfile, fname) ...@@ -5865,40 +5864,30 @@ push_parse_file (pfile, fname)
/* Do -U's, -D's and -A's in the order they were seen. */ /* Do -U's, -D's and -A's in the order they were seen. */
/* First reverse the list. */ /* First reverse the list. */
{ opts->pending = nreverse_pending (opts->pending);
struct cpp_pending *prev = 0, *next;
for (pend = opts->pending; pend; pend = next)
{
next = pend->next;
pend->next = prev;
prev = pend;
}
opts->pending = prev;
for (pend = opts->pending; pend; pend = pend->next) for (pend = opts->pending; pend; pend = pend->next)
{ {
if (pend->cmd != NULL && pend->cmd[0] == '-') if (pend->cmd != NULL && pend->cmd[0] == '-')
{ {
switch (pend->cmd[1]) switch (pend->cmd[1])
{ {
case 'U': case 'U':
if (opts->debug_output) if (opts->debug_output)
output_line_command (pfile, 0, same_file); output_line_command (pfile, 0, same_file);
do_undef (pfile, NULL, pend->arg, pend->arg + strlen (pend->arg)); do_undef (pfile, NULL, pend->arg, pend->arg + strlen (pend->arg));
break; break;
case 'D': case 'D':
if (opts->debug_output) if (opts->debug_output)
output_line_command (pfile, 0, same_file); output_line_command (pfile, 0, same_file);
make_definition (pfile, pend->arg); make_definition (pfile, pend->arg);
break; break;
case 'A': case 'A':
make_assertion (pfile, "-A", pend->arg); make_assertion (pfile, "-A", pend->arg);
break; break;
} }
} }
} }
opts->pending = NULL;
}
opts->done_initializing = 1; opts->done_initializing = 1;
...@@ -6054,6 +6043,7 @@ push_parse_file (pfile, fname) ...@@ -6054,6 +6043,7 @@ push_parse_file (pfile, fname)
cpp_perror_with_name (pfile, pend->arg); cpp_perror_with_name (pfile, pend->arg);
return FAILURE_EXIT_CODE; return FAILURE_EXIT_CODE;
} }
cpp_push_buffer (pfile, NULL, 0);
finclude (pfile, fd, pend->arg, 0, NULL_PTR); finclude (pfile, fd, pend->arg, 0, NULL_PTR);
cpp_scan_buffer (pfile); cpp_scan_buffer (pfile);
} }
...@@ -6203,9 +6193,11 @@ push_parse_file (pfile, fname) ...@@ -6203,9 +6193,11 @@ push_parse_file (pfile, fname)
trigraph_pcp (fp); trigraph_pcp (fp);
#endif #endif
/* Scan the -include files before the main input. */ /* Scan the -include files before the main input.
We push these in reverse order, so that the first one is handled first. */
pfile->no_record_file++; pfile->no_record_file++;
opts->pending = nreverse_pending (opts->pending);
for (pend = opts->pending; pend; pend = pend->next) for (pend = opts->pending; pend; pend = pend->next)
{ {
if (pend->cmd != NULL && strcmp (pend->cmd, "-include") == 0) if (pend->cmd != NULL && strcmp (pend->cmd, "-include") == 0)
...@@ -6216,8 +6208,8 @@ push_parse_file (pfile, fname) ...@@ -6216,8 +6208,8 @@ push_parse_file (pfile, fname)
cpp_perror_with_name (pfile, pend->arg); cpp_perror_with_name (pfile, pend->arg);
return FAILURE_EXIT_CODE; return FAILURE_EXIT_CODE;
} }
cpp_push_buffer (pfile, NULL, 0);
finclude (pfile, fd, pend->arg, 0, NULL_PTR); finclude (pfile, fd, pend->arg, 0, NULL_PTR);
cpp_scan_buffer (pfile);
} }
} }
pfile->no_record_file--; pfile->no_record_file--;
...@@ -6268,6 +6260,21 @@ init_parse_file (pfile) ...@@ -6268,6 +6260,21 @@ init_parse_file (pfile)
pfile->buffer = CPP_NULL_BUFFER(pfile); pfile->buffer = CPP_NULL_BUFFER(pfile);
} }
static struct cpp_pending *
nreverse_pending (list)
struct cpp_pending *list;
{
register struct cpp_pending *prev = 0, *next, *pend;
for (pend = list; pend; pend = next)
{
next = pend->next;
pend->next = prev;
prev = pend;
}
return prev;
}
static void static void
push_pending (pfile, cmd, arg) push_pending (pfile, cmd, arg)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -7499,7 +7506,7 @@ cpp_error_from_errno (pfile, name) ...@@ -7499,7 +7506,7 @@ cpp_error_from_errno (pfile, name)
if (ip != NULL) if (ip != NULL)
cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1); cpp_file_line_for_message (pfile, ip->nominal_fname, ip->lineno, -1);
cpp_message (pfile, 1, "%s: %s\n", name, my_strerror (errno)); cpp_message (pfile, 1, "%s: %s", name, my_strerror (errno));
} }
void void
...@@ -7507,7 +7514,7 @@ cpp_perror_with_name (pfile, name) ...@@ -7507,7 +7514,7 @@ cpp_perror_with_name (pfile, name)
cpp_reader *pfile; cpp_reader *pfile;
char *name; char *name;
{ {
cpp_message (pfile, 1, "%s: %s: %s\n", progname, name, my_strerror (errno)); cpp_message (pfile, 1, "%s: %s: %s", progname, name, my_strerror (errno));
} }
/* TODO: /* TODO:
...@@ -7525,8 +7532,4 @@ cpp_perror_with_name (pfile, name) ...@@ -7525,8 +7532,4 @@ cpp_perror_with_name (pfile, name)
* Support for trigraphs. * Support for trigraphs.
* *
* Support -dM flag (dump_all_macros). * Support -dM flag (dump_all_macros).
*
* -include should be made to return results incrementally.
* (current implementation only works when cpp is used as main program)
*
*/ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment