Makefile.in: Update.
authorNeil Booth <neil@daikokuya.demon.co.uk>
Thu, 9 May 2002 22:48:36 +0000 (22:48 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Thu, 9 May 2002 22:48:36 +0000 (22:48 +0000)
* 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

15 files changed:
gcc/ChangeLog
gcc/Makefile.in
gcc/c-common.c
gcc/c-common.h
gcc/c-decl.c
gcc/c-lex.c
gcc/c-lex.h
gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl2.c
gcc/doc/tm.texi
gcc/gcc.c
gcc/target-def.h
gcc/target.h
gcc/tree.c

index 1dd90ee30c8a26a78f195640cd0ad920aa7d211c..307bdaefaf61b6b0e037d072addf9848f0626c85 100644 (file)
@@ -1,3 +1,25 @@
+2002-05-09  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * 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.
+doc:
+       * tm.texi: Update.
+
 2002-05-09  Neil Booth  <neil@daikokuya.demon.co.uk>
 
        * cppexp.c (_cpp_expand_op_stack): Set op_limit.
index b1605563d85c7b9848b13569777cccab151e1fa6..092f1ea11144579ba9bf7095c5657af83f9cf199 100644 (file)
@@ -1158,7 +1158,7 @@ c-typeck.o : c-typeck.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
 c-lang.o : c-lang.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
     langhooks.h langhooks-def.h c-common.h
 c-lex.o : c-lex.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) c-lex.h \
-    debug.h $(C_TREE_H) c-common.h $(TARGET_H) \
+    debug.h $(C_TREE_H) c-common.h \
     c-pragma.h input.h intl.h flags.h toplev.h output.h \
     mbchar.h $(CPPLIB_H) $(EXPR_H) $(TM_P_H)
 c-objc-common.o : c-objc-common.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) \
