Commit Graph

1378 Commits

Author SHA1 Message Date
Daniel Jasper 320da71d26 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>>>();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286041 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-05 17:43:16 +00:00
Malcolm Parsons 13730b3c9c 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285934 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-03 16:57:30 +00:00
Daniel Jasper e54c81e47a 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;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285674 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 06:23:19 +00:00
Daniel Jasper 6598a29b37 clang-format: Fix incorrect pointer detection.
Before:
  void f() { f(float{1}, a *a); }

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285673 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 06:23:14 +00:00
Daniel Jasper 06b83f9d80 clang-format: Fix incorrect binary operator detection.
Before:
  int x = f(* + [] {});

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285671 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-01 06:23:05 +00:00
Daniel Jasper c3014c9312 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285570 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-31 13:23:00 +00:00
Andi-Bogdan Postelnicu e0d538f7e6 Bug 28065 - clang-format incorrectly aligns backslash.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285178 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-26 07:44:51 +00:00
Daniel Jasper 9c15a0692d 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) {

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283246 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-04 20:18:25 +00:00
Daniel Jasper 199dbc55ee [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!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282448 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-26 22:19:08 +00:00
Daniel Jasper 7315f7582b clang-format: Only special-case top-level */& in multivar-declstmts.
Before (even with PointerAlignment: Left):
  vector<int *> a, b;

After:
  vector<int*> a, b;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@282410 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-26 15:14:24 +00:00
Sylvestre Ledru ecf27f00be 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@278121 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-09 14:24:40 +00:00
Eric Liu 85c0fa18d9 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277335 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-01 10:16:37 +00:00
Daniel Jasper 9f35d626bf clang-format: Fix incorrect detection of QT-signals access specifier.
Before:
  void f() {
  label:
    signals
    .baz();
  }

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@276854 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-27 10:13:24 +00:00
Eric Liu a45abc6b0f 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275062 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-11 13:53:12 +00:00
Daniel Jasper 51e207d791 clang-format: Restrict r272537 to function ref qualifiers.
Seems this isn't generally desirable.

Before:
  int const * a;

After:
  int const* a;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272548 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-13 14:45:12 +00:00
Daniel Jasper 8212e11814 clang-format: Fix incorrect function type detection.
Before:
  returnsFunction (&param1, &param2)(param);

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272538 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-13 07:49:35 +00:00
Daniel Jasper ae85d31708 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272537 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-13 07:49:28 +00:00
Daniel Jasper 9538b3ee58 clang-format: Fix incorrect cast detection.
Before:
  auto s = sizeof...(Ts)-1;

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272536 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-13 07:49:09 +00:00
Daniel Jasper 441645e315 clang-format: Don't indent lambda body relative to its return type.
Before:
  []()  //
      -> int {
        return 1;  //
      };

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272535 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-13 07:48:45 +00:00
Daniel Jasper f5771074b9 clang-format: Fix incorrect calculation of "length" of /**/ comments.
This could lead to column limit violations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272125 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-08 09:45:08 +00:00
Daniel Jasper 6ae74bae68 clang-format: Fix bug in function ref qualifier identification.
.. and simplify it.

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

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272124 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-08 08:23:46 +00:00
Daniel Jasper d836b53adb 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270975 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-27 08:59:34 +00:00
Eric Liu ff59e8e8dc [clang-format] moved unit tests related to replacements cleaner from FormatTest.cpp to CleanUpTest.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270971 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-27 08:20:02 +00:00
Daniel Jasper b9b27cd4be 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()

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270028 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-19 06:30:48 +00:00
Daniel Jasper 5a2da625d3 clang-format: Fix enumerator case ranges.
Before:
  case a... b: break;

After:
  case a ... b: break;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270027 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-19 06:19:17 +00:00
Eric Liu 9635a67e3c [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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@269924 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-18 13:43:48 +00:00
Daniel Jasper 09327d7fa8 clang-format: Fix space after argument comments.
Before:
  f(/*a=*/a, /*b=*/ ::b);

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@268879 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-08 18:14:01 +00:00
Daniel Jasper a350eed549 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();
  };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@268878 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-08 18:12:22 +00:00
Eric Liu a433799777 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@267416 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-25 15:09:22 +00:00
Daniel Jasper 510a022f1b clang-format: Improve heuristics to detect function declarations/definitions.
Specifically understand ellipses in parameter lists and treat trailing
reference qualifiers and the "{" as signals.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266599 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-18 11:31:21 +00:00
Marianne Mailhot-Sarrasin 463ccc6b43 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266321 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-14 14:56:49 +00:00
Marianne Mailhot-Sarrasin 08708dba67 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266320 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-14 14:52:26 +00:00
Daniel Jasper ebbe2eca32 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()

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265557 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-06 16:41:39 +00:00
Daniel Jasper 077a1a7098 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();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265545 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-06 15:02:46 +00:00
Daniel Jasper 80197c36b2 clang-format: Fix incorrect function annotation detection.
Before:
  MACRO(
      abc).function() // wrap
      << abc;

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265540 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-06 13:58:09 +00:00
Daniel Jasper 983e29fb81 clang-format: Fix cast detection on "this".
Before:
  auto x = (X) this;

After:
  auto x = (X)this;

This fixes llvm.org/PR27198.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265385 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-05 11:46:06 +00:00
Eric Liu 6a4597fa13 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264745 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-29 16:31:53 +00:00
Eric Liu 3ec937288f Dsiable FormatStyle::GetStyleOfFile test case for mingw.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264289 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-24 14:59:39 +00:00
Eric Liu 4f5fb61d0a Added support for different VFSs in format::getStyle. Disable platform-related test case for MS compilers to avoid breaking buildbot.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264277 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-24 13:22:42 +00:00
Eric Liu 0589759dbf 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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264257 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-24 11:25:28 +00:00
Eric Liu 60fce8273c Added support for different VFSs in format::getStyle.
Summary:
Previously, format::getStyle assumes that the given file resides in
the real file system, which prevents the use of virtual file system in testing etc.
This patch adds a parameter in format::getStyle interface so that users can specify
the right file system. By default, the file system is the real file system.

Reviewers: djasper, klimek

Subscribers: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264253 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-24 10:50:17 +00:00
Daniel Jasper 5b12ee708d clang-format: Make include sorting's main include detection configurable.
This patch adds a regular expression to configure suffixes of an
included file to check whether it is the "main" include of the current
file. Previously, clang-format has allowed arbitrary suffixes on the
formatted file, which is still the case when no IncludeMainRegex is
specified.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@263943 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-21 14:11:27 +00:00
Daniel Jasper 12441fe65f clang-format: Slightly weaken AlignAfterOpenBracket=AlwaysBreak.
If a call takes a single argument, using AlwaysBreak can lead to lots
of wasted lines and additional indentation without improving the
readability in a significant way.

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

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@263709 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-17 12:00:22 +00:00
Daniel Jasper 484e92d2ec clang-format: [JS] Optionally re-quote string literals.
Turns "foo" into 'foo' (or vice versa, depending on configuration).
This makes it more convenient to follow the Google JavaScript style
guide:
https://google.github.io/styleguide/javascriptguide.xml?showone=Strings#Strings

This functionality is behind the option "JavaScriptQuotes", which can be:

  * "leave" (no re-quoting)
  * "single" (change to single quotes)
  * "double" (change to double quotes)

This also changes single quoted JavaScript string literals to be treated
as tok::string_literal, not tok::char_literal, which fixes two unrelated
tests.

Patch by Martin Probst. Thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262534 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-02 22:44:03 +00:00
Daniel Jasper 9e3b27922b [clang-format] Detect constructor initializers preceded by `noexcept`.
Patch by Erik Kessler, thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262402 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-01 21:41:58 +00:00
Manuel Klimek e30483a5c5 Add functions to apply replacements and reformat them.
This is a commonly useful feature to have, and we have implemented it
multiple times with different kinds of bugs. This implementation
centralizes the idea in a set of functions that we can then use from the various
tools.

Reverts r262234, which is a revert of r262232, and puts the functions
into FOrmat.h, as they are closely coupled to clang-format, and we
otherwise introduce a cyclic dependency between libFormat and
libTooling.

Patch by Eric Liu.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262323 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-01 12:37:30 +00:00
Daniel Jasper 1414490fdf clang-format: Correctly apply wrap before multi-line RHS rule to
ternary expressions.

Before:
  return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? aaaaa : bbbbbbbbbbbbbbb +
							     cccccccccccccccc;

After:
  return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
	     aaaaa :
	     bbbbbbbbbbbbbbb + cccccccccccccccc;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262293 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-01 04:19:59 +00:00
Daniel Jasper ca253e4477 clang-format: Increase the penalty for breaking between array subscripts.
Before:
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaaaaaaaaaaaaa]
                                    [a].aaaaaaaaaaaaaaaaaaaaaa();

After:
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaaaaaaaaaaaaa][a]
      .aaaaaaaaaaaaaaaaaaaaaa();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262292 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-01 04:19:55 +00:00
