[PATCH] D77614: [Syntax] Simplify TokenCollector::Builder, use captured expansion bounds. NFC

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 6 18:01:37 PDT 2020


sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
sammccall updated this revision to Diff 255551.
sammccall added a comment.
sammccall added a child revision: D77615: [Syntax] Merge overlapping top-level macros in TokenBuffer.

drop accidental change


The motivation here is fixing https://bugs.llvm.org/show_bug.cgi?id=45428, see
D77507 <https://reviews.llvm.org/D77507>. The fundamental problem is that a "top-level" expansion wasn't precisely
defined. Repairing this concept means that TokenBuffer's "top-level expansion"
may not correspond to a single macro expansion. Example:

  #define ID(X) X
  #define M 1+ID
  M(2); // expands to 1+2

The expansions overlap, but neither expansion alone yields all the tokens.
We need a TokenBuffer::Mapping that corresponds to their union.

This is fairly easy to fix in CollectPPExpansions, but the current design of
TokenCollector::Builder needs a fix too as it relies on the macro's expansion
range rather than the captured expansion bounds. This fix is hard to make due
to the way code is reused within Builder. And honestly, I found that code pretty
hard to reason about too.

The new approach doesn't use the expansion range, but only the expansion
location: it assumes an expansion is the contiguous set of expanded tokens with
the same expansion location, which seems like a reasonable formalization of
the "top-level" notion.

And hopefully the control flow is easier to follow too, it's considerably
shorter even with more documentation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77614

Files:
  clang/lib/Tooling/Syntax/Tokens.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77614.255551.patch
Type: text/x-patch
Size: 13661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200407/ac1d72e9/attachment-0001.bin>


More information about the cfe-commits mailing list