From a5f406013645696985998bdaf1d4d85c95a280dd Mon Sep 17 00:00:00 2001 From: Yitzhak Mandelbaum Date: Wed, 16 Oct 2019 01:06:46 +0000 Subject: [PATCH] [libTooling] Put all Transformer declarations in a single namespace. Summary: This revision introduces a new namespace, `clang::transformer`, to hold the declarations for the Transformer library. Reviewers: gribozavr Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68876 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374962 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../clang/Tooling/Transformer/MatchConsumer.h | 8 +++- .../clang/Tooling/Transformer/RangeSelector.h | 20 +++++++++- .../clang/Tooling/Transformer/RewriteRule.h | 21 +++++++++- include/clang/Tooling/Transformer/Stencil.h | 34 +++++++++++----- .../clang/Tooling/Transformer/Transformer.h | 4 +- lib/Tooling/Transformer/RangeSelector.cpp | 40 ++++++++++--------- lib/Tooling/Transformer/RewriteRule.cpp | 30 +++++++------- lib/Tooling/Transformer/Stencil.cpp | 39 +++++++++--------- lib/Tooling/Transformer/Transformer.cpp | 13 +++--- unittests/Tooling/RangeSelectorTest.cpp | 8 ++-- unittests/Tooling/StencilTest.cpp | 13 +----- unittests/Tooling/TransformerTest.cpp | 11 ++--- 12 files changed, 146 insertions(+), 95 deletions(-) diff --git a/include/clang/Tooling/Transformer/MatchConsumer.h b/include/clang/Tooling/Transformer/MatchConsumer.h index 51eb6af25a..0a1dbe13ea 100644 --- a/include/clang/Tooling/Transformer/MatchConsumer.h +++ b/include/clang/Tooling/Transformer/MatchConsumer.h @@ -22,8 +22,7 @@ #include "llvm/Support/Error.h" namespace clang { -namespace tooling { - +namespace transformer { /// A failable computation over nodes bound by AST matchers. /// /// The computation should report any errors though its return value (rather @@ -52,7 +51,12 @@ MatchConsumer ifBound(std::string ID, MatchConsumer TrueC, return (Map.find(ID) != Map.end() ? TrueC : FalseC)(Result); }; } +} // namespace transformer +namespace tooling { +// DEPRECATED: Temporary alias supporting client migration to the `transformer` +// namespace. +using transformer::ifBound; } // namespace tooling } // namespace clang #endif // LLVM_CLANG_TOOLING_TRANSFORMER_MATCH_CONSUMER_H_ diff --git a/include/clang/Tooling/Transformer/RangeSelector.h b/include/clang/Tooling/Transformer/RangeSelector.h index e178fb36a8..00f1f84d0f 100644 --- a/include/clang/Tooling/Transformer/RangeSelector.h +++ b/include/clang/Tooling/Transformer/RangeSelector.h @@ -23,7 +23,7 @@ #include namespace clang { -namespace tooling { +namespace transformer { using RangeSelector = MatchConsumer; inline RangeSelector charRange(CharSourceRange R) { @@ -87,6 +87,24 @@ RangeSelector elseBranch(std::string ID); /// source), if `S` is an expansion, and `S` itself, otherwise. Corresponds to /// `SourceManager::getExpansionRange`. RangeSelector expansion(RangeSelector S); +} // namespace transformer + +namespace tooling { +// DEPRECATED: These are temporary aliases supporting client migration to the +// `transformer` namespace. +using transformer::after; +using transformer::before; +using transformer::callArgs; +using transformer::charRange; +using transformer::elseBranch; +using transformer::expansion; +using transformer::initListElements; +using transformer::member; +using transformer::name; +using transformer::node; +using transformer::range; +using transformer::statement; +using transformer::statements; } // namespace tooling } // namespace clang diff --git a/include/clang/Tooling/Transformer/RewriteRule.h b/include/clang/Tooling/Transformer/RewriteRule.h index 902a9d5bfa..058ef3f23d 100644 --- a/include/clang/Tooling/Transformer/RewriteRule.h +++ b/include/clang/Tooling/Transformer/RewriteRule.h @@ -29,9 +29,8 @@ #include namespace clang { -namespace tooling { +namespace transformer { using TextGenerator = MatchConsumer; - /// Wraps a string as a TextGenerator. inline TextGenerator text(std::string M) { return [M](const ast_matchers::MatchFinder::MatchResult &) @@ -282,6 +281,24 @@ Expected> translateEdits(const ast_matchers::MatchFinder::MatchResult &Result, llvm::ArrayRef Edits); } // namespace detail +} // namespace transformer + +namespace tooling { +// DEPRECATED: These are temporary aliases supporting client migration to the +// `transformer` namespace. +using transformer::addInclude; +using transformer::applyFirst; +using transformer::change; +using transformer::insertAfter; +using transformer::insertBefore; +using transformer::makeRule; +using transformer::remove; +using transformer::text; +using transformer::RewriteRule; +using transformer::IncludeFormat; +namespace detail { +using namespace transformer::detail; +} // namespace detail } // namespace tooling } // namespace clang diff --git a/include/clang/Tooling/Transformer/Stencil.h b/include/clang/Tooling/Transformer/Stencil.h index eeb5902444..feb3ac8853 100644 --- a/include/clang/Tooling/Transformer/Stencil.h +++ b/include/clang/Tooling/Transformer/Stencil.h @@ -31,8 +31,7 @@ #include namespace clang { -namespace tooling { - +namespace transformer { /// A stencil is represented as a sequence of "parts" that can each individually /// generate a code string based on a match result. The different kinds of /// parts include (raw) text, references to bound nodes and assorted operations @@ -133,8 +132,10 @@ private: std::vector Parts; }; +// // Functions for conveniently building stencils. -namespace stencil { +// + /// Convenience wrapper for Stencil::cat that can be imported with a using decl. template Stencil cat(Ts &&... Parts) { return Stencil::cat(std::forward(Parts)...); @@ -146,12 +147,6 @@ StencilPart text(llvm::StringRef Text); /// \returns the source corresponding to the selected range. StencilPart selection(RangeSelector Selector); -/// \returns the source corresponding to the identified node. -/// FIXME: Deprecated. Write `selection(node(Id))` instead. -inline StencilPart node(llvm::StringRef Id) { - return selection(tooling::node(Id)); -} - /// Generates the source of the expression bound to \p Id, wrapping it in /// parentheses if it may parse differently depending on context. For example, a /// binary operation is always wrapped, while a variable reference is never @@ -197,6 +192,27 @@ StencilPart run(MatchConsumer C); /// /// \returns the string resulting from calling the node's print() method. StencilPart dPrint(llvm::StringRef Id); +} // namespace transformer + +namespace tooling { +namespace stencil { +// DEPRECATED: These are temporary aliases supporting client migration to the +// `transformer` namespace. +using transformer::access; +using transformer::addressOf; +using transformer::cat; +using transformer::deref; +using transformer::dPrint; +using transformer::expression; +using transformer::ifBound; +using transformer::run; +using transformer::selection; +using transformer::text; +/// \returns the source corresponding to the identified node. +/// FIXME: Deprecated. Write `selection(node(Id))` instead. +inline transformer::StencilPart node(llvm::StringRef Id) { + return selection(tooling::node(Id)); +} } // namespace stencil } // namespace tooling } // namespace clang diff --git a/include/clang/Tooling/Transformer/Transformer.h b/include/clang/Tooling/Transformer/Transformer.h index d714d446d5..31feacba5e 100644 --- a/include/clang/Tooling/Transformer/Transformer.h +++ b/include/clang/Tooling/Transformer/Transformer.h @@ -30,7 +30,7 @@ public: /// because of macros, but doesn't fail. Note that clients are responsible /// for handling the case that independent \c AtomicChanges conflict with each /// other. - Transformer(RewriteRule Rule, ChangeConsumer Consumer) + Transformer(transformer::RewriteRule Rule, ChangeConsumer Consumer) : Rule(std::move(Rule)), Consumer(std::move(Consumer)) {} /// N.B. Passes `this` pointer to `MatchFinder`. So, this object should not @@ -42,7 +42,7 @@ public: void run(const ast_matchers::MatchFinder::MatchResult &Result) override; private: - RewriteRule Rule; + transformer::RewriteRule Rule; /// Receives each successful rewrites as an \c AtomicChange. ChangeConsumer Consumer; }; diff --git a/lib/Tooling/Transformer/RangeSelector.cpp b/lib/Tooling/Transformer/RangeSelector.cpp index 496c2d987c..9f81423c90 100644 --- a/lib/Tooling/Transformer/RangeSelector.cpp +++ b/lib/Tooling/Transformer/RangeSelector.cpp @@ -20,7 +20,7 @@ #include using namespace clang; -using namespace tooling; +using namespace transformer; using ast_matchers::MatchFinder; using ast_type_traits::ASTNodeKind; @@ -104,7 +104,7 @@ static SourceLocation findOpenParen(const CallExpr &E, const SourceManager &SM, return findPreviousTokenKind(EndLoc, SM, LangOpts, tok::TokenKind::l_paren); } -RangeSelector tooling::before(RangeSelector Selector) { +RangeSelector transformer::before(RangeSelector Selector) { return [Selector](const MatchResult &Result) -> Expected { Expected SelectedRange = Selector(Result); if (!SelectedRange) @@ -113,7 +113,7 @@ RangeSelector tooling::before(RangeSelector Selector) { }; } -RangeSelector tooling::after(RangeSelector Selector) { +RangeSelector transformer::after(RangeSelector Selector) { return [Selector](const MatchResult &Result) -> Expected { Expected SelectedRange = Selector(Result); if (!SelectedRange) @@ -126,27 +126,29 @@ RangeSelector tooling::after(RangeSelector Selector) { }; } -RangeSelector tooling::node(std::string ID) { +RangeSelector transformer::node(std::string ID) { return [ID](const MatchResult &Result) -> Expected { Expected Node = getNode(Result.Nodes, ID); if (!Node) return Node.takeError(); return Node->get() != nullptr && Node->get() == nullptr - ? getExtendedRange(*Node, tok::TokenKind::semi, *Result.Context) + ? tooling::getExtendedRange(*Node, tok::TokenKind::semi, + *Result.Context) : CharSourceRange::getTokenRange(Node->getSourceRange()); }; } -RangeSelector tooling::statement(std::string ID) { +RangeSelector transformer::statement(std::string ID) { return [ID](const MatchResult &Result) -> Expected { Expected Node = getNode(Result.Nodes, ID); if (!Node) return Node.takeError(); - return getExtendedRange(*Node, tok::TokenKind::semi, *Result.Context); + return tooling::getExtendedRange(*Node, tok::TokenKind::semi, + *Result.Context); }; } -RangeSelector tooling::range(RangeSelector Begin, RangeSelector End) { +RangeSelector transformer::range(RangeSelector Begin, RangeSelector End) { return [Begin, End](const MatchResult &Result) -> Expected { Expected BeginRange = Begin(Result); if (!BeginRange) @@ -165,11 +167,11 @@ RangeSelector tooling::range(RangeSelector Begin, RangeSelector End) { }; } -RangeSelector tooling::range(std::string BeginID, std::string EndID) { - return tooling::range(node(std::move(BeginID)), node(std::move(EndID))); +RangeSelector transformer::range(std::string BeginID, std::string EndID) { + return transformer::range(node(std::move(BeginID)), node(std::move(EndID))); } -RangeSelector tooling::member(std::string ID) { +RangeSelector transformer::member(std::string ID) { return [ID](const MatchResult &Result) -> Expected { Expected Node = getNode(Result.Nodes, ID); if (!Node) @@ -181,7 +183,7 @@ RangeSelector tooling::member(std::string ID) { }; } -RangeSelector tooling::name(std::string ID) { +RangeSelector transformer::name(std::string ID) { return [ID](const MatchResult &Result) -> Expected { Expected N = getNode(Result.Nodes, ID); if (!N) @@ -197,7 +199,7 @@ RangeSelector tooling::name(std::string ID) { // `foo` for which this range will be too short. Doing so will // require subcasing `NamedDecl`, because it doesn't provide virtual // access to the \c DeclarationNameInfo. - if (getText(R, *Result.Context) != D->getName()) + if (tooling::getText(R, *Result.Context) != D->getName()) return CharSourceRange(); return R; } @@ -256,7 +258,7 @@ CharSourceRange getStatementsRange(const MatchResult &, } } // namespace -RangeSelector tooling::statements(std::string ID) { +RangeSelector transformer::statements(std::string ID) { return RelativeSelector(std::move(ID)); } @@ -271,7 +273,7 @@ CharSourceRange getCallArgumentsRange(const MatchResult &Result, } } // namespace -RangeSelector tooling::callArgs(std::string ID) { +RangeSelector transformer::callArgs(std::string ID) { return RelativeSelector(std::move(ID)); } @@ -285,24 +287,24 @@ CharSourceRange getElementsRange(const MatchResult &, } } // namespace -RangeSelector tooling::initListElements(std::string ID) { +RangeSelector transformer::initListElements(std::string ID) { return RelativeSelector(std::move(ID)); } namespace { // Returns the range of the else branch, including the `else` keyword. CharSourceRange getElseRange(const MatchResult &Result, const IfStmt &S) { - return maybeExtendRange( + return tooling::maybeExtendRange( CharSourceRange::getTokenRange(S.getElseLoc(), S.getEndLoc()), tok::TokenKind::semi, *Result.Context); } } // namespace -RangeSelector tooling::elseBranch(std::string ID) { +RangeSelector transformer::elseBranch(std::string ID) { return RelativeSelector(std::move(ID)); } -RangeSelector tooling::expansion(RangeSelector S) { +RangeSelector transformer::expansion(RangeSelector S) { return [S](const MatchResult &Result) -> Expected { Expected SRange = S(Result); if (!SRange) diff --git a/lib/Tooling/Transformer/RewriteRule.cpp b/lib/Tooling/Transformer/RewriteRule.cpp index 605b5031ca..6fa558f7b2 100644 --- a/lib/Tooling/Transformer/RewriteRule.cpp +++ b/lib/Tooling/Transformer/RewriteRule.cpp @@ -21,7 +21,7 @@ #include using namespace clang; -using namespace tooling; +using namespace transformer; using ast_matchers::MatchFinder; using ast_matchers::internal::DynTypedMatcher; @@ -29,16 +29,16 @@ using ast_type_traits::ASTNodeKind; using MatchResult = MatchFinder::MatchResult; -Expected> -tooling::detail::translateEdits(const MatchResult &Result, +Expected> +transformer::detail::translateEdits(const MatchResult &Result, llvm::ArrayRef Edits) { - SmallVector Transformations; + SmallVector Transformations; for (const auto &Edit : Edits) { Expected Range = Edit.TargetRange(Result); if (!Range) return Range.takeError(); llvm::Optional EditRange = - getRangeForEdit(*Range, *Result.Context); + tooling::getRangeForEdit(*Range, *Result.Context); // FIXME: let user specify whether to treat this case as an error or ignore // it as is currently done. if (!EditRange) @@ -46,7 +46,7 @@ tooling::detail::translateEdits(const MatchResult &Result, auto Replacement = Edit.Replacement(Result); if (!Replacement) return Replacement.takeError(); - tooling::detail::Transformation T; + transformer::detail::Transformation T; T.Range = *EditRange; T.Replacement = std::move(*Replacement); Transformations.push_back(std::move(T)); @@ -54,20 +54,20 @@ tooling::detail::translateEdits(const MatchResult &Result, return Transformations; } -ASTEdit tooling::change(RangeSelector S, TextGenerator Replacement) { +ASTEdit transformer::change(RangeSelector S, TextGenerator Replacement) { ASTEdit E; E.TargetRange = std::move(S); E.Replacement = std::move(Replacement); return E; } -RewriteRule tooling::makeRule(DynTypedMatcher M, SmallVector Edits, +RewriteRule transformer::makeRule(DynTypedMatcher M, SmallVector Edits, TextGenerator Explanation) { return RewriteRule{{RewriteRule::Case{ std::move(M), std::move(Edits), std::move(Explanation), {}}}}; } -void tooling::addInclude(RewriteRule &Rule, StringRef Header, +void transformer::addInclude(RewriteRule &Rule, StringRef Header, IncludeFormat Format) { for (auto &Case : Rule.Cases) Case.AddedIncludes.emplace_back(Header.str(), Format); @@ -103,7 +103,7 @@ static std::vector taggedMatchers( // Simply gathers the contents of the various rules into a single rule. The // actual work to combine these into an ordered choice is deferred to matcher // registration. -RewriteRule tooling::applyFirst(ArrayRef Rules) { +RewriteRule transformer::applyFirst(ArrayRef Rules) { RewriteRule R; for (auto &Rule : Rules) R.Cases.append(Rule.Cases.begin(), Rule.Cases.end()); @@ -111,7 +111,7 @@ RewriteRule tooling::applyFirst(ArrayRef Rules) { } std::vector -tooling::detail::buildMatchers(const RewriteRule &Rule) { +transformer::detail::buildMatchers(const RewriteRule &Rule) { // Map the cases into buckets of matchers -- one for each "root" AST kind, // which guarantees that they can be combined in a single anyOf matcher. Each // case is paired with an identifying number that is converted to a string id @@ -137,17 +137,17 @@ tooling::detail::buildMatchers(const RewriteRule &Rule) { return Matchers; } -DynTypedMatcher tooling::detail::buildMatcher(const RewriteRule &Rule) { +DynTypedMatcher transformer::detail::buildMatcher(const RewriteRule &Rule) { std::vector Ms = buildMatchers(Rule); assert(Ms.size() == 1 && "Cases must have compatible matchers."); return Ms[0]; } -SourceLocation tooling::detail::getRuleMatchLoc(const MatchResult &Result) { +SourceLocation transformer::detail::getRuleMatchLoc(const MatchResult &Result) { auto &NodesMap = Result.Nodes.getMap(); auto Root = NodesMap.find(RewriteRule::RootID); assert(Root != NodesMap.end() && "Transformation failed: missing root node."); - llvm::Optional RootRange = getRangeForEdit( + llvm::Optional RootRange = tooling::getRangeForEdit( CharSourceRange::getTokenRange(Root->second.getSourceRange()), *Result.Context); if (RootRange) @@ -161,7 +161,7 @@ SourceLocation tooling::detail::getRuleMatchLoc(const MatchResult &Result) { // Finds the case that was "selected" -- that is, whose matcher triggered the // `MatchResult`. const RewriteRule::Case & -tooling::detail::findSelectedCase(const MatchResult &Result, +transformer::detail::findSelectedCase(const MatchResult &Result, const RewriteRule &Rule) { if (Rule.Cases.size() == 1) return Rule.Cases[0]; diff --git a/lib/Tooling/Transformer/Stencil.cpp b/lib/Tooling/Transformer/Stencil.cpp index d252449418..984950a54e 100644 --- a/lib/Tooling/Transformer/Stencil.cpp +++ b/lib/Tooling/Transformer/Stencil.cpp @@ -22,7 +22,7 @@ #include using namespace clang; -using namespace tooling; +using namespace transformer; using ast_matchers::MatchFinder; using ast_type_traits::DynTypedNode; @@ -171,13 +171,13 @@ Error evalData(const UnaryOperationData &Data, llvm::Optional Source; switch (Data.Op) { case UnaryNodeOperator::Parens: - Source = buildParens(*E, *Match.Context); + Source = tooling::buildParens(*E, *Match.Context); break; case UnaryNodeOperator::Deref: - Source = buildDereference(*E, *Match.Context); + Source = tooling::buildDereference(*E, *Match.Context); break; case UnaryNodeOperator::Address: - Source = buildAddressOf(*E, *Match.Context); + Source = tooling::buildAddressOf(*E, *Match.Context); break; } if (!Source) @@ -193,7 +193,7 @@ Error evalData(const SelectorData &Data, const MatchFinder::MatchResult &Match, auto Range = Data.Selector(Match); if (!Range) return Range.takeError(); - *Result += getText(*Range, *Match.Context); + *Result += tooling::getText(*Range, *Match.Context); return Error::success(); } @@ -204,9 +204,10 @@ Error evalData(const AccessData &Data, const MatchFinder::MatchResult &Match, return llvm::make_error(errc::invalid_argument, "Id not bound: " + Data.BaseId); if (!E->isImplicitCXXThis()) { - if (llvm::Optional S = E->getType()->isAnyPointerType() - ? buildArrow(*E, *Match.Context) - : buildDot(*E, *Match.Context)) + if (llvm::Optional S = + E->getType()->isAnyPointerType() + ? tooling::buildArrow(*E, *Match.Context) + : tooling::buildDot(*E, *Match.Context)) *Result += *S; else return llvm::make_error( @@ -250,11 +251,11 @@ public: } // namespace StencilPart Stencil::wrap(StringRef Text) { - return stencil::text(Text); + return transformer::text(Text); } StencilPart Stencil::wrap(RangeSelector Selector) { - return stencil::selection(std::move(Selector)); + return transformer::selection(std::move(Selector)); } void Stencil::append(Stencil OtherStencil) { @@ -271,46 +272,46 @@ Stencil::eval(const MatchFinder::MatchResult &Match) const { return Result; } -StencilPart stencil::text(StringRef Text) { +StencilPart transformer::text(StringRef Text) { return StencilPart(std::make_shared>(Text)); } -StencilPart stencil::selection(RangeSelector Selector) { +StencilPart transformer::selection(RangeSelector Selector) { return StencilPart( std::make_shared>(std::move(Selector))); } -StencilPart stencil::dPrint(StringRef Id) { +StencilPart transformer::dPrint(StringRef Id) { return StencilPart(std::make_shared>(Id)); } -StencilPart stencil::expression(llvm::StringRef Id) { +StencilPart transformer::expression(llvm::StringRef Id) { return StencilPart(std::make_shared>( UnaryNodeOperator::Parens, Id)); } -StencilPart stencil::deref(llvm::StringRef ExprId) { +StencilPart transformer::deref(llvm::StringRef ExprId) { return StencilPart(std::make_shared>( UnaryNodeOperator::Deref, ExprId)); } -StencilPart stencil::addressOf(llvm::StringRef ExprId) { +StencilPart transformer::addressOf(llvm::StringRef ExprId) { return StencilPart(std::make_shared>( UnaryNodeOperator::Address, ExprId)); } -StencilPart stencil::access(StringRef BaseId, StencilPart Member) { +StencilPart transformer::access(StringRef BaseId, StencilPart Member) { return StencilPart( std::make_shared>(BaseId, std::move(Member))); } -StencilPart stencil::ifBound(StringRef Id, StencilPart TruePart, +StencilPart transformer::ifBound(StringRef Id, StencilPart TruePart, StencilPart FalsePart) { return StencilPart(std::make_shared>( Id, std::move(TruePart), std::move(FalsePart))); } -StencilPart stencil::run(MatchConsumer Fn) { +StencilPart transformer::run(MatchConsumer Fn) { return StencilPart( std::make_shared>>( std::move(Fn))); diff --git a/lib/Tooling/Transformer/Transformer.cpp b/lib/Tooling/Transformer/Transformer.cpp index 3baa1b9ff2..71f0646f4c 100644 --- a/lib/Tooling/Transformer/Transformer.cpp +++ b/lib/Tooling/Transformer/Transformer.cpp @@ -21,7 +21,7 @@ using namespace tooling; using ast_matchers::MatchFinder; void Transformer::registerMatchers(MatchFinder *MatchFinder) { - for (auto &Matcher : tooling::detail::buildMatchers(Rule)) + for (auto &Matcher : transformer::detail::buildMatchers(Rule)) MatchFinder->addDynamicMatcher(Matcher, this); } @@ -29,8 +29,9 @@ void Transformer::run(const MatchFinder::MatchResult &Result) { if (Result.Context->getDiagnostics().hasErrorOccurred()) return; - RewriteRule::Case Case = tooling::detail::findSelectedCase(Result, Rule); - auto Transformations = tooling::detail::translateEdits(Result, Case.Edits); + transformer::RewriteRule::Case Case = + transformer::detail::findSelectedCase(Result, Rule); + auto Transformations = transformer::detail::translateEdits(Result, Case.Edits); if (!Transformations) { Consumer(Transformations.takeError()); return; @@ -38,7 +39,7 @@ void Transformer::run(const MatchFinder::MatchResult &Result) { if (Transformations->empty()) { // No rewrite applied (but no error encountered either). - tooling::detail::getRuleMatchLoc(Result).print( + transformer::detail::getRuleMatchLoc(Result).print( llvm::errs() << "note: skipping match at loc ", *Result.SourceManager); llvm::errs() << "\n"; return; @@ -58,10 +59,10 @@ void Transformer::run(const MatchFinder::MatchResult &Result) { for (const auto &I : Case.AddedIncludes) { auto &Header = I.first; switch (I.second) { - case IncludeFormat::Quoted: + case transformer::IncludeFormat::Quoted: AC.addHeader(Header); break; - case IncludeFormat::Angled: + case transformer::IncludeFormat::Angled: AC.addHeader((llvm::Twine("<") + Header + ">").str()); break; } diff --git a/unittests/Tooling/RangeSelectorTest.cpp b/unittests/Tooling/RangeSelectorTest.cpp index 29a20a9f18..8a7d555e61 100644 --- a/unittests/Tooling/RangeSelectorTest.cpp +++ b/unittests/Tooling/RangeSelectorTest.cpp @@ -9,15 +9,15 @@ #include "clang/Tooling/Transformer/RangeSelector.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Frontend/ASTUnit.h" -#include "clang/Tooling/FixIt.h" #include "clang/Tooling/Tooling.h" +#include "clang/Tooling/Transformer/SourceCode.h" #include "llvm/Support/Error.h" #include "llvm/Testing/Support/Error.h" #include "gmock/gmock.h" #include "gtest/gtest.h" using namespace clang; -using namespace tooling; +using namespace transformer; using namespace ast_matchers; namespace { @@ -40,7 +40,7 @@ struct TestMatch { }; template TestMatch matchCode(StringRef Code, M Matcher) { - auto ASTUnit = buildASTFromCode(Code); + auto ASTUnit = tooling::buildASTFromCode(Code); assert(ASTUnit != nullptr && "AST construction failed"); ASTContext &Context = ASTUnit->getASTContext(); @@ -59,7 +59,7 @@ Expected select(RangeSelector Selector, const TestMatch &Match) { Expected Range = Selector(Match.Result); if (!Range) return Range.takeError(); - return fixit::internal::getText(*Range, *Match.Result.Context); + return tooling::getText(*Range, *Match.Result.Context); } // Applies \p Selector to a trivial match with only a single bound node with id diff --git a/unittests/Tooling/StencilTest.cpp b/unittests/Tooling/StencilTest.cpp index c524441beb..c62eae79d2 100644 --- a/unittests/Tooling/StencilTest.cpp +++ b/unittests/Tooling/StencilTest.cpp @@ -16,7 +16,7 @@ #include "gtest/gtest.h" using namespace clang; -using namespace tooling; +using namespace transformer; using namespace ast_matchers; namespace { @@ -27,15 +27,6 @@ using ::testing::AllOf; using ::testing::Eq; using ::testing::HasSubstr; using MatchResult = MatchFinder::MatchResult; -using stencil::access; -using stencil::addressOf; -using stencil::cat; -using stencil::deref; -using stencil::dPrint; -using stencil::expression; -using stencil::ifBound; -using stencil::run; -using stencil::text; // Create a valid translation-unit from a statement. static std::string wrapSnippet(StringRef StatementCode) { @@ -64,7 +55,7 @@ struct TestMatch { // `StatementCode` may contain other statements not described by `Matcher`. static llvm::Optional matchStmt(StringRef StatementCode, StatementMatcher Matcher) { - auto AstUnit = buildASTFromCode(wrapSnippet(StatementCode)); + auto AstUnit = tooling::buildASTFromCode(wrapSnippet(StatementCode)); if (AstUnit == nullptr) { ADD_FAILURE() << "AST construction failed"; return llvm::None; diff --git a/unittests/Tooling/TransformerTest.cpp b/unittests/Tooling/TransformerTest.cpp index feae0c649a..c42976a71c 100644 --- a/unittests/Tooling/TransformerTest.cpp +++ b/unittests/Tooling/TransformerTest.cpp @@ -18,9 +18,10 @@ using namespace clang; using namespace tooling; using namespace ast_matchers; - namespace { using ::testing::IsEmpty; +using transformer::RewriteRule; +using transformer::text; constexpr char KHeaderContents[] = R"cc( struct string { @@ -208,7 +209,7 @@ TEST_F(TransformerTest, AddIncludeQuoted) { TEST_F(TransformerTest, AddIncludeAngled) { RewriteRule Rule = makeRule(callExpr(callee(functionDecl(hasName("f")))), change(text("other()"))); - addInclude(Rule, "clang/OtherLib.h", IncludeFormat::Angled); + addInclude(Rule, "clang/OtherLib.h", transformer::IncludeFormat::Angled); std::string Input = R"cc( int f(int x); @@ -559,7 +560,7 @@ TEST_F(TransformerTest, OrderedRuleMultipleKinds) { change(name("fun"), text("DECL_RULE"))); RewriteRule Rule = applyFirst({ReplaceF1, DeclRule, ReplaceF1OrF2}); - EXPECT_EQ(tooling::detail::buildMatchers(Rule).size(), 2UL); + EXPECT_EQ(transformer::detail::buildMatchers(Rule).size(), 2UL); testRule(Rule, Input, Expected); } @@ -795,11 +796,11 @@ TEST_F(TransformerTest, NoPartialRewriteOfMacroExpansionForMacroArgs) { // rules. TEST(TransformerDeathTest, OrderedRuleTypes) { RewriteRule QualTypeRule = makeRule(qualType(), change(text("Q"))); - EXPECT_DEATH(tooling::detail::buildMatchers(QualTypeRule), + EXPECT_DEATH(transformer::detail::buildMatchers(QualTypeRule), "Matcher must be.*node matcher"); RewriteRule TypeRule = makeRule(arrayType(), change(text("T"))); - EXPECT_DEATH(tooling::detail::buildMatchers(TypeRule), + EXPECT_DEATH(transformer::detail::buildMatchers(TypeRule), "Matcher must be.*node matcher"); } #endif -- 2.40.0