blob: d8d5ee55acd8b1b410e8d8bab848dc9eb89726fc [file] [log] [blame]
Eric Liu4cfb88a2016-04-25 15:09:22 +00001//===--- AffectedRangeManager.h - Format C++ code ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief AffectedRangeManager class manages affected ranges in the code.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_LIB_FORMAT_AFFECTEDRANGEMANAGER_H
16#define LLVM_CLANG_LIB_FORMAT_AFFECTEDRANGEMANAGER_H
17
18#include "clang/Basic/SourceManager.h"
19
20namespace clang {
21namespace format {
22
23struct FormatToken;
24class AnnotatedLine;
25
26class AffectedRangeManager {
27public:
Eric Liu635423e2016-04-28 07:52:03 +000028 AffectedRangeManager(const SourceManager &SourceMgr,
Eric Liu4cfb88a2016-04-25 15:09:22 +000029 const ArrayRef<CharSourceRange> Ranges)
30 : SourceMgr(SourceMgr), Ranges(Ranges.begin(), Ranges.end()) {}
31
32 // Determines which lines are affected by the SourceRanges given as input.
33 // Returns \c true if at least one line between I and E or one of their
34 // children is affected.
35 bool computeAffectedLines(SmallVectorImpl<AnnotatedLine *>::iterator I,
36 SmallVectorImpl<AnnotatedLine *>::iterator E);
37
38 // Returns true if 'Range' intersects with one of the input ranges.
39 bool affectsCharSourceRange(const CharSourceRange &Range);
40
41private:
42 // Returns true if the range from 'First' to 'Last' intersects with one of the
43 // input ranges.
44 bool affectsTokenRange(const FormatToken &First, const FormatToken &Last,
45 bool IncludeLeadingNewlines);
46
47 // Returns true if one of the input ranges intersect the leading empty lines
48 // before 'Tok'.
49 bool affectsLeadingEmptyLines(const FormatToken &Tok);
50
51 // Marks all lines between I and E as well as all their children as affected.
52 void markAllAsAffected(SmallVectorImpl<AnnotatedLine *>::iterator I,
53 SmallVectorImpl<AnnotatedLine *>::iterator E);
54
55 // Determines whether 'Line' is affected by the SourceRanges given as input.
56 // Returns \c true if line or one if its children is affected.
57 bool nonPPLineAffected(AnnotatedLine *Line,
58 const AnnotatedLine *PreviousLine);
Eric Liuc5cad392016-04-28 07:51:47 +000059
Eric Liu635423e2016-04-28 07:52:03 +000060 const SourceManager &SourceMgr;
Eric Liu4cfb88a2016-04-25 15:09:22 +000061 const SmallVector<CharSourceRange, 8> Ranges;
62};
63
64} // namespace format
65} // namespace clang
66
Eric Liuc5cad392016-04-28 07:51:47 +000067#endif // LLVM_CLANG_LIB_FORMAT_AFFECTEDRANGEMANAGER_H