diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2000-06-23 10:56:09 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2000-06-23 10:56:09 +0000 |
commit | 82443371dbe45090104ee47b52206637f00c3b75 (patch) | |
tree | 64897139351a8cff8d093f5375b42a9234a1335c /gcc/cpplib.c | |
parent | 7ab923ccffee2b00e18580a21e54cee3f3a0c24c (diff) | |
download | gcc-82443371dbe45090104ee47b52206637f00c3b75.zip gcc-82443371dbe45090104ee47b52206637f00c3b75.tar.gz gcc-82443371dbe45090104ee47b52206637f00c3b75.tar.bz2 |
cpplib.c (struct pragma_entry): New structure.
* 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.
* cpp.texi: Update.
From-SVN: r34663
Diffstat (limited to 'gcc/cpplib.c')
-rw-r--r-- | gcc/cpplib.c | 75 |
1 files changed, 63 insertions, 12 deletions
diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 93798fa..f6cbd90 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -789,11 +789,50 @@ do_ident (pfile) /* 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[] = +{ + {"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) @@ -803,6 +842,7 @@ do_pragma (pfile) U_CHAR *buf; int pop; enum cpp_ttype token; + size_t len; here = CPP_WRITTEN (pfile); CPP_PUTS (pfile, "#pragma ", 8); @@ -819,20 +859,10 @@ do_pragma (pfile) } buf = pfile->token_buffer + key; + len = CPP_WRITTEN (pfile) - 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 + pop = pragma_dispatch (pfile, top_pragmas, buf, len); if (_cpp_get_directive_token (pfile) != CPP_VSPACE) goto skip; @@ -861,6 +891,27 @@ do_pragma_default (pfile) } 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 do_pragma_once (pfile) cpp_reader *pfile; { |