Daniel Jasper
1a31bab301
clang-format: Fix behavior with comments before conditional expressions
...
Before:
SomeFunction(aaaaaaaaaaaaaaaaa,
// comment.
ccccccccccccccccc ? aaaaaaaaaaaaaaaaaaaa
: bbbbbbbbbbbbbbbbbbbb);
After:
SomeFunction(aaaaaaaaaaaaaaaaa,
// comment.
ccccccccccccccccc ? aaaaaaaaaaaaaaaaaaaa : bbbbbbbbbbbbbbbbbbbb);
llvm-svn: 219921
2014-10-16 09:10:11 +00:00
Daniel Jasper
ea772b4df2
clang-format: [ObjC] Fix method expression detection.
...
Before:
return (a)[foo bar : baz];
After:
return (a)[foo bar:baz];
llvm-svn: 219919
2014-10-16 08:38:51 +00:00
Daniel Jasper
ec8e838baa
clang-format: [ObjC] Wrap ObjC method declarations before annotations.
...
Before:
- (instancetype)initXxxxxxxxxxxxxxxxxxxxxxxxx:(id<x>)x
y:(id<yyyyyyyyyyyyyyyyyyyy>)
y NS_DESIGNATED_INITIALIZER;
After:
- (instancetype)initXxxxxxxxxxxxxxxxxxxxxxxxx:(id<x>)x
y:(id<yyyyyyyyyyyyyyyyyyyy>)y
NS_DESIGNATED_INITIALIZER;
llvm-svn: 219564
2014-10-11 08:24:56 +00:00
Daniel Jasper
18210d7d2f
clang-format: Add option to control call argument bin-packing separately
...
This is desirable for the Chromium style guide:
http://www.chromium.org/developers/coding-style
llvm-svn: 219400
2014-10-09 09:52:05 +00:00
Daniel Jasper
4281c5ae01
clang-format: Fix bug with comments between non-trival parameters.
...
Before:
SomeFunction(a, a,
// comment
b + x);
After:
SomeFunction(a, a,
// comment
b + x);
llvm-svn: 219209
2014-10-07 14:45:34 +00:00
Daniel Jasper
a45eb4c000
clang-format: If in doubt, assume '+' is a binary operator.
...
Before:
#define LENGTH(x, y) (x) - (y)+1
After:
#define LENGTH(x, y) (x) - (y) + 1
llvm-svn: 219119
2014-10-06 13:16:43 +00:00
Daniel Jasper
67f8ad258f
clang-format: [JS] Support AllowShortFunctionsOnASingleLine.
...
Specifically, this also counts for stuff like (with style "inline"):
var x = function() {
return 1;
};
llvm-svn: 218689
2014-09-30 17:57:06 +00:00
Daniel Jasper
91881d99f7
clang-format: Fix GCC warning about implicit bool pointer conversion.
...
Introduced in r217880.
llvm-svn: 218597
2014-09-29 08:07:46 +00:00
Daniel Jasper
1779d438bc
clang-format: [JS] Improve formatting of function literals in chains
...
Before:
getSomeLongPromise(.....)
.then(
function(value) {
body();
body();
})
.thenCatch(function(error) {
body();
body();
});
After:
getSomeLongPromise(.....)
.then(function(value) {
body();
body();
})
.thenCatch(function(error) {
body();
body();
});
llvm-svn: 218595
2014-09-29 07:54:54 +00:00
Nico Weber
7533b4dada
clang-format: Don't let -style=Chromium imply c++03 template formatting.
...
Chromium's now using some c++11 language features, so it's now fine that
clang-format produces vector<vector<int>>.
llvm-svn: 218392
2014-09-24 17:17:32 +00:00
Daniel Jasper
3549ea1a73
clang-format: [JS] add space before operator 'in'.
...
Before:
return ('aaa')in bbbb;
After:
return ('aaa') in bbbb;
llvm-svn: 218119
2014-09-19 10:48:15 +00:00
Daniel Jasper
540dbe29bc
clang-format: Prevent column layout if elements aren't uniform enough.
...
This patch only considers the difference between the length of the
shortest and longest element, but we might want to look at other
features (token count, etc.) in future.
Before:
std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{
aaaaaaa, aaaaaaaaaa,
aaaaa, aaaaaaaaaaaaaaa,
aaa, aaaaaaaaaa,
a, aaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa,
aaaaaaa, a};
After:
std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{
aaaaaaa, aaaaaaaaaa, aaaaa, aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a,
aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa, aaaaaaa, a};
llvm-svn: 218111
2014-09-19 08:28:43 +00:00
Daniel Jasper
a41aa536dc
clang-format: Undo r216377.
...
It has proven to not be a food idea in many case.
llvm-svn: 218107
2014-09-19 08:01:25 +00:00
Daniel Jasper
b23e20b7f5
clang-format: Allow unbroken ::: in inline assembly.
...
Before:
asm volatile("nop" :: : "memory");
After:
asm volatile("nop" ::: "memory");
Patch by Eugene Toder. Thank you.
llvm-svn: 217883
2014-09-16 16:36:57 +00:00
Daniel Jasper
0085300a24
clang-format: Restructure and add missing tests.
...
Patch by Jean-Philippe Dufraigne, Thank you!
llvm-svn: 217880
2014-09-16 16:22:30 +00:00
Daniel Jasper
c58c70e2f3
clang-format: Basic support for Java.
...
llvm-svn: 217759
2014-09-15 11:21:46 +00:00
Daniel Jasper
ac043c900c
clang-format: Add option to break before non-assignment operators.
...
This will allow:
int aaaaaaaaaaaaaa =
bbbbbbbbbbbbbb
+ ccccccccccccccc;
llvm-svn: 217757
2014-09-15 11:11:00 +00:00
Daniel Jasper
d6f17d83a3
clang-format: Improve line breaks at function calls.
...
Before:
EXPECT_CALL(SomeObject, SomeFunction(Parameter)).Times(2).WillRepeatedly(
Return(SomeValue));
After:
EXPECT_CALL(SomeObject, SomeFunction(Parameter))
.Times(2)
.WillRepeatedly(Return(SomeValue));
llvm-svn: 217687
2014-09-12 16:35:28 +00:00
Roman Kashitsyn
650ecb53ca
Fix bug 20892 - clang-format does not handle C-style comments
...
Summary:
http://llvm.org/bugs/show_bug.cgi?id=20892
Add support of C-style formatting enabling/disabling directives. Now the following two styles are supported:
// clang-format on
/* clang-format on */
The flexibility in comments (support of extra spaces and/or slashes, etc.) is deliberately avoided to simplify search in large code bases.
Reviewers: djasper
Reviewed By: djasper
Subscribers: cfe-commits, curdeius, klimek
Differential Revision: http://reviews.llvm.org/D5309
llvm-svn: 217588
2014-09-11 14:47:20 +00:00
Daniel Jasper
b87899b567
clang-format: Add option to allow short case labels on a single line.
...
On a single line:
switch (a) {
case 1: x = 1; return;
case 2: x = 2; return;
default: break;
}
Not on a single line:
switch (a) {
case 1:
x = 1;
return;
case 2:
x = 2;
return;
default:
break;
}
This partly addresses llvm.org/PR16535. In the long run, we probably want to
lay these out in columns.
llvm-svn: 217501
2014-09-10 13:11:45 +00:00
Daniel Jasper
23376259c0
clang-format: [JS] Support regex literals with trailing escaped slash.
...
Before:
var regex = / a\//; int i;
After:
var regex = /a\//;
int i;
This required pushing the Lexer into its wrapper class and generating a
new one in this specific case. Otherwise, the sequence get lexed as a
//-comment. This is hacky, but I don't know a better way (short of
supporting regex literals in the Lexer).
Pushing the Lexer down seems to make all the call sites simpler.
llvm-svn: 217444
2014-09-09 14:37:39 +00:00
Daniel Jasper
90ebc98e3d
clang-format: [JS] Format embedded function literals more efficently.
...
Before:
return {
a: a,
link:
function() {
f(); //
},
link:
function() {
f(); //
}
};
After:
return {
a: a,
link: function() {
f(); //
},
link: function() {
f(); //
}
};
llvm-svn: 217238
2014-09-05 09:27:38 +00:00
Daniel Jasper
3a038de3c8
clang-format: [JS] JavaScript does not have the */&/&& madness.
...
Before:
e&& e.SomeFunction();
After:
e && e.SomeFunction();
Yeah, this might be useful for C++, too, but it is not such a frequent
pattern there (plus the fix is much harder).
llvm-svn: 217237
2014-09-05 08:53:45 +00:00
Daniel Jasper
3f69ba1075
clang-format: [JS] Better support for empty function literals.
...
Before:
SomeFunction(function(){});
After:
SomeFunction(function() {});
llvm-svn: 217236
2014-09-05 08:42:27 +00:00
Daniel Jasper
97bfb7b1ba
clang-format: [JS] Fix indentation in dict literals.
...
Before:
return {
'finish':
//
a
};
After:
return {
'finish':
//
a
};
llvm-svn: 217235
2014-09-05 08:29:31 +00:00
Daniel Jasper
4db69bd542
clang-format: [JS] Support alternative operator names as identifiers.
...
Before:
not. and . or . not_eq = 1;
After:
not.and.or.not_eq = 1;
llvm-svn: 217179
2014-09-04 18:23:42 +00:00
Daniel Jasper
8f2e94c8ab
clang-format: [JS] Supprot "catch" as function name.
...
Before:
someObject.catch ();
After:
someObject.catch();
llvm-svn: 217158
2014-09-04 15:03:34 +00:00
Daniel Jasper
94e11d02d8
clang-format: [JS] Support comments in dict literals.
...
Before:
var stuff = {
// comment for update
update : false,
// comment for update
modules : false,
// comment for update
tasks : false
};
After:
var stuff = {
// comment for update
update : false,
// comment for update
modules : false,
// comment for update
tasks : false
};
llvm-svn: 217157
2014-09-04 14:58:30 +00:00
Daniel Jasper
db986eb6bb
clang-format: Add an option 'SpaceAfterCStyleCast'.
...
This permits to add a space after closing parenthesis of a C-style cast.
Defaults to false to preserve old behavior.
Fixes llvm.org/PR19982.
Before:
(int)i;
After:
(int) i;
Patch by Marek Kurdej.
llvm-svn: 217022
2014-09-03 07:37:29 +00:00
Daniel Jasper
73e171f76d
clang-format: Fix unary operator detection in corner case.
...
Before:
decltype(* ::std::declval<const T &>()) void F();
After:
decltype(*::std::declval<const T &>()) void F();
llvm-svn: 216724
2014-08-29 12:54:38 +00:00
Daniel Jasper
168c8aa679
clang-format: Fix regression in formatting of braced initializers.
...
Before:
Node n{1, Node{1000}, //
2};
After:
Node n{1, Node{1000}, //
2};
llvm-svn: 216540
2014-08-27 11:53:26 +00:00
Daniel Jasper
8f46365481
clang-format: Don't butcher __asm blocks.
...
Instead completely cop out of formatting them for now.
This fixes llvm.org/PR20618.
llvm-svn: 216501
2014-08-26 23:15:12 +00:00
Daniel Jasper
ad981f888a
clang-format: New option SpacesInSquareBrackets.
...
Before:
int a[5];
a[3] += 42;
After:
int a[ 5 ];
a[ 3 ] += 42;
Fixes LLVM bug #17887 (http://llvm.org/bugs/show_bug.cgi?id=17887 ).
Patch by Marek Kurdej, thank you!
llvm-svn: 216449
2014-08-26 11:41:14 +00:00
Daniel Jasper
610381ff07
clang-format: Improve handling of block comments in braced lists.
...
Before:
std::vector<int> v = {
1, 0 /* comment */
};
After:
std::vector<int> v = {1, 0 /* comment */};
llvm-svn: 216445
2014-08-26 09:37:52 +00:00
Daniel Jasper
4b3ba214d0
clang-format: Understand sequenced casts.
...
This fixed llvm.org/PR20712.
Before:
int i = (int)(int) -2;
After:
int i = (int)(int)-2;
llvm-svn: 216378
2014-08-25 09:36:07 +00:00
Daniel Jasper
7189fb2cf9
clang-format: Improve formatting of nested builder-type calls.
...
Before:
f(FirstToken->WhitespaceRange.getBegin().getLocWithOffset(
First->LastNewlineOffset));
After:
f(FirstToken->WhitespaceRange.getBegin()
.getLocWithOffset(First->LastNewlineOffset));
llvm-svn: 216377
2014-08-25 08:48:17 +00:00
Daniel Jasper
ea79ea1627
clang-format: Prefer breaking after return type over template param
...
Before:
typename aaaaaaaaaa<aaaaaa>::aaaaaaaaaaa aaaaaaaaaa<
aaaaaa>::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bool *aaaaaaaaaaaaaaaaaa,
bool *aa) {}
After:
typename aaaaaaaaaa<aaaaaa>::aaaaaaaaaaa
aaaaaaaaaa<aaaaaa>::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
bool *aaaaaaaaaaaaaaaaaa, bool *aa) {}
llvm-svn: 215693
2014-08-15 05:00:39 +00:00
Daniel Jasper
497d9fdcf8
clang-format: [proto] Understand text-format nesting without :
...
Before:
option (MyProto.options) = {
field_c : "OK" msg_field{field_d : 123}
};
After:
option (MyProto.options) = {
field_c : "OK"
msg_field{field_d : 123}
};
(Note that the colon after "msg_field" is optional).
llvm-svn: 215692
2014-08-15 05:00:35 +00:00
Alexander Kornienko
c6221a58ec
Split a large unit-test, so that it doesn't exceed stack frame size in certain test environments
...
llvm-svn: 215639
2014-08-14 13:07:35 +00:00
Daniel Jasper
db76479d73
clang-format: Fix AlwaysBreakAfterDefinitionReturnType in Stroutrup style
...
Before:
template <class T>
T *f(T &c) // Problem here: no line break before f
{
return NULL;
}
After:
template <class T>
T *
f(T &c)
{
return NULL;
}
Patch by Marek Kurdej, thank you!
llvm-svn: 215633
2014-08-14 11:36:03 +00:00
Daniel Jasper
1904e9b98d
clang-format: Support chained dereferenced assignments.
...
Before:
x = * a(x) = *a(y);
After:
x = *a(x) = *a(y);
llvm-svn: 215632
2014-08-14 10:53:19 +00:00
Daniel Jasper
78b4533acf
clang-format: Support breaking arguments of function type typedefs.
...
Before:
typedef size_t (*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(
const aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
After:
typedef size_t (*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(
const aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
llvm-svn: 215631
2014-08-14 10:52:56 +00:00
Benjamin Kramer
2f5db8b3db
Header guard canonicalization, clang part.
...
Modifications made by clang-tidy with minor tweaks.
llvm-svn: 215557
2014-08-13 16:25:19 +00:00
Manuel Klimek
5f594f80f4
Fix crasher bug in clang-format.
...
llvm-svn: 215549
2014-08-13 14:00:41 +00:00
Daniel Jasper
839922e9d1
clang-format: Format long lists in columns if without bin-packing.
...
After (even with BinPacking = false):
const Aaaaaa aaaaa = {
aaaaa, bbbbb, ccccc, ddddd, eeeee, ffffff, ggggg, hhhhhh,
iiiiii, jjjjjj, kkkkkk, aaaaa, bbbbb, ccccc, ddddd, eeeee,
ffffff, ggggg, hhhhhh, iiiiii, jjjjjj, kkkkkk,
};
Before:
<each element on its own line>
This fixes http://llvm.org/PR20623 .
llvm-svn: 215529
2014-08-13 08:46:21 +00:00
Daniel Jasper
343643b979
clang-format: Understand #defines defining system includes.
...
Before:
#define MY_IMPORT < a / b >
After:
#define MY_IMPORT <a/b>
llvm-svn: 215527
2014-08-13 08:29:18 +00:00
Daniel Jasper
598dd330e8
clang-format: Avoid bad line break.
...
Before:
int
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(const
typename aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa);
After:
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
const typename aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa);
llvm-svn: 215442
2014-08-12 13:22:26 +00:00
Roman Kashitsyn
a043cedf0a
Fixes bug 20587 - Add K&R break before braces style
...
Summary:
http://llvm.org/bugs/show_bug.cgi?id=20587
Added K&R style. It could be enabled by the following option:
```
BreakBeforeBraces: KernighanRitchie
```
This style is like `Attach`, but break *only* before function
declarations.
As I can see, no additional logic required to support this style, any
style different from other styles automagically satisfies K&R.
Reviewers: djasper
Reviewed By: djasper
Subscribers: cfe-commits, klimek
Differential Revision: http://reviews.llvm.org/D4837
llvm-svn: 215354
2014-08-11 12:18:01 +00:00
Daniel Jasper
a5621202c4
clang-format: Prefer not to put lambdas on a single line.
...
Before:
string abc =
SomeFunction(aaaaaaaaaaaaa, aaaaa,
[]() { SomeOtherFunctioooooooooooooooooooooooooon(); });
After:
string abc = SomeFunction(aaaaaaaaaaaaa, aaaaa, []() {
SomeOtherFunctioooooooooooooooooooooooooon();
});
llvm-svn: 215197
2014-08-08 12:00:13 +00:00
Daniel Jasper
78b1949950
clang-format: Correct SBPO_Always-behavior after function-like keywords
...
Before:
auto f (int x) -> decltype(x) { return sizeof(x); }
int g () noexcept(someCall ());
static_assert(sizeof(char) == 1, "Your compiler is broken");
After:
auto f (int x) -> decltype (x) { return sizeof (x); }
int g () noexcept (someCall ());
static_assert (sizeof (char) == 1, "Your compiler is broken");
This fixes llvm.org/PR20559.
Patch by Roman Kashitsyn, thank you!
llvm-svn: 214969
2014-08-06 14:15:41 +00:00