Daniel Jasper
53395406da
clang-format: Fix regression formatting QT's "signals:" from r234318.
...
llvm-svn: 234320
2015-04-07 15:04:40 +00:00
Daniel Jasper
676e516354
clang-format: Don't allow labels when expecting declarations.
...
This fixes formatting unnamed bitfields (llvm.org/PR21999).
Before:
struct MyStruct {
uchar data;
uchar:
8;
uchar:
8;
uchar other;
};
After:
struct MyStruct {
uchar data;
uchar : 8;
uchar : 8;
uchar other;
};
llvm-svn: 234318
2015-04-07 14:36:33 +00:00
Daniel Jasper
acf67e3ecd
clang-format: Improve nested block formatting.
...
Before:
functionA(functionB({
int i;
int j;
}),
aaaa, bbbb, cccc);
After:
functionA(functionB({
int i;
int j;
}),
aaaa, bbbb, cccc);
llvm-svn: 234304
2015-04-07 08:20:35 +00:00
Daniel Jasper
9dedc775d7
clang-format: Indent relative to the ./-> and not the function name.
...
Before:
aaaaaaaaaaa //
.aaaa( //
bbbb) // This is different ..
.aaaa( //
cccc); // .. from this.
After:
aaaaaaaaaaa //
.aaaa( //
bbbb) // This is identical ..
.aaaa( //
cccc); // .. to this.
llvm-svn: 234300
2015-04-07 06:41:24 +00:00
Daniel Jasper
05cd92922d
clang-format: Force line break in trailing calls after multline exprs.
...
Before:
aaaaaaaa(aaaaaaaaaa,
bbbbbbbbbb).a();
After:
aaaaaaaa(aaaaaaaaaa,
bbbbbbbbbb)
.a();
llvm-svn: 233304
2015-03-26 18:46:28 +00:00
Daniel Jasper
e99c72fc2e
clang-format: Fix merging of _T macros.
...
NewlinesBefore and HasUnescapedNewline were not properly propagated
leading to llvm.org/PR23032.
llvm-svn: 233276
2015-03-26 14:47:35 +00:00
Daniel Jasper
414c9c6fb0
clang-format: Fix another bug in wrapping around "*".
...
Before:
void aaaaa(
aaaaaaaaaaaa* aaaaaaaaaaaaaa) {} // even violation the column limit
After:
void aaaaa(aaaaaaaaaaaa*
aaaaaaaaaaaaaa) {}
llvm-svn: 232717
2015-03-19 09:40:16 +00:00
Daniel Jasper
1130981907
clang-format: Fix bad wrapping after "*" introduced in r232044.
...
Before:
void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa*
const aaaaaaaaaaaa) {}
After:
void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaa* const aaaaaaaaaaaa) {}
llvm-svn: 232635
2015-03-18 14:20:13 +00:00
Daniel Jasper
92e0982936
[clang-format] Add missing test for std::function<void( int, int )>
...
spacing also fixed by r230473.
The fix in r230473 was done to enable fixing the spacing for
std::function<void( int, int )>.
I did not realized that it also fixed this
issue. Since it is fairly different from
Deleted &operator=(const Deleted &)& = default;
fixed in r230473, it seems sensible to add the regression test for it.
Also cleaned up the test by removing duplicated code and comment, and kept
repeated test set consistent.
Result of running the new tests with r230473 backed out:
[ RUN ] FormatTest.ConfigurableSpacesInParentheses
Actual: "std::function<void(int, int)> callback;"
Expected: "std::function<void( int, int )> callback;"
Actual: "std::function<void( int, int )> callback;"
Expected: "std::function<void(int, int)> callback;"
Actual: "std::function<void( int, int ) > callback;"
Expected: "std::function<void(int, int)> callback;"
[ FAILED ] FormatTest.ConfigurableSpacesInParentheses (402 ms)
Result of new tests with r230473:
[ RUN ] FormatTest.ConfigurableSpacesInParentheses
[ OK ] FormatTest.ConfigurableSpacesInParentheses (209 ms)
Review: http://reviews.llvm.org/D7922
Patch by Jean-Philippe Dufraigne. Thanks!
llvm-svn: 232632
2015-03-18 12:59:19 +00:00
Daniel Jasper
9ecb0e96b8
clang-format: Don't corrupt macros with open braces.
...
Formatting:
#define A { {
#define B } }
Before:
#define A \
{ \
{ #define B } \
}
After:
#define A \
{ \
{
#define B \
} \
}
This fixes llvm.org/PR22884.
llvm-svn: 232166
2015-03-13 13:32:11 +00:00
Daniel Jasper
55ca608cdc
clang-format: [OBJC] Don't indent 8 spaces in method declarations.
...
Before:
- (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
(SoooooooooooooooooooooomeType *)bbbbbbbbbb;
After:
- (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
(SoooooooooooooooooooooomeType *)bbbbbbbbbb;
llvm-svn: 232112
2015-03-12 22:13:45 +00:00
Daniel Jasper
b754a747be
clang-format: When putting */& next to types, also wrap before them.
...
Before:
LoooooooooooongType *
loooooooooooongVariable;
After:
LoooooooooooongType
*loooooooooooongVariable;
llvm-svn: 232044
2015-03-12 15:04:53 +00:00
Daniel Jasper
dc4f725673
clang-format: Fix incorrect && recognition.
...
Before:
if (a &&(b = c)) ..
After:
if (a && (b = c)) ..
llvm-svn: 231920
2015-03-11 12:59:49 +00:00
Daniel Jasper
ac5c97e36b
clang-format: Don't remove newline if macro ends in access specifier.
...
I.e.:
#define A public:
// The new line before this line would be removed.
int a;
llvm-svn: 231636
2015-03-09 08:13:55 +00:00
Daniel Jasper
98f8ae34da
clang-format: Slightly change indentation rules in for loops.
...
There was already a TODO to double-check whether the extra indenation
makes sense. A slightly different case reveals that it is actively harmful:
for (int i = 0; i < aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
bbbbbbbbbbbbbbbbbbbb < ccccccccccccccc;
++i) {
}
Here (and it is probably not a totally infrequent case, it just works out that
"i < " is four spaces and so the four space extra indentation makes the
operator precedence confusing. So, this will now instead be formatted
as:
for (int i = 0; i < aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
bbbbbbbbbbbbbbbbbbbb < ccccccccccccccc;
++i) {
}
llvm-svn: 231461
2015-03-06 10:57:12 +00:00
Daniel Jasper
0391e55650
clang-format: Fix access to uninitialized memory.
...
With incomplete code, we aren't guaranteed to generated changes for
every token. In that case, we need to assume that even the very first
change can continue a preprocessor directive and initialize values
accordingly.
llvm-svn: 231066
2015-03-03 13:59:49 +00:00
Daniel Jasper
e662316994
clang-format: Prefer wrapping a lambda's body over the lambda's return type.
...
Before:
aaaaaaaaaaaaaaaaaaaaaa(
[](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa)
-> aaaaaaaaaaaaaaaaaaaaa { return aaaaaaaaaaaaaaaaa; });
After:
aaaaaaaaaaaaaaaaaaaaaa(
[](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaaaaaaa {
return aaaaaaaaaaaaaaaaa;
});
llvm-svn: 230942
2015-03-02 10:35:13 +00:00
Daniel Jasper
bea1ab46d9
clang-format: Always align */& in multi-var DeclStmts.
...
Seems like the most consistent thing to do and in multi-var DeclStmts,
it is especially important to point out that the */& bind to the
identifier.
llvm-svn: 230903
2015-03-01 18:55:26 +00:00
Daniel Jasper
308062bd0d
clang-format: Make trailing commas in array inits force one per line.
...
Before:
NSArray *array = @[ @"a", @"a", ];
After:
NSArray *array = @[
@"a",
@"a",
];
llvm-svn: 230741
2015-02-27 08:41:05 +00:00
Daniel Jasper
b812e323fa
clang-format: Make braced list formatting more consistent.
...
Before:
Aaaa aaaaaaaaaaa{
{
a, // +1 indent weird.
b, // trailing comma signals one per line.
}, // trailing comma signals one per line.
};
After:
Aaaa aaaaaaaaaaa{
{
a, // better!?
b, // trailing comma signals one per line.
}, // trailing comma signals one per line.
};
Interesting that this apparently was entirely untested :-(.
llvm-svn: 230627
2015-02-26 11:46:29 +00:00
Daniel Jasper
beaa322c36
clang-format: Fix space of arrays of pointers to templated types.
...
Before:
vector<int>(*foo_)[6];
After:
vector<int> (*foo_)[6];
llvm-svn: 230625
2015-02-26 11:30:50 +00:00
Daniel Jasper
a42de763ac
clang-format: Allow breaking after "else if(" as a last resort.
...
This isn't generally nice, but better than violating the column limit.
llvm-svn: 230620
2015-02-26 09:49:08 +00:00
Daniel Jasper
1c22048834
clang-format: Fix spacing for function with ref-qualification ..
...
.. when using SpacesInCStyleCastParentheses != SpacesInParentheses.
Before:
FormatStyle Spaces = getLLVMStyle();
Deleted &operator=(const Deleted &)& = default;
Spaces.SpacesInParentheses = true;
Deleted(const Deleted &)& = default;
Spaces.SpacesInCStyleCastParentheses = true;
Spaces.SpacesInParentheses= false;
Deleted( const Deleted & )& = default;
After:
FormatStyle Spaces = getLLVMStyle();
Deleted &operator=(const Deleted &)& = default;;
Spaces.SpacesInParentheses= true;
Deleted( const Deleted & )& = default;
Spaces.SpacesInCStyleCastParentheses = true;
Spaces.SpacesInParentheses= false;
Deleted(const Deleted &)& = default;
Patch by Jean-Philippe Dufraigne. Thank you!
llvm-svn: 230473
2015-02-25 10:30:06 +00:00
Jacques Pienaar
411b251cea
clang-format: Change location of stashed token
...
Commit of patch in http://reviews.llvm.org/D7871
llvm-svn: 230395
2015-02-24 23:23:24 +00:00
Jacques Pienaar
68a7dbf86d
Fix merging of << at end of input.
...
Commit of review http://reviews.llvm.org/D7766
llvm-svn: 230061
2015-02-20 21:09:01 +00:00
Jacques Pienaar
fc27511223
clang-format: Space and triple angle braces.
...
Committing patch http://reviews.llvm.org/D6800 .
llvm-svn: 229783
2015-02-18 23:48:37 +00:00
Daniel Jasper
699631298e
clang-format: Don't force a break after "endl" if everything fits on one line.
...
llvm-svn: 229486
2015-02-17 10:05:15 +00:00
Daniel Jasper
d97d5d5cf7
clang-format: Fix crasher.
...
llvm-svn: 229485
2015-02-17 09:58:03 +00:00
Aaron Ballman
61005bc5de
Reverting a switch from LLVM_DELETED_FUNCTION to = delete; this test should not have changed.
...
llvm-svn: 229394
2015-02-16 14:14:01 +00:00
Aaron Ballman
abc1892057
Removing LLVM_DELETED_FUNCTION, as MSVC 2012 was the last reason for requiring the macro. NFC; Clang edition.
...
llvm-svn: 229339
2015-02-15 22:54:08 +00:00
Daniel Jasper
29d39d54e7
clang-format: Correctly mark preprocessor lines in child blocks.
...
This prevents contracting:
auto lambda = []() {
int a = 2
#if A
+ 2
#endif
;
};
into:
auto lambda = []() { int a = 2
#if A + 2
#endif ; };
Which is obviously BAD.
This fixes llvm.org/PR22496.
llvm-svn: 228522
2015-02-08 09:34:49 +00:00
Nico Weber
33381f5e0b
clang-format: Format Objective-C try blocks like all the other try blocks.
...
Before:
@try {
// ...
}
@finally {
// ...
}
Now:
@try {
// ...
} @finally {
// ...
}
This is consistent with how we format C++ try blocks and SEH try blocks.
clang-format not doing this before was an implementation oversight.
This is dependent on BraceBreakingStyle. The snippet above is with the
Attach style. Style Stroustrip for example still results in the "Before:"
snippet, which makes sense since other blocks (try, else) break after '}' too.
llvm-svn: 228483
2015-02-07 01:57:32 +00:00
Daniel Jasper
30029c6b58
clang-format: Fix assert triggering on carriage returns.
...
llvm-svn: 228288
2015-02-05 11:05:31 +00:00
Nico Weber
fac2371be3
clang-format: Add support for SEH __try / __except / __finally blocks.
...
This lets clang-format format
__try {
} __except(0) {
}
and
__try {
} __finally {
}
correctly. __try and __finally are keywords if `LangOpts.MicrosoftExt` is set,
so this turns this on. This also enables a few other keywords, but it
shouldn't overly perturb regular clang-format operation. __except is a
context-sensitive keyword, so `AdditionalKeywords` needs to be passed around to
a few more places.
Fixes PR22321.
llvm-svn: 228148
2015-02-04 15:26:27 +00:00
Daniel Jasper
47b35aeaa1
clang-format: Fix crasher caused by not properly setting dry-run.
...
llvm-svn: 227427
2015-01-29 10:47:14 +00:00
Daniel Jasper
d1c13736e0
clang-format: Fix another crasher caused by incomplete macro code.
...
We did't properly mark all of an AnnotatedLine's children as finalized
and thus would reformat the same tokens in different branches of #if/#else
sequences leading to invalid replacements.
llvm-svn: 226930
2015-01-23 19:37:25 +00:00
Daniel Jasper
7509216a41
clang-format: Fix incorrect classification of "*".
...
Before:
*a = b *c;
After:
*a = b * c;
llvm-svn: 226923
2015-01-23 19:04:49 +00:00
Daniel Jasper
e4b48c635c
clang-format: Fix crasher when splitting incomplete escape sequences.
...
llvm-svn: 226698
2015-01-21 19:50:35 +00:00
Daniel Jasper
04b979dd81
clang-format: Fix crasher caused by incorrect resetting of token info.
...
llvm-svn: 226685
2015-01-21 18:35:47 +00:00
Daniel Jasper
d1debfc2bb
clang-format: Fix bad memory access.
...
llvm-svn: 226680
2015-01-21 18:04:02 +00:00
Daniel Jasper
fd725c060b
clang-format: Fix use-heap-after-free bug.
...
Discovered by the awesome test case and ASAN.
llvm-svn: 226678
2015-01-21 17:35:29 +00:00
Daniel Jasper
6fd5d646cc
clang-format: Fix AlwaysBreakBeforeMultilineStrings with ColumnLimit=0
...
Before:
const char *x =
"hello llvm";
After:
const char *x = "hello llvm";
This fixes llvm.org/PR22245.
Patch by Bill Meltsner, thank you!
llvm-svn: 226564
2015-01-20 12:59:20 +00:00
Daniel Jasper
9b79efb51f
clang-format: Fix crasher on weird comments.
...
Crashing input:
/\
/ comment
llvm-svn: 226454
2015-01-19 11:49:32 +00:00
Daniel Jasper
193cdd381b
clang-format: Fix crasher on incomplete condition compilation.
...
Previously crashing input:
void f(
#if A
);
#else
#endif
llvm-svn: 226451
2015-01-19 10:52:16 +00:00
Daniel Jasper
20e8c3be3c
clang-format: Fix crash on invalid code.
...
Input "a<," made clang-format crash.
llvm-svn: 226450
2015-01-19 10:51:42 +00:00
Daniel Jasper
675b4f8350
clang-format: Fix clang-format crash on invalid code.
...
llvm-svn: 226449
2015-01-19 10:51:23 +00:00
Daniel Jasper
9d22bcc53e
clang-format: Fix assertion when trying to build a nullptr StringRef.
...
llvm-svn: 226448
2015-01-19 10:51:05 +00:00
Daniel Jasper
2bd7a64d12
clang-format: Fix endless loop on incomplete try-catch-block.
...
llvm-svn: 226447
2015-01-19 10:50:51 +00:00
Daniel Jasper
b1567c106f
clang-format: Remove assert that isn't helpful.
...
This assert would trigger on:
#d , = }
llvm-svn: 226446
2015-01-19 10:50:08 +00:00
Alexander Kornienko
00691cf3bb
Fix assertion in BreakableBlockComment ( http://llvm.org/PR21916 ).
...
Reviewers: djasper
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D6894
llvm-svn: 225628
2015-01-12 13:11:12 +00:00
Daniel Jasper
d6a1cab1bc
clang-format: Improve format of lambdas in ctor initializers.
...
Before:
Constructor()
: Constructor([] { // comment
int i;
}) {}
After:
Constructor()
: Constructor([] { // comment
int i;
}) {}
llvm-svn: 225625
2015-01-12 10:23:24 +00:00
Daniel Jasper
2337f28063
clang-format: Fix formatting of inline asm.
...
Specifically, adjust the leading "__asm {" and trailing "}" while still
leaving the assembly inside it alone.
This fixes llvm.org/PR22190.
llvm-svn: 225623
2015-01-12 10:14:56 +00:00
Daniel Jasper
d05d3a8919
clang-format: Force line break between "endl" and "<<".
...
This makes piped output easier to read in many instances.
Before:
llvm::errs() << aaaa << std::endl << bbbb << std::endl;
After:
llvm::errs() << aaaa << std::endl
<< bbbb << std::endl;
Also fix a few instance of "don't use else after return" as per the
coding standards.
llvm-svn: 225444
2015-01-08 13:56:57 +00:00
Daniel Jasper
b13135bc08
clang-format: Improve template parameter detection.
...
Before:
struct A < std::enable_if<sizeof(T2) <sizeof(int32)>::type>;
After:
struct A<std::enable_if<sizeof(T2) < sizeof(int32)>::type>;
llvm-svn: 225435
2015-01-08 08:48:21 +00:00
Daniel Jasper
4953210478
clang-format: Understand single-line comments at the end of blocks.
...
This prevents clang-format from moving/aligning the comment in the
snippet:
void f() {
int i; // some comment
// some unrelated comment
}
llvm-svn: 225352
2015-01-07 14:00:11 +00:00
Daniel Jasper
6a9682038f
clang-format: Fix unary operator detection.
...
Before:
** outparam = 1;
After:
**outparam = 1;
llvm-svn: 225349
2015-01-07 12:19:53 +00:00
Daniel Jasper
3a623dbd2a
clang-format: Fix incorrect detection of ObjC "in" keyword.
...
Before:
for (auto v : in [1]) { ..
After:
for (auto v : in[1]) { ..
llvm-svn: 224513
2014-12-18 12:11:01 +00:00
Alexander Kornienko
732b6bd4d1
Don't break single-line raw string literals.
...
Reviewers: djasper
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D6636
llvm-svn: 224223
2014-12-14 20:47:11 +00:00
Daniel Jasper
11a0ac66e1
clang-format: Revamp nested block formatting.
...
This fixed llvm.org/PR21804 and hopefully a few other strange cases.
Before:
if (blah_blah(whatever, whatever, [] {
doo_dah();
doo_dah();
})) {
}
}
After:
if (blah_blah(whatever, whatever, [] {
doo_dah();
doo_dah();
})) {
}
}
llvm-svn: 224112
2014-12-12 09:40:58 +00:00
Nico Weber
238462627e
clang-format: Add a test for PR19603 which seems fixed (maybe by r221338?).
...
llvm-svn: 223850
2014-12-09 23:22:35 +00:00
Daniel Jasper
3431b75069
clang-format: Support commas in lambda return types.
...
Before:
auto next_pair = [](A * a) -> pair<A*, A*>{};
After:
auto next_pair = [](A* a) -> pair<A*, A*>{};
llvm-svn: 223652
2014-12-08 13:22:37 +00:00
Daniel Jasper
55aed6777f
clang-format: Don't merge lines with comments.
...
Before:
int f() { // comment return 42; }
After:
int f() { // comment
return 42;
}
This fixes llvm.org/PR21769.
llvm-svn: 223609
2014-12-07 16:44:49 +00:00
Daniel Jasper
31f6c54733
clang-format: Support NS_OPTIONS, CF_ENUM and CF_OPTIONS.
...
This fixes llvm.org/PR21756.
llvm-svn: 223458
2014-12-05 10:42:21 +00:00
Daniel Jasper
86ee0b6daa
clang-format: More restrictively classify import declarations.
...
Before:
import::SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
After:
import::SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
llvm-svn: 223345
2014-12-04 08:57:27 +00:00
Daniel Jasper
c095663ec1
clang-format: Fix fake parentheses placement with comments.
...
Before:
return (a > b
// comment1
// comment2
|| c);
After:
return (a > b
// comment1
// comment2
|| c);
llvm-svn: 223234
2014-12-03 14:02:59 +00:00
Daniel Jasper
3219e43c94
clang-format: Add option to suppress operator alignment.
...
With alignment:
int aaaaaa = aa
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
* cccccccccccccccccccccccccccccccc;
Without alignment:
int aaaaaa = aa
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
* cccccccccccccccccccccccccccccccc;
This fixes llvm.org/PR21666.
llvm-svn: 223117
2014-12-02 13:24:51 +00:00
Daniel Jasper
8c6e9ef676
clang-format: precedence-based indentation when breaking before operators.
...
Before:
bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
== aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
* bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
&& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> ccccccccccccccccccccccccccccccccccccccccc;
After:
bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
== aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
* bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
&& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> ccccccccccccccccccccccccccccccccccccccccc;
Not particularly pretty, but can probably help to uncover bugs. And if this
bugs somebody, parentheses can help.
llvm-svn: 223111
2014-12-02 09:46:56 +00:00
Daniel Jasper
9e709351c5
clang-format: Add SFS_Empty to only empty functions on a single line.
...
Activated for and tested by Google's Java style.
This fixes llvm.org/PR21667.
llvm-svn: 222819
2014-11-26 10:43:58 +00:00
Daniel Jasper
79f226e780
clang-format: Make short case labels work with #ifs
...
Before:
switch (a) {
#if FOO
case 0: return 0; #endif
}
After:
switch (a) {
#if FOO
case 0: return 0;
#endif
}
This fixed llvm.org/PR21544.
llvm-svn: 222642
2014-11-23 21:45:03 +00:00
Daniel Jasper
bb86d847ba
clang-format: Improve ObjC blocks with return type.
...
Before:
Block b = ^int * (A * a, B * b) {}
After:
Block b = ^int *(A *a, B *b) {}
This fixed llvm.org/PR21619.
llvm-svn: 222639
2014-11-23 19:15:35 +00:00
Daniel Jasper
bcb55eec3a
clang-format: Understand more lambda return types.
...
Before:
auto a = [&b, c ](D * d) -> D * {}
After:
auto a = [&b, c](D* d) -> D* {}
llvm-svn: 222534
2014-11-21 14:08:38 +00:00
Daniel Jasper
4b444495ed
clang-format: Use nested block special case for all languages.
...
Previously this was only used for JavaScript.
Before:
functionCall({
int i;
int j;
},
aaaa, bbbb, cccc);
After:
functionCall({
int i;
int j;
}, aaaa, bbbb, cccc);
llvm-svn: 222531
2014-11-21 13:38:53 +00:00
Daniel Jasper
d081e88e79
clang-format: Handle comments in short case labels.
...
With AllowShortCaseLabelsOnASingleLine set to true:
This gets now left unchanged:
case 1:
// comment
return;
Whereas before it was changed into:
case 1: // comment return;
This fixes llvm.org/PR21630.
llvm-svn: 222529
2014-11-21 12:36:25 +00:00
Daniel Jasper
3aa9a6a126
clang-format: Add option to disable alignment after opening brackets
...
Before:
SomeFunction(parameter,
parameter);
After:
SomeFunction(parameter,
parameter);
Patch by Harry Terkelsen, thank you!
llvm-svn: 222284
2014-11-18 23:55:27 +00:00
Daniel Jasper
e1e348b857
clang-format: Fix more incorrect pointer detection.
...
Before:
Constructor() : a(a), b(c, d *e) {}
After:
Constructor() : a(a), b(c, d * e) {}
llvm-svn: 222158
2014-11-17 18:42:22 +00:00
Daniel Jasper
6a3fd8361f
clang-format: Fix regression introduced in r221609.
...
Before:
void f() { f(a, c *d); }
After:
void f() { f(a, c * d); }
llvm-svn: 222128
2014-11-17 13:55:04 +00:00
Daniel Jasper
d127e3b6af
clang-format: Correctly detect multiplication in ctor initializer.
...
Before:
Constructor() : a(a), area(width *height) {}
After:
Constructor() : a(a), area(width * height) {}
llvm-svn: 222010
2014-11-14 17:26:49 +00:00
Daniel Jasper
6c0ee17b89
clang-format: Improve function parameter packing.
...
Before:
void SomeLoooooooooooongFunction(
std::unique_ptr<aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>
aaaaaaaaaaaaaaaaaaaaaaaaaa, int bbbbbbbbbbbbb);
After:
void SomeLoooooooooooongFunction(
std::unique_ptr<aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>
aaaaaaaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbb);
llvm-svn: 221989
2014-11-14 13:14:45 +00:00
Daniel Jasper
6c22c44e12
clang-format: Support assignments as conditional operands.
...
Before:
return a != b
// comment
? a
: a = a != b
// comment
? a =
b : a;
After:
return a != b
// comment
? a
: a = a != b
// comment
? a = b
: a;
llvm-svn: 221987
2014-11-14 13:03:40 +00:00
Daniel Jasper
119ff533e4
clang-format: Improve indentation of comments in expressions.
...
Before:
int i = (a)
// comment
+ b;
return aaaa == bbbb
// comment
? aaaa
: bbbb;
After:
int i = (a)
// comment
+ b;
return aaaa == bbbb
// comment
? aaaa
: bbbb;
llvm-svn: 221985
2014-11-14 12:31:14 +00:00
Nico Weber
34272657de
clang-format: Format extern "C" blocks like namespace blocks.
...
namespace blocks act as if KeepEmptyLinesAtTheStartOfBlocks is always true,
and aren't collapsed to a single line even if they would fit. Do the same
for extern "C" blocks.
Before,
extern "C" {
void ExternCFunction();
}
was collapsed into `extern "C" { void ExternCFunction(); }`. Now it stays like
it was.
Fixes http://crbug.com/432640 and part of PR21419.
llvm-svn: 221897
2014-11-13 16:25:37 +00:00
Daniel Jasper
3eb341c478
clang-format: Improve handling of comments in binary expressions.
...
Before:
b = a &&
// Comment
b.c &&
d;
After:
b = a &&
// Comment
b.c && d;
This fixes llvm.org/PR21535.
llvm-svn: 221727
2014-11-11 23:04:51 +00:00
Daniel Jasper
64a328e96f
clang-format: Preserve trailing-comma logic even with comments.
...
Before:
vector<int> SomeVector = {// aaa
1, 2,
};
After:
vector<int> SomeVector = {
// aaa
1, 2,
};
llvm-svn: 221699
2014-11-11 19:34:57 +00:00
Daniel Jasper
0bd9a19b28
clang-format: Fix pointer formatting.
...
Before:
void f(Bar* a = nullptr, Bar * b);
After:
void f(Bar* a = nullptr, Bar* b);
llvm-svn: 221609
2014-11-10 16:57:30 +00:00
Daniel Jasper
e551bb70a3
Revert "clang-format: [js] Updates to Google's JavaScript style."
...
This reverts commit eefd2eaad43c5c2b17953ae7ed1e72b28e696f7b.
Apparently, this change was a bit premature.
llvm-svn: 221365
2014-11-05 17:22:31 +00:00
Daniel Jasper
502fac38e9
clang-format: Add test to prevent regression in r221125.
...
llvm-svn: 221339
2014-11-05 10:55:36 +00:00
Daniel Jasper
680b09ba88
clang-format: Improve free-standing macro detection.
...
Before:
SOME_WEIRD_LOG_MACRO
<< "Something long enough to cause a line break";
After:
SOME_WEIRD_LOG_MACRO
<< "Something long enough to cause a line break";
llvm-svn: 221338
2014-11-05 10:48:04 +00:00
Daniel Jasper
8022226db7
clang-format: Fix false positive in lambda detection.
...
Before:
delete [] a -> b;
After:
delete[] a->b;
This fixes part of llvm.org/PR21419.
llvm-svn: 221114
2014-11-02 22:46:42 +00:00
Daniel Jasper
f739b0dbfa
clang-format: [js] Updates to Google's JavaScript style.
...
The style guide is changing..
llvm-svn: 220977
2014-10-31 17:50:40 +00:00
Daniel Jasper
ac29eaccd2
clang-format: Format line if invoked on the trailing newline.
...
llvm-svn: 220883
2014-10-29 23:40:50 +00:00
Daniel Jasper
f0c809a19b
clang-format: Improve && detection as binary operator.
...
Before:
template <class T,
class = typename ::std::enable_if<
::std::is_array<T>{}&& ::std::is_array<T>{}>::type>
void F();
After:
template <class T,
class = typename ::std::enable_if<
::std::is_array<T>{} && ::std::is_array<T>{}>::type>
void F();
llvm-svn: 220813
2014-10-28 18:28:22 +00:00
Daniel Jasper
acb7e25d5f
clang-format: Fix test.
...
llvm-svn: 220807
2014-10-28 18:18:02 +00:00
Daniel Jasper
13a7f469be
clang-format: Improve && detection as binary operators.
...
Before:
template <class T, class = typename std::enable_if<std::is_integral<
T>::value &&(sizeof(T) > 1 || sizeof(T) < 8)>::type>
void F();
After:
template <class T, class = typename std::enable_if<
std::is_integral<T>::value &&
(sizeof(T) > 1 || sizeof(T) < 8)>::type>
void F();
llvm-svn: 220805
2014-10-28 18:11:52 +00:00
Daniel Jasper
2ad0aba610
clang-format: Improve function declaration detection.
...
Before:
ReturnType MACRO
FunctionName() {}
After:
ReturnType MACRO
FunctionName() {}
This fixes llvm.org/PR21404.
I wonder what the motivation for that if-condition was. But as no test
breaks, ...
llvm-svn: 220801
2014-10-28 17:06:04 +00:00
Daniel Jasper
50d634b343
clang-format: [ObjC] Add separate flag to control indentation in blocks
...
Apparently, people are very much divided on what the "correct"
indentation is. So, best to give them a choice.
The new flag is called ObjCBlockIndentWidth and the default is now set
to the same value as IndentWidth for the pre-defined styles.
llvm-svn: 220784
2014-10-28 16:53:38 +00:00
Daniel Jasper
e068ac77a2
clang-format: Don't break after very short return types.
...
Before:
void
SomeFunction(int parameter);
After:
void SomeFunction(
int parameter);
(Unless AlwaysBreakAfterDefinitionReturnType after type is set).
llvm-svn: 220686
2014-10-27 17:13:59 +00:00
Daniel Jasper
5634619389
clang-format: Fix bad merging of lines in nested blocks.
...
Before:
SomeFunction([]() {
#define A a
return 43; });
After:
SomeFunction([]() {
#define A a
return 43;
});
llvm-svn: 220684
2014-10-27 16:31:46 +00:00
Daniel Jasper
f322eb5c45
clang-format: Fix incorrect space after "<".
...
Before:
bool a = 2 <::SomeFunction();
After:
bool a = 2 < ::SomeFunction();
llvm-svn: 220505
2014-10-23 20:22:22 +00:00
Daniel Jasper
76284683f1
clang-format: Use AllowShortBlocksOnASingleLine for ObjC blocks, too.
...
llvm-svn: 220375
2014-10-22 09:12:44 +00:00
Daniel Jasper
b52c69e567
clang-format: Fix broken test.
...
llvm-svn: 220374
2014-10-22 09:01:12 +00:00
Daniel Jasper
e8a4939b77
clang-format: Fix incorrect trailing return arrow detection.
...
Before:
auto doSomething(Aaaaaa* aaaaaa) -> decltype(aaaaaa -> f()) {}
After:
auto doSomething(Aaaaaa* aaaaaa) -> decltype(aaaaaa->f()) {}
llvm-svn: 220373
2014-10-22 08:42:58 +00:00
Daniel Jasper
f1f267b447
clang-format: [ObjC] Fix spacing in block variable parameters.
...
Before:
{ void (^block)(Object * x); }
After:
{ void (^block)(Object *x); }
llvm-svn: 220270
2014-10-21 07:57:50 +00:00
Daniel Jasper
38efc13191
clang-format: Fix space in direct destructor calls.
...
Before:
void F(int& i) { i. ~int(); }
After:
void F(int& i) { i.~int(); }
Also, some cleanups.
llvm-svn: 220269
2014-10-21 07:51:54 +00:00
Daniel Jasper
8835a32078
clang-format: Fix overloaded operator edge case.
...
Before:
template <class F>
void Call(F f) {
f.template operator() <int>();
}
After:
template <class F>
void Call(F f) {
f.template operator()<int>();
}
llvm-svn: 220202
2014-10-20 13:56:30 +00:00
Daniel Jasper
7858079246
clang-format: [ObjC] Fix using selector names as macro arguments.
...
Before:
[self aaaaa:MACRO(a, b :, c :)];
After:
[self aaaaa:MACRO(a, b:, c:)];
llvm-svn: 220197
2014-10-20 12:01:45 +00:00
Daniel Jasper
86296e36d7
clang-format: Fix indentation of struct definitions with array init.
...
Before:
struct {
int x;
int y;
} points[] = {
{1, 2}, {2, 3},
};
After:
struct {
int x;
int y;
} points[] = {
{1, 2}, {2, 3},
};
llvm-svn: 220195
2014-10-20 11:12:51 +00:00
Daniel Jasper
da07a72928
clang-format: Prefer breaking before trailing return arrows.
...
Before:
auto SomeFunction(
A aaaaaaaaaaaaaaaaaaaaa) const -> decltype(f(aaaaaaaaaaaaaaaaaaaaa)) {}
After:
auto SomeFunction(A aaaaaaaaaaaaaaaaaaaaa) const
-> decltype(f(aaaaaaaaaaaaaaaaaaaaa)) {}
llvm-svn: 220043
2014-10-17 14:37:40 +00:00
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
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
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
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
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
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
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
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
Daniel Jasper
4718944399
clang-format: Add special comments to disable formatting.
...
With this patch:
int ThisWillBeFormatted;
// clang-format off
int ThisWontBeFormatted;
// clang-format on
int Formatted;
This is for regions where a significantly nicer code layout can be found
knowing the content of the code.
This fixes llvm.org/PR20463.
llvm-svn: 214966
2014-08-06 13:40:26 +00:00
Daniel Jasper
316ab38ed8
clang-format: Fix indentation in multi-line placement new.
...
Before:
auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =
new (aaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaa))
typename aaaaaaaaaaaaaaaaaaaaaaaa();
After:
auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =
new (aaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaa))
typename aaaaaaaaaaaaaaaaaaaaaaaa();
llvm-svn: 214964
2014-08-06 13:14:58 +00:00
Chad Rosier
0a84f17882
[PR19983] SBPO_Always not covering all the cases.
...
Patch by "Roman Kashitsyn" <romankashicin@gmail.com>.
Phabricator revision: http://reviews.llvm.org/D4788
llvm-svn: 214904
2014-08-05 17:58:54 +00:00
Daniel Jasper
ca4ea1ce59
clang-format: Add option to always break after a function's return type.
...
This is required for GNU coding style, among others.
Also update the configuration documentation.
Modified from an original patch by Jarkko Hietaniemi, thank you!
llvm-svn: 214858
2014-08-05 12:16:31 +00:00
Daniel Jasper
d9670878d4
clang-format: Break before 'else' in Stroustrup style.
...
Seems to be the desired thing to do according to:
http://www.stroustrup.com/Programming/PPP-style-rev3.pdf
Patch by Jarkko Hietaniemi, thank you!
llvm-svn: 214857
2014-08-05 12:06:20 +00:00
Daniel Jasper
65df5aa918
clang-format: Understand parameter pack initialization.
...
Before:
Constructor(A... a) : a_(X<A> { std::forward<A>(a) }...) {}
After:
Constructor(A... a) : a_(X<A>{std::forward<A>(a)}...) {}
llvm-svn: 214720
2014-08-04 14:51:02 +00:00
Daniel Jasper
dcf37fbec5
clang-format: Add a space in ObjC protocols.
...
Before:
@interface Foo (HackStuff)<MyProtocol>
After:
@interface Foo (HackStuff) <MyProtocol>
llvm-svn: 214508
2014-08-01 13:03:05 +00:00
Manuel Klimek
45bf56cdf9
Fix parsing of classes where the class name is an absolute nested name specifier.
...
llvm-svn: 214393
2014-07-31 07:19:30 +00:00
Daniel Jasper
71646ec206
clang-format: Understand 'typename' in placement new.
...
Before:
new (aaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaa)) typename aaaaaaaaaaaaaaaaaaaaaaaa();
After:
new (aaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaa))
typename aaaaaaaaaaaaaaaaaaaaaaaa();
llvm-svn: 214300
2014-07-30 12:14:10 +00:00
Daniel Jasper
6ba1638f0b
clang-format: Improve operator and template recognition.
...
Before:
static_assert(is_convertible < A &&, B > ::value, "AAA");
After:
static_assert(is_convertible<A &&, B>::value, "AAA");
llvm-svn: 214075
2014-07-28 13:19:58 +00:00
Daniel Jasper
8184d66f4b
clang-format: Improve pointer/reference detection.
...
Before (with left pointer alignment):
void f(int i = 0, SomeType* *temps = NULL);
After:
void f(int i = 0, SomeType** temps = NULL);
llvm-svn: 214071
2014-07-28 12:24:21 +00:00
Daniel Jasper
2ac3fdfd4a
clang-format: Fix unary operator recognition.
...
Before:
int x = ~ * p;
After:
int x = ~*p;
llvm-svn: 214070
2014-07-28 12:08:16 +00:00
Daniel Jasper
8b76d608b8
clang-format: Fix formatting of lock annotations in lambda definitions.
...
Before:
SomeFunction([](int i)LOCKS_EXCLUDED(a) {});
After:
SomeFunction([](int i) LOCKS_EXCLUDED(a) {});
llvm-svn: 214069
2014-07-28 12:08:06 +00:00
Daniel Jasper
fc3861ac48
clang-format: Fix parsing of conditional expressions.
...
Before:
aaaaaa = aaaaaaaaaaaa ? aaaaaaaaaa ? aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
: aaaaaaaaaaaaaaaaaaaaaa
: aaaaaaaaaaaaaaaaaaaaaaaaaaaa;
After:
aaaaaa = aaaaaaaaaaaa
? aaaaaaaaaa ? aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
: aaaaaaaaaaaaaaaaaaaaaa
: aaaaaaaaaaaaaaaaaaaaaaaaaaaa;
llvm-svn: 213258
2014-07-17 12:22:04 +00:00
Daniel Jasper
fcfac10c8a
clang-format: Improve heuristic around avoiding bad line breaks.
...
Now, this can be properly formatted:
static_cast<A< //
B> *>( //
);
Before, clang-format could end up, not formatting the code at all.
llvm-svn: 213055
2014-07-15 09:00:34 +00:00
Daniel Jasper
3064620d0d
clang-format: Improve cast detection (fix false positive).
...
Before:
fn(a)(b)+1;
After:
fn(a)(b) + 1;
llvm-svn: 212935
2014-07-14 12:38:38 +00:00
Daniel Jasper
85bcadcdc6
clang-format: Fix behavior around pointer-to-member invocations.
...
Before:
(aaaaaaaaaa->*
bbbbbbb)(aaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa));
After:
(aaaaaaaaaa->*bbbbbbb)(
aaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaa));
llvm-svn: 212617
2014-07-09 13:07:57 +00:00
Daniel Jasper
c75e1effed
clang-format: Add new option to indent wrapped function declarations.
...
Though not completely identical, make former
IndentFunctionDeclarationAfterType change this flag for backwards
compatibility (it is somewhat close in meaning and better the err'ing on
an unknown config flag).
llvm-svn: 212597
2014-07-09 08:42:42 +00:00
Daniel Jasper
4355e7f0ef
clang-format: Revamp function declaration/definition indentation.
...
Key changes:
- Correctly (well ...) distinguish function declarations and variable
declarations with ()-initialization.
- Don't indent when breaking function declarations/definitions after the
return type.
- Indent variable declarations and typedefs when breaking after the
type.
This fixes llvm.org/PR17999.
llvm-svn: 212591
2014-07-09 07:50:33 +00:00
Daniel Jasper
2520fe9662
clang-format: Support member function reference qualifiers.
...
Before:
string // break
operator()() &
{}
After:
string // break
operator()() & {}
llvm-svn: 212041
2014-06-30 13:54:27 +00:00
Daniel Jasper
91beebd04a
clang-format: Improve expression heuristics.
...
Upon encountering a binary operator inside parentheses, assume that the
parentheses contain an expression.
Before:
MACRO('0' <= c&& c <= '9');
After:
MACRO('0' <= c && c <= '9');
llvm-svn: 212040
2014-06-30 13:44:47 +00:00
Daniel Jasper
a2fb50f9b3
clang-format: Understand that breaking before lambdas is fine.
...
Before:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa([](
const aaaaaaaaaa &a) { return a; });
After:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
[](const aaaaaaaaaa &a) { return a; });
llvm-svn: 211575
2014-06-24 09:15:49 +00:00
Daniel Jasper
32ccb03871
clang-format: Fix corner case in pointer/reference detection.
...
llvm-svn: 211487
2014-06-23 07:36:18 +00:00
Daniel Jasper
553d4878da
clang-format: Introduce style with spaces on both sides of */&.
...
Patch by Janusz Sobczak (slightly extended).
This fixes llvm.org/19929.
llvm-svn: 211098
2014-06-17 12:40:34 +00:00
Rafael Espindola
1f24317d87
Fix msvc unittest build.
...
Looks like msvc has an asymmetrical operator ==.
llvm-svn: 210768
2014-06-12 11:35:17 +00:00
Rafael Espindola
d0136707a9
Give clang-format its own error category.
...
The posix errno values are probably to the best thing to use for
describing parse errors.
This should also fix the mingw build.
llvm-svn: 210739
2014-06-12 02:50:04 +00:00
Rafael Espindola
96b033006d
Use std::error_code instead of llvm::error_code.
...
This is an update for a llvm api change.
llvm-svn: 210688
2014-06-11 19:05:55 +00:00
Daniel Jasper
4ac7de7199
clang-format: Fix pointer/reference detection after decltype.
...
Before:
[](const decltype(*a) & value) {}
After:
[](const decltype(*a)& value) {}
llvm-svn: 210643
2014-06-11 07:35:16 +00:00
Daniel Jasper
ecaba17996
clang-format: Increase penalty for wrapping array subscript expressions
...
Before:
aaaaaaaaaaa aaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaa->aaaaaaaaa[0].aaaaaaa
[0].aaaaaaaaaaaaaaaaaaaaaa();
After:
aaaaaaaaaaa aaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaa->aaaaaaaaa[0]
.aaaaaaa[0]
.aaaaaaaaaaaaaaaaaaaaaa();
llvm-svn: 210529
2014-06-10 13:27:57 +00:00
Daniel Jasper
908180574e
clang-format: Fix enum formatting with specific comment.
...
Before:
enum Fruit { //
APPLE,
PEAR };
After:
enum Fruit { //
APPLE,
PEAR
};
llvm-svn: 210522
2014-06-10 10:42:26 +00:00
Daniel Jasper
da18fd86c7
clang-format: Support variadic lambda captures.
...
Before:
return [ i, args... ]{};
After:
return [i, args...] {};
llvm-svn: 210514
2014-06-10 06:39:03 +00:00
Daniel Jasper
3251fff0e3
clang-format: Handle multiline strings inside ternary expressions.
...
With AlwaysSplitBeforeMultilineStrings, clang-format would not find any
valid solution.
llvm-svn: 210513
2014-06-10 06:27:23 +00:00
Daniel Jasper
a69ca9be12
clang-format: Leave empty lines within UnwrappedLines.
...
These are commonly used to structure things like enums or long braced
lists. There doesn't seem to be a good reason to have the behavior in
such structures be different from the behavior between statements.
llvm-svn: 210183
2014-06-04 12:40:57 +00:00
Daniel Jasper
7d028298ce
clang-format: Fix special case of binary operator detection.
...
There is a pattern where evaluation order is used as control flow.
This patch special-cases a commonly occuring version of this pattern.
Before:
Aaaaa *aaa = nullptr;
// ...
aaa &&aaa->f();
After:
Aaaaa *aaa = nullptr;
// ...
aaa && aaa->f();
llvm-svn: 210017
2014-06-02 11:54:20 +00:00
Daniel Jasper
4afc6b3e16
clang-format: No space between ")" and braced init list.
...
Before:
auto j = decltype(i) {};
After:
auto j = decltype(i){};
This fixes llvm.org/PR19892.
llvm-svn: 210013
2014-06-02 10:57:55 +00:00
Daniel Jasper
e18ff37e08
clang-format: Fix Allman brace breaking of enums.
...
Before:
enum Side
{ LEFT,
RIGHT };
After:
enum Side
{
LEFT,
RIGHT
};
This fixes llvm.org/PR19911.
llvm-svn: 210011
2014-06-02 10:17:32 +00:00
Daniel Jasper
e3f907fded
clang-format: Fix trailing const (etc.) with Allman brace style.
...
Before:
void someLongFunction(int someLongParameter)
const
{
}
After:
void someLongFunction(
int someLongParameter) const
{
}
This fixes llvm.org/PR19912.
llvm-svn: 210010
2014-06-02 09:52:08 +00:00
Rafael Espindola
3ae0620a45
There is no std::errc:success, remove the llvm one.
...
llvm-svn: 209959
2014-05-31 03:20:52 +00:00
Daniel Jasper
d39312ec84
clang-format: Don't break before a case's colon.
...
Before (with just the right line length:
switch (a) {
case some_namespace::some_constant
:
return;
}
After:
switch (a) {
case some_namespace::
some_constant:
return;
}
llvm-svn: 209725
2014-05-28 10:09:11 +00:00
Daniel Jasper
335ff26631
clang-format: Format array and dict literals similar to blocks.
...
Especially, reduce the amount of indentation if it doesn't increase
readability.
Before:
NSMutableDictionary* dictionary = [NSMutableDictionary
dictionaryWithDictionary:@{
aaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaa,
bbbbbbbbbbbbbbbbbb : bbbbb,
cccccccccccccccc : ccccccccccccccc
}];
After:
NSMutableDictionary* dictionary =
[NSMutableDictionary dictionaryWithDictionary:@{
aaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaa,
bbbbbbbbbbbbbbbbbb : bbbbb,
cccccccccccccccc : ccccccccccccccc
}];
llvm-svn: 209720
2014-05-28 09:11:53 +00:00
Daniel Jasper
ba1b6bb667
clang-format: Keep '{' of dict literals on the same line in Allman style
...
Before:
void f()
{
[object
someMethod:@
{ @"a" : @"b" }];
}
After:
void f()
{
[object someMethod:@{ @"a" : @"b" }];
}
This fixes llvm.org/PR19854.
llvm-svn: 209615
2014-05-26 07:24:34 +00:00
Daniel Jasper
565ed5ed08
clang-format: Don't use Allman brace breaking for ObjC blocks.
...
It just seems wrong. This fixes llvm.org/PR19736.
llvm-svn: 209440
2014-05-22 13:53:55 +00:00
Daniel Jasper
bd630737bd
clang-format: Fix corner case in AllowShortBlocksOnASingleLine.
...
Before:
template <int> struct A4 { A4() { }
};
After:
template <int i> struct A4 {
A4() {}
};
This fixes llvm.org/PR19813 (at least the part that isn't working as
intended).
llvm-svn: 209438
2014-05-22 13:25:26 +00:00
Daniel Jasper
91b032ab55
clang-format: Fix braced list detection.
...
Before:
static_assert(std::is_integral<int> {} + 0, "");
int a = std::is_integral<int> {}
+ 0;
After:
static_assert(std::is_integral<int>{} + 0, "");
int a = std::is_integral<int>{} + 0;
llvm-svn: 209431
2014-05-22 12:46:38 +00:00
Daniel Jasper
438059e509
clang-format: Fix incorrect braced init identification.
...
Before:
int foo(int i) {
return fo1 {}
(i);
}
int foo(int i) {
return fo1 {}
(i);
}
After:
int foo(int i) { return fo1{}(i); }
int foo(int i) { return fo1{}(i); }
This fixes llvm.org/PR19812.
llvm-svn: 209428
2014-05-22 12:11:13 +00:00
Daniel Jasper
3948516a03
clang-format: Correctly identify multiplications in braces init lists.
...
Before:
int i{a *b};
After:
int i{a * b};
Also fix unrelated issue where braced init lists were counted as blocks
and prevented single-line functions.
llvm-svn: 209412
2014-05-22 09:00:33 +00:00
Daniel Jasper
5f3ea477cf
clang-format: Correctly calculate line lenghts for nest blocks.
...
If simple (one-statement) blocks can be inlined, the length needs to be
calculated correctly.
Before (in JavaScript but this also affects lambdas, etc.):
var x = {
valueOf: function() { return 1; }
};
After:
var x = {valueOf: function() { return 1; }};
llvm-svn: 209410
2014-05-22 08:36:53 +00:00
Daniel Jasper
5ebb2f3625
clang-format: Fix incorrect macro call detection.
...
In:
struct A {
A()
noexcept(....) {}
};
'A()' is not a macro call.
This fixes llvm.org/PR19814.
llvm-svn: 209294
2014-05-21 13:08:17 +00:00
Daniel Jasper
7f0c517168
clang-format: Don't force line breaks in ObjC calls with ColumnLimit 0.
...
Before:
[self.x a:b c:d];
Got reformatted toi (with ColumnLimit set to 0):
[self.x a:b
c:d];
llvm-svn: 209114
2014-05-19 08:06:34 +00:00
Daniel Jasper
17605d3961
clang-format: Add option to allow short blocks on a single line.
...
With AllowShortBlocksOnASingleLine, clang-format allows:
if (a) { return; }
Based on patch by Gonzalo BG, thank you!
llvm-svn: 208765
2014-05-14 09:33:35 +00:00
Daniel Jasper
0a1e5ace26
clang-format: Don't break in the middle of ">>".
...
Before:
zzzzzzzzzz = bbbbbbbbbbbbbbbbb >
> aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa);
After:
zzzzzzzzzz
= bbbbbbbbbbbbbbbbb
>> aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa);
This fixes llvm.org/PR19731.
llvm-svn: 208672
2014-05-13 08:01:47 +00:00
Daniel Jasper
04a71a45ff
clang-format: Initial support for try-catch.
...
Most of this patch was created by Alexander Rojas in
http://reviews.llvm.org/D2555
Thank you!
Synced and addressed review comments.
llvm-svn: 208302
2014-05-08 11:58:24 +00:00
Daniel Jasper
ea2d042f89
clang-format: Fix binary operator detection before lambdas.
...
Before:
bool foo = true&& [] { return false; }();
After:
bool foo = true && [] { return false; }();
llvm-svn: 208288
2014-05-08 08:50:10 +00:00
Nikola Smiljanic
e08a91ecd2
Enable alternative tokens by default for clang-format.
...
Patch by Bobby Moretti.
llvm-svn: 208269
2014-05-08 00:05:13 +00:00
Daniel Jasper
8acf822b6f
clang-format: Fix corner cases for comments in if conditions.
...
Before:
if ( // a
x + 3) { ..
After:
if ( // a
x + 3) { ..
llvm-svn: 208175
2014-05-07 09:23:05 +00:00
Daniel Jasper
7a2d60e328
clang-format: Fix bad space before braced initializer.
...
Before:
new int {1};
After:
new int{1};
llvm-svn: 208168
2014-05-07 07:59:03 +00:00
Dinesh Dwivedi
2e92e66f66
Fixed one issue with casting
...
Before:
(void) SimplifyICmpOperands(Cond, LHS, RHS);
After:
(void)SimplifyICmpOperands(Cond, LHS, RHS);
Differential Revision: http://reviews.llvm.org/D3615
llvm-svn: 208080
2014-05-06 11:46:49 +00:00
Daniel Jasper
f10a28d705
clang-format: Understand functions with decltype return type.
...
Before:
decltype(long_name_forcing_break)
f() {}
After:
decltype(long_name_forcing_break)
f() {}
llvm-svn: 207965
2014-05-05 13:48:09 +00:00
Dinesh Dwivedi
76f98f8047
Added some heuristics to identify c style casting
...
Before:
void f() { my_int a = (my_int) * b; }
void f() { return P ? (my_int) * P : (my_int)0; }
After:
void f() { my_int a = (my_int)*b; }
void f() { return P ? (my_int)*P : (my_int)0; }
Differential Revision: http://reviews.llvm.org/D3576
llvm-svn: 207964
2014-05-05 13:14:35 +00:00
Daniel Jasper
0e6c51c889
clang-format: Improve understanding of decltype.
...
Before:
SomeFunction([](decltype(x), A * a) {});
After:
SomeFunction([](decltype(x), A *a) {});
llvm-svn: 207961
2014-05-05 12:36:29 +00:00
Dinesh Dwivedi
afe6fb6f05
Fix bug in clang-format while merging short function
...
Before:
#ifdef _DEBUG
int foo( int i = 0 )
#else
int foo( int i = 5 )
#endif { return i; }
After:
#ifdef _DEBUG
int foo( int i = 0 )
#else
int foo( int i = 5 )
#endif
{
return i;
}
llvm-svn: 207958
2014-05-05 11:36:35 +00:00
Daniel Jasper
9509f18836
clang-format: Fix import statements with ColumnLimit: 0
...
These used to interact badly with AlwaysBreakBeforeMultilineStrings.
llvm-svn: 207955
2014-05-05 08:08:07 +00:00
Dinesh Dwivedi
ea3aca8b67
Fixes issue with Allman BreakBeforeBraces for Objective C @interface
...
Before:
@interface BSApplicationController () {
@private
id _extraIvar;
}
@end
After:
@interface BSApplicationController ()
{
@private
id _extraIvar;
}
@end
llvm-svn: 207849
2014-05-02 17:01:46 +00:00
Daniel Jasper
35995679c6
clang-format: Allow single-line function in WebKit style.
...
Before:
void f() {
return; }
After:
void f() { return; }
llvm-svn: 207527
2014-04-29 14:05:20 +00:00
Daniel Jasper
942d971c84
clang-format: Improve binary operator detection.
...
Before:
*(int *)(p &~3UL) = 0;
After:
*(int *)(p & ~3UL) = 0;
This fixes llvm.org/PR19464.
llvm-svn: 207405
2014-04-28 09:19:28 +00:00
Daniel Jasper
031e2409f9
clang-format: Fixes spaces in case statements.
...
This fixes llvm.org/PR19482.
Before:
switch (a) {
case(B) :
return;
}
After:
switch (a) {
case (B):
return;
}
llvm-svn: 207402
2014-04-28 07:48:36 +00:00
Daniel Jasper
437c3f5188
clang-format: Don't wrap after @interface.
...
This fixes llvm.org/PR19450.
Before:
@interface
BookmarkHomeHandsetViewController ()<BookmarkAllCollectionViewDelegate,
BookmarkFolderCollectionViewDelegate,
BookmarkMenuViewControllerDelegate,
BookmarkSearchViewControllerDelegate> {
}
After:
@interface aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ()<
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> {
}
llvm-svn: 207400
2014-04-28 07:34:48 +00:00
Daniel Jasper
66935020c4
clang-format: Fix bug when aligning trailing /**/-comments in macros.
...
Previously this could lead to a column limit violation with the
required escaped newlines.
llvm-svn: 207351
2014-04-27 10:03:19 +00:00
Chandler Carruth
1034666777
[Modules] Fix potential ODR violations by sinking the DEBUG_TYPE
...
definition below all of the header #include lines, clang edition.
If you want more details about this, you can see some of the commits to
Debug.h in LLVM recently. This is just the clang section of a cleanup
I've done for all uses of DEBUG_TYPE in LLVM.
llvm-svn: 206849
2014-04-22 03:17:02 +00:00
Alexander Kornienko
67d9c8c87e
Fix alignment of trailing block comments.
...
Summary:
This patch ensures that the lines of the block comments retain relative
column offsets. In order to do this WhitespaceManager::Changes representing
continuation of block comments keep a pointer on the change representing the
whitespace change before the block comment, and a relative column offset to this
change, so that the correct column can be reconstructed at the end of alignment
process.
Fixes http://llvm.org/PR19325
Reviewers: djasper
Reviewed By: djasper
CC: cfe-commits, klimek
Differential Revision: http://reviews.llvm.org/D3408
llvm-svn: 206472
2014-04-17 16:12:46 +00:00
Daniel Jasper
ae8e0d8da9
clang-format: Respect BinPackParameters in Cpp11BracedListStyle.
...
With BinPackParameters=false and Cpp11BracedListStyle=true (i.e. mostly
for Chromium):
Before:
const Aaaaaa aaaaa = {aaaaa, bbbbb, ccccc, ddddd, eeeee, ffffff,
ggggg, hhhhhh, iiiiii, jjjjjj, kkkkkk};
After:
const Aaaaaa aaaaa = {aaaaa,
bbbbb,
ccccc,
ddddd,
eeeee,
ffffff,
ggggg,
hhhhhh,
iiiiii,
jjjjjj,
kkkkkk};
This fixes llvm.org/PR19359. I am not sure we'll want this in all cases
in the long run, but I'll guess we'll get feedback on that.
llvm-svn: 206458
2014-04-17 11:32:02 +00:00
Daniel Jasper
0e61784ae5
clang-format: Add special case to reduce indentaiton in streams.
...
This is similar to how we treat assignments and seems to be generally
desirable.
Before:
llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaa);
After:
llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaa);
llvm-svn: 206384
2014-04-16 12:26:54 +00:00
Alexander Kornienko
64a42b8dd2
Fix assertion when breaking string literals with tab characters.
...
Summary: Fixes http://llvm.org/PR19368
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://reviews.llvm.org/D3379
llvm-svn: 206295
2014-04-15 14:52:43 +00:00
Daniel Jasper
20fd3c6ff7
clang-format: Basic support for C++1y.
...
Before:
int bi{1 '000' 000};
After:
int bi{1'000'000};
This fixes llvm.org/PR19342.
llvm-svn: 206263
2014-04-15 08:49:21 +00:00
Daniel Jasper
866468ae4d
clang-format: Fix regression caused by r206165.
...
llvm-svn: 206173
2014-04-14 13:15:29 +00:00
Daniel Jasper
72ab43b28b
clang-format: Fix incorrect &&-detection in macros.
...
Before:
#define A(a, b) (a &&b)
After:
#define A(a, b) (a && b)
This fixes llvm.org/PR19343.
llvm-svn: 206165
2014-04-14 12:50:02 +00:00
Daniel Jasper
db8804b32b
clang-format: Improve array literal formatting fix in r206161.
...
Instead of choosing based on the number of elements, simply respect the
user's choice of where to wrap array literals.
llvm-svn: 206162
2014-04-14 12:11:07 +00:00
Daniel Jasper
af4fee2636
clang-format: With ColumnLimit=0, keep short array literals on a line.
...
Before:
NSArray* a = [[NSArray alloc] initWithArray:@[
@"a"
]
copyItems:YES];
After:
NSArray* a = [[NSArray alloc] initWithArray:@[ @"a" ]
copyItems:YES];
This fixed llvm.org/PR19080.
llvm-svn: 206161
2014-04-14 12:05:05 +00:00
Daniel Jasper
c0d606a584
clang-format: Don't allow hanging indentation for operators on new lines
...
Before:
if (aaaaaaaa && bbbbbbbbbbbbbbb // need to wrap
== cccccccccccccc) ...
After:
if (aaaaaaaa
&& bbbbbbbbbbbbbbb // need to wrap
== cccccccccccccc) ...
The same rule has already be implemented for BreakBeforeBinaryOperators
set to false in r205527.
llvm-svn: 206159
2014-04-14 11:08:45 +00:00
Manuel Klimek
68b03049e0
Format code around VCS conflict markers.
...
Now correctly formats:
{
int a;
void f() {
callme(some(parameter1,
<<<<<<< text by the vcs
parameter2),
||||||| text by the vcs
parameter2),
parameter3,
======= text by the vcs
parameter2, parameter3),
>>>>>>> text by the vcs
otherparameter);
}
}
llvm-svn: 206157
2014-04-14 09:14:11 +00:00
Daniel Jasper
35ec2b244a
clang-format: Improve formatting of annotated variables.
...
Before:
bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(
aaaaaaaaaaaa) = aaaaaaaa::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
After:
bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa) =
aaaaaaaa::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
llvm-svn: 206155
2014-04-14 08:15:20 +00:00
Daniel Jasper
f9fc215f82
clang-format: Treat a trailing comment like a trailing comma in braced lists.
...
Before:
static StructInitInfo module = {MODULE_BUILTIN, /* type */
"streams" /* name */
};
After:
static StructInitInfo module = {
MODULE_BUILTIN, /* type */
"streams" /* name */
};
This fixes llvm.org/PR19378.
llvm-svn: 205851
2014-04-09 13:18:49 +00:00
Daniel Jasper
21397a3232
clang-format: Fix bug where clang-format would break the code.
...
Before, it would turn:
SomeFunction([]() { // Cool function..
return 43;
});
Into this:
SomeFunction([]() { // Cool function.. return 43; });
llvm-svn: 205849
2014-04-09 12:21:48 +00:00
Daniel Jasper
3ae6f5a47b
clang-format: Improve format of calls with several lambdas.
...
Before:
SomeFunction([]() {
int i = 42;
return i;
},
[]() {
int j = 43;
return j;
});
After:
SomeFunction([]() {
int i = 42;
return i;
},
[]() {
int j = 43;
return j;
});
llvm-svn: 205848
2014-04-09 12:08:39 +00:00
Daniel Jasper
f9a0906b98
clang-format: Allow breaking between trailing annotations in more cases.
...
Before:
void aaaaaaaaaaaaaa(aaaaaaaa aaa) override AAAAAAAAAAAAAAAAAAAAAAAA(
aaaaaaaaaaaaaaa);
After:
void aaaaaaaaaaaaaa(aaaaaaaa aaa) override
AAAAAAAAAAAAAAAAAAAAAAAA(aaaaaaaaaaaaaaa);
llvm-svn: 205846
2014-04-09 10:29:11 +00:00
Daniel Jasper
b48d3afcd5
clang-format: Keep more trailing annotations on the same line.
...
More precisely keep all short annotations (<10 characters) on the same
line if possible. Previously, clang-format would only prefer to do so
for "const", "override" and "final". However, it seems to be generally
preferable, especially because some codebases have to wrap those in
macros for backwards compatibility.
Before:
void someLongFunction(int someLongParameter)
OVERRIDE {}
After:
void someLongFunction(
int someLongParameter) OVERRIDE {}
This fixes llvm.org/PR19363.
llvm-svn: 205845
2014-04-09 10:01:49 +00:00
Daniel Jasper
b175d57edc
clang-format: Recognize lists ending in trailing commas correctly.
...
Previously, this did not look through trailing comments leading to a few
formatting oddities.
llvm-svn: 205843
2014-04-09 09:53:23 +00:00
Daniel Jasper
b77105d2ce
clang-format: Fix incorrect multi-block-parameter computation.
...
llvm-svn: 205763
2014-04-08 14:04:31 +00:00
Daniel Jasper
139d4a3875
clang-format: Correctly understand arrays of pointers.
...
Before:
A<int * []> a;
After:
A<int *[]> a;
This fixes llvm.org/PR19360.
llvm-svn: 205761
2014-04-08 13:07:41 +00:00
Daniel Jasper
d74cf40386
clang-format: Extend AllowShortFunctions.. to only merge inline functions.
...
Before AllowShortFunctionsOnASingleLine could either be true, merging
all functions, or false, merging no functions. This patch adds a third
value "Inline", which can be used to only merge short functions defined
inline in a class, i.e.:
void f() {
return 42;
}
class C {
void f() { return 42; }
};
llvm-svn: 205760
2014-04-08 12:46:38 +00:00
Daniel Jasper
922349cdba
clang-format: Don't merge simple blocks in case statements.
...
Before:
switch (a) {
case 1: { return 'a'; }
}
After:
switch (a) {
case 1: {
return 'a';
}
}
llvm-svn: 205611
2014-04-04 06:46:23 +00:00
Daniel Jasper
5c33265c9e
clang-format: Prefer an additional line-break over hanging indent.
...
Don't allow the RHS of an operator to be split over multiple
lines unless there is a line-break right after the operator.
Before:
if (aaaa && bbbbb || // break
cccc) {
}
After:
if (aaaa &&
bbbbb || // break
cccc) {
}
In most cases, this seems to increase readability.
llvm-svn: 205527
2014-04-03 12:00:33 +00:00
Daniel Jasper
cc7bf7fda1
clang-format: Understand that "auto" is a type.
...
Before:
MACRO(auto * a);
After:
MACRO(auto *a);
llvm-svn: 205517
2014-04-03 09:00:49 +00:00
Aaron Ballman
2b9036d54d
Fixing the MSVC 2012 build bot, which cannot do initializer lists yet. Amends r205307.
...
llvm-svn: 205325
2014-04-01 16:30:35 +00:00
Daniel Jasper
e1e4319ab7
clang-format: Support configurable list of foreach-macros.
...
This fixes llvm.org/PR17242.
Patch by Brian Green, thank you!
llvm-svn: 205307
2014-04-01 12:55:11 +00:00
Daniel Jasper
03b1bc7a2a
clang-format: Fix aligning of comments and escaped newlines in macros.
...
Before:
#define A \
int i; /*a*/ \
int jjj; /*b*/
After:
#define A \
int i; /*a*/ \
int jjj; /*b*/
llvm-svn: 205011
2014-03-28 15:06:01 +00:00
Daniel Jasper
395193c7a0
clang-format: Recognize more ObjC blocks with parameters/return type.
...
llvm-svn: 204990
2014-03-28 07:48:59 +00:00
Manuel Klimek
1f9d80ac66
Improve handling of bool expressions in template arguments.
...
Now correctly formats:
foo<true && false>();
llvm-svn: 204950
2014-03-27 19:00:52 +00:00
Daniel Jasper
5d2587daa2
clang-format: Avoid line-breaks that increase the current column.
...
While these might make sense for some rule (e.g. break after multi-line
operand), they generally appear ugly and confusing.
Before:
fffffffffff(R\"x(
multiline raw string literal xxxxxxxxxxxxxx
)x\" + bbbbbb)
After:
fffffffffff(R\"x(
multiline raw string literal xxxxxxxxxxxxxx
)x\" +
bbbbbb)
llvm-svn: 204937
2014-03-27 16:14:13 +00:00
Manuel Klimek
f81e5c0e50
Fix bool expression special case.
...
Clang-format now correctly formats:
some_type<a * b> v;
template <bool a, bool b> typename enabled_if<a && b>::type f() {}
llvm-svn: 204913
2014-03-27 11:17:36 +00:00
Daniel Jasper
c13ee34378
clang-format: Correctly identify ObjC Block with return type.
...
llvm-svn: 204905
2014-03-27 09:43:54 +00:00
Daniel Jasper
a65e887587
clang-format: Fix incorrect &/* detection.
...
Before:
STATIC_ASSERT((a &b) == 0);
After:
STATIC_ASSERT((a & b) == 0);
llvm-svn: 204709
2014-03-25 10:52:45 +00:00
Daniel Jasper
a26fc5c9db
clang-format: Add flag for removing empty lines at the start of blocks.
...
This unbreaks polly-formatting-tests and we can make a decision for
LLVM style independently.
llvm-svn: 204467
2014-03-21 13:43:14 +00:00
Daniel Jasper
01b35482e5
clang-format: Don't remove empty lines at the start of namespaces.
...
llvm-svn: 204462
2014-03-21 13:03:33 +00:00
Daniel Jasper
11164bdaf5
clang-format: Remove empty lines at the beginning of blocks.
...
They very rarely aid readability.
Formatting:
void f() {
if (a) {
f();
}
}
Now leads to:
void f() {
if (a) {
f();
}
}
llvm-svn: 204460
2014-03-21 12:58:53 +00:00
Daniel Jasper
a125d53a7b
clang-format: Let a trailing comma in braced lists enforce linebreaks.
...
Before:
vector<int> x{1, 2, 3, 4, };
After:
vector<int> x{
1, 2, 3, 4,
};
This fixes llvm.org/PR18519.
llvm-svn: 204458
2014-03-21 12:38:57 +00:00
Daniel Jasper
28df0a356e
clang-format: Fix for r204456.
...
llvm-svn: 204457
2014-03-21 12:15:40 +00:00
Daniel Jasper
14e58e5290
clang-format: Preserve meaning of trailing comments on parameters.
...
Formatting:
SomeFunction(a,
b, // comment
c);
Before:
SomeFunction(a, b, // comment
c);
After:
SomeFunction(a,
b, // comment
c);
llvm-svn: 204456
2014-03-21 11:58:45 +00:00
Alexander Kornienko
ce08126733
clang-format: Detect function-like macros only when upper case is used.
...
Reviewers: djasper
Reviewed By: djasper
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D3110
llvm-svn: 204156
2014-03-18 14:35:20 +00:00
Manuel Klimek
819788da83
Fix crasher bug.
...
Due to not resetting the fake rparen data on the token when iterating
over annotated lines, we would pop the last element of the paren stack.
This patch fixes the underlying root cause, and makes the code more
robust against similar problems in the future:
- reset the first token when iterating on the same annotated lines due
to preprocessor branches
- never pop the last element from the paren stack, so we do not crash,
but rather incorrectly format
- add assert()s so we can figure out if our assumptions are violated
llvm-svn: 204140
2014-03-18 11:22:45 +00:00
Daniel Jasper
1fd6f1f8d6
clang-format: Indent from dict literal labels.
...
Before:
@{
NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :
regularFont,
};
After:
@{
NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :
regularFont,
};
llvm-svn: 204041
2014-03-17 14:32:47 +00:00
Daniel Jasper
ac7e34e778
clang-format: Prevent ObjC code from confusing the braced-init detection
...
This was leading to bad formatting, e.g.:
Before:
f(^{
@autoreleasepool {
if (a) {
g();
}
}
});
After:
f(^{
@autoreleasepool {
if (a) {
g();
}
}
});
llvm-svn: 203777
2014-03-13 10:11:17 +00:00
Daniel Jasper
da353cd5f1
clang-format: Fix crasher.
...
Caused by unknown tokens (e.g. "\n") not properly updating the state.
Example:
const char* c = STRINGIFY(
\na : b);
llvm-svn: 203645
2014-03-12 08:24:47 +00:00
Daniel Jasper
8f59ae537c
clang-format: Avoid unnecessary break before lambda return type.
...
Before:
auto aaaaaaaa = [](int i, // break
int j)
-> int {
return fffffffffffffffffffffffffffffffffffffff(i * j);
};
After:
auto aaaaaaaa = [](int i, // break
int j) -> int {
return fffffffffffffffffffffffffffffffffffffff(i * j);
};
llvm-svn: 203562
2014-03-11 11:03:26 +00:00
Daniel Jasper
a58dd5db29
clang-format: Fix another false positive in the lambda detection.
...
Before:
int i = (*b)[a] -> f();
After:
int i = (*b)[a]->f();
llvm-svn: 203557
2014-03-11 10:03:33 +00:00
Daniel Jasper
d3c7ab975f
clang-format: Fix incorrect lambda recognition exposed by r203452.
...
Before:
int i = a[a][a] -> f();
After:
int i = a[a][a]->f();
llvm-svn: 203556
2014-03-11 09:59:36 +00:00
Daniel Jasper
c580af96fa
clang-format: Detect weird macro lambda usage.
...
Before:
void f() {
MACRO((const AA & a) { return 1; });
}
After:
void f() {
MACRO((const AA &a) { return 1; });
}
llvm-svn: 203551
2014-03-11 09:29:46 +00:00
Daniel Jasper
84a12e18d3
clang-format: Add spaces between lambdas and comments.
...
Before:
void f() {
bar([]() {}// Does not respect SpacesBeforeTrailingComments
);
}
After:
void f() {
bar([]() {} // Does not respect SpacesBeforeTrailingComments
);
}
This fixes llvm.org/PR19017.
llvm-svn: 203466
2014-03-10 15:06:25 +00:00
Alexander Kornienko
4504f93901
Preserve hanging indent when breaking line comments.
...
Summary:
If we need to break the second line here:
// something: aaaaa aaaaa aaaaaa aaaaa aaaaa
// aaaaa aaaaa aaaaaa aaaaa aaaaa aaaaa
with the patch it will be turned to
// something: aaaaa aaaaa aaaaaa aaaaa aaaaa
// aaaaa aaaaa aaaaaa aaaaa aaaaa
// aaaaa
instead of
// something: aaaaa aaaaa aaaaaa aaaaa aaaaa
// aaaaa aaaaa aaaaaa aaaaa aaaaa
// aaaaa
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2988
llvm-svn: 203458
2014-03-10 13:14:56 +00:00
Daniel Jasper
81a20787db
clang-format: Add spaces around trailing/lambda return types.
...
Before:
int c = []()->int { return 2; }();
After:
int c = []() -> int { return 2; }();
llvm-svn: 203452
2014-03-10 10:02:02 +00:00
Alexander Kornienko
86b2dfdc3b
Fix operator<< recognition (PR19064).
...
llvm-svn: 203123
2014-03-06 15:13:08 +00:00
Chandler Carruth
f8b7266d57
[C++11] Switch the clang-format LLVM style to use C++11 style braced
...
init list formatting. This suggestion has now gone into the LLVM coding
standards, and is particularly relevant now that we're using C++11.
Updated a really ridiculous number of tests to reflect this change.
llvm-svn: 202637
2014-03-02 12:37:31 +00:00
Daniel Jasper
5550de684f
clang-format: Don't wrap "const" etc. of function declarations.
...
Generally people seem to prefer wrapping the first function parameter
over wrapping the trailing tokens "const", "override" and "final". This
does not extend to function-like annotations and probably not to other
non-standard annotations.
Before:
void someLongFunction(int SomeLongParameter)
const { ... }
After:
void someLongFunction(
int SomeLongParameter) const { ... }
llvm-svn: 201504
2014-02-17 07:57:46 +00:00
Daniel Jasper
3a122c029d
clang-format: Fix formatting of class template declaration.
...
Before:
template <class R, class C>
struct Aaaaaaaaaaaaaaaaa<R (C::*)(int)
const> : Aaaaaaaaaaaaaaaaa<R (C::*)(int)> {};
After:
template <class R, class C>
struct Aaaaaaaaaaaaaaaaa<R (C::*)(int) const>
: Aaaaaaaaaaaaaaaaa<R (C::*)(int)> {};
llvm-svn: 201424
2014-02-14 18:22:40 +00:00
Daniel Jasper
1067ab0a1a
clang-format: Support lambdas with namespace-qualified return types.
...
E.g.:
Foo([]()->std::vector<int> { return { 2 }; }());
llvm-svn: 201139
2014-02-11 10:16:55 +00:00
Daniel Jasper
a0407740c3
clang-format: Fix alignment of comments inside statements.
...
Before:
auto result = SomeObject
// Calling someFunction on SomeObject
.someFunction();
After:
auto result = SomeObject
// Calling someFunction on SomeObject
.someFunction();
llvm-svn: 201138
2014-02-11 10:08:11 +00:00
Daniel Jasper
649899685b
clang-format: Fix column limit violation for merged lines in macros.
...
Before (81 columns):
#define A \
void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() { return aaaaaaaa; } \
int i;
After:
#define A \
void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() { \
return aaaaaaaa; \
} \
int i;
llvm-svn: 200974
2014-02-07 13:45:27 +00:00
Daniel Jasper
9cc3e97685
clang-format: Fix range-based for-loop formatting.
...
Before:
for (aaaaaaaaa aaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaa.aaaaaaaaaaaa()
.aaaaaaaaa()
.a()) {
}
After:
for (aaaaaaaaa aaaaaaaaaaaaaaaaaaaaa :
aaaaaaaaaaaa.aaaaaaaaaaaa().aaaaaaaaa().a()) {
}
llvm-svn: 200968
2014-02-07 10:09:46 +00:00
Daniel Jasper
0c214fa2e3
clang-format: Don't indent relative to unary operators.
...
It seems like most people see unary operators more like part of the
subsequent identifier and find relative indentation odd.
Before:
aaaaaaaaaa(!aaaaaaaaaa( // break
aaaaa));
After:
aaaaaaaaaa(!aaaaaaaaaa( // break
aaaaa));
llvm-svn: 200840
2014-02-05 13:43:04 +00:00
Nico Weber
514ecc8ce8
clang-format: Let chromium style inherit google style's javascript tweaks.
...
llvm-svn: 200652
2014-02-02 20:50:45 +00:00
Daniel Jasper
a88f80a1be
clang-format: Support ObjC's NS_ENUMs.
...
Before:
typedef NS_ENUM(NSInteger, MyType) {
/// Information about someDecentlyLongValue.
someDecentlyLongValue,
/// Information about anotherDecentlyLongValue.
anotherDecentlyLongValue,
/// Information about aThirdDecentlyLongValue.
aThirdDecentlyLongValue};
After:
typedef NS_ENUM(NSInteger, MyType) {
/// Information about someDecentlyLongValue.
someDecentlyLongValue,
/// Information about anotherDecentlyLongValue.
anotherDecentlyLongValue,
/// Information about aThirdDecentlyLongValue.
aThirdDecentlyLongValue
};
llvm-svn: 200469
2014-01-30 14:38:37 +00:00
Manuel Klimek
14bd917470
Fix crash on unmatched #endif's.
...
The following snippet would crash:
#endif
#if A
llvm-svn: 200381
2014-01-29 08:49:02 +00:00
Daniel Jasper
559b63cbb9
clang-format: Understand __attribute__s preceding parameter lists.
...
Before:
ReturnType __attribute__((unused))
function(int i);
After:
ReturnType __attribute__((unused))
function(int i);
This fixes llvm.org/PR18632.
llvm-svn: 200337
2014-01-28 20:13:43 +00:00
Daniel Jasper
e9beea24ef
clang-format: Add support for a space after @property
...
Mozilla and WebKit seem to use a space after @property (verified by
grepping their codebases) so we turn this on there as well.
Change by Christian Legnitto. Thank you!
llvm-svn: 200320
2014-01-28 15:20:33 +00:00
Daniel Jasper
ff974ab88a
clang-format: Fix incorrect space removal.
...
Before:
Deleted &operator=(const Deleted &)&= default;
Deleted &operator=(const Deleted &)&&= delete;
After:
Deleted &operator=(const Deleted &)& = default;
Deleted &operator=(const Deleted &)&& = delete;
llvm-svn: 200073
2014-01-25 09:16:02 +00:00
Manuel Klimek
421147ec65
Get rid of special parsing for return statements.
...
This was done when we were not able to parse lambdas to handle some
edge cases for block formatting different in return statements, but is
not necessary any more.
llvm-svn: 199982
2014-01-24 09:25:23 +00:00
Daniel Jasper
6b70ec0d46
clang-format: Fix incorrect lambda recognition.
...
Before:
std::unique_ptr<int[]> foo() {}
After:
std::unique_ptr<int []> foo() {}
Also, the formatting could go severely wrong after such a function
before.
llvm-svn: 199817
2014-01-22 17:01:47 +00:00
Daniel Jasper
7cfde414e1
clang-format: text following #if is likely an expression.
...
Before:
#if AAAA &&BBBB
After:
#if AAAA && BBBB
llvm-svn: 199713
2014-01-21 08:56:09 +00:00
Daniel Jasper
7052ce6d8b
clang-format: Better support and testing for protocol buffers.
...
With this patch, there is dedicated testing for protocol buffers
(https://developers.google.com/protocol-buffers/ ).
Also some minor tweaks formatting tweaks.
llvm-svn: 199580
2014-01-19 09:04:08 +00:00
Daniel Jasper
31745731e8
clang-format: Fix ObjC block as first call parameter formatting.
...
Before:
foo (^{ bar(); });
After:
foo(^{ bar(); });
llvm-svn: 199573
2014-01-19 07:46:32 +00:00
Daniel Jasper
47ef6ddece
clang-format: Don't break lines starting with "import <string-literal>"
...
The author might be missing the "#" or these might be protocol buffer
definitions. Either way, we should not break the line or the string.
There don't seem to be other valid use cases.
llvm-svn: 199501
2014-01-17 16:21:39 +00:00
Daniel Jasper
a225bcedb4
clang-format: Improve formatting of ObjC Blocks with return type.
...
Before:
int a = [operation block:^int(int * i) { return 1; }];
After:
int a = [operation block:^int(int *i) { return 1; }];
llvm-svn: 199411
2014-01-16 19:14:34 +00:00
Daniel Jasper
cb51cf409b
clang-format: Enable formatting of lambdas with explicit return type.
...
So clang-format can now format:
int c = []()->int { return 2; }();
int c = []()->vector<int> { return { 2 }; }();
llvm-svn: 199368
2014-01-16 09:11:55 +00:00
Daniel Jasper
b2e10a5459
clang-format: Fixed formatting of JavaScript container literals
...
Before:
var arr = [ 1, 2, 3 ];
var obj = {a : 1, b : 2, c : 3};
After:
var arr = [1, 2, 3];
var obj = {a: 1, b: 2, c: 3};
llvm-svn: 199317
2014-01-15 15:09:08 +00:00
Daniel Jasper
d07c2ee99e
clang-format: Fix bug introduced in r198871.
...
We cannot simply change the start column to accomodate for the @ in an
ObjC string literal as that will make clang-format happily violate the
column limit.
Use a different workaround instead. However, a better long-term
solution might be to join the @ and the rest of the literal into a
single token.
llvm-svn: 199198
2014-01-14 09:53:07 +00:00
Daniel Jasper
f6c7c18b8e
clang-format: Fix corner case with comment in ctor initializer.
...
Formatting:
Constructor() :
// Comment forcing unwanted break.
aaaa(aaaa) {}
Before:
Constructor()
:
// Comment forcing unwanted break.
aaaa(aaaa) {}
After:
Constructor()
: // Comment forcing unwanted break.
aaaa(aaaa) {}
llvm-svn: 199107
2014-01-13 14:10:04 +00:00
Daniel Jasper
85bde4cdd8
clang-format: Don't indent relative to ./->.
...
Before:
SomeThing // break
.SomeFunction( // break
param);
After:
SomeThing // break
.SomeFunction( // break
param);
Seems to be more common in editors and codebases I have looked at.
llvm-svn: 199105
2014-01-13 13:42:08 +00:00
Daniel Jasper
4d7a97adfc
clang-format: Slightly adapt line break in edge case.
...
Before:
SomeMap[std::pair(aaaaaaaaaaaa, bbbbbbbbbbbbbbb)]
.insert(ccccccccccccccccccccccc);
After:
SomeMap[std::pair(aaaaaaaaaaaa, bbbbbbbbbbbbbbb)].insert(
ccccccccccccccccccccccc);
This seems to be about 3:1 more common in Google and Chromium style and I found
only a handful of instances inside the LLVM codebase.
llvm-svn: 198924
2014-01-10 08:40:17 +00:00
Daniel Jasper
b1c19f8987
clang-format: Understand ObjC boxed expressions.
...
Before:
[dictionary setObject:@(1)forKey:@"number"];
After:
[dictionary setObject:@(1) forKey:@"number"];
llvm-svn: 198920
2014-01-10 07:44:53 +00:00
Daniel Jasper
174b012524
clang-format: Add @s when breaking NSString literals.
...
While it is allowed to not have an @ on subsequent lines, it seems
general practice to add them. If undesired, the code author can easily
remove them again and clang-format won't re-add them.
llvm-svn: 198871
2014-01-09 14:18:12 +00:00
Daniel Jasper
dc32c1bf3a
clang-format: Understand #pragma mark
...
Before:
#pragma mark Any non - hyphenated or hyphenated string(including parentheses).
After:
#pragma mark Any non-hyphenated or hyphenated string (including parentheses).
llvm-svn: 198870
2014-01-09 13:56:49 +00:00
Daniel Jasper
0160347b22
clang-format: Some tweaks to braces list formatting:
...
- Format a braced list with one element per line if it has nested
braced lists.
- Use a column layout only when the list has 6+ elements (instead of the
current 4+ elements).
llvm-svn: 198869
2014-01-09 13:42:56 +00:00
Benjamin Kramer
e21cb74224
clang-format: Don't hang forever when encountering a stray "}" in an @implementation block.
...
PR18406.
llvm-svn: 198770
2014-01-08 15:59:42 +00:00
Daniel Jasper
7620b6628b
clang-format: Fix spacing in Cpp11 braced lists:
...
Before:
vector<int> foo{ ::SomeFunction()};
After:
vector<int> foo{::SomeFunction()};
llvm-svn: 198769
2014-01-08 15:41:13 +00:00
Chandler Carruth
5553d0d4ca
Sort all the #include lines with LLVM's utils/sort_includes.py which
...
encodes the canonical rules for LLVM's style. I noticed this had drifted
quite a bit when cleaning up LLVM, so wanted to clean up Clang as well.
llvm-svn: 198686
2014-01-07 11:51:46 +00:00
Daniel Jasper
1a148b4922
clang-format: Spacing inside enum braces.
...
Before (in Google style):
enum ShortEnum {A, B, C};
After:
enum ShortEnum { A, B, C };
llvm-svn: 198559
2014-01-05 13:23:23 +00:00
Daniel Jasper
9697281eec
clang-format: Allow formatting short enums on a single line.
...
Before:
enum ShortEnum {
A,
B,
C
};
After:
enum ShortEnum { A, B, C };
This seems to be the predominant choice in LLVM/Clang as well as in
Google style.
llvm-svn: 198558
2014-01-05 12:38:10 +00:00