summaryrefslogtreecommitdiff
path: root/gcc/c-pragma.c
diff options
context:
space:
mode:
authorrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>2006-01-04 16:33:38 +0000
committerrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>2006-01-04 16:33:38 +0000
commitb75b98aa8366f8c69c546a6e0a8f0e7559540363 (patch)
tree665a7e61be294c2530782e0d9fbb6a33d6ef62ea /gcc/c-pragma.c
parentdbdaaad01d866c0620f69b9b78b8dadef5425e54 (diff)
downloadgcc-b75b98aa8366f8c69c546a6e0a8f0e7559540363.tar.gz
libcpp/
* directives.c (struct pragma_entry): Add is_deferred. Add ident entry to value union. (end_directive): Don't eat the line if in_deferred_pragma. (run_directive): Remove pragma hacks. (insert_pragma_entry): Remove. (new_pragma_entry): New. (register_pragma_1): Split out of register_pragma. Only handle the lookup tree and return the new entry. (cpp_register_pragma): Fill in the pragma entry here. (cpp_register_deferred_pragma): New. (register_pragma_internal): New. (_cpp_init_internal_pragmas): Use register_pragma_internal. (do_pragma): Allow pragma expansion after namespace. For deferred pragmas, don't slurp the line into a string. (destringize_and_run): Save tokens for deferred pragmas. (cpp_handle_deferred_pragma): Remove. * macro.c (builtin_macro): Remove pragma token hack. (_cpp_push_token_context): Rename from push_token_context and export. * internal.h (struct lexer_state): Add pragma_allow_expansion. (_cpp_push_token_context): Declare. * lex.c (_cpp_lex_token): Allow _cpp_handle_directive to return a token. Update the line number correctly if so. (_cpp_lex_direct): Emit CPP_PRAGMA_EOL tokens. (cpp_token_val_index): Return CPP_TOKEN_FLD_PRAGMA for pragmas. * include/cpplib.h (PRAGMA_EOL): New. (CPP_TOKEN_FLD_PRAGMA): New. (struct cpp_token): Add val.pragma. (struct cpp_options): Remove defer_pragmas. (cpp_handle_deferred_pragma): Remove. (cpp_register_deferred_pragma): Declare. gcc/ * c-lex.c (c_lex_with_flags) <CPP_PRAGMA>: Smuggle pragma id via integer constant. (pragma_lex): Remove. * c-pch.c (c_common_pch_pragma): Accept the name as an argument, rather than parsing it. * c-pragma.c (handle_pragma_weak, handle_pragma_redefine_extname, handle_pragma_extern_prefix): Add %< %> quotes. (registered_pragmas): New. (c_register_pragma_1): New. (c_register_pragma): Use it. (c_register_pragma_with_expansion): Likewise. (c_invoke_pragma_handler): New. (init_pragma): Use cpp_register_deferred_pragma directly for pch_preprocess. * c-pragma.h (enum pragma_kind): New. (pragma_handler): New. (c_invoke_pragma_handler): Declare. * c-common.c (c_parse_error): Pretty print CPP_PRAGMA and CPP_PRAGMA_EOL. * c-common.h (c_common_pch_pragma): Update decl. * Makefile.in (c-parser.o): Update dependencies. (GTFILES): Add c-pragma.h. * c-parser.c (struct c_token): Add pragma_kind. (struct c_parser): Add in_pragma. (c_lex_one_token): Always initialize keyword and pragma_kind. Extract data for CPP_PRAGMA. (c_parser_peek_2nd_token): Deny CPP_PRAGMA_EOL. (c_parser_consume_token): Don't allow CPP_PRAGMA unless errors. Don't allow CPP_PRAGMA_EOL if in_pragma. (c_parser_consume_pragma): New. (c_parser_skip_until_found): Stop on CPP_PRAGMA_EOL. (c_parser_skip_to_end_of_parameter): Likewise. (c_parser_skip_to_end_of_block_or_statement): Likewise. (c_parser_skip_to_pragma_eol): New. (c_parser_external_declaration): Handle CPP_PRAGMA. (c_parser_compound_statement_nostart): Likewise. (c_parser_statement_after_labels): Likewise. (c_parser_pragma): New. (pragma_lex): Likewise. (c_parser_pragma_pch_preprocess): New. (c_parser_new): Merge into ... (c_parse_file): ... here. Call c_parser_pragma_pch_preprocess. gcc/cp/ * lex.c (handle_pragma_java_exceptions): Fix whitespace. * parser.c (struct cp_token): Add pragma_kind. (eof_token): Update to match. (struct cp_lexer): Add in_pragma; rearrange next for better packing. (cp_parser_initial_pragma): New. (cp_lexer_new_main): Use it. Don't bother clearing c_lex_return_raw_strings. (cp_lexer_get_preprocessor_token): Always initialize keyword and pragma_kind fields. Handle CPP_PRAGMA. (cp_lexer_consume_token): Don't allow CPP_PRAGMA_EOL when in_pragma is set. (cp_lexer_handle_pragma): Remove. Update callers to cp_parser_pragma. (cp_lexer_print_token) <CPP_PRAGMA>: Don't print as a string. (cp_parser_skip_to_pragma_eol): New. (cp_parser_error): Use it. (cp_parser_skip_to_closing_parenthesis): Stop at CPP_PRAGMA_EOL; rearrange with switch statement. (cp_parser_skip_to_end_of_statement): Likewise. (cp_parser_skip_to_end_of_block_or_statement): Likewise. (cp_parser_skip_to_closing_brace): Likewise. (cp_parser_skip_until_found): Likewise. (cp_parser_statement): Add in_compound argument; update callers. Use it to decide how to handle pragma parsing. (cp_parser_labeled_statement): Add in_compound argument; pass it on to cp_parser_statement. (cp_parser_statement_seq_opt): Stop at CPP_PRAGMA_EOL. (cp_parser_declaration_seq_opt): Likewise. (cp_parser_parameter_declaration): Likewise. (cp_parser_member_specification_opt): Likewise. (cp_parser_function_definition_after_decl): Likewise. (cp_parser_cache_group): Handle CPP_PRAGMA/CPP_PRAGMA_EOL pairs. (cp_parser_pragma): New. (pragma_lex): New. gcc/testsuite/ * g++.dg/parse/pragma2.C: Update expected error lines. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@109336 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-pragma.c')
-rw-r--r--gcc/c-pragma.c58
1 files changed, 48 insertions, 10 deletions
diff --git a/gcc/c-pragma.c b/gcc/c-pragma.c
index 18eafcd96ad..e2a46773a95 100644
--- a/gcc/c-pragma.c
+++ b/gcc/c-pragma.c
@@ -37,6 +37,7 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
#include "vec.h"
#include "target.h"
+
#define GCC_BAD(gmsgid) \
do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
#define GCC_BAD2(gmsgid, arg) \
@@ -343,7 +344,7 @@ handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
t = pragma_lex (&x);
}
if (t != CPP_EOF)
- warning (OPT_Wpragmas, "junk at end of #pragma weak");
+ warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
decl = identifier_global_value (name);
if (decl && DECL_P (decl))
@@ -416,7 +417,7 @@ handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
GCC_BAD ("malformed #pragma redefine_extname, ignored");
t = pragma_lex (&x);
if (t != CPP_EOF)
- warning (OPT_Wpragmas, "junk at end of #pragma redefine_extname");
+ warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
if (!flag_mudflap && !targetm.handle_pragma_redefine_extname)
{
@@ -484,7 +485,7 @@ handle_pragma_extern_prefix (cpp_reader * ARG_UNUSED (dummy))
GCC_BAD ("malformed #pragma extern_prefix, ignored");
t = pragma_lex (&x);
if (t != CPP_EOF)
- warning (OPT_Wpragmas, "junk at end of #pragma extern_prefix");
+ warning (OPT_Wpragmas, "junk at end of %<#pragma extern_prefix%>");
if (targetm.handle_pragma_extern_prefix)
/* Note that the length includes the null terminator. */
@@ -667,26 +668,65 @@ handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
#endif
+/* A vector of registered pragma callbacks. */
+
+DEF_VEC_O (pragma_handler);
+DEF_VEC_ALLOC_O (pragma_handler, heap);
+
+static VEC(pragma_handler, heap) *registered_pragmas;
+
/* Front-end wrappers for pragma registration to avoid dragging
cpplib.h in almost everywhere. */
+
+static void
+c_register_pragma_1 (const char *space, const char *name,
+ pragma_handler handler, bool allow_expansion)
+{
+ unsigned id;
+
+ VEC_safe_push (pragma_handler, heap, registered_pragmas, &handler);
+ id = VEC_length (pragma_handler, registered_pragmas);
+ id += PRAGMA_FIRST_EXTERNAL - 1;
+
+ /* The C++ front end allocates 6 bits in cp_token; the C front end
+ allocates 7 bits in c_token. At present this is sufficient. */
+ gcc_assert (id < 64);
+
+ cpp_register_deferred_pragma (parse_in, space, name, id,
+ allow_expansion, false);
+}
+
void
-c_register_pragma (const char *space, const char *name,
- void (*handler) (struct cpp_reader *))
+c_register_pragma (const char *space, const char *name, pragma_handler handler)
{
- cpp_register_pragma (parse_in, space, name, handler, 0);
+ c_register_pragma_1 (space, name, handler, false);
}
void
c_register_pragma_with_expansion (const char *space, const char *name,
- void (*handler) (struct cpp_reader *))
+ pragma_handler handler)
+{
+ c_register_pragma_1 (space, name, handler, true);
+}
+
+void
+c_invoke_pragma_handler (unsigned int id)
{
- cpp_register_pragma (parse_in, space, name, handler, 1);
+ pragma_handler handler;
+
+ id -= PRAGMA_FIRST_EXTERNAL;
+ handler = *VEC_index (pragma_handler, registered_pragmas, id);
+
+ handler (parse_in);
}
/* Set up front-end pragmas. */
void
init_pragma (void)
{
+ cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
+ PRAGMA_GCC_PCH_PREPROCESS, false, false);
+
#ifdef HANDLE_PRAGMA_PACK
#ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
@@ -704,8 +744,6 @@ init_pragma (void)
c_register_pragma (0, "redefine_extname", handle_pragma_redefine_extname);
c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix);
- c_register_pragma ("GCC", "pch_preprocess", c_common_pch_pragma);
-
#ifdef REGISTER_TARGET_PRAGMAS
REGISTER_TARGET_PRAGMAS ();
#endif