Richard Trieu 3fae4abaf2 Remove use of builtin comma operator.
Cleanup for upcoming Clang warning -Wcomma.  No functionality change intended.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@261271 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-18 22:34:54 +00:00
Daniel Jasper fbdfbfbe68 clang-format: Make indentation after "<<" more consistent.
Before:
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
  Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa)
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      << aaa;

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260517 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-11 13:15:14 +00:00
Daniel Jasper c43284c491 clang-format: Make it more expensive to break template parameters.
In particular, make it more expensive than breaking after the return
type of a function definition/declaration.

Before:
  template <typename T>
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaa<
      T>::aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa);

After:
  template <typename T>
  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  aaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaaaaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260497 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-11 06:43:01 +00:00
Daniel Jasper 7bb97b213b clang-format: Fix weird alignment when not aligning after brackets.
Before:
  bbbbbbbbbbbb(aaaaaaaaaaaaaaaaaaaaaaaa, //
      ccccccc(aaaaaaaaaaaaaaaaa, //
	           b));

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

This fixes llvm.org/PR24905.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260080 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-08 09:52:54 +00:00
Daniel Jasper 508fd615f6 clang-format: Fix corner case in template detection.
Before:
  f(a.operator() < A > ());

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259884 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-05 14:17:16 +00:00
Daniel Jasper 7d018c0578 clang-format: Fix formatting of ternary expressions with comments.
Before:
  int i = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
	      /*bbbbbbbbbbbbbbbbbbbb=*/bbbbbbbbbbbbbbbbbbbbbbbbb :
				       ccccccccccccccccccccccccccc;

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259670 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-03 17:27:10 +00:00
Daniel Jasper 2b9f6f3342 clang-format: Make AlignAfterOpenBracket also affect angle brackets.
Patch by Matthew Whitehead, thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259487 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-02 10:28:11 +00:00
Daniel Jasper 4e199700be clang-format: Fix incorrect pointer detection in lambdas in constructor
initializers.

Before:
  Constructor() : member([](A *a, B * b) {}) {}

After:
  Constructor() : member([](A *a, B *b) {}) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259353 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-01 11:21:07 +00:00
Daniel Jasper 03bf8df72b clang-format: Add option to disable string literal formatting.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259352 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-01 11:21:02 +00:00
Daniel Jasper 3136e21b4a clang-format: Fix alignment of trailing multiline columns.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259351 91177308-0d34-0410-b5e6-96231b3b80d8
2016-02-01 11:20:55 +00:00
Manuel Klimek fe46d7ff72 Fix formatting of fully qualified names in array subscripts.
Before:
  a[ :🅱️:c];

After:
  a[:🅱️:c];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@258123 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-19 14:05:32 +00:00
Daniel Jasper ba5446436b clang-format: Fix incorrectly enforced linebreak with ColumnLimit 0.
Before:
  aaaa[bbbb]
      .cccc();

After:
  aaaa[bbbb].cccc();

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

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

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257615 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-13 16:41:34 +00:00
Benjamin Kramer fde9745812 [clang-format] Fix comment aligning when there are changes within the comment
As soon as a comment had whitespace changes inside of the token, we
couldn't identify the whole comment as a trailing comment anymore and
alignment stopped working. Add a new boolean to Change for this special
case and fix trailing comment identification to use it.

This also changes WhitespaceManager to sum the length of all Changes
inside of a token into the first Change.

Before this fix

  int xy;  // a
  int z;   //b

became

  int xy;  // a
  int z;  // b

with this patch we immediately get to:

  int xy;  // a
  int z;   // b

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257341 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-11 16:27:16 +00:00
Daniel Jasper a1826ba2ea clang-format: Fix overloading "operator," definitions more thoroughly.
Before:
  aaaaaaaaaaaaaaaaaaaaaa operator,(aaaaaaaaaaaaaaaaaaaaa &
                                   aaaaaaaaaaaaaaaaaaaaaaaaaa) const;
After:
  aaaaaaaaaaaaaaaaaaaaaa operator,(
      aaaaaaaaaaaaaaaaaaaaa &aaaaaaaaaaaaaaaaaaaaaaaaaa) const;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257330 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-11 12:55:33 +00:00
