c-pragma.h (cpp_register_pragma_space): Remove.
authorNeil Booth <neil@daikokuya.demon.co.uk>
Sun, 14 Oct 2001 17:44:00 +0000 (17:44 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Sun, 14 Oct 2001 17:44:00 +0000 (17:44 +0000)
* c-pragma.h (cpp_register_pragma_space): Remove.
* cpplib.h (cpp_register_pragma_space): Remove.
* cpplib.c (lookup_pragma_entry, insert_pragma_entry): New.
(cpp_register_pragma_space): Remove.
(cpp_register_pragma): Simplify using lookup_pragma_entry,
add sanity checks.
(do_pragma): Similarly.
(_cpp_init_internal_pragmas): Don't register namespaces.

* config/v850/v850.h (REGISTER_TARGET_PRAGMAS):
Don't register namespaces.
* cp/lex.c (init_cp_pragma): Similarly.
* doc/tm.texi: Update.

From-SVN: r46254

gcc/ChangeLog
gcc/c-pragma.h
gcc/config/v850/v850.h
gcc/cp/ChangeLog
gcc/cp/lex.c
gcc/cpplib.c
gcc/cpplib.h
gcc/doc/tm.texi

index e894502c2129af63b5b7e7cb3e1d8402ed11fe5e..4bddb844139d18e5b7336c31eea0e604dae19d03 100644 (file)
@@ -1,3 +1,19 @@
+2001-10-14  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * c-pragma.h (cpp_register_pragma_space): Remove.
+       * cpplib.h (cpp_register_pragma_space): Remove.
+       * cpplib.c (lookup_pragma_entry, insert_pragma_entry): New.
+       (cpp_register_pragma_space): Remove.
+       (cpp_register_pragma): Simplify using lookup_pragma_entry,
+       add sanity checks.
+       (do_pragma): Similarly.
+       (_cpp_init_internal_pragmas): Don't register namespaces.
+
+       * config/v850/v850.h (REGISTER_TARGET_PRAGMAS):
+       Don't register namespaces.
+       * cp/lex.c (init_cp_pragma): Similarly.
+       * doc/tm.texi: Update.
+
 2001-10-10  Craig Rodrigues  <rodrigc@gcc.gnu.org>
 
        PR c/4157
index 6f0d6ea15a0bd178806096f6df13f4ab9bf29ad3..dddfaceec2e37dc70e7aca006c8a18910c82896e 100644 (file)
@@ -51,7 +51,6 @@ typedef struct cpp_reader cpp_reader;
 extern void cpp_register_pragma PARAMS ((cpp_reader *,
                                         const char *, const char *,
                                         void (*) PARAMS ((cpp_reader *))));
-extern void cpp_register_pragma_space PARAMS ((cpp_reader *, const char *));
 #endif
 
 #endif /* GCC_C_PRAGMA_H */
index b077f6d72d9e8047a02d7df6c775e16d6aa35fe6..42f3c31d830ff430b1184308dfa2cb69868bc462 100644 (file)
@@ -1503,7 +1503,6 @@ do { char dstr[30];                                       \
 
 /* Tell compiler we want to support GHS pragmas */
 #define REGISTER_TARGET_PRAGMAS(PFILE) do {                              \
-  cpp_register_pragma_space (PFILE, "ghs");                              \
   cpp_register_pragma (PFILE, "ghs", "interrupt", ghs_pragma_interrupt);  \
   cpp_register_pragma (PFILE, "ghs", "section",   ghs_pragma_section);    \
   cpp_register_pragma (PFILE, "ghs", "starttda",  ghs_pragma_starttda);   \
index 92907b8d63872e1754978bc4b14f03c6503a92e4..467619534305f10f18ab18dc2fd9faaf26100328 100644 (file)
@@ -1,3 +1,7 @@
+2001-10-14  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * cp/lex.c (init_cp_pragma): Similarly.
+
 2001-10-13  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        * pt.c (lookup_template_class): Build complete template arguments
index ec445663ddfd3f89c1d04c440b623eee63197b28..ccd57a21345c8a7ca444027fd795acae30715a4c 100644 (file)
@@ -677,7 +677,6 @@ init_cp_pragma ()
   cpp_register_pragma (parse_in, 0, "implementation",
                       handle_pragma_implementation);
 
-  cpp_register_pragma_space (parse_in, "GCC");
   cpp_register_pragma (parse_in, "GCC", "interface", handle_pragma_interface);
   cpp_register_pragma (parse_in, "GCC", "implementation",
                       handle_pragma_implementation);
index 3138b7ee63b4092dad6d7d5d5bc867b4dde87584..9aab392c6427253763170a9d8acf5c6520efe207 100644 (file)
@@ -47,6 +47,20 @@ struct if_stack
   int type;                    /* Most recent conditional, for diagnostics.  */
 };
 
+/* Contains a registered pragma or pragma namespace.  */
+typedef void (*pragma_cb) PARAMS ((cpp_reader *));
+struct pragma_entry
+{
+  struct pragma_entry *next;
+  const char *name;
+  size_t len;
+  int is_nspace;
+  union {
+    pragma_cb handler;
+    struct pragma_entry *space;
+  } u;
+};
+
 /* Values for the origin field of struct directive.  KANDR directives
    come from traditional (K&R) C.  STDC89 directives come from the
    1989 C standard.  EXTENSION directives are extensions.  */
@@ -96,6 +110,10 @@ static int  strtoul_for_line        PARAMS ((const U_CHAR *, unsigned int,
 static void do_diagnostic      PARAMS ((cpp_reader *, enum error_type, int));
 static cpp_hashnode *lex_macro_node    PARAMS ((cpp_reader *));
 static void do_include_common  PARAMS ((cpp_reader *, enum include_type));
+static struct pragma_entry *lookup_pragma_entry
+  PARAMS ((struct pragma_entry *, const char *pragma));
+static struct pragma_entry *insert_pragma_entry
+  PARAMS ((cpp_reader *, struct pragma_entry **, const char *, pragma_cb));
 static void do_pragma_once     PARAMS ((cpp_reader *));
 static void do_pragma_poison   PARAMS ((cpp_reader *));
 static void do_pragma_system_header    PARAMS ((cpp_reader *));
@@ -842,149 +860,146 @@ do_ident (pfile)
   check_eol (pfile);
 }
 
-/* Pragmata handling.  We handle some of these, and pass the rest on
-   to the front end.  C99 defines three pragmas and says that no macro
-   expansion is to be performed on them; whether or not macro
-   expansion happens for other pragmas is implementation defined.
-   This implementation never macro-expands the text after #pragma.  */
-
-/* Sub-handlers for the pragmas needing treatment here.
-   They return 1 if the token buffer is to be popped, 0 if not.  */
-typedef void (*pragma_cb) PARAMS ((cpp_reader *));
-struct pragma_entry
+/* Lookup a PRAGMA name in a singly-linked CHAIN.  Returns the
+   matching entry, or NULL if none is found.  The returned entry could
+   be the start of a namespace chain, or a pragma.  */
+static struct pragma_entry *
+lookup_pragma_entry (chain, pragma)
+     struct pragma_entry *chain;
+     const char *pragma;
 {
-  struct pragma_entry *next;
-  const char *name;
-  size_t len;
-  int isnspace;
-  union {
-    pragma_cb handler;
-    struct pragma_entry *space;
-  } u;
-};
+  size_t len = strlen (pragma);
 
-void
-cpp_register_pragma (pfile, space, name, handler)
+  while (chain)
+    {
+      if (chain->len == len && !memcmp (chain->name, pragma, len))
+       break;
+      chain = chain->next;
+    }
+
+  return chain;
+}
+
+/* Create and insert a pragma entry for NAME at the beginning of a
+   singly-linked CHAIN.  If handler is NULL, it is a namespace,
+   otherwise it is a pragma and its handler.  */
+static struct pragma_entry *
+insert_pragma_entry (pfile, chain, name, handler)
      cpp_reader *pfile;
-     const char *space;
+     struct pragma_entry **chain;
      const char *name;
      pragma_cb handler;
 {
-  struct pragma_entry **x, *new;
-  size_t len;
-
-  x = &pfile->pragmas;
-  if (space)
-    {
-      struct pragma_entry *p = pfile->pragmas;
-      len = strlen (space);
-      while (p)
-       {
-         if (p->isnspace && p->len == len && !memcmp (p->name, space, len))
-           {
-             x = &p->u.space;
-             goto found;
-           }
-         p = p->next;
-       }
-      cpp_ice (pfile, "unknown #pragma namespace %s", space);
-      return;
-    }
+  struct pragma_entry *new;
 
- found:
   new = (struct pragma_entry *)
     _cpp_aligned_alloc (pfile, sizeof (struct pragma_entry));
   new->name = name;
   new->len = strlen (name);
-  new->isnspace = 0;
-  new->u.handler = handler;
+  if (handler)
+    {
+      new->is_nspace = 0;
+      new->u.handler = handler;
+    }
+  else
+    {
+      new->is_nspace = 1;
+      new->u.space = NULL;
+    }
 
-  new->next = *x;
-  *x = new;
+  new->next = *chain;
+  *chain = new;
+  return new;
 }
 
+/* Register a pragma NAME in namespace SPACE.  If SPACE is null, it
+   goes in the global namespace.  HANDLER is the handler it will call,
+   which must be non-NULL.  */
 void
-cpp_register_pragma_space (pfile, space)
+cpp_register_pragma (pfile, space, name, handler)
      cpp_reader *pfile;
      const char *space;
+     const char *name;
+     pragma_cb handler;
 {
-  struct pragma_entry *new;
-  const struct pragma_entry *p = pfile->pragmas;
-  size_t len = strlen (space);
+  struct pragma_entry **chain = &pfile->pragmas;
+  struct pragma_entry *entry;
 
-  while (p)
+  if (!handler)
+    abort ();
+
+  if (space)
     {
-      if (p->isnspace && p->len == len && !memcmp (p->name, space, len))
-       /* Multiple different callers are allowed to register the same
-          namespace.  */
-       return;
-      p = p->next;
+      entry = lookup_pragma_entry (*chain, space);
+      if (!entry)
+       entry = insert_pragma_entry (pfile, chain, space, NULL);
+      else if (!entry->is_nspace)
+       goto clash;
+      chain = &entry->u.space;
     }
 
-  new = (struct pragma_entry *)
-    _cpp_aligned_alloc (pfile, sizeof (struct pragma_entry));
-  new->name = space;
-  new->len = len;
-  new->isnspace = 1;
-  new->u.space = 0;
-
-  new->next = pfile->pragmas;
-  pfile->pragmas = new;
+  /* Check for duplicates.  */
+  entry = lookup_pragma_entry (*chain, name);
+  if (entry)
+    {
+      if (entry->is_nspace)
+       clash:
+       cpp_ice (pfile,
+                "registering \"%s\" as both a pragma and a pragma namespace",
+                entry->name);
+      else if (space)
+       cpp_ice (pfile, "#pragma %s %s is already registered", space, name);
+      else
+       cpp_ice (pfile, "#pragma %s is already registered", name);
+    }
+  else
+    insert_pragma_entry (pfile, chain, name, handler);
 }
-  
+
+/* Register the pragmas the preprocessor itself handles.  */
 void
 _cpp_init_internal_pragmas (pfile)
      cpp_reader *pfile;
 {
-  /* top level */
+  /* Pragmas in the global namespace.  */
   cpp_register_pragma (pfile, 0, "poison", do_pragma_poison);
   cpp_register_pragma (pfile, 0, "once", do_pragma_once);
 
-  /* GCC namespace */
-  cpp_register_pragma_space (pfile, "GCC");
-
+  /* New GCC-specific pragmas should be put in the GCC namespace.  */
   cpp_register_pragma (pfile, "GCC", "poison", do_pragma_poison);
   cpp_register_pragma (pfile, "GCC", "system_header", do_pragma_system_header);
   cpp_register_pragma (pfile, "GCC", "dependency", do_pragma_dependency);
 }
 
+/* Pragmata handling.  We handle some, and pass the rest on to the
+   front end.  C99 defines three pragmas and says that no macro
+   expansion is to be performed on them; whether or not macro
+   expansion happens for other pragmas is implementation defined.
+   This implementation never macro-expands the text after #pragma.  */
 static void
 do_pragma (pfile)
      cpp_reader *pfile;
 {
-  pragma_cb handler = NULL;
-  const struct pragma_entry *p;
+  const struct pragma_entry *p = NULL;
   const cpp_token *token;
-  unsigned int count = 0;
+  unsigned int count = 1;
 
-  p = pfile->pragmas;
   pfile->state.prevent_expansion++;
 
- new_space:
-  count++;
   token = cpp_get_token (pfile);
   if (token->type == CPP_NAME)
     {
-      const cpp_hashnode *node = token->val.node;
-      size_t len = NODE_LEN (node);
-
-      while (p)
+      p = lookup_pragma_entry (pfile->pragmas,
+                              (char *) NODE_NAME (token->val.node));
+      if (p && p->is_nspace)
        {
-         if (strlen (p->name) == len
-             && !memcmp (p->name, NODE_NAME (node), len))
-           {
-             if (p->isnspace)
-               {
-                 p = p->u.space;
-                 goto new_space;
-               }
-             else
-               {
-                 handler = p->u.handler;
-                 break;
-               }
-           }
-         p = p->next;
+         count = 2;
+         token = cpp_get_token (pfile);
+         if (token->type == CPP_NAME)
+           p = lookup_pragma_entry (p->u.space,
+                                    (char *) NODE_NAME (token->val.node));
+         else
+           p = NULL;
        }
     }
 
@@ -996,13 +1011,14 @@ do_pragma (pfile)
   if (pfile->cb.line_change)
     (*pfile->cb.line_change)(pfile, token, 1);
 
-  if (handler)
-    (*handler) (pfile);
+  if (p)
+    (*p->u.handler) (pfile);
   else if (pfile->cb.def_pragma)
     {
       _cpp_backup_tokens (pfile, count);
       (*pfile->cb.def_pragma) (pfile, pfile->directive_line);
     }
+
   pfile->state.prevent_expansion--;
 }
 
index d9f5d988f80ec3816707a20d7ecc6939ce021634..2ccac628114466506f71c53d38afa499378b1974 100644 (file)
@@ -494,7 +494,6 @@ extern unsigned char *cpp_spell_token PARAMS ((cpp_reader *, const cpp_token *,
 extern void cpp_register_pragma PARAMS ((cpp_reader *,
                                         const char *, const char *,
                                         void (*) PARAMS ((cpp_reader *))));
-extern void cpp_register_pragma_space PARAMS ((cpp_reader *, const char *));
 
 extern int cpp_start_read PARAMS ((cpp_reader *, const char *));
 extern void cpp_finish PARAMS ((cpp_reader *));
index 4a1474aeb558712c2c0631824f23cc78be0ddb6e..a790278ac9f3c455239798246710314d7a243cbd 100644 (file)
@@ -8485,10 +8485,10 @@ This macro is no longer supported.  You must use
 @findex pragma
 @item REGISTER_TARGET_PRAGMAS (@var{pfile})
 Define this macro if you want to implement any target-specific pragmas.
-If defined, it is a C expression which makes a series of calls to the
-@code{cpp_register_pragma} and/or @code{cpp_register_pragma_space}
-functions.  The @var{pfile} argument is the first argument to supply to
-these functions.  The macro may also do setup required for the pragmas.
+If defined, it is a C expression which makes a series of calls to
+@code{cpp_register_pragma} for each pragma, with @var{pfile} passed as
+the first argument to to these functions.  The macro may also do any
+setup required for the pragmas.
 
 The primary reason to define this macro is to provide compatibility with
 other compilers for the same target.  In general, we discourage
@@ -8511,14 +8511,12 @@ pragma of the form
 #pragma [@var{space}] @var{name} @dots{}
 @end smallexample
 
-@var{space} must have been the subject of a previous call to
-@code{cpp_register_pragma_space}, or else be a null pointer.  The
-callback routine receives @var{pfile} as its first argument, but must
-not use it for anything (this may change in the future).  It may read
-any text after the @var{name} by making calls to @code{c_lex}.  Text
-which is not read by the callback will be silently ignored.
-
-Note that both @var{space} and @var{name} are case sensitive.
+@var{space} is the case-sensitive namespace of the pragma, or
+@code{NULL} to put the pragma in the global namespace.  The callback
+routine receives @var{pfile} as its first argument, which can be passed
+on to cpplib's functions if necessary.  It may read any text after the
+@var{name} by making calls to @code{c_lex}.  Text which is not read by
+the callback will be silently ignored.
 
 For an example use of this routine, see @file{c4x.h} and the callback
 routines defined in @file{c4x.c}.
@@ -8536,15 +8534,6 @@ rule to the makefile fragment pointed to by @code{tmake_file} that shows
 how to build this object file.
 @end deftypefun
 
-@deftypefun void cpp_register_pragma_space (cpp_reader *@var{pfile}, const char *@var{space})
-This routine establishes a namespace for pragmas, which will be
-registered by subsequent calls to @code{cpp_register_pragma}.  For
-example, pragmas defined by the C standard are in the @samp{STDC}
-namespace, and pragmas specific to GCC are in the @samp{GCC} namespace.
-
-For an example use of this routine in a target header, see @file{v850.h}.
-@end deftypefun
-
 @findex HANDLE_SYSV_PRAGMA
 @findex #pragma
 @findex pragma