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

* c-opts.c (set_std_cxx98, set_std_c89): New.
	(COMMAND_LINE_OPTIONS): Move more from cppinit.c.
	(c_common_decode_option): Handle new switches from cppinit.c.
	Add -std=gnu++98.
	* cppinit.c (set_lang): Rename cpp_set_lang.  Export.
	(no_arg, no_num): Remove.
	(COMMAND_LINE_OPTIONS): Move more to c-opts.c.  Drop all lang-
	switches apart from -lang-objc and lang-asm.
	(cpp_handle_option): Similarly.
	* cpplib.h (cpp_set_lang): New.
	* doc/cppopts.texi, doc/invoke.texi: Document -std=c++98,
	-std=gnu++98.
	* objc/lang-specs.h: Remove -ansi.
cp:
	* lang-specs.h: Remove -ansi.

From-SVN: r56185
This commit is contained in:
Neil Booth 2002-08-10 20:58:45 +00:00 committed by Neil Booth
parent 77abb5d87d
commit f749a36bbe
10 changed files with 117 additions and 104 deletions

View File

@ -1,3 +1,19 @@
2002-08-10 Neil Booth <neil@daikokuya.co.uk>
* c-opts.c (set_std_cxx98, set_std_c89): New.
(COMMAND_LINE_OPTIONS): Move more from cppinit.c.
(c_common_decode_option): Handle new switches from cppinit.c.
Add -std=gnu++98.
* cppinit.c (set_lang): Rename cpp_set_lang. Export.
(no_arg, no_num): Remove.
(COMMAND_LINE_OPTIONS): Move more to c-opts.c. Drop all lang-
switches apart from -lang-objc and lang-asm.
(cpp_handle_option): Similarly.
* cpplib.h (cpp_set_lang): New.
* doc/cppopts.texi, doc/invoke.texi: Document -std=c++98,
-std=gnu++98.
* objc/lang-specs.h: Remove -ansi.
Sat Aug 10 19:59:43 CEST 2002 Jan Hubicka <jh@suse.cz>
Graham Stott

View File

