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 /// 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 const SourceManager &SourceMgr,
36 FormattingAttemptStatus *Status)
37 : Indenter(Indenter), Whitespaces(Whitespaces), Style(Style),
38 Keywords(Keywords), SourceMgr(SourceMgr), Status(Status) {}
40 /// Format the current block and return the penalty.
41 unsigned format(const SmallVectorImpl<AnnotatedLine *> &Lines,
42 bool DryRun = false, int AdditionalIndent = 0,
43 bool FixBadIndentation = false,
44 unsigned FirstStartColumn = 0,
45 unsigned NextStartColumn = 0,
46 unsigned LastStartColumn = 0);
49 /// Add a new line and the required indent before the first Token
50 /// of the \c UnwrappedLine if there was no structural parsing error.
51 void formatFirstToken(const AnnotatedLine &Line,
52 const AnnotatedLine *PreviousLine,
53 const SmallVectorImpl<AnnotatedLine *> &Lines,
54 unsigned Indent, unsigned NewlineIndent);
56 /// Returns the column limit for a line, taking into account whether we
57 /// need an escaped newline due to a continued preprocessor directive.
58 unsigned getColumnLimit(bool InPPDirective,
59 const AnnotatedLine *NextLine) const;
61 // Cache to store the penalty of formatting a vector of AnnotatedLines
62 // starting from a specific additional offset. Improves performance if there
63 // are many nested blocks.
64 std::map<std::pair<const SmallVectorImpl<AnnotatedLine *> *, unsigned>,
68 ContinuationIndenter *Indenter;
69 WhitespaceManager *Whitespaces;
70 const FormatStyle &Style;
71 const AdditionalKeywords &Keywords;
72 const SourceManager &SourceMgr;
73 FormattingAttemptStatus *Status;
75 } // end namespace format
76 } // end namespace clang
78 #endif // LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H