[libc][docgen] simplify posix links (#119595)
[llvm-project.git] / clang / lib / Format / UnwrappedLineFormatter.h
blob9b8acf427a2a000cb835a2d058dd4ba943b71808
1 //===--- UnwrappedLineFormatter.h - Format C++ code -------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Implements a combinatorial exploration of all the different
11 /// linebreaks unwrapped lines can be formatted in.
12 ///
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
16 #define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
18 #include "ContinuationIndenter.h"
20 namespace clang {
21 namespace format {
23 class ContinuationIndenter;
24 class WhitespaceManager;
26 class UnwrappedLineFormatter {
27 public:
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);
43 private:
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>,
61 unsigned>
62 PenaltyCache;
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