Path: blob/main/contrib/llvm-project/clang/lib/Format/UnwrappedLineFormatter.h
35233 views
//===--- UnwrappedLineFormatter.h - Format C++ code -------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// Implements a combinatorial exploration of all the different10/// linebreaks unwrapped lines can be formatted in.11///12//===----------------------------------------------------------------------===//1314#ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H15#define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H1617#include "ContinuationIndenter.h"1819namespace clang {20namespace format {2122class ContinuationIndenter;23class WhitespaceManager;2425class UnwrappedLineFormatter {26public:27UnwrappedLineFormatter(ContinuationIndenter *Indenter,28WhitespaceManager *Whitespaces,29const FormatStyle &Style,30const AdditionalKeywords &Keywords,31const SourceManager &SourceMgr,32FormattingAttemptStatus *Status)33: Indenter(Indenter), Whitespaces(Whitespaces), Style(Style),34Keywords(Keywords), SourceMgr(SourceMgr), Status(Status) {}3536/// Format the current block and return the penalty.37unsigned format(const SmallVectorImpl<AnnotatedLine *> &Lines,38bool DryRun = false, int AdditionalIndent = 0,39bool FixBadIndentation = false, unsigned FirstStartColumn = 0,40unsigned NextStartColumn = 0, unsigned LastStartColumn = 0);4142private:43/// Add a new line and the required indent before the first Token44/// of the \c UnwrappedLine if there was no structural parsing error.45void formatFirstToken(const AnnotatedLine &Line,46const AnnotatedLine *PreviousLine,47const AnnotatedLine *PrevPrevLine,48const SmallVectorImpl<AnnotatedLine *> &Lines,49unsigned Indent, unsigned NewlineIndent);5051/// Returns the column limit for a line, taking into account whether we52/// need an escaped newline due to a continued preprocessor directive.53unsigned getColumnLimit(bool InPPDirective,54const AnnotatedLine *NextLine) const;5556// Cache to store the penalty of formatting a vector of AnnotatedLines57// starting from a specific additional offset. Improves performance if there58// are many nested blocks.59std::map<std::pair<const SmallVectorImpl<AnnotatedLine *> *, unsigned>,60unsigned>61PenaltyCache;6263ContinuationIndenter *Indenter;64WhitespaceManager *Whitespaces;65const FormatStyle &Style;66const AdditionalKeywords &Keywords;67const SourceManager &SourceMgr;68FormattingAttemptStatus *Status;69};70} // end namespace format71} // end namespace clang7273#endif // LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H747576