xref: /freebsd/contrib/llvm-project/clang/lib/Format/UnwrappedLineParser.h (revision 753f127f3ace09432b2baeffd71a308760641a62)
10b57cec5SDimitry Andric //===--- UnwrappedLineParser.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
100b57cec5SDimitry Andric /// This file contains the declaration of the UnwrappedLineParser,
110b57cec5SDimitry Andric /// which turns a stream of tokens into UnwrappedLines.
120b57cec5SDimitry Andric ///
130b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
160b57cec5SDimitry Andric #define LLVM_CLANG_LIB_FORMAT_UNWRAPPEDLINEPARSER_H
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #include "FormatToken.h"
190b57cec5SDimitry Andric #include "clang/Basic/IdentifierTable.h"
200b57cec5SDimitry Andric #include "clang/Format/Format.h"
2104eeddc0SDimitry Andric #include "llvm/ADT/BitVector.h"
220b57cec5SDimitry Andric #include "llvm/Support/Regex.h"
23*753f127fSDimitry Andric #include <list>
240b57cec5SDimitry Andric #include <stack>
25349cc55cSDimitry Andric #include <vector>
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric namespace clang {
280b57cec5SDimitry Andric namespace format {
290b57cec5SDimitry Andric 
300b57cec5SDimitry Andric struct UnwrappedLineNode;
310b57cec5SDimitry Andric 
320b57cec5SDimitry Andric /// An unwrapped line is a sequence of \c Token, that we would like to
330b57cec5SDimitry Andric /// put on a single line if there was no column limit.
340b57cec5SDimitry Andric ///
350b57cec5SDimitry Andric /// This is used as a main interface between the \c UnwrappedLineParser and the
360b57cec5SDimitry Andric /// \c UnwrappedLineFormatter. The key property is that changing the formatting
370b57cec5SDimitry Andric /// within an unwrapped line does not affect any other unwrapped lines.
380b57cec5SDimitry Andric struct UnwrappedLine {
390b57cec5SDimitry Andric   UnwrappedLine();
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric   /// The \c Tokens comprising this \c UnwrappedLine.
42*753f127fSDimitry Andric   std::list<UnwrappedLineNode> Tokens;
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric   /// The indent level of the \c UnwrappedLine.
450b57cec5SDimitry Andric   unsigned Level;
460b57cec5SDimitry Andric 
470b57cec5SDimitry Andric   /// Whether this \c UnwrappedLine is part of a preprocessor directive.
480b57cec5SDimitry Andric   bool InPPDirective;
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric   bool MustBeDeclaration;
510b57cec5SDimitry Andric 
520b57cec5SDimitry Andric   /// If this \c UnwrappedLine closes a block in a sequence of lines,
530b57cec5SDimitry Andric   /// \c MatchingOpeningBlockLineIndex stores the index of the corresponding
540b57cec5SDimitry Andric   /// opening line. Otherwise, \c MatchingOpeningBlockLineIndex must be
550b57cec5SDimitry Andric   /// \c kInvalidIndex.
560b57cec5SDimitry Andric   size_t MatchingOpeningBlockLineIndex = kInvalidIndex;
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric   /// If this \c UnwrappedLine opens a block, stores the index of the
590b57cec5SDimitry Andric   /// line with the corresponding closing brace.
600b57cec5SDimitry Andric   size_t MatchingClosingBlockLineIndex = kInvalidIndex;
610b57cec5SDimitry Andric 
620b57cec5SDimitry Andric   static const size_t kInvalidIndex = -1;
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric   unsigned FirstStartColumn = 0;
650b57cec5SDimitry Andric };
660b57cec5SDimitry Andric 
670b57cec5SDimitry Andric class UnwrappedLineConsumer {
680b57cec5SDimitry Andric public:
690b57cec5SDimitry Andric   virtual ~UnwrappedLineConsumer() {}
700b57cec5SDimitry Andric   virtual void consumeUnwrappedLine(const UnwrappedLine &Line) = 0;
710b57cec5SDimitry Andric   virtual void finishRun() = 0;
720b57cec5SDimitry Andric };
730b57cec5SDimitry Andric 
740b57cec5SDimitry Andric class FormatTokenSource;
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric class UnwrappedLineParser {
770b57cec5SDimitry Andric public:
780b57cec5SDimitry Andric   UnwrappedLineParser(const FormatStyle &Style,
790b57cec5SDimitry Andric                       const AdditionalKeywords &Keywords,
800b57cec5SDimitry Andric                       unsigned FirstStartColumn, ArrayRef<FormatToken *> Tokens,
810b57cec5SDimitry Andric                       UnwrappedLineConsumer &Callback);
820b57cec5SDimitry Andric 
830b57cec5SDimitry Andric   void parse();
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric private:
8604eeddc0SDimitry Andric   enum class IfStmtKind {
8704eeddc0SDimitry Andric     NotIf,   // Not an if statement.
8804eeddc0SDimitry Andric     IfOnly,  // An if statement without the else clause.
8904eeddc0SDimitry Andric     IfElse,  // An if statement followed by else but not else if.
9004eeddc0SDimitry Andric     IfElseIf // An if statement followed by else if.
9104eeddc0SDimitry Andric   };
9204eeddc0SDimitry Andric 
930b57cec5SDimitry Andric   void reset();
940b57cec5SDimitry Andric   void parseFile();
9504eeddc0SDimitry Andric   bool precededByCommentOrPPDirective() const;
9681ad6265SDimitry Andric   bool parseLevel(const FormatToken *OpeningBrace = nullptr,
9781ad6265SDimitry Andric                   bool CanContainBracedList = true,
9881ad6265SDimitry Andric                   TokenType NextLBracesType = TT_Unknown,
9981ad6265SDimitry Andric                   IfStmtKind *IfKind = nullptr,
10081ad6265SDimitry Andric                   FormatToken **IfLeftBrace = nullptr);
10181ad6265SDimitry Andric   bool mightFitOnOneLine(UnwrappedLine &Line,
10281ad6265SDimitry Andric                          const FormatToken *OpeningBrace = nullptr) const;
10381ad6265SDimitry Andric   FormatToken *parseBlock(bool MustBeDeclaration = false,
10481ad6265SDimitry Andric                           unsigned AddLevels = 1u, bool MunchSemi = true,
10581ad6265SDimitry Andric                           bool KeepBraces = true, IfStmtKind *IfKind = nullptr,
10681ad6265SDimitry Andric                           bool UnindentWhitesmithsBraces = false,
10781ad6265SDimitry Andric                           bool CanContainBracedList = true,
10881ad6265SDimitry Andric                           TokenType NextLBracesType = TT_Unknown);
10981ad6265SDimitry Andric   void parseChildBlock(bool CanContainBracedList = true,
11081ad6265SDimitry Andric                        TokenType NextLBracesType = TT_Unknown);
1110b57cec5SDimitry Andric   void parsePPDirective();
1120b57cec5SDimitry Andric   void parsePPDefine();
1130b57cec5SDimitry Andric   void parsePPIf(bool IfDef);
1140b57cec5SDimitry Andric   void parsePPElIf();
1150b57cec5SDimitry Andric   void parsePPElse();
1160b57cec5SDimitry Andric   void parsePPEndIf();
1170b57cec5SDimitry Andric   void parsePPUnknown();
1180b57cec5SDimitry Andric   void readTokenWithJavaScriptASI();
11981ad6265SDimitry Andric   void parseStructuralElement(bool IsTopLevel = false,
12081ad6265SDimitry Andric                               TokenType NextLBracesType = TT_Unknown,
12181ad6265SDimitry Andric                               IfStmtKind *IfKind = nullptr,
12281ad6265SDimitry Andric                               FormatToken **IfLeftBrace = nullptr,
12381ad6265SDimitry Andric                               bool *HasDoWhile = nullptr,
12481ad6265SDimitry Andric                               bool *HasLabel = nullptr);
1250b57cec5SDimitry Andric   bool tryToParseBracedList();
1265ffd83dbSDimitry Andric   bool parseBracedList(bool ContinueOnSemicolons = false, bool IsEnum = false,
1270b57cec5SDimitry Andric                        tok::TokenKind ClosingBraceKind = tok::r_brace);
12881ad6265SDimitry Andric   void parseParens(TokenType AmpAmpTokenType = TT_Unknown);
1290b57cec5SDimitry Andric   void parseSquare(bool LambdaIntroducer = false);
13004eeddc0SDimitry Andric   void keepAncestorBraces();
13181ad6265SDimitry Andric   void parseUnbracedBody(bool CheckEOF = false);
13281ad6265SDimitry Andric   void handleAttributes();
13381ad6265SDimitry Andric   bool handleCppAttributes();
13404eeddc0SDimitry Andric   FormatToken *parseIfThenElse(IfStmtKind *IfKind, bool KeepBraces = false);
1350b57cec5SDimitry Andric   void parseTryCatch();
13681ad6265SDimitry Andric   void parseLoopBody(bool KeepBraces, bool WrapRightBrace);
1370b57cec5SDimitry Andric   void parseForOrWhileLoop();
1380b57cec5SDimitry Andric   void parseDoWhile();
139a7dea167SDimitry Andric   void parseLabel(bool LeftAlignLabel = false);
1400b57cec5SDimitry Andric   void parseCaseLabel();
1410b57cec5SDimitry Andric   void parseSwitch();
1420b57cec5SDimitry Andric   void parseNamespace();
1434824e7fdSDimitry Andric   void parseModuleImport();
1440b57cec5SDimitry Andric   void parseNew();
1450b57cec5SDimitry Andric   void parseAccessSpecifier();
1460b57cec5SDimitry Andric   bool parseEnum();
147fe6060f1SDimitry Andric   bool parseStructLike();
148e8d8bef9SDimitry Andric   void parseConcept();
14981ad6265SDimitry Andric   bool parseRequires();
15081ad6265SDimitry Andric   void parseRequiresClause(FormatToken *RequiresToken);
15181ad6265SDimitry Andric   void parseRequiresExpression(FormatToken *RequiresToken);
15281ad6265SDimitry Andric   void parseConstraintExpression();
1530b57cec5SDimitry Andric   void parseJavaEnumBody();
1540b57cec5SDimitry Andric   // Parses a record (aka class) as a top level element. If ParseAsExpr is true,
1550b57cec5SDimitry Andric   // parses the record as a child block, i.e. if the class declaration is an
1560b57cec5SDimitry Andric   // expression.
1570b57cec5SDimitry Andric   void parseRecord(bool ParseAsExpr = false);
158e8d8bef9SDimitry Andric   void parseObjCLightweightGenerics();
1590b57cec5SDimitry Andric   void parseObjCMethod();
1600b57cec5SDimitry Andric   void parseObjCProtocolList();
1610b57cec5SDimitry Andric   void parseObjCUntilAtEnd();
1620b57cec5SDimitry Andric   void parseObjCInterfaceOrImplementation();
1630b57cec5SDimitry Andric   bool parseObjCProtocol();
1640b57cec5SDimitry Andric   void parseJavaScriptEs6ImportExport();
1650b57cec5SDimitry Andric   void parseStatementMacro();
1665ffd83dbSDimitry Andric   void parseCSharpAttribute();
1675ffd83dbSDimitry Andric   // Parse a C# generic type constraint: `where T : IComparable<T>`.
1685ffd83dbSDimitry Andric   // See:
1695ffd83dbSDimitry Andric   // https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/where-generic-type-constraint
1705ffd83dbSDimitry Andric   void parseCSharpGenericTypeConstraint();
1710b57cec5SDimitry Andric   bool tryToParseLambda();
1720eae32dcSDimitry Andric   bool tryToParseChildBlock();
1730b57cec5SDimitry Andric   bool tryToParseLambdaIntroducer();
1745ffd83dbSDimitry Andric   bool tryToParsePropertyAccessor();
1750b57cec5SDimitry Andric   void tryToParseJSFunction();
1765ffd83dbSDimitry Andric   bool tryToParseSimpleAttribute();
17723408297SDimitry Andric 
17823408297SDimitry Andric   // Used by addUnwrappedLine to denote whether to keep or remove a level
17923408297SDimitry Andric   // when resetting the line state.
18023408297SDimitry Andric   enum class LineLevel { Remove, Keep };
18123408297SDimitry Andric 
18223408297SDimitry Andric   void addUnwrappedLine(LineLevel AdjustLevel = LineLevel::Remove);
1830b57cec5SDimitry Andric   bool eof() const;
1840b57cec5SDimitry Andric   // LevelDifference is the difference of levels after and before the current
1850b57cec5SDimitry Andric   // token. For example:
1860b57cec5SDimitry Andric   // - if the token is '{' and opens a block, LevelDifference is 1.
1870b57cec5SDimitry Andric   // - if the token is '}' and closes a block, LevelDifference is -1.
1880b57cec5SDimitry Andric   void nextToken(int LevelDifference = 0);
1890b57cec5SDimitry Andric   void readToken(int LevelDifference = 0);
1900b57cec5SDimitry Andric 
1910b57cec5SDimitry Andric   // Decides which comment tokens should be added to the current line and which
1920b57cec5SDimitry Andric   // should be added as comments before the next token.
1930b57cec5SDimitry Andric   //
1940b57cec5SDimitry Andric   // Comments specifies the sequence of comment tokens to analyze. They get
1950b57cec5SDimitry Andric   // either pushed to the current line or added to the comments before the next
1960b57cec5SDimitry Andric   // token.
1970b57cec5SDimitry Andric   //
1980b57cec5SDimitry Andric   // NextTok specifies the next token. A null pointer NextTok is supported, and
1990b57cec5SDimitry Andric   // signifies either the absence of a next token, or that the next token
2000b57cec5SDimitry Andric   // shouldn't be taken into accunt for the analysis.
2010b57cec5SDimitry Andric   void distributeComments(const SmallVectorImpl<FormatToken *> &Comments,
2020b57cec5SDimitry Andric                           const FormatToken *NextTok);
2030b57cec5SDimitry Andric 
2040b57cec5SDimitry Andric   // Adds the comment preceding the next token to unwrapped lines.
2050b57cec5SDimitry Andric   void flushComments(bool NewlineBeforeNext);
2060b57cec5SDimitry Andric   void pushToken(FormatToken *Tok);
2070b57cec5SDimitry Andric   void calculateBraceTypes(bool ExpectClassBody = false);
2080b57cec5SDimitry Andric 
2090b57cec5SDimitry Andric   // Marks a conditional compilation edge (for example, an '#if', '#ifdef',
2100b57cec5SDimitry Andric   // '#else' or merge conflict marker). If 'Unreachable' is true, assumes
2110b57cec5SDimitry Andric   // this branch either cannot be taken (for example '#if false'), or should
2120b57cec5SDimitry Andric   // not be taken in this round.
2130b57cec5SDimitry Andric   void conditionalCompilationCondition(bool Unreachable);
2140b57cec5SDimitry Andric   void conditionalCompilationStart(bool Unreachable);
2150b57cec5SDimitry Andric   void conditionalCompilationAlternative();
2160b57cec5SDimitry Andric   void conditionalCompilationEnd();
2170b57cec5SDimitry Andric 
2180b57cec5SDimitry Andric   bool isOnNewLine(const FormatToken &FormatTok);
2190b57cec5SDimitry Andric 
2200b57cec5SDimitry Andric   // Compute hash of the current preprocessor branch.
2210b57cec5SDimitry Andric   // This is used to identify the different branches, and thus track if block
2220b57cec5SDimitry Andric   // open and close in the same branch.
2230b57cec5SDimitry Andric   size_t computePPHash() const;
2240b57cec5SDimitry Andric 
2250b57cec5SDimitry Andric   // FIXME: We are constantly running into bugs where Line.Level is incorrectly
2260b57cec5SDimitry Andric   // subtracted from beyond 0. Introduce a method to subtract from Line.Level
2270b57cec5SDimitry Andric   // and use that everywhere in the Parser.
2280b57cec5SDimitry Andric   std::unique_ptr<UnwrappedLine> Line;
2290b57cec5SDimitry Andric 
2300b57cec5SDimitry Andric   // Comments are sorted into unwrapped lines by whether they are in the same
2310b57cec5SDimitry Andric   // line as the previous token, or not. If not, they belong to the next token.
2320b57cec5SDimitry Andric   // Since the next token might already be in a new unwrapped line, we need to
2330b57cec5SDimitry Andric   // store the comments belonging to that token.
2340b57cec5SDimitry Andric   SmallVector<FormatToken *, 1> CommentsBeforeNextToken;
2350b57cec5SDimitry Andric   FormatToken *FormatTok;
2360b57cec5SDimitry Andric   bool MustBreakBeforeNextToken;
2370b57cec5SDimitry Andric 
2380b57cec5SDimitry Andric   // The parsed lines. Only added to through \c CurrentLines.
2390b57cec5SDimitry Andric   SmallVector<UnwrappedLine, 8> Lines;
2400b57cec5SDimitry Andric 
2410b57cec5SDimitry Andric   // Preprocessor directives are parsed out-of-order from other unwrapped lines.
2420b57cec5SDimitry Andric   // Thus, we need to keep a list of preprocessor directives to be reported
2430b57cec5SDimitry Andric   // after an unwrapped line that has been started was finished.
2440b57cec5SDimitry Andric   SmallVector<UnwrappedLine, 4> PreprocessorDirectives;
2450b57cec5SDimitry Andric 
2460b57cec5SDimitry Andric   // New unwrapped lines are added via CurrentLines.
2470b57cec5SDimitry Andric   // Usually points to \c &Lines. While parsing a preprocessor directive when
2480b57cec5SDimitry Andric   // there is an unfinished previous unwrapped line, will point to
2490b57cec5SDimitry Andric   // \c &PreprocessorDirectives.
2500b57cec5SDimitry Andric   SmallVectorImpl<UnwrappedLine> *CurrentLines;
2510b57cec5SDimitry Andric 
2520b57cec5SDimitry Andric   // We store for each line whether it must be a declaration depending on
2530b57cec5SDimitry Andric   // whether we are in a compound statement or not.
25404eeddc0SDimitry Andric   llvm::BitVector DeclarationScopeStack;
2550b57cec5SDimitry Andric 
2560b57cec5SDimitry Andric   const FormatStyle &Style;
2570b57cec5SDimitry Andric   const AdditionalKeywords &Keywords;
2580b57cec5SDimitry Andric 
2590b57cec5SDimitry Andric   llvm::Regex CommentPragmasRegex;
2600b57cec5SDimitry Andric 
2610b57cec5SDimitry Andric   FormatTokenSource *Tokens;
2620b57cec5SDimitry Andric   UnwrappedLineConsumer &Callback;
2630b57cec5SDimitry Andric 
2640b57cec5SDimitry Andric   // FIXME: This is a temporary measure until we have reworked the ownership
2650b57cec5SDimitry Andric   // of the format tokens. The goal is to have the actual tokens created and
2660b57cec5SDimitry Andric   // owned outside of and handed into the UnwrappedLineParser.
2670b57cec5SDimitry Andric   ArrayRef<FormatToken *> AllTokens;
2680b57cec5SDimitry Andric 
26904eeddc0SDimitry Andric   // Keeps a stack of the states of nested control statements (true if the
27004eeddc0SDimitry Andric   // statement contains more than some predefined number of nested statements).
27104eeddc0SDimitry Andric   SmallVector<bool, 8> NestedTooDeep;
27204eeddc0SDimitry Andric 
2730b57cec5SDimitry Andric   // Represents preprocessor branch type, so we can find matching
2740b57cec5SDimitry Andric   // #if/#else/#endif directives.
2750b57cec5SDimitry Andric   enum PPBranchKind {
2760b57cec5SDimitry Andric     PP_Conditional, // Any #if, #ifdef, #ifndef, #elif, block outside #if 0
2770b57cec5SDimitry Andric     PP_Unreachable  // #if 0 or a conditional preprocessor block inside #if 0
2780b57cec5SDimitry Andric   };
2790b57cec5SDimitry Andric 
2800b57cec5SDimitry Andric   struct PPBranch {
2810b57cec5SDimitry Andric     PPBranch(PPBranchKind Kind, size_t Line) : Kind(Kind), Line(Line) {}
2820b57cec5SDimitry Andric     PPBranchKind Kind;
2830b57cec5SDimitry Andric     size_t Line;
2840b57cec5SDimitry Andric   };
2850b57cec5SDimitry Andric 
2860b57cec5SDimitry Andric   // Keeps a stack of currently active preprocessor branching directives.
2870b57cec5SDimitry Andric   SmallVector<PPBranch, 16> PPStack;
2880b57cec5SDimitry Andric 
2890b57cec5SDimitry Andric   // The \c UnwrappedLineParser re-parses the code for each combination
2900b57cec5SDimitry Andric   // of preprocessor branches that can be taken.
2910b57cec5SDimitry Andric   // To that end, we take the same branch (#if, #else, or one of the #elif
2920b57cec5SDimitry Andric   // branches) for each nesting level of preprocessor branches.
2930b57cec5SDimitry Andric   // \c PPBranchLevel stores the current nesting level of preprocessor
2940b57cec5SDimitry Andric   // branches during one pass over the code.
2950b57cec5SDimitry Andric   int PPBranchLevel;
2960b57cec5SDimitry Andric 
2970b57cec5SDimitry Andric   // Contains the current branch (#if, #else or one of the #elif branches)
2980b57cec5SDimitry Andric   // for each nesting level.
2990b57cec5SDimitry Andric   SmallVector<int, 8> PPLevelBranchIndex;
3000b57cec5SDimitry Andric 
3010b57cec5SDimitry Andric   // Contains the maximum number of branches at each nesting level.
3020b57cec5SDimitry Andric   SmallVector<int, 8> PPLevelBranchCount;
3030b57cec5SDimitry Andric 
3040b57cec5SDimitry Andric   // Contains the number of branches per nesting level we are currently
3050b57cec5SDimitry Andric   // in while parsing a preprocessor branch sequence.
3060b57cec5SDimitry Andric   // This is used to update PPLevelBranchCount at the end of a branch
3070b57cec5SDimitry Andric   // sequence.
3080b57cec5SDimitry Andric   std::stack<int> PPChainBranchIndex;
3090b57cec5SDimitry Andric 
3100b57cec5SDimitry Andric   // Include guard search state. Used to fixup preprocessor indent levels
3110b57cec5SDimitry Andric   // so that include guards do not participate in indentation.
3120b57cec5SDimitry Andric   enum IncludeGuardState {
3130b57cec5SDimitry Andric     IG_Inited,   // Search started, looking for #ifndef.
3140b57cec5SDimitry Andric     IG_IfNdefed, // #ifndef found, IncludeGuardToken points to condition.
3150b57cec5SDimitry Andric     IG_Defined,  // Matching #define found, checking other requirements.
3160b57cec5SDimitry Andric     IG_Found,    // All requirements met, need to fix indents.
3170b57cec5SDimitry Andric     IG_Rejected, // Search failed or never started.
3180b57cec5SDimitry Andric   };
3190b57cec5SDimitry Andric 
3200b57cec5SDimitry Andric   // Current state of include guard search.
3210b57cec5SDimitry Andric   IncludeGuardState IncludeGuard;
3220b57cec5SDimitry Andric 
3230b57cec5SDimitry Andric   // Points to the #ifndef condition for a potential include guard. Null unless
3240b57cec5SDimitry Andric   // IncludeGuardState == IG_IfNdefed.
3250b57cec5SDimitry Andric   FormatToken *IncludeGuardToken;
3260b57cec5SDimitry Andric 
3270b57cec5SDimitry Andric   // Contains the first start column where the source begins. This is zero for
3280b57cec5SDimitry Andric   // normal source code and may be nonzero when formatting a code fragment that
3290b57cec5SDimitry Andric   // does not start at the beginning of the file.
3300b57cec5SDimitry Andric   unsigned FirstStartColumn;
3310b57cec5SDimitry Andric 
3320b57cec5SDimitry Andric   friend class ScopedLineState;
3330b57cec5SDimitry Andric   friend class CompoundStatementIndenter;
3340b57cec5SDimitry Andric };
3350b57cec5SDimitry Andric 
3360b57cec5SDimitry Andric struct UnwrappedLineNode {
3370b57cec5SDimitry Andric   UnwrappedLineNode() : Tok(nullptr) {}
3380b57cec5SDimitry Andric   UnwrappedLineNode(FormatToken *Tok) : Tok(Tok) {}
3390b57cec5SDimitry Andric 
3400b57cec5SDimitry Andric   FormatToken *Tok;
3410b57cec5SDimitry Andric   SmallVector<UnwrappedLine, 0> Children;
3420b57cec5SDimitry Andric };
3430b57cec5SDimitry Andric 
3440b57cec5SDimitry Andric inline UnwrappedLine::UnwrappedLine()
3450b57cec5SDimitry Andric     : Level(0), InPPDirective(false), MustBeDeclaration(false),
3460b57cec5SDimitry Andric       MatchingOpeningBlockLineIndex(kInvalidIndex) {}
3470b57cec5SDimitry Andric 
3480b57cec5SDimitry Andric } // end namespace format
3490b57cec5SDimitry Andric } // end namespace clang
3500b57cec5SDimitry Andric 
3510b57cec5SDimitry Andric #endif
352