[clang] b831af5 - [libTooling] Simplify code with constexpr if. NFCI.
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 27 01:54:52 PDT 2022
Author: Benjamin Kramer
Date: 2022-08-27T10:50:06+02:00
New Revision: b831af51977b4150763d69a26a2d912459c1114d
URL: https://github.com/llvm/llvm-project/commit/b831af51977b4150763d69a26a2d912459c1114d
DIFF: https://github.com/llvm/llvm-project/commit/b831af51977b4150763d69a26a2d912459c1114d.diff
LOG: [libTooling] Simplify code with constexpr if. NFCI.
Added:
Modified:
clang/include/clang/Tooling/Transformer/Transformer.h
Removed:
################################################################################
diff --git a/clang/include/clang/Tooling/Transformer/Transformer.h b/clang/include/clang/Tooling/Transformer/Transformer.h
index 4e93783f2b9d9..23683bfb86036 100644
--- a/clang/include/clang/Tooling/Transformer/Transformer.h
+++ b/clang/include/clang/Tooling/Transformer/Transformer.h
@@ -112,22 +112,7 @@ class Transformer : public ast_matchers::MatchFinder::MatchCallback {
};
namespace detail {
-/// Asserts that all \c Metadata for the \c Rule is set.
-/// FIXME: Use constexpr-if in C++17.
-/// @{
-template <typename T>
-void assertMetadataSet(const transformer::RewriteRuleWith<T> &Rule) {
- assert(llvm::all_of(Rule.Metadata,
- [](const typename transformer::Generator<T> &Metadata)
- -> bool { return !!Metadata; }) &&
- "metadata generator must be provided for each rule");
-}
-template <>
-inline void assertMetadataSet(const transformer::RewriteRuleWith<void> &) {}
-/// @}
-
/// Runs the metadata generator on \c Rule and stuffs it into \c Result.
-/// FIXME: Use constexpr-if in C++17.
/// @{
template <typename T>
llvm::Error
@@ -135,17 +120,12 @@ populateMetadata(const transformer::RewriteRuleWith<T> &Rule,
size_t SelectedCase,
const ast_matchers::MatchFinder::MatchResult &Match,
TransformerResult<T> &Result) {
- auto Metadata = Rule.Metadata[SelectedCase]->eval(Match);
- if (!Metadata)
- return Metadata.takeError();
- Result.Metadata = std::move(*Metadata);
- return llvm::Error::success();
-}
-template <>
-inline llvm::Error
-populateMetadata(const transformer::RewriteRuleWith<void> &, size_t,
- const ast_matchers::MatchFinder::MatchResult &Match,
- TransformerResult<void> &) {
+ if constexpr (!std::is_void_v<T>) {
+ auto Metadata = Rule.Metadata[SelectedCase]->eval(Match);
+ if (!Metadata)
+ return Metadata.takeError();
+ Result.Metadata = std::move(*Metadata);
+ }
return llvm::Error::success();
}
/// @}
@@ -165,7 +145,11 @@ template <typename T> class WithMetadataImpl final : public TransformerImpl {
[](const transformer::RewriteRuleBase::Case &Case)
-> bool { return !!Case.Edits; }) &&
"edit generator must be provided for each rule");
- assertMetadataSet(Rule);
+ if constexpr (!std::is_void_v<T>)
+ assert(llvm::all_of(Rule.Metadata,
+ [](const typename transformer::Generator<T> &Metadata)
+ -> bool { return !!Metadata; }) &&
+ "metadata generator must be provided for each rule");
}
private:
More information about the cfe-commits
mailing list