[clang-format] Assert Line->First. NFC.
Cf. scan-build reports: * https://llvm.org/reports/scan-build/report-AffectedRangeManager.cpp-nonPPLineAffected-34-16c04b.html#EndPath * https://llvm.org/reports/scan-build/report-SortJavaScriptImports.cpp-parseModuleReferences-34-96a7f8.html#EndPath * https://llvm.org/reports/scan-build/report-TokenAnnotator.cpp-setCommentLineLevels-26-77bdba.html#EndPath * https://llvm.org/reports/scan-build/report-AffectedRangeManager.cpp-nonPPLineAffected-31-714434.html#EndPath * https://llvm.org/reports/scan-build/report-TokenAnnotator.cpp-setCommentLineLevels-16-bd39d0.html#EndPath * https://llvm.org/reports/scan-build/report-UnwrappedLineFormatter.cpp-format-90-668b2d.html#EndPath
This commit is contained in:
parent
3519dcfec2
commit
670a721de2
|
@ -27,6 +27,7 @@ bool AffectedRangeManager::computeAffectedLines(
|
|||
const AnnotatedLine *PreviousLine = nullptr;
|
||||
while (I != E) {
|
||||
AnnotatedLine *Line = *I;
|
||||
assert(Line->First);
|
||||
Line->LeadingEmptyLinesAffected = affectsLeadingEmptyLines(*Line->First);
|
||||
|
||||
// If a line is part of a preprocessor directive, it needs to be formatted
|
||||
|
@ -113,6 +114,7 @@ bool AffectedRangeManager::nonPPLineAffected(
|
|||
// affected.
|
||||
bool SomeFirstChildAffected = false;
|
||||
|
||||
assert(Line->First);
|
||||
for (FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) {
|
||||
// Determine whether 'Tok' was affected.
|
||||
if (affectsTokenRange(*Tok, *Tok, IncludeLeadingNewlines))
|
||||
|
|
|
@ -361,6 +361,7 @@ private:
|
|||
bool AnyImportAffected = false;
|
||||
bool FormattingOff = false;
|
||||
for (auto *Line : AnnotatedLines) {
|
||||
assert(Line->First);
|
||||
Current = Line->First;
|
||||
LineEnd = Line->Last;
|
||||
// clang-format comments toggle formatting on/off.
|
||||
|
|
|
@ -2353,9 +2353,10 @@ private:
|
|||
void TokenAnnotator::setCommentLineLevels(
|
||||
SmallVectorImpl<AnnotatedLine *> &Lines) {
|
||||
const AnnotatedLine *NextNonCommentLine = nullptr;
|
||||
for (AnnotatedLine *AL : llvm::reverse(Lines)) {
|
||||
for (AnnotatedLine *Line : llvm::reverse(Lines)) {
|
||||
assert(Line->First);
|
||||
bool CommentLine = true;
|
||||
for (const FormatToken *Tok = AL->First; Tok; Tok = Tok->Next) {
|
||||
for (const FormatToken *Tok = Line->First; Tok; Tok = Tok->Next) {
|
||||
if (!Tok->is(tok::comment)) {
|
||||
CommentLine = false;
|
||||
break;
|
||||
|
@ -2367,20 +2368,21 @@ void TokenAnnotator::setCommentLineLevels(
|
|||
if (NextNonCommentLine && CommentLine &&
|
||||
NextNonCommentLine->First->NewlinesBefore <= 1 &&
|
||||
NextNonCommentLine->First->OriginalColumn ==
|
||||
AL->First->OriginalColumn) {
|
||||
Line->First->OriginalColumn) {
|
||||
// Align comments for preprocessor lines with the # in column 0 if
|
||||
// preprocessor lines are not indented. Otherwise, align with the next
|
||||
// line.
|
||||
AL->Level = (Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
|
||||
(NextNonCommentLine->Type == LT_PreprocessorDirective ||
|
||||
NextNonCommentLine->Type == LT_ImportStatement))
|
||||
? 0
|
||||
: NextNonCommentLine->Level;
|
||||
Line->Level =
|
||||
(Style.IndentPPDirectives != FormatStyle::PPDIS_BeforeHash &&
|
||||
(NextNonCommentLine->Type == LT_PreprocessorDirective ||
|
||||
NextNonCommentLine->Type == LT_ImportStatement))
|
||||
? 0
|
||||
: NextNonCommentLine->Level;
|
||||
} else {
|
||||
NextNonCommentLine = AL->First->isNot(tok::r_brace) ? AL : nullptr;
|
||||
NextNonCommentLine = Line->First->isNot(tok::r_brace) ? Line : nullptr;
|
||||
}
|
||||
|
||||
setCommentLineLevels(AL->Children);
|
||||
setCommentLineLevels(Line->Children);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1213,6 +1213,7 @@ unsigned UnwrappedLineFormatter::format(
|
|||
Joiner.getNextMergedLine(DryRun, IndentTracker);
|
||||
Line; PrevPrevLine = PreviousLine, PreviousLine = Line, Line = NextLine,
|
||||
FirstLine = false) {
|
||||
assert(Line->First);
|
||||
const AnnotatedLine &TheLine = *Line;
|
||||
unsigned Indent = IndentTracker.getIndent();
|
||||
|
||||
|
@ -1240,7 +1241,7 @@ unsigned UnwrappedLineFormatter::format(
|
|||
|
||||
if (ShouldFormat && TheLine.Type != LT_Invalid) {
|
||||
if (!DryRun) {
|
||||
bool LastLine = Line->First->is(tok::eof);
|
||||
bool LastLine = TheLine.First->is(tok::eof);
|
||||
formatFirstToken(TheLine, PreviousLine, PrevPrevLine, Lines, Indent,
|
||||
LastLine ? LastStartColumn : NextStartColumn + Indent);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue