[cfe-dev] More thoughts on user defined literals

AlisdairM(public) public at alisdairm.net
Wed Jul 8 18:24:50 PDT 2009


[Sorry Eli - I will get the hang of 'reply-all' soon...]

> -----Original Message-----
> From: Eli Friedman [mailto:eli.friedman at gmail.com]
> Sent: 09 July 2009 01:00
> To: AlisdairM(public)
> Cc: clang-dev Developers
> Subject: Re: [cfe-dev] More thoughts on user defined literals
> 
> On Wed, Jul 8, 2009 at 4:51 PM, AlisdairM(public)<public at alisdairm.net>
> wrote:
> > My inexperienced question is - when we move from lex to parse, is it
> easy to identify there is no whitespace between the literal component
> and the ud-suffix, or should I be trying to take care of this in the
> lexing phase?
> 
> You can check in the parser with hasLeadingSpace(), but it's probably
> better to handle it in the lexer; it would massively complicate the
> parser to check for a string in every single place that expects an
> identifier.

What if the ud-suffix was its own token though?
The lexer could flag this token as tok::literal_suffix, and we could embed the IdentifierInfo as with a regular identifier.  Ultimately a user-defined literal is a disguised function call, rather than a literal value, and the evaluation of that function could be any type quite unrelated to the preceding literal.  I am increasingly uncomfortable combining this information with a string literal (or character etc.)

AlisdairM







More information about the cfe-dev mailing list