@ -40,6 +40,8 @@ static void complain_wrong_lang PARAMS ((size_t));
static void write_langs PARAMS ((char *, int));
static void print_help PARAMS ((void));
static void handle_OPT_d PARAMS ((const char *));
static void set_std_cxx98 PARAMS ((int));
static void set_std_c89 PARAMS ((int, int));
#define CL_C_ONLY (1 << 0) /* Only C. */
#define CL_OBJC_ONLY (1 << 1) /* Only ObjC. */
@ -210,6 +212,8 @@ static void handle_OPT_d PARAMS ((const char *));
OPT("fweak", CL_CXX, OPT_fweak) \
OPT("fxref", CL_CXX, OPT_fxref) \
OPT("gen-decls", CL_OBJC, OPT_gen_decls) \
OPT("lang-asm", CL_C_ONLY, OPT_lang_asm) \
OPT("lang-objc", CL_ALL, OPT_lang_objc) \
OPT("nostdinc", CL_ALL, OPT_nostdinc) \
OPT("nostdinc++", CL_ALL, OPT_nostdincplusplus) \
OPT("pedantic", CL_ALL, OPT_pedantic) \
@ -220,6 +224,7 @@ static void handle_OPT_d PARAMS ((const char *));
OPT("std=c89", CL_C, OPT_std_c89) \
OPT("std=c99", CL_C, OPT_std_c99) \
OPT("std=c9x", CL_C, OPT_std_c9x) \
OPT("std=gnu++98", CL_CXX, OPT_std_gnuplusplus98) \
OPT("std=gnu89", CL_C, OPT_std_gnu89) \
OPT("std=gnu99", CL_C, OPT_std_gnu99) \
OPT("std=gnu9x", CL_C, OPT_std_gnu9x) \
@ -230,8 +235,8 @@ static void handle_OPT_d PARAMS ((const char *));
OPT("traditional-cpp", CL_ALL, OPT_traditional_cpp) \
OPT("trigraphs", CL_ALL, OPT_trigraphs) \
OPT("undef", CL_ALL, OPT_undef) \
OPT("v", CL_ALL, OPT_v) \
OPT("w", CL_ALL, OPT_w)
OPT("v", CL_ALL, OPT_v) \
OPT("w", CL_ALL, OPT_w)
#define OPT(text, flags, code) code,
enum opt_code
@ -823,6 +828,13 @@ c_common_decode_option (argc, argv)
else
warn_write_strings = on;
break;
case OPT_ansi:
if (c_language == clk_c)
set_std_c89 (false, true);
else
set_std_cxx98 (true);
break;
case OPT_d:
handle_OPT_d (arg);
@ -1071,6 +1083,14 @@ c_common_decode_option (argc, argv)
flag_gen_declaration = 1;
break;
case OPT_lang_asm:
cpp_set_lang (parse_in, CLK_ASM);
break;
case OPT_lang_objc:
cpp_opts->objc = 1;
break;
case OPT_nostdinc:
/* No default include directories. You must specify all
include-file directories with -I. */
@ -1112,30 +1132,25 @@ c_common_decode_option (argc, argv)
*/
case OPT_std_cplusplus98:
case OPT_std_gnuplusplus98:
set_std_cxx98 (code == OPT_std_cplusplus98);
break;
case OPT_std_iso9899_199409:
case OPT_std_c89:
case OPT_std_iso9899_1990:
case OPT_std_iso9899_199409:
case OPT_ansi:
/* Note: -ansi is used by both the C and C++ front ends. */
if (c_language == clk_c)
{
flag_no_asm = 1;
flag_writable_strings = 0;
}
flag_isoc94 = (code == OPT_std_iso9899_199409);
flag_no_gnu_keywords = 1;
flag_no_nonansi_builtin = 1;
flag_noniso_default_format_attributes = 0;
flag_isoc99 = 0;
flag_iso = 1;
set_std_c89 (code == OPT_std_iso9899_199409, true);
break;
case OPT_std_gnu89:
set_std_c89 (false /* c94 */, false /* ISO */);
break;
case OPT_std_c99:
case OPT_std_c9x:
case OPT_std_iso9899_1999:
case OPT_std_iso9899_199x:
cpp_set_lang (parse_in, CLK_STDC99);
flag_writable_strings = 0;
flag_no_asm = 1;
flag_no_nonansi_builtin = 1;
@ -1145,17 +1160,9 @@ c_common_decode_option (argc, argv)
flag_iso = 1;
break;
case OPT_std_gnu89:
flag_writable_strings = 0;
flag_no_asm = 0;
flag_no_nonansi_builtin = 0;
flag_noniso_default_format_attributes = 1;
flag_isoc99 = 0;
flag_isoc94 = 0;
break;
case OPT_std_gnu99:
case OPT_std_gnu9x:
cpp_set_lang (parse_in, CLK_GNUC99);
flag_writable_strings = 0;
flag_no_asm = 0;
flag_no_nonansi_builtin = 0;
@ -1238,6 +1245,35 @@ c_common_post_options ()
return flag_preprocess_only;
}
/* Set the C 89 standard (with 1994 amendments if C94, without GNU
extensions if ISO). */
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++ 98 standard (without GNU extensions if ISO). */
static void
set_std_cxx98 (iso)
int iso;
{
cpp_set_lang (parse_in, iso ? CLK_CXX98: CLK_GNUCXX);
flag_no_gnu_keywords = iso;
flag_no_nonansi_builtin = iso;
flag_noniso_default_format_attributes = !iso;
flag_iso = iso;
}
/* Handle setting implicit to ON. */
static void
set_Wimplicit (on)

View File

@ -1,3 +1,7 @@
2002-08-10 Neil Booth <neil@daikokuya.co.uk>
* lang-specs.h: Remove -ansi.
2002-08-10 Nathan Sidwell <nathan@codesourcery.com>
* tree.c (maybe_dummy_object): Replace // with /* */

View File

@ -33,16 +33,14 @@ Boston, MA 02111-1307, USA. */
{".c++", "@c++", 0},
{".C", "@c++", 0},
{"@c++",
/* We should convert -ansi to -std=c++98 even if -fpreprocessed,
to get dollars in identifiers correct. */
"%{E|M|MM:cc1plus -E %{!no-gcc:-D__GNUG__=%v1}\
%{ansi:-std=c++98} %(cpp_options) %2 %(cpp_debug_options)}\
%(cpp_options) %2 %(cpp_debug_options)}\
%{!E:%{!M:%{!MM:\
%{save-temps:cc1plus -E %{!no-gcc:-D__GNUG__=%v1}\
%{ansi:-std=c++98} %(cpp_options) %2 %b.ii \n}\
%(cpp_options) %2 %b.ii \n}\
cc1plus %{save-temps:-fpreprocessed %b.ii}\
%{!save-temps:%(cpp_unique_options) %{!no-gcc:-D__GNUG__=%v1}}\
%{ansi:-std=c++98} %(cc1_options) %2 %{+e1*}\
%(cc1_options) %2 %{+e1*}\
%{!fsyntax-only:%(invoke_as)}}}}",
CPLUSPLUS_CPP_SPEC},
{".ii", "@c++-cpp-output", 0},

View File

