26 bool SomeLineAffected =
false;
31 Line->LeadingEmptyLinesAffected = affectsLeadingEmptyLines(*
Line->First);
35 if (
Line->InPPDirective) {
37 const auto *PPEnd = I + 1;
38 while (PPEnd != E && !(*PPEnd)->First->HasUnescapedNewline &&
39 (*PPEnd)->First->isNot(tok::eof)) {
40 Last = (*PPEnd)->Last;
44 if (affectsTokenRange(*
Line->First, *
Last,
46 SomeLineAffected =
true;
47 markAllAsAffected(I, PPEnd);
53 if (nonPPLineAffected(
Line, PreviousLine, Lines))
54 SomeLineAffected =
true;
59 return SomeLineAffected;
65 if (!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(), R.getBegin()) &&
66 !SourceMgr.isBeforeInTranslationUnit(R.getEnd(), Range.getBegin())) {
75 bool IncludeLeadingNewlines) {
77 if (!IncludeLeadingNewlines)
85bool AffectedRangeManager::affectsLeadingEmptyLines(
const FormatToken &
Tok) {
87 Tok.WhitespaceRange.getBegin(),
88 Tok.WhitespaceRange.getBegin().getLocWithOffset(
Tok.LastNewlineOffset));
92void AffectedRangeManager::markAllAsAffected(
96 (*I)->Affected =
true;
97 markAllAsAffected((*I)->Children.begin(), (*I)->Children.end());
102bool AffectedRangeManager::nonPPLineAffected(
105 bool SomeLineAffected =
false;
107 if (
Line->ChildrenAffected)
108 SomeLineAffected =
true;
111 bool SomeTokenAffected =
false;
114 bool IncludeLeadingNewlines =
false;
118 bool SomeFirstChildAffected =
false;
123 if (affectsTokenRange(*
Tok, *
Tok, IncludeLeadingNewlines))
124 SomeTokenAffected =
true;
127 if (!
Tok->Children.empty() &&
Tok->Children.front()->Affected)
128 SomeFirstChildAffected =
true;
130 IncludeLeadingNewlines =
Tok->Children.empty();
135 bool LineMoved = PreviousLine && PreviousLine->Affected &&
136 Line->First->NewlinesBefore == 0;
138 bool IsContinuedComment =
139 Line->First->is(tok::comment) && !
Line->First->Next &&
140 Line->First->NewlinesBefore < 2 && PreviousLine &&
141 PreviousLine->Affected && PreviousLine->Last->is(tok::comment);
143 bool IsAffectedClosingBrace =
144 Line->First->is(tok::r_brace) &&
146 Lines[
Line->MatchingOpeningBlockLineIndex]->Affected;
148 if (SomeTokenAffected || SomeFirstChildAffected || LineMoved ||
149 IsContinuedComment || IsAffectedClosingBrace) {
150 Line->Affected =
true;
151 SomeLineAffected =
true;
153 return SomeLineAffected;
AffectedRangeManager class manages affected ranges in the code.
This file implements a token annotator, i.e.
Represents a byte-granular source range.
static CharSourceRange getCharRange(SourceRange R)
Encodes a location in the source.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
Top level wrappers for InstallAPI frontend operations.