Commit f4ff5a69 by Neil Booth Committed by Neil Booth

c-opts.c (deps_seen, [...]): New.

	* c-opts.c (deps_seen, deps_file, deferred_count, deferred_size,
	handle_deferred_opts, sanitize_cpp_opts, defer_opt,
	struct deferred_opt): New.
	(COMMAND_LINE_OPTIONS): Add -M*.
	(missing_arg): Update.
	(c_common_decode_option): Handle -M*.
	(c_common_post_options): Handle -M*.  Use sanitize_cpp_opts;
	don't call cpp_post_options.
	(c_common_finish, check_deps_environment_vars): Update.
	* cppfiles.c (stack_include_file, handle_missing_header): Update.
	* cpphash.h (CPP_PRINT_DEPS): Remove.
	* cppinit.c: Don't include version.h.
	(cpp_create_reader): Don't call deps_init.  Initialize
	warn_long_long.
	(cpp_read_main_file): Init deps if necessary.
	(cpp_destroy): Conditionally free deps.
	(cpp_finish): Update.
	(no_tgt): Remove.
	(COMMAND_LINE_OPTIONS, cpp_handle_option): Remove -M*.
	(cpp_post_options): Rename post_options.
	* cpplib.h (struct cpp_options): Remove some dependency options;
	move others to a new structure.
	(cpp_post_options): Remove.
	(cpp_finish): Comment.
	* fix-header.c (read_scan_file): Don't call cpp_post_options.
treelang:
	* treelang.c: Remove cpp_post_options.

