Skip to content

Commit 437a186

Browse files
[gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
1 parent c9f5766 commit 437a186

File tree

9 files changed

+15
-15
lines changed

9 files changed

+15
-15
lines changed

Diff for: lib/AST/TypeRepr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ static void printGenericArgs(ASTPrinter &Printer, const PrintOptions &Opts,
336336

337337
void ComponentIdentTypeRepr::printImpl(ASTPrinter &Printer,
338338
const PrintOptions &Opts) const {
339-
if (TypeDecl *TD = dyn_cast_or_null<TypeDecl>(getBoundDecl())) {
339+
if (auto *TD = dyn_cast_or_null<TypeDecl>(getBoundDecl())) {
340340
if (auto MD = dyn_cast<ModuleDecl>(TD))
341341
Printer.printModuleRef(MD, getIdentifier());
342342
else

Diff for: lib/ClangImporter/ImportDecl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5423,7 +5423,7 @@ SwiftDeclConverter::getImplicitProperty(ImportedName importedName,
54235423
FinalAttr(/*IsImplicit=*/true));
54245424

54255425
// Import the getter.
5426-
FuncDecl *swiftGetter = dyn_cast_or_null<FuncDecl>(
5426+
auto *swiftGetter = dyn_cast_or_null<FuncDecl>(
54275427
importFunctionDecl(getter, getterName, None, property));
54285428
if (!swiftGetter)
54295429
return nullptr;

Diff for: lib/IDE/Formatting.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class FormatContext {
200200

201201
if (ParentLineAndColumn.first != LineAndColumn.first) {
202202
// The start line is not the same, see if this is at the 'else' clause.
203-
if (IfStmt *If = dyn_cast_or_null<IfStmt>(Cursor->getAsStmt())) {
203+
if (auto *If = dyn_cast_or_null<IfStmt>(Cursor->getAsStmt())) {
204204
SourceLoc ElseLoc = If->getElseLoc();
205205
// If we're at 'else', take the indent of 'if' and continue.
206206
if (ElseLoc.isValid() &&
@@ -268,7 +268,7 @@ class FormatContext {
268268
}
269269

270270
// Handle switch / case, indent unless at a case label.
271-
if (CaseStmt *Case = dyn_cast_or_null<CaseStmt>(Cursor->getAsStmt())) {
271+
if (auto *Case = dyn_cast_or_null<CaseStmt>(Cursor->getAsStmt())) {
272272
auto LabelItems = Case->getCaseLabelItems();
273273
SourceLoc Loc;
274274
if (!LabelItems.empty())

Diff for: lib/Index/Index.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ bool IndexSwiftASTWalker::reportInheritedTypeRefs(ArrayRef<TypeLoc> Inherited, D
726726

727727
bool IndexSwiftASTWalker::reportRelatedTypeRef(const TypeLoc &Ty, SymbolRoleSet Relations, Decl *Related) {
728728

729-
if (IdentTypeRepr *T = dyn_cast_or_null<IdentTypeRepr>(Ty.getTypeRepr())) {
729+
if (auto *T = dyn_cast_or_null<IdentTypeRepr>(Ty.getTypeRepr())) {
730730
auto Comps = T->getComponentRange();
731731
SourceLoc IdLoc = Comps.back()->getIdLoc();
732732
NominalTypeDecl *NTD = nullptr;
@@ -845,7 +845,7 @@ NominalTypeDecl *
845845
IndexSwiftASTWalker::getTypeLocAsNominalTypeDecl(const TypeLoc &Ty) {
846846
if (Type T = Ty.getType())
847847
return T->getAnyNominal();
848-
if (IdentTypeRepr *T = dyn_cast_or_null<IdentTypeRepr>(Ty.getTypeRepr())) {
848+
if (auto *T = dyn_cast_or_null<IdentTypeRepr>(Ty.getTypeRepr())) {
849849
auto Comp = T->getComponentRange().back();
850850
if (auto NTD = dyn_cast_or_null<NominalTypeDecl>(Comp->getBoundDecl()))
851851
return NTD;

Diff for: lib/SILGen/RValue.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using namespace Lowering;
2929

3030

3131
static unsigned getTupleSize(CanType t) {
32-
if (TupleType *tt = dyn_cast<TupleType>(t))
32+
if (auto tt = dyn_cast<TupleType>(t))
3333
return tt->getNumElements();
3434
return 1;
3535
}

Diff for: lib/SILOptimizer/IPO/GlobalPropertyOpt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class GlobalPropertyOpt {
122122
/// Returns true if the type is a tuple which contains at least one array
123123
/// (we don't check for arrays in nested tuples).
124124
bool isTupleWithArray(CanType type) {
125-
if (TupleType *tuple = dyn_cast<TupleType>(type)) {
125+
if (auto tuple = dyn_cast<TupleType>(type)) {
126126
for (Type subType : tuple->getElementTypes()) {
127127
if (CanType(subType).getNominalOrBoundGenericNominal() == ArrayType)
128128
return true;

Diff for: lib/SILOptimizer/Transforms/SILMem2Reg.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ StackAllocationPromoter::getLiveOutValue(BlockSet &PhiBlocks,
537537
// If there is a store (that must come after the phi), use its value.
538538
BlockToInstMap::iterator it = LastStoreInBlock.find(BB);
539539
if (it != LastStoreInBlock.end())
540-
if (StoreInst *St = dyn_cast_or_null<StoreInst>(it->second)) {
540+
if (auto *St = dyn_cast_or_null<StoreInst>(it->second)) {
541541
DEBUG(llvm::dbgs() << "*** Found Store def " << *St->getSrc());
542542
return St->getSrc();
543543
}

Diff for: lib/Sema/PCMacro.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class Instrumenter : InstrumenterBase {
270270
}
271271

272272
DoStmt *transformDoStmt(DoStmt *DS) {
273-
if (BraceStmt *B = dyn_cast_or_null<BraceStmt>(DS->getBody())) {
273+
if (auto *B = dyn_cast_or_null<BraceStmt>(DS->getBody())) {
274274
BraceStmt *NB = transformBraceStmt(B);
275275
if (NB != B) {
276276
DS->setBody(NB);
@@ -280,14 +280,14 @@ class Instrumenter : InstrumenterBase {
280280
}
281281

282282
DoCatchStmt *transformDoCatchStmt(DoCatchStmt *DCS) {
283-
if (BraceStmt *B = dyn_cast_or_null<BraceStmt>(DCS->getBody())) {
283+
if (auto *B = dyn_cast_or_null<BraceStmt>(DCS->getBody())) {
284284
BraceStmt *NB = transformBraceStmt(B);
285285
if (NB != B) {
286286
DCS->setBody(NB);
287287
}
288288
}
289289
for (CatchStmt *C : DCS->getCatches()) {
290-
if (BraceStmt *CB = dyn_cast_or_null<BraceStmt>(C->getBody())) {
290+
if (auto *CB = dyn_cast_or_null<BraceStmt>(C->getBody())) {
291291
BraceStmt *NCB = transformBraceStmt(CB);
292292
if (NCB != CB) {
293293
C->setBody(NCB);

Diff for: lib/Sema/PlaygroundTransform.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class Instrumenter : InstrumenterBase {
243243
}
244244

245245
DoStmt *transformDoStmt(DoStmt *DS) {
246-
if (BraceStmt *B = dyn_cast_or_null<BraceStmt>(DS->getBody())) {
246+
if (auto *B = dyn_cast_or_null<BraceStmt>(DS->getBody())) {
247247
BraceStmt *NB = transformBraceStmt(B);
248248
if (NB != B) {
249249
DS->setBody(NB);
@@ -253,14 +253,14 @@ class Instrumenter : InstrumenterBase {
253253
}
254254

255255
DoCatchStmt *transformDoCatchStmt(DoCatchStmt *DCS) {
256-
if (BraceStmt *B = dyn_cast_or_null<BraceStmt>(DCS->getBody())) {
256+
if (auto *B = dyn_cast_or_null<BraceStmt>(DCS->getBody())) {
257257
BraceStmt *NB = transformBraceStmt(B);
258258
if (NB != B) {
259259
DCS->setBody(NB);
260260
}
261261
}
262262
for (CatchStmt *C : DCS->getCatches()) {
263-
if (BraceStmt *CB = dyn_cast_or_null<BraceStmt>(C->getBody())) {
263+
if (auto *CB = dyn_cast_or_null<BraceStmt>(C->getBody())) {
264264
BraceStmt *NCB = transformBraceStmt(CB);
265265
if (NCB != CB) {
266266
C->setBody(NCB);

0 commit comments

Comments
 (0)