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
e189d46512
clang-format: [Java] Support try blocks with resources.
...
Before:
try
(SomeResource rs = someFunction()) {
Something();
}
After:
try (SomeResource rs = someFunction()) {
Something();
}
llvm-svn: 225973
2015-01-14 10:48:41 +00:00
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
5f1fa85e5b
clang-format: [Java] Fix incorrect recognition of annonymous classes.
...
Before:
someFunction(new Runnable() { public void run() { System.out.println(42);
}
});
After:
someFunction(new Runnable() {
public void run() {
System.out.println(42);
}
});
llvm-svn: 225142
2015-01-04 20:40:51 +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
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
e5d74867aa
clang-format: [Java] Support Foo.class;
...
Before:
SomeClass.
class.getName();
After:
SomeClass.class.getName();
This fixes llvm.org/PR21665.
llvm-svn: 222813
2014-11-26 08:17:08 +00:00
Daniel Jasper
616de864da
clang-format: [JS] Support Closure's module statements.
...
These are like import statements and should not be line-wrapped. Minor
restructuring of the handling of other import statements.
llvm-svn: 222637
2014-11-23 16:46:28 +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
ccb68b487e
clang-format: [Java] Accept generic types in enum declaration
...
Before:
enum Foo implements Bar<X, Y> {
ABC {
...
}
, CDE {
...
};
}
After:
enum Foo implements Bar<X, Y> {
ABC {
...
},
CDE {
...
};
}
Patch by Harry Terkelsen.
llvm-svn: 222394
2014-11-19 22:38:18 +00:00
Daniel Jasper
6be0f55d44
clang-format: [Java] Support Java enums.
...
In Java, enums can contain a class body and enum constants can have
arguments as well as class bodies. Support most of that.
llvm-svn: 221895
2014-11-13 15:56:28 +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
d0ec0d62d6
clang-format: Use identifier table for keywords in other languages.
...
Slightly easier to write, more efficient and prevents bugs by
misspelling them.
No functional changes intended.
llvm-svn: 221259
2014-11-04 12:41:02 +00:00
Daniel Jasper
82f9df9eb4
Revert "clang-format: [Java] Allow trailing semicolons after enums."
...
This reverts commit b5bdb2ef59ab922bcb4d6e843fffaee1f7f68a8c.
This doesn't really seem necessary on second though and causes problems
with C++ enum formatting.
llvm-svn: 221158
2014-11-03 15:42:11 +00:00
Daniel Jasper
5f2764d886
clang-format: [Java] Allow trailing semicolons after enums.
...
Before:
enum SomeThing { ABC, CDE }
;
After:
enum SomeThing { ABC, CDE };
llvm-svn: 221125
2014-11-03 03:00:42 +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
df2ff002f0
clang-format: [Java] Support enums without trailing semicolon.
...
Before:
class SomeClass {
enum SomeThing { ABC, CDE } void f() {
}
}
After:
class SomeClass {
enum SomeThing { ABC, CDE }
void f() {
}
}
This fixed llvm.org/PR21458.
llvm-svn: 221113
2014-11-02 22:31:39 +00:00
Daniel Jasper
a3ddf86dd4
clang-format: [Java] Support try/catch/finally blocks.
...
llvm-svn: 221104
2014-11-02 19:21:48 +00:00
Daniel Jasper
50b4bd7c0e
clang-format: [Java] Don't break after extends/implements.
...
Before:
abstract class SomeClass extends SomeOtherClass implements
SomeInterface {}
After:
abstract class SomeClass extends SomeOtherClass
implements SomeInterface {}
llvm-svn: 221103
2014-11-02 19:16:41 +00:00
Daniel Jasper
4bf9d470cb
clang-format: [Java] Support extending inner classes.
...
Before:
class A extends B
.C {}
After:
class A extends B.C {}
llvm-svn: 220280
2014-10-21 09:31:29 +00:00
Daniel Jasper
c58c70e2f3
clang-format: Basic support for Java.
...
llvm-svn: 217759
2014-09-15 11:21:46 +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
4429f14906
clang-format: Address review comments of r216501.
...
llvm-svn: 216565
2014-08-27 17:16:46 +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
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
David Blaikie
efb6eb2697
Use std::unique_ptr to handle transient ownership of UnwrappedLine in ScopedLineState
...
llvm-svn: 215294
2014-08-09 20:02:07 +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
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
ad9eb0d79d
clang-format: [JS] support free-standing functions again.
...
This worked initially but was broken by r210887.
Before:
function outer1(a, b) {
function inner1(a, b) { return a; } inner1(a, b);
} function outer2(a, b) { function inner2(a, b) { return a; } inner2(a, b); }
After:
function outer1(a, b) {
function inner1(a, b) { return a; }
inner1(a, b);
}
function outer2(a, b) {
function inner2(a, b) { return a; }
inner2(a, b);
}
Thanks to Adam Strzelecki for working on this.
llvm-svn: 212038
2014-06-30 13:24:54 +00:00
Daniel Jasper
5217a8b84f
clang-format: [JS] Understand named function literals.
...
Before:
return {a: function SomeFunction(){// ...
return 1;
}
}
;
After:
return {
a: function SomeFunction() {
// ...
return 1;
}
};
llvm-svn: 210887
2014-06-13 07:02:04 +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
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
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
069e5f4858
clang-format: [JS] Understand top-level function literals properly.
...
llvm-svn: 209205
2014-05-20 11:14:57 +00:00
Daniel Jasper
b05a81debb
clang-format: Fix bug introduced by r208392.
...
Also run clang-format over clang-format's files.
llvm-svn: 208409
2014-05-09 13:11:16 +00:00
Craig Topper
2145bc0229
[C++11] Use 'nullptr'.
...
llvm-svn: 208392
2014-05-09 08:15:10 +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
c03e16a7bc
clang-format: [JS] support closures in container literals.
...
Before:
return {body: {setAttribute: function(key, val) {this[key] = val;
}
, getAttribute : function(key) { return this[key]; }
, style : {
direction:
''
}
}
}
;
After:
return {
body: {
setAttribute: function(key, val) { this[key] = val; },
getAttribute: function(key) { return this[key]; },
style: {direction: ''}
}
};
llvm-svn: 208292
2014-05-08 09:25:39 +00:00
Daniel Jasper
4a39c84c91
clang-format: [JS] Don't indent in goog.scope blocks.
...
Before:
goog.scope(function() {
var x = a.b;
var y = c.d;
}); // goog.scope
After:
goog.scope(function() {
var x = a.b;
var y = c.d;
}); // goog.scope
llvm-svn: 208088
2014-05-06 13:54:10 +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
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
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
Manuel Klimek
1fcbe675fa
Correctly handle escaped newlines when the next token starts without a space.
...
We will need this to correctly handle conflict markers inside macro
definitions.
llvm-svn: 206029
2014-04-11 12:27:47 +00:00
Daniel Jasper
220c0d1f5e
clang-format: Fix false positive in braced list detection in protos.
...
llvm-svn: 205954
2014-04-10 07:27:12 +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
240dfda352
clang-format: Solve issues found and fixed by clang-tidy.
...
llvm-svn: 205193
2014-03-31 14:23:49 +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
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
Craig Topper
fb6b25b5e4
[C++11] Add 'override' keyword to virtual methods that override their base class.
...
llvm-svn: 203999
2014-03-15 04:29:04 +00:00
Alexander Kornienko
c2ee9cf861
Remove an unnecessary check for FormatTok not being null.
...
Summary:
This check hints clang analyzer, that FormatTok may be null, and it
reports a null pointer dereference error:
http://buildd-clang.debian.net/scan-build/report-827c64.html#Path28
Reviewers: djasper
Reviewed By: djasper
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D3040
llvm-svn: 203800
2014-03-13 13:59:48 +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
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
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
Ahmed Charles
9a16beb8bc
Change OwningPtr::take() to OwningPtr::release().
...
This is a precursor to moving to std::unique_ptr.
llvm-svn: 203275
2014-03-07 19:33:25 +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
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
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
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
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
352dae199a
clang-format: Recognize single-line macro usages inside macros.
...
Before:
#define LIST(L) \
L(FirstElement) L(SecondElement) L(ThirdElement) L(FourthElement) \
L(FifthElement)
After:
#define LIST(L) \
L(FirstElement) \
L(SecondElement) \
L(ThirdElement) \
L(FourthElement) \
L(FifthElement)
llvm-svn: 198407
2014-01-03 11:50:46 +00:00
Daniel Jasper
b88b25feec
clang-format: Fix various problems in formatting ObjC blocks.
...
Among other things, this fixes llvm.org/PR15269.
llvm-svn: 197900
2013-12-23 07:29:06 +00:00
Alexander Kornienko
3a33f0292b
Implemented GNU-style formatting for compound statements.
...
Summary:
Added BraceBreakingStyle::BS_GNU. I'm not sure about the correctness of
static initializer formatting, but compound statements should be fine.
Reviewers: djasper
Reviewed By: djasper
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2372
llvm-svn: 197138
2013-12-12 09:49:52 +00:00
Daniel Jasper
1556b59338
clang-format: Correctly handle Qt's Q_SLOTS.
...
This should fix llvm.org/PR17241. Maybe it sticks this time :-).
llvm-svn: 195953
2013-11-29 08:51:56 +00:00
Daniel Jasper
84c47a1074
clang-format: Support Qt's slot access specifiers.
...
This fixes llvm.org/PR17241.
llvm-svn: 195555
2013-11-23 17:53:41 +00:00
Daniel Jasper
b631d5e6f3
clang-format: Recognize braced lists with trailing function call.
...
Before:
int count = set<int> { f(), g(), h() }
.size();
After:
int count = set<int>{f(), g(), h()}.size();
llvm-svn: 195417
2013-11-22 07:26:53 +00:00
Alexander Kornienko
3cfa973978
Added an option to allow short function bodies be placed on a single line.
...
Summary:
The AllowShortFunctionsOnASingleLine option now controls short function
body placement on a single line independent of the BreakBeforeBraces option.
Updated tests using BreakBeforeBraces other than BS_Attach.
Addresses http://llvm.org/PR17888
Reviewers: klimek, djasper
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2230
llvm-svn: 195256
2013-11-20 16:33:05 +00:00
Manuel Klimek
f6fd3d3fcf
Remove incorrect assert.
...
If we run into the second preprocessor branch chain, the first branch
chain might have already set the maximum branch count on that level to
something > 0.
Fixes PR17645.
llvm-svn: 193153
2013-10-22 08:27:19 +00:00
Manuel Klimek
b212f3baa1
Automatically munch semicolons after blocks.
...
While it is mostly a user error to have the extra semicolon,
formatting it graciously will correctly format in the cases
where we do not fully understand the code (macros).
llvm-svn: 192543
2013-10-12 22:46:56 +00:00
Daniel Jasper
53bd167c60
clang-format: Fix assertion on unterminated #ifs.
...
llvm-svn: 192535
2013-10-12 13:32:56 +00:00
Manuel Klimek
71814b4465
Support formatting of preprocessor branches.
...
We now correctly format:
void SomeFunction(int param1,
#ifdef X
NoTemplate param2,
#else
template <
#ifdef A
MyType<Some> >
#else
Type1, Type2>
#endif
param2,
#endif
param3) {
f();
}
llvm-svn: 192503
2013-10-11 21:25:45 +00:00
Manuel Klimek
91e48586ae
Fix incorrect detection of class definitions with alignas specification.
...
llvm-svn: 192094
2013-10-07 09:15:41 +00:00
Daniel Jasper
f3d977979c
clang-format: Detect braced lists in subscript expressions.
...
Before (even with Style.Cpp11BracedListStyle):
f(MyMap[{ composite, key }]);
After:
f(MyMap[{composite, key}]);
llvm-svn: 190678
2013-09-13 10:55:31 +00:00
Daniel Jasper
015ed028cf
clang-format: Fix incorrect enum parsing / layouting.
...
Before:
enum {
Bar = Foo < int,
int > ::value
};
After:
enum {
Bar = Foo<int, int>::value
};
llvm-svn: 190674
2013-09-13 09:20:45 +00:00
Daniel Jasper
786a550b9f
clang-format: Format typed enums with nested names.
...
The explicit type specified for an enum can actually have a nested name
specifier.
This fixes llvm.org/PR17125.
llvm-svn: 190208
2013-09-06 21:32:35 +00:00
Daniel Jasper
b4b9998713
clang-format: Don't confuse operator[] with lambdas.
...
Before:
double &operator[](int i) { return 0; } int i;
After:
double &operator[](int i) { return 0; }
int i;
This fixes llvm.org/PR17134.
llvm-svn: 190207
2013-09-06 21:25:51 +00:00
Daniel Jasper
3b203a65c2
Add ATTRIBUTE_UNUSED to silence unused-function warning in release
...
builds.
llvm-svn: 190061
2013-09-05 16:05:56 +00:00
Manuel Klimek
9a53c7f40d
Fixes PR 17106 (explicitly typed enums are formatted differently).
...
Before:
enum X : int { A, B, C };
After:
enum X : int {
A,
B,
C
};
llvm-svn: 190054
2013-09-05 15:34:55 +00:00
Daniel Jasper
bf02b2c186
clang-format: Quickfix for braced init lists detected as lambdas.
...
Before:
constexpr char hello [] { "hello" };
After:
constexpr char hello[]{ "hello" };
llvm-svn: 190046
2013-09-05 11:49:39 +00:00
Daniel Jasper
9a8d48b5e1
clang-format: Fix parsing and indenting lambdas.
...
Before:
void f() {
other(x.begin(), x.end(), //
[&](int, int) { return 1; });
}
After:
void f() {
other(x.begin(), x.end(), //
[&](int, int) { return 1; });
}
llvm-svn: 190039
2013-09-05 10:04:31 +00:00
Daniel Jasper
9fe0e8dacd
clang-format: Enable formatting of nested blocks.
...
Among other things, this enables (better) formatting lambdas and
constructs like:
MACRO({
long_statement();
long_statement_2();
},
{
long_statement();
long_statement_2();
},
{ short_statement(); }, "");
This fixes llvm.org/PR15381.
llvm-svn: 190038
2013-09-05 09:29:45 +00:00
Manuel Klimek
f017dc0156
Remove code duplication in unwrapped line parser.
...
llvm-svn: 189933
2013-09-04 13:34:14 +00:00
Manuel Klimek
516e054c05
Implement parsing of blocks (^{ ... }) in the unwrapped line parser.
...
This patch makes sure we produce the right number of unwrapped lines,
a follow-up patch will make the whitespace formatting consistent.
Before:
void f() {
int i = {[operation setCompletionBlock : ^{ [self onOperationDone];
}]
}
;
}
After:
void f() {
int i = {[operation setCompletionBlock : ^{
[self onOperationDone];
}] };
}
llvm-svn: 189932
2013-09-04 13:25:30 +00:00
Manuel Klimek
bab25fdfa5
Fix layout of lambda captures.
...
Before:
int c = [ &, &a, a]{
[ =, c, &d]{
return b++;
}();
}();
After:
int c = [&, &a, a] {
[=, c, &d] {
return b++;
}();
}();
llvm-svn: 189924
2013-09-04 08:20:47 +00:00
Manuel Klimek
ffdeb595ba
First step towards correctly formatting lambdas.
...
Implements parsing of lambdas in the UnwrappedLineParser.
This introduces the correct line breaks; the formatting of
lambda captures are still incorrect, and the braces are also
still formatted as if they were braced init lists instead of
blocks.
llvm-svn: 189818
2013-09-03 15:10:01 +00:00
Daniel Jasper
7240762504
clang-format: Fix case-indentation in macros.
...
Before:
#define OPERATION_CASE(name) \
case OP_name: \
return operations::Operation##name
After:
#define OPERATION_CASE(name) \
case OP_name: \
return operations::Operation##name
llvm-svn: 189743
2013-09-02 08:26:29 +00:00
Daniel Jasper
b715087278
clang-format: Improve recovery from enums with errors.
...
Before:
namespace n {
enum Type {
One,
Two, // missing };
int i;
} void g() {
}
After:
namespace n {
enum Type {
One,
Two, // missing };
int i;
}
void g() {}
llvm-svn: 189662
2013-08-30 10:10:19 +00:00
Daniel Jasper
a15da3068d
clang-format: Fix corner case in ObjC interface definitions.
...
In
@implementation ObjcClass
- (void)method;
{
}
@end
the ObjC compiler seems to accept the superfluous comma after "method",
but clang-format used to assert on the subsequent "{".
This fixes llvm.org/PR16604.
llvm-svn: 189453
2013-08-28 08:04:23 +00:00
Daniel Jasper
65b79829c3
clang-format: Improve braced init list detection:
...
Before:
std::this_thread::sleep_for(std::chrono::nanoseconds{
std::chrono::seconds { 1 }
} /
5);
After:
std::this_thread::sleep_for(
std::chrono::nanoseconds{ std::chrono::seconds{ 1 } } / 5);
This fixes llvm.org/PR16554.
llvm-svn: 189451
2013-08-28 07:50:37 +00:00
Daniel Jasper
2b41a82e61
clang-format: Format enum struct/class like enum.
...
Patch by Joe Hermaszewski. Thank you!
llvm-svn: 188794
2013-08-20 12:42:50 +00:00
Manuel Klimek
a027f306a6
Fixes a couple of bugs with the Allman brace breaking.
...
In particular, left braces after an enum declaration now occur on their
own line. Further, when short ifs/whiles are allowed these no longer
cause the left brace to be on the same line as the if/while when a
brace is included.
Patch by Thomas Gibson-Robinson.
llvm-svn: 187901
2013-08-07 19:20:45 +00:00
Manuel Klimek
d3ed59ae15
Implement Allman style.
...
Patch by Frank Miller.
llvm-svn: 187678
2013-08-02 21:31:59 +00:00
Daniel Jasper
65ee347285
clang-format: Add more options to namespace indentation.
...
With this patch, clang-format can be configured to:
* not indent in namespace at all (former behavior).
* indent in namespace as in other blocks.
* indent only in inner namespaces (as required by WebKit style).
Also fix alignment of access specifiers in WebKit style.
Patch started by Marek Kurdej. Thank you!
llvm-svn: 187540
2013-07-31 23:16:02 +00:00
Daniel Jasper
516d7971b3
clang-format: Fix switch/case interaction with macros.
...
Before:
#define OPERATION_CASE(name) \
case OP_name: \
return operations::Operation##name
switch (OpCode) {
CASE(Add);
CASE(Subtract);
default:
return operations::Unknown;
}
After:
#define OPERATION_CASE(name) \
case OP_name: \
return operations::Operation##name;
switch (OpCode) {
CASE(Add);
CASE(Subtract);
default:
return operations::Unknown;
}
llvm-svn: 187118
2013-07-25 11:31:57 +00:00
Daniel Jasper
b1f74a8152
Fix alignment of closing brace in braced initializers.
...
Before:
someFunction(OtherParam, BracedList{
// comment 1 (Forcing intersting break)
param1, param2,
// comment 2
param3, param4
});
After:
someFunction(OtherParam, BracedList{
// comment 1 (Forcing intersting break)
param1, param2,
// comment 2
param3, param4
});
To do so, the UnwrappedLineParser now stores the information about the
kind of brace in the FormatToken.
llvm-svn: 185914
2013-07-09 09:06:29 +00:00
Daniel Jasper
ca7bd720eb
Fix incorrect token counting introduced by r185319.
...
This lead to weird formatting.
Before:
DoSomethingWithVector({ {} /* No data */ }, {
{ 1, 2 }
});
After:
DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } });
llvm-svn: 185346
2013-07-01 16:43:38 +00:00