[PATCH] D69625: [libTooling] Support implicit coercions in Stencil's `access` combinator.

Yitzhak Mandelbaum via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 30 09:58:39 PDT 2019


ymandel created this revision.
ymandel added a reviewer: gribozavr.
Herald added a project: clang.
ymandel added a parent revision: D69613: [libTooling] Simplify type structure of `Stencil`s..

Changes `clang::transformer::access` to also support `RangeSelector` as the
second argument.  This change makes `access` consistent with `cat` in that it
will accept text, `RangeSelector` or `Stencil`. The plan is for all Stencil
arguments to be supported in this way to provide a uniform user experience for
Stencil arguments.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69625

Files:
  clang/include/clang/Tooling/Transformer/Stencil.h
  clang/unittests/Tooling/StencilTest.cpp


Index: clang/unittests/Tooling/StencilTest.cpp
===================================================================
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -396,7 +396,7 @@
 }
 
 TEST(StencilToStringTest, AccessOpSelector) {
-  auto S = access("Id", selection(name("otherId")));
+  auto S = access("Id", name("otherId"));
   StringRef Expected = R"repr(access("Id", selection(...)))repr";
   EXPECT_EQ(S->toString(), Expected);
 }
Index: clang/include/clang/Tooling/Transformer/Stencil.h
===================================================================
--- clang/include/clang/Tooling/Transformer/Stencil.h
+++ clang/include/clang/Tooling/Transformer/Stencil.h
@@ -112,8 +112,8 @@
 /// `e->m`, when e is a pointer, `e2->m` when e = `*e2` and `e.m` otherwise.
 /// Additionally, `e` is wrapped in parentheses, if needed.
 Stencil access(llvm::StringRef BaseId, Stencil Member);
-inline Stencil access(llvm::StringRef BaseId, llvm::StringRef Member) {
-  return access(BaseId, text(Member));
+template <typename T> Stencil access(llvm::StringRef BaseId, T &&Member) {
+  return access(BaseId, makeStencil(std::forward<T>(Member)));
 }
 
 /// Chooses between the two stencil parts, based on whether \p ID is bound in


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69625.227131.patch
Type: text/x-patch
Size: 1267 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191030/3bc88d55/attachment.bin>


More information about the cfe-commits mailing list