Daniel Jasper 4764e0cdd6 clang-format: Slightly row back on r257257.
r257257 change the way clang-format enforces line breaks after a
templated type has been line-wrapped. This was to fix an incorrect line
break if BinPackParameters is set to false. However, it also leads to
an unwanted line break in a different case. Thus, for now, only do this
when BinPackParameters is false. This isn't ideal yet, but helps us
until we have a better solution.

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

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257325 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-11 11:01:05 +00:00
Daniel Jasper 5ae85ca16d clang-format: Fix incorrect line break in certain configurations.
Before:
  void aaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa,
                          vector<int>
                              bbbbbbbbbbbbbbb);

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257257 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-09 15:56:47 +00:00
Daniel Jasper a7580750ca clang-format: Support definitions/declarations of operator,.
Before:
  bool operator, ();

After:
  bool operator,();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257256 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-09 15:56:40 +00:00
Daniel Jasper 763af2c47f clang-format: Fix corner case in one-per-line formatting.
Before (example is JS, but also applies to C++):
  return [
    aaaa()
        .bbbbbbbb('A'),
    aaaa().bbbbbbbb('B'),
    aaaa().bbbbbbbb('C'),
  ];

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257079 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-07 18:11:54 +00:00
Daniel Jasper d228e08047 clang-format: Support weird lambda macros.
Before:
  MACRO((AA & a) { return 1; });

After:
  MACRO((AA &a) { return 1; });

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257062 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-07 14:36:11 +00:00
Daniel Jasper 402aa410d0 clang-format: Fix corner case in "if it saves columns"-calculation.
Before:
  aaaa
      .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
	  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
      .aaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256841 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-05 16:10:39 +00:00
Daniel Jasper 9376f992e0 clang-format: Handle \n the same way as std::endl with stream operator.
clang-format breaks multi-line streams after std::endl.
It now also break for '\n', the suggested replacement for std::endl:

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

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

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

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

Patch by Jean-Philippe Dufraigne, thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256832 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-05 13:06:27 +00:00
Daniel Jasper e0ad185696 clang-format: Avoid creating hanging indents in call sequences.
Before:
  aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaa(
                      aaaaaaaaaaaaaaaaaaaa)
        .aaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256831 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-05 13:03:59 +00:00
Daniel Jasper 70b119a229 clang-format: Improve line wrapping behavior in call sequences.
r256750 has been leading to an undesired behavior:

  aaaaaaaaaa
      .aaaaaaaaaaaaaaaaaaaaaaaa.aaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

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

  aaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaa.aaaaaa(
      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256830 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-05 13:03:50 +00:00
Daniel Jasper bd0910a7dc clang-format: Fix corner case in builder-type call formatting.
Before:
  return aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa,
						  aaaaaaaaaaaaaaaaa)
      .aaaa(aaaaaaaaaaaaaa);

After:
  return aaaaaaaaaaaaaaaa
      .aaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa)
      .aaaa(aaaaaaaaaaaaaa);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256750 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-04 12:41:11 +00:00
Daniel Jasper e64d34cacf clang-format: Align long braced init lists even if they are nested in
function calls.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256740 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-04 07:30:44 +00:00
Daniel Jasper 8dc688335d clang-format: Fix corner case for lambda assignments.
Before:
  std::function<std::string(const std::string &)> my_lambda = [](
      const string &s) { return s; };

After:
  std::function<std::string(const std::string &)> my_lambda =
      [](const string &s) { return s; };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256739 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-04 07:29:40 +00:00
Daniel Jasper e62754299f clang-format: Fix corner-case in ObjC method declaration formatting
Before:
  - (void)shortf:(GTMFoo *)theFoo
     longKeyword:(NSRect)theRect
   longerKeyword:(float)theInterval
           error:(NSError **)theError {
  }

After:
  - (void)shortf:(GTMFoo *)theFoo
        longKeyword:(NSRect)theRect
      longerKeyword:(float)theInterval
              error:(NSError **)theError {
  }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256738 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-04 07:29:07 +00:00
Daniel Jasper a7cb7ce92b clang-format: Slightly row back on r256343 by increasing penalty for
breaking between array subscripts.

Before:
  if (aaaaaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaaa]
                                                     [aaaaaaaaaaaaa])
After:
  if (aaaaaaaaaaaaaaaaaaaaaaaa &&
      aaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaaa][aaaaaaaaaaaaa])

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256640 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-30 12:23:00 +00:00
Daniel Jasper 53003b6a57 clang-format: Fix incorrect function type detection.
Before:
  int x = f (&h)();

After:
  int x = f(&h)();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256488 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-28 07:44:25 +00:00
Daniel Jasper 794a77e319 clang-format: [TableGen] Support ;-less include lines.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256412 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-25 08:53:31 +00:00
Daniel Jasper f47751e168 clang-format: Lower penalty for breaking between array subscripts.
Before:
  aaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaa(aaaaaaaaaaaa)][bbbbbbbbbbb(
      bbbbbbbbbbbb)]

After:
  aaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaa(aaaaaaaaaaaa)]
                           [bbbbbbbbbbb(bbbbbbbbbbbb)]

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256343 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-23 18:01:43 +00:00
Daniel Jasper 9d71da68e6 clang-format: Fix incorrect pointer detection.
Before:
  return * this += 1;

After:
  return *this += 1;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256342 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-23 18:01:29 +00:00
Daniel Jasper b8cc716acd clang-format: Properly set the BlockKind for more blocks.
Before:
  void f() { struct Dummy { };
    f();
  }

After:
  void f() {
    struct Dummy {};
    f();
  }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256175 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-21 18:31:15 +00:00
Zachary Turner dd7bdbf1bb Fix invalid enum comparison.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256055 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-18 22:58:42 +00:00
Zachary Turner bef33a25fe Support AlwaysBreakAfterReturnType
This changes the behavior of AlwaysBreakAfterDeclarationReturnType
so that it supports breaking after declarations, definitions, or
both.

Differential Revision: http://reviews.llvm.org/D10370
Reviewed By: Daniel Jasper

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256046 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-18 22:20:15 +00:00
Daniel Jasper 8025bf5092 clang-format: Add test for AlignAfterOpenBracket = AlwaysBreak in C++.
Revision 251405 added AlwaysBreak to support Google's JavaScript style. This
changeset complete existing AlignsAfterOpenBracket tests to exercise
AlwaysBreak for C++.

I thought this would be worthwhile.  With this option we can support request
from http://lists.llvm.org/pipermail/cfe-dev/2015-May/042942.html, that had
been requested a few times. This also partially solve related Bug 23422 and is
probably sufficient for most people.

  AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
  BinPackArguments = false;
  BinPackParameters = false;

With these setting we obtain this formatting:

  void fooWithAVeryLongParamList(
      int firstParameter,
      int secondParameter
      int lastParameter)
  {
      object.alsoThisDoenstFitSoIBreakImmidiatly(
          firstParameter,
          secondParameter,
          lastParameter);
  }

