26 bool SomeLineAffected =
false;
31 Line->LeadingEmptyLinesAffected = affectsLeadingEmptyLines(*
Line->First);
35 if (
Line->InPPDirective) {
38 while (PPEnd !=
E && !(*PPEnd)->First->HasUnescapedNewline) {
39 Last = (*PPEnd)->Last;
43 if (affectsTokenRange(*
Line->First, *
Last,
45 SomeLineAffected =
true;
46 markAllAsAffected(I, PPEnd);
52 if (nonPPLineAffected(
Line, PreviousLine, Lines))
53 SomeLineAffected =
true;
58 return SomeLineAffected;
74 bool IncludeLeadingNewlines) {
76 if (!IncludeLeadingNewlines)
79 End = End.getLocWithOffset(
Last.TokenText.size());
84bool AffectedRangeManager::affectsLeadingEmptyLines(
const FormatToken &Tok) {
86 Tok.WhitespaceRange.getBegin(),
87 Tok.WhitespaceRange.getBegin().getLocWithOffset(Tok.LastNewlineOffset));
91void AffectedRangeManager::markAllAsAffected(
92 SmallVectorImpl<AnnotatedLine *>::iterator I,
93 SmallVectorImpl<AnnotatedLine *>::iterator
E) {
95 (*I)->Affected =
true;
96 markAllAsAffected((*I)->Children.begin(), (*I)->Children.end());
101bool AffectedRangeManager::nonPPLineAffected(
102 AnnotatedLine *
Line,
const AnnotatedLine *PreviousLine,
103 SmallVectorImpl<AnnotatedLine *> &Lines) {
104 bool SomeLineAffected =
false;
106 if (
Line->ChildrenAffected)
107 SomeLineAffected =
true;
110 bool SomeTokenAffected =
false;
113 bool IncludeLeadingNewlines =
false;
117 bool SomeFirstChildAffected =
false;
120 for (FormatToken *Tok =
Line->First; Tok; Tok = Tok->Next) {
122 if (affectsTokenRange(*Tok, *Tok, IncludeLeadingNewlines))
123 SomeTokenAffected =
true;
126 if (!Tok->Children.empty() && Tok->Children.front()->Affected)
127 SomeFirstChildAffected =
true;
129 IncludeLeadingNewlines = Tok->Children.empty();
134 bool LineMoved = PreviousLine && PreviousLine->Affected &&
135 Line->First->NewlinesBefore == 0;
137 bool IsContinuedComment =
138 Line->First->is(tok::comment) && !
Line->First->Next &&
139 Line->First->NewlinesBefore < 2 && PreviousLine &&
140 PreviousLine->Affected && PreviousLine->Last->is(tok::comment);
142 bool IsAffectedClosingBrace =
143 Line->First->is(tok::r_brace) &&
145 Lines[
Line->MatchingOpeningBlockLineIndex]->Affected;
147 if (SomeTokenAffected || SomeFirstChildAffected || LineMoved ||
148 IsContinuedComment || IsAffectedClosingBrace) {
149 Line->Affected =
true;
150 SomeLineAffected =
true;
152 return SomeLineAffected;
AffectedRangeManager class manages affected ranges in the code.
This file implements a token annotator, i.e.
Represents a character-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.
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
The JSON file list parser is used to communicate input to InstallAPI.