diff options
author | Yitzhak Mandelbaum <yitzhakm@google.com> | 2019-09-23 13:21:42 +0000 |
---|---|---|
committer | Yitzhak Mandelbaum <yitzhakm@google.com> | 2019-09-23 13:21:42 +0000 |
commit | aa8d712ffccff9badf5a4313c271be6d0bb34399 (patch) | |
tree | e6597dd4d762d20eea480749b304f0b7fe68c690 /include/clang/Tooling | |
parent | 5612ffc5207ce1d757bfad8265452ffdc589d243 (diff) | |
download | clang-aa8d712ffccff9badf5a4313c271be6d0bb34399.tar.gz |
[libTooling] Add `access` and `ifBound` combinators to Stencil library.
Summary:
This revision add the `access` and `ifBound` combinators to the Stencil library:
* `access` -- constructs an idiomatic expression for accessing a member (a
`MemberExpr`).
* `ifBound` -- chooses between two `StencilParts` based on the whether an id is
bound in the match (corresponds to the combinator of the same name in
RangeSelector).
Reviewers: gribozavr
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67633
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@372605 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Tooling')
-rw-r--r-- | include/clang/Tooling/Refactoring/Stencil.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/clang/Tooling/Refactoring/Stencil.h b/include/clang/Tooling/Refactoring/Stencil.h index 1f24ccb261..43b0429d4e 100644 --- a/include/clang/Tooling/Refactoring/Stencil.h +++ b/include/clang/Tooling/Refactoring/Stencil.h @@ -153,6 +153,28 @@ inline StencilPart node(llvm::StringRef Id) { return selection(tooling::node(Id)); } +/// Constructs a `MemberExpr` that accesses the named member (\p Member) of the +/// object bound to \p BaseId. The access is constructed idiomatically: if \p +/// BaseId is bound to `e` and \p Member identifies member `m`, then returns +/// `e->m`, when e is a pointer, `e2->m` when e = `*e2` and `e.m` otherwise. +/// Additionally, `e` is wrapped in parentheses, if needed. +StencilPart access(llvm::StringRef BaseId, StencilPart Member); +inline StencilPart access(llvm::StringRef BaseId, llvm::StringRef Member) { + return access(BaseId, text(Member)); +} + +/// Chooses between the two stencil parts, based on whether \p ID is bound in +/// the match. +StencilPart ifBound(llvm::StringRef Id, StencilPart TruePart, + StencilPart FalsePart); + +/// Chooses between the two strings, based on whether \p ID is bound in the +/// match. +inline StencilPart ifBound(llvm::StringRef Id, llvm::StringRef TrueText, + llvm::StringRef FalseText) { + return ifBound(Id, text(TrueText), text(FalseText)); +} + /// For debug use only; semantics are not guaranteed. /// /// \returns the string resulting from calling the node's print() method. |