@@ -60,7 +60,8 @@ TuplePackMatcher::TuplePackMatcher(TupleType *lhsTuple, TupleType *rhsTuple)
60
60
ctx(lhsTuple->getASTContext ()) {}
61
61
62
62
bool TuplePackMatcher::match () {
63
- unsigned idx = 0 ;
63
+ unsigned lhsIdx = 0 ;
64
+ unsigned rhsIdx = 0 ;
64
65
65
66
// Iterate over the two tuples in parallel, popping elements from
66
67
// the start.
@@ -85,7 +86,7 @@ bool TuplePackMatcher::match() {
85
86
" by an unlabeled element" );
86
87
87
88
auto rhs = gatherTupleElements (rhsElts, lhsElt.getName (), ctx);
88
- pairs.emplace_back (lhsExpansionType, rhs, idx++ );
89
+ pairs.emplace_back (lhsExpansionType, rhs, lhsIdx++, rhsIdx );
89
90
continue ;
90
91
}
91
92
@@ -105,7 +106,7 @@ bool TuplePackMatcher::match() {
105
106
" by an unlabeled element" );
106
107
107
108
auto lhs = gatherTupleElements (lhsElts, rhsElt.getName (), ctx);
108
- pairs.emplace_back (lhs, rhsExpansionType, idx ++);
109
+ pairs.emplace_back (lhs, rhsExpansionType, lhsIdx, rhsIdx ++);
109
110
continue ;
110
111
}
111
112
@@ -116,7 +117,7 @@ bool TuplePackMatcher::match() {
116
117
lhsElts = lhsElts.slice (1 );
117
118
rhsElts = rhsElts.slice (1 );
118
119
119
- pairs.emplace_back (lhsElt.getType (), rhsElt.getType (), idx ++);
120
+ pairs.emplace_back (lhsElt.getType (), rhsElt.getType (), lhsIdx++, rhsIdx ++);
120
121
}
121
122
122
123
return false ;
@@ -135,8 +136,11 @@ bool ParamPackMatcher::match() {
135
136
// the pair is a pack expansion type.
136
137
unsigned prefixLength = 0 ;
137
138
for (unsigned i = 0 ; i < minLength; ++i) {
138
- auto lhsParam = lhsParams[i];
139
- auto rhsParam = rhsParams[i];
139
+ unsigned lhsIdx = i;
140
+ unsigned rhsIdx = i;
141
+
142
+ auto lhsParam = lhsParams[lhsIdx];
143
+ auto rhsParam = rhsParams[rhsIdx];
140
144
141
145
// FIXME: Check flags
142
146
@@ -150,16 +154,19 @@ bool ParamPackMatcher::match() {
150
154
151
155
// FIXME: Check flags
152
156
153
- pairs.emplace_back (lhsType, rhsType, i );
157
+ pairs.emplace_back (lhsType, rhsType, lhsIdx, rhsIdx );
154
158
++prefixLength;
155
159
}
156
160
157
161
// Consume the longest possible suffix where neither type in
158
162
// the pair is a pack expansion type.
159
163
unsigned suffixLength = 0 ;
160
164
for (unsigned i = 0 ; i < minLength - prefixLength; ++i) {
161
- auto lhsParam = lhsParams[lhsParams.size () - i - 1 ];
162
- auto rhsParam = rhsParams[rhsParams.size () - i - 1 ];
165
+ unsigned lhsIdx = lhsParams.size () - i - 1 ;
166
+ unsigned rhsIdx = rhsParams.size () - i - 1 ;
167
+
168
+ auto lhsParam = lhsParams[lhsIdx];
169
+ auto rhsParam = rhsParams[rhsIdx];
163
170
164
171
// FIXME: Check flags
165
172
@@ -171,7 +178,7 @@ bool ParamPackMatcher::match() {
171
178
break ;
172
179
}
173
180
174
- pairs.emplace_back (lhsType, rhsType, i );
181
+ pairs.emplace_back (lhsType, rhsType, lhsIdx, rhsIdx );
175
182
++suffixLength;
176
183
}
177
184
@@ -191,6 +198,9 @@ bool ParamPackMatcher::match() {
191
198
if (lhsParams.size () == 1 ) {
192
199
auto lhsType = lhsParams[0 ].getPlainType ();
193
200
if (auto *lhsExpansion = lhsType->getAs <PackExpansionType>()) {
201
+ unsigned lhsIdx = prefixLength;
202
+ unsigned rhsIdx = prefixLength;
203
+
194
204
SmallVector<Type, 2 > rhsTypes;
195
205
for (auto rhsParam : rhsParams) {
196
206
// FIXME: Check rhs flags
@@ -199,7 +209,7 @@ bool ParamPackMatcher::match() {
199
209
auto rhs = createPackBinding (ctx, rhsTypes);
200
210
201
211
// FIXME: Check lhs flags
202
- pairs.emplace_back (lhsExpansion, rhs, prefixLength );
212
+ pairs.emplace_back (lhsExpansion, rhs, lhsIdx, rhsIdx );
203
213
return false ;
204
214
}
205
215
}
@@ -209,6 +219,9 @@ bool ParamPackMatcher::match() {
209
219
if (rhsParams.size () == 1 ) {
210
220
auto rhsType = rhsParams[0 ].getPlainType ();
211
221
if (auto *rhsExpansion = rhsType->getAs <PackExpansionType>()) {
222
+ unsigned lhsIdx = prefixLength;
223
+ unsigned rhsIdx = prefixLength;
224
+
212
225
SmallVector<Type, 2 > lhsTypes;
213
226
for (auto lhsParam : lhsParams) {
214
227
// FIXME: Check lhs flags
@@ -217,7 +230,7 @@ bool ParamPackMatcher::match() {
217
230
auto lhs = createPackBinding (ctx, lhsTypes);
218
231
219
232
// FIXME: Check rhs flags
220
- pairs.emplace_back (lhs, rhsExpansion, prefixLength );
233
+ pairs.emplace_back (lhs, rhsExpansion, lhsIdx, rhsIdx );
221
234
return false ;
222
235
}
223
236
}
@@ -244,31 +257,37 @@ bool PackMatcher::match() {
244
257
// the pair is a pack expansion type.
245
258
unsigned prefixLength = 0 ;
246
259
for (unsigned i = 0 ; i < minLength; ++i) {
247
- auto lhsType = lhsTypes[i];
248
- auto rhsType = rhsTypes[i];
260
+ unsigned lhsIdx = i;
261
+ unsigned rhsIdx = i;
262
+
263
+ auto lhsType = lhsTypes[lhsIdx];
264
+ auto rhsType = rhsTypes[rhsIdx];
249
265
250
266
if (lhsType->is <PackExpansionType>() ||
251
267
rhsType->is <PackExpansionType>()) {
252
268
break ;
253
269
}
254
270
255
- pairs.emplace_back (lhsType, rhsType, i );
271
+ pairs.emplace_back (lhsType, rhsType, lhsIdx, rhsIdx );
256
272
++prefixLength;
257
273
}
258
274
259
275
// Consume the longest possible suffix where neither type in
260
276
// the pair is a pack expansion type.
261
277
unsigned suffixLength = 0 ;
262
278
for (unsigned i = 0 ; i < minLength - prefixLength; ++i) {
263
- auto lhsType = lhsTypes[lhsTypes.size () - i - 1 ];
264
- auto rhsType = rhsTypes[rhsTypes.size () - i - 1 ];
279
+ unsigned lhsIdx = lhsTypes.size () - i - 1 ;
280
+ unsigned rhsIdx = rhsTypes.size () - i - 1 ;
281
+
282
+ auto lhsType = lhsTypes[lhsIdx];
283
+ auto rhsType = rhsTypes[rhsIdx];
265
284
266
285
if (lhsType->is <PackExpansionType>() ||
267
286
rhsType->is <PackExpansionType>()) {
268
287
break ;
269
288
}
270
289
271
- pairs.emplace_back (lhsType, rhsType, i );
290
+ pairs.emplace_back (lhsType, rhsType, lhsIdx, rhsIdx );
272
291
++suffixLength;
273
292
}
274
293
@@ -288,9 +307,12 @@ bool PackMatcher::match() {
288
307
if (lhsTypes.size () == 1 ) {
289
308
auto lhsType = lhsTypes[0 ];
290
309
if (auto *lhsExpansion = lhsType->getAs <PackExpansionType>()) {
310
+ unsigned lhsIdx = prefixLength;
311
+ unsigned rhsIdx = prefixLength;
312
+
291
313
auto rhs = createPackBinding (ctx, rhsTypes);
292
314
293
- pairs.emplace_back (lhsExpansion, rhs, prefixLength );
315
+ pairs.emplace_back (lhsExpansion, rhs, lhsIdx, rhsIdx );
294
316
return false ;
295
317
}
296
318
}
@@ -300,9 +322,12 @@ bool PackMatcher::match() {
300
322
if (rhsTypes.size () == 1 ) {
301
323
auto rhsType = rhsTypes[0 ];
302
324
if (auto *rhsExpansion = rhsType->getAs <PackExpansionType>()) {
325
+ unsigned lhsIdx = prefixLength;
326
+ unsigned rhsIdx = prefixLength;
327
+
303
328
auto lhs = createPackBinding (ctx, lhsTypes);
304
329
305
- pairs.emplace_back (lhs, rhsExpansion, prefixLength );
330
+ pairs.emplace_back (lhs, rhsExpansion, lhsIdx, rhsIdx );
306
331
return false ;
307
332
}
308
333
}
0 commit comments