[PATCH] D116618: [clangd] Use the localSourceRange as the default claimed range for typelocs.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 4 13:43:17 PST 2022


sammccall added a comment.

This is neat, and I we're getting closer to the principled answer.
After staring at this patch for a while, and seeing what arrays, functions, and now parens have in common, I finally understand. The problem is *declarators*.

Declarators are inside-out: `((*x)[](double)` says that x is a pointer to an array to a function from double.
Whereas types that are decl-specifiers nest the other way: that would be written `pointer<array<function<double>>>`, just like decls or stmts nest.

So for decl-specifier TypeLocs the usual getSourceRange should apply. (Modulo hacks like decltype() where the range is just wrong).

For typelocs that are part of the declarator, there are two approaches that seem principled:

- claim their full range, but in the opposite order (parents before children)
- claim only the specific tokens used, in which case order doesn't matter

These are basically equivalent. declarator types have a "before" and an "after" chunk (see TypePrinter). They can claim these by claiming their full range, but the "gap" was claimed earlier, or they can claim the two ends separately.
If we can make it work, claiming the full range is probably better because it will handle unexpected stray tokens in a more natural way. 
Either way we should be able to unify this with the DeclaratorDecl hack.

I'll have a play with this idea...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116618/new/

https://reviews.llvm.org/D116618



More information about the cfe-commits mailing list