diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.h')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.h | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.h b/contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.h index b317565..0969a8c 100644 --- a/contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.h +++ b/contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.h @@ -18,6 +18,7 @@ #include "Encoding.h" #include "clang/Format/Format.h" +#include "llvm/Support/Regex.h" namespace clang { class SourceManager; @@ -72,6 +73,18 @@ private: /// accordingly. unsigned moveStateToNextToken(LineState &State, bool DryRun, bool Newline); + /// \brief Update 'State' according to the next token's fake left parentheses. + void moveStatePastFakeLParens(LineState &State, bool Newline); + /// \brief Update 'State' according to the next token's fake r_parens. + void moveStatePastFakeRParens(LineState &State); + + /// \brief Update 'State' according to the next token being one of "(<{[". + void moveStatePastScopeOpener(LineState &State, bool Newline); + /// \brief Update 'State' according to the next token being one of ")>}]". + void moveStatePastScopeCloser(LineState &State); + /// \brief Update 'State' with the next token opening a nested block. + void moveStateToNewBlock(LineState &State); + /// \brief If the current token sticks out over the end of the line, break /// it if possible. /// @@ -103,6 +116,9 @@ private: /// \c Replacement. unsigned addTokenOnNewLine(LineState &State, bool DryRun); + /// \brief Calculate the new column for a line wrap before the next token. + unsigned getNewLineColumn(const LineState &State); + /// \brief Adds a multiline token to the \p State. /// /// \returns Extra penalty for the first line of the literal: last line is @@ -115,13 +131,14 @@ private: /// /// This includes implicitly concatenated strings, strings that will be broken /// by clang-format and string literals with escaped newlines. - bool NextIsMultilineString(const LineState &State); + bool nextIsMultilineString(const LineState &State); FormatStyle Style; SourceManager &SourceMgr; WhitespaceManager &Whitespaces; encoding::Encoding Encoding; bool BinPackInconclusiveFunctions; + llvm::Regex CommentPragmasRegex; }; struct ParenState { @@ -130,10 +147,12 @@ struct ParenState { : Indent(Indent), IndentLevel(IndentLevel), LastSpace(LastSpace), FirstLessLess(0), BreakBeforeClosingBrace(false), QuestionColumn(0), AvoidBinPacking(AvoidBinPacking), BreakBeforeParameter(false), - NoLineBreak(NoLineBreak), ColonPos(0), StartOfFunctionCall(0), - StartOfArraySubscripts(0), NestedNameSpecifierContinuation(0), - CallContinuation(0), VariablePos(0), ContainsLineBreak(false), - ContainsUnwrappedBuilder(0) {} + NoLineBreak(NoLineBreak), LastOperatorWrapped(true), ColonPos(0), + StartOfFunctionCall(0), StartOfArraySubscripts(0), + NestedNameSpecifierContinuation(0), CallContinuation(0), VariablePos(0), + ContainsLineBreak(false), ContainsUnwrappedBuilder(0), + AlignColons(true), ObjCSelectorNameFound(false), + HasMultipleNestedBlocks(false), JSFunctionInlined(false) {} /// \brief The position to which a specific parenthesis level needs to be /// indented. @@ -176,6 +195,10 @@ struct ParenState { /// \brief Line breaking in this context would break a formatting rule. bool NoLineBreak; + /// \brief True if the last binary operator on this level was wrapped to the + /// next line. + bool LastOperatorWrapped; + /// \brief The position of the colon in an ObjC method declaration/call. unsigned ColonPos; @@ -210,6 +233,30 @@ struct ParenState { /// builder-type call on one line. bool ContainsUnwrappedBuilder; + /// \brief \c true if the colons of the curren ObjC method expression should + /// be aligned. + /// + /// Not considered for memoization as it will always have the same value at + /// the same token. + bool AlignColons; + + /// \brief \c true if at least one selector name was found in the current + /// ObjC method expression. + /// + /// Not considered for memoization as it will always have the same value at + /// the same token. + bool ObjCSelectorNameFound; + + /// \brief \c true if there are multiple nested blocks inside these parens. + /// + /// Not considered for memoization as it will always have the same value at + /// the same token. + bool HasMultipleNestedBlocks; + + // \brief The previous JavaScript 'function' keyword is not wrapped to a new + // line. + bool JSFunctionInlined; + bool operator<(const ParenState &Other) const { if (Indent != Other.Indent) return Indent < Other.Indent; @@ -227,6 +274,8 @@ struct ParenState { return BreakBeforeParameter; if (NoLineBreak != Other.NoLineBreak) return NoLineBreak; + if (LastOperatorWrapped != Other.LastOperatorWrapped) + return LastOperatorWrapped; if (ColonPos != Other.ColonPos) return ColonPos < Other.ColonPos; if (StartOfFunctionCall != Other.StartOfFunctionCall) @@ -241,6 +290,8 @@ struct ParenState { return ContainsLineBreak < Other.ContainsLineBreak; if (ContainsUnwrappedBuilder != Other.ContainsUnwrappedBuilder) return ContainsUnwrappedBuilder < Other.ContainsUnwrappedBuilder; + if (JSFunctionInlined != Other.JSFunctionInlined) + return JSFunctionInlined < Other.JSFunctionInlined; return false; } }; @@ -258,13 +309,10 @@ struct LineState { /// \brief \c true if this line contains a continued for-loop section. bool LineContainsContinuedForLoopSection; - /// \brief The level of nesting inside (), [], <> and {}. - unsigned ParenLevel; - - /// \brief The \c ParenLevel at the start of this line. + /// \brief The \c NestingLevel at the start of this line. unsigned StartOfLineLevel; - /// \brief The lowest \c ParenLevel on the current line. + /// \brief The lowest \c NestingLevel on the current line. unsigned LowestLevelOnLine; /// \brief The start column of the string literal, if we're in a string @@ -307,8 +355,6 @@ struct LineState { if (LineContainsContinuedForLoopSection != Other.LineContainsContinuedForLoopSection) return LineContainsContinuedForLoopSection; - if (ParenLevel != Other.ParenLevel) - return ParenLevel < Other.ParenLevel; if (StartOfLineLevel != Other.StartOfLineLevel) return StartOfLineLevel < Other.StartOfLineLevel; if (LowestLevelOnLine != Other.LowestLevelOnLine) |