[clang] [clang] add transformer range selector for spelled ranges (PR #177442)

Yitzhak Mandelbaum via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 27 08:16:26 PST 2026


================
@@ -437,3 +438,17 @@ RangeSelector transformer::expansion(RangeSelector S) {
     return Result.SourceManager->getExpansionRange(*SRange);
   };
 }
+
+RangeSelector transformer::spelled(RangeSelector S) {
+  return [S](const MatchResult &Result) -> Expected<CharSourceRange> {
+    Expected<CharSourceRange> SRange = S(Result);
+    if (!SRange)
+      return SRange.takeError();
+    const auto &SM = *Result.SourceManager;
+    const auto B = SRange->getBegin();
+    const auto E = SRange->getEnd();
+    return CharSourceRange(
+        SourceRange(SM.getSpellingLoc(B), SM.getSpellingLoc(E)),
+        SRange->isTokenRange());
----------------
ymand wrote:

In your comments, you mention that char ranges won't work (which I agree with). Given that, please update this code to explicitly reject them and add a corresponding test.

https://github.com/llvm/llvm-project/pull/177442


More information about the cfe-commits mailing list