diff options
author | Craig Topper <craig.topper@gmail.com> | 2014-05-09 08:15:10 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2014-05-09 08:15:10 +0000 |
commit | 2145bc02291df82c182dedf38293c355c99ed869 (patch) | |
tree | d06e3d6ed185ee90afd7331f9a717fa48c28718b /clang/lib/Format | |
parent | 2fc43a38213ed8dce70ccf16244c9800e38eae41 (diff) | |
download | bcm5719-llvm-2145bc02291df82c182dedf38293c355c99ed869.tar.gz bcm5719-llvm-2145bc02291df82c182dedf38293c355c99ed869.zip |
[C++11] Use 'nullptr'.
llvm-svn: 208392
Diffstat (limited to 'clang/lib/Format')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Format/Format.cpp | 31 | ||||
-rw-r--r-- | clang/lib/Format/FormatToken.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Format/FormatToken.h | 6 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 110 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.h | 4 | ||||
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.h | 2 |
8 files changed, 88 insertions, 87 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 9b8880ac34e..5c2bdc52171 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -29,7 +29,7 @@ namespace format { // Returns the length of everything up to the first possible line break after // the ), ], } or > matching \c Tok. static unsigned getLengthToMatchingParen(const FormatToken &Tok) { - if (Tok.MatchingParen == NULL) + if (!Tok.MatchingParen) return 0; FormatToken *End = Tok.MatchingParen; while (End->Next && !End->Next->CanBreakBefore) { @@ -220,7 +220,7 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline, assert(!State.Stack.empty()); if ((Current.Type == TT_ImplicitStringLiteral && - (Current.Previous->Tok.getIdentifierInfo() == NULL || + (Current.Previous->Tok.getIdentifierInfo() == nullptr || Current.Previous->Tok.getIdentifierInfo()->getPPKeywordID() == tok::pp_not_keyword))) { // FIXME: Is this correct? @@ -916,7 +916,7 @@ unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current, Current, State.Line->Level, StartColumn, Current.OriginalColumn, !Current.Previous, State.Line->InPPDirective, Encoding, Style)); } else if (Current.Type == TT_LineComment && - (Current.Previous == NULL || + (Current.Previous == nullptr || Current.Previous->Type != TT_ImplicitStringLiteral)) { if (CommentPragmasRegex.match(Current.TokenText.substr(2))) return 0; diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 56af0cdfb84..d72556debd4 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -495,7 +495,7 @@ public: void format(unsigned FirstIndent, const AnnotatedLine *Line) { LineState State = Indenter->getInitialState(FirstIndent, Line, /*DryRun=*/false); - while (State.NextToken != NULL) { + while (State.NextToken) { bool Newline = Indenter->mustBreak(State) || (Indenter->canBreak(State) && State.NextToken->NewlinesBefore > 0); @@ -647,7 +647,7 @@ private: FormatToken *Tok = I[1]->First; if (Tok->is(tok::r_brace) && !Tok->MustBreakBefore && - (Tok->getNextNonComment() == NULL || + (Tok->getNextNonComment() == nullptr || Tok->getNextNonComment()->is(tok::semi))) { // We merge empty blocks even if the line exceeds the column limit. Tok->SpacesRequiredBefore = 0; @@ -674,7 +674,7 @@ private: if (Tok->isOneOf(tok::l_brace, tok::r_brace)) return 0; Tok = Tok->Next; - } while (Tok != NULL); + } while (Tok); // Last, check that the third line starts with a closing brace. Tok = I[2]->First; @@ -739,7 +739,7 @@ public: std::vector<int> IndentForLevel; for (unsigned i = 0, e = Lines[0]->Level; i != e; ++i) IndentForLevel.push_back(Style.IndentWidth * i + AdditionalIndent); - const AnnotatedLine *PreviousLine = NULL; + const AnnotatedLine *PreviousLine = nullptr; for (SmallVectorImpl<AnnotatedLine *>::const_iterator I = Lines.begin(), E = Lines.end(); I != E; ++I) { @@ -808,7 +808,7 @@ public: if (TheLine.Last->TotalLength + Indent <= ColumnLimit) { LineState State = Indenter->getInitialState(Indent, &TheLine, DryRun); - while (State.NextToken != NULL) + while (State.NextToken) Indenter->addTokenToState(State, /*Newline=*/false, DryRun); } else if (Style.ColumnLimit == 0) { // FIXME: Implement nested blocks for ColumnLimit = 0. @@ -826,7 +826,7 @@ public: } else { // Format the first token if necessary, and notify the WhitespaceManager // about the unchanged whitespace. - for (FormatToken *Tok = TheLine.First; Tok != NULL; Tok = Tok->Next) { + for (FormatToken *Tok = TheLine.First; Tok; Tok = Tok->Next) { if (Tok == TheLine.First && (Tok->NewlinesBefore > 0 || Tok->IsFirst)) { unsigned LevelIndent = Tok->OriginalColumn; @@ -851,7 +851,7 @@ public: } } if (!DryRun) { - for (FormatToken *Tok = TheLine.First; Tok != NULL; Tok = Tok->Next) { + for (FormatToken *Tok = TheLine.First; Tok; Tok = Tok->Next) { Tok->Finalized = true; } } @@ -1001,7 +1001,7 @@ private: // Insert start element into queue. StateNode *Node = - new (Allocator.Allocate()) StateNode(InitialState, false, NULL); + new (Allocator.Allocate()) StateNode(InitialState, false, nullptr); Queue.push(QueueItem(OrderedPenalty(0, Count), Node)); ++Count; @@ -1011,7 +1011,7 @@ private: while (!Queue.empty()) { Penalty = Queue.top().first.first; StateNode *Node = Queue.top().second; - if (Node->State.NextToken == NULL) { + if (!Node->State.NextToken) { DEBUG(llvm::dbgs() << "\n---\nPenalty for line: " << Penalty << "\n"); break; } @@ -1182,9 +1182,9 @@ class FormatTokenLexer { public: FormatTokenLexer(Lexer &Lex, SourceManager &SourceMgr, FormatStyle &Style, encoding::Encoding Encoding) - : FormatTok(NULL), IsFirstToken(true), GreaterStashed(false), Column(0), - TrailingWhitespace(0), Lex(Lex), SourceMgr(SourceMgr), Style(Style), - IdentTable(getFormattingLangOpts()), Encoding(Encoding), + : FormatTok(nullptr), IsFirstToken(true), GreaterStashed(false), + Column(0), TrailingWhitespace(0), Lex(Lex), SourceMgr(SourceMgr), + Style(Style), IdentTable(getFormattingLangOpts()), Encoding(Encoding), FirstInLineIndex(0) { Lex.SetKeepWhitespaceMode(true); @@ -1643,7 +1643,7 @@ private: bool computeAffectedLines(SmallVectorImpl<AnnotatedLine *>::iterator I, SmallVectorImpl<AnnotatedLine *>::iterator E) { bool SomeLineAffected = false; - const AnnotatedLine *PreviousLine = NULL; + const AnnotatedLine *PreviousLine = nullptr; while (I != E) { AnnotatedLine *Line = *I; Line->LeadingEmptyLinesAffected = affectsLeadingEmptyLines(*Line->First); @@ -1714,8 +1714,9 @@ private: Line->First->NewlinesBefore == 0; bool IsContinuedComment = Line->First->is(tok::comment) && - Line->First->Next == NULL && - Line->First->NewlinesBefore < 2 && PreviousLine && + Line->First->Next == nullptr && + Line->First->NewlinesBefore < 2 && + PreviousLine && PreviousLine->Affected && PreviousLine->Last->is(tok::comment); diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index a7c003bc18a..5bc5acaebea 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -152,7 +152,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) { MustBreakBeforeItem.push_back(ItemBegin->MustBreakBefore); if (ItemBegin->is(tok::l_brace)) HasNestedBracedList = true; - const FormatToken *ItemEnd = NULL; + const FormatToken *ItemEnd = nullptr; if (i == Commas.size()) { ItemEnd = Token->MatchingParen; const FormatToken *NonCommentEnd = ItemEnd->getPreviousNonComment(); @@ -232,7 +232,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) { const CommaSeparatedList::ColumnFormat * CommaSeparatedList::getColumnFormat(unsigned RemainingCharacters) const { - const ColumnFormat *BestFormat = NULL; + const ColumnFormat *BestFormat = nullptr; for (SmallVector<ColumnFormat, 4>::const_reverse_iterator I = Formats.rbegin(), E = Formats.rend(); diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 056d4bdd1bb..a0214631844 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -109,7 +109,7 @@ struct FormatToken { StartsBinaryExpression(false), EndsBinaryExpression(false), OperatorIndex(0), LastOperator(false), PartOfMultiVariableDeclStmt(false), IsForEachMacro(false), - MatchingParen(NULL), Previous(NULL), Next(NULL), + MatchingParen(nullptr), Previous(nullptr), Next(nullptr), Decision(FD_Unformatted), Finalized(false) {} /// \brief The \c Token. @@ -354,7 +354,7 @@ struct FormatToken { /// \brief Returns the previous token ignoring comments. FormatToken *getPreviousNonComment() const { FormatToken *Tok = Previous; - while (Tok != NULL && Tok->is(tok::comment)) + while (Tok && Tok->is(tok::comment)) Tok = Tok->Previous; return Tok; } @@ -362,7 +362,7 @@ struct FormatToken { /// \brief Returns the next token ignoring comments. const FormatToken *getNextNonComment() const { const FormatToken *Tok = Next; - while (Tok != NULL && Tok->is(tok::comment)) + while (Tok && Tok->is(tok::comment)) Tok = Tok->Next; return Tok; } diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 2d94c7e6b2a..a3400cc6c5c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -41,7 +41,7 @@ public: private: bool parseAngle() { - if (CurrentToken == NULL) + if (!CurrentToken) return false; ScopedContextCreator ContextCreator(*this, tok::less, 10); FormatToken *Left = CurrentToken->Previous; @@ -49,9 +49,9 @@ private: // If there's a template keyword before the opening angle bracket, this is a // template parameter, not an argument. Contexts.back().InTemplateArgument = - Left->Previous != NULL && Left->Previous->Tok.isNot(tok::kw_template); + Left->Previous && Left->Previous->Tok.isNot(tok::kw_template); - while (CurrentToken != NULL) { + while (CurrentToken) { if (CurrentToken->is(tok::greater)) { Left->MatchingParen = CurrentToken; CurrentToken->MatchingParen = Left; @@ -85,7 +85,7 @@ private: } bool parseParens(bool LookForDecls = false) { - if (CurrentToken == NULL) + if (!CurrentToken) return false; ScopedContextCreator ContextCreator(*this, tok::l_paren, 1); @@ -141,7 +141,7 @@ private: bool MightBeFunctionType = CurrentToken->is(tok::star); bool HasMultipleLines = false; bool HasMultipleParametersOnALine = false; - while (CurrentToken != NULL) { + while (CurrentToken) { // LookForDecls is set when "if (" has been seen. Check for // 'identifier' '*' 'identifier' followed by not '=' -- this // '*' has to be a binary operator but determineStarAmpUsage() will @@ -175,7 +175,7 @@ private: if (StartsObjCMethodExpr) { CurrentToken->Type = TT_ObjCMethodExpr; - if (Contexts.back().FirstObjCSelectorName != NULL) { + if (Contexts.back().FirstObjCSelectorName) { Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName = Contexts.back().LongestObjCSelectorName; } @@ -243,7 +243,7 @@ private: Left->Type = TT_ArraySubscriptLSquare; } - while (CurrentToken != NULL) { + while (CurrentToken) { if (CurrentToken->is(tok::r_square)) { if (CurrentToken->Next && CurrentToken->Next->is(tok::l_paren) && Left->Type == TT_ObjCMethodExpr) { @@ -257,12 +257,12 @@ private: // determineStarAmpUsage() thinks that '*' '[' is allocating an // array of pointers, but if '[' starts a selector then '*' is a // binary operator. - if (Parent != NULL && Parent->Type == TT_PointerOrReference) + if (Parent && Parent->Type == TT_PointerOrReference) Parent->Type = TT_BinaryOperator; } Left->MatchingParen = CurrentToken; CurrentToken->MatchingParen = Left; - if (Contexts.back().FirstObjCSelectorName != NULL) { + if (Contexts.back().FirstObjCSelectorName) { Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName = Contexts.back().LongestObjCSelectorName; if (Contexts.back().NumBlockParameters > 1) @@ -288,7 +288,7 @@ private: } bool parseBrace() { - if (CurrentToken != NULL) { + if (CurrentToken) { FormatToken *Left = CurrentToken->Previous; if (Contexts.back().CaretFound) @@ -298,7 +298,7 @@ private: ScopedContextCreator ContextCreator(*this, tok::l_brace, 1); Contexts.back().ColonIsDictLiteral = true; - while (CurrentToken != NULL) { + while (CurrentToken) { if (CurrentToken->is(tok::r_brace)) { Left->MatchingParen = CurrentToken; CurrentToken->MatchingParen = Left; @@ -332,7 +332,7 @@ private: } bool parseConditional() { - while (CurrentToken != NULL) { + while (CurrentToken) { if (CurrentToken->is(tok::colon)) { CurrentToken->Type = TT_ConditionalExpr; next(); @@ -345,12 +345,12 @@ private: } bool parseTemplateDeclaration() { - if (CurrentToken != NULL && CurrentToken->is(tok::less)) { + if (CurrentToken && CurrentToken->is(tok::less)) { CurrentToken->Type = TT_TemplateOpener; next(); if (!parseAngle()) return false; - if (CurrentToken != NULL) + if (CurrentToken) CurrentToken->Previous->ClosesTemplateDeclaration = true; return true; } @@ -363,11 +363,11 @@ private: switch (Tok->Tok.getKind()) { case tok::plus: case tok::minus: - if (Tok->Previous == NULL && Line.MustBeDeclaration) + if (!Tok->Previous && Line.MustBeDeclaration) Tok->Type = TT_ObjCMethodSpecifier; break; case tok::colon: - if (Tok->Previous == NULL) + if (!Tok->Previous) return false; // Colons from ?: are handled in parseConditional(). if (Tok->Previous->is(tok::r_paren) && Contexts.size() == 1 && @@ -383,11 +383,11 @@ private: Contexts.back().LongestObjCSelectorName) { Contexts.back().LongestObjCSelectorName = Tok->Previous->ColumnWidth; } - if (Contexts.back().FirstObjCSelectorName == NULL) + if (!Contexts.back().FirstObjCSelectorName) Contexts.back().FirstObjCSelectorName = Tok->Previous; } else if (Contexts.back().ColonIsForRangeExpr) { Tok->Type = TT_RangeBasedForLoopColon; - } else if (CurrentToken != NULL && + } else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) { Tok->Type = TT_BitFieldColon; } else if (Contexts.size() == 1 && Line.First->isNot(tok::kw_enum)) { @@ -398,7 +398,7 @@ private: break; case tok::kw_if: case tok::kw_while: - if (CurrentToken != NULL && CurrentToken->is(tok::l_paren)) { + if (CurrentToken && CurrentToken->is(tok::l_paren)) { next(); if (!parseParens(/*LookForDecls=*/true)) return false; @@ -441,7 +441,7 @@ private: return false; case tok::r_brace: // Lines can start with '}'. - if (Tok->Previous != NULL) + if (Tok->Previous) return false; break; case tok::greater: @@ -489,15 +489,15 @@ private: void parseIncludeDirective() { next(); - if (CurrentToken != NULL && CurrentToken->is(tok::less)) { + if (CurrentToken && CurrentToken->is(tok::less)) { next(); - while (CurrentToken != NULL) { + while (CurrentToken) { if (CurrentToken->isNot(tok::comment) || CurrentToken->Next) CurrentToken->Type = TT_ImplicitStringLiteral; next(); } } else { - while (CurrentToken != NULL) { + while (CurrentToken) { if (CurrentToken->is(tok::string_literal)) // Mark these string literals as "implicit" literals, too, so that // they are not split or line-wrapped. @@ -512,7 +512,7 @@ private: // We still want to format the whitespace left of the first token of the // warning or error. next(); - while (CurrentToken != NULL) { + while (CurrentToken) { CurrentToken->Type = TT_ImplicitStringLiteral; next(); } @@ -523,7 +523,7 @@ private: if (CurrentToken && CurrentToken->TokenText == "mark") { next(); // Consume "mark". next(); // Consume first token (so we fix leading whitespace). - while (CurrentToken != NULL) { + while (CurrentToken) { CurrentToken->Type = TT_ImplicitStringLiteral; next(); } @@ -532,7 +532,7 @@ private: void parsePreprocessorDirective() { next(); - if (CurrentToken == NULL) + if (!CurrentToken) return; if (CurrentToken->Tok.is(tok::numeric_constant)) { CurrentToken->SpacesRequiredBefore = 1; @@ -540,7 +540,7 @@ private: } // Hashes in the middle of a line can lead to any strange token // sequence. - if (CurrentToken->Tok.getIdentifierInfo() == NULL) + if (!CurrentToken->Tok.getIdentifierInfo()) return; switch (CurrentToken->Tok.getIdentifierInfo()->getPPKeywordID()) { case tok::pp_include: @@ -562,7 +562,7 @@ private: default: break; } - while (CurrentToken != NULL) + while (CurrentToken) next(); } @@ -581,7 +581,7 @@ public: CurrentToken->Next && CurrentToken->Next->is(tok::string_literal)) parseIncludeDirective(); - while (CurrentToken != NULL) { + while (CurrentToken) { if (CurrentToken->is(tok::kw_virtual)) KeywordVirtualFound = true; if (!consumeToken()) @@ -591,7 +591,7 @@ public: return LT_VirtualFunctionDecl; if (Line.First->Type == TT_ObjCMethodSpecifier) { - if (Contexts.back().FirstObjCSelectorName != NULL) + if (Contexts.back().FirstObjCSelectorName) Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName = Contexts.back().LongestObjCSelectorName; return LT_ObjCMethodDecl; @@ -602,7 +602,7 @@ public: private: void resetTokenMetadata(FormatToken *Token) { - if (Token == nullptr) return; + if (!Token) return; // Reset token type in case we have already looked at it and then // recovered from an error (e.g. failure to find the matching >). @@ -613,13 +613,13 @@ private: CurrentToken->Type != TT_TrailingReturnArrow) CurrentToken->Type = TT_Unknown; if (CurrentToken->Role) - CurrentToken->Role.reset(NULL); + CurrentToken->Role.reset(nullptr); CurrentToken->FakeLParens.clear(); CurrentToken->FakeRParens = 0; } void next() { - if (CurrentToken != NULL) { + if (CurrentToken) { determineTokenType(*CurrentToken); CurrentToken->BindingStrength = Contexts.back().BindingStrength; CurrentToken->NestingLevel = Contexts.size() - 1; @@ -637,8 +637,8 @@ private: : ContextKind(ContextKind), BindingStrength(BindingStrength), LongestObjCSelectorName(0), NumBlockParameters(0), ColonIsForRangeExpr(false), ColonIsDictLiteral(false), - ColonIsObjCMethodExpr(false), FirstObjCSelectorName(NULL), - FirstStartOfName(NULL), IsExpression(IsExpression), + ColonIsObjCMethodExpr(false), FirstObjCSelectorName(nullptr), + FirstStartOfName(nullptr), IsExpression(IsExpression), CanBeExpression(true), InTemplateArgument(false), InCtorInitializer(false), CaretFound(false), IsForEachMacro(false) {} @@ -794,15 +794,15 @@ private: /// This is a heuristic based on whether \p Tok is an identifier following /// something that is likely a type. bool isStartOfName(const FormatToken &Tok) { - if (Tok.isNot(tok::identifier) || Tok.Previous == NULL) + if (Tok.isNot(tok::identifier) || !Tok.Previous) return false; // Skip "const" as it does not have an influence on whether this is a name. FormatToken *PreviousNotConst = Tok.Previous; - while (PreviousNotConst != NULL && PreviousNotConst->is(tok::kw_const)) + while (PreviousNotConst && PreviousNotConst->is(tok::kw_const)) PreviousNotConst = PreviousNotConst->Previous; - if (PreviousNotConst == NULL) + if (!PreviousNotConst) return false; bool IsPPKeyword = PreviousNotConst->is(tok::identifier) && @@ -885,11 +885,11 @@ private: TokenType determineStarAmpUsage(const FormatToken &Tok, bool IsExpression, bool InTemplateArgument) { const FormatToken *PrevToken = Tok.getPreviousNonComment(); - if (PrevToken == NULL) + if (!PrevToken) return TT_UnaryOperator; const FormatToken *NextToken = Tok.getNextNonComment(); - if (NextToken == NULL) + if (!NextToken) return TT_Unknown; if (PrevToken->is(tok::coloncolon) || @@ -934,7 +934,7 @@ private: TokenType determinePlusMinusCaretUsage(const FormatToken &Tok) { const FormatToken *PrevToken = Tok.getPreviousNonComment(); - if (PrevToken == NULL || PrevToken->Type == TT_CastRParen) + if (!PrevToken || PrevToken->Type == TT_CastRParen) return TT_UnaryOperator; // Use heuristics to recognize unary operators. @@ -954,7 +954,7 @@ private: /// \brief Determine whether ++/-- are pre- or post-increments/-decrements. TokenType determineIncrementUsage(const FormatToken &Tok) { const FormatToken *PrevToken = Tok.getPreviousNonComment(); - if (PrevToken == NULL || PrevToken->Type == TT_CastRParen) + if (!PrevToken || PrevToken->Type == TT_CastRParen) return TT_UnaryOperator; if (PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::identifier)) return TT_TrailingUnaryOperator; @@ -995,7 +995,7 @@ public: (Current->is(tok::colon) && Current->Type == TT_ObjCMethodExpr))) next(); - if (Current == NULL || Precedence > PrecedenceArrowAndPeriod) + if (!Current || Precedence > PrecedenceArrowAndPeriod) return; // Conditional expressions need to be parsed separately for proper nesting. @@ -1012,7 +1012,7 @@ public: } FormatToken *Start = Current; - FormatToken *LatestOperator = NULL; + FormatToken *LatestOperator = nullptr; unsigned OperatorIndex = 0; while (Current) { @@ -1030,7 +1030,7 @@ public: // At the end of the line or when an operator with higher precedence is // found, insert fake parenthesis and return. - if (Current == NULL || Current->closesScope() || + if (!Current || Current->closesScope() || (CurrentPrecedence != -1 && CurrentPrecedence < Precedence)) { if (LatestOperator) { LatestOperator->LastOperator = true; @@ -1098,7 +1098,7 @@ private: /// \brief Parse unary operator expressions and surround them with fake /// parentheses if appropriate. void parseUnaryOperator() { - if (Current == NULL || Current->Type != TT_UnaryOperator) { + if (!Current || Current->Type != TT_UnaryOperator) { parse(PrecedenceArrowAndPeriod); return; } @@ -1139,15 +1139,15 @@ private: void TokenAnnotator::setCommentLineLevels(SmallVectorImpl<AnnotatedLine *> &Lines) { - const AnnotatedLine *NextNonCommentLine = NULL; + const AnnotatedLine *NextNonCommentLine = nullptr; for (SmallVectorImpl<AnnotatedLine *>::reverse_iterator I = Lines.rbegin(), E = Lines.rend(); I != E; ++I) { if (NextNonCommentLine && (*I)->First->is(tok::comment) && - (*I)->First->Next == NULL) + (*I)->First->Next == nullptr) (*I)->Level = NextNonCommentLine->Level; else - NextNonCommentLine = (*I)->First->isNot(tok::r_brace) ? (*I) : NULL; + NextNonCommentLine = (*I)->First->isNot(tok::r_brace) ? (*I) : nullptr; setCommentLineLevels((*I)->Children); } @@ -1185,7 +1185,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { return; FormatToken *Current = Line.First->Next; bool InFunctionDecl = Line.MightBeFunctionDecl; - while (Current != NULL) { + while (Current) { if (Current->Type == TT_LineComment) { if (Current->Previous->BlockKind == BK_BracedInit && Current->Previous->opensScope()) @@ -1244,7 +1244,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { } calculateUnbreakableTailLengths(Line); - for (Current = Line.First; Current != NULL; Current = Current->Next) { + for (Current = Line.First; Current != nullptr; Current = Current->Next) { if (Current->Role) Current->Role->precomputeFormattingInfos(Current); } @@ -1261,7 +1261,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { void TokenAnnotator::calculateUnbreakableTailLengths(AnnotatedLine &Line) { unsigned UnbreakableTailLength = 0; FormatToken *Current = Line.Last; - while (Current != NULL) { + while (Current) { Current->UnbreakableTailLength = UnbreakableTailLength; if (Current->CanBreakBefore || Current->isOneOf(tok::comment, tok::string_literal)) { @@ -1526,8 +1526,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, return false; if (Tok.is(tok::colon)) return !Line.First->isOneOf(tok::kw_case, tok::kw_default) && - Tok.getNextNonComment() != NULL && Tok.Type != TT_ObjCMethodExpr && - !Tok.Previous->is(tok::question) && + Tok.getNextNonComment() && + Tok.Type != TT_ObjCMethodExpr && !Tok.Previous->is(tok::question) && (Tok.Type != TT_DictLiteral || Style.SpacesInContainerLiterals); if (Tok.Previous->Type == TT_UnaryOperator || Tok.Previous->Type == TT_CastRParen) @@ -1734,7 +1734,7 @@ void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) { for (unsigned i = 0, e = Tok->FakeLParens.size(); i != e; ++i) llvm::errs() << Tok->FakeLParens[i] << "/"; llvm::errs() << " FakeRParens=" << Tok->FakeRParens << "\n"; - if (Tok->Next == NULL) + if (Tok->Next) assert(Tok == Line.Last); Tok = Tok->Next; } diff --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h index bd919805847..0df70a0d02c 100644 --- a/clang/lib/Format/TokenAnnotator.h +++ b/clang/lib/Format/TokenAnnotator.h @@ -48,7 +48,7 @@ public: // Calculate Next and Previous for all tokens. Note that we must overwrite // Next and Previous for every token, as previous formatting runs might have // left them in a different state. - First->Previous = NULL; + First->Previous = nullptr; FormatToken *Current = First; for (std::list<UnwrappedLineNode>::const_iterator I = ++Line.Tokens.begin(), E = Line.Tokens.end(); @@ -67,7 +67,7 @@ public: } } Last = Current; - Last->Next = NULL; + Last->Next = nullptr; } ~AnnotatedLine() { diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index e229ff02f5b..b9b071bca8d 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -60,7 +60,7 @@ public: : Line(Line), TokenSource(TokenSource), ResetToken(ResetToken), PreviousLineLevel(Line.Level), PreviousTokenSource(TokenSource), StructuralError(StructuralError), - PreviousStructuralError(StructuralError), Token(NULL) { + PreviousStructuralError(StructuralError), Token(nullptr) { TokenSource = this; Line.Level = 0; Line.InPPDirective = true; @@ -207,15 +207,15 @@ private: UnwrappedLineParser::UnwrappedLineParser(const FormatStyle &Style, ArrayRef<FormatToken *> Tokens, UnwrappedLineConsumer &Callback) - : Line(new UnwrappedLine), MustBreakBeforeNextToken(false), - CurrentLines(&Lines), StructuralError(false), Style(Style), Tokens(NULL), - Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1) {} + : Line(new UnwrappedLine), MustBreakBeforeNextToken(false), + CurrentLines(&Lines), StructuralError(false), Style(Style), Tokens(nullptr), + Callback(Callback), AllTokens(Tokens), PPBranchLevel(-1) {} void UnwrappedLineParser::reset() { PPBranchLevel = -1; Line.reset(new UnwrappedLine); CommentsBeforeNextToken.clear(); - FormatTok = NULL; + FormatTok = nullptr; MustBreakBeforeNextToken = false; PreprocessorDirectives.clear(); CurrentLines = &Lines; @@ -452,7 +452,7 @@ void UnwrappedLineParser::parsePPDirective() { ScopedMacroState MacroState(*Line, Tokens, FormatTok, StructuralError); nextToken(); - if (FormatTok->Tok.getIdentifierInfo() == NULL) { + if (!FormatTok->Tok.getIdentifierInfo()) { parsePPUnknown(); return; } diff --git a/clang/lib/Format/UnwrappedLineParser.h b/clang/lib/Format/UnwrappedLineParser.h index 63898539b27..58099c9f511 100644 --- a/clang/lib/Format/UnwrappedLineParser.h +++ b/clang/lib/Format/UnwrappedLineParser.h @@ -201,7 +201,7 @@ private: }; struct UnwrappedLineNode { - UnwrappedLineNode() : Tok(NULL) {} + UnwrappedLineNode() : Tok(nullptr) {} UnwrappedLineNode(FormatToken *Tok) : Tok(Tok) {} FormatToken *Tok; |