Skip to content

Commit d437141

Browse files
committed
[Clang] Migrate visitors in ARCMigrate
1 parent c526eb8 commit d437141

15 files changed

+165
-162
lines changed

clang/lib/ARCMigrate/ObjCMT.cpp

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "Transforms.h"
10-
#include "clang/Analysis/RetainSummaryManager.h"
1110
#include "clang/ARCMigrate/ARCMT.h"
1211
#include "clang/ARCMigrate/ARCMTActions.h"
1312
#include "clang/AST/ASTConsumer.h"
1413
#include "clang/AST/ASTContext.h"
1514
#include "clang/AST/Attr.h"
15+
#include "clang/AST/DynamicRecursiveASTVisitor.h"
1616
#include "clang/AST/NSAPI.h"
1717
#include "clang/AST/ParentMap.h"
18-
#include "clang/AST/RecursiveASTVisitor.h"
1918
#include "clang/Analysis/DomainSpecific/CocoaConventions.h"
19+
#include "clang/Analysis/RetainSummaryManager.h"
2020
#include "clang/Basic/FileManager.h"
2121
#include "clang/Edit/Commit.h"
2222
#include "clang/Edit/EditedSource.h"
@@ -309,67 +309,68 @@ namespace {
309309
return true;
310310
}
311311

312-
class ObjCMigrator : public RecursiveASTVisitor<ObjCMigrator> {
313-
ObjCMigrateASTConsumer &Consumer;
314-
ParentMap &PMap;
315-
316-
public:
317-
ObjCMigrator(ObjCMigrateASTConsumer &consumer, ParentMap &PMap)
318-
: Consumer(consumer), PMap(PMap) { }
319-
320-
bool shouldVisitTemplateInstantiations() const { return false; }
321-
bool shouldWalkTypesOfTypeLocs() const { return false; }
312+
class ObjCMigrator : public DynamicRecursiveASTVisitor {
313+
ObjCMigrateASTConsumer &Consumer;
314+
ParentMap &PMap;
322315

323-
bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
324-
if (Consumer.ASTMigrateActions & FrontendOptions::ObjCMT_Literals) {
325-
edit::Commit commit(*Consumer.Editor);
326-
edit::rewriteToObjCLiteralSyntax(E, *Consumer.NSAPIObj, commit, &PMap);
327-
Consumer.Editor->commit(commit);
316+
public:
317+
ObjCMigrator(ObjCMigrateASTConsumer &consumer, ParentMap &PMap)
318+
: Consumer(consumer), PMap(PMap) {
319+
ShouldVisitTemplateInstantiations = false;
320+
ShouldWalkTypesOfTypeLocs = false;
328321
}
329322

330-
if (Consumer.ASTMigrateActions & FrontendOptions::ObjCMT_Subscripting) {
331-
edit::Commit commit(*Consumer.Editor);
332-
edit::rewriteToObjCSubscriptSyntax(E, *Consumer.NSAPIObj, commit);
333-
Consumer.Editor->commit(commit);
334-
}
323+
bool VisitObjCMessageExpr(ObjCMessageExpr *E) override {
324+
if (Consumer.ASTMigrateActions & FrontendOptions::ObjCMT_Literals) {
325+
edit::Commit commit(*Consumer.Editor);
326+
edit::rewriteToObjCLiteralSyntax(E, *Consumer.NSAPIObj, commit, &PMap);
327+
Consumer.Editor->commit(commit);
328+
}
335329

336-
if (Consumer.ASTMigrateActions & FrontendOptions::ObjCMT_PropertyDotSyntax) {
337-
edit::Commit commit(*Consumer.Editor);
338-
rewriteToPropertyDotSyntax(E, Consumer.PP, *Consumer.NSAPIObj,
339-
commit, &PMap);
340-
Consumer.Editor->commit(commit);
341-
}
330+
if (Consumer.ASTMigrateActions & FrontendOptions::ObjCMT_Subscripting) {
331+
edit::Commit commit(*Consumer.Editor);
332+
edit::rewriteToObjCSubscriptSyntax(E, *Consumer.NSAPIObj, commit);
333+
Consumer.Editor->commit(commit);
334+
}
342335

343-
return true;
344-
}
336+
if (Consumer.ASTMigrateActions &
337+
FrontendOptions::ObjCMT_PropertyDotSyntax) {
338+
edit::Commit commit(*Consumer.Editor);
339+
rewriteToPropertyDotSyntax(E, Consumer.PP, *Consumer.NSAPIObj, commit,
340+
&PMap);
341+
Consumer.Editor->commit(commit);
342+
}
345343

346-
bool TraverseObjCMessageExpr(ObjCMessageExpr *E) {
347-
// Do depth first; we want to rewrite the subexpressions first so that if
348-
// we have to move expressions we will move them already rewritten.
349-
for (Stmt *SubStmt : E->children())
350-
if (!TraverseStmt(SubStmt))
351-
return false;
344+
return true;
345+
}
352346

353-
return WalkUpFromObjCMessageExpr(E);
354-
}
355-
};
347+
bool TraverseObjCMessageExpr(ObjCMessageExpr *E) override {
348+
// Do depth first; we want to rewrite the subexpressions first so that if
349+
// we have to move expressions we will move them already rewritten.
350+
for (Stmt *SubStmt : E->children())
351+
if (!TraverseStmt(SubStmt))
352+
return false;
356353

357-
class BodyMigrator : public RecursiveASTVisitor<BodyMigrator> {
358-
ObjCMigrateASTConsumer &Consumer;
359-
std::unique_ptr<ParentMap> PMap;
354+
return WalkUpFromObjCMessageExpr(E);
355+
}
356+
};
360357

361-
public:
362-
BodyMigrator(ObjCMigrateASTConsumer &consumer) : Consumer(consumer) { }
358+
class BodyMigrator : public DynamicRecursiveASTVisitor {
359+
ObjCMigrateASTConsumer &Consumer;
360+
std::unique_ptr<ParentMap> PMap;
363361

364-
bool shouldVisitTemplateInstantiations() const { return false; }
365-
bool shouldWalkTypesOfTypeLocs() const { return false; }
362+
public:
363+
BodyMigrator(ObjCMigrateASTConsumer &consumer) : Consumer(consumer) {
364+
ShouldVisitTemplateInstantiations = false;
365+
ShouldWalkTypesOfTypeLocs = false;
366+
}
366367

367-
bool TraverseStmt(Stmt *S) {
368-
PMap.reset(new ParentMap(S));
369-
ObjCMigrator(Consumer, *PMap).TraverseStmt(S);
370-
return true;
371-
}
372-
};
368+
bool TraverseStmt(Stmt *S) override {
369+
PMap.reset(new ParentMap(S));
370+
ObjCMigrator(Consumer, *PMap).TraverseStmt(S);
371+
return true;
372+
}
373+
};
373374
} // end anonymous namespace
374375

