OSDN Git Service

* cppinit.c (builtin_array): Update.
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 25 Feb 2001 09:43:03 +0000 (09:43 +0000)
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 25 Feb 2001 09:43:03 +0000 (09:43 +0000)
        (init_builtins): Flag builtins to warn if redefined or
        undefined.  Define __GXX_WEAK as a normal macro.
        * cpplib.c (do_undef): Warn if flagged NODE_WARN.
        * cpplib.h (NODE_WARN): New flag.
        * cppmacro.c (builtin_macro): Remove handling of __GXX_WEAK__.
        Handle __STDC__ as a builtin only on Solaris.
        (warn_of_redefinition): Renamed from check_macro_definition.
        Reverse sense of test.  Always warn if NODE_WARN.
        (_cpp_create_definition): Use warn_of_redefinition.  Flag
        any macro beginning with "__STDC_" to require a mandatory
        warning if redefined or undefined.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@40053 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/cppinit.c
gcc/cpplib.c
gcc/cpplib.h
gcc/cppmacro.c

index 3509136..8fdb823 100644 (file)
@@ -1,3 +1,18 @@
+2001-02-25  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+        * cppinit.c (builtin_array): Update.
+        (init_builtins): Flag builtins to warn if redefined or
+        undefined.  Define __GXX_WEAK as a normal macro.
+        * cpplib.c (do_undef): Warn if flagged NODE_WARN.
+        * cpplib.h (NODE_WARN): New flag.
+        * cppmacro.c (builtin_macro): Remove handling of __GXX_WEAK__.
+        Handle __STDC__ as a builtin only on Solaris.
+        (warn_of_redefinition): Renamed from check_macro_definition.
+        Reverse sense of test.  Always warn if NODE_WARN.
+        (_cpp_create_definition): Use warn_of_redefinition.  Flag
+        any macro beginning with "__STDC_" to require a mandatory
+        warning if redefined or undefined.
+
 2001-02-24  Zack Weinberg  <zackw@stanford.edu>
 
        * xm-interix.h, xm-lynx.h, alpha/xm-vms.h, convex/xm-convex.h,