Patch by Jean-Philippe Dufraigne, thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255486 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-14 08:41:18 +00:00
Daniel Jasper 6657b3d324 clang-format: Extend Linux-brace-wrapping test.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255485 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-14 08:33:07 +00:00
Daniel Jasper 1e4fb607e7 clang-format: Make wrapping after "./->" cheaper, even if the element
before it is not a closing parenthesis.

Otherwise, this frequently leads to "hanging" indents that users
perceive as "weird".

Before:
  return !soooooooooooooome_map.insert(
                                   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
              .second;

After:
  return !soooooooooooooome_map
              .insert(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
              .second;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254933 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-07 19:50:48 +00:00
Daniel Jasper c5e6fe85ed clang-format: Make it possible to turn off comment reflowing.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254414 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-01 13:28:53 +00:00
Daniel Jasper b65b352ab0 clang-format: treat Q_SIGNALS as an access modifier
Patch by Alexander Richardson, thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254407 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-01 12:05:04 +00:00
Daniel Jasper 7a775e201b This fixes https://llvm.org/bugs/show_bug.cgi?id=25329, as well as
misalignments like the following:

  int a, b = 2;
  int c    = 3;

Patch by Beren Minor, thanks!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254406 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-01 12:00:43 +00:00
Daniel Jasper fc2939d53f clang-format: Re-add code path deleted in r253873 and add missing test.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253900 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-23 19:11:45 +00:00
Daniel Jasper c0390b0301 clang-format: Fix incorrect cast detection.
Before:
  bool b = f(g<int>)&&c;

After:
  bool b = f(g<int>) && c;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253872 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-23 15:55:50 +00:00
Daniel Jasper 6a92b11850 clang-format: If the template list of a variable declaration spans
multiple lines, also break before the variable name.

Before:
  std::vector<aaaaaa, // wrap
              aa> aaa;

After:
  std::vector<aaaaaa, // wrap
              aa>
      aaa;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253871 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-23 15:55:45 +00:00
Daniel Jasper aaf49845dc clang-format: Don't use incorrect space in macro calls with operators.
Before:
  MACRO(> );

After:
  MACRO(>);

Not overly important, but easy and good for symmetry reasons :-).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253669 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-20 15:26:50 +00:00
Daniel Jasper d27c92ca6f clang-format: Enable #include sorting by default.
This has seen quite some usage and I am not aware of any issues. Also
add a style option to enable/disable include sorting. The existing
command line flag can from now on be used to override whatever is set
in the style.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253202 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-16 12:38:56 +00:00
Saleem Abdulrasool bec01a5ecd Format: support inline namespaces
Correct handling for C++17 inline namespaces.  We would previously fail to
identify the inline namespaces as a namespace name since multiple ones may be
concatenated now with C++17.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251690 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-30 05:07:56 +00:00
Daniel Jasper ec740cd397 clang-format: Undo unwanted format change done in r251405.
Specifically, don't wrap between the {} of an empty constructor if the
"}" falls on column 81 and ConstructorInitializerAllOnOneLineOrOnePerLine
is set.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251406 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-27 13:42:08 +00:00
Daniel Jasper 6e0ab6e499 clang-format: Add an additional value to AlignAfterOpenBracket: AlwaysBreak.
Summary:
If this option is set, clang-format will always insert a line wrap, e.g.
before the first parameter of a function call unless all parameters fit
on the same line. This obviates the need to make a decision on the
alignment itself.

Use this style for Google's JavaScript style and add some minor tweaks
to correctly handle nested blocks etc. with it. Don't use this option
for for/while loops.

Reviewers: klimek

Subscribers: klimek, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251405 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-27 12:38:37 +00:00
Daniel Jasper afbad5d137 clang-format: Fix false positive in cast detection.
Before (with spaces in parentheses):
  void inFunction() { std::function<void( int, int )> fct; }

After:
  void inFunction() { std::function<void( int, int)> fct; }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251284 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-26 12:08:47 +00:00
Daniel Jasper 72c2907b9a clang-format: Fixed typecast getting put on a separate line from the
key in Obj-C dictionary literals

This fixes: https://llvm.org/PR22647

Patch by Kent Sutherland. Thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250010 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-12 03:19:07 +00:00
Daniel Jasper ed6a9434ed clang-format: Fixed missing space between Obj-C for/in and a typecast.
Fixes this bug: https://llvm.org/bugs/show_bug.cgi?id=24504

TokenAnnotator::spaceRequiredBetween was handling TT_ForEachMacro but
not TT_ObjCForIn, so lines that look like:

  for (id nextObject in (NSArray *)myArray)

would incorrectly turn into:

  for (id nextObject in(NSArray *)myArray)

Patch by Kent Sutherland, thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249553 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-07 15:09:08 +00:00
Daniel Jasper 304dc5d780 [clang-format] Stop alignment sequences on open braces and parens when
aligning assignments.

This was done correctly when aligning the declarations, but not when
aligning assignments.

FIXME: The code between assignments and declarations alignment is
roughly duplicated and
would benefit from factorization.

Bug 25090: https://llvm.org/bugs/show_bug.cgi?id=25090

Patch by Beren Minor. Thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249552 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-07 15:03:26 +00:00
Daniel Jasper 9a58694aec Make clang-format actually respect custom brace wrapping flags.
This fixes llvm.org/PR25073.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249519 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-07 04:06:10 +00:00
Daniel Jasper 0e6b5702af clang-format: Fix false ObjC block detection.
Before:
  inline A operator^(const A &lhs, const A &rhs) {} int i;

After:
  inline A operator^(const A &lhs, const A &rhs) {}
  int i;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249517 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-07 03:43:10 +00:00
Daniel Jasper e171822700 clang-format: Understand array reference types.
Before:
  void f(Type(&parameter)[10]) {}
  void f(Type (*parameter)[10]) {}

After:
  void f(Type (&parameter)[10]) {}
  void f(Type (*parameter)[10]) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249502 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-07 01:41:22 +00:00
Daniel Jasper a164fa507b clang-format: Fix false positive in pointer/reference detection.
Before:
  return options != nullptr &&operator==(*options);

After:
  return options != nullptr && operator==(*options);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249501 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-07 01:41:14 +00:00
Daniel Jasper fa119ac183 clang-format: Make IncludeCategories configurable in .clang-format file.
This was made much easier by introducing an IncludeCategory struct to
replace the previously used std::pair.

Also, cleaned up documentation and added examples.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249392 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-06 11:54:18 +00:00
Daniel Jasper d5adefdf2d [clang-format] Add support of consecutive declarations alignment
This allows clang-format to align identifiers in consecutive
declarations. This is useful for increasing the readability of the code
in the same way the alignment of assignations is.

The code is a slightly modified version of the consecutive assignment
alignment code. Currently only the identifiers are aligned, and there is
no support of alignment of the pointer star or reference symbol.

The patch also solve the issue of alignments not being possible due to
the ColumnLimit for both the existing AlignConsecutiveAligments and the
new AlignConsecutiveDeclarations.

Patch by Beren Minor, thank you.

Review: http://reviews.llvm.org/D12362

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248999 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-01 10:06:54 +00:00
Daniel Jasper 6cc91d4e13 clang-format: Add a new brace style "custom" as well as flags to
control the individual braces. The existing choices for brace wrapping
are now merely presets for the different flags that get expanded upon
calling the reformat function.

All presets have been chose to keep the existing formatting, so there
shouldn't be any difference in formatting behavior.

Also change the dump_format_style.py to properly document the nested
structs that are used to keep these flags discoverable among all the
configuration flags.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248802 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-29 14:57:55 +00:00
Daniel Jasper 21b3f468fc clang-format: Fix alignConsecutiveAssignments.
It wasn't correctly handling this case:

  int oneTwoThree = 123;
  int oneTwo      = 12;
  method();

Review: http://reviews.llvm.org/D12369
Patch by Beren Minor. Thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248254 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-22 09:32:00 +00:00
Daniel Jasper 594dc4f13a clang-format: Fix merging short case labels with comments.
This fixes llvm.org/PR24877.

Patch by Benjamin Daly, thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248145 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-21 09:50:01 +00:00
Daniel Jasper 41899787fa clang-format: Don't let a leading "template <..>" lead to wrapped initializers.
Before:
  Constructor() : initializer(0) {}

  template <typename T>
  Constructor()
      : initializer(0) {}

After:
  Constructor() : initializer(0) {}

  template <typename T>
  Constructor() : initializer(0) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246146 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-27 11:59:31 +00:00
Daniel Jasper e5cffd6593 clang-format: Add space before member function reference qualifiers.
Before:
  SomeType MemberFunction(const Deleted &)&;

After:
  SomeType MemberFunction(const Deleted &) &;

Seems to be much more common.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245934 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-25 13:40:51 +00:00
Daniel Jasper 424d6212ab clang-format: Always allow break after leading annotations.
Before:
  DEPRECATED("Use NewClass::NewFunction instead.") int OldFunction(
  const string &parameter) {}

Could not be formatted at all, as clang-format would both require and
disallow the break before "int".

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245846 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-24 15:10:01 +00:00
Daniel Jasper fa82f43900 clang-format: Make formatting of member function reference qualifiers
more consistent.

Before:
  SomeType MemberFunction(const Deleted &)&&;
  SomeType MemberFunction(const Deleted &) && { ... }

After:
  SomeType MemberFunction(const Deleted &)&&;
  SomeType MemberFunction(const Deleted &)&& { ... }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245843 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-24 14:28:08 +00:00
Daniel Jasper a3933711ef clang-format: Properly handle braced lists in macros.
Before:
  #define A    \
      { a, a } \
      ,

After:
  #define A {a, a},

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245837 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-24 13:23:37 +00:00
Daniel Jasper 05ed87540c clang-format: Be more conservative about specially indenting blocks in C++.
This is a bit of a step back of what we did in r222531, as there are
some corner cases in C++, where this kind of formatting is really bad.

Example:
Before:
  virtual aaaaaaaaaaaaaaaa(std::function<bool()> IsKindWeWant = [&]() {
    return true;
  }, aaaaa aaaaaaaaa);

After:
  virtual aaaaaaaaaaaaaaaa(std::function<bool()> IsKindWeWant =
                               [&]() { return true; },
                           aaaaa aaaaaaaaa);

The block formatting logic in JavaScript will probably go some other changes,
too, and we'll potentially be able to make the rules more consistent again. For
now, this seems to be the best approach for C++.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245694 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-21 11:44:57 +00:00
Daniel Jasper d2bb239313 clang-format: Don't remove space between #elif and parentheses.
Before:
  #elif(AAAA && BBBB)

After:
  #elif (AAAA && BBBB)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245043 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-14 12:44:06 +00:00
Daniel Jasper 75109be3b9 clang-format: Inside decltype(), there is an expression.
Before:
  decltype(a* b) F();

After:
  decltype(a * b) F();

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244891 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-13 13:43:51 +00:00
Daniel Jasper 3306f568e9 clang-format: Fix incorrect lambda-detection.
Before:
  [ a, a ]() -> a<1>{};

After:
  [a, a]() -> a<1> {};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244890 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-13 13:37:08 +00:00
Daniel Jasper ef23307ace clang-format: Make SpaceBeforeParens work with overloaded operators.
Patch by Jon Chesterfield, thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244660 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-11 20:32:24 +00:00
Roman Kashitsyn 8aef53c9eb Add WebKit brace style configuration option.
Summary:
Add brace style `BS_WebKit` as described on https://www.webkit.org/coding/coding-style.html:

* Function definitions: place each brace on its own line.
* Other braces: place the open brace on the line preceding the code block; place the close brace on its own line.

Set brace style used in `getWebKitStyle()` to the newly added `BS_WebKit`.

Reviewers: djasper, klimek

Subscribers: klimek, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244446 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-10 13:43:19 +00:00
Manuel Klimek c5f562c2a4 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);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243429 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-28 15:50:24 +00:00
Daniel Jasper fb1bfe5464 clang-format: Fix unary operator detection in for loops.
Before:
  for (;; * a = b) {}

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242849 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-21 22:51:00 +00:00
Daniel Jasper 8c6f4375dc clang-format: Fix crasher when a UTF8 character is found in an escape
sequence. Discovered by the fuzzer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242738 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-20 23:28:07 +00:00
Daniel Jasper 5061880d99 clang-format: Take nested lines into account when detection C++03
compatibility and variable alignment.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242611 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-18 16:35:30 +00:00
Daniel Jasper 6159c0fbd1 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!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242484 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-16 22:58:24 +00:00
Birunthan Mohanathas 6291795332 clang-format: Fix return type breaking with overloaded operator functions
Differential Revision: http://reviews.llvm.org/D11177


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242316 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-15 19:11:58 +00:00
Daniel Jasper bfbaed9ca7 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
  };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242299 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-15 16:26:47 +00:00
