2014-12-11 03:00:42 +08:00
|
|
|
//===--- UnwrappedLineFormatter.h - Format C++ code -------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief Implements a combinartorial exploration of all the different
|
|
|
|
/// 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
|
|
|
|
2015-05-11 16:21:35 +08:00
|
|
|
/// \brief Format the current block and return the penalty.
|
|
|
|
unsigned format(const SmallVectorImpl<AnnotatedLine *> &Lines,
|
|
|
|
bool DryRun = false, int AdditionalIndent = 0,
|
2017-10-30 22:01:50 +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:
|
|
|
|
/// \brief Add a new line and the required indent before the first Token
|
|
|
|
/// of the \c UnwrappedLine if there was no structural parsing error.
|
2017-01-31 19:25:01 +08:00
|
|
|
void formatFirstToken(const AnnotatedLine &Line,
|
2017-10-30 22:01:50 +08:00
|
|
|
const AnnotatedLine *PreviousLine, unsigned Indent,
|
|
|
|
unsigned NewlineIndent);
|
2014-12-11 03:00:42 +08:00
|
|
|
|
2015-05-12 17:23:57 +08:00
|
|
|
/// \brief Returns the column limit for a line, taking into account whether we
|
|
|
|
/// 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
|