Commit Graph

599 Commits

Author SHA1 Message Date
Daniel Jasper 92bd16fea4 clang-format: [JS] Make AllowShortFunctionsOnASingle line value "Empty"
work properly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253674 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-20 16:44:28 +00:00
Daniel Jasper 53b1a37ee0 clang-format: [JS] Properly add a space after "in" in for loops.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253672 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-20 16:18:42 +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 c48bd86a18 clang-format: [Proto] Support extending message.
Before:
  extend.foo.Bar {
  }

After:
  extend .foo.Bar {
  }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253667 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-20 14:32:54 +00:00
Richard Smith ea21696b87 Add support for GCC's '__auto_type' extension, per the GCC manual:
https://gcc.gnu.org/onlinedocs/gcc/Typeof.html

Differences from the GCC extension:
 * __auto_type is also permitted in C++ (but only in places where
   it could appear in C), allowing its use in headers that might
   be shared across C and C++, or used from C++98
 * __auto_type can be combined with a declarator, as with C++ auto
   (for instance, "__auto_type *p")
 * multiple variables can be declared in a single __auto_type
   declaration, with the C++ semantics (the deduced type must be
   the same in each case)

This patch also adds a missing restriction on applying typeof to
a bit-field, which GCC has historically rejected in C (due to
lack of clarity as to whether the operand should be promoted).
The same restriction also applies to __auto_type in C (in both
GCC and Clang).

This also fixes PR25449.

Patch by Nicholas Allegra!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252690 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-11 02:02:15 +00:00
Daniel Jasper 0bc4843289 clang-format: [JS] Add goog.setTestOnly to the list of stuff that
is import-statement-like and shouldn't be wrapped.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251643 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-29 19:05:20 +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
Nico Weber 4e6f624643 clang-format/java: Break after annotations on fields in Chromium style.
Chromium follows the Android style guide for Java code, and that doesn't make
the distinction between fields and non-fields that the Google Java style guide
makes:

https://source.android.com/source/code-style.html#use-standard-java-annotations
https://google.github.io/styleguide/javaguide.html#s4.8.5-annotations



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250422 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-15 16:03:01 +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 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 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 52ed5ec631 clang-format: [JS] Support pseudo-keywords
JavaScript allows keywords to appear in IdenfierName positions, e.g.
fields, or object literal members, but not as plain identifiers.

Patch by Martin Probst. Thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248714 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-28 14:29:45 +00:00
Daniel Jasper 048a64a775 clang-format: [JS] handle let (ES6)
Patch by Martin Probst. Thank you!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248713 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-28 14:28:08 +00:00
Nico Weber 90992a9c9f clang-format: In Java, `assert` is followed by an expression.
Before: assert a&& b;
Now:    assert a && b;


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@247750 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-15 23:48:17 +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 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 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
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
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
Birunthan Mohanathas 44a46fa5a5 clang-format: Print token type name instead of number in -debug output
Differential Revision: http://reviews.llvm.org/D11125


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242039 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-13 16:19:34 +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 e4dffdc233 clang-format: [JS] Assign proper penalties when breaking a type annotation
Before:
  class Test {
    aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa:
                         aaaaaaaaaaaaaaaaaaaaaaaa): aaaaaaaaaaaaaaaaaaaaaa {}
  }

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241908 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-10 13:39:26 +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
Daniel Jasper b3632d4efa clang-format: [JS] Allow line breaks after TypeScript type colons.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241339 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-03 10:37:23 +00:00
Daniel Jasper 0acd005aff clang-format: [Java/JS] Properly support instanceof and its precedence.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241337 91177308-0d34-0410-b5e6-96231b3b80d8
2015-07-03 10:12:53 +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
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 5994368c76 clang-format: [Proto] Don't treat "operator" as keyword.
Before:
  optional string operator= 1;

After:
  optional string operator = 1;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240624 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-25 08:38:46 +00:00
Eric Christopher dfc33ed9ea Fix "the the" in comments/documentation/etc.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240110 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-19 01:52:53 +00:00
Daniel Marjamaki c40533901b [clang] Refactoring of conditions so they use isOneOf() instead of multiple is().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@240008 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-18 10:59:26 +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 e9b9cc12c5 clang-format: [JS] Don't put top-level typescript enums on a single line.
This makes this consistent with non-typescript enums.

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

Patch initiated by Martin Probst.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239894 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-17 09:44:07 +00:00
Daniel Jasper 1cae5578fe clang-format: NFC. Add a function to test whether an annotated line
starts with a given sequence of tokens. Only the one-token version is
used yet, but other usages are coming up momentarily.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239892 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-17 09:43:56 +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
Daniel Jasper 8c828bc121 clang-format: [JS] Ensure that formatting actually takes place in tests.
And fix formatting issue discovered by that :-).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239530 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-11 13:29:20 +00:00
Daniel Jasper ed5723d05e clang-format: [JS] Only special case top level object literal
assignments as enums.

Top level object literals are treated as enums, and their k/v pairs are put on
separate lines:

  X.Y = {
    A: 1,
    B: 2
  };

However assignments within blocks should not be affected:

  function x() {
    y = {a:1, b:2};
  }

This change fixes the second case. Patch by Martin Probst.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239462 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-10 09:21:09 +00:00
Daniel Jasper fa8e4f7676 clang-format: [JS] Hotfix for runtime issue with deeply nested JS code.
I have not succeeded in writing a proper test case for this yet and we
also need to solve the underlying fundamental problem of trying too
many combinations with nested blocks (basically this somewhat works
around our Dijkstra algorithm). Preventing this linebreak is good
anyways as usually the penalties never make us choose it (that's why I
can't create a test) and it also looks ugly.

Also cleaned up state comparison code that I discovered while hunting
this down.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239398 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-09 11:39:22 +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 582d3da725 clang-format: [JS] Let fat arrows have 'Assignment' precedence.
This is a more correct representation than using "Equality" introduced
in r238942 which was a quick fix to solve an actual regression.

According to the typescript spec, arrows behave like "low-precedence"
assignments.

Before:
  var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) &&
                    aaaaaaaaaaaaaaaaaaaaa(bbbbbbb));
After:
  var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) &&
                              aaaaaaaaaaaaaaaaaaaaa(bbbbbbb));

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239137 91177308-0d34-0410-b5e6-96231b3b80d8
2015-06-05 08:25:37 +00:00