Commit Graph

520 Commits

Author SHA1 Message Date
Daniel Jasper 015c7a91f1 clang-format: Support aligning ObjC string literals.
Before:
  NSString s = @"aaaa"
      @"bbbb";

After:
  NSString s = @"aaaa"
               @"bbbb";

llvm-svn: 237000
2015-05-11 15:15:48 +00:00
Daniel Jasper c6366077ed clang-format: Preserve line break before } in __asm { ... }.
Some compilers ignore everything after a semicolon in such inline asm
blocks and thus, the closing brace must not be moved to the previous
line.

llvm-svn: 236946
2015-05-10 08:42:04 +00:00
Daniel Jasper 7325aee167 clang-format: [JS] Avoid bad line-warp around "function".
Before:
  someLooooooooongFunction(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, function(
                                              aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {
        // code
      });

After:
  someLooooooooongFunction(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
      function(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {
        // code
      });

llvm-svn: 236813
2015-05-08 08:38:52 +00:00
Daniel Jasper 9c95013e8f clang-format: Improve r236597, Properly indent method calls without inputs.
Before:
  [aaaaaaaaaaaa(aaaaaa)
          aaaaaaaaaaaaaaaaaaaa];

After:
  [aaaaaaaaaaaa(aaaaaa)
      aaaaaaaaaaaaaaaaaaaa];

llvm-svn: 236730
2015-05-07 14:19:59 +00:00
Daniel Jasper 1fe0d5ca59 clang-format: Merge labels and subsequent semicolons.
E.g.:

  default:;

This can be used to get around restrictions as to what can follow a
label. It fixes llvm.org/PR19648.

llvm-svn: 236604
2015-05-06 15:19:47 +00:00
Daniel Jasper 112b50e6b6 clang-format: Allow ternary expressions inside template parameters if
the template parameters aren't inside an expression context.

This fixes llvm.org/PR23270.

llvm-svn: 236603
2015-05-06 14:53:50 +00:00
Daniel Jasper e92bf6f141 clang-format: Consider operator precedence as penalty when breaking
before operators.

This fixes llvm.org/23382.

llvm-svn: 236602
2015-05-06 14:23:38 +00:00
Daniel Jasper 62c78f5474 clang-format: Prevent assertion discovered by fuzzer.
llvm-svn: 236578
2015-05-06 08:58:57 +00:00
Daniel Jasper 4d9ec17f1e clang-format: Prevent exponential runtime in token annotator.
llvm-svn: 236577
2015-05-06 08:38:24 +00:00
Daniel Jasper 9326f91922 clang-format: [JS] support optional methods.
Optional methods use ? tokens like this:

  interface X { y?(): z; }

It seems easiest to detect and disambiguate these from ternary
expressions by checking if the code is in a declaration context. Turns
out that that didn't quite work properly for interfaces in Java and JS,
and for JS file root contexts.

Patch by Martin Probst, thank you.

llvm-svn: 236488
2015-05-05 08:40:32 +00:00
Daniel Jasper 66cb8c503f clang-format: NFC: Delete FormatToken::IsForEachMacro. Use a TokenType instead.
llvm-svn: 236415
2015-05-04 09:22:29 +00:00
Daniel Jasper de7ca75ca0 clang-format: Force aligning different brackets relative to each other.
Before:
  void SomeFunction(vector< // break
      int> v);

After:
  void SomeFunction(vector< // break
                        int> v);

llvm-svn: 236412
2015-05-04 07:39:00 +00:00
Daniel Jasper d22190632c clang-format: [JS] Fix templated parameter default values.
Parameters can have templated types and default values (= ...), which is
another location in which a template closer should be followed by
whitespace.

Patch by Martin Probst, thank you.

llvm-svn: 236382
2015-05-02 07:54:58 +00:00
Daniel Jasper 0faa9136fa clang-format: Properly detect variable declarations with ObjC.
Before:
  LoooooooooooooooooooooooooooooooooooooooongType
  LoooooooooooooooooooooooooooooooooooooongVariable([A a]);

After:
  LoooooooooooooooooooooooooooooooooooooooongType
      LoooooooooooooooooooooooooooooooooooooongVariable([A a]);

llvm-svn: 235599
2015-04-23 13:58:40 +00:00
Daniel Jasper caf84fe21e clang-format: Allow splitting "= default" and "= delete".
Otherwise, this can violate the column limit.

llvm-svn: 235592
2015-04-23 12:59:09 +00:00
Daniel Jasper 532a031422 clang-format: Don't add unwanted space when creating new arrays.
Before:
  char** newargv = new char* [argc];

After:
  char** newargv = new char*[argc];

llvm-svn: 235583
2015-04-23 10:23:53 +00:00
Daniel Jasper 1b998815a0 clang-format: [Proto] Don't linewrap top-level options.
They are very similar to import statements.

llvm-svn: 235582
2015-04-23 09:54:10 +00:00
Daniel Jasper ee4a8a140a clang-format: Fix for #pragma option formatting.
Adapted patch from Sergey Razmetov. Thank you.

llvm-svn: 235492
2015-04-22 09:45:42 +00:00
Daniel Jasper e4ab49e8d3 clang-format: Fix incorrect multi-var declstmt detection.
This is now obvious as the pointer alignment behavior was changed.

Before (even with pointer alignment "Left"):
  MACRO Constructor(const int &i) : a(a), b(b) {}

After:
  MACRO Constructor(const int& i) : a(a), b(b) {}

llvm-svn: 235301
2015-04-20 12:54:29 +00:00
Daniel Jasper 20e15563ff clang-format: Undo r214508. It was essentially always removing the
space where we already had the flag ObjCSpaceBeforeProtocolList to
control it. I don't know what I was thinking.

llvm-svn: 235076
2015-04-16 07:02:19 +00:00
Daniel Jasper 2b1865c251 clang-format: Determine "in" as a keyword in ObjC for loops more precisely
Before:
  for (int i = 0; i < in [a]; ++i) ..

After:
  for (int i = 0; i < in[a]; ++i) ..

Also do some related cleanups.

llvm-svn: 234980
2015-04-15 07:26:18 +00:00
Daniel Jasper d9309774a6 clang-format: [JS] Support index signature types.
Patch by Martin Probst.

llvm-svn: 234754
2015-04-13 15:03:30 +00:00
Daniel Jasper a74f5072e1 clang-format: [JS] support optionality markers in JS types.
Patch by Martin Probst. Thank you.

llvm-svn: 234753
2015-04-13 15:01:40 +00:00
Daniel Jasper 739ec534d2 clang-format: [JS] Understand object literals with only methods.
Before:
  let theObject = {someMethodName() {
    doTheThing();
    doTheOtherThing();
  },
                   someOtherMethodName() {
                     doSomething();
                     doSomethingElse();
                   }};

After:
  let theObject = {
    someMethodName() {
      doTheThing();
      doTheOtherThing();
    },
    someOtherMethodName() {
      doSomething();
      doSomethingElse();
    }
  };

llvm-svn: 234091
2015-04-04 07:56:55 +00:00
Daniel Jasper 05cd92922d clang-format: Force line break in trailing calls after multline exprs.
Before:
  aaaaaaaa(aaaaaaaaaa,
           bbbbbbbbbb).a();

After:
  aaaaaaaa(aaaaaaaaaa,
           bbbbbbbbbb)
      .a();

llvm-svn: 233304
2015-03-26 18:46:28 +00:00
Daniel Jasper 414c9c6fb0 clang-format: Fix another bug in wrapping around "*".
Before:
  void aaaaa(
      aaaaaaaaaaaa* aaaaaaaaaaaaaa) {} // even violation the column limit

After:
  void aaaaa(aaaaaaaaaaaa*
                 aaaaaaaaaaaaaa) {}

llvm-svn: 232717
2015-03-19 09:40:16 +00:00
Daniel Jasper 1130981907 clang-format: Fix bad wrapping after "*" introduced in r232044.
Before:
  void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa*
                                              const aaaaaaaaaaaa) {}

After:
  void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaaaa* const aaaaaaaaaaaa) {}

