@@ -5117,7 +5117,7 @@ class ScopedDeclCollector : private SourceEntityWalker {
5117
5117
// / the code the user intended. In most cases the refactoring will continue,
5118
5118
// / with any unhandled decls wrapped in placeholders instead.
5119
5119
class AsyncConverter : private SourceEntityWalker {
5120
- ASTContext &Context ;
5120
+ SourceFile *SF ;
5121
5121
SourceManager &SM;
5122
5122
DiagnosticEngine &DiagEngine;
5123
5123
@@ -5170,11 +5170,11 @@ class AsyncConverter : private SourceEntityWalker {
5170
5170
5171
5171
public:
5172
5172
// / Convert a function
5173
- AsyncConverter (ASTContext &Context , SourceManager &SM,
5173
+ AsyncConverter (SourceFile *SF , SourceManager &SM,
5174
5174
DiagnosticEngine &DiagEngine, AbstractFunctionDecl *FD,
5175
5175
const AsyncHandlerParamDesc &TopHandler)
5176
- : Context(Context ), SM(SM), DiagEngine(DiagEngine),
5177
- StartNode (FD), TopHandler(TopHandler), OS(Buffer) {
5176
+ : SF(SF ), SM(SM), DiagEngine(DiagEngine), StartNode(FD ),
5177
+ TopHandler (TopHandler), OS(Buffer) {
5178
5178
Placeholders.insert (TopHandler.getHandler ());
5179
5179
ScopedDecls.collect (FD);
5180
5180
@@ -5184,21 +5184,21 @@ class AsyncConverter : private SourceEntityWalker {
5184
5184
}
5185
5185
5186
5186
// / Convert a call
5187
- AsyncConverter (ASTContext &Context, SourceManager &SM,
5188
- DiagnosticEngine &DiagEngine, CallExpr *CE, BraceStmt *Scope,
5189
- SourceFile &SF)
5190
- : Context(Context), SM(SM), DiagEngine(DiagEngine),
5191
- StartNode(CE), OS(Buffer) {
5187
+ AsyncConverter (SourceFile *SF, SourceManager &SM,
5188
+ DiagnosticEngine &DiagEngine, CallExpr *CE, BraceStmt *Scope)
5189
+ : SF(SF), SM(SM), DiagEngine(DiagEngine), StartNode(CE), OS(Buffer) {
5192
5190
ScopedDecls.collect (CE);
5193
5191
5194
5192
// Create the initial scope, can be more accurate than the general
5195
5193
// \c ScopedDeclCollector as there is a starting point.
5196
5194
llvm::DenseSet<const Decl *> UsedDecls;
5197
- DeclCollector::collect (Scope, SF, UsedDecls);
5198
- ReferenceCollector::collect (StartNode, Scope, SF, UsedDecls);
5195
+ DeclCollector::collect (Scope, * SF, UsedDecls);
5196
+ ReferenceCollector::collect (StartNode, Scope, * SF, UsedDecls);
5199
5197
addNewScope (UsedDecls);
5200
5198
}
5201
5199
5200
+ ASTContext &getASTContext () const { return SF->getASTContext (); }
5201
+
5202
5202
bool convert () {
5203
5203
assert (Buffer.empty () && " AsyncConverter can only be used once" );
5204
5204
@@ -5956,7 +5956,7 @@ class AsyncConverter : private SourceEntityWalker {
5956
5956
// / Returns a unique name using \c Name as base that doesn't clash with any
5957
5957
// / other names in the current scope.
5958
5958
Identifier createUniqueName (StringRef Name) {
5959
- Identifier Ident = Context .getIdentifier (Name);
5959
+ Identifier Ident = getASTContext () .getIdentifier (Name);
5960
5960
5961
5961
auto &CurrentNames = ScopedNames.back ();
5962
5962
if (CurrentNames.count (Ident)) {
@@ -5967,7 +5967,7 @@ class AsyncConverter : private SourceEntityWalker {
5967
5967
do {
5968
5968
UniquedName = Name;
5969
5969
UniquedName.append (std::to_string (UniqueId));
5970
- Ident = Context .getIdentifier (UniquedName);
5970
+ Ident = getASTContext () .getIdentifier (UniquedName);
5971
5971
UniqueId++;
5972
5972
} while (CurrentNames.count (Ident));
5973
5973
}
@@ -6254,7 +6254,7 @@ bool RefactoringActionConvertCallToAsyncAlternative::performChange() {
6254
6254
if (!Scopes.empty ())
6255
6255
Scope = cast<BraceStmt>(Scopes.back ().get <Stmt *>());
6256
6256
6257
- AsyncConverter Converter (Ctx , SM, DiagEngine, CE, Scope, *CursorInfo. SF );
6257
+ AsyncConverter Converter (TheFile , SM, DiagEngine, CE, Scope);
6258
6258
if (!Converter.convert ())
6259
6259
return true ;
6260
6260
@@ -6282,7 +6282,7 @@ bool RefactoringActionConvertToAsync::performChange() {
6282
6282
" Should not run performChange when refactoring is not applicable" );
6283
6283
6284
6284
auto HandlerDesc = AsyncHandlerParamDesc::find (FD, /* ignoreName=*/ true );
6285
- AsyncConverter Converter (Ctx , SM, DiagEngine, FD, HandlerDesc);
6285
+ AsyncConverter Converter (TheFile , SM, DiagEngine, FD, HandlerDesc);
6286
6286
if (!Converter.convert ())
6287
6287
return true ;
6288
6288
@@ -6319,14 +6319,14 @@ bool RefactoringActionAddAsyncAlternative::performChange() {
6319
6319
assert (HandlerDesc.isValid () &&
6320
6320
" Should not run performChange when refactoring is not applicable" );
6321
6321
6322
- AsyncConverter Converter (Ctx , SM, DiagEngine, FD, HandlerDesc);
6322
+ AsyncConverter Converter (TheFile , SM, DiagEngine, FD, HandlerDesc);
6323
6323
if (!Converter.convert ())
6324
6324
return true ;
6325
6325
6326
6326
EditConsumer.accept (SM, FD->getAttributeInsertionLoc (false ),
6327
6327
" @available(*, deprecated, message: \" Prefer async "
6328
6328
" alternative instead\" )\n " );
6329
- AsyncConverter LegacyBodyCreator (Ctx , SM, DiagEngine, FD, HandlerDesc);
6329
+ AsyncConverter LegacyBodyCreator (TheFile , SM, DiagEngine, FD, HandlerDesc);
6330
6330
if (LegacyBodyCreator.createLegacyBody ()) {
6331
6331
LegacyBodyCreator.replace (FD->getBody (), EditConsumer);
6332
6332
}
0 commit comments