Commit Graph

260 Commits

Author SHA1 Message Date
Andi-Bogdan Postelnicu 0ef8ee19f8 [clang-format] Add option to break before inheritance separation operator in class declaration.
Differential Revision: https://reviews.llvm.org/D30487

llvm-svn: 297467
2017-03-10 15:10:37 +00:00
Krasimir Georgiev bc05ebaa5a [clang-format] Look at NoLineBreak and NoLineBreakInOperand before breakProtrudingToken
Summary:
This patch makes ContinuationIndenter call breakProtrudingToken only if
NoLineBreak and NoLineBreakInOperand is false.

Previously, clang-format required two runs to converge on the following example with 24 columns:
Note that the second operand shouldn't be splitted according to NoLineBreakInOperand, but the
token breaker doesn't take that into account:
```
func(a, "long long long long", c);
```
After first run:
```
func(a, "long long "
        "long long",
         c);
```
After second run, where NoLineBreakInOperand is taken into account:
```
func(a,
     "long long "
     "long long",
     c);
```

With the patch, clang-format now obtains in one run:
```
func(a,
     "long long long"
     "long",
     c);
```
which is a better token split overall.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D30575

llvm-svn: 297274
2017-03-08 12:54:50 +00:00
Krasimir Georgiev 17725d8391 [clang-format] Enable comment reflowing in multiline comments containing pragmas
Summary:
This patch enables comment reflowing of lines not matching the comment pragma regex
in multiline comments containing comment pragma lines. Previously, these comments
were dumped without being reindented to the result.

Reviewers: djasper, mprobst

Reviewed By: mprobst

Subscribers: klimek, mprobst, cfe-commits

Differential Revision: https://reviews.llvm.org/D30697

llvm-svn: 297261
2017-03-08 08:55:12 +00:00
Nico Weber d96ae86735 clang-format: Fix many Objective-C formatting regressions from r289428
r289428 added a separate language kind for Objective-C, but kept many
"Language == LK_Cpp" checks untouched.  This introduced a "IsCpp()"
method that returns true for both C++ and Objective-C++, and replaces
all comparisons of Language with LK_Cpp with calls to this new method.

Also add a lot more test coverge for formatting things in LK_ObjC mode,
by having FormatTest's verifyFormat() test for LK_ObjC everything that's
being tested for LK_Cpp at the moment.

Fixes PR32060 and many other things.

llvm-svn: 296160
2017-02-24 19:10:12 +00:00
Daniel Jasper 98e0b12d13 clang-format: [JS] Improve line-wrapping behavior of template strings.
Specifically, similar to other blocks, clang-format now wraps both
after "${" and before the corresponding "}", if the contained
expression spans multiple lines.

llvm-svn: 295663
2017-02-20 14:51:16 +00:00
Daniel Jasper d9b319e3e3 clang-format: Prevent weird line-wraps in complex lambda introducers
Before:
  aaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
      [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]() -> ::std::
	  unordered_set<aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> {
	    //
	  });

After:
  aaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
      [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]()
	  -> ::std::unordered_set<
	      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> {
	//
      });

llvm-svn: 295659
2017-02-20 12:43:48 +00:00
Daniel Jasper c06f6da34e clang-format: [JS] Fix bugs in parsing and aligning template strings.
llvm-svn: 294009
2017-02-03 14:32:38 +00:00
Krasimir Georgiev 00c5c72d0e [clang-format] Don't reflow across comment pragmas.
Summary:
The comment reflower wasn't taking comment pragmas as reflow stoppers. This patch fixes that.

