Commit 4a58aab6 by Neil Booth Committed by Neil Booth

cppinit.c: Update comments.

	* cppinit.c: Update comments.
	(cpp_reader_init): Make -imacro and -include use the standard
	#include "" search path.
	(do_includes): New function.

From-SVN: r37542
parent 18c07aaf
2000-11-18 Neil Booth <neilb@earthling.net>
* cppinit.c: Update comments.
(cpp_reader_init): Make -imacro and -include use the standard
#include "" search path.
(do_includes): New function.
2000-11-18 Ben Elliston <bje@redhat.com> 2000-11-18 Ben Elliston <bje@redhat.com>
* config/sh/crt1.asm (start_l): Move PC-relative move instruction * config/sh/crt1.asm (start_l): Move PC-relative move instruction
......
...@@ -30,7 +30,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -30,7 +30,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "mkdeps.h" #include "mkdeps.h"
#include "cppdefault.h" #include "cppdefault.h"
/* Predefined symbols, built-in macros, and the default include path. */ /* Predefined symbols, built-in macros, and the default include path. */
#ifndef GET_ENV_PATH_LIST #ifndef GET_ENV_PATH_LIST
#define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0) #define GET_ENV_PATH_LIST(VAR,NAME) do { (VAR) = getenv (NAME); } while (0)
...@@ -47,13 +47,10 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -47,13 +47,10 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#define INO_T_EQ(a, b) ((a) == (b)) #define INO_T_EQ(a, b) ((a) == (b))
#endif #endif
/* Internal structures and prototypes. */ /* Internal structures and prototypes. */
/* A `struct pending_option' remembers one -D, -A, -U, -include, or -imacros /* A `struct pending_option' remembers one -D, -A, -U, -include, or
switch. There are four lists: one for -D and -U, one for -A, one -imacros switch. */
for -include, one for -imacros. `undef' is set for -U, clear for
-D, ignored for the others.
(Future: add an equivalent of -U for -A) */
typedef void (* cl_directive_handler) PARAMS ((cpp_reader *, const char *)); typedef void (* cl_directive_handler) PARAMS ((cpp_reader *, const char *));
struct pending_option struct pending_option
...@@ -66,7 +63,7 @@ struct pending_option ...@@ -66,7 +63,7 @@ struct pending_option
/* The `pending' structure accumulates all the options that are not /* The `pending' structure accumulates all the options that are not
actually processed until we hit cpp_start_read. It consists of actually processed until we hit cpp_start_read. It consists of
several lists, one for each type of option. We keep both head and several lists, one for each type of option. We keep both head and
tail pointers for quick insertion. */ tail pointers for quick insertion. */
struct cpp_pending struct cpp_pending
{ {
struct pending_option *directive_head, *directive_tail; struct pending_option *directive_head, *directive_tail;
...@@ -105,7 +102,9 @@ struct file_name_list * remove_dup_dir PARAMS ((cpp_reader *, ...@@ -105,7 +102,9 @@ struct file_name_list * remove_dup_dir PARAMS ((cpp_reader *,
struct file_name_list * remove_dup_dirs PARAMS ((cpp_reader *, struct file_name_list * remove_dup_dirs PARAMS ((cpp_reader *,
struct file_name_list *)); struct file_name_list *));
static void merge_include_chains PARAMS ((cpp_reader *)); static void merge_include_chains PARAMS ((cpp_reader *));
static void do_includes PARAMS ((cpp_reader *,
struct pending_option *,
int));
static void initialize_dependency_output PARAMS ((cpp_reader *)); static void initialize_dependency_output PARAMS ((cpp_reader *));
static void initialize_standard_includes PARAMS ((cpp_reader *)); static void initialize_standard_includes PARAMS ((cpp_reader *));
static void new_pending_directive PARAMS ((struct cpp_pending *, static void new_pending_directive PARAMS ((struct cpp_pending *,
...@@ -116,7 +115,7 @@ static int opt_comp PARAMS ((const void *, const void *)); ...@@ -116,7 +115,7 @@ static int opt_comp PARAMS ((const void *, const void *));
#endif #endif
static int parse_option PARAMS ((const char *)); static int parse_option PARAMS ((const char *));
/* Fourth argument to append_include_chain: chain to use */ /* Fourth argument to append_include_chain: chain to use. */
enum { QUOTE = 0, BRACKET, SYSTEM, AFTER }; enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
/* If we have designated initializers (GCC >2.7) these tables can be /* If we have designated initializers (GCC >2.7) these tables can be
...@@ -124,10 +123,10 @@ enum { QUOTE = 0, BRACKET, SYSTEM, AFTER }; ...@@ -124,10 +123,10 @@ enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
runtime. */ runtime. */
#if HAVE_DESIGNATED_INITIALIZERS #if HAVE_DESIGNATED_INITIALIZERS
#define init_IStable() /* nothing */ #define init_IStable() /* Nothing. */
#define ISTABLE __extension__ const U_CHAR _cpp_IStable[UCHAR_MAX + 1] = { #define ISTABLE __extension__ const U_CHAR _cpp_IStable[UCHAR_MAX + 1] = {
#define init_trigraph_map() /* nothing */ #define init_trigraph_map() /* Nothing. */
#define TRIGRAPH_MAP \ #define TRIGRAPH_MAP \
__extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = { __extension__ const U_CHAR _cpp_trigraph_map[UCHAR_MAX + 1] = {
...@@ -343,7 +342,7 @@ remove_dup_dirs (pfile, head) ...@@ -343,7 +342,7 @@ remove_dup_dirs (pfile, head)
bracket_include path. bracket_include path.
For the future: Check if the directory is empty (but For the future: Check if the directory is empty (but
how?) and possibly preload the include hash. */ how?) and possibly preload the include hash. */
static void static void
merge_include_chains (pfile) merge_include_chains (pfile)
...@@ -452,7 +451,7 @@ cpp_reader_init (pfile) ...@@ -452,7 +451,7 @@ cpp_reader_init (pfile)
CPP_OPTION (pfile, pending) = CPP_OPTION (pfile, pending) =
(struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending)); (struct cpp_pending *) xcalloc (1, sizeof (struct cpp_pending));
/* Initialize comment saving state. */ /* Initialize lexer state. */
pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments); pfile->state.save_comments = ! CPP_OPTION (pfile, discard_comments);
/* Indicate date and time not yet calculated. */ /* Indicate date and time not yet calculated. */
...@@ -475,7 +474,7 @@ cpp_reader_init (pfile) ...@@ -475,7 +474,7 @@ cpp_reader_init (pfile)
/* Macro pool initially 8K. Aligned, permanent pool. */ /* Macro pool initially 8K. Aligned, permanent pool. */
_cpp_init_pool (&pfile->macro_pool, 8 * 1024, 0, 0); _cpp_init_pool (&pfile->macro_pool, 8 * 1024, 0, 0);
/* Start with temporary pool. */ /* Start with temporary pool. */
pfile->string_pool = &pfile->temp_string_pool; pfile->string_pool = &pfile->temp_string_pool;
_cpp_init_hashtable (pfile); _cpp_init_hashtable (pfile);
...@@ -823,18 +822,42 @@ initialize_standard_includes (pfile) ...@@ -823,18 +822,42 @@ initialize_standard_includes (pfile)
|| (CPP_OPTION (pfile, cplusplus) || (CPP_OPTION (pfile, cplusplus)
&& !CPP_OPTION (pfile, no_standard_cplusplus_includes))) && !CPP_OPTION (pfile, no_standard_cplusplus_includes)))
{ {
/* XXX Potential memory leak! */
char *str = xstrdup (update_path (p->fname, p->component)); char *str = xstrdup (update_path (p->fname, p->component));
append_include_chain (pfile, str, SYSTEM, p->cxx_aware); append_include_chain (pfile, str, SYSTEM, p->cxx_aware);
} }
} }
} }
/* This is called after options have been processed. /* Handles -imacro and -include from the command line. */
* Check options for consistency, and setup for processing input static void
* from the file named FNAME. (Use standard input if FNAME==NULL.) do_includes (pfile, p, scan)
* Return 1 on success, 0 on failure. cpp_reader *pfile;
*/ struct pending_option *p;
int scan;
{
while (p)
{
cpp_token header;
struct pending_option *q;
header.type = CPP_STRING;
header.val.str.text = (unsigned char *) p->arg;
header.val.str.len = strlen (p->arg);
/* Use the #include "" search path. */
_cpp_execute_include (pfile, &header, 0, 0);
if (scan)
cpp_scan_buffer_nooutput (pfile);
q = p->next;
free (p);
p = q;
}
}
/* This is called after options have been processed. Check options
for consistency, and setup for processing input from the file named
FNAME. (Use standard input if FNAME == NULL.) Return 1 on success,
0 on failure. */
int int
cpp_start_read (pfile, fname) cpp_start_read (pfile, fname)
...@@ -918,27 +941,12 @@ cpp_start_read (pfile, fname) ...@@ -918,27 +941,12 @@ cpp_start_read (pfile, fname)
pfile->done_initializing = 1; pfile->done_initializing = 1;
/* The -imacros files can be scanned now, but the -include files /* The -imacros files can be scanned now, but the -include files
have to be pushed onto the include stack and processed later, have to be pushed onto the buffer stack and processed later,
in the main loop calling cpp_get_token. */ otherwise cppmain.c won't see the tokens. include_head was built
up as a stack, and popping this stack onto the buffer stack means
p = CPP_OPTION (pfile, pending)->imacros_head; we preserve the order of the command line. */
while (p) do_includes (pfile, CPP_OPTION (pfile, pending)->imacros_head, 1);
{ do_includes (pfile, CPP_OPTION (pfile, pending)->include_head, 0);
if (cpp_read_file (pfile, p->arg))
cpp_scan_buffer_nooutput (pfile);
q = p->next;
free (p);
p = q;
}
p = CPP_OPTION (pfile, pending)->include_head;
while (p)
{
cpp_read_file (pfile, p->arg);
q = p->next;
free (p);
p = q;
}
free (CPP_OPTION (pfile, pending)); free (CPP_OPTION (pfile, pending));
CPP_OPTION (pfile, pending) = NULL; CPP_OPTION (pfile, pending) = NULL;
...@@ -949,7 +957,7 @@ cpp_start_read (pfile, fname) ...@@ -949,7 +957,7 @@ cpp_start_read (pfile, fname)
/* This is called at the end of preprocessing. It pops the /* This is called at the end of preprocessing. It pops the
last buffer and writes dependency output. It should also last buffer and writes dependency output. It should also
clear macro definitions, such that you could call cpp_start_read clear macro definitions, such that you could call cpp_start_read
with a new filename to restart processing. */ with a new filename to restart processing. */
void void
cpp_finish (pfile) cpp_finish (pfile)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -1118,7 +1126,7 @@ static const struct cl_option cl_options[] = ...@@ -1118,7 +1126,7 @@ static const struct cl_option cl_options[] =
e.g. -iwithprefix and -iwithprefixbefore. Moreover, we want to e.g. -iwithprefix and -iwithprefixbefore. Moreover, we want to
accept options beginning with -g and -W that we do not recognise, accept options beginning with -g and -W that we do not recognise,
but not to swallow any subsequent command line argument; these are but not to swallow any subsequent command line argument; these are
handled as special cases in cpp_handle_option */ handled as special cases in cpp_handle_option. */
static int static int
parse_option (input) parse_option (input)
const char *input; const char *input;
...@@ -1149,13 +1157,13 @@ parse_option (input) ...@@ -1149,13 +1157,13 @@ parse_option (input)
we may match a later option or we may have been passed the we may match a later option or we may have been passed the
argument. The longest possible option match succeeds. argument. The longest possible option match succeeds.
If the option takes no arguments we have not matched and If the option takes no arguments we have not matched and
continue the search (e.g. input="stdc++" match was "stdc") */ continue the search (e.g. input="stdc++" match was "stdc"). */
mn = md + 1; mn = md + 1;
if (cl_options[md].msg) if (cl_options[md].msg)
{ {
/* Scan forwards. If we get an exact match, return it. /* Scan forwards. If we get an exact match, return it.
Otherwise, return the longest option-accepting match. Otherwise, return the longest option-accepting match.
This loops no more than twice with current options */ This loops no more than twice with current options. */
mx = md; mx = md;
for (; mn < N_OPTS; mn++) for (; mn < N_OPTS; mn++)
{ {
...@@ -1204,7 +1212,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1204,7 +1212,7 @@ cpp_handle_option (pfile, argc, argv)
int opt_index; int opt_index;
const char *arg = 0; const char *arg = 0;
/* Skip over '-' */ /* Skip over '-'. */
opt_index = parse_option (&argv[i][1]); opt_index = parse_option (&argv[i][1]);
if (opt_index < 0) if (opt_index < 0)
return i; return i;
...@@ -1216,7 +1224,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1216,7 +1224,7 @@ cpp_handle_option (pfile, argc, argv)
/* Yuk. Special case for -g and -W as they must not swallow /* Yuk. Special case for -g and -W as they must not swallow
up any following argument. If this becomes common, add up any following argument. If this becomes common, add
another field to the cl_options table */ another field to the cl_options table. */
if (arg[0] == '\0' && !(opt_code == OPT_g || opt_code == OPT_W)) if (arg[0] == '\0' && !(opt_code == OPT_g || opt_code == OPT_W))
{ {
arg = argv[++i]; arg = argv[++i];
...@@ -1230,7 +1238,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1230,7 +1238,7 @@ cpp_handle_option (pfile, argc, argv)
switch (opt_code) switch (opt_code)
{ {
case N_OPTS: /* shut GCC up */ case N_OPTS: /* Shut GCC up. */
break; break;
case OPT_fleading_underscore: case OPT_fleading_underscore:
CPP_OPTION (pfile, user_label_prefix) = "_"; CPP_OPTION (pfile, user_label_prefix) = "_";
...@@ -1263,7 +1271,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1263,7 +1271,7 @@ cpp_handle_option (pfile, argc, argv)
case OPT_w: case OPT_w:
CPP_OPTION (pfile, inhibit_warnings) = 1; CPP_OPTION (pfile, inhibit_warnings) = 1;
break; break;
case OPT_g: /* Silently ignore anything but -g3 */ case OPT_g: /* Silently ignore anything but -g3. */
if (!strcmp(&argv[i][2], "3")) if (!strcmp(&argv[i][2], "3"))
CPP_OPTION (pfile, debug_output) = 1; CPP_OPTION (pfile, debug_output) = 1;
break; break;
...@@ -1286,7 +1294,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1286,7 +1294,7 @@ cpp_handle_option (pfile, argc, argv)
case OPT_P: case OPT_P:
CPP_OPTION (pfile, no_line_commands) = 1; CPP_OPTION (pfile, no_line_commands) = 1;
break; break;
case OPT_dollar: /* Don't include $ in identifiers. */ case OPT_dollar: /* Don't include $ in identifiers. */
CPP_OPTION (pfile, dollars_in_ident) = 0; CPP_OPTION (pfile, dollars_in_ident) = 0;
break; break;
case OPT_H: case OPT_H:
...@@ -1423,7 +1431,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1423,7 +1431,7 @@ cpp_handle_option (pfile, argc, argv)
CPP_OPTION (pfile, verbose) = 1; CPP_OPTION (pfile, verbose) = 1;
break; break;
case OPT_stdin_stdout: case OPT_stdin_stdout:
/* JF handle '-' as file name meaning stdin or stdout */ /* JF handle '-' as file name meaning stdin or stdout. */
if (CPP_OPTION (pfile, in_fname) == NULL) if (CPP_OPTION (pfile, in_fname) == NULL)
CPP_OPTION (pfile, in_fname) = ""; CPP_OPTION (pfile, in_fname) = "";
else if (CPP_OPTION (pfile, out_fname) == NULL) else if (CPP_OPTION (pfile, out_fname) == NULL)
...@@ -1432,7 +1440,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1432,7 +1440,7 @@ cpp_handle_option (pfile, argc, argv)
case OPT_d: case OPT_d:
/* Args to -d specify what parts of macros to dump. /* Args to -d specify what parts of macros to dump.
Silently ignore unrecognised options; they may Silently ignore unrecognised options; they may
be aimed at the compiler proper. */ be aimed at the compiler proper. */
{ {
char c; char c;
...@@ -1479,9 +1487,9 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1479,9 +1487,9 @@ cpp_handle_option (pfile, argc, argv)
else else
CPP_OPTION (pfile, print_deps) = 1; CPP_OPTION (pfile, print_deps) = 1;
/* For -MD and -MMD options, write deps on file named by next arg */ /* For -MD and -MMD, write deps on file named by next arg. */
/* For -M and -MM, write deps on standard output /* For -M and -MM, write deps on standard output and
and suppress the usual output. */ suppress the usual output. */
if (opt_code == OPT_MD || opt_code == OPT_MMD) if (opt_code == OPT_MD || opt_code == OPT_MMD)
CPP_OPTION (pfile, deps_file) = arg; CPP_OPTION (pfile, deps_file) = arg;
else else
...@@ -1549,7 +1557,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1549,7 +1557,7 @@ cpp_handle_option (pfile, argc, argv)
break; break;
case OPT_isystem: case OPT_isystem:
/* Add directory to beginning of system include path, as a system /* Add directory to beginning of system include path, as a system
include directory. */ include directory. */
append_include_chain (pfile, xstrdup (arg), SYSTEM, 0); append_include_chain (pfile, xstrdup (arg), SYSTEM, 0);
break; break;
case OPT_include: case OPT_include:
...@@ -1613,7 +1621,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1613,7 +1621,7 @@ cpp_handle_option (pfile, argc, argv)
append_include_chain (pfile, xstrdup (arg), AFTER, 0); append_include_chain (pfile, xstrdup (arg), AFTER, 0);
break; break;
case OPT_W: case OPT_W:
/* Silently ignore unrecognised options */ /* Silently ignore unrecognised options. */
if (!strcmp (argv[i], "-Wall")) if (!strcmp (argv[i], "-Wall"))
{ {
CPP_OPTION (pfile, warn_trigraphs) = 1; CPP_OPTION (pfile, warn_trigraphs) = 1;
......
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