Skip to content

Commit 88579e1

Browse files
committed
[Refactoring] Store SourceFile on AsyncConverter
1 parent 9b15a61 commit 88579e1

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5117,7 +5117,7 @@ class ScopedDeclCollector : private SourceEntityWalker {
51175117
/// the code the user intended. In most cases the refactoring will continue,
51185118
/// with any unhandled decls wrapped in placeholders instead.
51195119
class AsyncConverter : private SourceEntityWalker {
5120-
ASTContext &Context;
5120+
SourceFile *SF;
51215121
SourceManager &SM;
51225122
DiagnosticEngine &DiagEngine;
51235123

@@ -5170,11 +5170,11 @@ class AsyncConverter : private SourceEntityWalker {
51705170

51715171
public:
51725172
/// Convert a function
5173-
AsyncConverter(ASTContext &Context, SourceManager &SM,
5173+
AsyncConverter(SourceFile *SF, SourceManager &SM,
51745174
DiagnosticEngine &DiagEngine, AbstractFunctionDecl *FD,
51755175
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) {
51785178
Placeholders.insert(TopHandler.getHandler());
51795179
ScopedDecls.collect(FD);
51805180

@@ -5184,21 +5184,21 @@ class AsyncConverter : private SourceEntityWalker {
51845184
}
51855185

51865186
/// 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) {
51925190
ScopedDecls.collect(CE);
51935191

51945192
// Create the initial scope, can be more accurate than the general
51955193
// \c ScopedDeclCollector as there is a starting point.
51965194
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);
51995197
addNewScope(UsedDecls);
52005198
}
52015199

5200+
ASTContext &getASTContext() const { return SF->getASTContext(); }
5201+
52025202
bool convert() {
52035203
assert(Buffer.empty() && "AsyncConverter can only be used once");
52045204

@@ -5956,7 +5956,7 @@ class AsyncConverter : private SourceEntityWalker {
59565956
/// Returns a unique name using \c Name as base that doesn't clash with any
59575957
/// other names in the current scope.
59585958
Identifier createUniqueName(StringRef Name) {
5959-
Identifier Ident = Context.getIdentifier(Name);
5959+
Identifier Ident = getASTContext().getIdentifier(Name);
59605960

59615961
auto &CurrentNames = ScopedNames.back();
59625962
if (CurrentNames.count(Ident)) {
@@ -5967,7 +5967,7 @@ class AsyncConverter : private SourceEntityWalker {
59675967
do {
59685968
UniquedName = Name;
59695969
UniquedName.append(std::to_string(UniqueId));
5970-
Ident = Context.getIdentifier(UniquedName);
5970+
Ident = getASTContext().getIdentifier(UniquedName);
59715971
UniqueId++;
59725972
} while (CurrentNames.count(Ident));
59735973
}
@@ -6254,7 +6254,7 @@ bool RefactoringActionConvertCallToAsyncAlternative::performChange() {
62546254
if (!Scopes.empty())
62556255
Scope = cast<BraceStmt>(Scopes.back().get<Stmt *>());
62566256

6257-
AsyncConverter Converter(Ctx, SM, DiagEngine, CE, Scope, *CursorInfo.SF);
6257+
AsyncConverter Converter(TheFile, SM, DiagEngine, CE, Scope);
62586258
if (!Converter.convert())
62596259
return true;
62606260

@@ -6282,7 +6282,7 @@ bool RefactoringActionConvertToAsync::performChange() {
62826282
"Should not run performChange when refactoring is not applicable");
62836283

62846284
auto HandlerDesc = AsyncHandlerParamDesc::find(FD, /*ignoreName=*/true);
6285-
AsyncConverter Converter(Ctx, SM, DiagEngine, FD, HandlerDesc);
6285+
AsyncConverter Converter(TheFile, SM, DiagEngine, FD, HandlerDesc);
62866286
if (!Converter.convert())
62876287
return true;
62886288

@@ -6319,14 +6319,14 @@ bool RefactoringActionAddAsyncAlternative::performChange() {
63196319
assert(HandlerDesc.isValid() &&
63206320
"Should not run performChange when refactoring is not applicable");
63216321

6322-
AsyncConverter Converter(Ctx, SM, DiagEngine, FD, HandlerDesc);
6322+
AsyncConverter Converter(TheFile, SM, DiagEngine, FD, HandlerDesc);
63236323
if (!Converter.convert())
63246324
return true;
63256325

63266326
EditConsumer.accept(SM, FD->getAttributeInsertionLoc(false),
63276327
"@available(*, deprecated, message: \"Prefer async "
63286328
"alternative instead\")\n");
6329-
AsyncConverter LegacyBodyCreator(Ctx, SM, DiagEngine, FD, HandlerDesc);
6329+
AsyncConverter LegacyBodyCreator(TheFile, SM, DiagEngine, FD, HandlerDesc);
63306330
if (LegacyBodyCreator.createLegacyBody()) {
63316331
LegacyBodyCreator.replace(FD->getBody(), EditConsumer);
63326332
}

0 commit comments

Comments
 (0)