[PATCH] D71356: [Tooling/Syntax] Helpers to find spelled tokens touching a location.

Ilya Biryukov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 12 01:48:54 PST 2019


ilya-biryukov added inline comments.


================
Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:260
+      All, [&](const syntax::Token &Tok) { return Tok.location() < Loc; });
+  bool AcceptRight = Right != All.end() && !(Loc < Right->location());
+  bool AcceptLeft = Right != All.begin() && !((Right - 1)->endLocation() < Loc);
----------------
NIT: why not `Right->location() <= Loc` instead of `!(Loc < Right->location)`?
Do we only overload `operator <` for `SourceLocations`?


================
Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:261
+  bool AcceptRight = Right != All.end() && !(Loc < Right->location());
+  bool AcceptLeft = Right != All.begin() && !((Right - 1)->endLocation() < Loc);
+  return llvm::makeArrayRef(Right - (AcceptLeft ? 1 : 0),
----------------
Maybe compare offsets instead of locations?
It might be more code, but it would read much cleaner.

It always feels weird to compare source locations for anything other than storing them in `std::map`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71356





More information about the cfe-commits mailing list