source:
```
// long long long long
// IWYU pragma:
```
format with column limit  = 20 before:
```
// long long long
// long IWYU pragma:
```
format with column limit  = 20 after:
```
// long long long
// long
// IWYU pragma:
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D29450

llvm-svn: 293898
2017-02-02 15:32:19 +00:00
Daniel Jasper c3aa05c01b clang-format: Do not use two-argument/operand special case with no alignment
Without alignment, there is no clean separation between the arguments, even if
there are only two.

Before:
  aaaaaaaaaaaaaa(
      aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
          aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
  aaaaaaaaaaaaaa(aaaaaaaaaaaa,
                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
                     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

llvm-svn: 293875
2017-02-02 08:30:21 +00:00
Daniel Jasper b127039c77 clang-format: Fix incorrect line breaks after forced operator wraps.
Before:
  bool x = aaaaa //
           ||
           bbbbb
           //
           || cccc;

After:
  bool x = aaaaa //
           || bbbbb
           //
           || cccc;

llvm-svn: 293839
2017-02-01 23:27:37 +00:00
Daniel Jasper 21f7dea5f5 clang-format: Don't force-wrap multiline RHSs for 2-operand experssions.
This rows back on r288120, r291801 and r292110. I apologize in advance
for the churn. All of those revisions where meant to make the wrapping
of RHS expressions more consistent. However, now that they are
consistent, we seem to be a bit too eager.

The reasoning here is that I think it is generally correct that we want
to line-wrap before multiline RHS expressions (or multiline arguments to
a function call). However, if there are only two of such operands or
arguments, there is always a clear vertical separation between them and
the additional line break seems much less desirable.

Somewhat good examples are expressions like:

  EXPECT_EQ(2, someLongExpression(
                   orCall));

llvm-svn: 293752
2017-02-01 09:23:39 +00:00
Daniel Jasper 3f11941d8a clang-format: [JS] Indent expressions in ${} relative to their surrounding
This only affects expressions inside ${} scopes of template strings.
Here, we want to indent relative to the surrounding template string and
not the surrounding expression. Otherwise, this can create quite a mess.

Before:
  var f = `
    aaaaaaaaaaaaaaaaaa: ${someFunction(
      aaaaa +  //
      bbbb)}`;

After:
  var f = `
    aaaaaaaaaaaaaaaaaa: ${someFunction(
                              aaaaa +  //
                              bbbb)}`;

llvm-svn: 293636
2017-01-31 14:39:33 +00:00
Daniel Jasper 7d42f3f746 [clang-format] Refactor WhitespaceManager and friends
The main motivation behind this is to cleanup the WhitespaceManager and
make it more extensible for future alignment etc. features.
Specifically, WhitespaceManager has started to copy more and more code
that is already present in FormatToken. Instead, I think it makes more
sense to actually store a reference to each FormatToken for each change.

This has as a consequence led to a change in the calculation of indent
levels. Now, we actually compute them for each Token ahead of time,
which should be more efficient as it removes an unsigned value for the
ParenState, which is used during the combinatorial exploration of the
solution space.

No functional changes intended.

Review: https://reviews.llvm.org/D29300
llvm-svn: 293616
2017-01-31 11:25:01 +00:00
Daniel Jasper 51c868e9aa clang-format: [JavaScript] Undo r291974 for JavaScript.
This had significant negative consequences and I don't have a good
solution for it yet.

Before:
  var string =
      [
        'aaaaaa',
        'bbbbbb',
      ]
          .join('+');

After:
  var string = [
    'aaaaaa',
    'bbbbbb',
  ].join('+');

llvm-svn: 293465
2017-01-30 07:08:40 +00:00
Krasimir Georgiev 91834227a3 [clang-format] Implement comment reflowing.
Summary:
This presents a version of the comment reflowing with less mutable state inside
the comment breakable token subclasses. The state has been pushed into the
driving breakProtrudingToken method. For this, the API of BreakableToken is enriched
by the methods getSplitBefore and getLineLengthAfterSplitBefore.

Reviewers: klimek

Reviewed By: klimek

Subscribers: djasper, klimek, mgorny, cfe-commits, ioeric

Differential Revision: https://reviews.llvm.org/D28764

llvm-svn: 293055
2017-01-25 13:58:58 +00:00
Daniel Jasper 240527ca99 clang-format: Always wrap before multi-line parameters/operands.
Before:
  aaaaaaaaaaaaaaaaaa(aaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa::
                                   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
                     aaaaaaaaaaaaaaaaaaaaa);

After:
  aaaaaaaaaaaaaaaaaa(aaaaaaaa,
                     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa::
                         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
                     aaaaaaaaaaaaaaaaaaaaa);

No new test cases, as the existing ones cover this fairly well.

llvm-svn: 292110
2017-01-16 13:13:15 +00:00
Daniel Jasper e61f9f9949 clang-format: Fix bug in making line break decisions.
Here, the optimization to not line wrap when it would not lead to a
reduction in columns was overwriting and enforced break that we want to
do no matter what.

Before:
  int i = someFunction(
              aaaaaaa,
              0).aaa(aaaaaaaaaaaaa) *
              aaaaaaa +
          aaaaaaa;

After:
  int i = someFunction(aaaaaaa, 0)
                  .aaa(aaaaaaaaaaaaa) *
              aaaaaaa +
          aaaaaaa;

llvm-svn: 291974
2017-01-13 23:18:16 +00:00
Daniel Jasper e37101076c clang-format: Fix regression introduced by r291801.
Uncovered by polly tests.

Before:
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa,
                                 {}, aaaaaaaaaaaaaaaaaaaaaaa);

After:
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa, {},
                                 aaaaaaaaaaaaaaaaaaaaaaa);

llvm-svn: 291807
2017-01-12 20:06:28 +00:00
Daniel Jasper d1a9d8acdf clang-format: Treat braced lists like other complex parameters.
Specifically, wrap before them if they are multi-line so that we don't
create long hanging indents. This prevents having a lot of code
indented a lot in some cases.

Before:
  someFunction(Param, {List1, List2,
                       List3});

After:
  someFunction(Param,
               {List1, List2,
                List3});

llvm-svn: 291801
2017-01-12 19:35:26 +00:00
Daniel Jasper 7aacf468c0 clang-format: Slightly tweak the behavior of <<-wrapping.
Before:
  SomeLongLoggingStatementOrMacro() << "Some long text "
                                    << some_variable << "\n";

Before:
  SomeLongLoggingStatementOrMacro()
      << "Some long text " << some_variable << "\n";

Short logging statements are already special cased in a different part
of the code.

llvm-svn: 290094
2016-12-19 11:14:23 +00:00
Daniel Jasper 03a04fe95f clang-format: Separate out a language kind for ObjC.
While C(++) and ObjC are generally formatted the same way and can be
mixed, people might want to choose different styles based on the
language. This patch recognizes .m and .mm files as ObjC and also
implements a very crude detection of whether or not a .h file contains
ObjC code. This can be improved over time.

Also move most of the ObjC tests into their own test file to keep file
size maintainable.

llvm-svn: 289428
2016-12-12 12:42:29 +00:00
Daniel Jasper 22ed262c23 clang-format: Wrap complex binary expressions on the RHS of a comma.
Specifically, if the RHS of a comma is a complex binary expression and
spans multiple lines, insert a line break before it. This usually is
often more readable compared to producing a hanging indent. See changes
in FormatTest.cpp for examples.

llvm-svn: 288120
2016-11-29 09:40:32 +00:00
Daniel Jasper 35e4122f48 clang-format: Fix unnnecessary line break.
Before:
  aaaaaaaaaa(aaaa(aaaa,
		  aaaa), //
	     aaaa,
             aaaaa);

After:
  aaaaaaaaaa(aaaa(aaaa,
		  aaaa), //
	     aaaa, aaaaa);

llvm-svn: 288119
2016-11-29 09:40:01 +00:00
Daniel Jasper fd36f0b504 clang-format: Support ObjC selectors with unnamed parameters.
This fixes llvm.org/PR28063.

llvm-svn: 286715
2016-11-12 07:38:22 +00:00
Mehdi Amini 9670f847b8 [NFC] Header cleanup
Summary: Removed unused headers, replaced some headers with forward class declarations

Patch by: Eugene <claprix@yandex.ru>

Differential Revision: https://reviews.llvm.org/D20100

llvm-svn: 275882
2016-07-18 19:02:11 +00:00
Daniel Jasper 87448c5548 clang-format: Don't indent lambda body relative to its return type.
Before:
  []()  //
      -> int {
        return 1;  //
      };

After:
  []()  //
      -> int {
    return 1;  //
  };

llvm-svn: 272535
2016-06-13 07:48:45 +00:00
Daniel Jasper acadc8e0d6 clang-format: Fix incorrect calculation of "length" of /**/ comments.
This could lead to column limit violations.

llvm-svn: 272125
2016-06-08 09:45:08 +00:00
Daniel Jasper e77f19c0af clang-format: Fix segfault introduced by allowing wraps after comments.
llvm-svn: 271191
2016-05-29 22:07:22 +00:00
Eric Liu 635423e618 Addressed reviewer's post-submission comments from http://reviews.llvm.org/D18551.
Summary: Make SourceManager in Environment, WhitespaceManager, and FormatTokenAnalyzer etc constant members.

Reviewers: djasper, klimek

Subscribers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D19587

llvm-svn: 267859
2016-04-28 07:52:03 +00:00
Martin Probst 5f8445b32a clang-format: [JS] generator and async functions.
For generators, see:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_generators
async functions are not quite in the spec yet, but stage 3 and already widely used:
http://tc39.github.io/ecmascript-asyncawait/

Reviewers: djasper

Subscribers: klimek

Differential Revision: http://reviews.llvm.org/D19204

llvm-svn: 267368
2016-04-24 22:05:09 +00:00
Daniel Jasper 710f8493c8 clang-format: Slightly weaken AlignAfterOpenBracket=AlwaysBreak.
If a call takes a single argument, using AlwaysBreak can lead to lots
of wasted lines and additional indentation without improving the
readability in a significant way.

Before:
  caaaaaaaaaaaall(
      caaaaaaaaaaaall(
          caaaaaaaaaaaall(
              caaaaaaaaaaaaaaaaaaaaaaall(aaaaaaaaaaaaaa, aaaaaaaaa))));

After:
  caaaaaaaaaaaall(caaaaaaaaaaaall(caaaaaaaaaaaall(
      caaaaaaaaaaaaaaaaaaaaaaall(aaaaaaaaaaaaaa, aaaaaaaaa))));

llvm-svn: 263709
2016-03-17 12:00:22 +00:00
Daniel Jasper 04b4e10873 clang-format: Correctly apply wrap before multi-line RHS rule to
ternary expressions.

Before:
  return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? aaaaa : bbbbbbbbbbbbbbb +
							     cccccccccccccccc;

After:
  return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
	     aaaaa :
	     bbbbbbbbbbbbbbb + cccccccccccccccc;

llvm-svn: 262293
2016-03-01 04:19:59 +00:00
Daniel Jasper 602a727add clang-format: Make indentation after "<<" more consistent.
Before:
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      << aaa;

After:
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      << aaa;

llvm-svn: 260517
2016-02-11 13:15:14 +00:00
Daniel Jasper 2a9f720129 clang-format: Fix weird alignment when not aligning after brackets.
Before:
  bbbbbbbbbbbb(aaaaaaaaaaaaaaaaaaaaaaaa, //
      ccccccc(aaaaaaaaaaaaaaaaa, //
	           b));

After:
  bbbbbbbbbbbb(aaaaaaaaaaaaaaaaaaaaaaaa, //
      ccccccc(aaaaaaaaaaaaaaaaa, //
     	  b));

This fixes llvm.org/PR24905.

llvm-svn: 260080
2016-02-08 09:52:54 +00:00
Daniel Jasper 0c9772e874 clang-format: Fix corner case in template detection.
Before:
  f(a.operator() < A > ());

After:
  f(a.operator()<A>());

llvm-svn: 259884
2016-02-05 14:17:16 +00:00
Daniel Jasper 45860fac37 clang-format: Fix formatting of ternary expressions with comments.
Before:
  int i = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
	      /*bbbbbbbbbbbbbbbbbbbb=*/bbbbbbbbbbbbbbbbbbbbbbbbb :
				       ccccccccccccccccccccccccccc;

After:
  int i = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
	      /*bbbbbbbbbbbbbbbbbbbb=*/bbbbbbbbbbbbbbbbbbbbbbbbb :
              ccccccccccccccccccccccccccc;

llvm-svn: 259670
2016-02-03 17:27:10 +00:00
Daniel Jasper b618a98582 clang-format: Make AlignAfterOpenBracket also affect angle brackets.
Patch by Matthew Whitehead, thank you.

llvm-svn: 259487
2016-02-02 10:28:11 +00:00
Daniel Jasper e1a7b76338 clang-format: Add option to disable string literal formatting.
llvm-svn: 259352
2016-02-01 11:21:02 +00:00
Daniel Jasper 15b01116d9 clang-format: [Java] Remove unnecessary line break after complex annotations
Before:
  @Annotation("Some"
      + " text")
  List<Integer>
      list;

After:
  @Annotation("Some"
      + " text")
  List<Integer> list;

llvm-svn: 258981
2016-01-27 20:14:23 +00:00
Daniel Jasper a3cd216483 clang-format: Fix incorrectly enforced linebreak with ColumnLimit 0.
Before:
  aaaa[bbbb]
      .cccc();

After:
  aaaa[bbbb].cccc();

llvm-svn: 257763
2016-01-14 13:36:46 +00:00
Daniel Jasper 50780ce110 clang-format: [ObjC+JS] Allow bin-packing of array literals.
After reading the style guides again, they don't actually say how to
pack or not pack array literals. Based on some user reports, array
initializers can unnecessarily get quite long if they contain many
small elements. Array literals with trailing commas are still formatted
one per line so that users have a way to opt out of the packing.

Before:
  var array = [
    aaaaaa,
    aaaaaa,
    aaaaaa,
    aaaaaa,
    aaaaaa,
    aaaaaa,
    aaaaaa,
    aaaaaa,
    aaaaaa,
    aaaaaa
  ];

After:
  var array = [
    aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa,
    aaaaaa, aaaaaa
  ];

llvm-svn: 257615
2016-01-13 16:41:34 +00:00
Daniel Jasper 06ca0fc69d clang-format: Slightly row back on r257257.
r257257 change the way clang-format enforces line breaks after a
templated type has been line-wrapped. This was to fix an incorrect line
break if BinPackParameters is set to false. However, it also leads to
an unwanted line break in a different case. Thus, for now, only do this
when BinPackParameters is false. This isn't ideal yet, but helps us
until we have a better solution.

With BinPackParameters:
Before:
  void fffffffffff(aaaaaaaaaaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaaaa,
                                               aaaaaaaaaa> aaaaaaaaaa);

After:
  void fffffffffff(
      aaaaaaaaaaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaa>
          aaaaaaaaaa);

llvm-svn: 257325
2016-01-11 11:01:05 +00:00
Daniel Jasper 2802456097 clang-format: [JS] Improve line-flow when calling functions on array literals.
Before:
  return [
    aaaaaaaaaaaaaaaaaaaaaa
  ].aaaaaaa(function() {
     //
   })
   .bbbbbb();

After:
  return [aaaaaaaaaaaaaaaaaaaaaa]
      .aaaaaaa(function() {
	//
      })
      .bbbbbb();

llvm-svn: 257324
2016-01-11 11:00:58 +00:00
Daniel Jasper 00693b08cf clang-format: Fix incorrect line break in certain configurations.
Before:
  void aaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa,
                          vector<int>
                              bbbbbbbbbbbbbbb);

After:
  void aaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa,
                          vector<int> bbbbbbbbbbbbbbb);

llvm-svn: 257257
2016-01-09 15:56:47 +00:00
Daniel Jasper 804a276fcf clang-format: Support definitions/declarations of operator,.
Before:
  bool operator, ();

After:
  bool operator,();

llvm-svn: 257256
2016-01-09 15:56:40 +00:00
Daniel Jasper 7bec87c998 clang-format: Fix corner case in one-per-line formatting.
Before (example is JS, but also applies to C++):
  return [
    aaaa()
        .bbbbbbbb('A'),
    aaaa().bbbbbbbb('B'),
    aaaa().bbbbbbbb('C'),
  ];

After:
  return [
    aaaa().bbbbbbbb('A'),
    aaaa().bbbbbbbb('B'),
    aaaa().bbbbbbbb('C'),
  ];

llvm-svn: 257079
2016-01-07 18:11:54 +00:00
Daniel Jasper 411af72e8c clang-format: Fix corner case in "if it saves columns"-calculation.
Before:
  aaaa
      .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      .aaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
  aaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      .aaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

llvm-svn: 256841
2016-01-05 16:10:39 +00:00
Daniel Jasper 0a589416e8 clang-format: Handle \n the same way as std::endl with stream operator.
clang-format breaks multi-line streams after std::endl.
It now also break for '\n', the suggested replacement for std::endl:

  http://llvm.org/docs/CodingStandards.html#avoid-std-endl

Before:
  llvm::errs() << aaaaaaaaaaaaaaaaaaaaaa << '\n' << bbbbbbbbbbbbbbbbbbbbbb
               << '\n';
  llvm::errs() << aaaa << "aaaaaaaaaaaaaaaaaa\n" << bbbb
               << "bbbbbbbbbbbbbbbbbb\n";

After:
  llvm::errs() << aaaaaaaaaaaaaaaaaaaaaa << '\n'
               << bbbbbbbbbbbbbbbbbbbbbb << '\n';
  llvm::errs() << aaaa << "aaaaaaaaaaaaaaaaaa\n"
               << bbbb << "bbbbbbbbbbbbbbbbbb\n";

This changeset ensure that multiline streams have a line break after:
  - std::endl
  - '\n'
  - "\n"
  - "Some Text\n"

Patch by Jean-Philippe Dufraigne, thank you.

llvm-svn: 256832
2016-01-05 13:06:27 +00:00
Daniel Jasper 801cdb27e4 clang-format: Avoid creating hanging indents in call sequences.
Before:
  aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaa(
                      aaaaaaaaaaaaaaaaaaaa)
        .aaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
  aaaaaaaaaaaaaaaa
        .aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa)
        .aaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

llvm-svn: 256831
2016-01-05 13:03:59 +00:00
Daniel Jasper 00492f96bf clang-format: Improve line wrapping behavior in call sequences.
r256750 has been leading to an undesired behavior:

  aaaaaaaaaa
      .aaaaaaaaaaaaaaaaaaaaaaaa.aaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

This change increases penalty for wrapping before member accesses that aren't
calls. Thus, this is again formatted as (as it has been before r256750):

  aaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaa.aaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

llvm-svn: 256830
2016-01-05 13:03:50 +00:00