Craig Topper
4b56692e30
[C++11] Use 'nullptr'.
...
llvm-svn: 210448
2014-06-09 02:04:02 +00:00
Daniel Jasper
58cb2edd69
clang-format: Fix incorrect indentation.
...
Before (JavaScript example, but can extend to other languages):
return {
a: 'E',
b: function() {
return function() {
f(); // This is wrong.
};
}
};
After:
return {
a: 'E',
b: function() {
return function() {
f(); // This is better.
};
}
};
llvm-svn: 210334
2014-06-06 13:49:04 +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
114a2bc9d2
clang-format: Refactor indentation behavior for multiple nested blocks.
...
This fixes a few oddities when formatting multiple nested JavaScript
blocks, e.g.:
Before:
promise.then(
function success() {
doFoo();
doBar();
},
[], function error() {
doFoo();
doBaz();
});
promise.then([],
function success() {
doFoo();
doBar();
},
function error() {
doFoo();
doBaz();
});
After:
promise.then(
function success() {
doFoo();
doBar();
},
[],
function error() {
doFoo();
doBaz();
});
promise.then([],
function success() {
doFoo();
doBar();
},
function error() {
doFoo();
doBaz();
});
llvm-svn: 210097
2014-06-03 12:02:45 +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
cb82dfb11c
Use error_code() instead of error_code::succes()
...
There is no std::error_code::success, so this removes much of the noise
in transitioning to std::error_code.
llvm-svn: 209949
2014-05-31 01:26:30 +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
60553be5fd
clang-format: Split up moveStateToNextToken.
...
No functional changes intended.
llvm-svn: 209626
2014-05-26 13:10:39 +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
Alexander Kornienko
0a0d6b4bb1
Use error_code::success() instead of make_error_code(llvm::errc::success).
...
llvm-svn: 209477
2014-05-22 22:06:08 +00:00
Daniel Jasper
c64b09acc3
clang-format: Introduce DisableFormat that prevents formatting.
...
And "none" pseudo-style indicating that formatting should be not
applied.
(1) Using .clang-format with "DisableFormat: true" effectively prevents
formatting for all files within the folder containing such .clang-format
file.
(2) Using -fallback-style=none together with -style=file prevents
formatting when .clang-format is not found, which can be used in on-save
callback.
Patch by Adam Strzelecki. Thank you!
llvm-svn: 209446
2014-05-22 15:12:22 +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
1f6c7e9358
clang-format: Store pointers to seen formatting states.
...
As the memory ownership is handled by the SpecificBumpPtrAllocator
anyway, there is no need to duplicate states when inserting them into
the Seen-set. This leads to an improvement of ~10% on the benchmark
formatting file.
No functional changes intended.
llvm-svn: 209422
2014-05-22 11:47:01 +00:00
Daniel Jasper
49802ef93b
clang-format: [JS] Understand line breaks in concatenated strings.
...
Before:
var literal = 'hello ' + 'world';
After:
var literal = 'hello ' +
'world';
There is no reason to concatenated two string literals with a '+' unless
the line break is intended.
llvm-svn: 209413
2014-05-22 09:10:04 +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
2a958321c8
clang-format: Fix corner case working around one-per-line dict literals.
...
Before:
var object_literal_with_long_name = {
a: 'aaaaaaaaaaaaaaaaaa', b: 'bbbbbbbbbbbbbbbbbb'
};
After:
var object_literal_with_long_name = {
a: 'aaaaaaaaaaaaaaaaaa',
b: 'bbbbbbbbbbbbbbbbbb'
};
llvm-svn: 209296
2014-05-21 13:26:58 +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
b16b969d7c
clang-format: [JS] Support different function literal style.
...
Before:
goog.array.forEach(array, function() {
doSomething();
doSomething();
},
this);
After:
goog.array.forEach(array, function() {
doSomething();
doSomething();
}, this);
llvm-svn: 209291
2014-05-21 12:51:23 +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
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
0dd5291e69
clang-format: [JS] Support ES6 destructuring assignments.
...
Before:
var[a, b, c] = [1, 2, 3];
After:
var [a, b, c] = [1, 2, 3];
llvm-svn: 209113
2014-05-19 07:37:07 +00:00
Daniel Jasper
78214397a3
clang-format: [JS] Support for EC6 arrow functions.
...
Before:
var b = a.map((x) = > x + 1);
After:
var b = a.map((x) => x + 1);
llvm-svn: 209112
2014-05-19 07:27:02 +00:00
Alp Toker
c3f36af8d0
Fix typos
...
llvm-svn: 208838
2014-05-15 01:35:53 +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
fb4333b093
clang-format: [JS] Basic support for escape sequences in regex literals.
...
Before:
var regex = /\\/ g; // This isn't even recognized as regex.
After:
var regex = /\\/g; // It now is.
llvm-svn: 208539
2014-05-12 11:29:50 +00:00
Benjamin Kramer
f3ca269839
Decouple ExprCXX.h and DeclCXX.h and clean up includes a bit.
...
Required pulling LambdaExpr::Capture into its own header.
No functionality change.
llvm-svn: 208470
2014-05-10 16:31:55 +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
Daniel Jasper
8f83a9072d
clang-format: [JS] Allow up to 3 empty lines in Google's JS style.
...
llvm-svn: 208404
2014-05-09 10:28:58 +00:00
Daniel Jasper
8951908218
clang-format: [JS] Fix spacing in dict literals.
...
Before:
someVariable = {'a':[{}]};
After:
someVariable = {'a': [{}]};
llvm-svn: 208403
2014-05-09 10:26:08 +00:00
Craig Topper
2145bc0229
[C++11] Use 'nullptr'.
...
llvm-svn: 208392
2014-05-09 08:15:10 +00:00
Daniel Jasper
05cd586863
clang-format: Cleanup redundant calculation of ParenLevel.
...
No functional changes intended.
llvm-svn: 208304
2014-05-08 12:21:30 +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
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
Daniel Jasper
f7405c129e
clang-format: [JS] Support regex literals after 'return'.
...
llvm-svn: 208285
2014-05-08 07:45:18 +00:00
Daniel Jasper
f9ae312fc0
clang-format: [JS] Initial support for regex literals.
...
llvm-svn: 208281
2014-05-08 07:01:45 +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
79dffb4128
clang-format: Be slightly more aggressive on single-line functions.
...
So that JS functions can also be merged into a single line.
Before:
var func = function() {
return 1;
};
After:
var func = function() { return 1; };
llvm-svn: 208176
2014-05-07 09:48:30 +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
Daniel Jasper
484033b188
clang-format: [JS] Keep space after closure style comments.
...
Before:
var x = /** @type {foo} */ (bar);
After:
var x = /** @type {foo} */(bar);
llvm-svn: 208093
2014-05-06 14:41:29 +00:00