diff options
author | Kai Tietz <kai.tietz@onevision.com> | 2009-11-11 18:37:19 +0000 |
---|---|---|
committer | Kai Tietz <ktietz@gcc.gnu.org> | 2009-11-11 19:37:19 +0100 |
commit | 17e7cb855000baa6598005571d7dd49cfac5282a (patch) | |
tree | e54ead3691775dbb1e9d31588966d79cac024672 /libcpp/lex.c | |
parent | 110532c838d2302c88de13ad88f81ec975ed4b1e (diff) | |
download | gcc-17e7cb855000baa6598005571d7dd49cfac5282a.zip gcc-17e7cb855000baa6598005571d7dd49cfac5282a.tar.gz gcc-17e7cb855000baa6598005571d7dd49cfac5282a.tar.bz2 |
ChangeLog for libcpp
2009-11-11 Kai Tietz <kai.tietz@onevision.com>
* directives.c (do_pragma_push_macro): New pragma handler.
(do_pragma_pop_macro): Likewise.
(_cpp_init_internal_pragmas): Add push_macro and
pop_macro handler to internal pragmas.
(lex_macro_node_from_str): Removed.
(cpp_push_definition): Replace lex_macro_node_from_str
by _cpp_lex_identifier.
(cpp_pop_definition): Likewise.
* internal.h (_cpp_lex_identifier): New prototype.
(def_pragma_macro): New structure.
(cpp_reader): New member pushed_macros.
* lex.c (_cpp_lex_identifier): New function.
(lex_identifier_intern): New function.
* init.c (cpp_create_reader): Initialize pushed_macros
member.
(cpp_destroy): Free elements in pushed_macros member.
* pch.c (_cpp_save_pushed_macros): New function.
(_cpp_restore_pushed_macros): Likewise.
(_cpp_restore_pushed_macros): Use _cpp_save_pushed_macros.
(cpp_read_state): Use _cpp_restore_pushed_macros.
ChangeLog for gcc
2009-11-11 Kai Tietz <kai.tietz@onevision.com>
* config/i386/cygming.h (HANDLE_PRAGMA_PUSH_POP_MACRO):
Removed.
* c-pragma.c (def_pragma_macro_value): Likewise.
(def_pragma_macro): Likewise.
(pushed_macro_table): Likewise.
(HANDLE_PRAGMA_PUSH_POP_MACRO): Remove guarded
code.
* doc/tm.texi (HANDLE_PRAGMA_PUSH_POP_MACRO):
Removed.
ChangeLog for gcc/testsuite
2009-11-11 Kai Tietz <kai.tietz@onevision.com>
* g++.dg/torture/pushpop_macro.C: New testcase.
* gcc.c-torture/execute/pushpop_macro.c: New testcase.
* gcc.dg/cpp/pragma-pop_macro-1.c: Allow test for all
targets.
From-SVN: r154098
Diffstat (limited to 'libcpp/lex.c')
-rw-r--r-- | libcpp/lex.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/libcpp/lex.c b/libcpp/lex.c index 55bffa9..ac28f92 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -504,6 +504,63 @@ forms_identifier_p (cpp_reader *pfile, int first, return false; } +/* Helper function to get the cpp_hashnode of the identifier BASE. */ +static cpp_hashnode * +lex_identifier_intern (cpp_reader *pfile, const uchar *base) +{ + cpp_hashnode *result; + const uchar *cur; + unsigned int len; + unsigned int hash = HT_HASHSTEP (0, *base); + + cur = base + 1; + while (ISIDNUM (*cur)) + { + hash = HT_HASHSTEP (hash, *cur); + cur++; + } + len = cur - base; + hash = HT_HASHFINISH (hash, len); + result = CPP_HASHNODE (ht_lookup_with_hash (pfile->hash_table, + base, len, hash, HT_ALLOC)); + + /* Rarely, identifiers require diagnostics when lexed. */ + if (__builtin_expect ((result->flags & NODE_DIAGNOSTIC) + && !pfile->state.skipping, 0)) + { + /* It is allowed to poison the same identifier twice. */ + if ((result->flags & NODE_POISONED) && !pfile->state.poisoned_ok) + cpp_error (pfile, CPP_DL_ERROR, "attempt to use poisoned \"%s\"", + NODE_NAME (result)); + + /* Constraint 6.10.3.5: __VA_ARGS__ should only appear in the + replacement list of a variadic macro. */ + if (result == pfile->spec_nodes.n__VA_ARGS__ + && !pfile->state.va_args_ok) + cpp_error (pfile, CPP_DL_PEDWARN, + "__VA_ARGS__ can only appear in the expansion" + " of a C99 variadic macro"); + + /* For -Wc++-compat, warn about use of C++ named operators. */ + if (result->flags & NODE_WARN_OPERATOR) + cpp_error (pfile, CPP_DL_WARNING, + "identifier \"%s\" is a special operator name in C++", + NODE_NAME (result)); + } + + return result; +} + +/* Get the cpp_hashnode of an identifier specified by NAME in + the current cpp_reader object. If none is found, NULL is returned. */ +cpp_hashnode * +_cpp_lex_identifier (cpp_reader *pfile, const char *name) +{ + cpp_hashnode *result; + result = lex_identifier_intern (pfile, (uchar *) name); + return result; +} + /* Lex an identifier starting at BUFFER->CUR - 1. */ static cpp_hashnode * lex_identifier (cpp_reader *pfile, const uchar *base, bool starts_ucn, |