26 bool SomeLineAffected =
false;
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))
52 SomeLineAffected =
true;
57 return SomeLineAffected;
72 bool AffectedRangeManager::affectsTokenRange(
const FormatToken &First,
74 bool IncludeLeadingNewlines) {
76 if (!IncludeLeadingNewlines)
84 bool AffectedRangeManager::affectsLeadingEmptyLines(
const FormatToken &Tok) {
86 Tok.WhitespaceRange.getBegin(),
87 Tok.WhitespaceRange.getBegin().getLocWithOffset(Tok.LastNewlineOffset));
91 void AffectedRangeManager::markAllAsAffected(
95 (*I)->Affected =
true;
96 markAllAsAffected((*I)->Children.begin(), (*I)->Children.end());
101 bool AffectedRangeManager::nonPPLineAffected(
102 AnnotatedLine *
Line,
const AnnotatedLine *PreviousLine) {
103 bool SomeLineAffected =
false;
104 Line->ChildrenAffected =
106 if (Line->ChildrenAffected)
107 SomeLineAffected =
true;
110 bool SomeTokenAffected =
false;
113 bool IncludeLeadingNewlines =
false;
117 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 ==
nullptr &&
138 Line->First->NewlinesBefore < 2 && PreviousLine &&
139 PreviousLine->Affected && PreviousLine->Last->is(tok::comment);
141 if (SomeTokenAffected || SomeFirstChildAffected || LineMoved ||
142 IsContinuedComment) {
143 Line->Affected =
true;
144 SomeLineAffected =
true;
146 return SomeLineAffected;
SourceLocation getBegin() const
AffectedRangeManager class manages affected ranges in the code.
This file implements a token annotator, i.e.
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
detail::InMemoryDirectory::const_iterator I
Represents a character-granular source range.
SourceLocation getEnd() const
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
static CharSourceRange getCharRange(SourceRange R)
Encodes a location in the source.
const TemplateArgument * iterator
SourceLocation getBegin() const
detail::InMemoryDirectory::const_iterator E