aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNeil Booth <neilb@earthling.net>2000-11-20 18:27:32 +0000
committerNeil Booth <neil@gcc.gnu.org>2000-11-20 18:27:32 +0000
commitdd07b88447abe48d1ec82b7e3fd7c2d95493b7e8 (patch)
tree24d965cfca605ecaa67abda32d7a2c64f3ee143c /gcc
parent4de5a4d99adf55dc93302dd284123dca93f50896 (diff)
downloadgcc-dd07b88447abe48d1ec82b7e3fd7c2d95493b7e8.zip
gcc-dd07b88447abe48d1ec82b7e3fd7c2d95493b7e8.tar.gz
gcc-dd07b88447abe48d1ec82b7e3fd7c2d95493b7e8.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog16
-rw-r--r--gcc/c-lang.c2
-rw-r--r--gcc/cp/lex.c2
-rw-r--r--gcc/cppexp.c4
-rw-r--r--gcc/cppinit.c198
-rw-r--r--gcc/cpplib.h37
-rw-r--r--gcc/cppmain.c3
-rw-r--r--gcc/fix-header.c2
-rw-r--r--gcc/objc/objc-act.c2
9 files changed, 175 insertions, 91 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 200ecc5..6bc280d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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>
* calls.c (expand_call): Clear target only when target is in
diff --git a/gcc/c-lang.c b/gcc/c-lang.c
index 7259429..1c9fe38 100644
--- a/gcc/c-lang.c
+++ b/gcc/c-lang.c
@@ -58,7 +58,7 @@ lang_init_options ()
{
#if USE_CPPLIB
cpp_init ();
- cpp_reader_init (&parse_in);
+ cpp_reader_init (&parse_in, CLK_GNUC89);
#endif
/* Mark as "unspecified". */
flag_bounds_check = -1;
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index b0553e0..7e7da03 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -254,7 +254,7 @@ lang_init_options ()
{
#if USE_CPPLIB
cpp_init ();
- cpp_reader_init (&parse_in);
+ cpp_reader_init (&parse_in, CLK_GNUC89);
#endif
/* Default exceptions on. */
diff --git a/gcc/cppexp.c b/gcc/cppexp.c
index 98bd94e..6665380 100644
--- a/gcc/cppexp.c
+++ b/gcc/cppexp.c
@@ -205,7 +205,9 @@ parse_number (pfile, tok)
if (CPP_WTRADITIONAL (pfile) && sufftab[i].u)
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");
}
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index 095e6d4..f8394e4 100644
--- a/gcc/cppinit.c
+++ b/gcc/cppinit.c
@@ -105,6 +105,7 @@ static void merge_include_chains PARAMS ((cpp_reader *));
static void do_includes PARAMS ((cpp_reader *,
struct pending_option *,
int));
+static void set_lang PARAMS ((cpp_reader *, enum c_lang));
static void initialize_dependency_output PARAMS ((cpp_reader *));
static void initialize_standard_includes PARAMS ((cpp_reader *));
static void new_pending_directive PARAMS ((struct cpp_pending *,
@@ -421,10 +422,111 @@ cpp_init ()
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. */
void
-cpp_reader_init (pfile)
+cpp_reader_init (pfile, lang)
cpp_reader *pfile;
+ enum c_lang lang;
{
struct spec_nodes *s;
@@ -439,11 +541,9 @@ cpp_reader_init (pfile)
cpp_init ();
}
- CPP_OPTION (pfile, dollars_in_ident) = 1;
- CPP_OPTION (pfile, cplusplus_comments) = 1;
+ set_lang (pfile, lang);
CPP_OPTION (pfile, warn_import) = 1;
CPP_OPTION (pfile, warn_paste) = 1;
- CPP_OPTION (pfile, digraphs) = 1;
CPP_OPTION (pfile, discard_comments) = 1;
CPP_OPTION (pfile, show_column) = 1;
CPP_OPTION (pfile, tabstop) = 8;
@@ -1077,6 +1177,7 @@ new_pending_directive (pend, text, handler)
DEF_OPT("pedantic", 0, OPT_pedantic) \
DEF_OPT("pedantic-errors", 0, OPT_pedantic_errors) \
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) \
@@ -1324,93 +1425,52 @@ cpp_handle_option (pfile, argc, argv)
CPP_OPTION (pfile, include_prefix_len) = strlen (arg);
break;
case OPT_lang_c:
- 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;
+ set_lang (pfile, CLK_GNUC89);
break;
case OPT_lang_cplusplus:
- CPP_OPTION (pfile, cplusplus) = 1;
- CPP_OPTION (pfile, cplusplus_comments) = 1;
- CPP_OPTION (pfile, c89) = 0;
- CPP_OPTION (pfile, c99) = 0;
- CPP_OPTION (pfile, objc) = 0;
- CPP_OPTION (pfile, digraphs) = 1;
- new_pending_directive (pend, "__cplusplus", cpp_define);
+ set_lang (pfile, CLK_GNUCXX);
break;
- case OPT_lang_objcplusplus:
- CPP_OPTION (pfile, cplusplus) = 1;
- 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);
+ set_lang (pfile, CLK_OBJC);
break;
- case OPT_lang_asm:
- CPP_OPTION (pfile, lang_asm) = 1;
- CPP_OPTION (pfile, dollars_in_ident) = 0;
- new_pending_directive (pend, "__ASSEMBLER__", cpp_define);
+ case OPT_lang_objcplusplus:
+ set_lang (pfile, CLK_OBJCXX);
break;
- case OPT_nostdinc:
- /* -nostdinc causes no default include directories.
- You must specify all include-file directories with -I. */
- CPP_OPTION (pfile, no_standard_includes) = 1;
+ case OPT_lang_asm:
+ set_lang (pfile, CLK_ASM);
break;
- case OPT_nostdincplusplus:
- /* -nostdinc++ causes no default C++-specific include directories. */
- CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
+ case OPT_std_cplusplus98:
+ set_lang (pfile, CLK_CXX98);
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;
+ set_lang (pfile, CLK_GNUC89);
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);
+ set_lang (pfile, CLK_GNUC99);
break;
case OPT_std_iso9899_199409:
- new_pending_directive (pend, "__STDC_VERSION__=199409L", cpp_define);
- /* Fall through */
+ set_lang (pfile, CLK_STDC94);
+ break;
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);
+ set_lang (pfile, CLK_STDC89);
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);
+ set_lang (pfile, CLK_STDC99);
+ break;
+ case OPT_nostdinc:
+ /* -nostdinc causes no default include directories.
+ You must specify all include-file directories with -I. */
+ CPP_OPTION (pfile, no_standard_includes) = 1;
+ break;
+ case OPT_nostdincplusplus:
+ /* -nostdinc++ causes no default C++-specific include directories. */
+ CPP_OPTION (pfile, no_standard_cplusplus_includes) = 1;
break;
case OPT_o:
if (CPP_OPTION (pfile, out_fname) != NULL)
diff --git a/gcc/cpplib.h b/gcc/cpplib.h
index 8c1a439..5922f94 100644
--- a/gcc/cpplib.h
+++ b/gcc/cpplib.h
@@ -152,6 +152,10 @@ enum cpp_ttype
#undef OP
#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. */
enum mi_state {MI_FAILED = 0, MI_OUTSIDE};
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 STRINGIFY_ARG (1 << 2) /* If macro argument to be stringified. */
#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. */
/* 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 */
};
-/* 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
tokens. Usually, there is only one cpp_reader object active. */
@@ -711,33 +715,34 @@ union tree_node;
struct cpp_hashnode
{
- const unsigned char *name; /* null-terminated name */
- unsigned int hash; /* cached hash value */
- unsigned short length; /* length of name excluding null */
- unsigned short arg_index; /* macro argument index */
- unsigned char directive_index; /* index into directive table. */
- ENUM_BITFIELD(node_type) type : 8; /* node type. */
- unsigned char flags; /* node flags. */
+ const unsigned char *name; /* Null-terminated name. */
+ unsigned int hash; /* Cached hash value. */
+ unsigned short length; /* Length of name excluding null. */
+ unsigned short arg_index; /* Macro argument index. */
+ unsigned char directive_index; /* Index into directive table. */
+ ENUM_BITFIELD(node_type) type : 8; /* Node type. */
+ unsigned char flags; /* Node flags. */
union
{
- cpp_macro *macro; /* a macro. */
- struct answer *answers; /* answers to an assertion. */
- enum cpp_ttype operator; /* code for a named operator. */
- enum builtin_type builtin; /* code for a builtin macro. */
+ cpp_macro *macro; /* If a macro. */
+ struct answer *answers; /* Answers to an assertion. */
+ enum cpp_ttype operator; /* Code for a named operator. */
+ enum builtin_type builtin; /* Code for a builtin macro. */
} 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 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 *,
unsigned char *));
extern void cpp_init PARAMS ((void));
extern int cpp_handle_options 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 *,
const char *, const char *,
diff --git a/gcc/cppmain.c b/gcc/cppmain.c
index ca966fc..d530e7d 100644
--- a/gcc/cppmain.c
+++ b/gcc/cppmain.c
@@ -87,7 +87,8 @@ main (argc, argv)
(void) textdomain (PACKAGE);
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);
if (argi < argc && ! CPP_FATAL_ERRORS (pfile))
diff --git a/gcc/fix-header.c b/gcc/fix-header.c
index be377de..b313848 100644
--- a/gcc/fix-header.c
+++ b/gcc/fix-header.c
@@ -611,7 +611,7 @@ read_scan_file (in_fname, argc, argv)
obstack_init (&scan_file_obstack);
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,
so ignore warnings and errors. */
diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c
index bea5844..b1b0279 100644
--- a/gcc/objc/objc-act.c
+++ b/gcc/objc/objc-act.c
@@ -700,7 +700,7 @@ lang_init_options ()
{
#if USE_CPPLIB
cpp_init ();
- cpp_reader_init (&parse_in);
+ cpp_reader_init (&parse_in, CLK_GNUC89);
#endif
}