@@ -836,7 +836,7 @@ class has_getDecl {
836
836
// / Matches overloaded operators with a specific name.
837
837
// /
838
838
// / The type argument ArgT is not used by this matcher but is used by
839
- // / PolymorphicMatcherWithParam1 and should be StringRef.
839
+ // / PolymorphicMatcher and should be StringRef.
840
840
template <typename T, typename ArgT>
841
841
class HasOverloadedOperatorNameMatcher : public SingleNodeMatcherInterface <T> {
842
842
static_assert (std::is_same<T, CXXOperatorCallExpr>::value ||
@@ -919,7 +919,7 @@ Matcher<ObjCMessageExpr> hasAnySelectorFunc(
919
919
920
920
// / Matches declarations for QualType and CallExpr.
921
921
// /
922
- // / Type argument DeclMatcherT is required by PolymorphicMatcherWithParam1 but
922
+ // / Type argument DeclMatcherT is required by PolymorphicMatcher but
923
923
// / not actually used.
924
924
template <typename T, typename DeclMatcherT>
925
925
class HasDeclarationMatcher : public MatcherInterface <T> {
@@ -1157,6 +1157,18 @@ template <class T> struct ExtractFunctionArgMeta<void(T)> {
1157
1157
using type = T;
1158
1158
};
1159
1159
1160
+ template <class T , class Tuple , std::size_t ... I>
1161
+ constexpr T *new_from_tuple_impl (Tuple &&t, std::index_sequence<I...>) {
1162
+ return new T (std::get<I>(std::forward<Tuple>(t))...);
1163
+ }
1164
+
1165
+ template <class T , class Tuple > constexpr T *new_from_tuple (Tuple &&t) {
1166
+ return new_from_tuple_impl<T>(
1167
+ std::forward<Tuple>(t),
1168
+ std::make_index_sequence<
1169
+ std::tuple_size<std::remove_reference_t <Tuple>>::value>{});
1170
+ }
1171
+
1160
1172
// / Default type lists for ArgumentAdaptingMatcher matchers.
1161
1173
using AdaptativeDefaultFromTypes = AllNodeBaseTypes;
1162
1174
using AdaptativeDefaultToTypes =
@@ -1426,7 +1438,7 @@ class ArgumentAdaptingMatcherFuncAdaptor {
1426
1438
// / \c HasMatcher<To, T>(InnerMatcher).
1427
1439
// /
1428
1440
// / If a matcher does not need knowledge about the inner type, prefer to use
1429
- // / PolymorphicMatcherWithParam1 .
1441
+ // / PolymorphicMatcher .
1430
1442
template <template <typename ToArg, typename FromArg> class ArgumentAdapterT ,
1431
1443
typename FromTypes = AdaptativeDefaultFromTypes,
1432
1444
typename ToTypes = AdaptativeDefaultToTypes>
@@ -1491,73 +1503,35 @@ template <typename MatcherType> class TraversalWrapper {
1491
1503
MatcherType InnerMatcher;
1492
1504
};
1493
1505
1494
- // / A PolymorphicMatcherWithParamN <MatcherT, P1, ..., PN> object can be
1506
+ // / A PolymorphicMatcher <MatcherT, P1, ..., PN> object can be
1495
1507
// / created from N parameters p1, ..., pN (of type P1, ..., PN) and
1496
1508
// / used as a Matcher<T> where a MatcherT<T, P1, ..., PN>(p1, ..., pN)
1497
1509
// / can be constructed.
1498
1510
// /
1499
1511
// / For example:
1500
- // / - PolymorphicMatcherWithParam0 <IsDefinitionMatcher>()
1512
+ // / - PolymorphicMatcher <IsDefinitionMatcher>()
1501
1513
// / creates an object that can be used as a Matcher<T> for any type T
1502
1514
// / where an IsDefinitionMatcher<T>() can be constructed.
1503
- // / - PolymorphicMatcherWithParam1 <ValueEqualsMatcher, int>(42)
1515
+ // / - PolymorphicMatcher <ValueEqualsMatcher, int>(42)
1504
1516
// / creates an object that can be used as a Matcher<T> for any type T
1505
1517
// / where a ValueEqualsMatcher<T, int>(42) can be constructed.
1506
- template <template <typename T> class MatcherT ,
1507
- typename ReturnTypesF = void (AllNodeBaseTypes)>
1508
- class PolymorphicMatcherWithParam0 {
1509
- public:
1510
- using ReturnTypes = typename ExtractFunctionArgMeta<ReturnTypesF>::type;
1511
-
1512
- template <typename T>
1513
- operator Matcher<T>() const {
1514
- static_assert (TypeListContainsSuperOf<ReturnTypes, T>::value,
1515
- " right polymorphic conversion" );
1516
- return Matcher<T>(new MatcherT<T>());
1517
- }
1518
- };
1519
-
1520
- template <template <typename T, typename P1> class MatcherT ,
1521
- typename P1,
1522
- typename ReturnTypesF = void (AllNodeBaseTypes)>
1523
- class PolymorphicMatcherWithParam1 {
1524
- public:
1525
- explicit PolymorphicMatcherWithParam1 (const P1 &Param1)
1526
- : Param1(Param1) {}
1527
-
1528
- using ReturnTypes = typename ExtractFunctionArgMeta<ReturnTypesF>::type;
1529
-
1530
- template <typename T>
1531
- operator Matcher<T>() const {
1532
- static_assert (TypeListContainsSuperOf<ReturnTypes, T>::value,
1533
- " right polymorphic conversion" );
1534
- return Matcher<T>(new MatcherT<T, P1>(Param1));
1535
- }
1536
-
1537
- private:
1538
- const P1 Param1;
1539
- };
1540
-
1541
- template <template <typename T, typename P1, typename P2> class MatcherT ,
1542
- typename P1, typename P2,
1543
- typename ReturnTypesF = void (AllNodeBaseTypes)>
1544
- class PolymorphicMatcherWithParam2 {
1518
+ template <template <typename T, typename ... Params> class MatcherT ,
1519
+ typename ReturnTypesF, typename ... ParamTypes>
1520
+ class PolymorphicMatcher {
1545
1521
public:
1546
- PolymorphicMatcherWithParam2 (const P1 &Param1, const P2 &Param2)
1547
- : Param1(Param1), Param2(Param2) {}
1522
+ PolymorphicMatcher (const ParamTypes &... Params) : Params(Params...) {}
1548
1523
1549
1524
using ReturnTypes = typename ExtractFunctionArgMeta<ReturnTypesF>::type;
1550
1525
1551
1526
template <typename T>
1552
1527
operator Matcher<T>() const {
1553
1528
static_assert (TypeListContainsSuperOf<ReturnTypes, T>::value,
1554
1529
" right polymorphic conversion" );
1555
- return Matcher<T>(new MatcherT<T, P1, P2>(Param1, Param2 ));
1530
+ return Matcher<T>(new_from_tuple< MatcherT<T, ParamTypes...>>(Params ));
1556
1531
}
1557
1532
1558
1533
private:
1559
- const P1 Param1;
1560
- const P2 Param2;
1534
+ const std::tuple<ParamTypes...> Params;
1561
1535
};
1562
1536
1563
1537
// / Matches nodes of type T that have child nodes of type ChildT for
@@ -2174,7 +2148,7 @@ inline Optional<StringRef> getOpName(const CXXOperatorCallExpr &Node) {
2174
2148
// / Matches overloaded operators with a specific name.
2175
2149
// /
2176
2150
// / The type argument ArgT is not used by this matcher but is used by
2177
- // / PolymorphicMatcherWithParam1 and should be std::vector<std::string>>.
2151
+ // / PolymorphicMatcher and should be std::vector<std::string>>.
2178
2152
template <typename T, typename ArgT = std::vector<std::string>>
2179
2153
class HasAnyOperatorNameMatcher : public SingleNodeMatcherInterface <T> {
2180
2154
static_assert (std::is_same<T, BinaryOperator>::value ||
@@ -2223,16 +2197,19 @@ class HasAnyOperatorNameMatcher : public SingleNodeMatcherInterface<T> {
2223
2197
const std::vector<std::string> Names;
2224
2198
};
2225
2199
2226
- using HasOpNameMatcher = PolymorphicMatcherWithParam1<
2227
- HasAnyOperatorNameMatcher, std::vector<std::string>,
2228
- void (TypeList<BinaryOperator, CXXOperatorCallExpr,
2229
- CXXRewrittenBinaryOperator, UnaryOperator>)>;
2200
+ using HasOpNameMatcher =
2201
+ PolymorphicMatcher<HasAnyOperatorNameMatcher,
2202
+ void (
2203
+ TypeList<BinaryOperator, CXXOperatorCallExpr,
2204
+ CXXRewrittenBinaryOperator, UnaryOperator>),
2205
+ std::vector<std::string>>;
2230
2206
2231
2207
HasOpNameMatcher hasAnyOperatorNameFunc (ArrayRef<const StringRef *> NameRefs);
2232
2208
2233
- using HasOverloadOpNameMatcher = PolymorphicMatcherWithParam1<
2234
- HasOverloadedOperatorNameMatcher, std::vector<std::string>,
2235
- void (TypeList<CXXOperatorCallExpr, FunctionDecl>)>;
2209
+ using HasOverloadOpNameMatcher =
2210
+ PolymorphicMatcher<HasOverloadedOperatorNameMatcher,
2211
+ void (TypeList<CXXOperatorCallExpr, FunctionDecl>),
2212
+ std::vector<std::string>>;
2236
2213
2237
2214
HasOverloadOpNameMatcher
2238
2215
hasAnyOverloadedOperatorNameFunc (ArrayRef<const StringRef *> NameRefs);
0 commit comments