Skip to content
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
2 changes: 1 addition & 1 deletion clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3582,7 +3582,7 @@ tooling::Replacements sortJavaImports(const FormatStyle &Style, StringRef Code,
ImportsInBlock.push_back(
{Identifier, Line, Prev, AssociatedCommentLines, IsStatic});
AssociatedCommentLines.clear();
} else if (Trimmed.size() > 0 && !ImportsInBlock.empty()) {
} else if (!Trimmed.empty() && !ImportsInBlock.empty()) {
// Associating comments within the imports with the nearest import below
AssociatedCommentLines.push_back(Line);
}
Expand Down
11 changes: 5 additions & 6 deletions clang/lib/Format/FormatTokenLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,8 +1371,7 @@ FormatToken *FormatTokenLexer::getNextToken() {
} else if (FormatTok->TokenText == "``") {
FormatTok->Tok.setIdentifierInfo(nullptr);
FormatTok->Tok.setKind(tok::hashhash);
} else if (Tokens.size() > 0 &&
Tokens.back()->is(Keywords.kw_apostrophe) &&
} else if (!Tokens.empty() && Tokens.back()->is(Keywords.kw_apostrophe) &&
NumberBase.match(FormatTok->TokenText, &Matches)) {
// In Verilog in a based number literal like `'b10`, there may be
// whitespace between `'b` and `10`. Therefore we handle the base and
Expand Down Expand Up @@ -1420,7 +1419,7 @@ FormatToken *FormatTokenLexer::getNextToken() {
tryParseJavaTextBlock();
}

if (Style.isVerilog() && Tokens.size() > 0 &&
if (Style.isVerilog() && !Tokens.empty() &&
Tokens.back()->is(TT_VerilogNumberBase) &&
FormatTok->Tok.isOneOf(tok::identifier, tok::question)) {
// Mark the number following a base like `'h?a0` as a number.
Expand Down Expand Up @@ -1454,9 +1453,9 @@ FormatToken *FormatTokenLexer::getNextToken() {
if (Style.isCpp()) {
auto *Identifier = FormatTok->Tok.getIdentifierInfo();
auto it = Macros.find(Identifier);
if (!(Tokens.size() > 0 && Tokens.back()->Tok.getIdentifierInfo() &&
Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() ==
tok::pp_define) &&
if ((Tokens.empty() || !Tokens.back()->Tok.getIdentifierInfo() ||
Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() !=
tok::pp_define) &&
it != Macros.end()) {
FormatTok->setType(it->second);
if (it->second == TT_IfMacro) {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Format/QualifierAlignmentFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ bool isPossibleMacro(const FormatToken *Tok) {
return false;

const auto Text = Tok->TokenText;
assert(Text.size() > 0);
assert(!Text.empty());

// T,K,U,V likely could be template arguments
if (Text.size() == 1)
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Format/UnwrappedLineFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ class LineJoiner {
tryFitMultipleLinesInOne(LevelIndentTracker &IndentTracker,
ArrayRef<AnnotatedLine *>::const_iterator I,
ArrayRef<AnnotatedLine *>::const_iterator E) {
const unsigned Indent = IndentTracker.getIndent();

// Can't join the last line with anything.
if (I + 1 == E)
return 0;
Expand All @@ -240,6 +238,7 @@ class LineJoiner {
return 0;
}

const auto Indent = IndentTracker.getIndent();
if (Style.ColumnLimit > 0 && Indent > Style.ColumnLimit)
return 0;

Expand Down Expand Up @@ -1090,7 +1089,7 @@ class LineFormatter {
const FormatToken *LBrace = State.NextToken->getPreviousNonComment();
bool HasLBrace = LBrace && LBrace->is(tok::l_brace) && LBrace->is(BK_Block);
FormatToken &Previous = *State.NextToken->Previous;
if (Previous.Children.size() == 0 || (!HasLBrace && !LBrace->MacroParent)) {
if (Previous.Children.empty() || (!HasLBrace && !LBrace->MacroParent)) {
// The previous token does not open a block. Nothing to do. We don't
// assert so that we can simply call this function for all tokens.
return true;
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Format/WhitespaceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,

for (unsigned i = Start; i != End; ++i) {
auto &CurrentChange = Changes[i];
if (ScopeStack.size() != 0 &&
if (!ScopeStack.empty() &&
CurrentChange.indentAndNestingLevel() <
Changes[ScopeStack.back()].indentAndNestingLevel()) {
ScopeStack.pop_back();
Expand All @@ -332,7 +332,7 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
ScopeStack.push_back(i);
}

bool InsideNestedScope = ScopeStack.size() != 0;
bool InsideNestedScope = !ScopeStack.empty();
bool ContinuedStringLiteral = i > Start &&
CurrentChange.Tok->is(tok::string_literal) &&
Changes[i - 1].Tok->is(tok::string_literal);
Expand Down Expand Up @@ -1048,7 +1048,7 @@ void WhitespaceManager::alignChainedConditionals() {
return C.Tok->is(TT_ConditionalExpr) &&
((C.Tok->is(tok::question) && !C.NewlinesBefore) ||
(C.Tok->is(tok::colon) && C.Tok->Next &&
(C.Tok->Next->FakeLParens.size() == 0 ||
(C.Tok->Next->FakeLParens.empty() ||
C.Tok->Next->FakeLParens.back() != prec::Conditional)));
},
Changes, /*StartAt=*/0);
Expand All @@ -1057,7 +1057,7 @@ void WhitespaceManager::alignChainedConditionals() {
FormatToken *Previous = C.Tok->getPreviousNonComment();
return C.NewlinesBefore && Previous && Previous->is(TT_ConditionalExpr) &&
(Previous->is(tok::colon) &&
(C.Tok->FakeLParens.size() == 0 ||
(C.Tok->FakeLParens.empty() ||
C.Tok->FakeLParens.back() != prec::Conditional));
};
// Ensure we keep alignment of wrapped operands with non-wrapped operands
Expand Down
Loading