@ -102,7 +102,6 @@ static void merge_include_chains PARAMS ((cpp_reader *));
static bool push_include PARAMS ((cpp_reader *,
struct pending_option *));
static void free_chain PARAMS ((struct pending_option *));
static void set_lang PARAMS ((cpp_reader *, enum c_lang));
static void init_dependency_output PARAMS ((cpp_reader *));
static void init_standard_includes PARAMS ((cpp_reader *));
static void read_original_filename PARAMS ((cpp_reader *));
@ -403,8 +402,8 @@ static const struct lang_flags lang_defaults[] =
};
/* Sets internal flags correctly for a given language. */
static void
set_lang (pfile, lang)
void
cpp_set_lang (pfile, lang)
cpp_reader *pfile;
enum c_lang lang;
{
@ -471,7 +470,7 @@ cpp_create_reader (lang)
pfile = (cpp_reader *) xcalloc (1, sizeof (cpp_reader));
set_lang (pfile, lang);
cpp_set_lang (pfile, lang);
CPP_OPTION (pfile, warn_import) = 1;
CPP_OPTION (pfile, warn_multichar) = 1;
CPP_OPTION (pfile, discard_comments) = 1;
@ -1123,13 +1122,11 @@ new_pending_directive (pend, text, handler)
/* Irix6 "cc -n32" and OSF4 cc have problems with char foo[] = ("string");
I.e. a const string initializer with parens around it. That is
what N_("string") resolves to, so we make no_* be macros instead. */
#define no_arg N_("argument missing after %s")
#define no_ass N_("assertion missing after %s")
#define no_dir N_("directory name missing after %s")
#define no_fil N_("file name missing after %s")
#define no_mac N_("macro name missing after %s")
#define no_pth N_("path name missing after %s")
#define no_num N_("number missing after %s")
#define no_tgt N_("target missing after %s")
/* This is the list of all command line options, with the leading
@ -1155,24 +1152,8 @@ new_pending_directive (pend, text, handler)
DEF_OPT("isystem", no_dir, OPT_isystem) \
DEF_OPT("iwithprefix", no_dir, OPT_iwithprefix) \
DEF_OPT("iwithprefixbefore", no_dir, OPT_iwithprefixbefore) \
DEF_OPT("lang-asm", 0, OPT_lang_asm) \
DEF_OPT("lang-c", 0, OPT_lang_c) \
DEF_OPT("lang-c++", 0, OPT_lang_cplusplus) \
DEF_OPT("lang-c89", 0, OPT_lang_c89) \
DEF_OPT("lang-objc", 0, OPT_lang_objc) \
DEF_OPT("o", no_fil, OPT_o) \
DEF_OPT("remap", 0, OPT_remap) \
DEF_OPT("std=c++98", 0, OPT_std_cplusplus98) \
DEF_OPT("std=c89", 0, OPT_std_c89) \
DEF_OPT("std=c99", 0, OPT_std_c99) \
DEF_OPT("std=c9x", 0, OPT_std_c9x) \
DEF_OPT("std=gnu89", 0, OPT_std_gnu89) \
DEF_OPT("std=gnu99", 0, OPT_std_gnu99) \
DEF_OPT("std=gnu9x", 0, OPT_std_gnu9x) \
DEF_OPT("std=iso9899:1990", 0, OPT_std_iso9899_1990) \
DEF_OPT("std=iso9899:199409", 0, OPT_std_iso9899_199409) \
DEF_OPT("std=iso9899:1999", 0, OPT_std_iso9899_1999) \
DEF_OPT("std=iso9899:199x", 0, OPT_std_iso9899_199x)
DEF_OPT("remap", 0, OPT_remap)
#define DEF_OPT(text, msg, code) code,
enum opt_code
@ -1329,42 +1310,6 @@ cpp_handle_option (pfile, argc, argv)
CPP_OPTION (pfile, include_prefix) = arg;
CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
break;
case OPT_lang_c:
set_lang (pfile, CLK_GNUC89);
break;
case OPT_lang_cplusplus:
set_lang (pfile, CLK_GNUCXX);
break;
case OPT_lang_objc:
CPP_OPTION (pfile, objc) = 1;
break;
case OPT_lang_asm:
set_lang (pfile, CLK_ASM);
break;
case OPT_std_cplusplus98:
set_lang (pfile, CLK_CXX98);
break;
case OPT_std_gnu89:
set_lang (pfile, CLK_GNUC89);
break;
case OPT_std_gnu9x:
case OPT_std_gnu99:
set_lang (pfile, CLK_GNUC99);
break;
case OPT_std_iso9899_199409:
set_lang (pfile, CLK_STDC94);
break;
case OPT_std_iso9899_1990:
case OPT_std_c89:
case OPT_lang_c89:
set_lang (pfile, CLK_STDC89);
break;
case OPT_std_iso9899_199x:
case OPT_std_iso9899_1999:
case OPT_std_c9x:
case OPT_std_c99:
set_lang (pfile, CLK_STDC99);
break;
case OPT_o:
if (CPP_OPTION (pfile, out_fname) == NULL)
CPP_OPTION (pfile, out_fname) = arg;

View File

@ -504,6 +504,10 @@ struct cpp_hashnode
/* Call this first to get a handle to pass to other functions. */
extern cpp_reader *cpp_create_reader PARAMS ((enum c_lang));
/* Call this to change the selected language standard (e.g. because of
command line options). */
extern void cpp_set_lang PARAMS ((cpp_reader *, enum c_lang));
/* Call these to get pointers to the options and callback structures
for a given reader. These pointers are good until you call
cpp_finish on that reader. You can either edit the callbacks

View File

@ -326,9 +326,8 @@ option.
@itemx -ansi
@opindex ansi
@opindex std=
Specify the standard to which the code should conform. Currently cpp
only knows about the standards for C; other language standards will be
added in the future.
Specify the standard to which the code should conform. Currently CPP
knows about C and C++ standards; others may be added in the future.
@var{standard}
may be one of:
@ -356,6 +355,13 @@ The 1990 C standard plus GNU extensions. This is the default.
@item gnu99
@itemx gnu9x
The 1999 C standard plus GNU extensions.
@item c++98
The 1998 ISO C++ standard plus amendments.
@item gnu++98
The same as @option{-std=c++98} plus GNU extensions. This is the
default for C++ code.
@end table
@item -I-

View File

@ -1009,8 +1009,8 @@ affected.
@item -std=
@opindex std
Determine the language standard. This option is currently only
supported when compiling C@. A value for this option must be provided;
possible values are
supported when compiling C or C++. A value for this option must be
provided; possible values are
@table @samp
@item c89
@ -1036,6 +1036,12 @@ Default, ISO C90 plus GNU extensions (including some C99 features).
ISO C99 plus GNU extensions. When ISO C99 is fully implemented in GCC,
this will become the default. The name @samp{gnu9x} is deprecated.
@item c++98
The 1998 ISO C++ standard plus amendments.
@item gnu++98
The same as @option{-std=c++98} plus GNU extensions. This is the
default for C++ code.
@end table
Even when this option is not specified, you can still use some of the

View File

@ -829,24 +829,23 @@ static const struct compiler default_compilers[] =
{"@c",
/* cc1 has an integrated ISO C preprocessor. We should invoke the
external preprocessor if -save-temps is given. */
"%{E|M|MM:%(trad_capable_cpp) %{ansi:-std=c89} %(cpp_options)\
%(cpp_debug_options)}\
"%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\
%{!E:%{!M:%{!MM:\
%{traditional|ftraditional:\
%eGNU C no longer supports -traditional without -E}\
%{save-temps|traditional-cpp:%(trad_capable_cpp) \
%{ansi:-std=c89} %(cpp_options) %b.i \n\
%(cpp_options) %b.i \n\
cc1 -fpreprocessed %b.i %(cc1_options)}\
%{!save-temps:%{!traditional-cpp:\
cc1 %{ansi:-std=c89} %(cpp_unique_options) %(cc1_options)}}\
cc1 %(cpp_unique_options) %(cc1_options)}}\
%{!fsyntax-only:%(invoke_as)}}}}", 0},
{"-",
"%{!E:%e-E required when input is from standard input}\
%(trad_capable_cpp) %{ansi:-std=c89} %(cpp_options)", 0},
%(trad_capable_cpp) %(cpp_options)", 0},
{".h", "@c-header", 0},
{"@c-header",
"%{!E:%ecompilation of header file requested} \
%(trad_capable_cpp) %{ansi:-std=c89} %(cpp_options) %(cpp_debug_options)",
%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)",
0},
{".i", "@cpp-output", 0},
{"@cpp-output",

View File

@ -26,15 +26,14 @@ Boston, MA 02111-1307, USA. */
/* cc1obj has an integrated ISO C preprocessor. We should invoke the
external preprocessor if -save-temps or -traditional is given. */
"%{E|M|MM:%(trad_capable_cpp)\
-lang-objc %{ansi:-std=c89} %(cpp_options) %(cpp_debug_options)}\
-lang-objc %(cpp_options) %(cpp_debug_options)}\
%{!E:%{!M:%{!MM:\
%{traditional|ftraditional|traditional-cpp:\
%eGNU Objective C no longer supports traditional compilation}\
%{save-temps:cc1obj -E %{ansi:-std=c89}\
%(cpp_options) %b.mi \n\
%{save-temps:cc1obj -E %(cpp_options) %b.mi \n\
cc1obj -fpreprocessed %b.mi %(cc1_options) %{gen-decls}}\
%{!save-temps:\
cc1obj %{ansi:-std=c89} %(cpp_unique_options) %(cc1_options) %{gen-decls}}\
cc1obj %(cpp_unique_options) %(cc1_options) %{gen-decls}}\
%{!fsyntax-only:%(invoke_as)}}}}", 0},
{".mi", "@objc-cpp-output", 0},
{"@objc-cpp-output",