Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 1 | //===--- AffectedRangeManager.h - Format C++ code ---------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 10 | /// AffectedRangeManager class manages affected ranges in the code. |
Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CLANG_LIB_FORMAT_AFFECTEDRANGEMANAGER_H |
| 15 | #define LLVM_CLANG_LIB_FORMAT_AFFECTEDRANGEMANAGER_H |
| 16 | |
| 17 | #include "clang/Basic/SourceManager.h" |
| 18 | |
| 19 | namespace clang { |
| 20 | namespace format { |
| 21 | |
| 22 | struct FormatToken; |
| 23 | class AnnotatedLine; |
| 24 | |
| 25 | class AffectedRangeManager { |
| 26 | public: |
Eric Liu | 635423e | 2016-04-28 07:52:03 +0000 | [diff] [blame] | 27 | AffectedRangeManager(const SourceManager &SourceMgr, |
Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 28 | const ArrayRef<CharSourceRange> Ranges) |
| 29 | : SourceMgr(SourceMgr), Ranges(Ranges.begin(), Ranges.end()) {} |
| 30 | |
| 31 | // Determines which lines are affected by the SourceRanges given as input. |
Manuel Klimek | 0dddcf7 | 2018-04-23 09:34:26 +0000 | [diff] [blame] | 32 | // 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] | 33 | // children is affected. |
Manuel Klimek | 0dddcf7 | 2018-04-23 09:34:26 +0000 | [diff] [blame] | 34 | bool computeAffectedLines(SmallVectorImpl<AnnotatedLine *> &Lines); |
Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 35 | |
| 36 | // Returns true if 'Range' intersects with one of the input ranges. |
| 37 | bool affectsCharSourceRange(const CharSourceRange &Range); |
| 38 | |
| 39 | private: |
| 40 | // Returns true if the range from 'First' to 'Last' intersects with one of the |
| 41 | // input ranges. |
| 42 | bool affectsTokenRange(const FormatToken &First, const FormatToken &Last, |
| 43 | bool IncludeLeadingNewlines); |
| 44 | |
| 45 | // Returns true if one of the input ranges intersect the leading empty lines |
| 46 | // before 'Tok'. |
| 47 | bool affectsLeadingEmptyLines(const FormatToken &Tok); |
| 48 | |
| 49 | // Marks all lines between I and E as well as all their children as affected. |
| 50 | void markAllAsAffected(SmallVectorImpl<AnnotatedLine *>::iterator I, |
| 51 | SmallVectorImpl<AnnotatedLine *>::iterator E); |
| 52 | |
| 53 | // Determines whether 'Line' is affected by the SourceRanges given as input. |
| 54 | // Returns \c true if line or one if its children is affected. |
Manuel Klimek | 0dddcf7 | 2018-04-23 09:34:26 +0000 | [diff] [blame] | 55 | bool nonPPLineAffected(AnnotatedLine *Line, const AnnotatedLine *PreviousLine, |
| 56 | SmallVectorImpl<AnnotatedLine *> &Lines); |
Eric Liu | c5cad39 | 2016-04-28 07:51:47 +0000 | [diff] [blame] | 57 | |
Eric Liu | 635423e | 2016-04-28 07:52:03 +0000 | [diff] [blame] | 58 | const SourceManager &SourceMgr; |
Eric Liu | 4cfb88a | 2016-04-25 15:09:22 +0000 | [diff] [blame] | 59 | const SmallVector<CharSourceRange, 8> Ranges; |
| 60 | }; |
| 61 | |
| 62 | } // namespace format |
| 63 | } // namespace clang |
| 64 | |
Eric Liu | c5cad39 | 2016-04-28 07:51:47 +0000 | [diff] [blame] | 65 | #endif // LLVM_CLANG_LIB_FORMAT_AFFECTEDRANGEMANAGER_H |