Commit Graph

1301 Commits

Author SHA1 Message Date
Manuel Klimek 9e32199861 Do not force linebreaks when MaxEmptyLinesToKeep is 0.
Previously we would format
 call(

     p);
as
 call(
     p);
with MaxEmptyLinesToKeep == 0.

Now we format it as:
  call(p);

llvm-svn: 243429
2015-07-28 15:50:24 +00:00
Daniel Jasper bcad06640b clang-format: Fix unary operator detection in for loops.
Before:
  for (;; * a = b) {}

After:
  for (;; *a = b) {}

llvm-svn: 242849
2015-07-21 22:51:00 +00:00
Daniel Jasper e35c220c8b clang-format: Fix crasher when a UTF8 character is found in an escape
sequence. Discovered by the fuzzer.

llvm-svn: 242738
2015-07-20 23:28:07 +00:00
Daniel Jasper 352f0df46d clang-format: Take nested lines into account when detection C++03
compatibility and variable alignment.

llvm-svn: 242611
2015-07-18 16:35:30 +00:00
Daniel Jasper 3c44c220f5 clang-format: Respect IndentWrappedFunctionNames when aligning colons
Before:
  - (void)shortf:(GTMFoo *)theFoo
  dontAlignNamef:(NSRect)theRect {
  }

After:
  - (void)shortf:(GTMFoo *)theFoo
      dontAlignNamef:(NSRect)theRect {
  }

Patch by Kwasi Mensah, thank you!

llvm-svn: 242484
2015-07-16 22:58:24 +00:00
Daniel Jasper c6dd273a98 clang-format: [Proto] Handle enum bodies differently.
In proto, enum constants can contain complex options and should be
handled more like individual declarations.

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

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

llvm-svn: 242404
2015-07-16 14:25:43 +00:00
Birunthan Mohanathas 525579d41c clang-format: Fix return type breaking with overloaded operator functions
Differential Revision: http://reviews.llvm.org/D11177

llvm-svn: 242316
2015-07-15 19:11:58 +00:00
Daniel Jasper 00fb2a1183 clang-format: Fix column layout with a comment in the last line.
Before:
  int aaaaa[] = {
      1, 2,
      3, // comment
      4, 5,
      6  // comment
  };

After:
  int aaaaa[] = {
      1, 2, 3, // comment
      4, 5, 6  // comment
  };

llvm-svn: 242299
2015-07-15 16:26:47 +00:00
Daniel Jasper ea40cee24d clang-format: Fix formatting of multiple lambdas in initializers.
Before:
  SomeFunction({[&] {
    // comment
  },
                [&] {
                  // comment
                }});

After:
  SomeFunction({[&] {
                  // comment
                },
                [&] {
                  // comment
                }});

llvm-svn: 242138
2015-07-14 11:26:14 +00:00
Birunthan Mohanathas 305fa9c2bf clang-format: Add Mozilla brace breaking style
Differential Revision: http://reviews.llvm.org/D10883

llvm-svn: 241986
2015-07-12 03:13:54 +00:00
Daniel Jasper b9a52814bf clang-format: [JS] Assign proper penalties when breaking a type annotation
Before:
  class Test {
    aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa:
                         aaaaaaaaaaaaaaaaaaaaaaaa): aaaaaaaaaaaaaaaaaaaaaa {}
  }

After:
  class Test {
    aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaa):
        aaaaaaaaaaaaaaaaaaaaaa {}
  }

