Commit Graph

1952 Commits

Author SHA1 Message Date
Daniel Jasper 697a8ec6cd clang-format: Fix bad variable declaration detection.
Before:
  LooooooooooooooooongType
  variable(nullptr, [](A *a) {});

After:
  LooooooooooooooooongType
      variable(nullptr, [](A *a) {});

llvm-svn: 294358
2017-02-07 21:38:16 +00:00
Martin Probst 8e3eba0373 clang-format: [JS] correcly format object literal methods.
Summary:
In JavaScript, object literals can contain methods:

   var x = {
     a() { return 1; },
   };

Previously, clang-format always parsed nested {} inside a braced list as
further braced lists. Special case this logic for JavaScript to try
parsing as a braced list, but fall back to parsing as a child block.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 294315
2017-02-07 16:33:13 +00:00
Martin Probst 16282993b7 clang-format: [JS] exclaim preceding regex literals.
Summary:
Regex detection would incorrectly classify a trailing `!` operator
(nullability cast) followed by a `/` as the start of a regular
expression literal. This fixes code such as:

    var foo = x()! / 10;

Which would previously parse a regexp all the way to the end of the
source file (or next `/`).

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 294304
2017-02-07 14:08:03 +00:00
Martin Probst 1027fb8a06 clang-format: [JS] handle parenthesized class expressions.
Summary:
In JavaScript, classes are expressions, so they can appear e.g. in
argument lists.

    var C = foo(class {
      bar() {
        return 1;
      }
    };

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 294302
2017-02-07 14:05:30 +00:00
Daniel Jasper 2db1b4a177 clang-format: Fix bug with conflicting BreakBeforeBinaryOperations and AlignAfterOpenBracket
Fix for the formatting options combination of
BreakBeforeBinaryOperators: All, AlignAfterOpenBracket: AlwaysBreak not
handling long templates correctly. This patch allows a break after an
opening left parenthesis, TemplateOpener, or bracket when both options
are enabled.

Patch by Daphne Pfister, thank you!

Fixes llvm.org/PR30304.

llvm-svn: 294179
2017-02-06 10:55:49 +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 d105b72df6 [clang-format] Re-align broken comment lines where appropriate.
Summary:
The comment aligner was skipping over newly broken comment lines. This patch fixes that.

source:
```
int ab; // line
int a; // long long
```

format with column limit 15 before:
```
int ab; // line
int a;  // long
       // long
```

format with column limit 15 after:
```
int ab; // line
int a;  // long
        // long
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293997
2017-02-03 10:18:25 +00:00
Daniel Jasper da910e0a8b clang-format: [Proto] Also supports implicit string literal concatenation
llvm-svn: 293995
2017-02-03 08:29:02 +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
Krasimir Georgiev b6ccd38dee [clang-format] Fix breaking of comment sections in unwrapped lines containing newlines.
Summary:
The breaking of line comment sections was misaligning the case where the first comment line is on an unwrapped line containing newlines. In this case, the breaking column must be based on the source column of the last token that is preceded by a newline, not on the first token of the unwrapped line.

source:
```
enum A {
  a, // line 1
  // line 2
};
```
format before:
```
enum A {
  a, // line 1
     // line 2
};
```
format after:
```
enum A {
  a, // line 1
  // line 2
};
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293891
2017-02-02 14:36:50 +00:00
Krasimir Georgiev 28912c09b2 [clang-format] Don't reflow lines starting with TODO, FIXME or XXX.
Summary: These lines commonly carry a special meaning.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293878
2017-02-02 10:52:08 +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
Krasimir Georgiev 13dbaa09e5 [clang-format] Fix regression about not aligning trailing comments in case they were previously aligned, but at different indent.
Summary:
Comment reflower was adding untouchable tokens in case two consecutive comment lines are aligned in the source code. This disallows the whitespace manager to re-indent them later.

source:
```
int i = f(abc, // line 1
          d, // line 2
	     // line 3
	  b);
```
Since line 2 and line 3 are aligned, the reflower was marking line 3 as untouchable; however the three comment lines need to be re-aligned.
output before:
```
int i = f(abc, // line 1
          d,   // line 2
	     // line 3
	  b);
```
output after:
```
int i = f(abc, // line 1
          d,   // line 2
	       // line 3
	  b);
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: sammccall, cfe-commits, klimek

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

llvm-svn: 293755
2017-02-01 10:10:04 +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
Nico Weber 9e2bc306ba Keep Chromium ObjC column limit at 80 for consistency with C++
https://reviews.llvm.org/D29337
Patch from Dan Beam <dbeam@chromium.org>!

llvm-svn: 293675
2017-01-31 18:42:05 +00:00
Krasimir Georgiev b796cebf3f [clang-format] Fix regression about adding leading whitespace to the content of line comments
Summary:
The reflower didn't measure precisely the line column of a line in the middle of
a line comment section that has a prefix that needs to be adapted.

source:
```
/// a
//b
```

format before:
```
/// a
 //b
```

format after:
```
/// a
// b
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: sammccall, cfe-commits, klimek

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

llvm-svn: 293641
2017-01-31 15:40:15 +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
Krasimir Georgiev af1b9622d4 [clang-format] Fix reflow in block comment lines with leading whitespace.
Summary:
The reflower was not taking into account the additional  leading whitespace in block comment lines.

source:
```
{
/*
 * long long long long
 *   long
 * long long long long
 */
}
```

format (with column limit 20) before:
```
{
  /*
   * long long long
   * long long long long
   * long long
   */
}
```
format after:
```
{
  /*
   * long long long
   * long long long
   * long long long
   */
}
```

Reviewers: djasper, klimek

Reviewed By: djasper

Subscribers: cfe-commits, sammccall, klimek

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

llvm-svn: 293633
2017-01-31 14:31:44 +00:00
Krasimir Georgiev 753625b62e [clang-format] Fix regression merging comments across newlines.
Summary:
This fixes a regression that causes example:
```
enum A {
  a, // line a

  // line b
  b
};
```
to be formatted as follows:
```
enum A {
  a, // line a
     // line b
  b
};
```

Reviewers: djasper, klimek

Reviewed By: klimek

Subscribers: cfe-commits, sammccall, djasper, klimek

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

llvm-svn: 293624
2017-01-31 13:32:38 +00:00
Daniel Jasper 24de6fbfdb clang-format: [JS] Properly set scopes inside template strings.
Before:
  var f = `aaaaaaaaaaaaa:${aaaaaaa
              .aaaaa} aaaaaaaa
           aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`;

After:
  var f = `aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa
           aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`;

llvm-svn: 293622
2017-01-31 13:03:07 +00:00
Daniel Jasper f201929010 clang-format: [JS] Fix incorrect line break in template strings.
Before:
  var f = `aaaa ${a ? 'a' : 'b'
                            }`;

After:
  var f = `aaaa ${a ? 'a' : 'b'}`;

llvm-svn: 293618
2017-01-31 12:07:35 +00:00
Krasimir Georgiev 8f62cf74ef [clang-format] Don't reflow comment lines starting with '@'.
Summary:
This patch stops reflowing comment lines starting with '@', since they commonly
have a special meaning.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293617
2017-01-31 11:38:02 +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
Krasimir Georgiev e518e0bfe9 [clang-format] Fix regression that breaks comments without a comment prefix
Summary:
Consider formatting the following code fragment with column limit 20:
```
{
  // line 1
  // line 2\
  // long long long line
}
```
Before this fix the output is:
```
{
  // line 1
  // line 2\
  // long long
  long line
}
```
This patch fixes a regression that breaks the last comment line without
adding the '//' prefix.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293548
2017-01-30 21:00:01 +00:00
Krasimir Georgiev 8432161f1d [clang-format] Separate line comment sections after a right brace from comment sections in the scope.
Summary:
The following two comment lines form a single comment section:
```
if (1) { // line 1
   // line 2
}
```
This is because the break of a comment section was based on the original column
of the first token of the previous line (in this case, the 'if').
This patch splits these two comment lines into different sections by taking into
account the original column of the right brace preceding the first line comment
where applicable.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 293539
2017-01-30 19:18:55 +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
Martin Probst fa37b18f94 clang-format: [JS] do not format MPEG transport streams.
Summary:
The MPEG transport stream file format also uses ".ts" as its file extension.
This change detects its specific framing format (0x47 every 189 bytes) and
simply ignores MPEG TS files.

Reviewers: djasper, sammccall

Subscribers: klimek, cfe-commits

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

llvm-svn: 293270
2017-01-27 09:09:11 +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
Antonio Maiorano 7eb7507aeb clang-format: fix fallback style set to "none" not always formatting
This fixes clang-format not formatting if fallback-style is explicitly set to
"none", and either a config file is found or YAML is passed in without a
"BasedOnStyle". With this change, passing "none" in these cases will have no
affect, and LLVM style will be used as the base style.

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

llvm-svn: 292562
2017-01-20 01:22:42 +00:00
Antonio Maiorano 3adfb6a3ee clang-format: Make GetStyle return Expected<FormatStyle> instead of FormatStyle
Change the contract of GetStyle so that it returns an error when an error occurs
(i.e. when it writes to stderr), and only returns the fallback style when it
can't find a configuration file.

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

llvm-svn: 292174
2017-01-17 00:12:27 +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
Martin Probst e6b5b34f6f clang-format: [JS] revert over-eager ASI check.
Summary: Change r291428 introduced ASI detection after closing curly braces. That would generally be correct, however this breaks indentation for structural statements. What happens is that CompoundStatementIndenter increases indentation for the current line, then after reading ASI creates a new line (with the increased line level), and only after the structural parser sees e.g. the if/then/else branch closed, line level is reduced. That leads to the new line started by ASI having a level too high.

Reviewers: djasper

Subscribers: sammccall, cfe-commits, klimek

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

llvm-svn: 292099
2017-01-16 09:52:40 +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 c941e7d21b clang-format: Improve support for override/final as variable names.
Before:
  bool a = f() &&override.f();
  bool a = f() &&final.f();
  void f(const MyOverride & override);
  void f(const MyFinal & final);

After:
  bool a = f() && override.f();
  bool a = f() && final.f();
  void f(const MyOverride &override);
  void f(const MyFinal &final);

llvm-svn: 291434
2017-01-09 11:04:07 +00:00
Martin Probst d40bca431d clang-format: [JS] ASI after imports
Summary:
Automatic semicolon insertion should break import and export statements:

Before, this would format on one line:

  // Note: no semi after 'x' below!
  import {x} from 'x'
  export function foo() {}

Into:
  import {x} from 'x' export function foo() {}

With this change, the statements get separated.

This also improves automatic semicolon insertion to consider closing
braces preceding declarations and statements.

Reviewers: klimek

Subscribers: cfe-commits

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

llvm-svn: 291428
2017-01-09 08:56:36 +00:00
Martin Probst af16c50639 clang-format: [JS] avoid indent after ambient function declarations.
Summary:
Before:
  declare function foo();
    let x = 1;

After:
  declare function foo();
  let x = 1;

The problem was that clang-format would unconditionally try to parse a child block, even though ambient function declarations do not have a body (similar to forward declarations).

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 290959
2017-01-04 13:36:43 +00:00
Nico Weber ea64969763 Change clang-format's Chromium JavaScript defaults
Chromium is starting to use clang-format on more JavaScript.

In doing this, we discovered that our defaults were not doing a good job
differentiating between JS and C++.

This change moves some defaults to only apply to C++.
https://reviews.llvm.org/D28165

Patch from Dan Beam <dbeam@chromium.org>!

llvm-svn: 290930
2017-01-04 02:33:36 +00:00
Piotr Padlewski 1ec383c74a Use after move bug fixes
Summary: Bunch of fixed bugs in Clang after running misc-use-after-move in clang-tidy.

Reviewers: rsmith, mboehme

Subscribers: cfe-commits, klimek

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

llvm-svn: 290424
2016-12-23 11:40:44 +00:00
Daniel Jasper 2388861f09 clang-format: Less eagerly try to keep label-value pairs on a line.
Before:
  string v =
      StrCat("aaaaaaaaaaaaaaaaaaaaaaaaaaa: ", SomeFunction(aaaaaaaaaaaa,
                                                           aaaaaaaaaaaaaaa),
             bbbbbbbbbbbbbbbbbbbbbbb);

After:
  string v = StrCat("aaaaaaaaaaaaaaaaaaaaaaaaaaa: ",
                    SomeFunction(aaaaaaaaaaaa, aaaaaaaaaaaaaaa),
                    bbbbbbbbbbbbbbbbbbbbbbb);

llvm-svn: 290337
2016-12-22 12:37:06 +00:00
Antonio Maiorano 34c037641b Make FormatStyle.GetStyleOfFile test work on MSVC
Modify getStyle to use vfs::FileSystem::makeAbsolute just like FS.addFile does,
rather than sys::fs::make_absolute. The latter gets the CWD from the platform,
while the former expects it to be set by the client, causing a mismatch when
converting relative paths to absolute.

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

llvm-svn: 290319
2016-12-22 05:10:07 +00:00
Daniel Jasper 083d1700a0 clang-format: Fix bug in handling of single-column lists.
Members that are themselves wrapped in fake parentheses would lead to
AvoidBinPacking be set on the wrong ParenState.

After:
  vector<int> aaaa = {
      aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
      aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
      aaaaaa.aaaaaaa,
      aaaaaa.aaaaaaa,
      aaaaaa.aaaaaaa,
      aaaaaa.aaaaaaa,
  };

Before we were falling back to bin-packing these.

llvm-svn: 290259
2016-12-21 17:02:06 +00:00
Daniel Jasper f789f05ee2 clang-format: Fix bug in understanding string-label&value analysis.
While for <<-operators often used in log statments, a single key value
pair is always on the second operator, e.g.

  llvm::errs() << "aaaaa=" << aaaaa;

It is on the first operator for plus- or comma-concatenated strings:

  string s = "aaaaaaaaaa: " + aaaaaaaa;

(the "=" not counting because that's a different operator precedence)

llvm-svn: 290177
2016-12-20 15:27:46 +00:00
Benjamin Kramer 353395e3c2 [Format] Remove dead code.
No functionality change.

llvm-svn: 290135
2016-12-19 21:10:50 +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
Eric Liu 93459d3142 [clang-format] revert an unintended change in r288493 and add a test case.
llvm-svn: 290093
2016-12-19 10:41:05 +00:00
Daniel Jasper ff8d61369b clang-format: Fix regression introduced in r290084.
We still want to try in linewrap within single elements of a 1-column
list.

After:
  Type *Params[] = {PointerType::getUnqual(FunctionType::get(
			Builder.getVoidTy(), Builder.getInt8PtrTy(), false)),
		    Builder.getInt8PtrTy(),
		    Builder.getInt32Ty(),
		    LongType,
		    LongType,
		    LongType};

Before:
  No line break in the first element, so column limit violation.

llvm-svn: 290090
2016-12-19 08:40:56 +00:00
Daniel Jasper e6169665ec clang-format: Allow "single column" list layout even if that violates the
column limit.

Single-column layout basically means that we format the list with one
element per line. Not doing that when there is a column limit violation
doesn't change the fact that there is an item that doesn't fit within
the column limit.

Before (with a column limit of 30):
  std::vector<int> a = {
      aaaaaaaa, aaaaaaaa,
      aaaaaaaa, aaaaaaaa,
      aaaaaaaaaa, aaaaaaaa,
      aaaaaaaaaaaaaaaaaaaaaaaaaaa};

After:
  std::vector<int> a = {
      aaaaaaaa,
      aaaaaaaa,
      aaaaaaaa,
      aaaaaaaa,
      aaaaaaaaaa,
      aaaaaaaa,
      aaaaaaaaaaaaaaaaaaaaaaaaaaa};

(and previously we would have formatted like "After" it wasn't for the one
item that is too long)

llvm-svn: 290084
2016-12-19 07:26:11 +00:00
Sylvestre Ledru dcb038d4f2 Update the default of the Mozilla coding style
Summary:
I also proposed the change in Firefox .clang-format file:
https://bugzilla.mozilla.org/show_bug.cgi?id=1322321

Reviewers: klimek

Subscribers: cfe-commits

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

llvm-svn: 289660
2016-12-14 16:09:29 +00:00
Daniel Jasper 7209bb9d4e clang-format: Keep string-literal-label + value pairs on a line.
We have previously done that for <<-operators. This patch also adds
this logic for "," and "+".

Before:
  string v = "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa + "aaaaaaaaaaaaaaaa: " +
             aaaaaaaaaaaaaaaa + "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa;
  string v = StrCat("aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa, "aaaaaaaaaaaaaaaa: ",
                    aaaaaaaaaaaaaaaa, "aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa);

After:
  string v = "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa +
	     "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa +
	     "aaaaaaaaaaaaaaaa: " + aaaaaaaaaaaaaaaa;
  string v = StrCat("aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa,
		    "aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa,
		    "aaaaaaaaaaaaaaaa: ", aaaaaaaaaaaaaaaa);

llvm-svn: 289531
2016-12-13 11:16:42 +00:00
Daniel Jasper e4ada024b0 clang-format: Improve braced-list detection.
Before:
  vector<int> v { 12 }
      GUARDED_BY(mutex);

After:
  vector<int> v{12} GUARDED_BY(mutex);

llvm-svn: 289525
2016-12-13 10:05:03 +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
Eric Liu 21d1032855 [clang-format] calculate MaxInsertOffset in the original code correctly.
Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 289203
2016-12-09 11:45:50 +00:00
Eric Liu 964782adbb [ClangFormat] Only insert #include into the #include block in the beginning of the file.
Summary:
This avoid inserting #include into:
- raw string literals containing #include.
- #if block.
- Special #include among declarations (e.g. functions).

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 288493
2016-12-02 11:01:43 +00:00
Krasimir Georgiev bba2d59ea4 Removed DEBUG_TYPE from TokenAnalyzer.h
Summary:
Defining DEBUG_TYPE in a header file doesn't make sense.
It is already defined in the corresponding source file.

Reviewers: klimek, ioeric

Subscribers: klimek

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

llvm-svn: 288125
2016-11-29 10:21:28 +00:00
Daniel Jasper e98e58111b clang-format: [JS] Properly format dict literals that skip labels.
llvm-svn: 288121
2016-11-29 09:40:36 +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
Benjamin Kramer ebac56ebb0 [Format] Avoid copying std::sets and simplify code a bit.
No functional change.

llvm-svn: 287892
2016-11-24 15:42:29 +00:00
Cameron Desrochers 1991e5d673 [clang-format] Fixed line merging of more than two lines
Differential Revision: https://reviews.llvm.org/D19063

llvm-svn: 286973
2016-11-15 15:07:07 +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
Nico Weber b2673a1e48 [clang-format] Fix PR30527: Regression when clang-format insert spaces in [] when in template
Actual regression was introduced in r272668. This revision fixes JS script, but
also regress Cpp case. It manifests with spaces added when template is followed
with array. Bug 30527 mentions case of array as a nested template type
(foo<bar<baz>[]>). Fix is to detect such case and to prevent treating it as
array initialization, but as a subscript case. However, before r272668, this
case was treated simple because we were detecting it as a StartsObjCMethodExpr.
Same was true for other similar case - array of templates (foo<int>[]). This
patch tries to address two problems: 1) fixing regression 2) making sure both
cases (array as a nested type, array of templates) which were entering
StartsObjCMethodExpr branch are handled now appropriately.

https://reviews.llvm.org/D26163
Patch from Branko Kokanovic <branko@kokanovic.org>!

llvm-svn: 286507
2016-11-10 21:49:25 +00:00
Martin Probst e19acaa361 drop kw_module from ASI protection block
llvm-svn: 286469
2016-11-10 16:21:04 +00:00
Martin Probst 3dbbefae36 clang-format: [JS] do not break after declare namespace.
Summary:
See TypeScript grammar for tokens following 'declare':
https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#A.10

Additional minor change:
clang-format: [JS] Prevent ASI before const.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 286468
2016-11-10 16:21:02 +00:00
Martin Probst 72fd75a0d1 clang-format: [JS] do not break after declare namespace.
See TypeScript grammar for tokens following 'declare':
https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#A.10

llvm-svn: 286467
2016-11-10 16:20:58 +00:00
Daniel Jasper 8315ea1613 clang-format: [TypeScript] Fix bug in handling of non-null operator.
Before:
  var i = x!-1;

After:
  var i = x! - 1;

llvm-svn: 286367
2016-11-09 14:12:55 +00:00
Daniel Jasper 528d682ff6 [clang-format] Remove (SourceManager, FileID) variants
In Format, remove the reformat() and clean() functions taking a SourceManager
and a FileID. Keep the versions taking StringRef Code.

- there was duplicated functionality
- the FileID versions were harder to use
- the clean() version is dead code anyways

Patch by Krasimir Georgiev. Thank you.

llvm-svn: 286243
2016-11-08 16:11:33 +00:00
Daniel Jasper a432208bca clang-format: Better support for CUDA's triple brackets.
Before:
  aaaaaaaaaaaaaaa<
      aaaaaaaaa, aaaaaaaaaa,
      aaaaaaaaaaaaaa><<<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaaaaaa>>>();

After:
  aaaaaaaaaaaaaaa<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaa>
      <<<aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaaaaaa>>>();

llvm-svn: 286041
2016-11-05 17:43:16 +00:00
Malcolm Parsons 6af3f14efb Fixed column shift when formatting line containing bit shift operators
Summary:
During clang-format source lexing >> and << operators are split and
treated as two less/greater operators but column position of following
tokens was not adjusted accordingly.

Fixes PR26887

Patch by Paweł Żukowski.

Reviewers: djasper

Subscribers: malcolm.parsons, mprobst, klimek, cfe-commits

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

llvm-svn: 285934
2016-11-03 16:57:30 +00:00
Daniel Jasper 28b4d5133c clang-format: Fix bug in function reference qualifier detection.
Before:
  template <typename T>
      void F(T) &&
      = delete;

After:
  template <typename T>
  void F(T) && = delete;

llvm-svn: 285674
2016-11-01 06:23:19 +00:00
Daniel Jasper d0d27aa59b clang-format: Fix incorrect pointer detection.
Before:
  void f() { f(float{1}, a *a); }

After:
  void f() { f(float{1}, a * a); }

llvm-svn: 285673
2016-11-01 06:23:14 +00:00
Daniel Jasper b559b43802 clang-format: [JS] Fix incorrect space when "as" is used as identifier.
Before:
  aaaaa.as ();

After:
  aaaaa.as();

llvm-svn: 285672
2016-11-01 06:23:10 +00:00
Daniel Jasper 3ade3be2a1 clang-format: Fix incorrect binary operator detection.
Before:
  int x = f(* + [] {});

After:
  int x = f(*+[] {});

llvm-svn: 285671
2016-11-01 06:23:05 +00:00
Daniel Jasper 71e50af675 clang-format: [JS] Fix formatting of generator functions.
Before:
  var x = {
    a: function*
	() {
	  //
	}
  }

After:
  var x = {
    a: function*() {
      //
    }
  }

llvm-svn: 285670
2016-11-01 06:22:59 +00:00
Daniel Jasper 4d67dd77a1 clang-format: [JS] Fix space when for is used as regular identifier.
Before:
  x.for () = 1;

After:
  x.for() = 1;

llvm-svn: 285669
2016-11-01 06:22:54 +00:00
Daniel Jasper fda47cd873 Skip over AnnotatedLines with >50 levels of nesting; don't format them.
Reasoning:
- ExpressionParser uses a lot of stack for these, bad in some environments.
- Our formatting algorithm is N^3 and gets really slow.
- The resulting formatting is unlikely to be any good.
- This is probably generated code we're formatting by accident.

We treat these as unparseable, and signal incomplete formatting. 50 is
an arbitrary number, I've only seen real problems from ~150 levels.

Patch by Sam McCall. Thank you.

llvm-svn: 285570
2016-10-31 13:23:00 +00:00
Daniel Jasper eb886635d9 clang-format: [JS] Fix missing space after 'yield'.
Before:
  class X {
    delete(val) {
      return null;
    }
    * gen() {
      yield[1, 2];
    }
    * gen() {
      yield{a: 1};
    }
  };

After:
  class X {
    delete(val) {
      return null;
    }
    * gen() {
      yield [1, 2];
    }
    * gen() {
      yield {a: 1};
    }
  };

llvm-svn: 285569
2016-10-31 13:18:25 +00:00
Andi-Bogdan Postelnicu a9a8fdee7e Bug 28065 - clang-format incorrectly aligns backslash.
llvm-svn: 285178
2016-10-26 07:44:51 +00:00
Martin Probst 717f6dcddc clang-format: [JS] Fix template string ASI.
Summary:
Previously, automatic semicolon insertion would add an unwrapped line
when a template string contained a line break.

    var x = `foo${
        bar}`;

Would be formatted with `bar...` on a separate line and no indent.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 284807
2016-10-21 05:11:38 +00:00
Malcolm Parsons 5d8cdb83db [Format] Cleanup after replacing constructor body with = default
Summary:
Remove colon and commas after replacing constructor body with = default.
Fix annotation of TT_CtorInitializerColon when preceded by a comment.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 284732
2016-10-20 14:58:45 +00:00
Reid Kleckner 6432d45f7b Use noexcept instead of LLVM_NOEXCEPT now that all compilers support it
llvm-svn: 284667
2016-10-19 23:39:55 +00:00
Benjamin Kramer 089a39e859 Don't copy replacements in for-range loop. NFC.
llvm-svn: 284589
2016-10-19 13:50:17 +00:00
Eric Liu 99eeab7ff3 [clang-format] Add comment manipulation header
Summary:
Introduces a separate target for comment manipulation.
Currently, comment manipulation is in BreakableComment.cpp.
Towards implementing comment reflowing, we want to factor out the
comment-related functionality, so it can be reused.
Start simple by just moving out getLineCommentIndentPrefix.

Patch by Krasimir Georgiev!

Reviewers: djasper

Subscribers: klimek, beanz, mgorny, modocache

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

llvm-svn: 284573
2016-10-19 08:19:46 +00:00
Eric Liu 735f3a26be Removed duplicate header include
Reviewers: ioeric

Subscribers: klimek

Patch by Krasimir Georgiev!

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

llvm-svn: 284228
2016-10-14 11:48:10 +00:00
Eric Liu 7956c4004d Make DeletedLines local variables in checkEmptyNamespace.
Summary: Patch by Sam McCall!

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 283332
2016-10-05 15:49:01 +00:00
Eric Liu 11a4237b23 [clang-format] append newline after code when inserting new headers at the end of the code which does not end with newline.
Summary:
append newline after code when inserting new headers at the end of the
code which does not end with newline.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 283330
2016-10-05 15:42:19 +00:00
Daniel Jasper 85d1f0b610 clang-format: Fix bad multi-variable for-loop formatting.
Before:
  for (int*p, *q; p != q; p = p->next) {

After:
  for (int *p, *q; p != q; p = p->next) {

llvm-svn: 283246
2016-10-04 20:18:25 +00:00
Justin Lebar 9091055efa Move UTF functions into namespace llvm.
Summary:
This lets people link against LLVM and their own version of the UTF
library.

I determined this only affects llvm, clang, lld, and lldb by running

$ git grep -wl 'UTF[0-9]\+\|\bConvertUTF\bisLegalUTF\|getNumBytesFor' | cut -f 1 -d '/' | sort | uniq
  clang
  lld
  lldb
  llvm

Tested with

  ninja lldb
  ninja check-clang check-llvm check-lld

(ninja check-lldb doesn't complete for me with or without this patch.)

Reviewers: rnk

Subscribers: klimek, beanz, mgorny, llvm-commits

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

llvm-svn: 282822
2016-09-30 00:38:45 +00:00
Daniel Jasper e31388aee9 [clang-format] Don't allow newline after uppercase Obj-C block return types
Fixes the following:
  BOOL (^aaa)(void) = ^BOOL {
  };

The first BOOL's token was getting set to TT_FunctionAnnotationRParen
incorrectly, which was causing an unexpected newline after (^aaa). This
was introduced in r245846.

Patch by Kent Sutherland, thank you!

llvm-svn: 282448
2016-09-26 22:19:08 +00:00
Daniel Jasper 3f2cde91d8 clang-format: Only special-case top-level */& in multivar-declstmts.
Before (even with PointerAlignment: Left):
  vector<int *> a, b;

After:
  vector<int*> a, b;

llvm-svn: 282410
2016-09-26 15:14:24 +00:00
Eric Liu c0d3a80123 [clang-format] support header deletion in cleanupAroundReplacemnts.
Summary:
- If a replacement has offset UINT_MAX, length 0, and a replacement text
  that is an #include directive, this will insert the #include into the
  correct block in the \p Code.
- If a replacement has offset UINT_MAX, length 1, and a replacement text
  that is the name of the header to be removed, the header will be removed
  from \p Code if it exists.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 282253
2016-09-23 15:10:56 +00:00
Martin Probst 4210d2fd1e clang-format: [JS] reserved words in method names.
Summary:
Before:
    class X {
      delete () {
        ...
      }
    }

After:
    class X {
      delete() {
        ...
      }
    }

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 282138
2016-09-22 07:18:00 +00:00
Martin Probst 6f99d2433b clang-format: [JS] do not wrapp @returns tags.
Summary: @returns is incorrect code, the standard is @return. However wrapping it can still confuse users.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 282056
2016-09-21 06:56:38 +00:00
Martin Probst 63014581aa clang-format: [JS] Fix line breaks before comments when sorting imports.
Summary:
Previously, clang-format would always insert an additional line break after the
import block if the main body started with a comment, due to loosing track of
the first non-import line.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 281888
2016-09-19 07:02:34 +00:00
Martin Probst fbbe75b1fe clang-format: [JS] Do not wrap taze annotation comments.
Summary:
`// taze: ... from ...` comments are used help tools where a
specific global symbol comes from.

Before:
    // taze: many, different, symbols from
    // 'some_long_location_here'

After:
    // taze: many, different, symbols from 'some_long_location_here'

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 281857
2016-09-18 17:33:51 +00:00
Martin Probst b9316ff849 clang-format: [JS] ASI insertion after boolean literals.
Summary:
Before when a semicolon was missing after a boolean literal:
    a = true
    return 1;

clang-format would parse this as one line and format as:
    a = true return 1;

It turns out that C++ does not consider `true` and `false` to be literals, we
have to check for that explicitly.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 281856
2016-09-18 17:21:52 +00:00
Daniel Jasper 58209dd9ad clang-format: [JS] Fix a crash in handledTemplateStrings.
llvm-svn: 281816
2016-09-17 07:20:36 +00:00
Eric Liu 2574d15c5b Remove redundant comma around parenthesis in parameter list.
Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 281344
2016-09-13 15:02:43 +00:00
Eric Liu 01426ff875 Also cleanup comments around redundant colons/commas in format::cleanup.
Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 281064
2016-09-09 17:50:49 +00:00
Daniel Jasper 28d8a5ab43 clang-format: [JavaScript] Change default AllowShortFunctionsOnASingleLine
for Google style to "empty".

llvm-svn: 280878
2016-09-07 23:01:13 +00:00
Daniel Jasper 496c199959 clang-format: [JavaScript] Do requoting in a separate pass
The attempt to fix requoting behavior in r280487 after changes to
tooling::Replacements are incomplete. We essentially need to add to
replacements at the same position, one to insert a line break and one to
change the quoting and that's incompatible with the new
tooling::Replacement API, which does not allow for order-dependent
Replacements. To make the order clear, Replacements::merge() has to be
used, but that requires the merged Replacement to actually refer to the
changed text, which is hard to reproduce for the requoting.

This change fixes the behavior by moving the requoting to a completely
separate pass. The added benefit is that no weird ColumnWidth
calculations are necessary anymore and this should just work even if we
implement string literal splitting in the future.

llvm-svn: 280874
2016-09-07 22:48:53 +00:00
Martin Probst 34ecf42bff clang-format: [JS] whitespace required between ! and as.
Summary:
Before:
    x!as string
After:
    x! as string

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 280731
2016-09-06 18:55:34 +00:00
Martin Probst 56ff7aaacb clang-format: [JS] ignore comments when wrapping returns.
Summary:
When code contains a comment between `return` and the value:

    return /* lengthy comment here */ (
        lengthyValueComesHere);

Do not wrap before the comment, as that'd break the code through JS' automatic
semicolon insertion.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 280730
2016-09-06 18:39:30 +00:00
Martin Probst a9855afedf clang-format: [JS] merge requoting replacements.
Summary:
When formatting source code that needs both requoting and reindentation,
merge the replacements to avoid erroring out for conflicting replacements.

Also removes the misleading Replacements parameter from the
TokenAnalyzer API.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 280487
2016-09-02 14:29:48 +00:00
Martin Probst 6918dcafe8 clang-format: [JS] handle default bindings in imports.
Summary:
Default imports appear outside of named bindings in curly braces:

  import A from 'a';
  import A, {symbol} from 'a';

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 280486
2016-09-02 14:06:32 +00:00
Martin Probst b480ffbcef clang-format: [JS] Sort all JavaScript imports if any changed.
Summary:
User feedback is that they expect *all* imports to be sorted if any import was
affected by a change, not just imports up to the first non-affected line, as
clang-format currently does.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 280485
2016-09-02 14:01:17 +00:00
Daniel Jasper 3042713b4b clang-format: Set default WebKit style to use C++11.
The WebKit style page says to use nullptr, so this should be fine:
https://webkit.org/code-style-guidelines/

This fixes: llvm.org/PR30220

llvm-svn: 280245
2016-08-31 14:05:56 +00:00
Daniel Jasper d6a0078039 clang-format: Correctly calculate affected ranges when sorting #includes.
affectedRanges takes a start and an end offset, not offset and length.

llvm-svn: 280165
2016-08-30 21:33:41 +00:00
Martin Probst 6181da4796 clang-format: [JS] nested and tagged template strings.
JavaScript template strings can be nested arbitrarily:

    foo = `text ${es.map(e => { return `<${e}>`; })} text`;

This change lexes nested template strings using a stack of lexer states to
correctly switch back to template string lexing on closing braces.

Also, reuse the same stack for the token-stashed logic.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 279727
2016-08-25 10:13:21 +00:00
Martin Probst ed87d788d6 clang-format: [JS] supports casts to types starting with punctuation ("{[(").
Before:

    x as{x: number}

After:

    x as {x: number}

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 279436
2016-08-22 14:23:30 +00:00
Martin Probst e1e12a73d7 clang-format: [JS] handle object literals with casts.
Summary: E.g. `{a: 1} as b`.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 279250
2016-08-19 14:35:01 +00:00
Eric Liu a992afe809 Make clang-format remove duplicate headers when sorting #includes.
Summary: When sorting #includes, #include directives that have the same text will be deduplicated when sorting #includes, and only the first #include in the duplicate #includes remains. If the `Cursor` is provided and put on a deleted #include, it will be put on the remaining #include in the duplicate #includes.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 278206
2016-08-10 09:32:23 +00:00
Sylvestre Ledru 83bbd5731b clang-format: Add SpaceAfterTemplate
Summary:
This is required for compliance with the Mozilla style guide.

This is a rebase+minor change of Birunthan Mohanathas's patch


Reviewers: djasper

Subscribers: klimek, cfe-commits, opilarium

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

llvm-svn: 278121
2016-08-09 14:24:40 +00:00
Eric Liu 40ef2fb363 Implement tooling::Replacements as a class.
Summary:
- Implement clang::tooling::Replacements as a class to provide interfaces to
  control how replacements for a single file are combined and provide guarantee
  on the order of replacements being applied.
- tooling::Replacements only contains replacements for the same file now.
  Use std::map<std::string, tooling::Replacements> to represent multi-file
  replacements.
- Error handling for the interface change will be improved in followup patches.

Reviewers: djasper, klimek

Subscribers: cfe-commits

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

llvm-svn: 277335
2016-08-01 10:16:37 +00:00
Daniel Jasper 31343832e7 clang-format: Fix incorrect detection of QT-signals access specifier.
Before:
  void f() {
  label:
    signals
    .baz();
  }

After:
  void f() {
  label:
    signals.baz();
  }

llvm-svn: 276854
2016-07-27 10:13:24 +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 d9d8da2821 clang-format: [JS] Allow top-level conditionals again.
I am not sure exactly which test breakage Martin was trying to fix in
r273694. For now, fix the behavior for top-level conditionals, which
(surprisingly) are actually used somewhat commonly.

llvm-svn: 275183
2016-07-12 15:45:53 +00:00
Eric Liu 4f8d99433d Make tooling::applyAllReplacements return llvm::Expected<string> instead of empty string to indicate potential error.
Summary:
return llvm::Expected<> to carry error status and error information.
This is the first step towards introducing "Error" into tooling::Replacements.

Reviewers: djasper, klimek

Subscribers: ioeric, klimek, cfe-commits

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

llvm-svn: 275062
2016-07-11 13:53:12 +00:00
Martin Probst 2a19454a86 clang-format: [JS] Sort imports case insensitive.
Summary: ASCII case sorting does not help finding imported symbols quickly, and it is common to have e.g. class Foo and function fooFactory exported/imported from the same file.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 274977
2016-07-09 15:11:18 +00:00
Martin Probst a8c9d154b8 clang-format: [JS] support trailing commas in imports.
Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 274976
2016-07-09 15:09:22 +00:00
Martin Probst ec3dc98802 clang-format: [JS] Fix build breakage.
Checking Line.MustBeDeclaration does actually break the field and param initializer use case.

llvm-svn: 273694
2016-06-24 17:45:13 +00:00
Martin Probst 31d6da7c0c clang-format: [JS] handle conditionals in fields, default params.
Summary:

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 273619
2016-06-23 21:51:49 +00:00
Martin Probst 1b7f98042d clang-format: [JS] recognize more type locations.
Summary: Includes parenthesized type expressions and type aliases.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 273603
2016-06-23 19:52:32 +00:00
Daniel Jasper 7f3b99fca7 clang-format: [Proto] Use more compact format for text-formatted options
Before:
  enum Type {
    UNKNOWN = 0 [(some_options) = {
      a: aa,
      b: bb
    }];
  };

After:
  enum Type {
    UNKNOWN = 0 [(some_options) = {a: aa, b: bb}];
  };

llvm-svn: 273553
2016-06-23 09:40:19 +00:00
Martin Probst dce8e4173b clang-format: [JS] Do not break before 'as'.
Summary:
'as' is a pseudo operator, so automatic semicolon insertion kicks in and the
code fails to part.

Reviewers: djasper

Subscribers: klimek

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

llvm-svn: 273422
2016-06-22 14:35:14 +00:00
Daniel Jasper f8bcc2445d clang-format: [JS] Add a Closure Compiler JSDoc tags to the default
Google configuration so that it isn't line-wrapped.

llvm-svn: 273285
2016-06-21 17:00:20 +00:00
Daniel Jasper 8b61d14d7e clang-format: [Proto] Fix "import public" after r273179.
llvm-svn: 273196
2016-06-20 20:39:53 +00:00
Daniel Jasper 3d5a7d6b65 clang-format: [Proto] Don't do bad things if imports are missing ;.
llvm-svn: 273179
2016-06-20 18:20:38 +00:00
Eric Liu 3753f912bf [clang-format] do not add existing includes.
Summary: do not add existing includes.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 272669
2016-06-14 14:09:21 +00:00
Daniel Jasper 887a399418 clang-format: [JS] Fix failing format with TypeScript casts.
Before, this could be formatted at all (with BracketAlignmentStyle
AlwaysBreak):

  foo = <Bar[]>[
    1, /* */
    2
  ];

llvm-svn: 272668
2016-06-14 13:54:38 +00:00
Daniel Jasper 6465008e0e clang-format: [JS] Support annotated classes.
llvm-svn: 272654
2016-06-14 11:28:02 +00:00
Martin Probst fb2342d274 clang-format: [JS] Initialize new configuration value.
llvm-svn: 272569
2016-06-13 17:50:10 +00:00
Martin Probst ece8c0c65f clang-format: [JS] Indent namespaces in JavaScript/TS by default.
Summary: There's no convention of avoiding the nested indentation.

Reviewers: djasper

Subscribers: klimek, alexeagle, cfe-commits

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

llvm-svn: 272559
2016-06-13 16:41:28 +00:00
Martin Probst 0cd74ee875 clang-format: [JS] Introduce JavaScriptWrapImports option.
Summary:
When turned on, clang-format wraps JavaScript imports (and importing exports),
instead of forcing the entire import statement onto one line.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 272558
2016-06-13 16:39:50 +00:00
Daniel Jasper 1f5d6371fd clang-format: Restrict r272537 to function ref qualifiers.
Seems this isn't generally desirable.

Before:
  int const * a;

After:
  int const* a;

llvm-svn: 272548
2016-06-13 14:45:12 +00:00
Daniel Jasper 215616691a clang-format: Fix incorrect function type detection.
Before:
  returnsFunction (&param1, &param2)(param);

After:
  returnsFunction(&param1, &param2)(param);

llvm-svn: 272538
2016-06-13 07:49:35 +00:00
Daniel Jasper 43e4d3a05b clang-format: Don't merge const and &, e.g. in function ref qualifiers.
Before (when aligning & to the right):
  SomeType MemberFunction(const Deleted &) const&;

After:
  SomeType MemberFunction(const Deleted &) const &;

This also applies to variable declarations, e.g.:
  int const * a;

However, this form is very uncommon (most people would write
"const int* a" instead) and contracting to "const*" might actually send
the wrong signal of what the const binds to.

llvm-svn: 272537
2016-06-13 07:49:28 +00:00
Daniel Jasper 594be2f037 clang-format: Fix incorrect cast detection.
Before:
  auto s = sizeof...(Ts)-1;

After:
  auto s = sizeof...(Ts) - 1;

llvm-svn: 272536
2016-06-13 07:49:09 +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
Martin Probst 0eb40cfa6f clang-format: [JS] post-fix non-null assertion operator.
Summary:
Do not insert whitespace preceding the "!" postfix operator. This is an
incomplete fix, but should cover common usage.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 272524
2016-06-13 00:49:54 +00:00
Eric Liu 43d67b6883 [clang-format] pass Style by reference instead of value.
llvm-svn: 272465
2016-06-11 11:45:08 +00:00
Martin Probst 2ec2324f3c clang-format: [JS] recognized named functions in AnnotatingParser.
Summary: This also fixes union type formatting in function parameter types.

Before: function x(path: number| string) {}
After: function x(path: number|string) {}

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 272330
2016-06-09 22:49:04 +00:00
Martin Probst 4838588343 clang-format: [JS] fix a FIXME.
llvm-svn: 272143
2016-06-08 14:05:26 +00:00
Martin Probst 6f43efbdde clang-format: [JS] fix an assertion failure caused by shrinking sources.
Summary:
The JavaScript import sorter has a corner condition that can cause the overall
source text length to shrink. This change circumvents the issue by appending
trailing space in the line after the import blocks to match at least the
previous source code length.

This needs a better long term fix, but this fixes the immediate issue.

Reviewers: alexeagle, djasper

Subscribers: klimek

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

llvm-svn: 272142
2016-06-08 14:04:04 +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 2b4d6eae39 clang-format: Fix bug in function ref qualifier identification.
.. and simplify it.

Before:
  void A::f()&& {}
  void f() && {}

After:
  void A::f() && {}
  void f() && {}

llvm-svn: 272124
2016-06-08 08:23:46 +00:00
Eric Liu 3528832930 [clang-format] make header guard identification stricter (with Lexer).
Summary: make header guard identification stricter with Lexer.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 271883
2016-06-06 11:00:13 +00:00
Eric Liu 303baf53b1 [clang-format] skip empty lines and comments in the top of the code when inserting new headers.
Summary:
[clang-format] skip empty lines and comments in the top of the code when inserting new headers.

Pair-programmed with @hokein

Reviewers: djasper

Subscribers: ioeric, cfe-commits, hokein, klimek

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

llvm-svn: 271664
2016-06-03 12:52:59 +00:00
Martin Probst 48622090c7 clang-format: [JS] no ASI on `import {x as\n y}`.
Summary: ASI did not handle the ES6 `as` operator correctly.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 271401
2016-06-01 15:22:47 +00:00
Martin Probst 081f176a62 clang-format: [JS] Sort imported symbols.
Summary: E.g. sort `import {b, a} from 'x';` into `import {a, b} from 'x';`.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 271400
2016-06-01 15:19:53 +00:00
Benjamin Kramer 1cb7ee1300 Avoid unused variable warning in release builds.
llvm-svn: 271280
2016-05-31 14:14:42 +00:00
Eric Liu 659afd55fa [clang-format] insert new #includes into correct blocks when cleaning up Replacement with cleanupAroundReplacements().
Summary:
When a replacement's offset is set to UINT_MAX or -1U, it is treated as
a header insertion replacement by cleanupAroundReplacements(). The new #include
directive is then inserted into the correct block.

Reviewers: klimek, djasper

Subscribers: klimek, cfe-commits, bkramer

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

llvm-svn: 271276
2016-05-31 13:34:20 +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
Martin Probst 7ea9b6d783 clang-format: [JS] Support shebang lines on the very first line.
Summary:
Shebang lines (`#!/bin/blah`) can be used in JavaScript scripts to indicate
they should be run using e.g. node. This change treats # lines on the first line
as line comments.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 271185
2016-05-29 14:41:36 +00:00
Martin Probst 409697ecb9 clang-format: [JS] fix async parsing.
Summary:
Only treat the sequence `async function` as the start of a function expression,
as opposed to every occurrence of the token `async` (whoops).

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 271184
2016-05-29 14:41:07 +00:00
Martin Probst 1244ecbbd2 clang-format: [JS] FormatToken.startsSequence/endsSequence.
Refactors AnnotatedLine.startsWith/endsWith by extracting the core functionality
into FormatToken.startsSequence/endsSequence. This allows checking tokens within
the pointered linked list structure with a lookahead, automatically ignoring
comments, which is useful in many places (e.g. see subsequent commit).

llvm-svn: 271183
2016-05-29 14:41:02 +00:00
Daniel Jasper 99302edd1c clang-format: Allow splitting the line after /**/-comments.
While it might change the meaning of the comment in rare circumstances,
it is better than violating the column limit.

llvm-svn: 270975
2016-05-27 08:59:34 +00:00
Martin Probst c4a0dd49a3 clang-format: [JS] sort ES6 imports.
Summary:
This change automatically sorts ES6 imports and exports into four groups:
absolute imports, parent imports, relative imports, and then exports. Exports
are sorted in the same order, but not grouped further.

To keep JS import sorting out of Format.cpp, this required extracting the
TokenAnalyzer infrastructure to separate header and implementation files.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 270203
2016-05-20 11:24:24 +00:00
Daniel Jasper 997cf2fea8 clang-format: [JS] Treat "for" as a reserved word after a ".".
Otherwise, clang-format can get confused with statements like:

  x.for = 1;

llvm-svn: 270188
2016-05-20 06:16:01 +00:00
Daniel Jasper 5dbcd3bd07 clang-format: [JS] Fix spacing in destructuring assignments.
Before:
  const[a, b, c] = [1, 2, 3];

After:
  const [a, b, c] = [1, 2, 3];

llvm-svn: 270029
2016-05-19 07:18:07 +00:00
Daniel Jasper 451544ab57 clang-format: Fix incorrect indentation in last line of macro definition
Before:
  #define MACRO(a) \
    if (a) {       \
      f();         \
    } else         \
    g()

After:
  #define MACRO(a) \
    if (a) {       \
      f();         \
    } else         \
      g()

llvm-svn: 270028
2016-05-19 06:30:48 +00:00
Daniel Jasper e2fab13313 clang-format: Fix enumerator case ranges.
Before:
  case a... b: break;

After:
  case a ... b: break;

llvm-svn: 270027
2016-05-19 06:19:17 +00:00
Eric Liu baf58c2309 [clang-format] Make formatReplacements() also sort #includes.
Summary: [clang-format] Make formatReplacements() also sort #includes.

Reviewers: bkramer, djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 269924
2016-05-18 13:43:48 +00:00
Eric Liu 2874ac3e28 [clang-format] Make FormatTokenLess::operator() const.
llvm-svn: 269889
2016-05-18 08:14:49 +00:00
Eric Liu ce5e4bc7ac Make clang-format cleaner remove redundant commas in list and redundant colon in constructor initializer.
Summary: Make clang-format cleaner remove redundant commas/colons in constructor initializer list.

Reviewers: klimek, djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 269888
2016-05-18 08:02:56 +00:00
Martin Probst cb6e042040 clang-format: [JS] simplify logic by parsing forward.
This also reduces complexity to O(n) from O(n^2) by avoiding backtracking
re-parses, and fixes length calculation.

llvm-svn: 269748
2016-05-17 06:29:33 +00:00
Martin Probst e71b4cbdd1 clang-format: [JS] fix template string width counting.
Summary:
Simply looking at the final text greatly simplifies the algorithm and also
fixes a reported issue. This requires duplicating the "actual encoding width"
logic, but that seems cleaner than the column acrobatics before.

Reviewers: djasper, bkramer

Subscribers: cfe-commits, klimek

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

llvm-svn: 269747
2016-05-17 06:29:29 +00:00
Martin Probst a166979e45 clang-format: [JS] respect clang-format off when requoting strings.
Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 269282
2016-05-12 11:20:32 +00:00
Nemanja Ivanovic bb1ea2d613 Enable support for __float128 in Clang and enable it on pertinent platforms
This patch corresponds to reviews:
http://reviews.llvm.org/D15120
http://reviews.llvm.org/D19125

It adds support for the __float128 keyword, literals and target feature to
enable it. Based on the latter of the two aforementioned reviews, this feature
is enabled on Linux on i386/X86 as well as SystemZ.
This is also the second attempt in commiting this feature. The first attempt
did not enable it on required platforms which caused failures when compiling
type_traits with -std=gnu++11.

If you see failures with compiling this header on your platform after this
commit, it is likely that your platform needs to have this feature enabled.

llvm-svn: 268898
2016-05-09 08:52:33 +00:00
Daniel Jasper 2b2c967c1a clang-format: Fix space after argument comments.
Before:
  f(/*a=*/a, /*b=*/ ::b);

After:
  f(/*a=*/a, /*b=*/::b);

llvm-svn: 268879
2016-05-08 18:14:01 +00:00
Daniel Jasper a7900adf41 clang-format: Support enum type template arguments.
Before:
  template <enum E> class A { public : E *f(); };

After:
  template <enum E> class A {
  public:
    E *f();
  };

llvm-svn: 268878
2016-05-08 18:12:22 +00:00
Eric Liu 8d59829947 removed redundant '#'
llvm-svn: 267860
2016-04-28 07:52:06 +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
Eric Liu c5cad396dd Addressed review's comments.
llvm-svn: 267858
2016-04-28 07:51:47 +00:00
Eric Liu 4cfb88a936 Added Fixer implementation and fix() interface in clang-format for removing redundant code.
Summary:
After applying replacements, redundant code like extra commas or empty namespaces
might be introduced. Fixer can detect and remove any redundant code introduced by replacements.
The current implementation only handles redundant commas.

Reviewers: djasper, klimek

Subscribers: ioeric, mprobst, klimek, cfe-commits

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

llvm-svn: 267416
2016-04-25 15:09:22 +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
Eric Liu 89be047201 Fixed a bug in AnnotatedLine::startsWith when there are comments in the line.
Summary: When there are comments in the line, one token may be checked multiple times.

Reviewers: mprobst, djasper

Subscribers: ioeric, cfe-commits, klimek

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

llvm-svn: 266803
2016-04-19 19:25:33 +00:00
Martin Probst 533965c195 reuse mustBeJSIdent for interface detection
llvm-svn: 266790
2016-04-19 18:19:06 +00:00
Martin Probst 1e8261ea04 clang-format: [JS] support `interface` as a free standing identifier.
Summary:
`interface` can be used as a fee standing identifier in JavaScript/TypeScript.
This change uses the heuristic of whether it's followed by another identifier
as an indication.

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

llvm-svn: 266789
2016-04-19 18:18:59 +00:00
Martin Probst 053f1aa6d0 clang-format: [JS] simplify import/export.
Summary:
Change `import` and `export` parsing to special case the renaming
syntax (`import x, {y as bar} ...`, `export {x}`) and otherwise just
parse a regular structural element.

This simplifies the code a bit and should be more correct - it's easier
to recognise the specific import syntax than to recognise arbitrary
expressions and declarations.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 266743
2016-04-19 14:55:37 +00:00
Daniel Jasper c3ff0cd8a2 clang-format: Improve heuristics to detect function declarations/definitions.
Specifically understand ellipses in parameter lists and treat trailing
reference qualifiers and the "{" as signals.

llvm-svn: 266599
2016-04-18 11:31:21 +00:00
Mehdi Amini 7322b8bcc0 Add missing include for StringRef (NFC)
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 266594
2016-04-18 09:08:59 +00:00
Nemanja Ivanovic d7d45bf8ce Revert 266186 as it breaks anything that includes type_traits on some platforms
Since this patch provided support for the __float128 type but disabled it
on all platforms by default, some platforms can't compile type_traits with
-std=gnu++11 since there is a specialization with __float128.
This reverts the patch until D19125 is approved (i.e. we know which platforms
need this support enabled).

llvm-svn: 266460
2016-04-15 18:04:13 +00:00
Marianne Mailhot-Sarrasin 03137c6538 clang-format: Last line in incomplete block is indented incorrectly
Indentation of the last line was reset to the initial indentation of the block when reaching EOF.

Patch by Maxime Beaulieu

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

llvm-svn: 266321
2016-04-14 14:56:49 +00:00
Marianne Mailhot-Sarrasin 51fe279fbb clang-format: Implemented tab usage for continuation and indentation
Use tabs to fill whitespace at the start of a line.

Patch by Maxime Beaulieu

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

llvm-svn: 266320
2016-04-14 14:52:26 +00:00
Marianne Mailhot-Sarrasin 4988fa1bc5 clang-format: Allow include of clangFormat.h in managed context
Including VirtualFileSystem.h in the clangFormat.h indirectly includes <atomic>.
This header is blocked when compiling with /clr.

Patch by Maxime Beaulieu

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

llvm-svn: 266319
2016-04-14 14:47:37 +00:00
Nemanja Ivanovic 50f29e06a1 Enable support for __float128 in Clang
This patch corresponds to review:
http://reviews.llvm.org/D15120

It adds support for the __float128 keyword, literals and a target feature to
enable it. This support is disabled by default on all targets and any target
that has support for this type is free to add it.

Based on feedback that I've received from target maintainers, this appears to
be the right thing for most targets. I have not heard from the maintainers of
X86 which I believe supports this type. I will subsequently investigate the
impact of enabling this on X86.

llvm-svn: 266186
2016-04-13 09:49:45 +00:00
Benjamin Kramer 5ffc24e202 [clang-format] Walk backwards from end() instead of forwards from rend().
This should've been forwards from rbegin(), reverse iterators are just
too confusing to be used by mere mortals. Fixes out-of-bounds walks over
the list.

llvm-svn: 265934
2016-04-11 12:19:19 +00:00
Martin Probst bbffeac569 clang-format: [JS] do not insert semicolons after wrapped annotations.
Reviewers: djasper

Subscribers: klimek

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

llvm-svn: 265916
2016-04-11 07:35:57 +00:00
Daniel Jasper 2cce7b728b clang-format: Fix label-in-if statement in macros where it is actually used.
Before:
  #define A \
    if (a)  \
    label:  \
    f()

After:
  #define A \
    if (a)  \
    label:  \
      f()

llvm-svn: 265557
2016-04-06 16:41:39 +00:00
Daniel Jasper 4060947289 clang-format: Support labels in brace-less ifs.
While I am not personally convinced about the usefulness of this
construct, we should break it.

Before:
  if (a) label:
  f();

After:
  if (a)
  label:
    f();

llvm-svn: 265545
2016-04-06 15:02:46 +00:00
Daniel Jasper 19bc1d007a clang-format: Fix incorrect function annotation detection.
Before:
  MACRO(
      abc).function() // wrap
      << abc;

After:
  MACRO(abc).function() // wrap
      << abc;

llvm-svn: 265540
2016-04-06 13:58:09 +00:00
Daniel Jasper 94b1bdf91a clang-format: Fix cast detection on "this".
Before:
  auto x = (X) this;

After:
  auto x = (X)this;

This fixes llvm.org/PR27198.

llvm-svn: 265385
2016-04-05 11:46:06 +00:00
Eric Liu 4c1ef97adb Added formatAndApplyAllReplacements that works on multiple files in libTooling.
Summary:
formatAndApplyAllReplacements takes a set of Replacements, applies them on a
Rewriter, and reformats the changed code.

Reviewers: klimek, djasper

Subscribers: ioeric, klimek, cfe-commits

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

llvm-svn: 264745
2016-03-29 16:31:53 +00:00
Eric Liu 547d87912a Added support for different VFSs in format::getStyle. Disable platform-related test case for MS compilers to avoid breaking buildbot.
llvm-svn: 264277
2016-03-24 13:22:42 +00:00
Eric Liu d47583232a Revert "Added support for different VFSs in format::getStyle."
This reverts commit r264253. It is breaking the buildbot http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/2203

llvm-svn: 264276
2016-03-24 13:22:37 +00:00
Eric Liu 295915ceb7 Revert "removed redundant comment in format::getStyle."
This reverts commit r264254.

llvm-svn: 264275
2016-03-24 13:22:28 +00:00
Eric Liu 6b47faad53 Revert "Added support for different VFSs in format::getStyle."
This reverts commit r264253. It is breaking the buildbot http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/2203

llvm-svn: 264257
2016-03-24 11:25:28 +00:00