This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[cpplib]: Implement #pragma GCC whatever


Hi,
The attached patch implements a GCC namespace for pragmas. I.e.
	#pragma GCC whatever

The existing pragmas (once, implementation, poison, system_header) are
now also available in this namespace.

There was a bug in the old code that only the characters up to the length
of the pragma were checked. I.e.
	#pragma once_and_only
would be accepted as pragma once.

The pragma dependency thing is a different, forthcoming, patch.

built & tested on i686-pc-linux-gnu

ok?

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2000-06-22  Nathan Sidwell  <nathan@codesourcery.com>

	* cpplib.c (struct pragma_entry): New structure.
	(pragma_dispatch): Pragma dispatcher.
	(top_pragmas, gcc_pragmas): New static variables.
	(do_pragma): Use pragma_dispatch.
	(do_pragma_gcc): New pragma handler.

Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplib.c,v
retrieving revision 1.177
diff -c -3 -p -r1.177 cpplib.c
*** cpplib.c	2000/06/21 23:08:17	1.177
--- cpplib.c	2000/06/22 13:09:04
*************** do_ident (pfile)
*** 789,800 ****
--- 789,840 ----
  
  /* Sub-handlers for the pragmas needing treatment here.
     They return 1 if the token buffer is to be popped, 0 if not. */
+ struct pragma_entry
+ {
+   char const *name;
+   int (*handler) PARAMS ((cpp_reader *));
+ };
+ 
+ static int pragma_dispatch             
+     PARAMS ((cpp_reader *, const struct pragma_entry *, U_CHAR *, size_t));
  static int do_pragma_once		PARAMS ((cpp_reader *));
  static int do_pragma_implementation	PARAMS ((cpp_reader *));
  static int do_pragma_poison		PARAMS ((cpp_reader *));
  static int do_pragma_system_header	PARAMS ((cpp_reader *));
  static int do_pragma_default		PARAMS ((cpp_reader *));
+ static int do_pragma_gcc                PARAMS ((cpp_reader *));
+ 
+ static const struct pragma_entry top_pragmas[] =
+ {
+   {"once", do_pragma_once},
+   {"implementation", do_pragma_implementation},
+   {"poison", do_pragma_poison},
+   {"system_header", do_pragma_system_header},
+   {"GCC", do_pragma_gcc},
+   {NULL, do_pragma_default}
+ };
+ 
+ static const struct pragma_entry gcc_pragmas[] =
+ {
+   {"once", do_pragma_once},
+   {"implementation", do_pragma_implementation},
+   {"poison", do_pragma_poison},
+   {"system_header", do_pragma_system_header},
+   {NULL, do_pragma_default}
+ };
  
+ static int pragma_dispatch (pfile, table, p, len)
+      cpp_reader *pfile;
+      const struct pragma_entry *table;
+      U_CHAR *p;
+      size_t len;
+ {
+   for (; table->name; table++)
+     if (strlen (table->name) == len && !memcmp (p, table->name, len))
+       return (*table->handler) (pfile);
+   return (*table->handler) (pfile);
+ }
+ 
  static int
  do_pragma (pfile)
       cpp_reader *pfile;
*************** do_pragma (pfile)
*** 803,808 ****
--- 843,849 ----
    U_CHAR *buf;
    int pop;
    enum cpp_ttype token;
+   size_t  len;
  
    here = CPP_WRITTEN (pfile);
    CPP_PUTS (pfile, "#pragma ", 8);
*************** do_pragma (pfile)
*** 819,838 ****
      }
  
    buf = pfile->token_buffer + key;
    CPP_PUTC (pfile, ' ');
  
! #define tokis(x) !strncmp((char *) buf, x, sizeof(x) - 1)
!   if (tokis ("once"))
!     pop = do_pragma_once (pfile);
!   else if (tokis ("implementation"))
!     pop = do_pragma_implementation (pfile);
!   else if (tokis ("poison"))
!     pop = do_pragma_poison (pfile);
!   else if (tokis ("system_header"))
!     pop = do_pragma_system_header (pfile);
!   else
!     pop = do_pragma_default (pfile);
! #undef tokis
  
    if (_cpp_get_directive_token (pfile) != CPP_VSPACE)
      goto skip;
--- 860,869 ----
      }
  
    buf = pfile->token_buffer + key;
+   len = CPP_WRITTEN (pfile) - key;
    CPP_PUTC (pfile, ' ');
  
!   pop = pragma_dispatch (pfile, top_pragmas, buf, len);
  
    if (_cpp_get_directive_token (pfile) != CPP_VSPACE)
      goto skip;
*************** do_pragma_default (pfile)
*** 858,863 ****
--- 889,915 ----
    while (_cpp_get_directive_token (pfile) != CPP_VSPACE)
      CPP_PUTC (pfile, ' ');
    return 0;
+ }
+ 
+ static int
+ do_pragma_gcc (pfile)
+      cpp_reader *pfile;
+ {
+   long key;
+   enum cpp_ttype token;
+   U_CHAR *buf;
+   size_t  len;
+   
+   key = CPP_WRITTEN (pfile);
+   token = _cpp_get_directive_token (pfile);
+   if (token != CPP_NAME)
+     return token == CPP_VSPACE;
+ 
+   buf = pfile->token_buffer + key;
+   len = CPP_WRITTEN (pfile) - key;
+   CPP_PUTC (pfile, ' ');
+   
+   return pragma_dispatch (pfile, gcc_pragmas, buf, len);
  }
  
  static int

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]