llvm-svn: 241908
2015-07-10 13:39:26 +00:00
Daniel Jasper 3bacc4df8e clang-format: Break after "for (" less eagerly.
Before:
  for (
      auto aaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
      aaaaaaaaaaaaaaaaaaaaaaaaaaa != bbbbbbbbbbbbbbbbbbbbbbb;
      ++aaaaaaaaaaaaaaaaaaaaaaaaaaa) {

After:
  for (auto aaaaaaaaaaaaaaaaaaaaaaaaaaa(
           aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
       aaaaaaaaaaaaaaaaaaaaaaaaaaa != bbbbbbbbbbbbbbbbbbbbbbb;
       ++aaaaaaaaaaaaaaaaaaaaaaaaaaa) {

llvm-svn: 241601
2015-07-07 16:09:39 +00:00
Daniel Jasper b9edcfb018 clang-format: Don't wrap before the ] of a lambda introducer.
Before:
  return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa([=
  ](int iiiiiiiiiiii) {
    return aaaaaaaaaaaaaaaaaaaaaaa != aaaaaaaaaaaaaaaaaaaaaaa;
  });

After:
  return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa([=](
      int iiiiiiiiiiii) {
    return aaaaaaaaaaaaaaaaaaaaaaa != aaaaaaaaaaaaaaaaaaaaaaa;
  });

llvm-svn: 241583
2015-07-07 13:50:50 +00:00
Daniel Jasper 5c235c0966 clang-format: [JS] Properly reset parse state after parsing interface.
llvm-svn: 241446
2015-07-06 14:26:04 +00:00
Daniel Jasper b2328b1e7f clang-format: [JS] Prevent confusing TypeScript parameters wraps.
Before:
  aaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa:
                     aaaaaaaaaaaaaaaaaa): aaaaaaaaaaaaaaaaaaaaaa {}

After:
  aaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa,
                     aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa):
      aaaaaaaaaaaaaaaaaaaaaa {}

llvm-svn: 241444
2015-07-06 14:07:51 +00:00
Daniel Jasper a5fa4d1d7e clang-format: Fix __attribute__ being treated as decl name.
__attribute__ was treated as the name of a function definition, with the
tokens in parentheses being the parameter list. This formats incorrectly
with AlwaysBreakAfterDefinitionReturnType. Fix it by treating
__attribute__ like decltype.

Patch by Strager Neds, thank you.

llvm-svn: 241439
2015-07-06 11:30:34 +00:00
Birunthan Mohanathas b001a0ba5e clang-format: Add MacroBlock{Begin,End} options
The MacroBlockBegin and MacroBlockEnd options make matching macro identifiers
behave like '{' and '}', respectively, in terms of indentation.

Mozilla code, for example, uses several macros that begin and end a scope.
Previously, Clang-Format removed the indentation resulting in:

    MACRO_BEGIN(...)
    MACRO_ENTRY(...)
    MACRO_ENTRY(...)
    MACRO_END

Now, using the options

    MacroBlockBegin: "^[A-Z_]+_BEGIN$"
    MacroBlockEnd: "^[A-Z_]+_END$"

will yield the expected result:

    MACRO_BEGIN(...)
      MACRO_ENTRY(...)
      MACRO_ENTRY(...)
    MACRO_END

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

llvm-svn: 241363
2015-07-03 17:25:16 +00:00
Daniel Jasper 5a3de1d0e1 clang-format: [JS] Allow line breaks after TypeScript type colons.
llvm-svn: 241339
2015-07-03 10:37:23 +00:00
Daniel Jasper 043ac05010 clang-format: [Java/JS] Properly support instanceof and its precedence.
llvm-svn: 241337
2015-07-03 10:12:53 +00:00
Daniel Jasper f144620cc1 clang-format: [JS] Treat regex literals like string literals.
Using the token type "unknown" can interfere badly with
WhitespaceManager's way of handling multiline comments.

llvm-svn: 241273
2015-07-02 15:00:44 +00:00
Daniel Jasper f737215288 clang-format: [JS] Skip comments when applying the regex-literal heuristic
llvm-svn: 241264
2015-07-02 14:14:04 +00:00
Daniel Jasper 55c384e039 clang-format: [JS] Fix bug in regex literal parsing.
The lexer wasn't properly reset leading to unexpected deletions.

llvm-svn: 241262
2015-07-02 14:01:34 +00:00
Daniel Jasper c553ae13b5 clang-format: [JS] Support regex literals at the start of a file.
llvm-svn: 241259
2015-07-02 13:20:45 +00:00
Daniel Jasper 553a5b0041 clang-format: [JS] Fix character counting in template strings.
Some counts were off, we don't need to take the leading newlines of the
first ` into account and some tests were just wrong.

llvm-svn: 241257
2015-07-02 13:08:28 +00:00
Daniel Jasper 3992e2c742 clang-format: Support member function reference qualifiers with
trailing return types.

Before:
  template <typename T>
      auto x() & -> int {}

After:
  template <typename T>
  auto x() & -> int {}

llvm-svn: 241188
2015-07-01 21:02:24 +00:00
Daniel Jasper a87af7a326 clang-format: Properly parse parenthesis in braced lists.
Among other things, this makes clang-format understand arbitrary blocks
embedded in them, such as:

  SomeFunction({MACRO({ return output; }), b});

where MACRO could e.g. expand to a lambda.

llvm-svn: 241059
2015-06-30 11:32:22 +00:00
Birunthan Mohanathas a0388a8af2 clang-format: Add option to break after definition return type for top-level functions only
Differential Revision: http://reviews.llvm.org/D10774

llvm-svn: 240959
2015-06-29 15:30:42 +00:00
Daniel Jasper 739b85f2e7 clang-format: Don't indent relative to unary operators (some more).
Before:
  long aaaaaaaa = !aaaa( // break
                      aaaaaa);
  long aaaaaaaa = !aa.aa( // break
      aaaaaa);

After:
  long aaaaaaaa = !aaaa( // break
      aaaaaa);
  long aaaaaaaa = !aa.aa( // break
      aaaaaa);

llvm-svn: 240934
2015-06-29 10:42:59 +00:00
Nico Weber 45c4812851 clang-format: Support @autoreleasepool.
Format @autoreleasepool properly for the Attach brace style
by recognizing @autoreleasepool as a block introducer.

Patch from Strager Neds!
http://reviews.llvm.org/D10372

llvm-svn: 240896
2015-06-28 01:06:16 +00:00
Daniel Jasper 23d3bcfe5b clang-format: [Proto] Don't treat "operator" as keyword.
Before:
  optional string operator= 1;

After:
  optional string operator = 1;

llvm-svn: 240624
2015-06-25 08:38:46 +00:00
Daniel Jasper 6b8d26c209 clang-format: [JS] Support regex literals containing quotes (' and ").
llvm-svn: 240548
2015-06-24 16:01:02 +00:00
Alexander Kornienko ab9db51042 Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").
llvm-svn: 240353
2015-06-22 23:07:51 +00:00
Alexander Kornienko 3d9d929e42 Fixed/added namespace ending comments using clang-tidy. NFC
The patch is generated using this command:

  $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \
      -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \
      work/llvm/tools/clang

To reduce churn, not touching namespaces spanning less than 10 lines.

llvm-svn: 240270
2015-06-22 09:47:44 +00:00
Daniel Jasper 9fb676a254 clang-format: Make exception to AlwaysBreakBeforeMultilineStrings more
conservative.

In particular, this fixes an unwanted corner case.

Before:
  string s =
      someFunction("aaaa"
                   "bbbb");

After:
  string s = someFunction(
      "aaaa"
      "bbbb");

llvm-svn: 240129
2015-06-19 10:32:28 +00:00
Daniel Jasper b5a0b85494 clang-format: Better fix to detect elaborated enum return types.
The previous one (r240021) regressed:
  enum E Type::f() { .. }

llvm-svn: 240127
2015-06-19 08:17:32 +00:00
Daniel Jasper 1bf729cee1 clang-format: Row back on the AlwaysBreakBeforeMultilineStrings change.
It was a bit too aggressive.

With this patch, we keep on breaking here:
  aaaaaaaaaaaaa(aaaaaaa,
                "aaaaaaa"
                "bbbbbbb");

But don't break in:
  aaaaaaaaaaaaa(aaaaaaa, aaaaaaaa("aaaaaaa"
                                  "bbbbbbb"));

llvm-svn: 240024
2015-06-18 16:05:17 +00:00
Daniel Jasper 47721ac75d clang-format: Better support functions with elaborated enum return types.
Before, this wasn't formatted properly:
  enum ::C f() {
    return a;
  }

llvm-svn: 240021
2015-06-18 15:45:17 +00:00
Daniel Jasper ed3f395773 clang-format: [JS] Add a special case for indenting function literals.
Before:
  var func =
      function() {
        doSomething();
      };

After:
  var func =
      function() {
    doSomething();
  };

This is a very narrow special case which fixes most of the discrepency
with what our users do. In the long run, we should try to come up with
a more generic fix for indenting these.

llvm-svn: 240014
2015-06-18 12:32:59 +00:00
Daniel Jasper 2aaedd3a7e clang-format: Make AlwaysBreakBeforeMultilineStrings more conservative.
In essence this is meant to consistently indent multiline strings by a
fixed amount of spaces from the start of the line. Don't do this in
cases where it wouldn't help anyway.

Before:
  someFunction(aaaaa,
               "aaaaa"
               "bbbbb");

After:
  someFunction(aaaaa, "aaaaa"
                      "bbbbb");

llvm-svn: 240004
2015-06-18 09:12:47 +00:00
Daniel Jasper e6fcf7d372 clang-format: clang-format (NFC)
llvm-svn: 239903
2015-06-17 13:08:06 +00:00
Daniel Jasper d6e618892f clang-format: Don't generate unnecessary replacements for \r\n line endings.
Patch by Mathieu Champlon. Thank you.

llvm-svn: 239900
2015-06-17 12:23:15 +00:00
Daniel Jasper 9f4ec15270 clang-format: [JS] Don't put top-level typescript enums on a single line.
This makes this consistent with non-typescript enums.

Also shuffle the language-dependent stuff in mustBreakBefore to a
single location.

Patch initiated by Martin Probst.

llvm-svn: 239894
2015-06-17 09:44:07 +00:00
Daniel Jasper 90cf380e92 clang-format: [JS] Fix typescript enum formatting.
Patch by Martin Probst.

Before:
  enum {
    A,
    B
  } var x = 1;

After:
  enum {
    A,
    B
  }
  var x = 1;

llvm-svn: 239893
2015-06-17 09:44:02 +00:00
Daniel Jasper d246a5ac16 clang-format: NFC. Move testing of selective formatting to a separate file.
This is a first step for splitting the huge FormatTest.cpp into separate
files to make it easier to find specific tests.

llvm-svn: 239730
2015-06-15 15:25:11 +00:00
Daniel Jasper b2ad4d4c26 clang-format: [JS] Tweak behavior for multiline array initializer parameters
Before:
  var someVariable = SomeFuntion(aaaa, [
    aaaaaaaaaaaaaaaaaaaaaaaaaaa,
    bbbbbbbbbbbbbbbbbbbbbbbbbbb,
    ccccccccccccccccccccccccccc
  ],
                                 aaaa);

After:
  var someVariable = SomeFuntion(aaaa,
                                 [
                                   aaaaaaaaaaaaaaaaaaaaaaaaaaa,
                                   bbbbbbbbbbbbbbbbbbbbbbbbbbb,
                                   ccccccccccccccccccccccccccc
                                 ],
                                 aaaa);

llvm-svn: 239722
2015-06-15 09:23:17 +00:00
Daniel Jasper 2ebb0c57fb clang-format: [JS] Fix corner case in template string parsing.
Before, these would not properly detected because of the char/string
literal found when re-lexing after the first `:

  var x = `'`;  // comment with matching quote '
  var x = `"`;  // comment with matching quote "

llvm-svn: 239693
2015-06-14 07:16:57 +00:00
Daniel Jasper 60ba32d453 clang-format: Always add space before lambda-{
Before:
  int c = []() -> int *{ return 2; }();

After:
  int c = []() -> int * { return 2; }();

Based on patch by James Dennett (http://reviews.llvm.org/D10410), thank you!

llvm-svn: 239600
2015-06-12 09:59:16 +00:00
Daniel Jasper 554e49fe84 clang-format: Understand C-style case in case label.
Before:
  case (my_int) ONE:

After:
  case (my_int)ONE:

This fixed llvm.org/PR23760

llvm-svn: 239597
2015-06-12 07:15:33 +00:00
Daniel Jasper 216c9cdb1d clang-format: [JS] Support "export enum" declarations.
llvm-svn: 239595
2015-06-12 05:08:18 +00:00
Daniel Jasper 4c0bf7034c clang-format: [JS] Add tests to ensure clang-format doesn't break code
by triggering automatic semicolon insertion changes.

NFC intended. Patch by Martin Probst.

llvm-svn: 239594
2015-06-12 04:58:27 +00:00