aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Format/ContinuationIndenter.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-03-20 11:40:34 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-05-14 11:43:05 +0000
commit349cc55c9796c4596a5b9904cd3281af295f878f (patch)
tree410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/clang/lib/Format/ContinuationIndenter.cpp
parentcb2ae6163174b90e999326ecec3699ee093a5d43 (diff)
parentc0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff)
Diffstat (limited to 'contrib/llvm-project/clang/lib/Format/ContinuationIndenter.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Format/ContinuationIndenter.cpp29
1 files changed, 22 insertions, 7 deletions
diff --git a/contrib/llvm-project/clang/lib/Format/ContinuationIndenter.cpp b/contrib/llvm-project/clang/lib/Format/ContinuationIndenter.cpp
index 8fbc15f27922..1e4f5690ef24 100644
--- a/contrib/llvm-project/clang/lib/Format/ContinuationIndenter.cpp
+++ b/contrib/llvm-project/clang/lib/Format/ContinuationIndenter.cpp
@@ -14,10 +14,12 @@
#include "ContinuationIndenter.h"
#include "BreakableToken.h"
#include "FormatInternal.h"
+#include "FormatToken.h"
#include "WhitespaceManager.h"
#include "clang/Basic/OperatorPrecedence.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Format/Format.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Debug.h"
#define DEBUG_TYPE "format-indenter"
@@ -491,11 +493,24 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
return true;
}
+ // Break after the closing parenthesis of TypeScript decorators before
+ // functions, getters and setters.
+ static const llvm::StringSet<> BreakBeforeDecoratedTokens = {"get", "set",
+ "function"};
+ if (Style.Language == FormatStyle::LK_JavaScript &&
+ BreakBeforeDecoratedTokens.contains(Current.TokenText) &&
+ Previous.is(tok::r_paren) && Previous.is(TT_JavaAnnotation)) {
+ return true;
+ }
+
// If the return type spans multiple lines, wrap before the function name.
if (((Current.is(TT_FunctionDeclarationName) &&
// Don't break before a C# function when no break after return type
(!Style.isCSharp() ||
- Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None)) ||
+ Style.AlwaysBreakAfterReturnType != FormatStyle::RTBS_None) &&
+ // Don't always break between a JavaScript `function` and the function
+ // name.
+ Style.Language != FormatStyle::LK_JavaScript) ||
(Current.is(tok::kw_operator) && !Previous.is(tok::coloncolon))) &&
!Previous.is(tok::kw_template) && State.Stack.back().BreakBeforeParameter)
return true;
@@ -943,7 +958,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
State.Line->MustBeDeclaration) ||
(!Style.AllowAllArgumentsOnNextLine &&
!State.Line->MustBeDeclaration) ||
- (!Style.AllowAllConstructorInitializersOnNextLine &&
+ (Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine &&
PreviousIsBreakingCtorInitializerColon) ||
Previous.is(TT_DictLiteral))
State.Stack.back().BreakBeforeParameter = true;
@@ -952,7 +967,7 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
// and we allow all arguments on the next line, we should not break
// before the next parameter.
if (PreviousIsBreakingCtorInitializerColon &&
- Style.AllowAllConstructorInitializersOnNextLine)
+ Style.PackConstructorInitializers == FormatStyle::PCIS_NextLine)
State.Stack.back().BreakBeforeParameter = false;
}
@@ -1232,10 +1247,10 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
? 0
: 2);
State.Stack.back().NestedBlockIndent = State.Stack.back().Indent;
- if (Style.ConstructorInitializerAllOnOneLineOrOnePerLine) {
+ if (Style.PackConstructorInitializers > FormatStyle::PCIS_BinPack) {
State.Stack.back().AvoidBinPacking = true;
State.Stack.back().BreakBeforeParameter =
- !Style.AllowAllConstructorInitializersOnNextLine;
+ Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine;
} else {
State.Stack.back().BreakBeforeParameter = false;
}
@@ -1245,7 +1260,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
State.Stack.back().Indent =
State.FirstIndent + Style.ConstructorInitializerIndentWidth;
State.Stack.back().NestedBlockIndent = State.Stack.back().Indent;
- if (Style.ConstructorInitializerAllOnOneLineOrOnePerLine)
+ if (Style.PackConstructorInitializers > FormatStyle::PCIS_BinPack)
State.Stack.back().AvoidBinPacking = true;
}
if (Current.is(TT_InheritanceColon))
@@ -1592,7 +1607,7 @@ void ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
// BreakBeforeParameter is calculated based on an incorrect assumption
// (it is checked whether the whole expression fits into one line without
// considering a line break inside a message receiver).
- // We check whether arguements fit after receiver scope closer (into the same
+ // We check whether arguments fit after receiver scope closer (into the same
// line).
if (State.Stack.back().BreakBeforeParameter && Current.MatchingParen &&
Current.MatchingParen->Previous) {