375376
void ObjCMigrateASTConsumer::migrateDecl(Decl *D) {
@@ -1672,12 +1673,14 @@ void ObjCMigrateASTConsumer::migrateAddMethodAnnotation(
16721673
}
16731674

16741675
namespace {
1675-
class SuperInitChecker : public RecursiveASTVisitor<SuperInitChecker> {
1676+
class SuperInitChecker : public DynamicRecursiveASTVisitor {
16761677
public:
1677-
bool shouldVisitTemplateInstantiations() const { return false; }
1678-
bool shouldWalkTypesOfTypeLocs() const { return false; }
1678+
SuperInitChecker() {
1679+
ShouldVisitTemplateInstantiations = false;
1680+
ShouldWalkTypesOfTypeLocs = false;
1681+
}
16791682

1680-
bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
1683+
bool VisitObjCMessageExpr(ObjCMessageExpr *E) override {
16811684
if (E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
16821685
if (E->getMethodFamily() == OMF_init)
16831686
return false;

clang/lib/ARCMigrate/TransAPIUses.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
//
1717
//===----------------------------------------------------------------------===//
1818

19-
#include "Transforms.h"
2019
#include "Internals.h"
20+
#include "Transforms.h"
2121
#include "clang/AST/ASTContext.h"
22+
#include "clang/AST/DynamicRecursiveASTVisitor.h"
2223
#include "clang/Sema/SemaDiagnostic.h"
2324

2425
using namespace clang;
@@ -27,7 +28,7 @@ using namespace trans;
2728

2829
namespace {
2930

30-
class APIChecker : public RecursiveASTVisitor<APIChecker> {
31+
class APIChecker : public DynamicRecursiveASTVisitor {
3132
MigrationPass &Pass;
3233

3334
Selector getReturnValueSel, setReturnValueSel;
@@ -51,7 +52,7 @@ class APIChecker : public RecursiveASTVisitor<APIChecker> {
5152
zoneSel = sels.getNullarySelector(&ids.get("zone"));
5253
}
5354

54-
bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
55+
bool VisitObjCMessageExpr(ObjCMessageExpr *E) override {
5556
// NSInvocation.
5657
if (E->isInstanceMessage() &&
5758
E->getReceiverInterface() &&

clang/lib/ARCMigrate/TransARCAssign.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
//
2121
//===----------------------------------------------------------------------===//
2222

23-
#include "Transforms.h"
2423
#include "Internals.h"
24+
#include "Transforms.h"
2525
#include "clang/AST/ASTContext.h"
26+
#include "clang/AST/DynamicRecursiveASTVisitor.h"
2627
#include "clang/Sema/SemaDiagnostic.h"
2728

2829
using namespace clang;
@@ -31,14 +32,14 @@ using namespace trans;
3132

3233
namespace {
3334

34-
class ARCAssignChecker : public RecursiveASTVisitor<ARCAssignChecker> {
35+
class ARCAssignChecker : public DynamicRecursiveASTVisitor {
3536
MigrationPass &Pass;
3637
llvm::DenseSet<VarDecl *> ModifiedVars;
3738

3839
public:
3940
ARCAssignChecker(MigrationPass &pass) : Pass(pass) { }
4041

41-
bool VisitBinaryOperator(BinaryOperator *Exp) {
42+
bool VisitBinaryOperator(BinaryOperator *Exp) override {
4243
if (Exp->getType()->isDependentType())
4344
return true;
4445

clang/lib/ARCMigrate/TransAutoreleasePool.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@
2626
//
2727
//===----------------------------------------------------------------------===//
2828

29-
#include "Transforms.h"
3029
#include "Internals.h"
30+
#include "Transforms.h"
3131
#include "clang/AST/ASTContext.h"
32+
#include "clang/AST/DynamicRecursiveASTVisitor.h"
3233
#include "clang/Basic/SourceManager.h"
3334
#include "clang/Sema/SemaDiagnostic.h"
3435
#include <map>
@@ -39,15 +40,15 @@ using namespace trans;
3940

4041
namespace {
4142

42-
class ReleaseCollector : public RecursiveASTVisitor<ReleaseCollector> {
43+
class ReleaseCollector : public DynamicRecursiveASTVisitor {
4344
Decl *Dcl;
4445
SmallVectorImpl<ObjCMessageExpr *> &Releases;
4546

4647
public:
4748
ReleaseCollector(Decl *D, SmallVectorImpl<ObjCMessageExpr *> &releases)
4849
: Dcl(D), Releases(releases) { }
4950

50-
bool VisitObjCMessageExpr(ObjCMessageExpr *E) {
51+
bool VisitObjCMessageExpr(ObjCMessageExpr *E) override {
5152
if (!E->isInstanceMessage())
5253
return true;
5354
if (E->getMethodFamily() != OMF_release)
@@ -60,13 +61,11 @@ class ReleaseCollector : public RecursiveASTVisitor<ReleaseCollector> {
6061
return true;
6162
}
6263
};
63-
6464
}
6565

6666
namespace {
6767

68-
class AutoreleasePoolRewriter
69-
: public RecursiveASTVisitor<AutoreleasePoolRewriter> {
68+
class AutoreleasePoolRewriter : public DynamicRecursiveASTVisitor {
7069
public:
7170
AutoreleasePoolRewriter(MigrationPass &pass)
7271
: Body(nullptr), Pass(pass) {
@@ -80,7 +79,7 @@ class AutoreleasePoolRewriter
8079
TraverseStmt(body);
8180
}
8281

83-
~AutoreleasePoolRewriter() {
82+
~AutoreleasePoolRewriter() override {
8483
SmallVector<VarDecl *, 8> VarsToHandle;
8584

8685
for (std::map<VarDecl *, PoolVarInfo>::iterator
@@ -160,7 +159,7 @@ class AutoreleasePoolRewriter
160159
}
161160
}
162161

163-
bool VisitCompoundStmt(CompoundStmt *S) {
162+
bool VisitCompoundStmt(CompoundStmt *S) override {
164163
SmallVector<PoolScope, 4> Scopes;
165164

166165
for (Stmt::child_iterator
@@ -245,7 +244,7 @@ class AutoreleasePoolRewriter
245244
}
246245
};
247246

248-
class NameReferenceChecker : public RecursiveASTVisitor<NameReferenceChecker>{
247+
class NameReferenceChecker : public DynamicRecursiveASTVisitor {
249248
ASTContext &Ctx;
250249
SourceRange ScopeRange;
251250
SourceLocation &referenceLoc, &declarationLoc;
@@ -260,15 +259,15 @@ class AutoreleasePoolRewriter
260259
(*scope.End)->getBeginLoc());
261260
}
262261

263-
bool VisitDeclRefExpr(DeclRefExpr *E) {
262+
bool VisitDeclRefExpr(DeclRefExpr *E) override {
264263
return checkRef(E->getLocation(), E->getDecl()->getLocation());
265264
}
266265

267-
bool VisitTypedefTypeLoc(TypedefTypeLoc TL) {
266+
bool VisitTypedefTypeLoc(TypedefTypeLoc TL) override {
268267
return checkRef(TL.getBeginLoc(), TL.getTypedefNameDecl()->getLocation());
269268
}
270269

271-
bool VisitTagTypeLoc(TagTypeLoc TL) {
270+
bool VisitTagTypeLoc(TagTypeLoc TL) override {
272271
return checkRef(TL.getBeginLoc(), TL.getDecl()->getLocation());
273272
}
274273

clang/lib/ARCMigrate/TransBlockObjCVariable.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
//
2525
//===----------------------------------------------------------------------===//
2626

27-
#include "Transforms.h"
2827
#include "Internals.h"
28+
#include "Transforms.h"
2929
#include "clang/AST/ASTContext.h"
3030
#include "clang/AST/Attr.h"
31+
#include "clang/AST/DynamicRecursiveASTVisitor.h"
3132
#include "clang/Basic/SourceManager.h"
3233

3334
using namespace clang;
@@ -36,18 +37,16 @@ using namespace trans;
3637

3738
namespace {
3839

39-
class RootBlockObjCVarRewriter :
40-
public RecursiveASTVisitor<RootBlockObjCVarRewriter> {
40+
class RootBlockObjCVarRewriter : public DynamicRecursiveASTVisitor {
4141
llvm::DenseSet<VarDecl *> &VarsToChange;
4242

43-
class BlockVarChecker : public RecursiveASTVisitor<BlockVarChecker> {
43+
class BlockVarChecker : public DynamicRecursiveASTVisitor {
4444
VarDecl *Var;
4545

46-
typedef RecursiveASTVisitor<BlockVarChecker> base;
4746
public:
4847
BlockVarChecker(VarDecl *var) : Var(var) { }
4948

50-
bool TraverseImplicitCastExpr(ImplicitCastExpr *castE) {
49+
bool TraverseImplicitCastExpr(ImplicitCastExpr *castE) override {
5150
if (DeclRefExpr *
5251
ref = dyn_cast<DeclRefExpr>(castE->getSubExpr())) {
5352
if (ref->getDecl() == Var) {
@@ -59,10 +58,10 @@ class RootBlockObjCVarRewriter :
5958
}
6059
}
6160

62-
return base::TraverseImplicitCastExpr(castE);
61+
return DynamicRecursiveASTVisitor::TraverseImplicitCastExpr(castE);
6362
}
6463

65-
bool VisitDeclRefExpr(DeclRefExpr *E) {
64+
bool VisitDeclRefExpr(DeclRefExpr *E) override {
6665
if (E->getDecl() == Var)
6766
return false; // The reference of the variable, and not just its value,
6867
// is needed.
@@ -74,7 +73,7 @@ class RootBlockObjCVarRewriter :
7473
RootBlockObjCVarRewriter(llvm::DenseSet<VarDecl *> &VarsToChange)
7574
: VarsToChange(VarsToChange) { }
7675

77-
bool VisitBlockDecl(BlockDecl *block) {
76+
bool VisitBlockDecl(BlockDecl *block) override {
7877
SmallVector<VarDecl *, 4> BlockVars;
7978

8079
for (const auto &I : block->captures()) {
@@ -108,14 +107,14 @@ class RootBlockObjCVarRewriter :
108107
}
109108
};
110109

111-
class BlockObjCVarRewriter : public RecursiveASTVisitor<BlockObjCVarRewriter> {
110+
class BlockObjCVarRewriter : public DynamicRecursiveASTVisitor {
112111
llvm::DenseSet<VarDecl *> &VarsToChange;
113112

114113
public:
115114
BlockObjCVarRewriter(llvm::DenseSet<VarDecl *> &VarsToChange)
116115
: VarsToChange(VarsToChange) { }
117116

118-
bool TraverseBlockDecl(BlockDecl *block) {
117+
bool TraverseBlockDecl(BlockDecl *block) override {
119118
RootBlockObjCVarRewriter(VarsToChange).TraverseDecl(block);
120119
return true;
121120
}

0 commit comments

Comments
 (0)