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