diff options
author | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-11-23 23:25:40 +0000 |
---|---|---|
committer | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-11-23 23:25:40 +0000 |
commit | 68bf2ad934202d583d12eff842fdeb4114f9c783 (patch) | |
tree | c218ffe339a9fcc74872e3e0827398246b77ded8 /libcpp | |
parent | ae21cabb6d56d24385469959a35d824e26ae3dfe (diff) | |
download | gcc-68bf2ad934202d583d12eff842fdeb4114f9c783.tar.gz |
gcc:
2004-11-23 Daniel Jacobowitz <dan@codesourcery.com>
Joseph Myers <joseph@codesourcery.com>
* config/sol2-c.c (solaris_register_pragmas): Use
c_register_pragma_with_expansion.
* config/sol2.h (HANDLE_PRAGMA_PACK_WITH_EXPANSION): Define.
* c-pragma.c (c_register_pragma): Update call to
cpp_register_pragma.
(c_register_pragma_with_expansion): New function.
(init_pragma): Honor HANDLE_PRAGMA_PACK_WITH_EXPANSION.
* c-pragma.h (c_register_pragma_with_expansion): New prototype.
* doc/extend.texi (Solaris Pragmas): Mention macro expansion for
#pragma align.
* doc/tm.texi (c_register_pragma_with_expansion,
HANDLE_PRAGMA_PACK_WITH_EXPANSION): Document.
gcc/testsuite:
2004-11-23 Daniel Jacobowitz <dan@codesourcery.com>
* gcc.dg/pragma-align-2.c: Test macro expansion.
* gcc.dg/pragma-pack-2.c: New test.
libcpp:
2004-11-23 Daniel Jacobowitz <dan@codesourcery.com>
Joseph Myers <joseph@codesourcery.com>
* internal.h (struct lexer_state): Add in_deferred_pragma.
* directives.c (struct pragma_entry): Add allow_expansion.
(insert_pragma_entry): Take allow_expansion flag.
(register_pragma): Likewise.
(cpp_register_pragma): Likewise.
(_cpp_init_internal_pragmas): Update calls to cpp_register_pragma.
(do_pragma): Honor allow_expansion.
(cpp_handle_deferred_pragma): Set in_deferred_pragma.
* include/cpplib.h (cpp_register_pragma): Update prototype.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@91117 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 13 | ||||
-rw-r--r-- | libcpp/directives.c | 48 | ||||
-rw-r--r-- | libcpp/include/cpplib.h | 2 | ||||
-rw-r--r-- | libcpp/internal.h | 3 |
4 files changed, 50 insertions, 16 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index eb5d76f7b33..3e8567bf05e 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,16 @@ +2004-11-23 Daniel Jacobowitz <dan@codesourcery.com> + Joseph Myers <joseph@codesourcery.com> + + * internal.h (struct lexer_state): Add in_deferred_pragma. + * directives.c (struct pragma_entry): Add allow_expansion. + (insert_pragma_entry): Take allow_expansion flag. + (register_pragma): Likewise. + (cpp_register_pragma): Likewise. + (_cpp_init_internal_pragmas): Update calls to cpp_register_pragma. + (do_pragma): Honor allow_expansion. + (cpp_handle_deferred_pragma): Set in_deferred_pragma. + * include/cpplib.h (cpp_register_pragma): Update prototype. + 2004-11-18 Daniel Jacobowitz <dan@codesourcery.com> Mark Mitchell <mark@codesourcery.com> diff --git a/libcpp/directives.c b/libcpp/directives.c index 10d080bee44..a835b6812a5 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -45,6 +45,7 @@ struct pragma_entry struct pragma_entry *next; const cpp_hashnode *pragma; /* Name and length. */ bool is_nspace; + bool allow_expansion; bool is_internal; union { pragma_cb handler; @@ -108,9 +109,9 @@ static struct pragma_entry *insert_pragma_entry (cpp_reader *, struct pragma_entry **, const cpp_hashnode *, pragma_cb, - bool); + bool, bool); static void register_pragma (cpp_reader *, const char *, const char *, - pragma_cb, bool); + pragma_cb, bool, bool); static int count_registered_pragmas (struct pragma_entry *); static char ** save_registered_pragmas (struct pragma_entry *, char **); static char ** restore_registered_pragmas (cpp_reader *, struct pragma_entry *, @@ -964,7 +965,7 @@ lookup_pragma_entry (struct pragma_entry *chain, const cpp_hashnode *pragma) static struct pragma_entry * insert_pragma_entry (cpp_reader *pfile, struct pragma_entry **chain, const cpp_hashnode *pragma, pragma_cb handler, - bool internal) + bool allow_expansion, bool internal) { struct pragma_entry *new; @@ -982,6 +983,7 @@ insert_pragma_entry (cpp_reader *pfile, struct pragma_entry **chain, new->u.space = NULL; } + new->allow_expansion = allow_expansion; new->is_internal = internal; new->next = *chain; *chain = new; @@ -990,12 +992,13 @@ insert_pragma_entry (cpp_reader *pfile, struct pragma_entry **chain, /* 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. INTERNAL is true if this is a pragma - registered by cpplib itself, false if it is registered via + which must be non-NULL. If ALLOW_EXPANSION is set, allow macro + expansion while parsing pragma NAME. INTERNAL is true if this is a + pragma registered by cpplib itself, false if it is registered via cpp_register_pragma */ static void register_pragma (cpp_reader *pfile, const char *space, const char *name, - pragma_cb handler, bool internal) + pragma_cb handler, bool allow_expansion, bool internal) { struct pragma_entry **chain = &pfile->pragmas; struct pragma_entry *entry; @@ -1009,7 +1012,8 @@ register_pragma (cpp_reader *pfile, const char *space, const char *name, node = cpp_lookup (pfile, U space, strlen (space)); entry = lookup_pragma_entry (*chain, node); if (!entry) - entry = insert_pragma_entry (pfile, chain, node, NULL, internal); + entry = insert_pragma_entry (pfile, chain, node, NULL, + allow_expansion, internal); else if (!entry->is_nspace) goto clash; chain = &entry->u.space; @@ -1032,17 +1036,20 @@ register_pragma (cpp_reader *pfile, const char *space, const char *name, cpp_error (pfile, CPP_DL_ICE, "#pragma %s is already registered", name); } else - insert_pragma_entry (pfile, chain, node, handler, internal); + insert_pragma_entry (pfile, chain, node, handler, allow_expansion, + internal); } /* 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. This function is exported from libcpp. */ + which must be non-NULL. If ALLOW_EXPANSION is set, allow macro + expansion while parsing pragma NAME. This function is exported + from libcpp. */ void cpp_register_pragma (cpp_reader *pfile, const char *space, const char *name, - pragma_cb handler) + pragma_cb handler, bool allow_expansion) { - register_pragma (pfile, space, name, handler, false); + register_pragma (pfile, space, name, handler, allow_expansion, false); } /* Register the pragmas the preprocessor itself handles. */ @@ -1050,12 +1057,14 @@ void _cpp_init_internal_pragmas (cpp_reader *pfile) { /* Pragmas in the global namespace. */ - register_pragma (pfile, 0, "once", do_pragma_once, true); + register_pragma (pfile, 0, "once", do_pragma_once, false, true); /* New GCC-specific pragmas should be put in the GCC namespace. */ - register_pragma (pfile, "GCC", "poison", do_pragma_poison, true); - register_pragma (pfile, "GCC", "system_header", do_pragma_system_header, true); - register_pragma (pfile, "GCC", "dependency", do_pragma_dependency, true); + register_pragma (pfile, "GCC", "poison", do_pragma_poison, false, true); + register_pragma (pfile, "GCC", "system_header", do_pragma_system_header, + false, true); + register_pragma (pfile, "GCC", "dependency", do_pragma_dependency, + false, true); } /* Return the number of registered pragmas in PE. */ @@ -1176,7 +1185,14 @@ do_pragma (cpp_reader *pfile) numbers in place. */ if (pfile->cb.line_change) (*pfile->cb.line_change) (pfile, pragma_token, false); + /* Never expand macros if handling a deferred pragma, since + the macro definitions now applicable may be different + from those at the point the pragma appeared. */ + if (p->allow_expansion && !pfile->state.in_deferred_pragma) + pfile->state.prevent_expansion--; (*p->u.handler) (pfile); + if (p->allow_expansion && !pfile->state.in_deferred_pragma) + pfile->state.prevent_expansion++; } else { @@ -1430,6 +1446,7 @@ cpp_handle_deferred_pragma (cpp_reader *pfile, const cpp_string *s) pfile->context->macro = 0; pfile->context->prev = 0; pfile->cb.line_change = NULL; + pfile->state.in_deferred_pragma = true; CPP_OPTION (pfile, defer_pragmas) = false; run_directive (pfile, T_PRAGMA, (const char *)s->text, s->len); @@ -1439,6 +1456,7 @@ cpp_handle_deferred_pragma (cpp_reader *pfile, const cpp_string *s) pfile->cur_token = saved_cur_token; pfile->cur_run = saved_cur_run; pfile->cb.line_change = saved_line_change; + pfile->state.in_deferred_pragma = false; CPP_OPTION (pfile, defer_pragmas) = saved_defer_pragmas; } diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 4ee626ecd1c..13213882aa8 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -638,7 +638,7 @@ extern unsigned char *cpp_token_as_text (cpp_reader *, const cpp_token *); extern unsigned char *cpp_spell_token (cpp_reader *, const cpp_token *, unsigned char *); extern void cpp_register_pragma (cpp_reader *, const char *, const char *, - void (*) (cpp_reader *)); + void (*) (cpp_reader *), bool); extern void cpp_handle_deferred_pragma (cpp_reader *, const cpp_string *); extern int cpp_avoid_paste (cpp_reader *, const cpp_token *, const cpp_token *); diff --git a/libcpp/internal.h b/libcpp/internal.h index 15a3dfada9e..70694fd039d 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -205,6 +205,9 @@ struct lexer_state /* Nonzero to prevent macro expansion. */ unsigned char prevent_expansion; + /* Nonzero when handling a deferred pragma. */ + unsigned char in_deferred_pragma; + /* Nonzero when parsing arguments to a function-like macro. */ unsigned char parsing_args; |