index 22ce18d..d8efb4b 100644 (file)
@@ -607,7 +607,9 @@ cpp_destroy (pfile)
 /* This structure defines one built-in identifier.  A node will be
    entered in the hash table under the name NAME, with value VALUE (if
    any).  If flags has OPERATOR, the node's operator field is used; if
-   flags has BUILTIN the node's builtin field is used.
+   flags has BUILTIN the node's builtin field is used.  Macros that are
+   known at build time should not be flagged BUILTIN, as then they do
+   not appear in macro dumps with e.g. -dM or -dD.
 
    Two values are not compile time constants, so we tag
    them in the FLAGS field instead:
@@ -632,7 +634,6 @@ struct builtin
 #define OPERATOR       0x10
 
 #define B(n, t)       { U n, 0, t, 0, BUILTIN, sizeof n - 1 }
-#define BC(n, t)      { U n, 0, t, 0, BUILTIN | CPLUS, sizeof n - 1 }
 #define C(n, v)       { U n, v, 0, 0, 0, sizeof n - 1 }
 #define X(n, f)       { U n, 0, 0, 0, f, sizeof n - 1 }
 #define O(n, c, f)    { U n, 0, 0, c, OPERATOR | f, sizeof n - 1 }
@@ -644,8 +645,6 @@ static const struct builtin builtin_array[] =
   B("__BASE_FILE__",    BT_BASE_FILE),
   B("__LINE__",                 BT_SPECLINE),
   B("__INCLUDE_LEVEL__", BT_INCLUDE_LEVEL),
-  B("__STDC__",                 BT_STDC),
-  BC("__GXX_WEAK__",     BT_WEAK),
 
   X("__VERSION__",             VERS),
   X("__USER_LABEL_PREFIX__",   ULP),
@@ -663,6 +662,11 @@ static const struct builtin builtin_array[] =
 #ifndef NO_BUILTIN_WINT_TYPE
   C("__WINT_TYPE__",           WINT_TYPE),
 #endif
+#ifdef STDC_0_IN_SYSTEM_HEADERS
+  B("__STDC__",                 BT_STDC),
+#else
+  C("__STDC__",                 "1"),
+#endif
 
   /* Named operators known to the preprocessor.  These cannot be #defined
      and always have their stated meaning.  They are treated like normal
@@ -714,7 +718,7 @@ init_builtins (pfile)
          else
            {
              hp->type = NT_MACRO;
-             hp->flags |= NODE_BUILTIN;
+             hp->flags |= NODE_BUILTIN | NODE_WARN;
              hp->value.builtin = b->builtin;
            }
        }
@@ -746,7 +750,13 @@ init_builtins (pfile)
     }
 
   if (CPP_OPTION (pfile, cplusplus))
-    _cpp_define_builtin (pfile, "__cplusplus 1");
+    {
+      _cpp_define_builtin (pfile, "__cplusplus 1");
+      if (SUPPORTS_ONE_ONLY)
+       _cpp_define_builtin (pfile, "__GXX_WEAK__ 1");
+      else
+       _cpp_define_builtin (pfile, "__GXX_WEAK__ 0");
+    }
   if (CPP_OPTION (pfile, objc))
     _cpp_define_builtin (pfile, "__OBJC__ 1");
 
index da6e397..0ebd093 100644 (file)
@@ -477,7 +477,7 @@ do_undef (pfile)
       if (pfile->cb.undef)
        (*pfile->cb.undef) (pfile, node);
 
-      if (node->flags & NODE_BUILTIN)
+      if (node->flags & NODE_WARN)
        cpp_warning (pfile, "undefining \"%s\"", node->name);
 
       _cpp_free_definition (node);
index 2b7a99d..0993792 100644 (file)
@@ -444,6 +444,7 @@ enum cpp_buffer_type {BUF_FAKE, BUF_FILE, BUF_BUILTIN,
 #define NODE_POISONED  (1 << 1)        /* Poisoned identifier.  */
 #define NODE_BUILTIN   (1 << 2)        /* Builtin macro.  */
 #define NODE_DIAGNOSTIC (1 << 3)       /* Possible diagnostic when lexed.  */
+#define NODE_WARN      (1 << 4)        /* Warn if redefined or undefined.  */
 
 /* Different flavors of hash node.  */
 enum node_type
index 7a65e97..4d4302d 100644 (file)
@@ -29,10 +29,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 #include "cpplib.h"
 #include "cpphash.h"
 
