diff options
author | Neil Booth <neil@daikokuya.demon.co.uk> | 2002-05-09 22:48:36 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2002-05-09 22:48:36 +0000 |
commit | 3df892916c733cfa42ffa9eaaab1c115ebfe45ce (patch) | |
tree | 8450e93598f1089a0cde24353bf2a3ffbbdee87e /gcc/c-common.c | |
parent | 32fa4565a7d89525a0577f2bffed598f1d1d9194 (diff) | |
download | gcc-3df892916c733cfa42ffa9eaaab1c115ebfe45ce.zip gcc-3df892916c733cfa42ffa9eaaab1c115ebfe45ce.tar.gz gcc-3df892916c733cfa42ffa9eaaab1c115ebfe45ce.tar.bz2 |
Makefile.in: Update.
* Makefile.in: Update.
* c-common.c (flag_iso, flag_undef, cb_register_builtins,
builtin_define_std): New.
(c_common_init): Register CPP builtins callback.
* c-common.h (flag_iso, flag_undef): New.
* c-decl.c (c_decode_option): Set flag_iso and flag_undef.
* c-lex.c: Don't include target.h.
(cb_register_builtins): Move to c-common.c.
(init_c_lex): Don't register hook here.
* c-lex.h (builtin_define, builtin_assert, builtin_define_std): New.
(cpp_define, cpp_assert): Remove.
* gcc.c (cc1_options): Pass -undef to front end.
* target-def.h (TARGET_REGISTER_CPP_BUILTINS): Remove.
(TARGET_INITIALIZER): Update.
* target.h (struct cpp_reader): Don't predeclare.
(struct gcc_target): Remove cpp builtin hook.
* tree.c (default_register_cpp_builtins): Remove.
cp:
* cp-tree.h (flag_ansi): Remove.
* decl2.c (flag_ansi): Remove.
(cxx_decode_option): Set flag_iso and flag_undef.
doc:
* tm.texi: Update.
From-SVN: r53349
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r-- | gcc/c-common.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c index b23bcfe..59a0b7f 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -184,6 +184,14 @@ tree c_global_trees[CTI_MAX]; /* Nonzero if prepreprocessing only. */ int flag_preprocess_only; +/* Nonzero if an ISO standard was selected. It rejects macros in the + user's namespace. */ +int flag_iso; + +/* Nonzero if -undef was given. It suppresses target built-in macros + and assertions. */ +int flag_undef; + /* Nonzero means don't recognize the non-ANSI builtin functions. */ int flag_no_builtin; @@ -275,6 +283,8 @@ static int if_stack_space = 0; /* Stack pointer. */ static int if_stack_pointer = 0; +static void cb_register_builtins PARAMS ((cpp_reader *)); + static tree handle_packed_attribute PARAMS ((tree *, tree, tree, int, bool *)); static tree handle_nocommon_attribute PARAMS ((tree *, tree, tree, int, @@ -4298,6 +4308,73 @@ c_common_post_options () warning ("-Wmissing-format-attribute ignored without -Wformat"); } +/* Hook that registers front end and target-specific built-ins. */ +static void +cb_register_builtins (pfile) + cpp_reader *pfile; +{ + /* -undef turns off target-specific built-ins. */ + if (flag_undef) + return; + + if (c_language == clk_cplusplus) + { + if (SUPPORTS_ONE_ONLY) + cpp_define (pfile, "__GXX_WEAK__"); + else + cpp_define (pfile, "__GXX_WEAK__=0"); + } + + /* A straightforward target hook doesn't work, because of problems + linking that hook's body when part of non-C front ends. */ +#ifdef TARGET_REGISTER_CPP_BUILTINS + TARGET_REGISTER_CPP_BUILTINS; +#endif +} + +/* Pass an object-like macro. If it doesn't lie in the user's + namespace, defines it unconditionally. Otherwise define a version + with two leading underscores, and another version with two leading + and trailing underscores, and define the original only if an ISO + standard was not nominated. + + e.g. passing "unix" defines "__unix", "__unix__" and possibly + "unix". Passing "_mips" defines "__mips", "__mips__" and possibly + "_mips". */ +void +builtin_define_std (macro) + const char *macro; +{ + size_t len = strlen (macro); + char *buff = alloca (len + 5); + char *p = buff + 2; + char *q = p + len; + + /* prepend __ (or maybe just _) if in user's namespace. */ + memcpy (p, macro, len + 1); + if (*p != '_') + *--p = '_'; + if (p[1] != '_' && !ISUPPER (p[1])) + *--p = '_'; + cpp_define (parse_in, p); + + /* If it was in user's namespace... */ + if (p != buff + 2) + { + /* Define the original macro if permitted. */ + if (!flag_iso) + cpp_define (parse_in, macro); + + /* Define the macro with leading and following __. */ + if (q[-1] != '_') + *q++ = '_'; + if (q[-2] != '_') + *q++ = '_'; + *q = '\0'; + cpp_define (parse_in, p); + } +} + /* Front end initialization common to C, ObjC and C++. */ const char * c_common_init (filename) @@ -4322,6 +4399,10 @@ c_common_init (filename) options->warn_multichar = warn_multichar; + /* Register preprocessor built-ins before calls to + cpp_main_file. */ + cpp_get_callbacks (parse_in)->register_builtins = cb_register_builtins; + /* NULL is passed up to toplev.c and we exit quickly. */ if (flag_preprocess_only) { |