Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 603e37c

Browse files
committed
[C++11] Use 'nullptr'.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208280 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 60efcfe commit 603e37c

12 files changed

+109
-110
lines changed

lib/Basic/Builtins.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
using namespace clang;
2121

2222
static const Builtin::Info BuiltinInfo[] = {
23-
{ "not a builtin function", 0, 0, 0, ALL_LANGUAGES },
23+
{ "not a builtin function", nullptr, nullptr, nullptr, ALL_LANGUAGES},
2424
#define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
2525
#define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) { #ID, TYPE, ATTRS, 0, BUILTIN_LANG },
2626
#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, BUILTIN_LANG) { #ID, TYPE, ATTRS, HEADER,\
@@ -37,7 +37,7 @@ const Builtin::Info &Builtin::Context::GetRecord(unsigned ID) const {
3737

3838
Builtin::Context::Context() {
3939
// Get the target specific builtins from the target.
40-
TSRecords = 0;
40+
TSRecords = nullptr;
4141
NumTSRecords = 0;
4242
}
4343

@@ -116,7 +116,7 @@ bool Builtin::Context::isLike(unsigned ID, unsigned &FormatIdx,
116116
++Like;
117117

118118
assert(::strchr(Like, ':') && "Format specifier must end with a ':'");
119-
FormatIdx = ::strtol(Like, 0, 10);
119+
FormatIdx = ::strtol(Like, nullptr, 10);
120120
return true;
121121
}
122122

lib/Basic/Diagnostic.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ DiagnosticsEngine::DiagnosticsEngine(
4141
DiagnosticOptions *DiagOpts,
4242
DiagnosticConsumer *client, bool ShouldOwnClient)
4343
: Diags(diags), DiagOpts(DiagOpts), Client(client),
44-
OwnsDiagClient(ShouldOwnClient), SourceMgr(0) {
44+
OwnsDiagClient(ShouldOwnClient), SourceMgr(nullptr) {
4545
ArgToStringFn = DummyArgToStringFn;
46-
ArgToStringCookie = 0;
46+
ArgToStringCookie = nullptr;
4747

4848
AllExtensionsSilenced = 0;
4949
IgnoreAllWarnings = false;
@@ -157,7 +157,7 @@ DiagnosticsEngine::GetDiagStatePointForLoc(SourceLocation L) const {
157157
if (LastStateChangePos.isValid() &&
158158
Loc.isBeforeInTranslationUnitThan(LastStateChangePos))
159159
Pos = std::upper_bound(DiagStatePoints.begin(), DiagStatePoints.end(),
160-
DiagStatePoint(0, Loc));
160+
DiagStatePoint(nullptr, Loc));
161161
--Pos;
162162
return Pos;
163163
}
@@ -612,7 +612,7 @@ static const char *getTokenDescForDiagnostic(tok::TokenKind Kind) {
612612
case tok::identifier:
613613
return "identifier";
614614
default:
615-
return 0;
615+
return nullptr;
616616
}
617617
}
618618

@@ -672,7 +672,7 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd,
672672
// The digit is a number from 0-9 indicating which argument this comes from.
673673
// The modifier is a string of digits from the set [-a-z]+, arguments is a
674674
// brace enclosed string.
675-
const char *Modifier = 0, *Argument = 0;
675+
const char *Modifier = nullptr, *Argument = nullptr;
676676
unsigned ModifierLen = 0, ArgumentLen = 0;
677677

678678
// Check to see if we have a modifier. If so eat it.

lib/Basic/DiagnosticIDs.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static const StaticDiagInfoRec *GetDiagInfo(unsigned DiagID) {
109109
// Out of bounds diag. Can't be in the table.
110110
using namespace diag;
111111
if (DiagID >= DIAG_UPPER_LIMIT || DiagID <= DIAG_START_COMMON)
112-
return 0;
112+
return nullptr;
113113

114114
// Compute the index of the requested diagnostic in the static table.
115115
// 1. Add the number of diagnostics in each category preceding the
@@ -139,7 +139,7 @@ CATEGORY(ANALYSIS, SEMA)
139139

140140
// Avoid out of bounds reads.
141141
if (ID + Offset >= StaticDiagInfoSize)
142-
return 0;
142+
return nullptr;
143143

144144
assert(ID < StaticDiagInfoSize && Offset < StaticDiagInfoSize);
145145

@@ -148,7 +148,7 @@ CATEGORY(ANALYSIS, SEMA)
148148
// happen when this function is called with an ID that points into a hole in
149149
// the diagID space.
150150
if (Found->DiagID != DiagID)
151-
return 0;
151+
return nullptr;
152152
return Found;
153153
}
154154

@@ -216,7 +216,7 @@ static const StaticDiagCategoryRec CategoryNameTable[] = {
216216
#define CATEGORY(X, ENUM) { X, STR_SIZE(X, uint8_t) },
217217
#include "clang/Basic/DiagnosticGroups.inc"
218218
#undef GET_CATEGORY_TABLE
219-
{ 0, 0 }
219+
{ nullptr, 0 }
220220
};
221221

222222
/// getNumberOfCategories - Return the number of categories
@@ -301,9 +301,7 @@ namespace clang {
301301
// Common Diagnostic implementation
302302
//===----------------------------------------------------------------------===//
303303

304-
DiagnosticIDs::DiagnosticIDs() {
305-
CustomDiagInfo = 0;
306-
}
304+
DiagnosticIDs::DiagnosticIDs() { CustomDiagInfo = nullptr; }
307305

308306
DiagnosticIDs::~DiagnosticIDs() {
309307
delete CustomDiagInfo;
@@ -316,7 +314,7 @@ DiagnosticIDs::~DiagnosticIDs() {
316314
/// \param FormatString A fixed diagnostic format string that will be hashed and
317315
/// mapped to a unique DiagID.
318316
unsigned DiagnosticIDs::getCustomDiagID(Level L, StringRef FormatString) {
319-
if (CustomDiagInfo == 0)
317+
if (!CustomDiagInfo)
320318
CustomDiagInfo = new diag::CustomDiagInfo();
321319
return CustomDiagInfo->getOrCreateDiagID(L, FormatString, *this);
322320
}

lib/Basic/FileManager.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ FileManager::~FileManager() {
7070
void FileManager::addStatCache(FileSystemStatCache *statCache,
7171
bool AtBeginning) {
7272
assert(statCache && "No stat cache provided?");
73-
if (AtBeginning || StatCache.get() == 0) {
73+
if (AtBeginning || !StatCache.get()) {
7474
statCache->setNextStatCache(StatCache.release());
7575
StatCache.reset(statCache);
7676
return;
@@ -103,7 +103,7 @@ void FileManager::removeStatCache(FileSystemStatCache *statCache) {
103103
}
104104

105105
void FileManager::clearStatCaches() {
106-
StatCache.reset(0);
106+
StatCache.reset(nullptr);
107107
}
108108

109109
/// \brief Retrieve the directory that the given file name resides in.
@@ -112,10 +112,10 @@ static const DirectoryEntry *getDirectoryFromFile(FileManager &FileMgr,
112112
StringRef Filename,
113113
bool CacheFailure) {
114114
if (Filename.empty())
115-
return NULL;
115+
return nullptr;
116116

117117
if (llvm::sys::path::is_separator(Filename[Filename.size() - 1]))
118-
return NULL; // If Filename is a directory.
118+
return nullptr; // If Filename is a directory.
119119

120120
StringRef DirName = llvm::sys::path::parent_path(Filename);
121121
// Use the current directory if file has no path component.
@@ -179,8 +179,8 @@ const DirectoryEntry *FileManager::getDirectory(StringRef DirName,
179179
// See if there was already an entry in the map. Note that the map
180180
// contains both virtual and real directories.
181181
if (NamedDirEnt.getValue())
182-
return NamedDirEnt.getValue() == NON_EXISTENT_DIR
183-
? 0 : NamedDirEnt.getValue();
182+
return NamedDirEnt.getValue() == NON_EXISTENT_DIR ? nullptr
183+
: NamedDirEnt.getValue();
184184

185185
++NumDirCacheMisses;
186186

@@ -193,11 +193,11 @@ const DirectoryEntry *FileManager::getDirectory(StringRef DirName,
193193

194194
// Check to see if the directory exists.
195195
FileData Data;
196-
if (getStatValue(InterndDirName, Data, false, 0 /*directory lookup*/)) {
196+
if (getStatValue(InterndDirName, Data, false, nullptr /*directory lookup*/)) {
197197
// There's no real directory at the given path.
198198
if (!CacheFailure)
199199
SeenDirEntries.erase(DirName);
200-
return 0;
200+
return nullptr;
201201
}
202202

203203
// It exists. See if we have already opened a directory with the
@@ -227,7 +227,7 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
227227
// See if there is already an entry in the map.
228228
if (NamedFileEnt.getValue())
229229
return NamedFileEnt.getValue() == NON_EXISTENT_FILE
230-
? 0 : NamedFileEnt.getValue();
230+
? nullptr : NamedFileEnt.getValue();
231231

232232
++NumFileCacheMisses;
233233

@@ -245,25 +245,25 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
245245
// without a 'sys' subdir will get a cached failure result.
246246
const DirectoryEntry *DirInfo = getDirectoryFromFile(*this, Filename,
247247
CacheFailure);
248-
if (DirInfo == 0) { // Directory doesn't exist, file can't exist.
248+
if (DirInfo == nullptr) { // Directory doesn't exist, file can't exist.
249249
if (!CacheFailure)
250250
SeenFileEntries.erase(Filename);
251-
252-
return 0;
251+
252+
return nullptr;
253253
}
254254

255255
// FIXME: Use the directory info to prune this, before doing the stat syscall.
256256
// FIXME: This will reduce the # syscalls.
257257

258258
// Nope, there isn't. Check to see if the file exists.
259-
vfs::File *F = 0;
259+
vfs::File *F = nullptr;
260260
FileData Data;
261-
if (getStatValue(InterndFileName, Data, true, openFile ? &F : 0)) {
261+
if (getStatValue(InterndFileName, Data, true, openFile ? &F : nullptr)) {
262262
// There's no real file at the given path.
263263
if (!CacheFailure)
264264
SeenFileEntries.erase(Filename);
265-
266-
return 0;
265+
266+
return nullptr;
267267
}
268268

269269
assert((openFile || !F) && "undesired open file");
@@ -314,7 +314,7 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size,
314314
NamedFileEnt.setValue(NON_EXISTENT_FILE);
315315

316316
addAncestorsAsVirtualDirs(Filename);
317-
FileEntry *UFE = 0;
317+
FileEntry *UFE = nullptr;
318318

319319
// Now that all ancestors of Filename are in the cache, the
320320
// following call is guaranteed to find the DirectoryEntry from the
@@ -327,7 +327,7 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size,
327327
// Check to see if the file exists. If so, drop the virtual file
328328
FileData Data;
329329
const char *InterndFileName = NamedFileEnt.getKeyData();
330-
if (getStatValue(InterndFileName, Data, true, 0) == 0) {
330+
if (getStatValue(InterndFileName, Data, true, nullptr) == 0) {
331331
Data.Size = Size;
332332
Data.ModTime = ModificationTime;
333333
UFE = &UniqueRealFiles[Data.UniqueID];

lib/Basic/FileSystemStatCache.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile,
9696
// fstat rarely fails. If it does, claim the initial open didn't
9797
// succeed.
9898
R = CacheMissing;
99-
*F = 0;
99+
*F = nullptr;
100100
}
101101
}
102102
}
@@ -110,7 +110,7 @@ bool FileSystemStatCache::get(const char *Path, FileData &Data, bool isFile,
110110
// If not, close the file if opened.
111111
if (F && *F) {
112112
(*F)->close();
113-
*F = 0;
113+
*F = nullptr;
114114
}
115115

116116
return true;

lib/Basic/IdentifierTable.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ IdentifierInfo::IdentifierInfo() {
4242
RevertedTokenID = false;
4343
OutOfDate = false;
4444
IsModulesImport = false;
45-
FETokenInfo = 0;
46-
Entry = 0;
45+
FETokenInfo = nullptr;
46+
Entry = nullptr;
4747
}
4848

4949
//===----------------------------------------------------------------------===//
@@ -527,7 +527,7 @@ Selector SelectorTable::getSelector(unsigned nKeys, IdentifierInfo **IIV) {
527527
llvm::FoldingSetNodeID ID;
528528
MultiKeywordSelector::Profile(ID, IIV, nKeys);
529529

530-
void *InsertPos = 0;
530+
void *InsertPos = nullptr;
531531
if (MultiKeywordSelector *SI =
532532
SelTabImpl.Table.FindNodeOrInsertPos(ID, InsertPos))
533533
return Selector(SI);
@@ -555,7 +555,7 @@ const char *clang::getOperatorSpelling(OverloadedOperatorKind Operator) {
555555
switch (Operator) {
556556
case OO_None:
557557
case NUM_OVERLOADED_OPERATORS:
558-
return 0;
558+
return nullptr;
559559

560560
#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
561561
case OO_##Name: return Spelling;

lib/Basic/Module.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ using namespace clang;
2727
Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent,
2828
const FileEntry *File, bool IsFramework, bool IsExplicit)
2929
: Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent), ModuleMap(File),
30-
Umbrella(), ASTFile(0), IsMissingRequirement(false), IsAvailable(true),
31-
IsFromModuleFile(false), IsFramework(IsFramework), IsExplicit(IsExplicit),
32-
IsSystem(false), IsExternC(false), IsInferred(false),
33-
InferSubmodules(false), InferExplicitSubmodules(false),
30+
Umbrella(), ASTFile(nullptr), IsMissingRequirement(false),
31+
IsAvailable(true), IsFromModuleFile(false), IsFramework(IsFramework),
32+
IsExplicit(IsExplicit), IsSystem(false), IsExternC(false),
33+
IsInferred(false), InferSubmodules(false), InferExplicitSubmodules(false),
3434
InferExportWildcard(false), ConfigMacrosExhaustive(false),
3535
NameVisibility(Hidden) {
3636
if (Parent) {
@@ -192,8 +192,8 @@ void Module::markUnavailable(bool MissingRequirement) {
192192
Module *Module::findSubmodule(StringRef Name) const {
193193
llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name);
194194
if (Pos == SubModuleIndex.end())
195-
return 0;
196-
195+
return nullptr;
196+
197197
return SubModules[Pos->getValue()];
198198
}
199199

0 commit comments

Comments
 (0)