Skip to content

Commit

Permalink
[clang-format][NFC] Clean up nullptr comparison style
Browse files Browse the repository at this point in the history
For example, use 'Next' instead of 'Next != nullptr',
and '!Next' instead of 'Next == nullptr'.

Differential Revision: https://reviews.llvm.org/D144355
  • Loading branch information
owenca committed Feb 21, 2023
1 parent 801bd32 commit 0ef289e
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion clang/lib/Format/AffectedRangeManager.cpp
Expand Up @@ -135,7 +135,7 @@ bool AffectedRangeManager::nonPPLineAffected(
Line->First->NewlinesBefore == 0;

bool IsContinuedComment =
Line->First->is(tok::comment) && Line->First->Next == nullptr &&
Line->First->is(tok::comment) && !Line->First->Next &&
Line->First->NewlinesBefore < 2 && PreviousLine &&
PreviousLine->Affected && PreviousLine->Last->is(tok::comment);

Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Format/ContinuationIndenter.cpp
Expand Up @@ -614,7 +614,7 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
State.NoContinuation = false;

if ((Current.is(TT_ImplicitStringLiteral) &&
(Previous.Tok.getIdentifierInfo() == nullptr ||
(!Previous.Tok.getIdentifierInfo() ||
Previous.Tok.getIdentifierInfo()->getPPKeywordID() ==
tok::pp_not_keyword))) {
unsigned EndColumn =
Expand Down Expand Up @@ -1750,11 +1750,11 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
NewState.BreakBeforeParameter = BreakBeforeParameter;
NewState.HasMultipleNestedBlocks = (Current.BlockParameterCount > 1);

if (Style.BraceWrapping.BeforeLambdaBody && Current.Next != nullptr &&
if (Style.BraceWrapping.BeforeLambdaBody && Current.Next &&
Current.is(tok::l_paren)) {
// Search for any parameter that is a lambda.
FormatToken const *next = Current.Next;
while (next != nullptr) {
while (next) {
if (next->is(TT_LambdaLSquare)) {
NewState.HasMultipleNestedBlocks = true;
break;
Expand Down Expand Up @@ -2169,7 +2169,7 @@ ContinuationIndenter::createBreakableToken(const FormatToken &Current,
Current, StartColumn, Current.OriginalColumn, !Current.Previous,
State.Line->InPPDirective, Encoding, Style, Whitespaces.useCRLF());
} else if (Current.is(TT_LineComment) &&
(Current.Previous == nullptr ||
(!Current.Previous ||
Current.Previous->isNot(TT_ImplicitStringLiteral))) {
bool RegularComments = [&]() {
for (const FormatToken *T = &Current; T && T->is(TT_LineComment);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/Format.cpp
Expand Up @@ -2454,7 +2454,7 @@ class Cleaner : public TokenAnalyzer {
}

bool containsOnlyComments(const AnnotatedLine &Line) {
for (FormatToken *Tok = Line.First; Tok != nullptr; Tok = Tok->Next)
for (FormatToken *Tok = Line.First; Tok; Tok = Tok->Next)
if (Tok->isNot(tok::comment))
return false;
return true;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/FormatToken.cpp
Expand Up @@ -96,7 +96,7 @@ void TokenRole::precomputeFormattingInfos(const FormatToken *Token) {}
unsigned CommaSeparatedList::formatAfterToken(LineState &State,
ContinuationIndenter *Indenter,
bool DryRun) {
if (State.NextToken == nullptr || !State.NextToken->Previous)
if (!State.NextToken || !State.NextToken->Previous)
return 0;

if (Formats.size() == 1)
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Format/FormatToken.h
Expand Up @@ -1556,7 +1556,7 @@ struct AdditionalKeywords {
/// Returns \c true if \p Tok is a keyword or an identifier.
bool isWordLike(const FormatToken &Tok) const {
// getIdentifierinfo returns non-null for keywords as well as identifiers.
return Tok.Tok.getIdentifierInfo() != nullptr &&
return Tok.Tok.getIdentifierInfo() &&
!Tok.isOneOf(kw_verilogHash, kw_verilogHashHash, kw_apostrophe);
}

Expand Down Expand Up @@ -1719,7 +1719,7 @@ struct AdditionalKeywords {
VerilogExtraKeywords.end();
default:
// getIdentifierInfo returns non-null for both identifiers and keywords.
return Tok.Tok.getIdentifierInfo() != nullptr;
return Tok.Tok.getIdentifierInfo();
}
}

Expand Down
16 changes: 8 additions & 8 deletions clang/lib/Format/TokenAnnotator.cpp
Expand Up @@ -45,7 +45,7 @@ static bool startsWithInitStatement(const AnnotatedLine &Line) {
/// invokes @selector(...)). So, we allow treat any identifier or
/// keyword as a potential Objective-C selector component.
static bool canBeObjCSelectorComponent(const FormatToken &Tok) {
return Tok.Tok.getIdentifierInfo() != nullptr;
return Tok.Tok.getIdentifierInfo();
}

/// With `Left` being '(', check if we're at either `[...](` or
Expand Down Expand Up @@ -1314,7 +1314,7 @@ class AnnotatingParser {
Tok->Next->isNot(tok::l_paren)) {
Tok->setType(TT_CSharpGenericTypeConstraint);
parseCSharpGenericTypeConstraint();
if (Tok->getPreviousNonComment() == nullptr)
if (!Tok->getPreviousNonComment())
Line.IsContinuation = true;
}
break;
Expand Down Expand Up @@ -2975,7 +2975,7 @@ void TokenAnnotator::setCommentLineLevels(

static unsigned maxNestingDepth(const AnnotatedLine &Line) {
unsigned Result = 0;
for (const auto *Tok = Line.First; Tok != nullptr; Tok = Tok->Next)
for (const auto *Tok = Line.First; Tok; Tok = Tok->Next)
Result = std::max(Result, Tok->NestingLevel);
return Result;
}
Expand Down Expand Up @@ -3291,7 +3291,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {

calculateUnbreakableTailLengths(Line);
unsigned IndentLevel = Line.Level;
for (Current = Line.First; Current != nullptr; Current = Current->Next) {
for (Current = Line.First; Current; Current = Current->Next) {
if (Current->Role)
Current->Role->precomputeFormattingInfos(Current);
if (Current->MatchingParen &&
Expand Down Expand Up @@ -3331,10 +3331,10 @@ void TokenAnnotator::calculateArrayInitializerColumnList(
auto *CurrentToken = Line.First;
CurrentToken->ArrayInitializerLineStart = true;
unsigned Depth = 0;
while (CurrentToken != nullptr && CurrentToken != Line.Last) {
while (CurrentToken && CurrentToken != Line.Last) {
if (CurrentToken->is(tok::l_brace)) {
CurrentToken->IsArrayInitializer = true;
if (CurrentToken->Next != nullptr)
if (CurrentToken->Next)
CurrentToken->Next->MustBreakBefore = true;
CurrentToken =
calculateInitializerColumnList(Line, CurrentToken->Next, Depth + 1);
Expand All @@ -3346,14 +3346,14 @@ void TokenAnnotator::calculateArrayInitializerColumnList(

FormatToken *TokenAnnotator::calculateInitializerColumnList(
AnnotatedLine &Line, FormatToken *CurrentToken, unsigned Depth) const {
while (CurrentToken != nullptr && CurrentToken != Line.Last) {
while (CurrentToken && CurrentToken != Line.Last) {
if (CurrentToken->is(tok::l_brace))
++Depth;
else if (CurrentToken->is(tok::r_brace))
--Depth;
if (Depth == 2 && CurrentToken->isOneOf(tok::l_brace, tok::comma)) {
CurrentToken = CurrentToken->Next;
if (CurrentToken == nullptr)
if (!CurrentToken)
break;
CurrentToken->StartsColumn = true;
CurrentToken = CurrentToken->Previous;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/UnwrappedLineFormatter.cpp
Expand Up @@ -1435,7 +1435,7 @@ void UnwrappedLineFormatter::formatFirstToken(
Newlines = std::min(Newlines, 1u);
}
// Remove empty lines at the start of nested blocks (lambdas/arrow functions)
if (PreviousLine == nullptr && Line.Level > 0)
if (!PreviousLine && Line.Level > 0)
Newlines = std::min(Newlines, 1u);
if (Newlines == 0 && !RootToken.IsFirst)
Newlines = 1;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/UnwrappedLineParser.cpp
Expand Up @@ -1166,7 +1166,7 @@ static bool mustBeJSIdent(const AdditionalKeywords &Keywords,
const FormatToken *FormatTok) {
// FIXME: This returns true for C/C++ keywords like 'struct'.
return FormatTok->is(tok::identifier) &&
(FormatTok->Tok.getIdentifierInfo() == nullptr ||
(!FormatTok->Tok.getIdentifierInfo() ||
!FormatTok->isOneOf(
Keywords.kw_in, Keywords.kw_of, Keywords.kw_as, Keywords.kw_async,
Keywords.kw_await, Keywords.kw_yield, Keywords.kw_finally,
Expand Down
11 changes: 5 additions & 6 deletions clang/lib/Format/WhitespaceManager.cpp
Expand Up @@ -1172,7 +1172,7 @@ void WhitespaceManager::alignArrayInitializersRightJustified(
Changes[CellIter->Index].Spaces = (MaxNetWidth - ThisNetWidth);
auto RowCount = 1U;
auto Offset = std::distance(Cells.begin(), CellIter);
for (const auto *Next = CellIter->NextColumnElement; Next != nullptr;
for (const auto *Next = CellIter->NextColumnElement; Next;
Next = Next->NextColumnElement) {
auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]);
auto *End = Start + Offset;
Expand All @@ -1191,7 +1191,7 @@ void WhitespaceManager::alignArrayInitializersRightJustified(
Changes[CellIter->Index].Spaces += (i > 0) ? 1 : 0;
}
alignToStartOfCell(CellIter->Index, CellIter->EndIndex);
for (const auto *Next = CellIter->NextColumnElement; Next != nullptr;
for (const auto *Next = CellIter->NextColumnElement; Next;
Next = Next->NextColumnElement) {
ThisWidth =
calculateCellWidth(Next->Index, Next->EndIndex, true) + NetWidth;
Expand Down Expand Up @@ -1233,7 +1233,7 @@ void WhitespaceManager::alignArrayInitializersLeftJustified(
}
auto RowCount = 1U;
auto Offset = std::distance(Cells.begin(), CellIter);
for (const auto *Next = CellIter->NextColumnElement; Next != nullptr;
for (const auto *Next = CellIter->NextColumnElement; Next;
Next = Next->NextColumnElement) {
if (RowCount > CellDescs.CellCounts.size())
break;
Expand All @@ -1253,7 +1253,7 @@ void WhitespaceManager::alignArrayInitializersLeftJustified(
bool WhitespaceManager::isSplitCell(const CellDescription &Cell) {
if (Cell.HasSplit)
return true;
for (const auto *Next = Cell.NextColumnElement; Next != nullptr;
for (const auto *Next = Cell.NextColumnElement; Next;
Next = Next->NextColumnElement) {
if (Next->HasSplit)
return true;
Expand Down Expand Up @@ -1406,8 +1406,7 @@ WhitespaceManager::CellDescriptions
WhitespaceManager::linkCells(CellDescriptions &&CellDesc) {
auto &Cells = CellDesc.Cells;
for (auto *CellIter = Cells.begin(); CellIter != Cells.end(); ++CellIter) {
if (CellIter->NextColumnElement == nullptr &&
((CellIter + 1) != Cells.end())) {
if (!CellIter->NextColumnElement && (CellIter + 1) != Cells.end()) {
for (auto *NextIter = CellIter + 1; NextIter != Cells.end(); ++NextIter) {
if (NextIter->Cell == CellIter->Cell) {
CellIter->NextColumnElement = &(*NextIter);
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Format/WhitespaceManager.h
Expand Up @@ -294,7 +294,7 @@ class WhitespaceManager {
calculateCellWidth(CellIter->Index, CellIter->EndIndex, true);
if (Changes[CellIter->Index].NewlinesBefore == 0)
CellWidth += NetWidth;
for (const auto *Next = CellIter->NextColumnElement; Next != nullptr;
for (const auto *Next = CellIter->NextColumnElement; Next;
Next = Next->NextColumnElement) {
auto ThisWidth = calculateCellWidth(Next->Index, Next->EndIndex, true);
if (Changes[Next->Index].NewlinesBefore == 0)
Expand All @@ -312,7 +312,7 @@ class WhitespaceManager {
auto MaxNetWidth = getNetWidth(CellStart, CellStop, InitialSpaces);
auto RowCount = 1U;
auto Offset = std::distance(CellStart, CellStop);
for (const auto *Next = CellStop->NextColumnElement; Next != nullptr;
for (const auto *Next = CellStop->NextColumnElement; Next;
Next = Next->NextColumnElement) {
if (RowCount > MaxRowCount)
break;
Expand Down

0 comments on commit 0ef289e

Please sign in to comment.