Daniel Jasper f83c8a72dd clang-format: Fix formatting of multiple lambdas in initializers.
Before:
  SomeFunction({[&] {
    // comment
  },
                [&] {
                  // comment
                }});

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242138 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-14 11:26:14 +00:00
Birunthan Mohanathas fac72109a1 clang-format: Add Mozilla brace breaking style
Differential Revision: http://reviews.llvm.org/D10883


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241986 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-12 03:13:54 +00:00
Daniel Jasper 07ac853f86 clang-format: Break after "for (" less eagerly.
Before:
  for (
      auto aaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
      aaaaaaaaaaaaaaaaaaaaaaaaaaa != bbbbbbbbbbbbbbbbbbbbbbb;
      ++aaaaaaaaaaaaaaaaaaaaaaaaaaa) {

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241601 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-07 16:09:39 +00:00
Daniel Jasper a1c3b039b8 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;
  });

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241583 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-07 13:50:50 +00:00
Daniel Jasper 174220cf7c 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241439 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-06 11:30:34 +00:00
Birunthan Mohanathas 0af047c817 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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241363 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-03 17:25:16 +00:00
Daniel Jasper deadc2760c 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 {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241188 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-01 21:02:24 +00:00
Daniel Jasper 8378e8520c 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241059 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-30 11:32:22 +00:00
Birunthan Mohanathas 9d44adcff8 clang-format: Add option to break after definition return type for top-level functions only
Differential Revision: http://reviews.llvm.org/D10774


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240959 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-29 15:30:42 +00:00
Daniel Jasper 2ce34c5ced 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);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240934 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-29 10:42:59 +00:00
Nico Weber 33b0503c15 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


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240896 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-28 01:06:16 +00:00
Daniel Jasper 9d37b395c7 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");

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240129 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-19 10:32:28 +00:00
Daniel Jasper f68ad12985 clang-format: Better fix to detect elaborated enum return types.
The previous one (r240021) regressed:
  enum E Type::f() { .. }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240127 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-19 08:17:32 +00:00
