2014-12-11 03:00:42 +08:00
|
|
|
//===--- UnwrappedLineFormatter.h - Format C++ code -------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-12-11 03:00:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Implements a combinartorial exploration of all the different
|
2014-12-11 03:00:42 +08:00
|
|
|
/// linebreaks unwrapped lines can be formatted in.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
|
|
|
|
#define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
|
|
|
|
|
|
|
|
#include "ContinuationIndenter.h"
|
|
|
|
#include "clang/Format/Format.h"
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace format {
|
|
|
|
|
|
|
|
class ContinuationIndenter;
|
|
|
|
class WhitespaceManager;
|
|
|
|
|
|
|
|
class UnwrappedLineFormatter {
|
|
|
|
public:
|
|
|
|
UnwrappedLineFormatter(ContinuationIndenter *Indenter,
|
|
|
|
WhitespaceManager *Whitespaces,
|
2015-02-04 23:26:27 +08:00
|
|
|
const FormatStyle &Style,
|
2015-05-07 20:26:30 +08:00
|
|
|
const AdditionalKeywords &Keywords,
|
2017-04-21 22:35:20 +08:00
|
|
|
const SourceManager &SourceMgr,
|
|
|
|
FormattingAttemptStatus *Status)
|
2015-02-04 23:26:27 +08:00
|
|
|
: Indenter(Indenter), Whitespaces(Whitespaces), Style(Style),
|
2017-09-20 17:51:03 +08:00
|
|
|
Keywords(Keywords), SourceMgr(SourceMgr), Status(Status) {}
|
2014-12-11 03:00:42 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Format the current block and return the penalty.
|
2015-05-11 16:21:35 +08:00
|
|
|
unsigned format(const SmallVectorImpl<AnnotatedLine *> &Lines,
|
|
|
|
bool DryRun = false, int AdditionalIndent = 0,
|
2019-03-01 17:09:54 +08:00
|
|
|
bool FixBadIndentation = false, unsigned FirstStartColumn = 0,
|
|
|
|
unsigned NextStartColumn = 0, unsigned LastStartColumn = 0);
|
2015-04-23 17:23:17 +08:00
|
|
|
|
2014-12-11 03:00:42 +08:00
|
|
|
private:
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Add a new line and the required indent before the first Token
|
2014-12-11 03:00:42 +08:00
|
|
|
/// of the \c UnwrappedLine if there was no structural parsing error.
|
2017-01-31 19:25:01 +08:00
|
|
|
void formatFirstToken(const AnnotatedLine &Line,
|
2018-04-19 21:02:15 +08:00
|
|
|
const AnnotatedLine *PreviousLine,
|
|
|
|
const SmallVectorImpl<AnnotatedLine *> &Lines,
|
|
|
|
unsigned Indent, unsigned NewlineIndent);
|
2014-12-11 03:00:42 +08:00
|
|
|
|
2018-05-09 09:00:01 +08:00
|
|
|
/// Returns the column limit for a line, taking into account whether we
|
2015-05-12 17:23:57 +08:00
|
|
|
/// need an escaped newline due to a continued preprocessor directive.
|
2015-06-17 21:08:06 +08:00
|
|
|
unsigned getColumnLimit(bool InPPDirective,
|
|
|
|
const AnnotatedLine *NextLine) const;
|
2014-12-11 03:00:42 +08:00
|
|
|
|
|
|
|
// Cache to store the penalty of formatting a vector of AnnotatedLines
|
|
|
|
// starting from a specific additional offset. Improves performance if there
|
|
|
|
// are many nested blocks.
|
|
|
|
std::map<std::pair<const SmallVectorImpl<AnnotatedLine *> *, unsigned>,
|
2017-01-31 19:25:01 +08:00
|
|
|
unsigned>
|
|
|
|
PenaltyCache;
|
2015-05-07 20:26:30 +08:00
|
|
|
|
2015-05-11 16:21:35 +08:00
|
|
|
ContinuationIndenter *Indenter;
|
|
|
|
WhitespaceManager *Whitespaces;
|
|
|
|
const FormatStyle &Style;
|
|
|
|
const AdditionalKeywords &Keywords;
|
2017-04-21 22:35:20 +08:00
|
|
|
const SourceManager &SourceMgr;
|
|
|
|
FormattingAttemptStatus *Status;
|
2014-12-11 03:00:42 +08:00
|
|
|
};
|
|
|
|
} // end namespace format
|
|
|
|
} // end namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H
|