@@ -128,11 +128,6 @@ class BuilderClosureVisitor
128
128
return var;
129
129
}
130
130
131
- // / Build an implicit reference to the given variable.
132
- DeclRefExpr *buildVarRef (VarDecl *var, SourceLoc loc) {
133
- return new (ctx) DeclRefExpr (var, DeclNameLoc (loc), /* Implicit=*/ true );
134
- }
135
-
136
131
public:
137
132
BuilderClosureVisitor (ASTContext &ctx, ConstraintSystem *cs, DeclContext *dc,
138
133
Type builderType, Type bodyResultType)
@@ -147,7 +142,7 @@ class BuilderClosureVisitor
147
142
if (!bodyVar)
148
143
return None;
149
144
150
- applied.returnExpr = buildVarRef (bodyVar, stmt->getEndLoc ());
145
+ applied.returnExpr = builder. buildVarRef (bodyVar, stmt->getEndLoc ());
151
146
152
147
// If there is a buildFinalResult(_:), call it.
153
148
ASTContext &ctx = cs->getASTContext ();
@@ -227,7 +222,7 @@ class BuilderClosureVisitor
227
222
if (!childVar)
228
223
return ;
229
224
230
- expressions.push_back (buildVarRef (childVar, childVar->getLoc ()));
225
+ expressions.push_back (builder. buildVarRef (childVar, childVar->getLoc ()));
231
226
};
232
227
233
228
for (auto node : braceStmt->getElements ()) {
@@ -342,7 +337,7 @@ class BuilderClosureVisitor
342
337
if (!childVar)
343
338
return nullptr ;
344
339
345
- auto childRef = buildVarRef (childVar, doStmt->getEndLoc ());
340
+ auto childRef = builder. buildVarRef (childVar, doStmt->getEndLoc ());
346
341
347
342
return captureExpr (childRef, /* oneWay=*/ true , doStmt);
348
343
}
@@ -455,8 +450,8 @@ class BuilderClosureVisitor
455
450
if (!cs || !thenVar || (elseChainVar && !*elseChainVar))
456
451
return nullptr ;
457
452
458
- Expr *thenVarRefExpr = buildVarRef (
459
- thenVar, ifStmt->getThenStmt ()->getEndLoc ());
453
+ Expr *thenVarRefExpr =
454
+ builder. buildVarRef ( thenVar, ifStmt->getThenStmt ()->getEndLoc ());
460
455
461
456
// If there is a #available in the condition, wrap the 'then' in a call to
462
457
// buildLimitedAvailability(_:).
@@ -487,12 +482,13 @@ class BuilderClosureVisitor
487
482
// - If there's an `else if`, the chain expression from that
488
483
// should already be producing a chain result.
489
484
} else if (isElseIf) {
490
- elseExpr = buildVarRef (*elseChainVar, ifStmt->getEndLoc ());
485
+ elseExpr = builder. buildVarRef (*elseChainVar, ifStmt->getEndLoc ());
491
486
elseLoc = ifStmt->getElseLoc ();
492
487
493
488
// - Otherwise, wrap it to produce a chain result.
494
489
} else {
495
- Expr *elseVarRefExpr = buildVarRef (*elseChainVar, ifStmt->getEndLoc ());
490
+ Expr *elseVarRefExpr =
491
+ builder.buildVarRef (*elseChainVar, ifStmt->getEndLoc ());
496
492
497
493
// If there is a #unavailable in the condition, wrap the 'else' in a call
498
494
// to buildLimitedAvailability(_:).
@@ -679,7 +675,7 @@ class BuilderClosureVisitor
679
675
680
676
// Build the expression that injects the case variable into appropriate
681
677
// buildEither(first:)/buildEither(second:) chain.
682
- Expr *caseVarRef = buildVarRef (caseVar, caseStmt->getEndLoc ());
678
+ Expr *caseVarRef = builder. buildVarRef (caseVar, caseStmt->getEndLoc ());
683
679
Expr *injectedCaseExpr = buildWrappedChainPayload (
684
680
caseVarRef, idx, capturedCaseVars.size (), /* isOptional=*/ false );
685
681
@@ -826,13 +822,13 @@ class BuilderClosureVisitor
826
822
// Form a call to Array.append(_:) to add the result of executing each
827
823
// iteration of the loop body to the array formed above.
828
824
SourceLoc endLoc = forEachStmt->getEndLoc ();
829
- auto arrayVarRef = buildVarRef (arrayVar, endLoc);
825
+ auto arrayVarRef = builder. buildVarRef (arrayVar, endLoc);
830
826
auto arrayAppendRef = new (ctx) UnresolvedDotExpr (
831
827
arrayVarRef, endLoc, DeclNameRef (ctx.getIdentifier (" append" )),
832
828
DeclNameLoc (endLoc), /* implicit=*/ true );
833
829
arrayAppendRef->setFunctionRefKind (FunctionRefKind::SingleApply);
834
830
835
- auto bodyVarRef = buildVarRef (bodyVar, endLoc);
831
+ auto bodyVarRef = builder. buildVarRef (bodyVar, endLoc);
836
832
auto *argList = ArgumentList::createImplicit (
837
833
ctx, endLoc, {Argument::unlabeled (bodyVarRef)}, endLoc);
838
834
Expr *arrayAppendCall =
@@ -846,7 +842,7 @@ class BuilderClosureVisitor
846
842
// Form the final call to buildArray(arrayVar) to allow the function
847
843
// builder to reshape the array into whatever it wants as the result of
848
844
// the for-each loop.
849
- auto finalArrayVarRef = buildVarRef (arrayVar, endLoc);
845
+ auto finalArrayVarRef = builder. buildVarRef (arrayVar, endLoc);
850
846
auto buildArrayCall = buildCallIfWanted (
851
847
endLoc, ctx.Id_buildArray , { finalArrayVarRef }, { Identifier () });
852
848
assert (buildArrayCall);
@@ -2217,3 +2213,8 @@ VarDecl *ResultBuilder::buildVar(SourceLoc loc) {
2217
2213
var->setImplicit ();
2218
2214
return var;
2219
2215
}
2216
+
2217
+ DeclRefExpr *ResultBuilder::buildVarRef (VarDecl *var, SourceLoc loc) {
2218
+ return new (DC->getASTContext ())
2219
+ DeclRefExpr (var, DeclNameLoc (loc), /* Implicit=*/ true );
2220
+ }
0 commit comments