10b57cec5SDimitry Andric //===--- UnwrappedLineFormatter.h - Format C++ code -------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric /// 90b57cec5SDimitry Andric /// \file 10*bdd1243dSDimitry Andric /// Implements a combinatorial exploration of all the different 110b57cec5SDimitry Andric /// linebreaks unwrapped lines can be formatted in. 120b57cec5SDimitry Andric /// 130b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H 160b57cec5SDimitry Andric #define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric #include "ContinuationIndenter.h" 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric namespace clang { 210b57cec5SDimitry Andric namespace format { 220b57cec5SDimitry Andric 230b57cec5SDimitry Andric class ContinuationIndenter; 240b57cec5SDimitry Andric class WhitespaceManager; 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric class UnwrappedLineFormatter { 270b57cec5SDimitry Andric public: UnwrappedLineFormatter(ContinuationIndenter * Indenter,WhitespaceManager * Whitespaces,const FormatStyle & Style,const AdditionalKeywords & Keywords,const SourceManager & SourceMgr,FormattingAttemptStatus * Status)280b57cec5SDimitry Andric UnwrappedLineFormatter(ContinuationIndenter *Indenter, 290b57cec5SDimitry Andric WhitespaceManager *Whitespaces, 300b57cec5SDimitry Andric const FormatStyle &Style, 310b57cec5SDimitry Andric const AdditionalKeywords &Keywords, 320b57cec5SDimitry Andric const SourceManager &SourceMgr, 330b57cec5SDimitry Andric FormattingAttemptStatus *Status) 340b57cec5SDimitry Andric : Indenter(Indenter), Whitespaces(Whitespaces), Style(Style), 350b57cec5SDimitry Andric Keywords(Keywords), SourceMgr(SourceMgr), Status(Status) {} 360b57cec5SDimitry Andric 370b57cec5SDimitry Andric /// Format the current block and return the penalty. 380b57cec5SDimitry Andric unsigned format(const SmallVectorImpl<AnnotatedLine *> &Lines, 390b57cec5SDimitry Andric bool DryRun = false, int AdditionalIndent = 0, 400b57cec5SDimitry Andric bool FixBadIndentation = false, unsigned FirstStartColumn = 0, 410b57cec5SDimitry Andric unsigned NextStartColumn = 0, unsigned LastStartColumn = 0); 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric private: 440b57cec5SDimitry Andric /// Add a new line and the required indent before the first Token 450b57cec5SDimitry Andric /// of the \c UnwrappedLine if there was no structural parsing error. 460b57cec5SDimitry Andric void formatFirstToken(const AnnotatedLine &Line, 470b57cec5SDimitry Andric const AnnotatedLine *PreviousLine, 48fe6060f1SDimitry Andric const AnnotatedLine *PrevPrevLine, 490b57cec5SDimitry Andric const SmallVectorImpl<AnnotatedLine *> &Lines, 500b57cec5SDimitry Andric unsigned Indent, unsigned NewlineIndent); 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric /// Returns the column limit for a line, taking into account whether we 530b57cec5SDimitry Andric /// need an escaped newline due to a continued preprocessor directive. 540b57cec5SDimitry Andric unsigned getColumnLimit(bool InPPDirective, 550b57cec5SDimitry Andric const AnnotatedLine *NextLine) const; 560b57cec5SDimitry Andric 570b57cec5SDimitry Andric // Cache to store the penalty of formatting a vector of AnnotatedLines 580b57cec5SDimitry Andric // starting from a specific additional offset. Improves performance if there 590b57cec5SDimitry Andric // are many nested blocks. 600b57cec5SDimitry Andric std::map<std::pair<const SmallVectorImpl<AnnotatedLine *> *, unsigned>, 610b57cec5SDimitry Andric unsigned> 620b57cec5SDimitry Andric PenaltyCache; 630b57cec5SDimitry Andric 640b57cec5SDimitry Andric ContinuationIndenter *Indenter; 650b57cec5SDimitry Andric WhitespaceManager *Whitespaces; 660b57cec5SDimitry Andric const FormatStyle &Style; 670b57cec5SDimitry Andric const AdditionalKeywords &Keywords; 680b57cec5SDimitry Andric const SourceManager &SourceMgr; 690b57cec5SDimitry Andric FormattingAttemptStatus *Status; 700b57cec5SDimitry Andric }; 710b57cec5SDimitry Andric } // end namespace format 720b57cec5SDimitry Andric } // end namespace clang 730b57cec5SDimitry Andric 740b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEFORMATTER_H 75