c-lang.c (lang_init_options): Update call to cpp_reader_init.

* c-lang.c (lang_init_options): Update call to
	cpp_reader_init.
	* cppmain.c (main): Similarly.
	* fix-header.c (read_scan_file): Similarly.
	* cp/lex.c (lang_init_options): Similarly.
	* objc/objc-act.c (lang_init_options): Similarly.
	* cppexp.c (parse_number): Only warn for unextended C89.
	* cppinit.c (set_lang): New function.
	(cpp_reader_init): Take a LANG argument and pass it to set_lang.
	(COMMAND_LINE_OPTIONS): New option std=c++98.
	(cpp_handle_option): Use set_lang.
	* cpplib.h (enum_c_lang): New enumeration.  Update comments.

From-SVN: r37587
This commit is contained in:
Neil Booth 2000-11-20 18:27:32 +00:00 committed by Neil Booth
parent 4de5a4d99a
commit dd07b88447
9 changed files with 182 additions and 98 deletions

View file

@ -1,3 +1,19 @@
2000-11-20 Neil Booth <neilb@earthling.net>
* c-lang.c (lang_init_options): Update call to
cpp_reader_init.
* cppmain.c (main): Similarly.
* fix-header.c (read_scan_file): Similarly.
* cp/lex.c (lang_init_options): Similarly.
* objc/objc-act.c (lang_init_options): Similarly.
* cppexp.c (parse_number): Only warn for unextended C89.
* cppinit.c (set_lang): New function.
(cpp_reader_init): Take a LANG argument and pass it to set_lang.
(COMMAND_LINE_OPTIONS): New option std=c++98.
(cpp_handle_option): Use set_lang.
* cpplex.c (_cpp_lex_token): Warn pedantically if not C99.
* cppib.h (enum_c_lang): New enumeration. Update comments.
2000-11-20 Will Cohen <wcohen@redhat.com> 2000-11-20 Will Cohen <wcohen@redhat.com>
* calls.c (expand_call): Clear target only when target is in * calls.c (expand_call): Clear target only when target is in

View file