llvm-svn: 232635
2015-03-18 14:20:13 +00:00
Daniel Jasper bc46b939e6 clang-format: [JS] support cast syntax and type arguments.
Casts in TS syntax (foo = <type>bar;) should not be followed by
whitespace.

Patch by Martin Probst. Thank you.

llvm-svn: 232321
2015-03-15 13:59:51 +00:00
Daniel Jasper 60948b12bb clang-format: [JS] more precisely detect enums.
The current enum detection is overly aggressive. As NestingLevel only
applies per line (?) it classifies many if not most object literals as
enum declarations and adds superfluous line breaks into them. This
change narrows the heuristic by requiring an assignment just before the
open brace and requiring the line to start with an identifier.

Patch by Martin Probst. Thank you.

llvm-svn: 232320
2015-03-15 13:55:54 +00:00
Daniel Jasper b754a747be clang-format: When putting */& next to types, also wrap before them.
Before:
  LoooooooooooongType *
      loooooooooooongVariable;

After:
  LoooooooooooongType
      *loooooooooooongVariable;

llvm-svn: 232044
2015-03-12 15:04:53 +00:00
Daniel Jasper dc4f725673 clang-format: Fix incorrect && recognition.
Before:
  if (a &&(b = c)) ..

After:
  if (a && (b = c)) ..