-#ifndef STDC_0_IN_SYSTEM_HEADERS
-#define STDC_0_IN_SYSTEM_HEADERS 0 /* Boolean macro.  */
-#endif
-
 struct cpp_macro
 {
   cpp_hashnode **params;       /* Parameters, if any.  */
@@ -92,9 +88,8 @@ static void free_lookahead PARAMS ((cpp_lookahead *));
 /* #define directive parsing and handling.  */
 
 static cpp_token *lex_expansion_token PARAMS ((cpp_reader *, cpp_macro *));
-static int check_macro_redefinition PARAMS ((cpp_reader *,
-                                            const cpp_hashnode *,
-                                            const cpp_macro *));
+static int warn_of_redefinition PARAMS ((cpp_reader *, const cpp_hashnode *,
+                                        const cpp_macro *));
 static int save_parameter PARAMS ((cpp_reader *, cpp_macro *, cpp_hashnode *));
 static int parse_params PARAMS ((cpp_reader *, cpp_macro *));
 static void check_trad_stringification PARAMS ((cpp_reader *,
@@ -184,11 +179,8 @@ builtin_macro (pfile, token)
 
     case BT_STDC:
       {
-       int stdc = 1;
-
-       if (STDC_0_IN_SYSTEM_HEADERS && CPP_IN_SYSTEM_HEADER (pfile)
-           && pfile->spec_nodes.n__STRICT_ANSI__->type == NT_VOID)
-         stdc = 0;
+       int stdc = (!CPP_IN_SYSTEM_HEADER (pfile)
+                   || pfile->spec_nodes.n__STRICT_ANSI__->type != NT_VOID);
        make_number_token (pfile, token, stdc);
       }
       break;
@@ -217,10 +209,6 @@ builtin_macro (pfile, token)
       *token = node->value.builtin == BT_DATE ? pfile->date: pfile->time;
       break;
 
-    case BT_WEAK:
-      make_number_token (pfile, token, SUPPORTS_ONE_ONLY);
-      break;
-
     default:
       cpp_ice (pfile, "invalid builtin macro \"%s\"", node->name);
       break;
@@ -1178,9 +1166,9 @@ _cpp_push_token (pfile, token, pos)
 
 /* #define directive parsing and handling.  */
 
-/* Returns non-zero if a macro redefinition is trivial.  */
+/* Returns non-zero if a macro redefinition warning is required.  */
 static int
-check_macro_redefinition (pfile, node, macro2)
+warn_of_redefinition (pfile, node, macro2)
      cpp_reader *pfile;
      const cpp_hashnode *node;
      const cpp_macro *macro2;
@@ -1188,9 +1176,15 @@ check_macro_redefinition (pfile, node, macro2)
   const cpp_macro *macro1;
   unsigned int i;
 
-  if (node->type != NT_MACRO || node->flags & NODE_BUILTIN)
-    return ! pfile->done_initializing;
+  /* Some redefinitions need to be warned about regardless.  */
+  if (node->flags & NODE_WARN)
+    return 1;
 
+  if (! CPP_PEDANTIC (pfile))
+    return 0;
+
+  /* Redefinition of a macro is allowed if and only if the old and new
+     definitions are the same.  (6.10.3 paragraph 2). */
   macro1 = node->value.macro;
 
   /* The quick failures.  */
@@ -1198,19 +1192,19 @@ check_macro_redefinition (pfile, node, macro2)
       || macro1->paramc != macro2->paramc
       || macro1->fun_like != macro2->fun_like
       || macro1->variadic != macro2->variadic)
-    return 0;
+    return 1;
 
   /* Check each token.  */
   for (i = 0; i < macro1->count; i++)
     if (! _cpp_equiv_tokens (&macro1->expansion[i], &macro2->expansion[i]))
-      return 0;
+      return 1;
 
   /* Check parameter spellings.  */
   for (i = 0; i < macro1->paramc; i++)
     if (macro1->params[i] != macro2->params[i])
-      return 0;
+      return 1;
 
-  return 1;
+  return 0;
 }
 
 /* Free the definition of hashnode H.  */
@@ -1472,19 +1466,15 @@ _cpp_create_definition (pfile, node)
   /* Commit the memory.  */
   POOL_COMMIT (&pfile->macro_pool, macro->count * sizeof (cpp_token));
 
-  /* Redefinition of a macro is allowed if and only if the old and new
-     definitions are the same.  (6.10.3 paragraph 2). */
   if (node->type != NT_VOID)
     {
-      if (CPP_PEDANTIC (pfile)
-         && !check_macro_redefinition (pfile, node, macro))
+      if (warn_of_redefinition (pfile, node, macro))
        {
          cpp_pedwarn_with_line (pfile, pfile->directive_pos.line,
                                 pfile->directive_pos.col,
                                 "\"%s\" redefined", node->name);
 
-         if (pfile->done_initializing && node->type == NT_MACRO
-             && !(node->flags & NODE_BUILTIN))
+         if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
            cpp_pedwarn_with_file_and_line (pfile,
                                            node->value.macro->file,
                                            node->value.macro->line, 1,
@@ -1496,6 +1486,8 @@ _cpp_create_definition (pfile, node)
   /* Enter definition in hash table.  */
   node->type = NT_MACRO;
   node->value.macro = macro;
+  if (! ustrncmp (node->name, DSC ("__STDC_")))
+    node->flags |= NODE_WARN;
 
  cleanup: