@@ -77,10 +77,6 @@ class BuilderClosureVisitor
77
77
// / e.g., during constraint generation.
78
78
bool hadError = false ;
79
79
80
- // / Counter used to give unique names to the variables that are
81
- // / created implicitly.
82
- unsigned varCounter = 0 ;
83
-
84
80
// / The record of what happened when we applied the builder transform.
85
81
AppliedBuilderTransform applied;
86
82
@@ -95,17 +91,6 @@ class BuilderClosureVisitor
95
91
return builder.buildCall (loc, fnName, argExprs, argLabels);
96
92
}
97
93
98
- // / Build an implicit variable in this context.
99
- VarDecl *buildVar (SourceLoc loc) {
100
- // Create the implicit variable.
101
- Identifier name = ctx.getIdentifier (
102
- (" $__builder" + Twine (varCounter++)).str ());
103
- auto var = new (ctx) VarDecl (/* isStatic=*/ false , VarDecl::Introducer::Var,
104
- loc, name, dc);
105
- var->setImplicit ();
106
- return var;
107
- }
108
-
109
94
// / Capture the given expression into an implicitly-generated variable.
110
95
VarDecl *captureExpr (Expr *expr, bool oneWay,
111
96
llvm::PointerUnion<Stmt *, Expr *> forEntity = nullptr ) {
@@ -127,7 +112,7 @@ class BuilderClosureVisitor
127
112
}
128
113
129
114
// Create the implicit variable.
130
- auto var = buildVar (expr->getStartLoc ());
115
+ auto var = builder. buildVar (expr->getStartLoc ());
131
116
132
117
// Record the new variable and its corresponding expression & statement.
133
118
if (auto forStmt = forEntity.dyn_cast <Stmt *>()) {
@@ -563,7 +548,7 @@ class BuilderClosureVisitor
563
548
}
564
549
565
550
// Create a variable to capture the result of this expression.
566
- auto ifVar = buildVar (ifStmt->getStartLoc ());
551
+ auto ifVar = builder. buildVar (ifStmt->getStartLoc ());
567
552
cs->setType (ifVar, resultType);
568
553
applied.capturedStmts .insert ({ifStmt, { ifVar, { thenExpr, elseExpr }}});
569
554
return ifVar;
@@ -730,7 +715,7 @@ class BuilderClosureVisitor
730
715
}
731
716
732
717
// Create a variable to capture the result of evaluating the switch.
733
- auto switchVar = buildVar (switchStmt->getStartLoc ());
718
+ auto switchVar = builder. buildVar (switchStmt->getStartLoc ());
734
719
cs->setType (switchVar, resultType);
735
720
applied.capturedStmts .insert (
736
721
{switchStmt, { switchVar, std::move (injectedCaseExprs) } });
@@ -820,7 +805,7 @@ class BuilderClosureVisitor
820
805
// iteration of the loop. We need a fresh type variable to remove the
821
806
// lvalue-ness of the array variable.
822
807
SourceLoc loc = forEachStmt->getForLoc ();
823
- VarDecl *arrayVar = buildVar (loc);
808
+ VarDecl *arrayVar = builder. buildVar (loc);
824
809
Type arrayElementType = cs->createTypeVariable (
825
810
cs->getConstraintLocator (forEachStmt), 0 );
826
811
cs->addConstraint (ConstraintKind::Equal, cs->getType (bodyVar),
@@ -879,7 +864,7 @@ class BuilderClosureVisitor
879
864
880
865
// Form a final variable for the for-each expression itself, which will
881
866
// be initialized with the call to the result builder's buildArray(_:).
882
- auto finalForEachVar = buildVar (loc);
867
+ auto finalForEachVar = builder. buildVar (loc);
883
868
cs->setType (finalForEachVar, cs->getType (buildArrayCall));
884
869
applied.capturedStmts .insert (
885
870
{forEachStmt, {
@@ -2226,3 +2211,14 @@ Expr *ResultBuilder::buildCall(SourceLoc loc, Identifier fnName,
2226
2211
auto *argList = ArgumentList::createImplicit (ctx, openLoc, args, closeLoc);
2227
2212
return CallExpr::createImplicit (ctx, memberRef, argList);
2228
2213
}
2214
+
2215
+ VarDecl *ResultBuilder::buildVar (SourceLoc loc) {
2216
+ auto &ctx = DC->getASTContext ();
2217
+ // Create the implicit variable.
2218
+ Identifier name =
2219
+ ctx.getIdentifier ((" $__builder" + Twine (VarCounter++)).str ());
2220
+ auto var = new (ctx)
2221
+ VarDecl (/* isStatic=*/ false , VarDecl::Introducer::Var, loc, name, DC);
2222
+ var->setImplicit ();
2223
+ return var;
2224
+ }
0 commit comments