1 //===--- UnwrappedLineFormatter.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 Implements a combinartorial exploration of all the different
12 /// linebreaks unwrapped lines can be formatted in.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
17 #define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
19 #include "ContinuationIndenter.h"
20 #include "clang/Format/Format.h"
26 class ContinuationIndenter;
27 class WhitespaceManager;
29 class UnwrappedLineFormatter {
31 UnwrappedLineFormatter(ContinuationIndenter *Indenter,
32 WhitespaceManager *Whitespaces,
33 const FormatStyle &Style,
34 const AdditionalKeywords &Keywords,
35 bool *IncompleteFormat)
36 : Indenter(Indenter), Whitespaces(Whitespaces), Style(Style),
37 Keywords(Keywords), IncompleteFormat(IncompleteFormat) {}
39 /// \brief Format the current block and return the penalty.
40 unsigned format(const SmallVectorImpl<AnnotatedLine *> &Lines,
41 bool DryRun = false, int AdditionalIndent = 0,
42 bool FixBadIndentation = false);
45 /// \brief Add a new line and the required indent before the first Token
46 /// of the \c UnwrappedLine if there was no structural parsing error.
47 void formatFirstToken(FormatToken &RootToken,
48 const AnnotatedLine *PreviousLine, unsigned IndentLevel,
49 unsigned Indent, bool InPPDirective);
51 /// \brief Returns the column limit for a line, taking into account whether we
52 /// need an escaped newline due to a continued preprocessor directive.
53 unsigned getColumnLimit(bool InPPDirective,
54 const AnnotatedLine *NextLine) const;
56 // Cache to store the penalty of formatting a vector of AnnotatedLines
57 // starting from a specific additional offset. Improves performance if there
58 // are many nested blocks.
59 std::map<std::pair<const SmallVectorImpl<AnnotatedLine *> *, unsigned>,
60 unsigned> PenaltyCache;
62 ContinuationIndenter *Indenter;
63 WhitespaceManager *Whitespaces;
64 const FormatStyle &Style;
65 const AdditionalKeywords &Keywords;
66 bool *IncompleteFormat;
68 } // end namespace format
69 } // end namespace clang
71 #endif // LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H