[PATCH] Start to unify contextual keywords

Richard Smith richard at metafoo.co.uk
Thu Dec 12 12:47:08 PST 2013


I like the simplification here.

+  if (TagType == DeclSpec::TST_struct && Tok.isNot(tok::identifier)) {
+    const IdentifierInfo *II = Tok.getIdentifierInfo();

This will assert if there's an annotation token here (that might happen if
we've done some tentative parsing and annotated a nested name specifier).


The reverting-and-unreverting mechanism here seems unsatisfying. Perhaps we
should redesign this somewhat. How about changing the semantics to be
simply that these tokens are always normal identifiers, except when they're
followed by a left paren (in the case where your patch calls
TryIdentKeywordUpgrade).

Specifically, something like: change the RevertedTokenID flag on Token to a
ContextualKeyword flag or similar, set the kind to tok::identifier by
default for these traits, and generate a StringSwitch
in TryIdentKeywordUpgrade to pick the right kind. Then we can drop
the TryKeywordIdentFallback hack entirely -- the semantics would be simply
that these identifiers are normal identifiers unless they're followed by a
left paren.


On Thu, Dec 12, 2013 at 6:46 AM, Alp Toker <alp at nuanti.com> wrote:

> Hi,
>
> Now that we emit diagnostics for keyword-as-identifier hacks
> (-Wkeyword-compat) we can go ahead and simplify some of the old revertible
> keyword support.
>
> This patch adds a TryIdentKeywordUpgrade() function to mirror the recently
> added TryKeywordIdentFallback(), and uses it to replace hard-coded
> REVERTIBLE_TYPE_TRAITs.
>
> The mid-term goal is to work with libc++ to remove dependence on the GNU
> token hacks, and to unify context-sensitive keyword handing in the C++
> frontend.
>
>  4 files changed, 43 insertions(+), 70 deletions(-)
>
> Alp.
>
> --
> http://www.nuanti.com
> the browser experts
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131212/036b7c49/attachment.html>


More information about the cfe-commits mailing list