clang  6.0.0svn
UnwrappedLineFormatter.h
Go to the documentation of this file.
1 //===--- UnwrappedLineFormatter.h - Format C++ code -------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Implements a combinartorial exploration of all the different
12 /// linebreaks unwrapped lines can be formatted in.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
17 #define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
18 
19 #include "ContinuationIndenter.h"
20 #include "clang/Format/Format.h"
21 #include <map>
22 
23 namespace clang {
24 namespace format {
25 
26 class ContinuationIndenter;
27 class WhitespaceManager;
28 
30 public:
32  WhitespaceManager *Whitespaces,
33  const FormatStyle &Style,
34  const AdditionalKeywords &Keywords,
35  const SourceManager &SourceMgr,
37  : Indenter(Indenter), Whitespaces(Whitespaces), Style(Style),
38  Keywords(Keywords), SourceMgr(SourceMgr), Status(Status) {}
39 
40  /// \brief 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);
47 
48 private:
49  /// \brief 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, unsigned Indent,
53  unsigned NewlineIndent);
54 
55  /// \brief Returns the column limit for a line, taking into account whether we
56  /// need an escaped newline due to a continued preprocessor directive.
57  unsigned getColumnLimit(bool InPPDirective,
58  const AnnotatedLine *NextLine) const;
59 
60  // Cache to store the penalty of formatting a vector of AnnotatedLines
61  // starting from a specific additional offset. Improves performance if there
62  // are many nested blocks.
63  std::map<std::pair<const SmallVectorImpl<AnnotatedLine *> *, unsigned>,
64  unsigned>
65  PenaltyCache;
66 
67  ContinuationIndenter *Indenter;
68  WhitespaceManager *Whitespaces;
69  const FormatStyle &Style;
70  const AdditionalKeywords &Keywords;
71  const SourceManager &SourceMgr;
73 };
74 } // end namespace format
75 } // end namespace clang
76 
77 #endif // LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
unsigned format(const SmallVectorImpl< AnnotatedLine *> &Lines, bool DryRun=false, int AdditionalIndent=0, bool FixBadIndentation=false, unsigned FirstStartColumn=0, unsigned NextStartColumn=0, unsigned LastStartColumn=0)
Format the current block and return the penalty.
Manages the whitespaces around tokens and their replacements.
UnwrappedLineFormatter(ContinuationIndenter *Indenter, WhitespaceManager *Whitespaces, const FormatStyle &Style, const AdditionalKeywords &Keywords, const SourceManager &SourceMgr, FormattingAttemptStatus *Status)
const AnnotatedLine * Line
const bool InPPDirective
Various functions to configurably format source code.
Encapsulates keywords that are context sensitive or for languages not properly supported by Clang&#39;s l...
Definition: FormatToken.h:634
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition: Format.h:46
Represents the status of a formatting attempt.
Definition: Format.h:1776
Dataflow Directional Tag Classes.
This file implements an indenter that manages the indentation of continuations.
This class handles loading and caching of source files into memory.