/ formatting / cocotron-styling.patch
cocotron-styling.patch
1 --- llvm/clang/lib/Format/TokenAnnotator.cpp 2 +++ llvm/clang/lib/Format/TokenAnnotator.cpp 3 @@ -2981,7 +2981,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, 4 // Don't space between ')' and <id> or ')' and 'new'. 'new' is not a 5 // keyword in Objective-C, and '+ (instancetype)new;' is a standard class 6 // method declaration. 7 - return false; 8 + return true; 9 } 10 if (Line.Type == LT_ObjCProperty && 11 (Right.is(tok::equal) || Left.is(tok::equal))) 12 @@ -3005,6 +3007,22 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, 13 if (Right.is(TT_RangeBasedForLoopColon) && 14 !Style.SpaceBeforeRangeBasedForLoopColon) 15 return false; 16 + if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr) && Left.Previous && Left.Previous->is(TT_SelectorName)) { 17 + bool isInSelector = false; 18 + FormatToken *tok = Left.Previous->Previous; 19 + while (tok) { 20 + if (tok->closesScope()) { 21 + break; 22 + } else if (tok->opensScope() && tok->Previous && tok->Previous->isObjCAtKeyword(tok::objc_selector) && tok->Previous->Previous && tok->Previous->Previous->is(tok::at)) { 23 + isInSelector = true; 24 + break; 25 + } 26 + tok = tok->Previous; 27 + } 28 + if (!isInSelector) { 29 + return true; 30 + } 31 + } 32 if (Right.is(tok::colon)) { 33 if (Line.First->isOneOf(tok::kw_case, tok::kw_default) || 34 !Right.getNextNonComment() || Right.getNextNonComment()->is(tok::semi)) 35 --- llvm/clang/lib/Format/Format.cpp 36 +++ llvm/clang/lib/Format/Format.cpp 37 @@ -658,6 +658,9 @@ static FormatStyle expandPresets(const FormatStyle &Style) { 38 false, true, true, 39 true}; 40 switch (Style.BreakBeforeBraces) { 41 + case FormatStyle::BS_Attach: 42 + Expanded.BraceWrapping.AfterFunction = Style.ColumnLimit != 0 ? true : false; 43 + break; 44 case FormatStyle::BS_Linux: 45 Expanded.BraceWrapping.AfterClass = true; 46 Expanded.BraceWrapping.AfterFunction = true; 47 --- llvm/clang/lib/Format/UnwrappedLineFormatter.cpp 48 +++ llvm/clang/lib/Format/UnwrappedLineFormatter.cpp 49 @@ -339,6 +339,8 @@ private: 50 TheLine->Last->TotalLength <= Style.ColumnLimit) 51 ? 1 52 : 0; 53 + } else if (I[1]->First->is(tok::l_brace) && Style.BraceWrapping.AfterFunction) { 54 + return (Style.ColumnLimit == 0 || TheLine->Last->TotalLength + I[1]->Last->TotalLength + 1 <= Style.ColumnLimit) ? 1 : 0; 55 } 56 // Try to merge either empty or one-line block if is precedeed by control 57 // statement token 58 @@ -1132,6 +1134,8 @@ unsigned UnwrappedLineFormatter::format( 59 !Style.JavaScriptWrapImports)) || 60 (Style.isCSharp() && 61 TheLine.InPPDirective); // don't split #regions in C# 62 + bool functionBraceWrapped = TheLine.mightBeFunctionDefinition() && NextLine && NextLine->startsWith(tok::l_brace) && !TheLine.endsWith(tok::l_brace); 63 + FitsIntoOneLine = FitsIntoOneLine && !functionBraceWrapped; 64 if (Style.ColumnLimit == 0) 65 NoColumnLimitLineFormatter(Indenter, Whitespaces, Style, this) 66 .formatLine(TheLine, NextStartColumn + Indent,