Daniel Jasper faa3c986ea 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"));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240024 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-18 16:05:17 +00:00
Daniel Jasper da9b856426 clang-format: Better support functions with elaborated enum return types.
Before, this wasn't formatted properly:
  enum ::C f() {
    return a;
  }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240021 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-18 15:45:17 +00:00
Daniel Jasper 7b2b09b307 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");

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240004 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-18 09:12:47 +00:00
Daniel Jasper f8d4459793 clang-format: clang-format (NFC)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239903 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-17 13:08:06 +00:00
Daniel Jasper 86666d6bf2 clang-format: Don't generate unnecessary replacements for \r\n line endings.
Patch by Mathieu Champlon. Thank you.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239900 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-17 12:23:15 +00:00
Daniel Jasper 5349c83a3b 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239730 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-15 15:25:11 +00:00
Daniel Jasper 97f3ecf98d 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!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239600 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-12 09:59:16 +00:00
Daniel Jasper 14dee3a62a clang-format: Understand C-style case in case label.
Before:
  case (my_int) ONE:

After:
  case (my_int)ONE:

This fixed llvm.org/PR23760

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239597 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-12 07:15:33 +00:00
Manuel Klimek 5f4ac97702 Fix crash in clang-format.
The following example used to crash clang-format.
 #define a\
  /**/}

Adjusting the indentation level cache for the line starting with the
comment would lead to an out-of-bounds array read.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239521 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-11 10:14:13 +00:00
Daniel Jasper 5596c4ee94 clang-format: Don't add spaces in foreach macro definition.
Before clang-format would e.g. add a space into

   #define Q_FOREACH(x, y)

which turns this into a non-function-like macro.

Patch by Strager Neds, thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239513 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-11 08:38:19 +00:00
Daniel Jasper 3db9851d2c clang-format: Support //!-comments, increase test coverage.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239404 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-09 13:16:54 +00:00
Daniel Jasper ecbdb36dba clang-format: More eagerly wrap trailing return types.
Before:
  template <typename T>
  auto aaaaaaaaaaaaaaaaaaaaaa(T t) -> decltype(eaaaaaaaaaaaaaaa<T>(t.a)
                                                   .aaaaaaaa());

After:
  template <typename T>
  auto aaaaaaaaaaaaaaaaaaaaaa(T t)
      -> decltype(eaaaaaaaaaaaaaaa<T>(t.a).aaaaaaaa());

Also add a test case for a difficult template parsing case I stumbled accross.
Needs fixing.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239149 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-05 13:18:09 +00:00
Daniel Jasper 7e690f7c5c clang-format: Properly reset BreakBeforeParameter when wrapping
operators to the new line.

Before:
  LOG_IF(aaa == //
         bbb)
      << a
      << b;

After:
  LOG_IF(aaa == //
         bbb)
      << a << b;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238911 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-03 09:26:03 +00:00
Daniel Jasper 94d4037154 clang-format: Lower binding strengths created by the [] created by ObjC
method expressions and array literals. They should not bind stronger
than regular parentheses or the braces of braced lists.

Specific test case in JavaScript:
Before:
  var aaaaa: List<
      SomeThing> = [new SomeThingAAAAAAAAAAAA(), new SomeThingBBBBBBBBB()];

After:
  var aaaaa: List<SomeThing> = [
    new SomeThingAAAAAAAAAAAA(),
    new SomeThingBBBBBBBBB()
  ];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238400 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-28 07:21:50 +00:00
Daniel Jasper 4b3ecccc19 clang-format: Fix false positive in function annotation detection.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238285 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-27 04:55:47 +00:00
Daniel Jasper 4dd7f125d3 clang-format: Guard the bin-packing in braced lists on BinPackArguments
instead of BinPackParameters. Braced lists are used as constructor
calls in many places and so the bin-packing should follow what is done
for other calls and not what is done for function declarations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238184 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-26 07:26:26 +00:00
Daniel Jasper a6074110bb clang-format: Fix child-formatting in macros.
This fixes a case where the column limit was incorrectly calculated
leading to a macro like this:

  #define A                                       \
    [] {                                          \
      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(        \
          xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx); \
    }

exceeding the column limit.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238182 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-26 07:03:42 +00:00
Anders Waldenborg a78300001a clang-format: Add space in function pointers with SpaceBeforeParens=Always
"void (*my_function)(void)" should become "void (*my_function) (void)" when
SpaceBeforeParens is set to 'Always'

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



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237704 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-19 16:54:26 +00:00
Daniel Jasper 2da70aa8bf clang-format: Improve *-detection.
Before:
  S << a *(10);

After:
  S << a * (10);

This fixes llvm.org/PR16500.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237690 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-19 12:29:27 +00:00
Daniel Jasper f723d21c87 clang-format: Improve for-loop formatting.
Before:
  for (SmallVectorImpl<TemplateIdAnnotationn *>::iterator I =
           Container.begin(),
                                                          E = Container.end();
       I != E; ++I)

After:
  for (SmallVectorImpl<TemplateIdAnnotationn *>::iterator
           I = Container.begin(),
           E = Container.end();
       I != E; ++I)

This fixes llvm.org/PR23544.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237688 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-19 11:51:39 +00:00
Daniel Jasper d42fd2ae0f clang-format: Support #include_next
Before:
  #include_next < test.h >

After:
  #include_next <test.h>

