Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 1 | //===--- 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 |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 11 | /// AffectedRangeManager class manages affected ranges in the code. |
Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 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 | |
| 20 | namespace clang { |
| 21 | namespace format { |
| 22 | |
| 23 | struct FormatToken; |
| 24 | class AnnotatedLine; |
| 25 | |
| 26 | class AffectedRangeManager { |
| 27 | public: |
Eric Liu | 635423e | 2016-04-28 07:52:03 +0000 | [diff] [blame] | 28 | AffectedRangeManager(const SourceManager &SourceMgr, |
Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 29 | 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. |
Manuel Klimek | 0dddcf7 | 2018-04-23 09:34:26 +0000 | [diff] [blame] | 33 | // Returns \c true if at least one line in \p Lines or one of their |
Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 34 | // children is affected. |
Manuel Klimek | 0dddcf7 | 2018-04-23 09:34:26 +0000 | [diff] [blame] | 35 | bool computeAffectedLines(SmallVectorImpl<AnnotatedLine *> &Lines); |
Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 36 | |
| 37 | // Returns true if 'Range' intersects with one of the input ranges. |
| 38 | bool affectsCharSourceRange(const CharSourceRange &Range); |
| 39 | |
| 40 | private: |
| 41 | // Returns true if the range from 'First' to 'Last' intersects with one of the |
| 42 | // input ranges. |
| 43 | bool affectsTokenRange(const FormatToken &First, const FormatToken &Last, |
| 44 | bool IncludeLeadingNewlines); |
| 45 | |
| 46 | // Returns true if one of the input ranges intersect the leading empty lines |
| 47 | // before 'Tok'. |
| 48 | bool affectsLeadingEmptyLines(const FormatToken &Tok); |
| 49 | |
| 50 | // Marks all lines between I and E as well as all their children as affected. |
| 51 | void markAllAsAffected(SmallVectorImpl<AnnotatedLine *>::iterator I, |
| 52 | SmallVectorImpl<AnnotatedLine *>::iterator E); |
| 53 | |
| 54 | // Determines whether 'Line' is affected by the SourceRanges given as input. |
| 55 | // Returns \c true if line or one if its children is affected. |
Manuel Klimek | 0dddcf7 | 2018-04-23 09:34:26 +0000 | [diff] [blame] | 56 | bool nonPPLineAffected(AnnotatedLine *Line, const AnnotatedLine *PreviousLine, |
| 57 | SmallVectorImpl<AnnotatedLine *> &Lines); |
Eric Liu | c5cad39 | 2016-04-28 07:51:47 +0000 | [diff] [blame] | 58 | |
Eric Liu | 635423e | 2016-04-28 07:52:03 +0000 | [diff] [blame] | 59 | const SourceManager &SourceMgr; |
Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 60 | const SmallVector<CharSourceRange, 8> Ranges; |
| 61 | }; |
| 62 | |
| 63 | } // namespace format |
| 64 | } // namespace clang |
| 65 | |
Eric Liu | c5cad39 | 2016-04-28 07:51:47 +0000 | [diff] [blame] | 66 | #endif // LLVM_CLANG_LIB_FORMAT_AFFECTEDRANGEMANAGER_H |