1 //===--- UnwrappedLineFormatter.h - Format C++ code -------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// Implements a combinatorial exploration of all the different
11 /// linebreaks unwrapped lines can be formatted in.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
16 #define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
18 #include "ContinuationIndenter.h"
23 class ContinuationIndenter
;
24 class WhitespaceManager
;
26 class UnwrappedLineFormatter
{
28 UnwrappedLineFormatter(ContinuationIndenter
*Indenter
,
29 WhitespaceManager
*Whitespaces
,
30 const FormatStyle
&Style
,
31 const AdditionalKeywords
&Keywords
,
32 const SourceManager
&SourceMgr
,
33 FormattingAttemptStatus
*Status
)
34 : Indenter(Indenter
), Whitespaces(Whitespaces
), Style(Style
),
35 Keywords(Keywords
), SourceMgr(SourceMgr
), Status(Status
) {}
37 /// Format the current block and return the penalty.
38 unsigned format(const SmallVectorImpl
<AnnotatedLine
*> &Lines
,
39 bool DryRun
= false, int AdditionalIndent
= 0,
40 bool FixBadIndentation
= false, unsigned FirstStartColumn
= 0,
41 unsigned NextStartColumn
= 0, unsigned LastStartColumn
= 0);
44 /// Add a new line and the required indent before the first Token
45 /// of the \c UnwrappedLine if there was no structural parsing error.
46 void formatFirstToken(const AnnotatedLine
&Line
,
47 const AnnotatedLine
*PreviousLine
,
48 const AnnotatedLine
*PrevPrevLine
,
49 const SmallVectorImpl
<AnnotatedLine
*> &Lines
,
50 unsigned Indent
, unsigned NewlineIndent
);
52 /// Returns the column limit for a line, taking into account whether we
53 /// need an escaped newline due to a continued preprocessor directive.
54 unsigned getColumnLimit(bool InPPDirective
,
55 const AnnotatedLine
*NextLine
) const;
57 // Cache to store the penalty of formatting a vector of AnnotatedLines
58 // starting from a specific additional offset. Improves performance if there
59 // are many nested blocks.
60 std::map
<std::pair
<const SmallVectorImpl
<AnnotatedLine
*> *, unsigned>,
64 ContinuationIndenter
*Indenter
;
65 WhitespaceManager
*Whitespaces
;
66 const FormatStyle
&Style
;
67 const AdditionalKeywords
&Keywords
;
68 const SourceManager
&SourceMgr
;
69 FormattingAttemptStatus
*Status
;
71 } // end namespace format
72 } // end namespace clang
74 #endif // LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H