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
Alp Toker
0621cb2e7d
Make clang's rewrite engine a core feature
...
The rewrite facility's footprint is small so it's not worth going to these
lengths to support disabling at configure time, particularly since key compiler
features now depend on it.
Meanwhile the Objective-C rewriters have been moved under the
ENABLE_CLANG_ARCMT umbrella for now as they're comparatively heavy and still
potentially worth excluding from lightweight builds.
Tests are now passing with any combination of feature flags. The flags
historically haven't been tested by LLVM's build servers so caveat emptor.
llvm-svn: 213171
2014-07-16 16:48:33 +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
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
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
9c2820c4e3
clang-format: [proto] Add required space before absolute references.
...
llvm-svn: 211488
2014-06-23 07:36:25 +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
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
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
17062ff550
clang-format: [JS] Treat dict literals similar to objc method exprs.
...
Before:
return {
link:
function() {
f(); //
}
};
return {
a: a,
link: function() {
f(); //
}
}
After:
return {
link: function() {
f(); //
}
};
return {
a: a,
link: function() {
f(); //
}
};
llvm-svn: 210537
2014-06-10 14:44:02 +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
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
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
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
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