llvm-svn: 231920
2015-03-11 12:59:49 +00:00
Benjamin Kramer 28b45ce151 Make constant static variables const so they can go into a read-only section
NFC.

llvm-svn: 231597
2015-03-08 16:06:46 +00:00
Daniel Jasper e662316994 clang-format: Prefer wrapping a lambda's body over the lambda's return type.
Before:
  aaaaaaaaaaaaaaaaaaaaaa(
      [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa)
          -> aaaaaaaaaaaaaaaaaaaaa { return aaaaaaaaaaaaaaaaa; });

After:
  aaaaaaaaaaaaaaaaaaaaaa(
      [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaaaaaaa {
        return aaaaaaaaaaaaaaaaa;
      });

llvm-svn: 230942
2015-03-02 10:35:13 +00:00
Daniel Jasper bea1ab46d9 clang-format: Always align */& in multi-var DeclStmts.
Seems like the most consistent thing to do and in multi-var DeclStmts,
it is especially important to point out that the */& bind to the
identifier.

llvm-svn: 230903
2015-03-01 18:55:26 +00:00
Daniel Jasper 308062bd0d clang-format: Make trailing commas in array inits force one per line.
Before:
  NSArray *array = @[ @"a", @"a", ];

After:
  NSArray *array = @[
    @"a",
    @"a",
  ];

llvm-svn: 230741
2015-02-27 08:41:05 +00:00
Daniel Jasper beaa322c36 clang-format: Fix space of arrays of pointers to templated types.
Before:
  vector<int>(*foo_)[6];

After:
  vector<int> (*foo_)[6];

llvm-svn: 230625
2015-02-26 11:30:50 +00:00
Daniel Jasper a42de763ac clang-format: Allow breaking after "else if(" as a last resort.
This isn't generally nice, but better than violating the column limit.

llvm-svn: 230620
2015-02-26 09:49:08 +00:00
Daniel Jasper 1c22048834 clang-format: Fix spacing for function with ref-qualification ..
.. when using SpacesInCStyleCastParentheses != SpacesInParentheses.

Before:
  FormatStyle Spaces = getLLVMStyle();
  Deleted &operator=(const Deleted &)& = default;

  Spaces.SpacesInParentheses = true;
  Deleted(const Deleted &)& = default;

  Spaces.SpacesInCStyleCastParentheses = true;
  Spaces.SpacesInParentheses= false;
  Deleted( const Deleted & )& = default;

After:
  FormatStyle Spaces = getLLVMStyle();
  Deleted &operator=(const Deleted &)& = default;;

  Spaces.SpacesInParentheses= true;
  Deleted( const Deleted & )& = default;

  Spaces.SpacesInCStyleCastParentheses = true;
  Spaces.SpacesInParentheses= false;
  Deleted(const Deleted &)& = default;

Patch by Jean-Philippe Dufraigne. Thank you!

llvm-svn: 230473
2015-02-25 10:30:06 +00:00
Daniel Jasper fca735cd58 clang-format: [js] Support ES6 module exports.
Patch by Martin Probst, thank you!

llvm-svn: 229865
2015-02-19 16:14:18 +00:00
Daniel Jasper 354aa51587 clang-format: [js] Support ES6 module imports.
Patch by Martin Probst.

llvm-svn: 229863
2015-02-19 16:07:32 +00:00
Jacques Pienaar fc27511223 clang-format: Space and triple angle braces.
Committing patch http://reviews.llvm.org/D6800.

llvm-svn: 229783
2015-02-18 23:48:37 +00:00
Daniel Jasper 3c42dba2dc clang-format: [JS] support AtScript style annotations for JS.
Based on Java annotation support and style.

Patch by Martin Probst.

llvm-svn: 229703
2015-02-18 17:17:15 +00:00
Daniel Jasper b10bdff337 clang-format: [JS] Support type annotations.
This patch adds support for type annotations that follow TypeScript's,
Flow's, and AtScript's syntax style.

Patch by Martin Probst, thank you.
Review: http://reviews.llvm.org/D7721

llvm-svn: 229700
2015-02-18 17:09:53 +00:00
Daniel Jasper 699631298e clang-format: Don't force a break after "endl" if everything fits on one line.
llvm-svn: 229486
2015-02-17 10:05:15 +00:00
Nico Weber fac2371be3 clang-format: Add support for SEH __try / __except / __finally blocks.
This lets clang-format format

    __try {
    } __except(0) {
    }

and

    __try {
    } __finally {
    }

correctly. __try and __finally are keywords if `LangOpts.MicrosoftExt` is set,
so this turns this on.  This also enables a few other keywords, but it
shouldn't overly perturb regular clang-format operation.  __except is a
context-sensitive keyword, so `AdditionalKeywords` needs to be passed around to
a few more places.

Fixes PR22321.

llvm-svn: 228148
2015-02-04 15:26:27 +00:00
Daniel Jasper 7509216a41 clang-format: Fix incorrect classification of "*".
Before:
  *a = b *c;

After:
  *a = b * c;

llvm-svn: 226923
2015-01-23 19:04:49 +00:00
Daniel Jasper d1debfc2bb clang-format: Fix bad memory access.
llvm-svn: 226680
2015-01-21 18:04:02 +00:00
Daniel Jasper 9b79efb51f clang-format: Fix crasher on weird comments.
Crashing input:
  /\
  / comment

llvm-svn: 226454
2015-01-19 11:49:32 +00:00
Daniel Jasper 193cdd381b clang-format: Fix crasher on incomplete condition compilation.
Previously crashing input:
  void f(
  #if A
      );
  #else
  #endif

llvm-svn: 226451
2015-01-19 10:52:16 +00:00
Daniel Jasper e189d46512 clang-format: [Java] Support try blocks with resources.
Before:
  try
    (SomeResource rs = someFunction()) {
      Something();
    }

After:
  try (SomeResource rs = someFunction()) {
    Something();
  }

llvm-svn: 225973
2015-01-14 10:48:41 +00:00