25 bool SomeLineAffected =
false;
30 Line->LeadingEmptyLinesAffected = affectsLeadingEmptyLines(*
Line->First);
34 if (
Line->InPPDirective) {
37 while (PPEnd != E && !(*PPEnd)->First->HasUnescapedNewline) {
38 Last = (*PPEnd)->Last;
42 if (affectsTokenRange(*
Line->First, *
Last,
44 SomeLineAffected =
true;
45 markAllAsAffected(I, PPEnd);
51 if (nonPPLineAffected(
Line, PreviousLine, Lines))
52 SomeLineAffected =
true;
57 return SomeLineAffected;
73 bool IncludeLeadingNewlines) {
75 if (!IncludeLeadingNewlines)
78 End = End.getLocWithOffset(
Last.TokenText.size());
83bool AffectedRangeManager::affectsLeadingEmptyLines(
const FormatToken &Tok) {
85 Tok.WhitespaceRange.getBegin(),
86 Tok.WhitespaceRange.getBegin().getLocWithOffset(Tok.LastNewlineOffset));
90void AffectedRangeManager::markAllAsAffected(
91 SmallVectorImpl<AnnotatedLine *>::iterator I,
92 SmallVectorImpl<AnnotatedLine *>::iterator E) {
94 (*I)->Affected =
true;
95 markAllAsAffected((*I)->Children.begin(), (*I)->Children.end());
100bool AffectedRangeManager::nonPPLineAffected(
101 AnnotatedLine *
Line,
const AnnotatedLine *PreviousLine,
102 SmallVectorImpl<AnnotatedLine *> &Lines) {
103 bool SomeLineAffected =
false;
105 if (
Line->ChildrenAffected)
106 SomeLineAffected =
true;
109 bool SomeTokenAffected =
false;
112 bool IncludeLeadingNewlines =
false;
116 bool SomeFirstChildAffected =
false;
119 for (FormatToken *Tok =
Line->First; Tok; Tok = Tok->Next) {
121 if (affectsTokenRange(*Tok, *Tok, IncludeLeadingNewlines))
122 SomeTokenAffected =
true;
125 if (!Tok->Children.empty() && Tok->Children.front()->Affected)
126 SomeFirstChildAffected =
true;
128 IncludeLeadingNewlines = Tok->Children.empty();
133 bool LineMoved = PreviousLine && PreviousLine->Affected &&
134 Line->First->NewlinesBefore == 0;
136 bool IsContinuedComment =
137 Line->First->is(tok::comment) && !
Line->First->Next &&
138 Line->First->NewlinesBefore < 2 && PreviousLine &&
139 PreviousLine->Affected && PreviousLine->Last->is(tok::comment);
141 bool IsAffectedClosingBrace =
142 Line->First->is(tok::r_brace) &&
144 Lines[
Line->MatchingOpeningBlockLineIndex]->Affected;
146 if (SomeTokenAffected || SomeFirstChildAffected || LineMoved ||
147 IsContinuedComment || IsAffectedClosingBrace) {
148 Line->Affected =
true;
149 SomeLineAffected =
true;
151 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.