[PATCH] D61681: [clangd] A code tweak to expand a macro

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 1 05:22:46 PDT 2019


sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp:57
+  if (It == Spelled.begin())
+    return Spelled.end();
+  // Check the token we found actually touches the cursor position.
----------------
it's pretty weird for a function whose return type is spelled "Token*" to use Spelled.end() rather than nullptr as a sentinel


================
Comment at: clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp:125
+
+std::string ExpandMacro::title() const { return "Expand macro"; }
+
----------------
include macro name?


================
Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:288
+#define FUNC(X) X+X+X
+^F^O^O^ BAR ^F^O^O^
+^F^U^N^C^(1)
----------------
Can you verify we don't trigger here? `FOO[[ ]]BAR`

The zero-width range in `FOO^ BAR` is indeed interpreted as pointing at FOO by SelectionTree, but that's a whitespace-sensitive heuristic.

Given
```
int x(int);
#define B x
int y = B^(42);
```

The `^` points at the `(`. (Maybe we should lift this logic into Tweak::Selection)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61681





More information about the cfe-commits mailing list