Handle C2x attributes in Objective-C.
authorJoseph Myers <joseph@codesourcery.com>
Fri, 29 Nov 2019 01:06:57 +0000 (01:06 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Fri, 29 Nov 2019 01:06:57 +0000 (01:06 +0000)
commit34b43828f840640f8275712867fc52ef6c2714dd
tree562eed26a9a2096a4c4fd6e2005a1601c1484355
parent70ce1ab9fd2e201631b253bb62489d07189d2d50
Handle C2x attributes in Objective-C.

When adding the initial support for C2x attributes, I deferred the
unbounded lookahead support required to support such attributes in
Objective-C (except for the changes to string literal handling, which
were the riskier piece of preparation for such lookahead support).
This patch adds that remaining ObjC support.

For C, the parser continues to work exactly as it did before.  For
ObjC, however, when checking for whether '[[' starts attributes, it
lexes however many tokens are needed to check for a matching ']]', but
in a raw mode that omits all the context-sensitive processing that
c_lex_with_flags normally does, so that that processing can be done
later when the right context-sensitive flags are set.  Those tokens
are saved in a separate raw_tokens vector in the parser, and normal
c_lex_one_token calls will get tokens from there and perform the
remaining processing on them, if any tokens are found there, so all
parsing not using the new interfaces gets the same tokens as it did
before.  (For C, this raw lexing never occurs and the vector of raw
tokens is always NULL.)

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c:
* c-parser.c (struct c_parser): Add members raw_tokens and
raw_tokens_used.
(c_lex_one_token): Add argument raw.  Handle lexing raw tokens and
using previously-lexed raw tokens.
(c_parser_peek_nth_token_raw)
(c_parser_check_balanced_raw_token_sequence): New functions.
(c_parser_nth_token_starts_std_attributes): Use
c_parser_check_balanced_raw_token_sequence for Objective-C.

gcc/testsuite:
* objc.dg/attributes/gnu2x-attr-syntax-1.m: New test.

From-SVN: r278827
gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/objc.dg/attributes/gnu2x-attr-syntax-1.m [new file with mode: 0644]