@@ -542,6 +542,11 @@ class alignas(8) Expr {
542
542
bool isSelfExprOf (const AbstractFunctionDecl *AFD,
543
543
bool sameBase = false ) const ;
544
544
545
+ // / Given that this is a packed argument expression of the sort that
546
+ // / would be produced from packSingleArgument, return the index of the
547
+ // / unlabeled trailing closure, if there is one.
548
+ Optional<unsigned > getUnlabeledTrailingClosureIndexOfPackedArgument () const ;
549
+
545
550
// / Produce a mapping from each subexpression to its parent
546
551
// / expression, with the provided expression serving as the root of
547
552
// / the parent map.
@@ -1206,8 +1211,6 @@ class ObjectLiteralExpr final
1206
1211
ArrayRef<Identifier> argLabels,
1207
1212
ArrayRef<SourceLoc> argLabelLocs,
1208
1213
SourceLoc rParenLoc,
1209
- SourceLoc trailingLBrace,
1210
- SourceLoc trailingRBrace,
1211
1214
ArrayRef<TrailingClosure> trailingClosures,
1212
1215
bool implicit);
1213
1216
@@ -1230,6 +1233,11 @@ class ObjectLiteralExpr final
1230
1233
return Bits.ObjectLiteralExpr .HasTrailingClosure ;
1231
1234
}
1232
1235
1236
+ // / Return the index of the unlabeled trailing closure argument.
1237
+ Optional<unsigned > getUnlabeledTrailingClosureIndex () const {
1238
+ return getArg ()->getUnlabeledTrailingClosureIndexOfPackedArgument ();
1239
+ }
1240
+
1233
1241
SourceLoc getSourceLoc () const { return PoundLoc; }
1234
1242
SourceRange getSourceRange () const {
1235
1243
return SourceRange (PoundLoc, Arg->getEndLoc ());
@@ -1794,6 +1802,11 @@ class DynamicSubscriptExpr final
1794
1802
return Bits.DynamicSubscriptExpr .HasTrailingClosure ;
1795
1803
}
1796
1804
1805
+ // / Return the index of the unlabeled trailing closure argument.
1806
+ Optional<unsigned > getUnlabeledTrailingClosureIndex () const {
1807
+ return Index->getUnlabeledTrailingClosureIndexOfPackedArgument ();
1808
+ }
1809
+
1797
1810
SourceLoc getLoc () const { return Index->getStartLoc (); }
1798
1811
1799
1812
SourceLoc getStartLoc () const { return getBase ()->getStartLoc (); }
@@ -1836,8 +1849,6 @@ class UnresolvedMemberExpr final
1836
1849
ArrayRef<Identifier> argLabels,
1837
1850
ArrayRef<SourceLoc> argLabelLocs,
1838
1851
SourceLoc rParenLoc,
1839
- SourceLoc trailingLBrace,
1840
- SourceLoc trailingRBrace,
1841
1852
ArrayRef<TrailingClosure> trailingClosures,
1842
1853
bool implicit);
1843
1854
@@ -1865,6 +1876,11 @@ class UnresolvedMemberExpr final
1865
1876
return Bits.UnresolvedMemberExpr .HasTrailingClosure ;
1866
1877
}
1867
1878
1879
+ // / Return the index of the unlabeled trailing closure argument.
1880
+ Optional<unsigned > getUnlabeledTrailingClosureIndex () const {
1881
+ return getArgument ()->getUnlabeledTrailingClosureIndexOfPackedArgument ();
1882
+ }
1883
+
1868
1884
SourceLoc getLoc () const { return NameLoc.getBaseNameLoc (); }
1869
1885
1870
1886
SourceLoc getStartLoc () const { return DotLoc; }
@@ -2046,6 +2062,11 @@ class ParenExpr : public IdentityExpr {
2046
2062
// / Whether this expression has a trailing closure as its argument.
2047
2063
bool hasTrailingClosure () const { return Bits.ParenExpr .HasTrailingClosure ; }
2048
2064
2065
+ Optional<unsigned >
2066
+ getUnlabeledTrailingClosureIndexOfPackedArgument () const {
2067
+ return hasTrailingClosure () ? Optional<unsigned >(0 ) : None;
2068
+ }
2069
+
2049
2070
static bool classof (const Expr *E) { return E->getKind () == ExprKind::Paren; }
2050
2071
};
2051
2072
@@ -2059,9 +2080,6 @@ class TupleExpr final : public Expr,
2059
2080
SourceLoc LParenLoc;
2060
2081
SourceLoc RParenLoc;
2061
2082
2062
- SourceLoc TrailingLBraceLoc;
2063
- SourceLoc TrailingRBraceLoc;
2064
-
2065
2083
Optional<unsigned > FirstTrailingArgumentAt;
2066
2084
2067
2085
size_t numTrailingObjects (OverloadToken<Expr *>) const {
@@ -2094,8 +2112,6 @@ class TupleExpr final : public Expr,
2094
2112
ArrayRef<Expr *> SubExprs,
2095
2113
ArrayRef<Identifier> ElementNames,
2096
2114
ArrayRef<SourceLoc> ElementNameLocs,
2097
- SourceLoc TrailingLBrace,
2098
- SourceLoc TrailingRBrace,
2099
2115
Optional<unsigned > FirstTrailingArgumentAt, bool Implicit, Type Ty);
2100
2116
2101
2117
public:
@@ -2114,8 +2130,6 @@ class TupleExpr final : public Expr,
2114
2130
ArrayRef<Expr *> SubExprs,
2115
2131
ArrayRef<Identifier> ElementNames,
2116
2132
ArrayRef<SourceLoc> ElementNameLocs,
2117
- SourceLoc TrailingLBrace,
2118
- SourceLoc TrailingRBrace,
2119
2133
Optional<unsigned > FirstTrailingArgumentAt,
2120
2134
bool Implicit, Type Ty = Type());
2121
2135
@@ -2132,8 +2146,9 @@ class TupleExpr final : public Expr,
2132
2146
2133
2147
SourceRange getSourceRange () const ;
2134
2148
2135
- SourceLoc getTrailingLBraceLoc () const { return TrailingLBraceLoc; }
2136
- SourceLoc getTrailingRBraceLoc () const { return TrailingRBraceLoc; }
2149
+ bool hasAnyTrailingClosures () const {
2150
+ return (bool ) FirstTrailingArgumentAt;
2151
+ }
2137
2152
2138
2153
// / Whether this expression has a trailing closure as its argument.
2139
2154
bool hasTrailingClosure () const {
@@ -2146,6 +2161,11 @@ class TupleExpr final : public Expr,
2146
2161
return FirstTrailingArgumentAt ? !hasTrailingClosure () : false ;
2147
2162
}
2148
2163
2164
+ Optional<unsigned >
2165
+ getUnlabeledTrailingClosureIndexOfPackedArgument () const {
2166
+ return FirstTrailingArgumentAt;
2167
+ }
2168
+
2149
2169
// / Retrieve the elements of this tuple.
2150
2170
MutableArrayRef<Expr*> getElements () {
2151
2171
return { getTrailingObjects<Expr *>(), getNumElements () };
@@ -2155,6 +2175,14 @@ class TupleExpr final : public Expr,
2155
2175
ArrayRef<Expr*> getElements () const {
2156
2176
return { getTrailingObjects<Expr *>(), getNumElements () };
2157
2177
}
2178
+
2179
+ MutableArrayRef<Expr*> getTrailingElements () {
2180
+ return getElements ().take_back (getNumTrailingElements ());
2181
+ }
2182
+
2183
+ ArrayRef<Expr*> getTrailingElements () const {
2184
+ return getElements ().take_back (getNumTrailingElements ());
2185
+ }
2158
2186
2159
2187
unsigned getNumElements () const { return Bits.TupleExpr .NumElements ; }
2160
2188
@@ -2398,8 +2426,6 @@ class SubscriptExpr final : public LookupExpr,
2398
2426
ArrayRef<Identifier> indexArgLabels,
2399
2427
ArrayRef<SourceLoc> indexArgLabelLocs,
2400
2428
SourceLoc rSquareLoc,
2401
- SourceLoc trailingLBrace,
2402
- SourceLoc trailingRBrace,
2403
2429
ArrayRef<TrailingClosure> trailingClosures,
2404
2430
ConcreteDeclRef decl = ConcreteDeclRef(),
2405
2431
bool implicit = false,
@@ -2424,6 +2450,11 @@ class SubscriptExpr final : public LookupExpr,
2424
2450
return Bits.SubscriptExpr .HasTrailingClosure ;
2425
2451
}
2426
2452
2453
+ // / Return the index of the unlabeled trailing closure argument.
2454
+ Optional<unsigned > getUnlabeledTrailingClosureIndex () const {
2455
+ return getIndex ()->getUnlabeledTrailingClosureIndexOfPackedArgument ();
2456
+ }
2457
+
2427
2458
// / Determine whether this subscript reference should bypass the
2428
2459
// / ordinary accessors.
2429
2460
AccessSemantics getAccessSemantics () const {
@@ -4221,6 +4252,9 @@ class ApplyExpr : public Expr {
4221
4252
// / Whether this application was written using a trailing closure.
4222
4253
bool hasTrailingClosure () const ;
4223
4254
4255
+ // / Return the index of the unlabeled trailing closure argument.
4256
+ Optional<unsigned > getUnlabeledTrailingClosureIndex () const ;
4257
+
4224
4258
static bool classof (const Expr *E) {
4225
4259
return E->getKind () >= ExprKind::First_ApplyExpr &&
4226
4260
E->getKind () <= ExprKind::Last_ApplyExpr;
@@ -4264,8 +4298,7 @@ class CallExpr final : public ApplyExpr,
4264
4298
llvm::function_ref<Type(const Expr *)> getType =
4265
4299
[](const Expr *E) -> Type { return E->getType (); }) {
4266
4300
return create (ctx, fn, SourceLoc (), args, argLabels, {}, SourceLoc (),
4267
- SourceLoc (), SourceLoc (), /* trailingClosures=*/ {},
4268
- /* implicit=*/ true , getType);
4301
+ /* trailingClosures=*/ {}, /* implicit=*/ true , getType);
4269
4302
}
4270
4303
4271
4304
// / Create a new call expression.
@@ -4280,8 +4313,8 @@ class CallExpr final : public ApplyExpr,
4280
4313
static CallExpr *
4281
4314
create (ASTContext &ctx, Expr *fn, SourceLoc lParenLoc, ArrayRef<Expr *> args,
4282
4315
ArrayRef<Identifier> argLabels, ArrayRef<SourceLoc> argLabelLocs,
4283
- SourceLoc rParenLoc, SourceLoc trailingLBrace, SourceLoc trailingRBrace ,
4284
- ArrayRef<TrailingClosure> trailingClosures, bool implicit,
4316
+ SourceLoc rParenLoc, ArrayRef<TrailingClosure> trailingClosures ,
4317
+ bool implicit,
4285
4318
llvm::function_ref<Type(const Expr *)> getType =
4286
4319
[](const Expr *E) -> Type { return E->getType (); });
4287
4320
@@ -4305,6 +4338,11 @@ class CallExpr final : public ApplyExpr,
4305
4338
// / Whether this call with written with a single trailing closure.
4306
4339
bool hasTrailingClosure () const { return Bits.CallExpr .HasTrailingClosure ; }
4307
4340
4341
+ // / Return the index of the unlabeled trailing closure argument.
4342
+ Optional<unsigned > getUnlabeledTrailingClosureIndex () const {
4343
+ return getArg ()->getUnlabeledTrailingClosureIndexOfPackedArgument ();
4344
+ }
4345
+
4308
4346
using TrailingCallArguments::getArgumentLabels;
4309
4347
4310
4348
// / Retrieve the expression that directly represents the callee.
@@ -5175,8 +5213,6 @@ class KeyPathExpr : public Expr {
5175
5213
ArrayRef<Identifier> indexArgLabels,
5176
5214
ArrayRef<SourceLoc> indexArgLabelLocs,
5177
5215
SourceLoc rSquareLoc,
5178
- SourceLoc trailingLBrace,
5179
- SourceLoc trailingRBrace,
5180
5216
ArrayRef<TrailingClosure> trailingClosures);
5181
5217
5182
5218
// / Create an unresolved component for a subscript.
@@ -5229,8 +5265,6 @@ class KeyPathExpr : public Expr {
5229
5265
ArrayRef<Identifier> indexArgLabels,
5230
5266
ArrayRef<SourceLoc> indexArgLabelLocs,
5231
5267
SourceLoc rSquareLoc,
5232
- SourceLoc trailingLBrace,
5233
- SourceLoc trailingRBrace,
5234
5268
ArrayRef<TrailingClosure> trailingClosures,
5235
5269
Type elementType,
5236
5270
ArrayRef<ProtocolConformanceRef> indexHashables);
@@ -5621,8 +5655,6 @@ Expr *packSingleArgument(ASTContext &ctx, SourceLoc lParenLoc,
5621
5655
ArrayRef<Identifier> &argLabels,
5622
5656
ArrayRef<SourceLoc> &argLabelLocs,
5623
5657
SourceLoc rParenLoc,
5624
- SourceLoc trailingLBrace,
5625
- SourceLoc trailingRBrace,
5626
5658
ArrayRef<TrailingClosure> trailingClosures,
5627
5659
bool implicit,
5628
5660
SmallVectorImpl<Identifier> &argLabelsScratch,
0 commit comments