diff options
author | Yitzhak Mandelbaum <yitzhakm@google.com> | 2019-11-04 08:30:18 -0500 |
---|---|---|
committer | Yitzhak Mandelbaum <yitzhakm@google.com> | 2019-11-11 12:44:15 -0500 |
commit | 489449c28aaa45086d507fbad96826420adf409d (patch) | |
tree | aee53aafb71c762cbbb82c30688dd4ea7be00655 /clang/unittests/Tooling/TransformerTest.cpp | |
parent | 14df08f0580cea8f8bec5814e3b895b373001b56 (diff) | |
download | llvm-489449c28aaa45086d507fbad96826420adf409d.zip llvm-489449c28aaa45086d507fbad96826420adf409d.tar.gz llvm-489449c28aaa45086d507fbad96826420adf409d.tar.bz2 |
[libTooling] Further simplify `Stencil` type and introduce `MatchComputation`.
Summary:
This revision introduces a new interface `MatchComputation` which generalizes
the `Stencil` interface and replaces the `std::function` interface of
`MatchConsumer`. With this revision, `Stencil` (as an abstraction) becomes just
one collection of implementations of
`MatchComputation<std::string>`. Correspondingly, we remove the `Stencil` class
entirely in favor of a simple type alias, deprecate `MatchConsumer` and change
all functions that accepted `MatchConsumer<std::string>` to use
`MatchComputation<std::string>` instead.
Reviewers: gribozavr
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D69802
Diffstat (limited to 'clang/unittests/Tooling/TransformerTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/TransformerTest.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/clang/unittests/Tooling/TransformerTest.cpp b/clang/unittests/Tooling/TransformerTest.cpp index c99bf97..c382783 100644 --- a/clang/unittests/Tooling/TransformerTest.cpp +++ b/clang/unittests/Tooling/TransformerTest.cpp @@ -575,13 +575,16 @@ TEST_F(TransformerTest, TextGeneratorFailure) { std::string Input = "int conflictOneRule() { return 3 + 7; }"; // Try to change the whole binary-operator expression AND one its operands: StringRef O = "O"; - auto AlwaysFail = [](const ast_matchers::MatchFinder::MatchResult &) - -> llvm::Expected<std::string> { - return llvm::createStringError(llvm::errc::invalid_argument, "ERROR"); + class AlwaysFail : public transformer::MatchComputation<std::string> { + llvm::Error eval(const ast_matchers::MatchFinder::MatchResult &, + std::string *) const override { + return llvm::createStringError(llvm::errc::invalid_argument, "ERROR"); + } + std::string toString() const override { return "AlwaysFail"; } }; - Transformer T( - makeRule(binaryOperator().bind(O), changeTo(node(O), AlwaysFail)), - consumer()); + Transformer T(makeRule(binaryOperator().bind(O), + changeTo(node(O), std::make_shared<AlwaysFail>())), + consumer()); T.registerMatchers(&MatchFinder); EXPECT_FALSE(rewrite(Input)); EXPECT_THAT(Changes, IsEmpty()); |