/* C/ObjC/C++ command line option handling.
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
Contributed by Neil Booth.
This file is part of GCC.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA. */
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA. */
#include "config.h"
#include "system.h"
#include "c-incpath.h"
#include "opts.h"
#include "options.h"
+#include "mkdeps.h"
#ifndef DOLLARS_IN_IDENTIFIERS
# define DOLLARS_IN_IDENTIFIERS true
/* If -Wunused-macros. */
static bool warn_unused_macros;
+/* If -Wvariadic-macros. */
+static bool warn_variadic_macros = true;
+
/* Number of deferred options. */
static size_t deferred_count;
case OPT_idirafter:
case OPT_isysroot:
case OPT_isystem:
+ case OPT_iquote:
error ("missing path after \"%s\"", opt);
break;
unsigned int
sdcpp_common_init_options (unsigned int argc, const char **argv ATTRIBUTE_UNUSED)
{
- parse_in = cpp_create_reader (CLK_GNUC89, NULL);
+ parse_in = cpp_create_reader (CLK_GNUC89, NULL, &line_table);
cpp_opts = cpp_get_options (parse_in);
cpp_opts->dollars_in_ident = DOLLARS_IN_IDENTIFIERS;
before passing on command-line options to cpplib. */
cpp_opts->warn_dollars = 0;
- deferred_opts = xmalloc (argc * sizeof (struct deferred_opt));
+ deferred_opts = XNEWVEC (struct deferred_opt, argc);
return CL_SDCPP;
}
case OPT_I:
if (strcmp (arg, "-"))
- add_path (xstrdup (arg), BRACKET, 0);
+ add_path (xstrdup (arg), BRACKET, 0, true);
else
{
if (quote_chain_split)
error ("-I- specified twice");
quote_chain_split = true;
split_quote_chain ();
+ inform ("obsolete option -I- used, please use -iquote instead");
}
break;
case OPT_Werror:
cpp_opts->warnings_are_errors = value;
+ global_dc->warning_as_error_requested = value;
break;
case OPT_Wimport:
cpp_opts->warn_system_headers = value;
break;
+ case OPT_Wtraditional:
+ cpp_opts->warn_traditional = value;
+ break;
+
case OPT_Wtrigraphs:
cpp_opts->warn_trigraphs = value;
break;
warn_unused_macros = value;
break;
+ case OPT_Wvariadic_macros:
+ warn_variadic_macros = value;
+ break;
+
case OPT_ansi:
set_std_c89 (false, true);
break;
case OPT_fpch_deps:
cpp_opts->restore_pch_deps = value;
break;
+
+ case OPT_fpch_preprocess:
+ flag_pch_preprocess = value;
+ break;
#endif
case OPT_fpreprocessed:
break;
case OPT_idirafter:
- add_path (xstrdup (arg), AFTER, 0);
+ add_path (xstrdup (arg), AFTER, 0, true);
break;
case OPT_imacros:
iprefix = arg;
break;
+ case OPT_iquote:
+ add_path (xstrdup (arg), QUOTE, 0, true);
+ break;
+
case OPT_isysroot:
sysroot = arg;
break;
case OPT_isystem:
- add_path (xstrdup (arg), SYSTEM, 0);
+ add_path (xstrdup (arg), SYSTEM, 0, true);
break;
case OPT_iwithprefix:
cpp_opts->pedantic_parse_number = 1;
break;
+#if 0 // pch not supported by sdcpp
+ case OPT_print_pch_checksum:
+ c_common_print_pch_checksum (stdout);
+ exit_after_options = true;
+ break;
+#endif
+
case OPT_remap:
cpp_opts->remap = 1;
break;
/* Canonicalize the input and output filenames. */
if (in_fnames == NULL)
{
- in_fnames = xmalloc (sizeof (in_fnames[0]));
+ in_fnames = XNEWVEC (const char *, 1);
in_fnames[0] = "";
}
else if (strcmp (in_fnames[0], "-") == 0)
cb->dir_change = cb_dir_change;
cpp_post_options (parse_in);
- saved_lineno = input_line;
- input_line = 0;
+ input_location = UNKNOWN_LOCATION;
/* If an error has occurred in cpplib, note it so we fail
immediately. */
return false;
}
- if (flag_working_directory && ! flag_no_line_commands)
+ if (flag_working_directory && !flag_no_line_commands)
pp_dir_change (parse_in, get_src_pwd ());
return 1;
}
-/* Front end initialization common to C, ObjC and C++. */
+/* Front end initialization. */
bool
sdcpp_common_init (void)
{
- input_line = saved_lineno;
-
/* Default CPP arithmetic to something sensible for the host for the
benefit of dumb users like fix-header. */
cpp_opts->precision = CHAR_BIT * sizeof (long);
are known. */
cpp_init_iconv (parse_in);
+#if 0
+ if (version_flag)
+ c_common_print_pch_checksum (stderr);
+#endif
+
finish_options ();
preprocess_file (parse_in);
return false;
deps_file = spec;
deps_append = 1;
+ deps_seen = true;
}
}
handle_deferred_opts (void)
{
size_t i;
+ struct deps *deps;
+
+ /* Avoid allocating the deps buffer if we don't need it.
+ (This flag may be true without there having been -MT or -MQ
+ options, but we'll still need the deps buffer.) */
+ if (!deps_seen)
+ return;
+
+ deps = cpp_get_deps (parse_in);
for (i = 0; i < deferred_count; i++)
{
struct deferred_opt *opt = &deferred_opts[i];
if (opt->code == OPT_MT || opt->code == OPT_MQ)
- cpp_add_dependency_target (parse_in, opt->arg, opt->code == OPT_MQ);
+ deps_add_target (deps, opt->arg, opt->code == OPT_MQ);
}
}
cpp_opts->unsigned_char = !flag_signed_char;
cpp_opts->stdc_0_in_system_headers = STDC_0_IN_SYSTEM_HEADERS;
+ /* Similarly with -Wno-variadic-macros. No check for c99 here, since
+ this also turns off warnings about GCCs extension. */
+ cpp_opts->warn_variadic_macros
+ = warn_variadic_macros && (pedantic || warn_traditional);
+
/* If we're generating preprocessor output, emit current directory
if explicitly requested */
if (flag_working_directory == -1)
prefix = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
- path = xmalloc (prefix_len + suffix_len + 1);
+ path = (char *) xmalloc (prefix_len + suffix_len + 1);
memcpy (path, prefix, prefix_len);
memcpy (path + prefix_len, suffix, suffix_len);
path[prefix_len + suffix_len] = '\0';
- add_path (path, chain, 0);
+ add_path (path, chain, 0, false);
}
/* Handle -D, -U, -A, -imacros, and the first -include. */
{
size_t i;
- cpp_change_file (parse_in, LC_RENAME, _("<built-in>"));
+ cb_file_change (parse_in,
+ linemap_add (&line_table, LC_RENAME, 0,
+ _("<built-in>"), 0));
+
cpp_init_builtins (parse_in, 0 /*flag_hosted*/);
/* We're about to send user input to cpplib, so make it warn for
{
struct deferred_opt *opt = &deferred_opts[include_cursor++];
- if (! cpp_opts->preprocessed && opt->code == OPT_include
+ if (!cpp_opts->preprocessed && opt->code == OPT_include
&& cpp_push_include (parse_in, opt->arg))
return;
}
/* -Wunused-macros should only warn about macros defined hereafter. */
cpp_opts->warn_unused_macros = warn_unused_macros;
/* Restore the line map from <command line>. */
- if (! cpp_opts->preprocessed)
- cpp_change_file (parse_in, LC_RENAME, main_input_filename);
+ if (!cpp_opts->preprocessed)
+ cpp_change_file (parse_in, LC_RENAME, this_input_filename);
/* Set this here so the client can change the option if it wishes,
and after stacking the main file so we don't trace the main file. */
- cpp_get_line_maps (parse_in)->trace_includes
- = cpp_opts->print_include_names;
+ line_table.trace_includes = cpp_opts->print_include_names;
}
}
/* File change callback. Has to handle -include files. */
static void
-cb_file_change (cpp_reader *pfile ATTRIBUTE_UNUSED,
+cb_file_change (cpp_reader * ARG_UNUSED (pfile),
const struct line_map *new_map)
{
pp_file_change (new_map);
}
void
-cb_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
+cb_dir_change (cpp_reader * ARG_UNUSED (pfile), const char *dir)
{
- if (! set_src_pwd (dir))
- warning ("too late for # directive to set debug directory");
+ if (!set_src_pwd (dir))
+ warning (0, "too late for # directive to set debug directory");
}
/* Set the C 89 standard (with 1994 amendments if C94, without GNU