@@ -170,16 +170,39 @@ void simple_display(llvm::raw_ostream &os, PropertyWrapperLValueness l);
170
170
// / be initialized out-of-line using an expression of the wrapped property type.
171
171
PropertyWrapperValuePlaceholderExpr *findWrappedValuePlaceholder (Expr *init);
172
172
173
- // / Describes the backing property of a property that has an attached wrapper.
174
- struct PropertyWrapperBackingPropertyInfo {
173
+ // / The synthesized auxiliary declarations for a wrapped property, including the
174
+ // / backing property wrapper, the projected value variable, and if the wrapped
175
+ // / declaration is a parameter, the local wrapped value variable.
176
+ struct PropertyWrapperAuxiliaryVariables {
175
177
// / The backing property.
176
178
VarDecl *backingVar = nullptr ;
177
179
178
180
// / The synthesized projection property, if any. When present, this takes the name
179
181
// / of the original wrapped property prefixed with \c $
180
182
VarDecl *projectionVar = nullptr ;
181
183
182
- private:
184
+ // / The synthesized local wrapped value property, which shadows the original wrapped
185
+ // / declaration if it is a parameter.
186
+ VarDecl *localWrappedValueVar = nullptr ;
187
+
188
+ PropertyWrapperAuxiliaryVariables () {}
189
+
190
+ PropertyWrapperAuxiliaryVariables (VarDecl *backingVar, VarDecl *projectionVar,
191
+ VarDecl *localWrappedValueVar = nullptr )
192
+ : backingVar(backingVar), projectionVar(projectionVar),
193
+ localWrappedValueVar (localWrappedValueVar) {}
194
+
195
+ // / Whether this is a valid property wrapper.
196
+ bool isValid () const {
197
+ return backingVar != nullptr ;
198
+ }
199
+
200
+ explicit operator bool () const { return isValid (); }
201
+ };
202
+
203
+ // / Describes how to initialize the backing storage of a property with
204
+ // / an attached wrapper.
205
+ class PropertyWrapperInitializerInfo {
183
206
struct {
184
207
// / An expression that initializes the backing property from a value of
185
208
// / the original property's type via \c init(wrappedValue:) if supported
@@ -203,15 +226,10 @@ struct PropertyWrapperBackingPropertyInfo {
203
226
} projectedValueInit;
204
227
205
228
public:
206
- PropertyWrapperBackingPropertyInfo () { }
207
-
208
- PropertyWrapperBackingPropertyInfo (VarDecl *backingVar, VarDecl *projectionVar)
209
- : backingVar(backingVar), projectionVar(projectionVar) { }
229
+ PropertyWrapperInitializerInfo () { }
210
230
211
- PropertyWrapperBackingPropertyInfo (VarDecl *backingVar, VarDecl *projectionVar,
212
- Expr *wrappedValueInitExpr,
213
- Expr *projectedValueInitExpr)
214
- : backingVar(backingVar), projectionVar(projectionVar) {
231
+ PropertyWrapperInitializerInfo (Expr *wrappedValueInitExpr,
232
+ Expr *projectedValueInitExpr) {
215
233
wrappedValueInit.expr = wrappedValueInitExpr;
216
234
if (wrappedValueInitExpr) {
217
235
wrappedValueInit.placeholder = findWrappedValuePlaceholder (wrappedValueInitExpr);
@@ -223,16 +241,11 @@ struct PropertyWrapperBackingPropertyInfo {
223
241
}
224
242
}
225
243
226
- // / Whether this is a valid property wrapper.
227
- bool isValid () const {
228
- return backingVar != nullptr ;
229
- }
230
-
231
244
bool hasInitFromWrappedValue () const {
232
245
return wrappedValueInit.expr != nullptr ;
233
246
}
234
247
235
- Expr *getInitFromWrappedValue () {
248
+ Expr *getInitFromWrappedValue () const {
236
249
return wrappedValueInit.expr ;
237
250
}
238
251
@@ -244,7 +257,7 @@ struct PropertyWrapperBackingPropertyInfo {
244
257
return projectedValueInit.expr != nullptr ;
245
258
}
246
259
247
- Expr *getInitFromProjectedValue () {
260
+ Expr *getInitFromProjectedValue () const {
248
261
return projectedValueInit.expr ;
249
262
}
250
263
@@ -255,14 +268,6 @@ struct PropertyWrapperBackingPropertyInfo {
255
268
bool hasSynthesizedInitializers () const {
256
269
return hasInitFromWrappedValue () || hasInitFromProjectedValue ();
257
270
}
258
-
259
- explicit operator bool () const { return isValid (); }
260
-
261
- friend bool operator ==(const PropertyWrapperBackingPropertyInfo &lhs,
262
- const PropertyWrapperBackingPropertyInfo &rhs) {
263
- // FIXME: Can't currently compare expressions.
264
- return lhs.backingVar == rhs.backingVar ;
265
- }
266
271
};
267
272
268
273
void simple_display (
@@ -271,7 +276,11 @@ void simple_display(
271
276
272
277
void simple_display (
273
278
llvm::raw_ostream &out,
274
- const PropertyWrapperBackingPropertyInfo &backingInfo);
279
+ const PropertyWrapperInitializerInfo &initInfo);
280
+
281
+ void simple_display (
282
+ llvm::raw_ostream &out,
283
+ const PropertyWrapperAuxiliaryVariables &auxiliaryVars);
275
284
276
285
} // end namespace swift
277
286
0 commit comments