Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 734732 | Differences between
and this patch

Collapse All | Expand All

(-)a/clang/include/clang/Format/Format.h (+13 lines)
Lines 21-26 Link Here
21
#include "llvm/Support/Regex.h"
21
#include "llvm/Support/Regex.h"
22
#include <system_error>
22
#include <system_error>
23
23
24
#define KEEP_LINE_BREAKS_FOR_NON_EMPTY_LINES_BACKPORTED
25
24
namespace llvm {
26
namespace llvm {
25
namespace vfs {
27
namespace vfs {
26
class FileSystem;
28
class FileSystem;
Lines 1476-1481 struct FormatStyle { Link Here
1476
  bool JavaScriptWrapImports;
1478
  bool JavaScriptWrapImports;
1477
  // clang-format on
1479
  // clang-format on
1478
1480
1481
  /// If true, no line breaks are optimized out (works only with ColumnLimit = 0)
1482
  /// \code
1483
  ///    true:                                  false:
1484
  ///    int foo(int a,                 vs.     int foo(int a, int b) {
1485
  ///            int b) {
1486
  ///      bar();                                 bar();
1487
  ///    }                                      }
1488
  /// \endcode
1489
  bool KeepLineBreaksForNonEmptyLines;
1490
1479
  /// If true, the empty line at the start of blocks is kept.
1491
  /// If true, the empty line at the start of blocks is kept.
1480
  /// \code
1492
  /// \code
1481
  ///    true:                                  false:
1493
  ///    true:                                  false:
Lines 2126-2131 struct FormatStyle { Link Here
2126
           JavaImportGroups == R.JavaImportGroups &&
2138
           JavaImportGroups == R.JavaImportGroups &&
2127
           JavaScriptQuotes == R.JavaScriptQuotes &&
2139
           JavaScriptQuotes == R.JavaScriptQuotes &&
2128
           JavaScriptWrapImports == R.JavaScriptWrapImports &&
2140
           JavaScriptWrapImports == R.JavaScriptWrapImports &&
2141
           KeepLineBreaksForNonEmptyLines == R.KeepLineBreaksForNonEmptyLines &&
2129
           KeepEmptyLinesAtTheStartOfBlocks ==
2142
           KeepEmptyLinesAtTheStartOfBlocks ==
2130
               R.KeepEmptyLinesAtTheStartOfBlocks &&
2143
               R.KeepEmptyLinesAtTheStartOfBlocks &&
2131
           MacroBlockBegin == R.MacroBlockBegin &&
2144
           MacroBlockBegin == R.MacroBlockBegin &&
(-)a/clang/lib/Format/Format.cpp (+4 lines)
Lines 488-493 template <> struct MappingTraits<FormatStyle> { Link Here
488
    IO.mapOptional("JavaImportGroups", Style.JavaImportGroups);
488
    IO.mapOptional("JavaImportGroups", Style.JavaImportGroups);
489
    IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
489
    IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
490
    IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
490
    IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
491
    IO.mapOptional("KeepLineBreaksForNonEmptyLines",
492
                   Style.KeepLineBreaksForNonEmptyLines);
491
    IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
493
    IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
492
                   Style.KeepEmptyLinesAtTheStartOfBlocks);
494
                   Style.KeepEmptyLinesAtTheStartOfBlocks);
493
    IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
495
    IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
Lines 790-795 FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { Link Here
790
  LLVMStyle.JavaScriptWrapImports = true;
792
  LLVMStyle.JavaScriptWrapImports = true;
791
  LLVMStyle.TabWidth = 8;
793
  LLVMStyle.TabWidth = 8;
792
  LLVMStyle.MaxEmptyLinesToKeep = 1;
794
  LLVMStyle.MaxEmptyLinesToKeep = 1;
795
  LLVMStyle.KeepLineBreaksForNonEmptyLines = false;
793
  LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true;
796
  LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true;
794
  LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
797
  LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
795
  LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
798
  LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
Lines 870-875 FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { Link Here
870
  GoogleStyle.IncludeStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
873
  GoogleStyle.IncludeStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
871
  GoogleStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
874
  GoogleStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
872
  GoogleStyle.IndentCaseLabels = true;
875
  GoogleStyle.IndentCaseLabels = true;
876
  GoogleStyle.KeepLineBreaksForNonEmptyLines = false;
873
  GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
877
  GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
874
  GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
878
  GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
875
  GoogleStyle.ObjCSpaceAfterProperty = false;
879
  GoogleStyle.ObjCSpaceAfterProperty = false;
(-)a/clang/lib/Format/UnwrappedLineFormatter.cpp (-4 / +5 lines)
Lines 741-747 public: Link Here
741
  LineFormatter(ContinuationIndenter *Indenter, WhitespaceManager *Whitespaces,
741
  LineFormatter(ContinuationIndenter *Indenter, WhitespaceManager *Whitespaces,
742
                const FormatStyle &Style,
742
                const FormatStyle &Style,
743
                UnwrappedLineFormatter *BlockFormatter)
743
                UnwrappedLineFormatter *BlockFormatter)
744
      : Indenter(Indenter), Whitespaces(Whitespaces), Style(Style),
744
      : Indenter(Indenter), Style(Style), Whitespaces(Whitespaces),
745
        BlockFormatter(BlockFormatter) {}
745
        BlockFormatter(BlockFormatter) {}
746
  virtual ~LineFormatter() {}
746
  virtual ~LineFormatter() {}
747
747
Lines 782-788 protected: Link Here
782
      // assert so that we can simply call this function for all tokens.
782
      // assert so that we can simply call this function for all tokens.
783
      return true;
783
      return true;
784
784
785
    if (NewLine) {
785
    if (NewLine || (Previous.Children[0]->First->MustBreakBefore &&
786
                    Style.KeepLineBreaksForNonEmptyLines)) {
786
      int AdditionalIndent = State.Stack.back().Indent -
787
      int AdditionalIndent = State.Stack.back().Indent -
787
                             Previous.Children[0]->Level * Style.IndentWidth;
788
                             Previous.Children[0]->Level * Style.IndentWidth;
788
789
Lines 827-836 protected: Link Here
827
  }
828
  }
828
829
829
  ContinuationIndenter *Indenter;
830
  ContinuationIndenter *Indenter;
831
  const FormatStyle &Style;
830
832
831
private:
833
private:
832
  WhitespaceManager *Whitespaces;
834
  WhitespaceManager *Whitespaces;
833
  const FormatStyle &Style;
834
  UnwrappedLineFormatter *BlockFormatter;
835
  UnwrappedLineFormatter *BlockFormatter;
835
};
836
};
836
837
Lines 853-859 public: Link Here
853
    while (State.NextToken) {
854
    while (State.NextToken) {
854
      bool Newline =
855
      bool Newline =
855
          Indenter->mustBreak(State) ||
856
          Indenter->mustBreak(State) ||
856
          (Indenter->canBreak(State) && State.NextToken->NewlinesBefore > 0);
857
          (State.NextToken->NewlinesBefore > 0 && Indenter->canBreak(State));
857
      unsigned Penalty = 0;
858
      unsigned Penalty = 0;
858
      formatChildren(State, Newline, /*DryRun=*/false, Penalty);
859
      formatChildren(State, Newline, /*DryRun=*/false, Penalty);
859
      Indenter->addTokenToState(State, Newline, /*DryRun=*/false);
860
      Indenter->addTokenToState(State, Newline, /*DryRun=*/false);
(-)a/clang/lib/Format/UnwrappedLineParser.cpp (+2 lines)
Lines 2640-2645 void UnwrappedLineParser::nextToken(int LevelDifference) { Link Here
2640
  else
2640
  else
2641
    readTokenWithJavaScriptASI();
2641
    readTokenWithJavaScriptASI();
2642
  FormatTok->Previous = Previous;
2642
  FormatTok->Previous = Previous;
2643
  if (FormatTok->NewlinesBefore && Style.KeepLineBreaksForNonEmptyLines)
2644
    FormatTok->MustBreakBefore = true;
2643
}
2645
}
2644
2646
2645
void UnwrappedLineParser::distributeComments(
2647
void UnwrappedLineParser::distributeComments(
(-)a/clang/unittests/Format/FormatTest.cpp (+16 lines)
Lines 393-398 TEST_F(FormatTest, RemovesEmptyLines) { Link Here
393
                   "  void funk() {}\n"
393
                   "  void funk() {}\n"
394
                   "};",
394
                   "};",
395
                   Style));
395
                   Style));
396
397
  Style.KeepLineBreaksForNonEmptyLines = true;
398
  Style.ColumnLimit = 0;
399
  EXPECT_EQ("int foo(int a,\n"
400
            "        int b)\n"
401
            "{\n"
402
            "}",
403
            format("int foo(int a,\n"
404
                   "int b) {}",
405
                   Style));
406
407
  EXPECT_EQ("[]() {\n"
408
            "  foo(); }",
409
            format("[]() {\n"
410
                   "foo(); }",
411
                   Style));
396
}
412
}
397
413
398
TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) {
414
TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) {

Return to bug 734732