From-SVN: r56239
parent 34116c2a
2002-08-13 Neil Booth <neil@daikokuya.co.uk>
* c-opts.c (deps_seen, deps_file, deferred_count, deferred_size,
handle_deferred_opts, sanitize_cpp_opts, defer_opt,
struct deferred_opt): New.
(COMMAND_LINE_OPTIONS): Add -M*.
(missing_arg): Update.
(c_common_decode_option): Handle -M*.
(c_common_post_options): Handle -M*. Use sanitize_cpp_opts;
don't call cpp_post_options.
(c_common_finish, check_deps_environment_vars): Update.
* cppfiles.c (stack_include_file, handle_missing_header): Update.
* cpphash.h (CPP_PRINT_DEPS): Remove.
* cppinit.c: Don't include version.h.
(cpp_create_reader): Don't call deps_init. Initialize
warn_long_long.
(cpp_read_main_file): Init deps if necessary.
(cpp_destroy): Conditionally free deps.
(cpp_finish): Update.
(no_tgt): Remove.
(COMMAND_LINE_OPTIONS, cpp_handle_option): Remove -M*.
(cpp_post_options): Rename post_options.
* cpplib.h (struct cpp_options): Remove some dependency options;
move others to a new structure.
(cpp_post_options): Remove.
(cpp_finish): Comment.
* fix-header.c (read_scan_file): Don't call cpp_post_options.
2002-08-12 Hans-Peter Nilsson <hp@bitrange.com> 2002-08-12 Hans-Peter Nilsson <hp@bitrange.com>
* config/mmix/mmix.md (define_constants): Add MMIX_rR_REGNUM. * config/mmix/mmix.md (define_constants): Add MMIX_rR_REGNUM.
......
...@@ -2211,7 +2211,7 @@ cpphash.o: cpphash.c $(CONFIG_H) $(LIBCPP_DEPS) ...@@ -2211,7 +2211,7 @@ cpphash.o: cpphash.c $(CONFIG_H) $(LIBCPP_DEPS)
cpptrad.o: cpptrad.c $(CONFIG_H) $(LIBCPP_DEPS) cpptrad.o: cpptrad.c $(CONFIG_H) $(LIBCPP_DEPS)
cppfiles.o: cppfiles.c $(CONFIG_H) $(LIBCPP_DEPS) $(SPLAY_TREE_H) mkdeps.h cppfiles.o: cppfiles.c $(CONFIG_H) $(LIBCPP_DEPS) $(SPLAY_TREE_H) mkdeps.h
cppinit.o: cppinit.c $(CONFIG_H) $(LIBCPP_DEPS) cppdefault.h \ cppinit.o: cppinit.c $(CONFIG_H) $(LIBCPP_DEPS) cppdefault.h \
mkdeps.h prefix.h version.h mkdeps.h prefix.h
cppdefault.o: cppdefault.c $(CONFIG_H) $(SYSTEM_H) cppdefault.h Makefile cppdefault.o: cppdefault.c $(CONFIG_H) $(SYSTEM_H) cppdefault.h Makefile
$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \ $(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
......
...@@ -31,6 +31,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA ...@@ -31,6 +31,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "diagnostic.h" #include "diagnostic.h"
#include "intl.h" #include "intl.h"
/* CPP's options. */
static cpp_options *cpp_opts; static cpp_options *cpp_opts;
/* Input filename. */ /* Input filename. */
...@@ -43,6 +44,15 @@ static FILE *out_stream; ...@@ -43,6 +44,15 @@ static FILE *out_stream;
/* Append dependencies to deps_file. */ /* Append dependencies to deps_file. */
static bool deps_append; static bool deps_append;
/* If dependency switches (-MF etc.) have been given. */
static bool deps_seen;
/* Dependency output file. */
static const char *deps_file;
/* Number of deferred options, deferred options array size. */
static size_t deferred_count, deferred_size;
static void missing_arg PARAMS ((size_t)); static void missing_arg PARAMS ((size_t));
static size_t find_opt PARAMS ((const char *, int)); static size_t find_opt PARAMS ((const char *, int));
static void set_Wimplicit PARAMS ((int)); static void set_Wimplicit PARAMS ((int));
...@@ -55,6 +65,8 @@ static void set_std_c89 PARAMS ((int, int)); ...@@ -55,6 +65,8 @@ static void set_std_c89 PARAMS ((int, int));
static void set_std_c99 PARAMS ((int)); static void set_std_c99 PARAMS ((int));
static void check_deps_environment_vars PARAMS ((void)); static void check_deps_environment_vars PARAMS ((void));
static void preprocess_file PARAMS ((void)); static void preprocess_file PARAMS ((void));
static void handle_deferred_opts PARAMS ((void));
static void sanitize_cpp_opts PARAMS ((void));
#ifndef STDC_0_IN_SYSTEM_HEADERS #ifndef STDC_0_IN_SYSTEM_HEADERS
#define STDC_0_IN_SYSTEM_HEADERS 0 #define STDC_0_IN_SYSTEM_HEADERS 0
...@@ -102,6 +114,15 @@ static void preprocess_file PARAMS ((void)); ...@@ -102,6 +114,15 @@ static void preprocess_file PARAMS ((void));
OPT("CC", CL_ALL, OPT_CC) \ OPT("CC", CL_ALL, OPT_CC) \
OPT("E", CL_ALL, OPT_E) \ OPT("E", CL_ALL, OPT_E) \
OPT("H", CL_ALL, OPT_H) \ OPT("H", CL_ALL, OPT_H) \
OPT("M", CL_ALL, OPT_M) \
OPT("MD", CL_ALL | CL_SEPARATE, OPT_MD) \
OPT("MF", CL_ALL | CL_ARG, OPT_MF) \
OPT("MG", CL_ALL, OPT_MG) \
OPT("MM", CL_ALL, OPT_MM) \
OPT("MMD", CL_ALL | CL_SEPARATE, OPT_MMD) \
OPT("MP", CL_ALL, OPT_MP) \
OPT("MQ", CL_ALL | CL_ARG, OPT_MQ) \
OPT("MT", CL_ALL | CL_ARG, OPT_MT) \
OPT("P", CL_ALL, OPT_P) \ OPT("P", CL_ALL, OPT_P) \
OPT("Wall", CL_ALL, OPT_Wall) \ OPT("Wall", CL_ALL, OPT_Wall) \
OPT("Wbad-function-cast", CL_C, OPT_Wbad_function_cast) \ OPT("Wbad-function-cast", CL_C, OPT_Wbad_function_cast) \
...@@ -284,6 +305,16 @@ static const struct cl_option cl_options[] = ...@@ -284,6 +305,16 @@ static const struct cl_option cl_options[] =
#undef OPT #undef OPT
#undef COMMAND_LINE_OPTIONS #undef COMMAND_LINE_OPTIONS
/* Holds switches parsed by c_common_decode_option (), but whose
handling is deffered to c_common_post_options (). */
static void defer_opt PARAMS ((enum opt_code, const char *));
static struct deferred_opt
{
enum opt_code code;
const char *arg;
} *deferred_opts;
#ifdef HOST_EBCDIC #ifdef HOST_EBCDIC
static int opt_comp PARAMS ((const void *, const void *)); static int opt_comp PARAMS ((const void *, const void *));
...@@ -303,6 +334,8 @@ static void ...@@ -303,6 +334,8 @@ static void
missing_arg (opt_index) missing_arg (opt_index)
size_t opt_index; size_t opt_index;
{ {
const char *opt_text = cl_options[opt_index].opt_text;
switch (opt_index) switch (opt_index)
{ {
case OPT_Wformat_eq: case OPT_Wformat_eq:
...@@ -313,15 +346,23 @@ missing_arg (opt_index) ...@@ -313,15 +346,23 @@ missing_arg (opt_index)
case OPT_ftabstop: case OPT_ftabstop:
case OPT_ftemplate_depth: case OPT_ftemplate_depth:
default: default:
error ("missing argument to \"-%s\"", cl_options[opt_index].opt_text); error ("missing argument to \"-%s\"", opt_text);
break; break;
case OPT_fconstant_string_class: case OPT_fconstant_string_class:
error ("no class name specified with -fconstant-string-class="); error ("no class name specified with \"-%s\"", opt_text);
break; break;
case OPT_MF:
case OPT_MD:
case OPT_MMD:
case OPT_o: case OPT_o:
error ("missing filename after \"-%s\"", cl_options[opt_index].opt_text); error ("missing filename after \"-%s\"", opt_text);
break;
case OPT_MQ:
case OPT_MT:
error ("missing target after \"-%s\"", opt_text);
break; break;
} }
} }
...@@ -420,6 +461,30 @@ find_opt (input, lang_flag) ...@@ -420,6 +461,30 @@ find_opt (input, lang_flag)
return N_OPTS; return N_OPTS;
} }
/* Defer option CODE with argument ARG. */
static void
defer_opt (code, arg)
enum opt_code code;
const char *arg;
{
/* FIXME: this should be in c_common_init_options, which should take
argc and argv. */
if (!deferred_opts)
{
extern int save_argc;
deferred_size = save_argc;
deferred_opts = (struct deferred_opt *)
xmalloc (deferred_size * sizeof (struct deferred_opt));
}
if (deferred_count == deferred_size)
abort ();
deferred_opts[deferred_count].code = code;
deferred_opts[deferred_count].arg = arg;
deferred_count++;
}
/* Common initialization before parsing options. */ /* Common initialization before parsing options. */
void void
c_common_init_options (lang) c_common_init_options (lang)
...@@ -432,10 +497,8 @@ c_common_init_options (lang) ...@@ -432,10 +497,8 @@ c_common_init_options (lang)
#endif #endif
c_language = lang; c_language = lang;
parse_in = cpp_create_reader (lang == clk_c parse_in = cpp_create_reader (lang == clk_c ? CLK_GNUC89 : CLK_GNUCXX);
? CLK_GNUC89 : CLK_GNUCXX);
cpp_opts = cpp_get_options (parse_in); cpp_opts = cpp_get_options (parse_in);
if (flag_objc) if (flag_objc)
cpp_opts->objc = 1; cpp_opts->objc = 1;
...@@ -563,6 +626,44 @@ c_common_decode_option (argc, argv) ...@@ -563,6 +626,44 @@ c_common_decode_option (argc, argv)
cpp_opts->print_include_names = 1; cpp_opts->print_include_names = 1;
break; break;
case OPT_M:
case OPT_MM:
/* When doing dependencies with -M or -MM, suppress normal
preprocessed output, but still do -dM etc. as software
depends on this. Preprocessed output does occur if -MD, -MMD
or environment var dependency generation is used. */
cpp_opts->deps.style = (code == OPT_M ? DEPS_SYSTEM: DEPS_USER);
cpp_opts->no_output = 1;
cpp_opts->inhibit_warnings = 1;
break;
case OPT_MD:
case OPT_MMD:
cpp_opts->deps.style = (code == OPT_MD ? DEPS_SYSTEM: DEPS_USER);
deps_file = arg;
break;
case OPT_MF:
deps_seen = true;
deps_file = arg;
break;
case OPT_MG:
deps_seen = true;
cpp_opts->deps.missing_files = true;
break;
case OPT_MP:
deps_seen = true;
cpp_opts->deps.phony_targets = true;
break;
case OPT_MQ:
case OPT_MT:
deps_seen = true;
defer_opt (code, arg);
break;
case OPT_P: case OPT_P:
cpp_opts->no_line_commands = 1; cpp_opts->no_line_commands = 1;
break; break;
...@@ -1219,26 +1320,12 @@ c_common_post_options () ...@@ -1219,26 +1320,12 @@ c_common_post_options ()
if (out_fname == NULL || !strcmp (out_fname, "-")) if (out_fname == NULL || !strcmp (out_fname, "-"))
out_fname = ""; out_fname = "";
if (cpp_opts->print_deps == 0) if (cpp_opts->deps.style != DEPS_NONE)
check_deps_environment_vars (); check_deps_environment_vars ();
/* If we're not outputting dependencies, complain if other -M handle_deferred_opts ();
options have been given. */
if (!cpp_opts->print_deps
&& (cpp_opts->print_deps_missing_files
|| cpp_opts->deps_file
|| cpp_opts->deps_phony_targets))
error ("you must additionally specify either -M or -MM");
cpp_post_options (parse_in); sanitize_cpp_opts ();
cpp_opts->unsigned_char = !flag_signed_char;
cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
/* We want -Wno-long-long to override -pedantic -std=non-c99
and/or -Wtraditional, whatever the ordering. */
cpp_opts->warn_long_long
= warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
flag_inline_trees = 1; flag_inline_trees = 1;
...@@ -1339,17 +1426,17 @@ c_common_finish () ...@@ -1339,17 +1426,17 @@ c_common_finish ()
{ {
FILE *deps_stream = NULL; FILE *deps_stream = NULL;
if (cpp_opts->print_deps) if (cpp_opts->deps.style != DEPS_NONE)
{ {
/* If -M or -MM was seen without -MF, default output to the /* If -M or -MM was seen without -MF, default output to the
output stream. */ output stream. */
if (!cpp_opts->deps_file) if (!deps_file)
deps_stream = out_stream; deps_stream = out_stream;
else else
{ {
deps_stream = fopen (cpp_opts->deps_file, deps_append ? "a": "w"); deps_stream = fopen (deps_file, deps_append ? "a": "w");
if (!deps_stream) if (!deps_stream)
fatal_io_error ("opening dependency file %s", cpp_opts->deps_file); fatal_io_error ("opening dependency file %s", deps_file);
} }
} }
...@@ -1359,29 +1446,12 @@ c_common_finish () ...@@ -1359,29 +1446,12 @@ c_common_finish ()
if (deps_stream && deps_stream != out_stream if (deps_stream && deps_stream != out_stream
&& (ferror (deps_stream) || fclose (deps_stream))) && (ferror (deps_stream) || fclose (deps_stream)))
fatal_io_error ("closing dependency file %s", cpp_opts->deps_file); fatal_io_error ("closing dependency file %s", deps_file);
if (out_stream && (ferror (out_stream) || fclose (out_stream))) if (out_stream && (ferror (out_stream) || fclose (out_stream)))
fatal_io_error ("when writing output to %s", out_fname); fatal_io_error ("when writing output to %s", out_fname);
} }
/* Set the C 89 standard (with 1994 amendments if C94, without GNU
extensions if ISO). There is no concept of gnu94. */
static void
set_std_c89 (c94, iso)
int c94, iso;
{
cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
flag_iso = iso;
flag_no_asm = iso;
flag_no_gnu_keywords = iso;
flag_no_nonansi_builtin = iso;
flag_noniso_default_format_attributes = !iso;
flag_isoc94 = c94;
flag_isoc99 = 0;
flag_writable_strings = 0;
}
/* Either of two environment variables can specify output of /* Either of two environment variables can specify output of
dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE dependencies. Their value is either "OUTPUT_FILE" or "OUTPUT_FILE
DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to DEPS_TARGET", where OUTPUT_FILE is the file to write deps info to
...@@ -1395,12 +1465,12 @@ check_deps_environment_vars () ...@@ -1395,12 +1465,12 @@ check_deps_environment_vars ()
GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT"); GET_ENVIRONMENT (spec, "DEPENDENCIES_OUTPUT");
if (spec) if (spec)
cpp_opts->print_deps = 1; cpp_opts->deps.style = DEPS_USER;
else else
{ {
GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES"); GET_ENVIRONMENT (spec, "SUNPRO_DEPENDENCIES");
if (spec) if (spec)
cpp_opts->print_deps = 2; cpp_opts->deps.style = DEPS_SYSTEM;
} }
if (spec) if (spec)
...@@ -1410,16 +1480,91 @@ check_deps_environment_vars () ...@@ -1410,16 +1480,91 @@ check_deps_environment_vars ()
if (s) if (s)
{ {
/* Let the caller perform MAKE quoting. */ /* Let the caller perform MAKE quoting. */
cpp_add_dependency_target (parse_in, s + 1, 0); defer_opt (OPT_MT, s + 1);
*s = '\0'; *s = '\0';
} }
/* Command line -MF overrides environment variables and default. */ /* Command line -MF overrides environment variables and default. */
if (!cpp_opts->deps_file) if (!deps_file)
cpp_opts->deps_file = spec; deps_file = spec;
deps_append = 1;
}
}
/* Handle deferred command line switches. */
static void
handle_deferred_opts ()
{
size_t i;
cpp_opts->print_deps_append = 1; for (i = 0; i < deferred_count; i++)
{
struct deferred_opt *opt = &deferred_opts[i];
switch (opt->code)
{
case OPT_MT:
case OPT_MQ:
cpp_add_dependency_target (parse_in, opt->arg, opt->code == OPT_MQ);
break;
default:
abort ();
}
}
free (deferred_opts);
}
/* These settings are appropriate for GCC, but not necessarily so for
cpplib as a library. */
static void
sanitize_cpp_opts ()
{
/* If we don't know what style of dependencies to output, complain
if any other dependency switches have been given. */
if (deps_seen && cpp_opts->deps.style == DEPS_NONE)
error ("to generate dependencies you must specify either -M or -MM");
/* -dM and dependencies suppress normal output; do it here so that
the last -d[MDN] switch overrides earlier ones. */
if (cpp_opts->dump_macros == dump_only)
cpp_opts->no_output = 1;
/* Disable -dD, -dN and -dI if normal output is suppressed. Allow
-dM since at least glibc relies on -M -dM to work. */
if (cpp_opts->no_output)
{
if (cpp_opts->dump_macros != dump_only)
cpp_opts->dump_macros = dump_none;
cpp_opts->dump_includes = 0;
} }
cpp_opts->unsigned_char = !flag_signed_char;
cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
/* We want -Wno-long-long to override -pedantic -std=non-c99
and/or -Wtraditional, whatever the ordering. */
cpp_opts->warn_long_long
= warn_long_long && ((!flag_isoc99 && pedantic) || warn_traditional);
}
/* Set the C 89 standard (with 1994 amendments if C94, without GNU
extensions if ISO). There is no concept of gnu94. */
static void
set_std_c89 (c94, iso)
int c94, iso;
{
cpp_set_lang (parse_in, c94 ? CLK_STDC94: iso ? CLK_STDC89: CLK_GNUC89);
flag_iso = iso;
flag_no_asm = iso;
flag_no_gnu_keywords = iso;
flag_no_nonansi_builtin = iso;
flag_noniso_default_format_attributes = !iso;
flag_isoc94 = c94;
flag_isoc99 = 0;
flag_writable_strings = 0;
} }
/* Set the C 99 standard (without GNU extensions if ISO). */ /* Set the C 99 standard (without GNU extensions if ISO). */
......
...@@ -319,7 +319,7 @@ stack_include_file (pfile, inc) ...@@ -319,7 +319,7 @@ stack_include_file (pfile, inc)
(inc->foundhere ? inc->foundhere->sysp : 0)); (inc->foundhere ? inc->foundhere->sysp : 0));
/* For -M, add the file to the dependencies on its first inclusion. */ /* For -M, add the file to the dependencies on its first inclusion. */
if (CPP_OPTION (pfile, print_deps) > !!sysp && !inc->include_count) if (CPP_OPTION (pfile, deps.style) > !!sysp && !inc->include_count)
deps_add_dep (pfile->deps, inc->name); deps_add_dep (pfile->deps, inc->name);
/* Not in cache? */ /* Not in cache? */
...@@ -663,9 +663,10 @@ handle_missing_header (pfile, fname, angle_brackets) ...@@ -663,9 +663,10 @@ handle_missing_header (pfile, fname, angle_brackets)
const char *fname; const char *fname;
int angle_brackets; int angle_brackets;
{ {
int print_dep = CPP_PRINT_DEPS(pfile) > (angle_brackets || pfile->map->sysp); bool print_dep
= CPP_OPTION (pfile, deps.style) > (angle_brackets || pfile->map->sysp);
if (CPP_OPTION (pfile, print_deps_missing_files) && print_dep)
if (CPP_OPTION (pfile, deps.missing_files) && print_dep)
deps_add_dep (pfile->deps, fname); deps_add_dep (pfile->deps, fname);
/* If -M was specified, then don't count this as an error, because /* If -M was specified, then don't count this as an error, because
we can still produce correct output. Otherwise, we can't produce we can still produce correct output. Otherwise, we can't produce
...@@ -673,7 +674,7 @@ handle_missing_header (pfile, fname, angle_brackets) ...@@ -673,7 +674,7 @@ handle_missing_header (pfile, fname, angle_brackets)
the missing file, and we don't know what directory this missing the missing file, and we don't know what directory this missing
file exists in. */ file exists in. */
else else
cpp_errno (pfile, CPP_PRINT_DEPS (pfile) && ! print_dep cpp_errno (pfile, CPP_OPTION (pfile, deps.style) && ! print_dep
? DL_WARNING: DL_ERROR, fname); ? DL_WARNING: DL_ERROR, fname);
} }
......
...@@ -400,7 +400,7 @@ struct cpp_reader ...@@ -400,7 +400,7 @@ struct cpp_reader
cpp_token avoid_paste; cpp_token avoid_paste;
cpp_token eof; cpp_token eof;
/* Opaque handle to the dependencies of mkdeps.c. Used by -M etc. */ /* Opaque handle to the dependencies of mkdeps.c. */
struct deps *deps; struct deps *deps;
/* Obstack holding all macro hash nodes. This never shrinks. /* Obstack holding all macro hash nodes. This never shrinks.
...@@ -480,7 +480,6 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1]; ...@@ -480,7 +480,6 @@ extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
/* Macros. */ /* Macros. */
#define CPP_PRINT_DEPS(PFILE) CPP_OPTION (PFILE, print_deps)
#define CPP_IN_SYSTEM_HEADER(PFILE) ((PFILE)->map && (PFILE)->map->sysp) #define CPP_IN_SYSTEM_HEADER(PFILE) ((PFILE)->map && (PFILE)->map->sysp)
#define CPP_PEDANTIC(PF) CPP_OPTION (PF, pedantic) #define CPP_PEDANTIC(PF) CPP_OPTION (PF, pedantic)
#define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional) #define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, warn_traditional)
......
...@@ -25,7 +25,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ...@@ -25,7 +25,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "cpphash.h" #include "cpphash.h"
#include "prefix.h" #include "prefix.h"
#include "intl.h" #include "intl.h"
#include "version.h"
#include "mkdeps.h" #include "mkdeps.h"
#include "cppdefault.h" #include "cppdefault.h"
...@@ -108,6 +107,7 @@ static void new_pending_directive PARAMS ((struct cpp_pending *, ...@@ -108,6 +107,7 @@ static void new_pending_directive PARAMS ((struct cpp_pending *,
const char *, const char *,
cl_directive_handler)); cl_directive_handler));
static int parse_option PARAMS ((const char *)); static int parse_option PARAMS ((const char *));
static void post_options PARAMS ((cpp_reader *));
/* Fourth argument to append_include_chain: chain to use. /* Fourth argument to append_include_chain: chain to use.
Note it's never asked to append to the quote chain. */ Note it's never asked to append to the quote chain. */
...@@ -477,6 +477,7 @@ cpp_create_reader (lang) ...@@ -477,6 +477,7 @@ cpp_create_reader (lang)
CPP_OPTION (pfile, tabstop) = 8; CPP_OPTION (pfile, tabstop) = 8;
CPP_OPTION (pfile, operator_names) = 1; CPP_OPTION (pfile, operator_names) = 1;
CPP_OPTION (pfile, warn_endif_labels) = 1; CPP_OPTION (pfile, warn_endif_labels) = 1;
CPP_OPTION (pfile, warn_long_long) = !CPP_OPTION (pfile, c99);
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));
...@@ -490,10 +491,6 @@ cpp_create_reader (lang) ...@@ -490,10 +491,6 @@ cpp_create_reader (lang)
CPP_OPTION (pfile, unsigned_char) = 0; CPP_OPTION (pfile, unsigned_char) = 0;
CPP_OPTION (pfile, unsigned_wchar) = 1; CPP_OPTION (pfile, unsigned_wchar) = 1;
/* It's simplest to just create this struct whether or not it will
be needed. */
pfile->deps = deps_init ();
/* Initialise the line map. Start at logical line 1, so we can use /* Initialise the line map. Start at logical line 1, so we can use
a line number of zero for special states. */ a line number of zero for special states. */
init_line_maps (&pfile->line_maps); init_line_maps (&pfile->line_maps);
...@@ -560,7 +557,8 @@ cpp_destroy (pfile) ...@@ -560,7 +557,8 @@ cpp_destroy (pfile)
pfile->macro_buffer_len = 0; pfile->macro_buffer_len = 0;
} }
deps_free (pfile->deps); if (pfile->deps)
deps_free (pfile->deps);
obstack_free (&pfile->buffer_ob, 0); obstack_free (&pfile->buffer_ob, 0);
_cpp_destroy_hashtable (pfile); _cpp_destroy_hashtable (pfile);
...@@ -902,6 +900,8 @@ cpp_read_main_file (pfile, fname, table) ...@@ -902,6 +900,8 @@ cpp_read_main_file (pfile, fname, table)
{ {
sanity_checks (pfile); sanity_checks (pfile);
post_options (pfile);
/* The front ends don't set up the hash table until they have /* The front ends don't set up the hash table until they have
finished processing the command line options, so initializing the finished processing the command line options, so initializing the
hashtable is deferred until now. */ hashtable is deferred until now. */
...@@ -927,17 +927,22 @@ cpp_read_main_file (pfile, fname, table) ...@@ -927,17 +927,22 @@ cpp_read_main_file (pfile, fname, table)
fprintf (stderr, _("End of search list.\n")); fprintf (stderr, _("End of search list.\n"));
} }
if (CPP_OPTION (pfile, print_deps)) if (CPP_OPTION (pfile, deps.style) != DEPS_NONE)
/* Set the default target (if there is none already). */ {
deps_add_default_target (pfile->deps, fname); if (!pfile->deps)
pfile->deps = deps_init ();
/* Set the default target (if there is none already). */
deps_add_default_target (pfile->deps, fname);
}
/* Open the main input file. */ /* Open the main input file. */
if (!_cpp_read_file (pfile, fname)) if (!_cpp_read_file (pfile, fname))
return NULL; return NULL;
/* Set this after cpp_post_options so the client can change the /* Set this here so the client can change the option if it wishes,
option if it wishes, and after stacking the main file so we don't and after stacking the main file so we don't trace the main
trace the main file. */ file. */
pfile->line_maps.trace_includes = CPP_OPTION (pfile, print_include_names); pfile->line_maps.trace_includes = CPP_OPTION (pfile, print_include_names);
/* For foo.i, read the original filename foo.c now, for the benefit /* For foo.i, read the original filename foo.c now, for the benefit
...@@ -1067,11 +1072,12 @@ cpp_finish (pfile, deps_stream) ...@@ -1067,11 +1072,12 @@ cpp_finish (pfile, deps_stream)
_cpp_pop_buffer (pfile); _cpp_pop_buffer (pfile);
/* Don't write the deps file if there are errors. */ /* Don't write the deps file if there are errors. */
if (deps_stream && CPP_OPTION (pfile, print_deps) && !pfile->errors) if (CPP_OPTION (pfile, deps.style) != DEPS_NONE
&& deps_stream && pfile->errors == 0)
{ {
deps_write (pfile->deps, deps_stream, 72); deps_write (pfile->deps, deps_stream, 72);
if (CPP_OPTION (pfile, deps_phony_targets)) if (CPP_OPTION (pfile, deps.phony_targets))
deps_phony_targets (pfile->deps, deps_stream); deps_phony_targets (pfile->deps, deps_stream);
} }
...@@ -1106,7 +1112,6 @@ new_pending_directive (pend, text, handler) ...@@ -1106,7 +1112,6 @@ new_pending_directive (pend, text, handler)
#define no_fil N_("file name missing after %s") #define no_fil N_("file name missing after %s")
#define no_mac N_("macro name missing after %s") #define no_mac N_("macro name missing after %s")
#define no_pth N_("path name missing after %s") #define no_pth N_("path name missing after %s")
#define no_tgt N_("target missing after %s")
/* This is the list of all command line options, with the leading /* This is the list of all command line options, with the leading
"-" removed. It must be sorted in ASCII collating order. */ "-" removed. It must be sorted in ASCII collating order. */
...@@ -1114,15 +1119,6 @@ new_pending_directive (pend, text, handler) ...@@ -1114,15 +1119,6 @@ new_pending_directive (pend, text, handler)
DEF_OPT("A", no_ass, OPT_A) \ DEF_OPT("A", no_ass, OPT_A) \
DEF_OPT("D", no_mac, OPT_D) \ DEF_OPT("D", no_mac, OPT_D) \
DEF_OPT("I", no_dir, OPT_I) \ DEF_OPT("I", no_dir, OPT_I) \
DEF_OPT("M", 0, OPT_M) \
DEF_OPT("MD", no_fil, OPT_MD) \
DEF_OPT("MF", no_fil, OPT_MF) \
DEF_OPT("MG", 0, OPT_MG) \
DEF_OPT("MM", 0, OPT_MM) \
DEF_OPT("MMD", no_fil, OPT_MMD) \
DEF_OPT("MP", 0, OPT_MP) \
DEF_OPT("MQ", no_tgt, OPT_MQ) \
DEF_OPT("MT", no_tgt, OPT_MT) \
DEF_OPT("U", no_mac, OPT_U) \ DEF_OPT("U", no_mac, OPT_U) \
DEF_OPT("idirafter", no_dir, OPT_idirafter) \ DEF_OPT("idirafter", no_dir, OPT_idirafter) \
DEF_OPT("imacros", no_fil, OPT_imacros) \ DEF_OPT("imacros", no_fil, OPT_imacros) \
...@@ -1272,44 +1268,6 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1272,44 +1268,6 @@ cpp_handle_option (pfile, argc, argv)
CPP_OPTION (pfile, include_prefix_len) = strlen (arg); CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
break; break;
case OPT_MG:
CPP_OPTION (pfile, print_deps_missing_files) = 1;
break;
case OPT_M:
/* When doing dependencies with -M or -MM, suppress normal
preprocessed output, but still do -dM etc. as software
depends on this. Preprocessed output occurs if -MD, -MMD
or environment var dependency generation is used. */
CPP_OPTION (pfile, print_deps) = 2;
CPP_OPTION (pfile, no_output) = 1;
CPP_OPTION (pfile, inhibit_warnings) = 1;
break;
case OPT_MM:
CPP_OPTION (pfile, print_deps) = 1;
CPP_OPTION (pfile, no_output) = 1;
CPP_OPTION (pfile, inhibit_warnings) = 1;
break;
case OPT_MF:
CPP_OPTION (pfile, deps_file) = arg;
break;
case OPT_MP:
CPP_OPTION (pfile, deps_phony_targets) = 1;
break;
case OPT_MQ:
case OPT_MT:
/* Add a target. -MQ quotes for Make. */
deps_add_target (pfile->deps, arg, opt_code == OPT_MQ);
break;
case OPT_MD:
CPP_OPTION (pfile, print_deps) = 2;
CPP_OPTION (pfile, deps_file) = arg;
break;
case OPT_MMD:
CPP_OPTION (pfile, print_deps) = 1;
CPP_OPTION (pfile, deps_file) = arg;
break;
case OPT_A: case OPT_A:
if (arg[0] == '-') if (arg[0] == '-')
{ {
...@@ -1446,22 +1404,14 @@ cpp_handle_options (pfile, argc, argv) ...@@ -1446,22 +1404,14 @@ cpp_handle_options (pfile, argc, argv)
return i; return i;
} }
/* Extra processing when all options are parsed, after all calls to static void
cpp_handle_option[s]. Consistency checks etc. */ post_options (pfile)
void
cpp_post_options (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
/* -Wtraditional is not useful in C++ mode. */ /* -Wtraditional is not useful in C++ mode. */
if (CPP_OPTION (pfile, cplusplus)) if (CPP_OPTION (pfile, cplusplus))
CPP_OPTION (pfile, warn_traditional) = 0; CPP_OPTION (pfile, warn_traditional) = 0;
/* The compiler front ends override this, but I think this is the
appropriate setting for the library. */
CPP_OPTION (pfile, warn_long_long)
= ((CPP_OPTION (pfile, pedantic) && !CPP_OPTION (pfile, c99))
|| CPP_OPTION (pfile, warn_traditional));
/* Permanently disable macro expansion if we are rescanning /* Permanently disable macro expansion if we are rescanning
preprocessed text. Read preprocesed source in ISO mode. */ preprocessed text. Read preprocesed source in ISO mode. */
if (CPP_OPTION (pfile, preprocessed)) if (CPP_OPTION (pfile, preprocessed))
...@@ -1473,18 +1423,4 @@ cpp_post_options (pfile) ...@@ -1473,18 +1423,4 @@ cpp_post_options (pfile)
/* Traditional CPP does not accurately track column information. */ /* Traditional CPP does not accurately track column information. */
if (CPP_OPTION (pfile, traditional)) if (CPP_OPTION (pfile, traditional))
CPP_OPTION (pfile, show_column) = 0; CPP_OPTION (pfile, show_column) = 0;
/* -dM and dependencies suppress normal output; do it here so that
the last -d[MDN] switch overrides earlier ones. */
if (CPP_OPTION (pfile, dump_macros) == dump_only)
CPP_OPTION (pfile, no_output) = 1;
/* Disable -dD, -dN and -dI if normal output is suppressed. Allow
-dM since at least glibc relies on -M -dM to work. */
if (CPP_OPTION (pfile, no_output))
{
if (CPP_OPTION (pfile, dump_macros) != dump_only)
CPP_OPTION (pfile, dump_macros) = dump_none;
CPP_OPTION (pfile, dump_includes) = 0;
}
} }
...@@ -227,10 +227,6 @@ struct cpp_options ...@@ -227,10 +227,6 @@ struct cpp_options
/* Pending options - -D, -U, -A, -I, -ixxx. */ /* Pending options - -D, -U, -A, -I, -ixxx. */
struct cpp_pending *pending; struct cpp_pending *pending;
/* File name which deps are being written to. This is 0 if deps are
being written to stdout. */
const char *deps_file;
/* Search paths for include files. */ /* Search paths for include files. */
struct search_path *quote_include; /* "" */ struct search_path *quote_include; /* "" */
struct search_path *bracket_include; /* <> */ struct search_path *bracket_include; /* <> */
...@@ -276,21 +272,6 @@ struct cpp_options ...@@ -276,21 +272,6 @@ struct cpp_options
/* Nonzero means to allow hexadecimal floats and LL suffixes. */ /* Nonzero means to allow hexadecimal floats and LL suffixes. */
unsigned char extended_numbers; unsigned char extended_numbers;
/* Nonzero means print the names of included files rather than the
preprocessed output. 1 means just the #include "...", 2 means
#include <...> as well. */
unsigned char print_deps;
/* Nonzero if phony targets are created for each header. */
unsigned char deps_phony_targets;
/* Nonzero if missing .h files in -M output are assumed to be
generated files and not errors. */
unsigned char print_deps_missing_files;
/* If true, fopen (deps_file, "a") else fopen (deps_file, "w"). */
unsigned char print_deps_append;
/* Nonzero means print names of header files (-H). */ /* Nonzero means print names of header files (-H). */
unsigned char print_include_names; unsigned char print_include_names;
...@@ -394,6 +375,20 @@ struct cpp_options ...@@ -394,6 +375,20 @@ struct cpp_options
/* True for traditional preprocessing. */ /* True for traditional preprocessing. */
unsigned char traditional; unsigned char traditional;
/* Dependency generation. */
struct
{
/* Style of header dependencies to generate. */
enum {DEPS_NONE = 0, DEPS_USER, DEPS_SYSTEM } style;
/* Assume missing files are generated files. */
bool missing_files;
/* Generate phony targets for each dependency apart from the first
one. */
bool phony_targets;
} deps;
/* Target-specific features set by the front end or client. */ /* Target-specific features set by the front end or client. */
/* Precision for target CPP arithmetic, target characters, target /* Precision for target CPP arithmetic, target characters, target
...@@ -522,14 +517,10 @@ extern void cpp_set_callbacks PARAMS ((cpp_reader *, cpp_callbacks *)); ...@@ -522,14 +517,10 @@ extern void cpp_set_callbacks PARAMS ((cpp_reader *, cpp_callbacks *));
/* Now call cpp_handle_option[s] to handle 1[or more] switches. The /* Now call cpp_handle_option[s] to handle 1[or more] switches. The
return value is the number of arguments used. If return value is the number of arguments used. If
cpp_handle_options returns without using all arguments, it couldn't cpp_handle_options returns without using all arguments, it couldn't
understand the next switch. When there are no switches left, you understand the next switch. Options processing is not completed
must call cpp_post_options before calling cpp_read_main_file. Only until you call cpp_finish_options. */
after cpp_post_options are the contents of the cpp_options
structure reliable. Options processing is not completed until you
call cpp_finish_options. */
extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **)); extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **));
extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **)); extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **));
extern void cpp_post_options PARAMS ((cpp_reader *));
/* This function reads the file, but does not start preprocessing. It /* This function reads the file, but does not start preprocessing. It
returns the name of the original file; this is the same as the returns the name of the original file; this is the same as the
...@@ -551,6 +542,13 @@ extern const char *cpp_read_main_file PARAMS ((cpp_reader *, const char *, ...@@ -551,6 +542,13 @@ extern const char *cpp_read_main_file PARAMS ((cpp_reader *, const char *,
from cpp_read_main_file, before they get debug callbacks. */ from cpp_read_main_file, before they get debug callbacks. */
extern void cpp_finish_options PARAMS ((cpp_reader *)); extern void cpp_finish_options PARAMS ((cpp_reader *));
/* Call this to finish preprocessing. If you requested dependency
generation, pass an open stream to write the information to,
otherwise NULL. It is your responsibility to close the stream.
Returns cpp_errors (pfile). */
extern int cpp_finish PARAMS ((cpp_reader *, FILE *deps_stream));
/* Call this to release the handle at the end of preprocessing. Any /* Call this to release the handle at the end of preprocessing. Any
use of the handle after this function returns is invalid. Returns use of the handle after this function returns is invalid. Returns
cpp_errors (pfile). */ cpp_errors (pfile). */
...@@ -568,7 +566,6 @@ extern void cpp_register_pragma PARAMS ((cpp_reader *, ...@@ -568,7 +566,6 @@ extern void cpp_register_pragma PARAMS ((cpp_reader *,
const char *, const char *, const char *, const char *,
void (*) PARAMS ((cpp_reader *)))); void (*) PARAMS ((cpp_reader *))));
extern int cpp_finish PARAMS ((cpp_reader *, FILE *));
extern int cpp_avoid_paste PARAMS ((cpp_reader *, const cpp_token *, extern int cpp_avoid_paste PARAMS ((cpp_reader *, const cpp_token *,
const cpp_token *)); const cpp_token *));
extern const cpp_token *cpp_get_token PARAMS ((cpp_reader *)); extern const cpp_token *cpp_get_token PARAMS ((cpp_reader *));
......
...@@ -632,7 +632,6 @@ read_scan_file (in_fname, argc, argv) ...@@ -632,7 +632,6 @@ read_scan_file (in_fname, argc, argv)
i = cpp_handle_options (scan_in, argc, argv); i = cpp_handle_options (scan_in, argc, argv);
if (i < argc) if (i < argc)
cpp_error (scan_in, DL_ERROR, "invalid option `%s'", argv[i]); cpp_error (scan_in, DL_ERROR, "invalid option `%s'", argv[i]);
cpp_post_options (scan_in);
if (cpp_errors (scan_in)) if (cpp_errors (scan_in))
exit (FATAL_EXIT_CODE); exit (FATAL_EXIT_CODE);
......
2002-08-13 Neil Booth <neil@daikokuya.co.uk>
* treelang.c: Remove cpp_post_options.
2002-08-08 Nathan Sidwell <nathan@codesourcery.com> 2002-08-08 Nathan Sidwell <nathan@codesourcery.com>
* treelang/Make-lang.in (treelang.mostlyclean): Remove coverage files. * treelang/Make-lang.in (treelang.mostlyclean): Remove coverage files.
......
...@@ -955,14 +955,6 @@ cpp_create_reader (enum c_lang lang ATTRIBUTE_UNUSED) ...@@ -955,14 +955,6 @@ cpp_create_reader (enum c_lang lang ATTRIBUTE_UNUSED)
/* Should not be called for treelang. */ /* Should not be called for treelang. */
void void
cpp_post_options (cpp_reader *pfile ATTRIBUTE_UNUSED)
{
abort ();
}
/* Should not be called for treelang. */
void
cpp_preprocess_file (cpp_reader *pfile ATTRIBUTE_UNUSED) cpp_preprocess_file (cpp_reader *pfile ATTRIBUTE_UNUSED)
{ {
abort (); abort ();
......
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