mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2024-11-23 12:09:51 +00:00
66 lines
3.0 KiB
Diff
66 lines
3.0 KiB
Diff
--- llvm/clang/lib/Format/TokenAnnotator.cpp
|
|
+++ llvm/clang/lib/Format/TokenAnnotator.cpp
|
|
@@ -2981,7 +2981,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
|
// Don't space between ')' and <id> or ')' and 'new'. 'new' is not a
|
|
// keyword in Objective-C, and '+ (instancetype)new;' is a standard class
|
|
// method declaration.
|
|
- return false;
|
|
+ return true;
|
|
}
|
|
if (Line.Type == LT_ObjCProperty &&
|
|
(Right.is(tok::equal) || Left.is(tok::equal)))
|
|
@@ -3005,6 +3007,22 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
|
if (Right.is(TT_RangeBasedForLoopColon) &&
|
|
!Style.SpaceBeforeRangeBasedForLoopColon)
|
|
return false;
|
|
+ if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr) && Left.Previous && Left.Previous->is(TT_SelectorName)) {
|
|
+ bool isInSelector = false;
|
|
+ FormatToken *tok = Left.Previous->Previous;
|
|
+ while (tok) {
|
|
+ if (tok->closesScope()) {
|
|
+ break;
|
|
+ } else if (tok->opensScope() && tok->Previous && tok->Previous->isObjCAtKeyword(tok::objc_selector) && tok->Previous->Previous && tok->Previous->Previous->is(tok::at)) {
|
|
+ isInSelector = true;
|
|
+ break;
|
|
+ }
|
|
+ tok = tok->Previous;
|
|
+ }
|
|
+ if (!isInSelector) {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
if (Right.is(tok::colon)) {
|
|
if (Line.First->isOneOf(tok::kw_case, tok::kw_default) ||
|
|
!Right.getNextNonComment() || Right.getNextNonComment()->is(tok::semi))
|
|
--- llvm/clang/lib/Format/Format.cpp
|
|
+++ llvm/clang/lib/Format/Format.cpp
|
|
@@ -658,6 +658,9 @@ static FormatStyle expandPresets(const FormatStyle &Style) {
|
|
false, true, true,
|
|
true};
|
|
switch (Style.BreakBeforeBraces) {
|
|
+ case FormatStyle::BS_Attach:
|
|
+ Expanded.BraceWrapping.AfterFunction = Style.ColumnLimit != 0 ? true : false;
|
|
+ break;
|
|
case FormatStyle::BS_Linux:
|
|
Expanded.BraceWrapping.AfterClass = true;
|
|
Expanded.BraceWrapping.AfterFunction = true;
|
|
--- llvm/clang/lib/Format/UnwrappedLineFormatter.cpp
|
|
+++ llvm/clang/lib/Format/UnwrappedLineFormatter.cpp
|
|
@@ -339,6 +339,8 @@ private:
|
|
TheLine->Last->TotalLength <= Style.ColumnLimit)
|
|
? 1
|
|
: 0;
|
|
+ } else if (I[1]->First->is(tok::l_brace) && Style.BraceWrapping.AfterFunction) {
|
|
+ return (Style.ColumnLimit == 0 || TheLine->Last->TotalLength + I[1]->Last->TotalLength + 1 <= Style.ColumnLimit) ? 1 : 0;
|
|
}
|
|
// Try to merge either empty or one-line block if is precedeed by control
|
|
// statement token
|
|
@@ -1132,6 +1140,7 @@ unsigned UnwrappedLineFormatter::format(
|
|
!Style.JavaScriptWrapImports)) ||
|
|
(Style.isCSharp() &&
|
|
TheLine.InPPDirective); // don't split #regions in C#
|
|
+ FitsIntoOneLine = FitsIntoOneLine && (!TheLine.mightBeFunctionDefinition() || TheLine.endsWith(tok::l_brace));
|
|
if (Style.ColumnLimit == 0)
|
|
NoColumnLimitLineFormatter(Indenter, Whitespaces, Style, this)
|
|
.formatLine(TheLine, NextStartColumn + Indent,
|