1 //===--- AffectedRangeManager.h - Format C++ code ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief AffectedRangeManager class manages affected ranges in the code.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_LIB_FORMAT_AFFECTEDRANGEMANAGER_H
16 #define LLVM_CLANG_LIB_FORMAT_AFFECTEDRANGEMANAGER_H
18 #include "clang/Basic/SourceManager.h"
26 class AffectedRangeManager {
28 AffectedRangeManager(const SourceManager &SourceMgr,
29 const ArrayRef<CharSourceRange> Ranges)
30 : SourceMgr(SourceMgr), Ranges(Ranges.begin(), Ranges.end()) {}
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);
38 // Returns true if 'Range' intersects with one of the input ranges.
39 bool affectsCharSourceRange(const CharSourceRange &Range);
42 // Returns true if the range from 'First' to 'Last' intersects with one of the
44 bool affectsTokenRange(const FormatToken &First, const FormatToken &Last,
45 bool IncludeLeadingNewlines);
47 // Returns true if one of the input ranges intersect the leading empty lines
49 bool affectsLeadingEmptyLines(const FormatToken &Tok);
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);
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);
60 const SourceManager &SourceMgr;
61 const SmallVector<CharSourceRange, 8> Ranges;
67 #endif // LLVM_CLANG_LIB_FORMAT_AFFECTEDRANGEMANAGER_H