1
- // ===--- SolutionApplicationTarget .h - Solution Target ------ ----*- C++ -*-===//
1
+ // ===--- SyntacticElementTarget .h - Syntactic Element Target ----*- C++ -*-===//
2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
//
13
- // This file defines the SolutionApplicationTarget class.
13
+ // This file defines the SyntacticElementTarget class.
14
14
//
15
15
// ===----------------------------------------------------------------------===//
16
16
17
- #ifndef SWIFT_SEMA_SOLUTION_APPLICATION_TARGET_H
18
- #define SWIFT_SEMA_SOLUTION_APPLICATION_TARGET_H
17
+ #ifndef SWIFT_SEMA_SYNTACTIC_ELEMENT_TARGET_H
18
+ #define SWIFT_SEMA_SYNTACTIC_ELEMENT_TARGET_H
19
19
20
20
#include " swift/AST/AnyFunctionRef.h"
21
21
#include " swift/AST/Expr.h"
@@ -48,7 +48,7 @@ struct ForEachStmtInfo {
48
48
49
49
// / Describes the target to which a constraint system's solution can be
50
50
// / applied.
51
- class SolutionApplicationTarget {
51
+ class SyntacticElementTarget {
52
52
public:
53
53
enum class Kind {
54
54
expression,
@@ -169,68 +169,67 @@ class SolutionApplicationTarget {
169
169
void maybeApplyPropertyWrapper ();
170
170
171
171
public:
172
- SolutionApplicationTarget (Expr *expr, DeclContext *dc,
173
- ContextualTypePurpose contextualPurpose,
174
- Type convertType,
175
- ConstraintLocator *convertTypeLocator,
176
- bool isDiscarded)
177
- : SolutionApplicationTarget(expr, dc, contextualPurpose,
178
- TypeLoc::withoutLoc (convertType),
179
- convertTypeLocator, isDiscarded) {}
180
-
181
- SolutionApplicationTarget (Expr *expr, DeclContext *dc,
182
- ContextualTypePurpose contextualPurpose,
183
- Type convertType, bool isDiscarded)
184
- : SolutionApplicationTarget(expr, dc, contextualPurpose, convertType,
185
- /* convertTypeLocator*/ nullptr , isDiscarded) {
186
- }
187
-
188
- SolutionApplicationTarget (Expr *expr, DeclContext *dc,
189
- ContextualTypePurpose contextualPurpose,
190
- TypeLoc convertType,
191
- ConstraintLocator *convertTypeLocator,
192
- bool isDiscarded);
193
-
194
- SolutionApplicationTarget (Expr *expr, DeclContext *dc, ExprPattern *pattern,
195
- Type patternType)
196
- : SolutionApplicationTarget(expr, dc, CTP_ExprPattern, patternType,
197
- /* isDiscarded=*/ false ) {
172
+ SyntacticElementTarget (Expr *expr, DeclContext *dc,
173
+ ContextualTypePurpose contextualPurpose,
174
+ Type convertType,
175
+ ConstraintLocator *convertTypeLocator,
176
+ bool isDiscarded)
177
+ : SyntacticElementTarget(expr, dc, contextualPurpose,
178
+ TypeLoc::withoutLoc (convertType),
179
+ convertTypeLocator, isDiscarded) {}
180
+
181
+ SyntacticElementTarget (Expr *expr, DeclContext *dc,
182
+ ContextualTypePurpose contextualPurpose,
183
+ Type convertType, bool isDiscarded)
184
+ : SyntacticElementTarget(expr, dc, contextualPurpose, convertType,
185
+ /* convertTypeLocator*/ nullptr , isDiscarded) {}
186
+
187
+ SyntacticElementTarget (Expr *expr, DeclContext *dc,
188
+ ContextualTypePurpose contextualPurpose,
189
+ TypeLoc convertType,
190
+ ConstraintLocator *convertTypeLocator,
191
+ bool isDiscarded);
192
+
193
+ SyntacticElementTarget (Expr *expr, DeclContext *dc, ExprPattern *pattern,
194
+ Type patternType)
195
+ : SyntacticElementTarget(expr, dc, CTP_ExprPattern, patternType,
196
+ /* isDiscarded=*/ false ) {
198
197
setPattern (pattern);
199
198
}
200
199
201
- SolutionApplicationTarget (ClosureExpr *closure, Type convertType) {
200
+ SyntacticElementTarget (ClosureExpr *closure, Type convertType) {
202
201
kind = Kind::closure;
203
202
this ->closure .closure = closure;
204
203
this ->closure .convertType = convertType;
205
204
}
206
205
207
- SolutionApplicationTarget (AnyFunctionRef fn)
208
- : SolutionApplicationTarget (fn, fn.getBody()) { }
206
+ SyntacticElementTarget (AnyFunctionRef fn)
207
+ : SyntacticElementTarget (fn, fn.getBody()) {}
209
208
210
- SolutionApplicationTarget (StmtCondition stmtCondition, DeclContext *dc) {
209
+ SyntacticElementTarget (StmtCondition stmtCondition, DeclContext *dc) {
211
210
kind = Kind::stmtCondition;
212
211
this ->stmtCondition .stmtCondition = stmtCondition;
213
212
this ->stmtCondition .dc = dc;
214
213
}
215
214
216
- SolutionApplicationTarget (AnyFunctionRef fn, BraceStmt *body) {
215
+ SyntacticElementTarget (AnyFunctionRef fn, BraceStmt *body) {
217
216
kind = Kind::function;
218
217
function.function = fn;
219
218
function.body = body;
220
219
}
221
220
222
- SolutionApplicationTarget (CaseLabelItem *caseLabelItem, DeclContext *dc) {
221
+ SyntacticElementTarget (CaseLabelItem *caseLabelItem, DeclContext *dc) {
223
222
kind = Kind::caseLabelItem;
224
223
this ->caseLabelItem .caseLabelItem = caseLabelItem;
225
224
this ->caseLabelItem .dc = dc;
226
225
}
227
226
228
- SolutionApplicationTarget (PatternBindingDecl *patternBinding) {
227
+ SyntacticElementTarget (PatternBindingDecl *patternBinding) {
229
228
kind = Kind::patternBinding;
230
229
this ->patternBinding = patternBinding;
231
230
}
232
231
233
- SolutionApplicationTarget (VarDecl *uninitializedWrappedVar)
232
+ SyntacticElementTarget (VarDecl *uninitializedWrappedVar)
234
233
: kind(Kind::uninitializedVar) {
235
234
if (auto *PDB = uninitializedWrappedVar->getParentPatternBinding ()) {
236
235
uninitializedVar.binding = PDB;
@@ -245,60 +244,61 @@ class SolutionApplicationTarget {
245
244
uninitializedVar.type = Type ();
246
245
}
247
246
248
- SolutionApplicationTarget (PatternBindingDecl *binding, unsigned index,
249
- Pattern *var, Type patternTy)
247
+ SyntacticElementTarget (PatternBindingDecl *binding, unsigned index,
248
+ Pattern *var, Type patternTy)
250
249
: kind(Kind::uninitializedVar) {
251
250
uninitializedVar.binding = binding;
252
251
uninitializedVar.index = index;
253
252
uninitializedVar.declaration = var;
254
253
uninitializedVar.type = patternTy;
255
254
}
256
255
257
- SolutionApplicationTarget (ForEachStmt *stmt, DeclContext *dc,
258
- bool bindPatternVarsOneWay)
259
- : kind(Kind::forEachStmt) {
256
+ SyntacticElementTarget (ForEachStmt *stmt, DeclContext *dc,
257
+ bool bindPatternVarsOneWay)
258
+ : kind(Kind::forEachStmt) {
260
259
forEachStmt.stmt = stmt;
261
260
forEachStmt.dc = dc;
262
261
forEachStmt.bindPatternVarsOneWay = bindPatternVarsOneWay;
263
262
}
264
263
265
264
// / Form a target for the initialization of a pattern from an expression.
266
- static SolutionApplicationTarget forInitialization (
267
- Expr *initializer, DeclContext *dc, Type patternType, Pattern *pattern ,
268
- bool bindPatternVarsOneWay);
265
+ static SyntacticElementTarget
266
+ forInitialization ( Expr *initializer, DeclContext *dc, Type patternType,
267
+ Pattern *pattern, bool bindPatternVarsOneWay);
269
268
270
269
// / Form a target for the initialization of a pattern binding entry from
271
270
// / an expression.
272
- static SolutionApplicationTarget forInitialization (
273
- Expr *initializer, DeclContext *dc, Type patternType,
274
- PatternBindingDecl *patternBinding, unsigned patternBindingIndex ,
275
- bool bindPatternVarsOneWay);
271
+ static SyntacticElementTarget
272
+ forInitialization ( Expr *initializer, DeclContext *dc, Type patternType,
273
+ PatternBindingDecl *patternBinding,
274
+ unsigned patternBindingIndex, bool bindPatternVarsOneWay);
276
275
277
276
// / Form a target for a for-in loop.
278
- static SolutionApplicationTarget forForEachStmt (
279
- ForEachStmt *stmt, DeclContext *dc,
280
- bool bindPatternVarsOneWay);
277
+ static SyntacticElementTarget forForEachStmt (ForEachStmt *stmt,
278
+ DeclContext *dc,
279
+ bool bindPatternVarsOneWay);
281
280
282
281
// / Form a target for a property with an attached property wrapper that is
283
282
// / initialized out-of-line.
284
- static SolutionApplicationTarget
283
+ static SyntacticElementTarget
285
284
forUninitializedWrappedVar (VarDecl *wrappedVar) {
286
285
return {wrappedVar};
287
286
}
288
287
289
- static SolutionApplicationTarget
290
- forUninitializedVar (PatternBindingDecl *binding, unsigned index,
291
- Type patternTy) {
288
+ static SyntacticElementTarget forUninitializedVar (PatternBindingDecl *binding,
289
+ unsigned index,
290
+ Type patternTy) {
292
291
return {binding, index, binding->getPattern (index), patternTy};
293
292
}
294
293
295
294
// / Form a target for a synthesized property wrapper initializer.
296
- static SolutionApplicationTarget forPropertyWrapperInitializer (
297
- VarDecl *wrappedVar, DeclContext *dc, Expr *initializer);
295
+ static SyntacticElementTarget
296
+ forPropertyWrapperInitializer (VarDecl *wrappedVar, DeclContext *dc,
297
+ Expr *initializer);
298
298
299
- static SolutionApplicationTarget forExprPattern (Expr *expr, DeclContext *dc,
300
- ExprPattern *pattern,
301
- Type patternTy) {
299
+ static SyntacticElementTarget forExprPattern (Expr *expr, DeclContext *dc,
300
+ ExprPattern *pattern,
301
+ Type patternTy) {
302
302
return {expr, dc, pattern, patternTy};
303
303
}
304
304
@@ -373,8 +373,7 @@ class SolutionApplicationTarget {
373
373
return patternBinding->getDeclContext ();
374
374
375
375
case Kind::uninitializedVar: {
376
- if (auto *wrappedVar =
377
- uninitializedVar.declaration .dyn_cast <VarDecl *>())
376
+ if (auto *wrappedVar = uninitializedVar.declaration .dyn_cast <VarDecl *>())
378
377
return wrappedVar->getDeclContext ();
379
378
380
379
return uninitializedVar.binding ->getInitContext (uninitializedVar.index );
@@ -472,9 +471,7 @@ class SolutionApplicationTarget {
472
471
ContextualPattern getContextualPattern () const ;
473
472
474
473
// / Whether this target is for a for-in statement.
475
- bool isForEachStmt () const {
476
- return kind == Kind::forEachStmt;
477
- }
474
+ bool isForEachStmt () const { return kind == Kind::forEachStmt; }
478
475
479
476
// / Whether this is an initialization for an Optional.Some pattern.
480
477
bool isOptionalSomePatternInit () const {
@@ -516,8 +513,8 @@ class SolutionApplicationTarget {
516
513
if (!apply || !wrappedVar)
517
514
return false ;
518
515
519
- // Don't create property wrapper generator functions for static variables and
520
- // local variables with initializers.
516
+ // Don't create property wrapper generator functions for static variables
517
+ // and local variables with initializers.
521
518
bool hasInit = expression.propertyWrapper .hasInitialWrappedValue ;
522
519
if (wrappedVar->isStatic () ||
523
520
(hasInit && wrappedVar->getDeclContext ()->isLocalContext ()))
@@ -856,7 +853,7 @@ class SolutionApplicationTarget {
856
853
857
854
case Kind::uninitializedVar: {
858
855
if (auto *wrappedVar =
859
- uninitializedVar.declaration .dyn_cast <VarDecl *>()) {
856
+ uninitializedVar.declaration .dyn_cast <VarDecl *>()) {
860
857
return wrappedVar->getLoc ();
861
858
}
862
859
return uninitializedVar.declaration .get <Pattern *>()->getLoc ();
@@ -869,10 +866,10 @@ class SolutionApplicationTarget {
869
866
}
870
867
871
868
// / Walk the contents of the application target.
872
- Optional<SolutionApplicationTarget > walk (ASTWalker &walker) const ;
869
+ Optional<SyntacticElementTarget > walk (ASTWalker &walker) const ;
873
870
};
874
871
875
- }
876
- }
872
+ } // namespace constraints
873
+ } // namespace swift
877
874
878
- #endif /* SWIFT_SEMA_SOLUTION_APPLICATION_TARGET_H */
875
+ #endif /* SWIFT_SEMA_SYNTACTIC_ELEMENT_TARGET_H */
0 commit comments