@ -58,7 +58,7 @@ lang_init_options ()
{ {
#if USE_CPPLIB #if USE_CPPLIB
cpp_init (); cpp_init ();
cpp_reader_init (&parse_in); cpp_reader_init (&parse_in, CLK_GNUC89);
#endif #endif
/* Mark as "unspecified". */ /* Mark as "unspecified". */
flag_bounds_check = -1; flag_bounds_check = -1;

View file

@ -254,7 +254,7 @@ lang_init_options ()
{ {
#if USE_CPPLIB #if USE_CPPLIB
cpp_init (); cpp_init ();
cpp_reader_init (&parse_in); cpp_reader_init (&parse_in, CLK_GNUC89);
#endif #endif
/* Default exceptions on. */ /* Default exceptions on. */

View file

@ -205,7 +205,9 @@ parse_number (pfile, tok)
if (CPP_WTRADITIONAL (pfile) && sufftab[i].u) if (CPP_WTRADITIONAL (pfile) && sufftab[i].u)
cpp_warning (pfile, "traditional C rejects the `U' suffix"); cpp_warning (pfile, "traditional C rejects the `U' suffix");
if (CPP_OPTION (pfile, c89) && sufftab[i].l == 2) if (CPP_OPTION (pfile, c89)
&& sufftab[i].l == 2
&& pfile->spec_nodes.n__STRICT_ANSI__->type == NT_MACRO)
SYNTAX_ERROR ("too many 'l' suffixes in integer constant"); SYNTAX_ERROR ("too many 'l' suffixes in integer constant");
} }

View file

@ -105,6 +105,7 @@ static void merge_include_chains PARAMS ((cpp_reader *));
static void do_includes PARAMS ((cpp_reader *, static void do_includes PARAMS ((cpp_reader *,
struct pending_option *, struct pending_option *,
int)); int));
static void set_lang PARAMS ((cpp_reader *, enum c_lang));
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 *,
@ -421,10 +422,111 @@ cpp_init ()
cpp_init_completed = 1; cpp_init_completed = 1;
} }
/* Sets internal flags correctly for a given language, and defines
macros if necessary. */
static void
set_lang (pfile, lang)
cpp_reader *pfile;
enum c_lang lang;
{
struct cpp_pending *pend = CPP_OPTION (pfile, pending);
/* Default to zero. */
CPP_OPTION (pfile, lang_asm) = 0;
CPP_OPTION (pfile, objc) = 0;
CPP_OPTION (pfile, cplusplus) = 0;
switch (lang)
{
/* GNU C. */
case CLK_GNUC99:
CPP_OPTION (pfile, trigraphs) = 0;
CPP_OPTION (pfile, dollars_in_ident) = 1;
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, c89) = 0;
CPP_OPTION (pfile, c99) = 1;
new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
break;
case CLK_GNUC89:
CPP_OPTION (pfile, trigraphs) = 0;
CPP_OPTION (pfile, dollars_in_ident) = 1;
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, c89) = 1;
CPP_OPTION (pfile, c99) = 0;
break;
/* ISO C. */
case CLK_STDC94:
new_pending_directive (pend, "__STDC_VERSION__=199409L", cpp_define);
case CLK_STDC89:
CPP_OPTION (pfile, trigraphs) = 1;
CPP_OPTION (pfile, dollars_in_ident) = 0;
CPP_OPTION (pfile, cplusplus_comments) = 0;
CPP_OPTION (pfile, digraphs) = lang == CLK_STDC94;
CPP_OPTION (pfile, c89) = 1;
CPP_OPTION (pfile, c99) = 0;
new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
break;
case CLK_STDC99:
CPP_OPTION (pfile, trigraphs) = 1;
CPP_OPTION (pfile, dollars_in_ident) = 0;
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, c89) = 0;
CPP_OPTION (pfile, c99) = 1;
new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
break;
/* Objective C. */
case CLK_OBJCXX:
new_pending_directive (pend, "__cplusplus", cpp_define);
CPP_OPTION (pfile, cplusplus) = 1;
case CLK_OBJC:
CPP_OPTION (pfile, trigraphs) = 0;
CPP_OPTION (pfile, dollars_in_ident) = 1;
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, c89) = 0;
CPP_OPTION (pfile, c99) = 0;
CPP_OPTION (pfile, objc) = 1;
new_pending_directive (pend, "__OBJC__", cpp_define);
break;
/* C++. */
case CLK_GNUCXX:
case CLK_CXX98:
CPP_OPTION (pfile, cplusplus) = 1;
CPP_OPTION (pfile, trigraphs) = lang == CLK_CXX98;
CPP_OPTION (pfile, dollars_in_ident) = lang == CLK_GNUCXX;
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, c89) = 0;
CPP_OPTION (pfile, c99) = 0;
new_pending_directive (pend, "__cplusplus", cpp_define);
break;
/* Assembler. */
case CLK_ASM:
CPP_OPTION (pfile, trigraphs) = 0;
CPP_OPTION (pfile, dollars_in_ident) = 0; /* Maybe not? */
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, digraphs) = 0;
CPP_OPTION (pfile, c89) = 0;
CPP_OPTION (pfile, c99) = 0;
CPP_OPTION (pfile, lang_asm) = 1;
new_pending_directive (pend, "__ASSEMBLER__", cpp_define);
break;
}
}
/* Initialize a cpp_reader structure. */ /* Initialize a cpp_reader structure. */
void void
cpp_reader_init (pfile) cpp_reader_init (pfile, lang)
cpp_reader *pfile; cpp_reader *pfile;
enum c_lang lang;
{ {
struct spec_nodes *s; struct spec_nodes *s;
@ -439,11 +541,9 @@ cpp_reader_init (pfile)
cpp_init (); cpp_init ();
} }
CPP_OPTION (pfile, dollars_in_ident) = 1; set_lang (pfile, lang);
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, warn_import) = 1; CPP_OPTION (pfile, warn_import) = 1;
CPP_OPTION (pfile, warn_paste) = 1; CPP_OPTION (pfile, warn_paste) = 1;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, discard_comments) = 1; CPP_OPTION (pfile, discard_comments) = 1;
CPP_OPTION (pfile, show_column) = 1; CPP_OPTION (pfile, show_column) = 1;
CPP_OPTION (pfile, tabstop) = 8; CPP_OPTION (pfile, tabstop) = 8;
@ -1077,6 +1177,7 @@ new_pending_directive (pend, text, handler)
DEF_OPT("pedantic", 0, OPT_pedantic) \ DEF_OPT("pedantic", 0, OPT_pedantic) \
DEF_OPT("pedantic-errors", 0, OPT_pedantic_errors) \ DEF_OPT("pedantic-errors", 0, OPT_pedantic_errors) \
DEF_OPT("remap", 0, OPT_remap) \ 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=c89", 0, OPT_std_c89) \
DEF_OPT("std=c99", 0, OPT_std_c99) \ DEF_OPT("std=c99", 0, OPT_std_c99) \
DEF_OPT("std=c9x", 0, OPT_std_c9x) \ DEF_OPT("std=c9x", 0, OPT_std_c9x) \
@ -1324,37 +1425,43 @@ 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_lang_c: case OPT_lang_c:
CPP_OPTION (pfile, cplusplus) = 0; set_lang (pfile, CLK_GNUC89);
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, c89) = 0;
CPP_OPTION (pfile, c99) = 1;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, objc) = 0;
break; break;
case OPT_lang_cplusplus: case OPT_lang_cplusplus:
CPP_OPTION (pfile, cplusplus) = 1; set_lang (pfile, CLK_GNUCXX);
CPP_OPTION (pfile, cplusplus_comments) = 1; break;
CPP_OPTION (pfile, c89) = 0; case OPT_lang_objc:
CPP_OPTION (pfile, c99) = 0; set_lang (pfile, CLK_OBJC);
CPP_OPTION (pfile, objc) = 0;
CPP_OPTION (pfile, digraphs) = 1;
new_pending_directive (pend, "__cplusplus", cpp_define);
break; break;
case OPT_lang_objcplusplus: case OPT_lang_objcplusplus:
CPP_OPTION (pfile, cplusplus) = 1; set_lang (pfile, CLK_OBJCXX);
new_pending_directive (pend, "__cplusplus", cpp_define);
/* fall through */
case OPT_lang_objc:
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, c89) = 0;
CPP_OPTION (pfile, c99) = 0;
CPP_OPTION (pfile, objc) = 1;
new_pending_directive (pend, "__OBJC__", cpp_define);
break; break;
case OPT_lang_asm: case OPT_lang_asm:
CPP_OPTION (pfile, lang_asm) = 1; set_lang (pfile, CLK_ASM);
CPP_OPTION (pfile, dollars_in_ident) = 0; break;
new_pending_directive (pend, "__ASSEMBLER__", cpp_define); 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; break;
case OPT_nostdinc: case OPT_nostdinc:
/* -nostdinc causes no default include directories. /* -nostdinc causes no default include directories.
@ -1365,53 +1472,6 @@ cpp_handle_option (pfile, argc, argv)
/* -nostdinc++ causes no default C++-specific include directories. */ /* -nostdinc++ causes no default C++-specific include directories. */
CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1; CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
break; break;
case OPT_std_gnu89:
CPP_OPTION (pfile, cplusplus) = 0;
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, c89) = 1;
CPP_OPTION (pfile, c99) = 0;
CPP_OPTION (pfile, objc) = 0;
CPP_OPTION (pfile, digraphs) = 1;
break;
case OPT_std_gnu9x:
case OPT_std_gnu99:
CPP_OPTION (pfile, cplusplus) = 0;
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, c89) = 0;
CPP_OPTION (pfile, c99) = 1;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, objc) = 0;
new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
break;
case OPT_std_iso9899_199409:
new_pending_directive (pend, "__STDC_VERSION__=199409L", cpp_define);
/* Fall through */
case OPT_std_iso9899_1990:
case OPT_std_c89:
case OPT_lang_c89:
CPP_OPTION (pfile, cplusplus) = 0;
CPP_OPTION (pfile, cplusplus_comments) = 0;
CPP_OPTION (pfile, c89) = 1;
CPP_OPTION (pfile, c99) = 0;
CPP_OPTION (pfile, objc) = 0;
CPP_OPTION (pfile, digraphs) = opt_code == OPT_std_iso9899_199409;
CPP_OPTION (pfile, trigraphs) = 1;
new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
break;
case OPT_std_iso9899_199x:
case OPT_std_iso9899_1999:
case OPT_std_c9x:
case OPT_std_c99:
CPP_OPTION (pfile, cplusplus) = 0;
CPP_OPTION (pfile, cplusplus_comments) = 1;
CPP_OPTION (pfile, c89) = 0;
CPP_OPTION (pfile, c99) = 1;
CPP_OPTION (pfile, objc) = 0;
CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, trigraphs) = 1;
new_pending_directive (pend, "__STRICT_ANSI__", cpp_define);
new_pending_directive (pend, "__STDC_VERSION__=199901L", cpp_define);
break;
case OPT_o: case OPT_o:
if (CPP_OPTION (pfile, out_fname) != NULL) if (CPP_OPTION (pfile, out_fname) != NULL)
{ {

View file

@ -152,6 +152,10 @@ enum cpp_ttype
#undef OP #undef OP
#undef TK #undef TK
/* C language kind, used when calling cpp_reader_init. */
enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_STDC89, CLK_STDC94, CLK_STDC99,
CLK_GNUCXX, CLK_CXX98, CLK_OBJC, CLK_OBJCXX, CLK_ASM};
/* Multiple-include optimisation. */ /* Multiple-include optimisation. */
enum mi_state {MI_FAILED = 0, MI_OUTSIDE}; enum mi_state {MI_FAILED = 0, MI_OUTSIDE};
enum mi_ind {MI_IND_NONE = 0, MI_IND_NOT}; enum mi_ind {MI_IND_NONE = 0, MI_IND_NOT};
@ -168,7 +172,7 @@ struct cpp_string
#define DIGRAPH (1 << 1) /* If it was a digraph. */ #define DIGRAPH (1 << 1) /* If it was a digraph. */
#define STRINGIFY_ARG (1 << 2) /* If macro argument to be stringified. */ #define STRINGIFY_ARG (1 << 2) /* If macro argument to be stringified. */
#define PASTE_LEFT (1 << 3) /* If on LHS of a ## operator. */ #define PASTE_LEFT (1 << 3) /* If on LHS of a ## operator. */
#define NAMED_OP (1 << 4) /* C++ named operators, also "defined". */ #define NAMED_OP (1 << 4) /* C++ named operators. */
#define NO_EXPAND (1 << 5) /* Do not macro-expand this token. */ #define NO_EXPAND (1 << 5) /* Do not macro-expand this token. */
/* A preprocessing token. This has been carefully packed and should /* A preprocessing token. This has been carefully packed and should
@ -518,7 +522,7 @@ struct spec_nodes
cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */ cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */
}; };
/* a cpp_reader encapsulates the "state" of a pre-processor run. /* A cpp_reader encapsulates the "state" of a pre-processor run.
Applying cpp_get_token repeatedly yields a stream of pre-processor Applying cpp_get_token repeatedly yields a stream of pre-processor
tokens. Usually, there is only one cpp_reader object active. */ tokens. Usually, there is only one cpp_reader object active. */
@ -711,33 +715,34 @@ union tree_node;
struct cpp_hashnode struct cpp_hashnode
{ {
const unsigned char *name; /* null-terminated name */ const unsigned char *name; /* Null-terminated name. */
unsigned int hash; /* cached hash value */ unsigned int hash; /* Cached hash value. */
unsigned short length; /* length of name excluding null */ unsigned short length; /* Length of name excluding null. */
unsigned short arg_index; /* macro argument index */ unsigned short arg_index; /* Macro argument index. */
unsigned char directive_index; /* index into directive table. */ unsigned char directive_index; /* Index into directive table. */
ENUM_BITFIELD(node_type) type : 8; /* node type. */ ENUM_BITFIELD(node_type) type : 8; /* Node type. */
unsigned char flags; /* node flags. */ unsigned char flags; /* Node flags. */
union union
{ {
cpp_macro *macro; /* a macro. */ cpp_macro *macro; /* If a macro. */
struct answer *answers; /* answers to an assertion. */ struct answer *answers; /* Answers to an assertion. */
enum cpp_ttype operator; /* code for a named operator. */ enum cpp_ttype operator; /* Code for a named operator. */
enum builtin_type builtin; /* code for a builtin macro. */ enum builtin_type builtin; /* Code for a builtin macro. */
} value; } value;
union tree_node *fe_value; /* front end value */ union tree_node *fe_value; /* Front end value. */
}; };
extern unsigned int cpp_token_len PARAMS ((const cpp_token *)); extern unsigned int cpp_token_len PARAMS ((const cpp_token *));
extern unsigned char *cpp_token_as_text PARAMS ((cpp_reader *, const cpp_token *)); extern unsigned char *cpp_token_as_text PARAMS ((cpp_reader *,
const cpp_token *));
extern unsigned char *cpp_spell_token PARAMS ((cpp_reader *, const cpp_token *, extern unsigned char *cpp_spell_token PARAMS ((cpp_reader *, const cpp_token *,
unsigned char *)); unsigned char *));
extern void cpp_init PARAMS ((void)); extern void cpp_init PARAMS ((void));
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_reader_init PARAMS ((cpp_reader *)); extern void cpp_reader_init PARAMS ((cpp_reader *, enum c_lang));
extern void cpp_register_pragma PARAMS ((cpp_reader *, extern void cpp_register_pragma PARAMS ((cpp_reader *,
const char *, const char *, const char *, const char *,

View file

@ -87,7 +87,8 @@ main (argc, argv)
(void) textdomain (PACKAGE); (void) textdomain (PACKAGE);
cpp_init (); cpp_init ();
cpp_reader_init (pfile); /* Default language is GNU C89. */
cpp_reader_init (pfile, CLK_GNUC89);
argi += cpp_handle_options (pfile, argc - argi , argv + argi); argi += cpp_handle_options (pfile, argc - argi , argv + argi);
if (argi < argc && ! CPP_FATAL_ERRORS (pfile)) if (argi < argc && ! CPP_FATAL_ERRORS (pfile))

View file

@ -611,7 +611,7 @@ read_scan_file (in_fname, argc, argv)
obstack_init (&scan_file_obstack); obstack_init (&scan_file_obstack);
cpp_init (); /* Initialize cpplib. */ cpp_init (); /* Initialize cpplib. */
cpp_reader_init (&scan_in); cpp_reader_init (&scan_in, CLK_GNUC89);
/* We are going to be scanning a header file out of its proper context, /* We are going to be scanning a header file out of its proper context,
so ignore warnings and errors. */ so ignore warnings and errors. */

View file

@ -700,7 +700,7 @@ lang_init_options ()
{ {
#if USE_CPPLIB #if USE_CPPLIB
cpp_init (); cpp_init ();
cpp_reader_init (&parse_in); cpp_reader_init (&parse_in, CLK_GNUC89);
#endif #endif
} }