[PATCH] Mimic MSVC whitespace collapse for incompatible token pasting

Will Wilson will at indefiant.com
Fri Apr 10 16:06:56 PDT 2015


Hi Reid,

On 11 April 2015 at 00:29, Reid Kleckner <rnk at google.com> wrote:
>
> I still think a local fix would be better. As a reader, it's hard to
> convince myself that the comment is correct:
> +  // MSVC: If previous token was pasted, this must be a recovery from an
> invalid
> +  // paste operation. Ignore spaces before this token to mimic MSVC
> output.
> +  // Required for generating valid UUID strings in some MS headers.
>
> Why is it that we only come here for invalid token pastes?
>

The doc for PasteTokens() gives the general premise of the function:


Tok is the LHS of a ## operator, and CurToken is the ##
operator.  Read the ## and RHS, and paste the LHS/RHS together.  If there
are more ## after it, chomp them iteratively.

Basically, if an invalid paste is attempted, the iteration is aborted and
the concatenated token is returned without doing any more pasting.
Therefore, assuming a successful PasteTokens() call would have consumed all
## operators, the only reason PasteTokens() would be called with an earlier
## in the Tokens array would be if the iteration were previously aborted.
At least, this is my understanding of it.

It's not pretty, but without rewriting the iteration logic to deal cleanly
with the MSVC pasting logic I'm not sure how to improve it... Any ideas?

- Will.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150411/66ea1d16/attachment.html>


More information about the cfe-commits mailing list