index b23bcfe14dd08cbd75e1c8093b094c7d250668a5..59a0b7f9f93e3fb2b0b6161dd4be9787c7e97111 100644 (file)
@@ -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)
     {
index eca6cf137f0fa3c93b07ac425f9ab42d8bdfa2a7..7c5c30dab9ddf038105a389ba7beb05343109a25 100644 (file)
@@ -378,6 +378,14 @@ extern c_language_kind c_language;
 /* Nonzero if prepreprocessing only.  */
 extern int flag_preprocess_only;
 
+/* Nonzero if an ISO standard was selected.  It rejects macros in the
+   user's namespace.  */
+extern int flag_iso;
+
+/* Nonzero if -undef was given.  It suppresses target built-in macros
+   and assertions.  */
+extern int flag_undef;
+
 /* Nonzero means give string constants the type `const char *', rather
    than `char *'.  */
 
index 61f8f695e4539ddc30b6a284dd841d19d99bc35b..854cd7309fd9960adefc28ffdda1cca6f4376816 100644 (file)
@@ -541,6 +541,7 @@ c_decode_option (argc, argv)
          flag_no_nonansi_builtin = 1;
          flag_noniso_default_format_attributes = 0;
          flag_isoc99 = 0;
+         flag_iso = 1;
        }
       else if (!strcmp (argstart, "iso9899:199409"))
        {
@@ -558,6 +559,7 @@ c_decode_option (argc, argv)
          flag_noniso_default_format_attributes = 0;
          flag_isoc99 = 1;
          flag_isoc94 = 1;
+         flag_iso = 1;
        }
       else if (!strcmp (argstart, "gnu89"))
        {
@@ -636,6 +638,8 @@ c_decode_option (argc, argv)
     ;
   else if (!strcmp (p, "-ansi"))
     goto iso_1990;
+  else if (!strcmp (p, "-undef"))
+    flag_undef = 1;
   else if (!strcmp (p, "-Werror-implicit-function-declaration"))
     mesg_implicit_function_declaration = 2;
   else if (!strncmp (p, "-Wformat=", 9))
index 075a2edb9ab93b763ec6d29bae2059ffec0a527d..357017c9ca09cd7eb6ff5e036831db26b44425da 100644 (file)
@@ -39,7 +39,6 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "tm_p.h"
 #include "splay-tree.h"
 #include "debug.h"
-#include "target.h"
 
 #ifdef MULTIBYTE_CHARS
 #include "mbchar.h"
@@ -81,7 +80,6 @@ static tree lex_string                PARAMS ((const unsigned char *, unsigned int,
 static tree lex_charconst      PARAMS ((const cpp_token *));
 static void update_header_times        PARAMS ((const char *));
 static int dump_one_header     PARAMS ((splay_tree_node, void *));
-static void cb_register_builtins PARAMS ((cpp_reader *));
 static void cb_line_change     PARAMS ((cpp_reader *, const cpp_token *, int));
 static void cb_ident           PARAMS ((cpp_reader *, unsigned int,
                                         const cpp_string *));
@@ -123,7 +121,6 @@ init_c_lex (filename)
   cb->ident = cb_ident;
   cb->file_change = cb_file_change;
   cb->def_pragma = cb_def_pragma;
-  cb->register_builtins = cb_register_builtins;
 
   /* Set the debug callbacks if we can use them.  */
   if (debug_info_level == DINFO_LEVEL_VERBOSE
@@ -228,25 +225,6 @@ dump_time_statistics ()
   splay_tree_foreach (file_info_tree, dump_one_header, 0);
 }
 
-/* Register preprocessor built-ins.  */
-static void
-cb_register_builtins (pfile)
-     cpp_reader *pfile;
-{
-  if (c_language == clk_cplusplus)
-    {
-      if (SUPPORTS_ONE_ONLY)
-       cpp_define (pfile, "__GXX_WEAK__");
-      else
-       cpp_define (pfile, "__GXX_WEAK__=0");
-    }
-
-  (*targetm.register_cpp_builtins) (pfile);
-}
-
-/* Not yet handled: #pragma, #define, #undef.
-   No need to deal with linemarkers under normal conditions.  */
-
 static void
 cb_ident (pfile, line, str)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
index 7821ab90ee134178e06ef45b797a4cdecfc0edc8..049bf6b36235eadf01be44821b770ac10b53fd4a 100644 (file)
@@ -34,9 +34,19 @@ extern int indent_level;
 
 struct cpp_reader;
 extern struct cpp_reader* parse_in;
-/* Copied from cpplib.h to avoid target code having to pull in all of
-   cpplib.h.  */
-extern void cpp_define PARAMS ((struct cpp_reader *, const char *));
-extern void cpp_assert PARAMS ((struct cpp_reader *, const char *));
+
+#define builtin_define(TXT) cpp_define (parse_in, TXT)
+#define builtin_assert(TXT) cpp_assert (parse_in, TXT)
+
+/* 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".  */
+extern void builtin_define_std PARAMS ((const char *));
 
 #endif /* ! GCC_C_LEX_H */
index aa6dff611da95baf9633b64e260d55d7527f999f..167df4e8d58fe7dbc5f2b9feb1f334298fb6bb41 100644 (file)
@@ -1,3 +1,9 @@
+2002-05-09  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * cp-tree.h (flag_ansi): Remove.
+       * decl2.c (flag_ansi): Remove.
+       (cxx_decode_option): Set flag_iso and flag_undef.
+
 2002-05-09  Jason Merrill  <jason@redhat.com>
 
        * typeck.c (get_member_function_from_ptrfunc): Reorganize.
index db74366e8db97fd32fe9af5a1f686c5a324f8a8e..0f2ad7ca80be515900b50b4733c37762fc242e97 100644 (file)
@@ -1021,12 +1021,6 @@ extern int interface_only, interface_unknown;
 
 extern int flag_elide_constructors;
 
-/* Nonzero means enable obscure standard features and disable GNU
-   extensions that might cause standard-compliant code to be
-   miscompiled.  */
-
-extern int flag_ansi;
-
 /* Nonzero means that member functions defined in class scope are
    inline by default.  */
 
index f716de0c94e465f7e974582f15a4f9d499774bd6..2054a37e545208b5264f54d7336994ca50fdc40f 100644 (file)
@@ -136,12 +136,6 @@ int flag_no_gnu_keywords;
 
 int flag_signed_bitfields = 1;
 
-/* Nonzero means enable obscure standard features and disable GNU
-   extensions that might cause standard-compliant code to be
-   miscompiled.  */
-
-int flag_ansi;
-
 /* Nonzero means do emit exported implementations of functions even if
    they can be inlined.  */
 
@@ -699,8 +693,10 @@ cxx_decode_option (argc, argv)
     }
   else if (!strcmp (p, "-E"))
     flag_preprocess_only = 1;
+  else if (!strcmp (p, "-undef"))
+    flag_undef = 1;
   else if (!strcmp (p, "-ansi"))
-    flag_no_nonansi_builtin = 1, flag_ansi = 1,
+    flag_no_nonansi_builtin = 1, flag_iso = 1,
     flag_noniso_default_format_attributes = 0, flag_no_gnu_keywords = 1;
 #ifdef SPEW_DEBUG
   /* Undocumented, only ever used when you're invoking cc1plus by hand, since
index b70ae4862a4415fe4ffd47867d8783f56ae72a5a..f382796937a5aa8e2e427c9b76754e403f91e646 100644 (file)
@@ -622,19 +622,32 @@ The macro @code{STANDARD_STARTFILE_PREFIX}.
 @c prevent bad page break with this line
 Here are run-time target specifications.
 
-@deftypefn {Target Hook} void TARGET_REGISTER_CPP_BUILTINS (cpp_reader *@var{pfile})
-This macro expands to a target-specific function, called by the C
-family of front ends, that allows you to define preprocessor built-in
-macros and assertions at run-time.
-
-Pass the argument (a preprocessor handle) as the first argument to the
-functions @code{cpp_define} and @code{cpp_assert}, declared in
-@file{c-lex.h}.  The second argument is the same as the argument to
-the respective command-line option, for example @code{__mips__} for
-@code{cpp_define}, and @code{cpu=mips} for @code{cpp_assert}.
-@end deftypefn
-
 @table @code
+@findex TARGET_REGISTER_CPP_BUILTINS
+@item TARGET_REGISTER_CPP_BUILTINS
+This macro expands to a block of code that defines target-specific
+built-in preprocessor macros and assertions, using the functions
+@code{builtin_macro}, @code{builtin_macro_std} and
+@code{builtin_assert} declared in @file{c-lex.h}.
+
+@code{builtin_assert} takes a string in the form you pass to the
+command-line option @option{-A}, such as @code{cpu=mips}, and creates
+the assertion.  @code{builtin_macro} takes a string in the form
+accepted by option @option{-D} and unconditionally defines the macro.
+
+@code{builtin_macro_std} takes a string representing the name of an
+object-like macro.  If it doesn't lie in the user's namespace,
+@code{builtin_macro_std} defines it unconditionally.  Otherwise, it
+defines a version with two leading underscores, and another version
+with two leading and trailing underscores, and defines the original
+only if an ISO standard was not requested on the command line.  For
+example, passing @code{unix} defines @code{__unix}, @code{__unix__}
+and possibly @code{unix}; passing @code{_mips} defines @code{__mips},
+@code{__mips__} and possibly @code{_mips}, and passing @code{_ABI64}
+defines only @code{_ABI64}.
+
+This macro obsoletes the @code{CPP_PREDEFINES} target macro.
+
 @findex CPP_PREDEFINES
 @item CPP_PREDEFINES
 Define this to be a string constant containing @option{-D} options to
index d792e34771593a812934003696eb18b72eb3642b..3e5a430a364017f322e963ddbcb6314c268f5ebe 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -701,7 +701,7 @@ static const char *cc1_options =
 "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
  %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
  %{g*} %{O*} %{W*&pedantic*} %{w} %{std*} %{ansi}\
- %{v:-version} %{pg:-p} %{p} %{f*}\
+ %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\
  %{Qn:-fno-ident} %{--help:--help}\
  %{--target-help:--target-help}\
  %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}}\
index c419441976ab11e7db6b4818262370f2c26b25a7..76d238e07267b6584bc8c5afdd97ae528ef5d269 100644 (file)
@@ -179,7 +179,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #define TARGET_SET_DEFAULT_TYPE_ATTRIBUTES default_set_default_type_attributes
 #define TARGET_INSERT_ATTRIBUTES default_insert_attributes
 #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P default_function_attribute_inlinable_p
-#define TARGET_REGISTER_CPP_BUILTINS default_register_cpp_builtins
 #define TARGET_MS_BITFIELD_LAYOUT_P default_ms_bitfield_layout_p
 
 /* In builtins.c.  */
@@ -206,7 +205,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   TARGET_SET_DEFAULT_TYPE_ATTRIBUTES,          \
   TARGET_INSERT_ATTRIBUTES,                    \
   TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P,       \
-  TARGET_REGISTER_CPP_BUILTINS,                        \
   TARGET_MS_BITFIELD_LAYOUT_P,                 \
   TARGET_INIT_BUILTINS,                                \
   TARGET_EXPAND_BUILTIN,                       \
index a21c5126b79dbee0e863e8526b9ee268586fed99..1f294126ae9434412b9a100bb20594a856f322b9 100644 (file)
@@ -44,8 +44,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    to gradually reduce the amount of conditional compilation that is
    scattered throughout GCC.  */
 
-struct cpp_reader;
-
 struct gcc_target
 {
   /* Functions that output assembler for the target.  */
@@ -200,8 +198,6 @@ struct gcc_target
      can be inlined despite its machine attributes, false otherwise.  */
   bool (* function_attribute_inlinable_p) PARAMS ((tree fndecl));
 
-  void (* register_cpp_builtins) PARAMS ((struct cpp_reader *));
-
   /* Return true if bitfields in RECORD_TYPE should follow the
      Microsoft Visual C++ bitfield layout rules.  */
   bool (* ms_bitfield_layout_p) PARAMS ((tree record_type));
index aaef9737db6057b5611174e2fb2a2d368abf7c14..945f3a15eca873884ff82a2aaaa5afab71c083b7 100644 (file)
@@ -2543,13 +2543,6 @@ build_type_attribute_variant (ttype, attribute)
   return ttype;
 }
 
-/* Default registration of target-specific CPP built-ins.  */
-void
-default_register_cpp_builtins (pfile)
-     struct cpp_reader *pfile ATTRIBUTE_UNUSED;
-{
-}
-
 /* Default value of targetm.comp_type_attributes that always returns 1.  */
 
 int