clang 20.0.0git
UnwrappedLineFormatter.h
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
16#define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
17
19
20namespace clang {
21namespace format {
22
23class ContinuationIndenter;
24class WhitespaceManager;
25
27public:
29 WhitespaceManager *Whitespaces,
30 const FormatStyle &Style,
31 const AdditionalKeywords &Keywords,
32 const SourceManager &SourceMgr,
34 : Indenter(Indenter), Whitespaces(Whitespaces), Style(Style),
35 Keywords(Keywords), SourceMgr(SourceMgr), Status(Status) {}
36
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);
42
43private:
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,
50 unsigned Indent, unsigned NewlineIndent);
51
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;
56
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;
63
64 ContinuationIndenter *Indenter;
65 WhitespaceManager *Whitespaces;
66 const FormatStyle &Style;
67 const AdditionalKeywords &Keywords;
68 const SourceManager &SourceMgr;
70};
71} // end namespace format
72} // end namespace clang
73
74#endif // LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
This file implements an indenter that manages the indentation of continuations.
ContinuationIndenter * Indenter
This class handles loading and caching of source files into memory.
UnwrappedLineFormatter(ContinuationIndenter *Indenter, WhitespaceManager *Whitespaces, const FormatStyle &Style, const AdditionalKeywords &Keywords, const SourceManager &SourceMgr, FormattingAttemptStatus *Status)
Manages the whitespaces around tokens and their replacements.
The JSON file list parser is used to communicate input to InstallAPI.
Encapsulates keywords that are context sensitive or for languages not properly supported by Clang's l...
Definition: FormatToken.h:1024
The FormatStyle is used to configure the formatting to follow specific guidelines.
Definition: Format.h:55
Represents the status of a formatting attempt.
Definition: Format.h:5373