Skip to content

Commit 5ae29e3

Browse files
authored
Merge pull request #6121 from gottesmm/more_clang_tidy
2 parents dc7669a + 81d75e3 commit 5ae29e3

36 files changed

+133
-153
lines changed

lib/AST/ASTContext.cpp

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ void ASTContext::setLazyResolver(LazyResolver *resolver) {
473473
/// specified string.
474474
Identifier ASTContext::getIdentifier(StringRef Str) const {
475475
// Make sure null pointers stay null.
476-
if (Str.data() == nullptr) return Identifier(0);
476+
if (Str.data() == nullptr)
477+
return Identifier(nullptr);
477478

478479
auto I = Impl.IdentifierTable.insert(std::make_pair(Str, char())).first;
479480
return Identifier(I->getKeyData());
@@ -2421,7 +2422,7 @@ Type ErrorType::get(Type originalType) {
24212422
BuiltinIntegerType *BuiltinIntegerType::get(BuiltinIntegerWidth BitWidth,
24222423
const ASTContext &C) {
24232424
BuiltinIntegerType *&Result = C.Impl.IntegerTypes[BitWidth];
2424-
if (Result == 0)
2425+
if (Result == nullptr)
24252426
Result = new (C, AllocationArena::Permanent) BuiltinIntegerType(BitWidth,C);
24262427
return Result;
24272428
}
@@ -2451,7 +2452,7 @@ ParenType *ParenType::get(const ASTContext &C, Type underlying,
24512452
auto arena = getArena(properties);
24522453
ParenType *&Result =
24532454
C.Impl.getArena(arena).ParenTypes[{underlying, flags.toRaw()}];
2454-
if (Result == 0) {
2455+
if (Result == nullptr) {
24552456
Result = new (C, arena) ParenType(underlying, properties, flags);
24562457
}
24572458
return Result;
@@ -2485,8 +2486,7 @@ Type TupleType::get(ArrayRef<TupleTypeElt> Fields, const ASTContext &C) {
24852486

24862487
auto arena = getArena(properties);
24872488

2488-
2489-
void *InsertPos = 0;
2489+
void *InsertPos = nullptr;
24902490
// Check to see if we've already seen this tuple before.
24912491
llvm::FoldingSetNodeID ID;
24922492
TupleType::Profile(ID, Fields);
@@ -2509,8 +2509,8 @@ Type TupleType::get(ArrayRef<TupleTypeElt> Fields, const ASTContext &C) {
25092509

25102510
Fields = ArrayRef<TupleTypeElt>(FieldsCopy, Fields.size());
25112511

2512-
TupleType *New = new (C, arena) TupleType(Fields, IsCanonical ? &C : 0,
2513-
properties);
2512+
TupleType *New =
2513+
new (C, arena) TupleType(Fields, IsCanonical ? &C : nullptr, properties);
25142514
C.Impl.getArena(arena).TupleTypes.InsertNode(New, InsertPos);
25152515
return New;
25162516
}
@@ -2525,7 +2525,7 @@ UnboundGenericType *UnboundGenericType::
25252525
get(GenericTypeDecl *TheDecl, Type Parent, const ASTContext &C) {
25262526
llvm::FoldingSetNodeID ID;
25272527
UnboundGenericType::Profile(ID, TheDecl, Parent);
2528-
void *InsertPos = 0;
2528+
void *InsertPos = nullptr;
25292529
RecursiveTypeProperties properties;
25302530
if (Parent) properties |= Parent->getRecursiveProperties();
25312531
auto arena = getArena(properties);
@@ -2581,7 +2581,7 @@ BoundGenericType *BoundGenericType::get(NominalTypeDecl *TheDecl,
25812581

25822582
auto arena = getArena(properties);
25832583

2584-
void *InsertPos = 0;
2584+
void *InsertPos = nullptr;
25852585
if (BoundGenericType *BGT =
25862586
C.Impl.getArena(arena).BoundGenericTypes.FindNodeOrInsertPos(ID,
25872587
InsertPos))
@@ -2600,18 +2600,15 @@ BoundGenericType *BoundGenericType::get(NominalTypeDecl *TheDecl,
26002600

26012601
BoundGenericType *newType;
26022602
if (auto theClass = dyn_cast<ClassDecl>(TheDecl)) {
2603-
newType = new (C, arena) BoundGenericClassType(theClass, Parent, ArgsCopy,
2604-
IsCanonical ? &C : 0,
2605-
properties);
2603+
newType = new (C, arena) BoundGenericClassType(
2604+
theClass, Parent, ArgsCopy, IsCanonical ? &C : nullptr, properties);
26062605
} else if (auto theStruct = dyn_cast<StructDecl>(TheDecl)) {
2607-
newType = new (C, arena) BoundGenericStructType(theStruct, Parent, ArgsCopy,
2608-
IsCanonical ? &C : 0,
2609-
properties);
2606+
newType = new (C, arena) BoundGenericStructType(
2607+
theStruct, Parent, ArgsCopy, IsCanonical ? &C : nullptr, properties);
26102608
} else {
26112609
auto theEnum = cast<EnumDecl>(TheDecl);
2612-
newType = new (C, arena) BoundGenericEnumType(theEnum, Parent, ArgsCopy,
2613-
IsCanonical ? &C : 0,
2614-
properties);
2610+
newType = new (C, arena) BoundGenericEnumType(
2611+
theEnum, Parent, ArgsCopy, IsCanonical ? &C : nullptr, properties);
26152612
}
26162613
C.Impl.getArena(arena).BoundGenericTypes.InsertNode(newType, InsertPos);
26172614

@@ -2654,7 +2651,7 @@ EnumType *EnumType::get(EnumDecl *D, Type Parent, const ASTContext &C) {
26542651
if (Parent) properties |= Parent->getRecursiveProperties();
26552652
auto arena = getArena(properties);
26562653

2657-
void *insertPos = 0;
2654+
void *insertPos = nullptr;
26582655
if (auto enumTy
26592656
= C.Impl.getArena(arena).EnumTypes.FindNodeOrInsertPos(id, insertPos))
26602657
return enumTy;
@@ -2681,7 +2678,7 @@ StructType *StructType::get(StructDecl *D, Type Parent, const ASTContext &C) {
26812678
if (Parent) properties |= Parent->getRecursiveProperties();
26822679
auto arena = getArena(properties);
26832680

2684-
void *insertPos = 0;
2681+
void *insertPos = nullptr;
26852682
if (auto structTy
26862683
= C.Impl.getArena(arena).StructTypes.FindNodeOrInsertPos(id, insertPos))
26872684
return structTy;
@@ -2708,7 +2705,7 @@ ClassType *ClassType::get(ClassDecl *D, Type Parent, const ASTContext &C) {
27082705
if (Parent) properties |= Parent->getRecursiveProperties();
27092706
auto arena = getArena(properties);
27102707

2711-
void *insertPos = 0;
2708+
void *insertPos = nullptr;
27122709
if (auto classTy
27132710
= C.Impl.getArena(arena).ClassTypes.FindNodeOrInsertPos(id, insertPos))
27142711
return classTy;
@@ -2726,7 +2723,7 @@ void ClassType::Profile(llvm::FoldingSetNodeID &ID, ClassDecl *D, Type Parent) {
27262723
ProtocolCompositionType *
27272724
ProtocolCompositionType::build(const ASTContext &C, ArrayRef<Type> Protocols) {
27282725
// Check to see if we've already seen this protocol composition before.
2729-
void *InsertPos = 0;
2726+
void *InsertPos = nullptr;
27302727
llvm::FoldingSetNodeID ID;
27312728
ProtocolCompositionType::Profile(ID, Protocols);
27322729
if (ProtocolCompositionType *Result
@@ -2764,19 +2761,16 @@ ReferenceStorageType *ReferenceStorageType::get(Type T, Ownership ownership,
27642761
switch (ownership) {
27652762
case Ownership::Strong: llvm_unreachable("not possible");
27662763
case Ownership::Unowned:
2767-
return entry =
2768-
new (C, arena) UnownedStorageType(T, T->isCanonical() ? &C : 0,
2769-
properties);
2764+
return entry = new (C, arena) UnownedStorageType(
2765+
T, T->isCanonical() ? &C : nullptr, properties);
27702766
case Ownership::Weak:
27712767
assert(T->getAnyOptionalObjectType() &&
27722768
"object of weak storage type is not optional");
2773-
return entry =
2774-
new (C, arena) WeakStorageType(T, T->isCanonical() ? &C : 0,
2775-
properties);
2769+
return entry = new (C, arena)
2770+
WeakStorageType(T, T->isCanonical() ? &C : nullptr, properties);
27762771
case Ownership::Unmanaged:
2777-
return entry =
2778-
new (C, arena) UnmanagedStorageType(T, T->isCanonical() ? &C : 0,
2779-
properties);
2772+
return entry = new (C, arena) UnmanagedStorageType(
2773+
T, T->isCanonical() ? &C : nullptr, properties);
27802774
}
27812775
llvm_unreachable("bad ownership");
27822776
}
@@ -2807,9 +2801,8 @@ MetatypeType *MetatypeType::get(Type T, Optional<MetatypeRepresentation> Repr,
28072801
MetatypeType *&Entry = Ctx.Impl.getArena(arena).MetatypeTypes[{T, reprKey}];
28082802
if (Entry) return Entry;
28092803

2810-
return Entry = new (Ctx, arena) MetatypeType(T,
2811-
T->isCanonical() ? &Ctx : 0,
2812-
properties, Repr);
2804+
return Entry = new (Ctx, arena) MetatypeType(
2805+
T, T->isCanonical() ? &Ctx : nullptr, properties, Repr);
28132806
}
28142807

28152808
MetatypeType::MetatypeType(Type T, const ASTContext *C,
@@ -2833,9 +2826,8 @@ ExistentialMetatypeType::get(Type T, Optional<MetatypeRepresentation> repr,
28332826
auto &entry = ctx.Impl.getArena(arena).ExistentialMetatypeTypes[{T, reprKey}];
28342827
if (entry) return entry;
28352828

2836-
return entry = new (ctx, arena) ExistentialMetatypeType(T,
2837-
T->isCanonical() ? &ctx : 0,
2838-
properties, repr);
2829+
return entry = new (ctx, arena) ExistentialMetatypeType(
2830+
T, T->isCanonical() ? &ctx : nullptr, properties, repr);
28392831
}
28402832

28412833
ExistentialMetatypeType::ExistentialMetatypeType(Type T,
@@ -2945,14 +2937,11 @@ FunctionType *FunctionType::get(Type Input, Type Result,
29452937
FunctionType::FunctionType(Type input, Type output,
29462938
RecursiveTypeProperties properties,
29472939
const ExtInfo &Info)
2948-
: AnyFunctionType(TypeKind::Function,
2949-
(input->isCanonical() && output->isCanonical()) ?
2950-
&input->getASTContext() : 0,
2951-
input, output,
2952-
properties,
2953-
Info)
2954-
{ }
2955-
2940+
: AnyFunctionType(TypeKind::Function,
2941+
(input->isCanonical() && output->isCanonical())
2942+
? &input->getASTContext()
2943+
: nullptr,
2944+
input, output, properties, Info) {}
29562945

29572946
void GenericFunctionType::Profile(llvm::FoldingSetNodeID &ID,
29582947
GenericSignature *sig,
@@ -3298,7 +3287,7 @@ ProtocolType *ProtocolType::get(ProtocolDecl *D, const ASTContext &C) {
32983287
if (Parent) properties |= Parent->getRecursiveProperties();
32993288
auto arena = getArena(properties);
33003289

3301-
void *insertPos = 0;
3290+
void *insertPos = nullptr;
33023291
if (auto protoTy
33033292
= C.Impl.getArena(arena).ProtocolTypes.FindNodeOrInsertPos(id, insertPos))
33043293
return protoTy;

lib/AST/ASTScope.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -865,14 +865,11 @@ ASTScope *ASTScope::createIfNeeded(const ASTScope *parent, Decl *decl) {
865865
if (decl->isImplicit()) return nullptr;
866866

867867
// Accessors are always nested within their abstract storage declaration.
868-
bool isAccessor = false;
869868
if (auto func = dyn_cast<FuncDecl>(decl)) {
870-
if (func->isAccessor()) {
871-
isAccessor = true;
872-
if (!parentDirectDescendedFromAbstractStorageDecl(
873-
parent, func->getAccessorStorageDecl()))
874-
return nullptr;
875-
}
869+
if (func->isAccessor() &&
870+
!parentDirectDescendedFromAbstractStorageDecl(
871+
parent, func->getAccessorStorageDecl()))
872+
return nullptr;
876873
}
877874

878875
ASTContext &ctx = decl->getASTContext();

lib/AST/Builtins.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ struct BuiltinExtraInfoTy {
3232
};
3333

3434
static const BuiltinExtraInfoTy BuiltinExtraInfo[] = {
35-
{0},
35+
{nullptr},
3636
#define BUILTIN(Id, Name, Attrs) {Attrs},
3737
#include "swift/AST/Builtins.def"
3838
};
3939

4040
bool BuiltinInfo::isReadNone() const {
41-
return strchr(BuiltinExtraInfo[(unsigned)ID].Attributes, 'n') != 0;
41+
return strchr(BuiltinExtraInfo[(unsigned)ID].Attributes, 'n') != nullptr;
4242
}
4343

4444
bool IntrinsicInfo::hasAttribute(llvm::Attribute::AttrKind Kind) const {

lib/AST/Identifier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ using namespace swift;
2222

2323

2424
raw_ostream &llvm::operator<<(raw_ostream &OS, Identifier I) {
25-
if (I.get() == 0) return OS << "_";
25+
if (I.get() == nullptr)
26+
return OS << "_";
2627
return OS << I.get();
2728
}
2829

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,8 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
684684
// scope, and if so, whether this is a reference to one of them.
685685
// FIXME: We should persist this information between lookups.
686686
while (!DC->isModuleScopeContext()) {
687-
ValueDecl *BaseDecl = 0;
688-
ValueDecl *MetaBaseDecl = 0;
687+
ValueDecl *BaseDecl = nullptr;
688+
ValueDecl *MetaBaseDecl = nullptr;
689689
GenericParamList *GenericParams = nullptr;
690690
Type ExtendedType;
691691
bool isTypeLookup = false;

lib/AST/Type.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ void *TypeBase::operator new(size_t bytes, const ASTContext &ctx,
6363
}
6464

6565
bool CanType::isActuallyCanonicalOrNull() const {
66-
return getPointer() == 0 ||
67-
getPointer() == llvm::DenseMapInfo<TypeBase*>::getTombstoneKey() ||
66+
return getPointer() == nullptr ||
67+
getPointer() == llvm::DenseMapInfo<TypeBase *>::getTombstoneKey() ||
6868
getPointer()->isCanonical();
6969
}
7070

@@ -1056,7 +1056,7 @@ void ProtocolType::canonicalizeProtocols(
10561056
}
10571057

10581058
// We have seen this protocol before; zap this occurrence.
1059-
protocols[I] = 0;
1059+
protocols[I] = nullptr;
10601060
zappedAny = true;
10611061
}
10621062

@@ -1093,7 +1093,7 @@ CanType TypeBase::getCanonicalType() {
10931093
return CanType(CT);
10941094

10951095
// Otherwise, compute and cache it.
1096-
TypeBase *Result = 0;
1096+
TypeBase *Result = nullptr;
10971097
switch (getKind()) {
10981098
#define ALWAYS_CANONICAL_TYPE(id, parent) case TypeKind::id:
10991099
#define TYPE(id, parent)

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2712,7 +2712,7 @@ EffectiveClangContext ClangImporter::Implementation::getEffectiveClangContext(
27122712
clang::LookupResult lookupResult(sema, clangName,
27132713
clang::SourceLocation(),
27142714
clang::Sema::LookupOrdinaryName);
2715-
if (sema.LookupName(lookupResult, /*Scope=*/0)) {
2715+
if (sema.LookupName(lookupResult, /*Scope=*/nullptr)) {
27162716
// FIXME: Filter based on access path? C++ access control?
27172717
for (auto clangDecl : lookupResult) {
27182718
if (auto objcClass = dyn_cast<clang::ObjCInterfaceDecl>(clangDecl))

lib/ClangImporter/ImportType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,7 +2255,7 @@ Decl *ClangImporter::Implementation::importDeclByName(StringRef name) {
22552255
clang::LookupResult lookupResult(sema, clangName, clang::SourceLocation(),
22562256
clang::Sema::LookupOrdinaryName);
22572257
lookupResult.setAllowHidden(true);
2258-
if (!sema.LookupName(lookupResult, /*Scope=*/0)) {
2258+
if (!sema.LookupName(lookupResult, /*Scope=*/nullptr)) {
22592259
return nullptr;
22602260
}
22612261

@@ -2308,7 +2308,7 @@ static Type getNamedProtocolType(ClangImporter::Implementation &impl,
23082308
clang::LookupResult lookupResult(sema, clangName, clang::SourceLocation(),
23092309
clang::Sema::LookupObjCProtocolName);
23102310
lookupResult.setAllowHidden(true);
2311-
if (!sema.LookupName(lookupResult, /*Scope=*/0))
2311+
if (!sema.LookupName(lookupResult, /*Scope=*/nullptr))
23122312
return Type();
23132313

23142314
for (auto decl : lookupResult) {

lib/Driver/Compilation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ int Compilation::performSingleCommand(const Job *Cmd) {
723723
SmallVector<const char *, 128> Argv;
724724
Argv.push_back(Cmd->getExecutable());
725725
Argv.append(Cmd->getArguments().begin(), Cmd->getArguments().end());
726-
Argv.push_back(0);
726+
Argv.push_back(nullptr);
727727

728728
const char *ExecPath = Cmd->getExecutable();
729729
const char **argv = Argv.data();

lib/Frontend/SerializedDiagnosticConsumer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class SerializedDiagnosticConsumer : public DiagnosticConsumer {
145145
// Write the generated bitstream to "Out".
146146
State->OS->write((char *)&State->Buffer.front(), State->Buffer.size());
147147
State->OS->flush();
148-
State->OS.reset(0);
148+
State->OS.reset(nullptr);
149149
}
150150

151151
virtual void handleDiagnostic(SourceManager &SM, SourceLoc Loc,
@@ -303,7 +303,7 @@ static void emitBlockID(unsigned ID, const char *Name,
303303
Stream.EmitRecord(llvm::bitc::BLOCKINFO_CODE_SETBID, Record);
304304

305305
// Emit the block name if present.
306-
if (Name == 0 || Name[0] == 0)
306+
if (Name == nullptr || Name[0] == 0)
307307
return;
308308

309309
Record.clear();

lib/IDE/TypeReconstruction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static bool FindFirstNamedDeclWithKind(
482482
name_ident, ast->getIdentifier(priv_decl_id.getValue().c_str()),
483483
decls);
484484
else
485-
result._module.lookupQualified(name_ident, NLOptions(), NULL, decls);
485+
result._module.lookupQualified(name_ident, NLOptions(), nullptr, decls);
486486
if (!decls.empty()) {
487487
bool check_type_aliases = false;
488488
// Look for an exact match first
@@ -1854,7 +1854,7 @@ static void VisitNodeTupleElement(
18541854
ASTContext *ast, std::vector<Demangle::NodePointer> &nodes,
18551855
Demangle::NodePointer &cur_node, VisitNodeResult &result,
18561856
const VisitNodeResult &generic_context) { // set by GenericType case
1857-
const char *tuple_name = NULL;
1857+
const char *tuple_name = nullptr;
18581858
VisitNodeResult tuple_type_result;
18591859
Demangle::Node::iterator end = cur_node->end();
18601860
for (Demangle::Node::iterator pos = cur_node->begin(); pos != end; ++pos) {
@@ -1896,7 +1896,7 @@ static void VisitNodeTypeList(
18961896
VisitNode(ast, nodes, type_result, generic_context);
18971897
if (type_result._error.empty() && type_result._types.size() == 1) {
18981898
if (type_result._decls.empty())
1899-
result._decls.push_back(NULL);
1899+
result._decls.push_back(nullptr);
19001900
else
19011901
result._decls.push_back(type_result._decls.front());
19021902
result._types.push_back(type_result._types.front());

lib/IRGen/GenClangType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ static clang::CanQualType getClangSelectorType(
9494
static clang::CanQualType getClangMetatypeType(
9595
const clang::ASTContext &clangCtx) {
9696
clang::QualType clangType =
97-
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinClassTy, 0, 0);
97+
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinClassTy, nullptr, 0);
9898
clangType = clangCtx.getObjCObjectPointerType(clangType);
9999
return clangCtx.getCanonicalType(clangType);
100100
}
101101

102102
static clang::CanQualType getClangIdType(
103103
const clang::ASTContext &clangCtx) {
104104
clang::QualType clangType =
105-
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinIdTy, 0, 0);
105+
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinIdTy, nullptr, 0);
106106
clangType = clangCtx.getObjCObjectPointerType(clangType);
107107
return clangCtx.getCanonicalType(clangType);
108108
}

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ void IRGenDebugInfo::setEntryPointLoc(IRBuilder &Builder) {
362362
}
363363

364364
llvm::DIScope *IRGenDebugInfo::getOrCreateScope(const SILDebugScope *DS) {
365-
if (DS == 0)
365+
if (DS == nullptr)
366366
return MainFile;
367367

368368
// Try to find it in the cache first.

0 commit comments

Comments
 (0)