Skip to content

More clang tidy fixes #6121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 35 additions & 46 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ void ASTContext::setLazyResolver(LazyResolver *resolver) {
/// specified string.
Identifier ASTContext::getIdentifier(StringRef Str) const {
// Make sure null pointers stay null.
if (Str.data() == nullptr) return Identifier(0);
if (Str.data() == nullptr)
return Identifier(nullptr);

auto I = Impl.IdentifierTable.insert(std::make_pair(Str, char())).first;
return Identifier(I->getKeyData());
Expand Down Expand Up @@ -2421,7 +2422,7 @@ Type ErrorType::get(Type originalType) {
BuiltinIntegerType *BuiltinIntegerType::get(BuiltinIntegerWidth BitWidth,
const ASTContext &C) {
BuiltinIntegerType *&Result = C.Impl.IntegerTypes[BitWidth];
if (Result == 0)
if (Result == nullptr)
Result = new (C, AllocationArena::Permanent) BuiltinIntegerType(BitWidth,C);
return Result;
}
Expand Down Expand Up @@ -2451,7 +2452,7 @@ ParenType *ParenType::get(const ASTContext &C, Type underlying,
auto arena = getArena(properties);
ParenType *&Result =
C.Impl.getArena(arena).ParenTypes[{underlying, flags.toRaw()}];
if (Result == 0) {
if (Result == nullptr) {
Result = new (C, arena) ParenType(underlying, properties, flags);
}
return Result;
Expand Down Expand Up @@ -2485,8 +2486,7 @@ Type TupleType::get(ArrayRef<TupleTypeElt> Fields, const ASTContext &C) {

auto arena = getArena(properties);


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

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

TupleType *New = new (C, arena) TupleType(Fields, IsCanonical ? &C : 0,
properties);
TupleType *New =
new (C, arena) TupleType(Fields, IsCanonical ? &C : nullptr, properties);
C.Impl.getArena(arena).TupleTypes.InsertNode(New, InsertPos);
return New;
}
Expand All @@ -2525,7 +2525,7 @@ UnboundGenericType *UnboundGenericType::
get(GenericTypeDecl *TheDecl, Type Parent, const ASTContext &C) {
llvm::FoldingSetNodeID ID;
UnboundGenericType::Profile(ID, TheDecl, Parent);
void *InsertPos = 0;
void *InsertPos = nullptr;
RecursiveTypeProperties properties;
if (Parent) properties |= Parent->getRecursiveProperties();
auto arena = getArena(properties);
Expand Down Expand Up @@ -2581,7 +2581,7 @@ BoundGenericType *BoundGenericType::get(NominalTypeDecl *TheDecl,

auto arena = getArena(properties);

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

BoundGenericType *newType;
if (auto theClass = dyn_cast<ClassDecl>(TheDecl)) {
newType = new (C, arena) BoundGenericClassType(theClass, Parent, ArgsCopy,
IsCanonical ? &C : 0,
properties);
newType = new (C, arena) BoundGenericClassType(
theClass, Parent, ArgsCopy, IsCanonical ? &C : nullptr, properties);
} else if (auto theStruct = dyn_cast<StructDecl>(TheDecl)) {
newType = new (C, arena) BoundGenericStructType(theStruct, Parent, ArgsCopy,
IsCanonical ? &C : 0,
properties);
newType = new (C, arena) BoundGenericStructType(
theStruct, Parent, ArgsCopy, IsCanonical ? &C : nullptr, properties);
} else {
auto theEnum = cast<EnumDecl>(TheDecl);
newType = new (C, arena) BoundGenericEnumType(theEnum, Parent, ArgsCopy,
IsCanonical ? &C : 0,
properties);
newType = new (C, arena) BoundGenericEnumType(
theEnum, Parent, ArgsCopy, IsCanonical ? &C : nullptr, properties);
}
C.Impl.getArena(arena).BoundGenericTypes.InsertNode(newType, InsertPos);

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

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

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

void *insertPos = 0;
void *insertPos = nullptr;
if (auto classTy
= C.Impl.getArena(arena).ClassTypes.FindNodeOrInsertPos(id, insertPos))
return classTy;
Expand All @@ -2726,7 +2723,7 @@ void ClassType::Profile(llvm::FoldingSetNodeID &ID, ClassDecl *D, Type Parent) {
ProtocolCompositionType *
ProtocolCompositionType::build(const ASTContext &C, ArrayRef<Type> Protocols) {
// Check to see if we've already seen this protocol composition before.
void *InsertPos = 0;
void *InsertPos = nullptr;
llvm::FoldingSetNodeID ID;
ProtocolCompositionType::Profile(ID, Protocols);
if (ProtocolCompositionType *Result
Expand Down Expand Up @@ -2764,19 +2761,16 @@ ReferenceStorageType *ReferenceStorageType::get(Type T, Ownership ownership,
switch (ownership) {
case Ownership::Strong: llvm_unreachable("not possible");
case Ownership::Unowned:
return entry =
new (C, arena) UnownedStorageType(T, T->isCanonical() ? &C : 0,
properties);
return entry = new (C, arena) UnownedStorageType(
T, T->isCanonical() ? &C : nullptr, properties);
case Ownership::Weak:
assert(T->getAnyOptionalObjectType() &&
"object of weak storage type is not optional");
return entry =
new (C, arena) WeakStorageType(T, T->isCanonical() ? &C : 0,
properties);
return entry = new (C, arena)
WeakStorageType(T, T->isCanonical() ? &C : nullptr, properties);
case Ownership::Unmanaged:
return entry =
new (C, arena) UnmanagedStorageType(T, T->isCanonical() ? &C : 0,
properties);
return entry = new (C, arena) UnmanagedStorageType(
T, T->isCanonical() ? &C : nullptr, properties);
}
llvm_unreachable("bad ownership");
}
Expand Down Expand Up @@ -2807,9 +2801,8 @@ MetatypeType *MetatypeType::get(Type T, Optional<MetatypeRepresentation> Repr,
MetatypeType *&Entry = Ctx.Impl.getArena(arena).MetatypeTypes[{T, reprKey}];
if (Entry) return Entry;

return Entry = new (Ctx, arena) MetatypeType(T,
T->isCanonical() ? &Ctx : 0,
properties, Repr);
return Entry = new (Ctx, arena) MetatypeType(
T, T->isCanonical() ? &Ctx : nullptr, properties, Repr);
}

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

return entry = new (ctx, arena) ExistentialMetatypeType(T,
T->isCanonical() ? &ctx : 0,
properties, repr);
return entry = new (ctx, arena) ExistentialMetatypeType(
T, T->isCanonical() ? &ctx : nullptr, properties, repr);
}

ExistentialMetatypeType::ExistentialMetatypeType(Type T,
Expand Down Expand Up @@ -2945,14 +2937,11 @@ FunctionType *FunctionType::get(Type Input, Type Result,
FunctionType::FunctionType(Type input, Type output,
RecursiveTypeProperties properties,
const ExtInfo &Info)
: AnyFunctionType(TypeKind::Function,
(input->isCanonical() && output->isCanonical()) ?
&input->getASTContext() : 0,
input, output,
properties,
Info)
{ }

: AnyFunctionType(TypeKind::Function,
(input->isCanonical() && output->isCanonical())
? &input->getASTContext()
: nullptr,
input, output, properties, Info) {}

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

void *insertPos = 0;
void *insertPos = nullptr;
if (auto protoTy
= C.Impl.getArena(arena).ProtocolTypes.FindNodeOrInsertPos(id, insertPos))
return protoTy;
Expand Down
11 changes: 4 additions & 7 deletions lib/AST/ASTScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,14 +865,11 @@ ASTScope *ASTScope::createIfNeeded(const ASTScope *parent, Decl *decl) {
if (decl->isImplicit()) return nullptr;

// Accessors are always nested within their abstract storage declaration.
bool isAccessor = false;
if (auto func = dyn_cast<FuncDecl>(decl)) {
if (func->isAccessor()) {
isAccessor = true;
if (!parentDirectDescendedFromAbstractStorageDecl(
parent, func->getAccessorStorageDecl()))
return nullptr;
}
if (func->isAccessor() &&
!parentDirectDescendedFromAbstractStorageDecl(
parent, func->getAccessorStorageDecl()))
return nullptr;
}

ASTContext &ctx = decl->getASTContext();
Expand Down
4 changes: 2 additions & 2 deletions lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ struct BuiltinExtraInfoTy {
};

static const BuiltinExtraInfoTy BuiltinExtraInfo[] = {
{0},
{nullptr},
#define BUILTIN(Id, Name, Attrs) {Attrs},
#include "swift/AST/Builtins.def"
};

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

bool IntrinsicInfo::hasAttribute(llvm::Attribute::AttrKind Kind) const {
Expand Down
3 changes: 2 additions & 1 deletion lib/AST/Identifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ using namespace swift;


raw_ostream &llvm::operator<<(raw_ostream &OS, Identifier I) {
if (I.get() == 0) return OS << "_";
if (I.get() == nullptr)
return OS << "_";
return OS << I.get();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,8 @@ UnqualifiedLookup::UnqualifiedLookup(DeclName Name, DeclContext *DC,
// scope, and if so, whether this is a reference to one of them.
// FIXME: We should persist this information between lookups.
while (!DC->isModuleScopeContext()) {
ValueDecl *BaseDecl = 0;
ValueDecl *MetaBaseDecl = 0;
ValueDecl *BaseDecl = nullptr;
ValueDecl *MetaBaseDecl = nullptr;
GenericParamList *GenericParams = nullptr;
Type ExtendedType;
bool isTypeLookup = false;
Expand Down
8 changes: 4 additions & 4 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ void *TypeBase::operator new(size_t bytes, const ASTContext &ctx,
}

bool CanType::isActuallyCanonicalOrNull() const {
return getPointer() == 0 ||
getPointer() == llvm::DenseMapInfo<TypeBase*>::getTombstoneKey() ||
return getPointer() == nullptr ||
getPointer() == llvm::DenseMapInfo<TypeBase *>::getTombstoneKey() ||
getPointer()->isCanonical();
}

Expand Down Expand Up @@ -1056,7 +1056,7 @@ void ProtocolType::canonicalizeProtocols(
}

// We have seen this protocol before; zap this occurrence.
protocols[I] = 0;
protocols[I] = nullptr;
zappedAny = true;
}

Expand Down Expand Up @@ -1093,7 +1093,7 @@ CanType TypeBase::getCanonicalType() {
return CanType(CT);

// Otherwise, compute and cache it.
TypeBase *Result = 0;
TypeBase *Result = nullptr;
switch (getKind()) {
#define ALWAYS_CANONICAL_TYPE(id, parent) case TypeKind::id:
#define TYPE(id, parent)
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2712,7 +2712,7 @@ EffectiveClangContext ClangImporter::Implementation::getEffectiveClangContext(
clang::LookupResult lookupResult(sema, clangName,
clang::SourceLocation(),
clang::Sema::LookupOrdinaryName);
if (sema.LookupName(lookupResult, /*Scope=*/0)) {
if (sema.LookupName(lookupResult, /*Scope=*/nullptr)) {
// FIXME: Filter based on access path? C++ access control?
for (auto clangDecl : lookupResult) {
if (auto objcClass = dyn_cast<clang::ObjCInterfaceDecl>(clangDecl))
Expand Down
4 changes: 2 additions & 2 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,7 @@ Decl *ClangImporter::Implementation::importDeclByName(StringRef name) {
clang::LookupResult lookupResult(sema, clangName, clang::SourceLocation(),
clang::Sema::LookupOrdinaryName);
lookupResult.setAllowHidden(true);
if (!sema.LookupName(lookupResult, /*Scope=*/0)) {
if (!sema.LookupName(lookupResult, /*Scope=*/nullptr)) {
return nullptr;
}

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

for (auto decl : lookupResult) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ int Compilation::performSingleCommand(const Job *Cmd) {
SmallVector<const char *, 128> Argv;
Argv.push_back(Cmd->getExecutable());
Argv.append(Cmd->getArguments().begin(), Cmd->getArguments().end());
Argv.push_back(0);
Argv.push_back(nullptr);

const char *ExecPath = Cmd->getExecutable();
const char **argv = Argv.data();
Expand Down
4 changes: 2 additions & 2 deletions lib/Frontend/SerializedDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class SerializedDiagnosticConsumer : public DiagnosticConsumer {
// Write the generated bitstream to "Out".
State->OS->write((char *)&State->Buffer.front(), State->Buffer.size());
State->OS->flush();
State->OS.reset(0);
State->OS.reset(nullptr);
}

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

// Emit the block name if present.
if (Name == 0 || Name[0] == 0)
if (Name == nullptr || Name[0] == 0)
return;

Record.clear();
Expand Down
6 changes: 3 additions & 3 deletions lib/IDE/TypeReconstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static bool FindFirstNamedDeclWithKind(
name_ident, ast->getIdentifier(priv_decl_id.getValue().c_str()),
decls);
else
result._module.lookupQualified(name_ident, NLOptions(), NULL, decls);
result._module.lookupQualified(name_ident, NLOptions(), nullptr, decls);
if (!decls.empty()) {
bool check_type_aliases = false;
// Look for an exact match first
Expand Down Expand Up @@ -1854,7 +1854,7 @@ static void VisitNodeTupleElement(
ASTContext *ast, std::vector<Demangle::NodePointer> &nodes,
Demangle::NodePointer &cur_node, VisitNodeResult &result,
const VisitNodeResult &generic_context) { // set by GenericType case
const char *tuple_name = NULL;
const char *tuple_name = nullptr;
VisitNodeResult tuple_type_result;
Demangle::Node::iterator end = cur_node->end();
for (Demangle::Node::iterator pos = cur_node->begin(); pos != end; ++pos) {
Expand Down Expand Up @@ -1896,7 +1896,7 @@ static void VisitNodeTypeList(
VisitNode(ast, nodes, type_result, generic_context);
if (type_result._error.empty() && type_result._types.size() == 1) {
if (type_result._decls.empty())
result._decls.push_back(NULL);
result._decls.push_back(nullptr);
else
result._decls.push_back(type_result._decls.front());
result._types.push_back(type_result._types.front());
Expand Down
4 changes: 2 additions & 2 deletions lib/IRGen/GenClangType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ static clang::CanQualType getClangSelectorType(
static clang::CanQualType getClangMetatypeType(
const clang::ASTContext &clangCtx) {
clang::QualType clangType =
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinClassTy, 0, 0);
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinClassTy, nullptr, 0);
clangType = clangCtx.getObjCObjectPointerType(clangType);
return clangCtx.getCanonicalType(clangType);
}

static clang::CanQualType getClangIdType(
const clang::ASTContext &clangCtx) {
clang::QualType clangType =
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinIdTy, 0, 0);
clangCtx.getObjCObjectType(clangCtx.ObjCBuiltinIdTy, nullptr, 0);
clangType = clangCtx.getObjCObjectPointerType(clangType);
return clangCtx.getCanonicalType(clangType);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ void IRGenDebugInfo::setEntryPointLoc(IRBuilder &Builder) {
}

llvm::DIScope *IRGenDebugInfo::getOrCreateScope(const SILDebugScope *DS) {
if (DS == 0)
if (DS == nullptr)
return MainFile;

// Try to find it in the cache first.
Expand Down
Loading