This fixes llvm.org/PR23500

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237686 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-19 11:22:29 +00:00
Daniel Jasper 857905e4b4 clang-format: Correctly detect casts to qualified types.
Before:
  ns::E f() { return (ns::E) - 1; }

After:
  ns::E f() { return (ns::E)-1; }

This fixes llvm.org/PR23503.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237684 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-19 11:18:39 +00:00
Daniel Jasper 3e51222d4b clang-format: Fix regression caused by r237244.
Before:
  [call aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.
          aaaaaaaa];

After:
  [call aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa
          .aaaaaaaa];

This merely papers over the fact that we aren't parsing ObjC method calls
correctly. Also, the indentation is weird.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237681 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-19 11:06:33 +00:00
Daniel Jasper 6219f10c6f clang-format: Fix another regression caused by r237565.
Before:
  class C : test {
    class D : test{void f(){int i{2};
  }
  }
  ;
  }
  ;

After:
  class C : test {
    class D : test {
      void f() { int i{2}; }
    };
  };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237569 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-18 14:49:19 +00:00
Daniel Jasper 513f0c09b4 clang-format: Fix regression introduced by r237565.
Before:
  class C : public D {
    SomeClass SC { 2 };
  };

After:
  class C : public D {
    SomeClass SC{2};
  };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237568 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-18 14:12:24 +00:00
Daniel Jasper 6338229cf6 clang-format: Improve detection of macros annotating functions.
Before:
  ASSERT("aaaaaaaaaaaaaaa")
      << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
      << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;

After:
  ASSERT("aaaaaaaaaaaaaaa") << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                            << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;

Also cleanup implementation a bit and only mark closing parenthesis of
these annotations.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237567 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-18 13:47:23 +00:00
Daniel Jasper b0cbc5dca1 clang-format: Allow braced initializers in template arguments of class
specializations.

Before:
  template <class T>
      struct S < std::is_arithmetic<T> {
  } > {};

After:
  template <class T> struct S<std::is_arithmetic<T>{}> {};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237565 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-18 12:52:00 +00:00
Daniel Jasper d1ceccab96 clang-format: Support function annotations in macros.
Before:
  DEPRECATED("Use NewClass::NewFunction instead.") string
      OldFunction(const string &parameter) {}

After:
  DEPRECATED("Use NewClass::NewFunction instead.")
  string OldFunction(const string &parameter) {}

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237562 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-18 09:47:22 +00:00
Daniel Jasper bee9c263f2 clang-format: Properly align ObjC string literals.
Before:
  NSString s = @"a"
               "b"
               "c";
  NSString s = @"a"
               @"b"
                @"c";

After:
  NSString s = @"a"
                "b"
                "c";
  NSString s = @"a"
               @"b"
               @"c";

This fixes llvm.org/PR23536.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237538 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-17 08:13:23 +00:00
Daniel Jasper 7599b4c4e6 clang-format: Improve line wrapping around << operators.
Generally, clang-format tries to keep label-value pairs on a single
line for stream operators. However, we should not do that if there is
just a single such pair, as that doesn't help much.

Before:
  llvm::errs() << "aaaaaaaaaaaa: " << aaaaaaa(aaaaaaaaa,
                                              aaaaaaaaa);

After:
  llvm::errs() << "aaaaaaaaaaaa: "
               << aaaaaaa(aaaaaaaaa, aaaaaaaaa);

Also remove old test case that was testing actual behavior any more.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237535 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-17 07:27:09 +00:00
Daniel Jasper db89841ef9 clang-format: Slightly change format decisions around macro annotations.
Before:
  bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
      GUARDED_BY(aaaaaaaaaaaa) = aaaaaaaaaaaaaaaaaaaaaaaaa;

After:
  bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa) =
      aaaaaaaaaaaaaaaaaaaaaaaaa;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237430 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-15 09:58:11 +00:00
Daniel Jasper b5236493da clang-format: Don't use column layout in lists that have separating
comments. At some point, we might to want to a layout with a different
number of columns instead, but at the moment, this causes more
confusion than it's worth.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237427 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-15 09:41:59 +00:00
Daniel Jasper b6c4df3a32 clang-format: Add missing space before ObjC selector.
Before:
  [self aaaaa:(1 + 2)bbbbb:3];

After:
  [self aaaaa:(1 + 2) bbbbb:3];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237424 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-15 09:05:31 +00:00
Daniel Jasper cd67166a37 clang-format: Improve nested block / lambda indentation when wrapping
before binary/ternary operators.

Basically, it doesn't seem right to indent a nested block aligned to a
binary or ternary operator.

Before:
  int i = aaaaaa ? 1  //
                 : [] {
                   return 2;  //
                 }();
  llvm::errs() << "number of twos is "
               << std::count_if(v.begin(), v.end(), [](int x) {
                 return x == 2;  // force break
               });

After:
  int i = aaaaaa ? 1  //
                 : [] {
                     return 2;  //
                   }();
  llvm::errs() << "number of twos is "
               << std::count_if(v.begin(), v.end(), [](int x) {
                    return x == 2;  // force break
                  });

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237263 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-13 16:09:21 +00:00
Daniel Jasper 9eea8caa35 clang-format: Fix incorrect */& classification.
Before:
  void f() { f(new a(), c *d); }

After:
  void f() { f(new a(), c * d); }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237249 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-13 12:54:30 +00:00
Daniel Jasper 9d1d803853 clang-format: Fix semicolon less macro-detection.
It was fooled by the comment.

Before:
  SOME_UNRELATED_MACRO
      /*static*/ int i;

After:
  SOME_UNRELATED_MACRO
  /*static*/ int i;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237246 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-13 11:35:53 +00:00
Daniel Jasper 30307bf8c6 clang-format: [ObjC] Further improve wrapping of methods calls without inputs.
Before:
  [aaaaaaaaaaaaaaaaaaaaaaa
      .aaaaaaaa[aaaaaaaaaaaaaaaaaaaaa] aaaaaaaaaaaaaaaaaaaaaa];

After:
  [aaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaa[aaaaaaaaaaaaaaaaaaaaa]
      aaaaaaaaaaaaaaaaaaaaaa];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237244 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-13 10:23:03 +00:00
Daniel Jasper 6d4764d315 clang-format: [ObjC] Make IndentWrappedFunctionNames work with ObjC functions
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237241 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-13 09:38:25 +00:00
Daniel Jasper 3afb086aeb clang-format: Prefer formatting local lambdas like functions.
Before:
  auto my_lambda =
      [](const string &some_parameter) { return some_parameter.size(); };

