ContentStartsOnNewline || (NewCode->find('\n') != std::string::npos);
if (IsMultiline) {
// Break before further function parameters on all levels.
- for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
- State.Stack[i].BreakBeforeParameter = true;
+ for (ParenState &Paren : State.Stack)
+ Paren.BreakBeforeParameter = true;
}
return Fixes.second + PrefixExcessCharacters * Style.PenaltyExcessCharacter;
}
unsigned ContinuationIndenter::addMultilineToken(const FormatToken &Current,
LineState &State) {
// Break before further function parameters on all levels.
- for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
- State.Stack[i].BreakBeforeParameter = true;
+ for (ParenState &Paren : State.Stack)
+ Paren.BreakBeforeParameter = true;
unsigned ColumnsUsed = State.Column;
// We can only affect layout of the first and the last line, so the penalty
// the next parameter on all levels, so that the next parameter is clearly
// visible. Line comments already introduce a break.
if (Current.isNot(TT_LineComment)) {
- for (unsigned i = 0, e = State.Stack.size(); i != e; ++i)
- State.Stack[i].BreakBeforeParameter = true;
+ for (ParenState &Paren : State.Stack)
+ Paren.BreakBeforeParameter = true;
}
if (Current.is(TT_BlockComment))
IO.mapOptional("Language", Style.Language);
if (IO.outputting()) {
- StringRef StylesArray[] = {"LLVM", "Google", "Chromium", "Mozilla",
- "WebKit", "GNU", "Microsoft"};
- ArrayRef<StringRef> Styles(StylesArray);
- for (size_t i = 0, e = Styles.size(); i < e; ++i) {
- StringRef StyleName(Styles[i]);
+ StringRef Styles[] = {"LLVM", "Google", "Chromium", "Mozilla",
+ "WebKit", "GNU", "Microsoft"};
+ for (StringRef StyleName : Styles) {
FormatStyle PredefinedStyle;
if (getPredefinedStyle(StyleName, Style.Language, &PredefinedStyle) &&
Style == PredefinedStyle) {
// configuration (which can only be at slot 0) after it.
FormatStyle::FormatStyleSet StyleSet;
bool LanguageFound = false;
- for (int i = Styles.size() - 1; i >= 0; --i) {
- if (Styles[i].Language != FormatStyle::LK_None)
- StyleSet.Add(Styles[i]);
- if (Styles[i].Language == Language)
+ for (const FormatStyle &Style : llvm::reverse(Styles)) {
+ if (Style.Language != FormatStyle::LK_None)
+ StyleSet.Add(Style);
+ if (Style.Language == Language)
LanguageFound = true;
}
if (!LanguageFound) {
tooling::Replacements Result;
deriveLocalStyle(AnnotatedLines);
AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
- for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
- Annotator.calculateFormattingInformation(*AnnotatedLines[i]);
- }
+ for (AnnotatedLine *Line : AnnotatedLines)
+ Annotator.calculateFormattingInformation(*Line);
Annotator.setCommentLineLevels(AnnotatedLines);
WhitespaceManager Whitespaces(
deriveLocalStyle(const SmallVectorImpl<AnnotatedLine *> &AnnotatedLines) {
bool HasBinPackedFunction = false;
bool HasOnePerLineFunction = false;
- for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
- if (!AnnotatedLines[i]->First->Next)
+ for (AnnotatedLine *Line : AnnotatedLines) {
+ if (!Line->First->Next)
continue;
- FormatToken *Tok = AnnotatedLines[i]->First->Next;
+ FormatToken *Tok = Line->First->Next;
while (Tok->Next) {
if (Tok->is(PPK_BinPacked))
HasBinPackedFunction = true;
if (!affectsRange(Ranges, IncludesBeginOffset, IncludesEndOffset))
return;
SmallVector<unsigned, 16> Indices;
- for (unsigned i = 0, e = Includes.size(); i != e; ++i) {
+ for (unsigned i = 0, e = Includes.size(); i != e; ++i)
Indices.push_back(i);
- }
if (Style.SortIncludes == FormatStyle::SI_CaseInsensitive) {
llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
unsigned LongestMatchIndex = UINT_MAX;
unsigned LongestMatchLength = 0;
for (unsigned I = 0; I < Style.JavaImportGroups.size(); I++) {
- std::string GroupPrefix = Style.JavaImportGroups[I];
+ const std::string &GroupPrefix = Style.JavaImportGroups[I];
if (ImportIdentifier.startswith(GroupPrefix) &&
GroupPrefix.length() > LongestMatchLength) {
LongestMatchIndex = I;
// Spin through the lines and ensure we have balanced braces.
int Braces = 0;
- for (size_t I = 0, E = AnnotatedLines.size(); I != E; ++I) {
- FormatToken *Tok = AnnotatedLines[I]->First;
+ for (AnnotatedLine *Line : AnnotatedLines) {
+ FormatToken *Tok = Line->First;
while (Tok) {
Braces += Tok->is(tok::l_brace) ? 1 : Tok->is(tok::r_brace) ? -1 : 0;
Tok = Tok->Next;
assert(UnwrappedLines.rbegin()->empty());
unsigned Penalty = 0;
for (unsigned Run = 0, RunE = UnwrappedLines.size(); Run + 1 != RunE; ++Run) {
+ const auto &Lines = UnwrappedLines[Run];
LLVM_DEBUG(llvm::dbgs() << "Run " << Run << "...\n");
SmallVector<AnnotatedLine *, 16> AnnotatedLines;
TokenAnnotator Annotator(Style, Lex.getKeywords());
- for (unsigned i = 0, e = UnwrappedLines[Run].size(); i != e; ++i) {
- AnnotatedLines.push_back(new AnnotatedLine(UnwrappedLines[Run][i]));
+ for (const UnwrappedLine &Line : Lines) {
+ AnnotatedLines.push_back(new AnnotatedLine(Line));
Annotator.annotate(*AnnotatedLines.back());
}
for (const tooling::Replacement &Fix : RunResult.first)
llvm::dbgs() << Fix.toString() << "\n";
});
- for (unsigned i = 0, e = AnnotatedLines.size(); i != e; ++i) {
- delete AnnotatedLines[i];
- }
+ for (AnnotatedLine *Line : AnnotatedLines)
+ delete Line;
Penalty += RunResult.second;
for (const auto &R : RunResult.first) {
}
~AnnotatedLine() {
- for (unsigned i = 0, e = Children.size(); i != e; ++i) {
- delete Children[i];
- }
+ for (AnnotatedLine *Child : Children)
+ delete Child;
FormatToken *Current = First;
while (Current) {
Current->Children.clear();
} while (Tok->Tok.isNot(tok::eof) && !LBraceStack.empty());
// Assume other blocks for all unclosed opening braces.
- for (unsigned i = 0, e = LBraceStack.size(); i != e; ++i) {
- if (LBraceStack[i]->is(BK_Unknown))
- LBraceStack[i]->setBlockKind(BK_Block);
+ for (FormatToken *LBrace : LBraceStack) {
+ if (LBrace->is(BK_Unknown))
+ LBrace->setBlockKind(BK_Block);
}
FormatTok = Tokens->setPosition(StoredPosition);
AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
tooling::Replacements Fixes;
SmallVector<UsingDeclaration, 4> UsingDeclarations;
- for (size_t I = 0, E = AnnotatedLines.size(); I != E; ++I) {
- const auto *FirstTok = AnnotatedLines[I]->First;
- if (AnnotatedLines[I]->InPPDirective ||
- !AnnotatedLines[I]->startsWith(tok::kw_using) || FirstTok->Finalized) {
+ for (const AnnotatedLine *Line : AnnotatedLines) {
+ const auto *FirstTok = Line->First;
+ if (Line->InPPDirective || !Line->startsWith(tok::kw_using) ||
+ FirstTok->Finalized) {
endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes);
continue;
}
endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes);
continue;
}
- UsingDeclarations.push_back(UsingDeclaration(AnnotatedLines[I], Label));
+ UsingDeclarations.push_back(UsingDeclaration(Line, Label));
}
endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes);
return {Fixes, 0};
// Now go through and fixup the spaces.
auto *CellIter = Cells.begin();
- for (auto i = 0U; i < CellDescs.CellCount; i++, ++CellIter) {
+ for (auto i = 0U; i < CellDescs.CellCount; ++i, ++CellIter) {
unsigned NetWidth = 0U;
if (isSplitCell(*CellIter))
NetWidth = getNetWidth(Cells.begin(), CellIter, CellDescs.InitialSpaces);