After:
  auto my_lambda = [](const string &some_parameter) {
    return some_parameter.size();
  };

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237235 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-13 08:47:16 +00:00
Daniel Jasper 202c7cf413 clang-format: Support column layout with comment after {.
Before:
  vector<int> iiiiiiiiiiiiiii = {                      //
      1111111111, 2222222222, 33333333333, 4444444444, //
      111111111, 222222222, 3333333333, 444444444,     //
      11111111, 22222222, 333333333, 44444444};

After:
  vector<int> iiiiiiiiiiiiiii = {                      //
      1111111111, 2222222222, 33333333333, 4444444444, //
      111111111,  222222222,  3333333333,  444444444,  //
      11111111,   22222222,   333333333,   44444444};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237233 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-13 08:16:00 +00:00
Daniel Jasper a00c9ee75f clang-format: Fix */& detection for lambdas in macros.
Before:
  #define MACRO() [](A * a) { return 1; }

After:
  #define MACRO() [](A *a) { return 1; }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237109 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-12 10:20:32 +00:00
Daniel Jasper ea22a3f133 clang-format: Fix hanging nested blocks in macros.
Before:
  #define MACRO()                     \
    Debug(aaa, /* force line break */ \
          {                           \
      int i;                          \
      int j;                          \
          })

After:
  #define MACRO()                     \
    Debug(aaa, /* force line break */ \
          {                           \
            int i;                    \
            int j;                    \
          })

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237108 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-12 10:16:02 +00:00
Manuel Klimek 54f26dc467 Refactor clang-format's formatter.
Summary:
a) Pull out a class LevelIndentTracker whose responsibility is to keep track
   of the indent of levels across multiple annotated lines.
b) Put all responsibility for merging lines into the LineJoiner; make the
   LineJoiner iterate over the lines so we never operate on a line that might
   be merged later; this makes the interface safer to use.
c) Move formatting of the end-of-file whitespace into formatFirstToken.

Fix bugs that became obvious after the refactoring:
1. We would not format lines with offsets correctly inside nested blocks if
   only the outer expression was affected:
   int x = s({ // clang-format only this line
     class X {
       public:
    // ^ this starts at the non-modified indnent level; previously we would
    //   not fix this, now we correctly outdent it.
       void f();
     };
   });
2. We would incorrectly align comments across lines that do not have comments
   for lines with nested blocks:
   int expression; // with comment
   int x = s({
     int y; // comment
     int z; // we would incorrectly align this comment with the comment on
            // 'expression'
   });

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237104 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-12 09:23:57 +00:00
Daniel Jasper 2bfdd4f5d5 clang-format: Support aligning ObjC string literals.
Before:
  NSString s = @"aaaa"
      @"bbbb";

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237000 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-11 15:15:48 +00:00
Daniel Jasper 75557a85f8 clang-format: Improve column layout.
Specifically, calculate the deviation between the shortest and longest
element (which is used to prevent excessive whitespace) per column, not
overall. This automatically handles the corner cases of a single column
and a single row so that the actualy implementation becomes simpler.

Before:
  vector<int> x = {1,
                   aaaaaaaaaaaaaaaaaaaaaa,
                   2,
                   bbbbbbbbbbbbbbbbbbbbbb,
                   3,
                   cccccccccccccccccccccc};

After:
  vector<int> x = {1, aaaaaaaaaaaaaaaaaaaaaa,
                   2, bbbbbbbbbbbbbbbbbbbbbb,
                   3, cccccccccccccccccccccc};

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236992 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-11 13:35:40 +00:00
Daniel Jasper d775e36456 clang-format: Don't merge subsequent lines into _asm blocks.
Before:
  _asm {
  } int i;

After:
  _asm {
  }
  int i;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236985 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-11 11:59:46 +00:00
Daniel Jasper 3eb01df09c clang-format: Improve wrapping of << operators.
Before:
  llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
                     aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
                      aaaaaaaaaaaaaaaa) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;

After:
  llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
                      aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
                      aaaaaaaaaaaaaaaa)
               << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;

Also, cleanup and simplify the operator wrapping logic.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236960 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-10 21:15:07 +00:00
Daniel Jasper 9b03bacc4a 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236946 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-10 08:42:04 +00:00
Daniel Jasper 9fb893e047 clang-format: Fix bug in escaped newline calculation.
This prevents clang-format from inadvertently joining stuff into macro
definitions as reported in llvm.org/PR23466.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236944 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-10 08:00:25 +00:00
Daniel Jasper 04822968f3 clang-format: Several improvements around formatting braced lists.
In particular:
* If the difference between the longest and shortest element, we copped
  out of column format completely. Now, we instead allow to arrange
  these in a single column, essentially enforcing a one-per-line format.
* Allow column layout even if there are braced lists. Especially, if
  there are many short lists, this can be beneficial. The bad case,
  where there is a long nested init list is usually caught as we now
  limit the length difference of the longest and shortest element.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236851 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-08 13:51:14 +00:00
Daniel Jasper c5d09e5e3e clang-format: Improve r236597, Properly indent method calls without inputs.
Before:
  [aaaaaaaaaaaa(aaaaaa)
          aaaaaaaaaaaaaaaaaaaa];

After:
  [aaaaaaaaaaaa(aaaaaa)
      aaaaaaaaaaaaaaaaaaaa];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236730 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-07 14:19:59 +00:00
Manuel Klimek 1b514675e0 Implements a way to retrieve information about whether some lines were not formatted due to syntax errors.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236722 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-07 12:26:30 +00:00
Daniel Jasper f84d646002 clang-format: Don't indent 'signals' as access specifier if it isn't one
Before:
  {
  signals.set(0);
  }

After:
  {
    signals.set(0);
  }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236630 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-06 19:21:23 +00:00
Daniel Jasper 4ec9a3892c 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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236604 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-06 15:19:47 +00:00
Daniel Jasper 3ab2989008 clang-format: Allow ternary expressions inside template parameters if
the template parameters aren't inside an expression context.

This fixes llvm.org/PR23270.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236603 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-06 14:53:50 +00:00
Daniel Jasper 10fc44072e clang-format: Consider operator precedence as penalty when breaking
before operators.

This fixes llvm.org/23382.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236602 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-06 14:23:38 +00:00
Daniel Jasper 1fc06ca35a clang-format: Accept slightly more record declarations.
This fixes llvm.org/PR23397.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236599 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-06 14:03:02 +00:00
Daniel Jasper 0c4ddbdc14 clang-format: Fix bad wrapping of ObjC method exprs.
Before:
  [aaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa:
      aaaaaaaa aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];

After:
  [aaaaaaaaaaaaaaaaaaaaaaaaa
      aaaaaaaaaaaaaaaaa:aaaaaaaa
                    aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];

Note that this might now violate the column limit and we probably need an
alternative way of indenting these then. However, that is still strictly better
than the messy formatting that clang-format did before.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236598 91177308-0d34-0410-b5e6-96231b3b80d8
2015-05-06 13:13:03 +00:00