NAKAMURA Takumi
e9ac8b4d63
Exclude printLineState() in -Asserts. [-Wunused-function]
...
llvm-svn: 224430
2014-12-17 14:46:56 +00:00
Daniel Jasper
0580ff0ec6
clang-format: Fix incorrect calculation of token lenghts.
...
This led, e.g. to break JavaScript regex literals too early.
llvm-svn: 224419
2014-12-17 09:11:08 +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
Alexander Kornienko
ff2437fe84
Don't break string literals in Java and JavaScript.
...
The proper way to break string literals in these languages is by inserting a "+"
between parts which we don't support yet. So we disable string literal breaking
until then.
llvm-svn: 224120
2014-12-12 13:03:22 +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
Daniel Jasper
0df50938be
clang-format: Factor out UnwrappedLineFormatter into a separate file.
...
No functional changes intended.
llvm-svn: 223936
2014-12-10 19:00:42 +00:00
Daniel Jasper
24a147776e
clang-format: Remove a few else after return statements.
...
They are against the LLVM coding conventions. No functional changes
intended.
llvm-svn: 223930
2014-12-10 17:24:34 +00:00
Daniel Jasper
a536df4b28
clang-format: Indent correctly in conditional expressions after return.
...
This only applies when not aligning after the return itself (which is
commonly done for C++.
Before:
return aaaaaaaaaa
? bbbbbbbbbb(
bbbbbb) // This is indented relative to aaaaaaaaaa.
: b;
After:
return aaaaaaaaaa
? bbbbbbbbbb(
bbbbbb)
: b;
llvm-svn: 223694
2014-12-08 21:28:31 +00:00
Daniel Jasper
211e1329cc
clang-format: [Java] Always break after annotations of multiline decls.
...
Before:
@Mock DataLoader loooooooooooooooooooooooader =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
After:
@Mock
DataLoader loooooooooooooooooooooooader =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
llvm-svn: 223688
2014-12-08 20:08:04 +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
a4e55f4d1e
clang-format: [JS] Don't put top-level dict literals on a single line.
...
These are often used for enums which apparently are easier to read if
formatted with one element per line.
llvm-svn: 223367
2014-12-04 16:07:17 +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
8379107afe
clang-format: Fix expression parser not closing stuff at end of stmt.
...
Uncovered by a Java test case:
Before:
public some.package.Type someFunction( // comment
int parameter) {}
After:
public some.package.Type someFunction( // comment
int parameter) {}
llvm-svn: 223228
2014-12-03 13:20:49 +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
41368e9e07
clang-format: [JS] Contract fewer functions to a single line.
...
Before:
var someVariable =
function(x) { return x.zIsTooLongForOneLineWithTheDeclarationLine(); };
After:
var someVariable = function(x) {
return x.zIsTooLongForOneLineWithTheDeclarationLine();
};
llvm-svn: 222893
2014-11-27 15:37:42 +00:00
Daniel Jasper
4087432f8b
clang-format: [JS] Try not to break in container literals.
...
Before:
var obj = {
fooooooooo:
function(x) { return x.zIsTooLongForOneLineWithTheDeclarationLine(); }
};
After:
var obj = {
fooooooooo: function(x) {
return x.zIsTooLongForOneLineWithTheDeclarationLine();
}
};
llvm-svn: 222892
2014-11-27 15:24:48 +00:00
Daniel Jasper
7912123893
clang-format: [JS] new and delete are valid function names.
...
Before:
someObject.new ();
someObject.delete ();
After:
someObject.new();
someObject.delete();
llvm-svn: 222890
2014-11-27 14:55:17 +00:00
Daniel Jasper
53c38f4e79
clang-format: [JS] Make Closure module detection more narrow.
...
Before:
var MyLongClassName = goog.module.get('my.long.module.name.followedBy.MyLongClassName');
After:
var MyLongClassName =
goog.module.get('my.long.module.name.followedBy.MyLongClassName');
llvm-svn: 222888
2014-11-27 14:46:03 +00:00
Daniel Jasper
13404dad0d
clang-format: Don't use column layout with AlignAfterOpenBrackets.
...
This fixes llvm.org/PR21676.
llvm-svn: 222886
2014-11-27 14:40:48 +00:00
Daniel Jasper
9b9e07608d
clang-format: [Java] Don't line-wrap package declarations.
...
This fixes llvm.org/PR21677.
llvm-svn: 222843
2014-11-26 18:03:42 +00:00
Nico Weber
450425c980
clang-format: Tweak -style=Chromium for Java files.
...
For Java, don't do any of the deviations from Google Style that Chromium style
does for C++.
Chromium's Java follows Android Java style [1], which is roughly Google Java
style with an indent of 4 and a continuation indent of 8.
1: https://source.android.com/source/code-style.html
llvm-svn: 222839
2014-11-26 16:43:18 +00:00
Daniel Jasper
375815d24b
clang-format: [Java] Improve formatting of throws declarations.
...
Before:
public void doSoooooooooo() throws LoooooooooongException,
LooooooooooongException {}
After:
public void doSoooooooooo()
throws LoooooooooongException, LooooooooooongException {}
llvm-svn: 222829
2014-11-26 12:31:19 +00:00
Daniel Jasper
4f56b0bb88
clang-format: [Java] Improve cast detection.
...
Before:
a[b >> 1] = (byte)(c() << 4);
After:
a[b >> 1] = (byte) (c() << 4);
llvm-svn: 222827
2014-11-26 12:23:10 +00:00
Daniel Jasper
07013a42d2
clang-format: [Java] Fix breaking after annotations.
...
Before:
@Annotation1 // comment
@Annotation2 class C {}
After:
@Annotation1 // comment
@Annotation2
class C {}
llvm-svn: 222825
2014-11-26 11:20:43 +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
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
a98b7b01be
clang-format: Refactoring.
...
Re-apply r222638 and r222641 without variadic templates.
llvm-svn: 222747
2014-11-25 10:05:17 +00:00
Aaron Ballman
484ee9b404
Reverting r222638; it broke the MSVC build bots because Visual Studio 2012 does not support variadic templates. Also reverting r222641 because it was relying on 222638.
...
llvm-svn: 222656
2014-11-24 15:42:34 +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
325e486f9b
clang-format: [Java] Treat 'instanceof' like other binary operators.
...
This fixes llvm.org/PR21436.
llvm-svn: 222641
2014-11-23 21:34:25 +00:00
Daniel Jasper
a0143fab5e
clang-format: [Java] Space before array initializers.
...
Before:
new int[]{1, 2, 3, 4};
After:
new int[] {1, 2, 3, 4};
llvm-svn: 222640
2014-11-23 20:54:37 +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
7198b0c778
clang-format: Refactoring.
...
Provide more overloads to simplify testing the type of a token. No
functional changes intended.
llvm-svn: 222638
2014-11-23 19:03:25 +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
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
82c9275344
clang-format: [Java] Support more Java keywords.
...
Before:
public final<X> Foo foo() {
}
public abstract<X> Foo foo();
After:
public final <X> Foo foo() {
}
public abstract <X> Foo foo();
Patch by Harry Terkelsen. Thank you.
llvm-svn: 222527
2014-11-21 12:19:07 +00:00
Daniel Jasper
8354ea84dd
clang-format: [Java] Basic lambda support.
...
llvm-svn: 222524
2014-11-21 12:14:12 +00:00
Daniel Jasper
6cab6784b9
clang-format: [Java] Don't align after "return".
...
Doesn't seem to be common practice in Java.
Before:
return aaaaaaaaaaaaaaaaaaa
&& bbbbbbbbbbbbbbbbbbb
&& ccccccccccccccccccc;
After:
return aaaaaaaaaaaaaaaaaaa
&& bbbbbbbbbbbbbbbbbbb
&& ccccccccccccccccccc;
Patch by Harry Terkelsen.
llvm-svn: 222424
2014-11-20 09:54:49 +00:00
Daniel Jasper
caf8685958
clang-format: [Java] Don't force break before generic type method.
...
Before:
Foo.bar()
.<X>
baz();
After:
Foo.bar()
.<X>baz();
Patch by Harry Terkelsen.
llvm-svn: 222423
2014-11-20 09:48:11 +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
fe2cf6673a
clang-format: [Java] Ignore C++-specific keywords
...
Before:
public void union
(Object o);
public void struct
(Object o);
public void delete (Object o);
After:
public void union(Object o);
public void struct(Object o);
public void delete(Object o);
Patch by Harry Terkelsen, thank you!
llvm-svn: 222357
2014-11-19 14:11:11 +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
6761b42b90
clang-format: Fix space between generic type parameter and square
...
bracket
Before:
public Foo<X, Y> [] foos;
After:
public Foo<X, Y>[] foos;
Patch by Harry Terkelsen. Thank you!
llvm-svn: 222283
2014-11-18 23:48:01 +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
4bfa736f1b
clang-format: [Java] Further improve generics formatting.
...
llvm-svn: 222011
2014-11-14 17:30:15 +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
Daniel Jasper
734d52b58b
clang-format: [Java] Fix line break behavior of class declarations.
...
Change breaking preferences:
1. Break before "extends"
2. Break before "implements"
3. Break within the implements list.
llvm-svn: 221981
2014-11-14 10:15:56 +00:00
Daniel Jasper
09f6abe8d8
clang-format: [Java] Improve generic return type formatting.
...
Before:
public<R> ArrayList<R> get() {
After:
public <R> ArrayList<R> get() {
llvm-svn: 221979
2014-11-14 09:05:32 +00:00
Daniel Jasper
30a2406e65
clang-format: [Java] No altnerative operator names in Java.
...
Before:
someObject.and ();
After:
someObject.and();
llvm-svn: 221978
2014-11-14 09:02:28 +00:00
Daniel Jasper
61d81973c1
clang-format: [Java] Improve formatting of generics.
...
Before:
Function < F, ? extends T > function;
After:
Function<F, ? extends T> function;
llvm-svn: 221976
2014-11-14 08:22:46 +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
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
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
Nico Weber
a644d7f39c
clang-format: [Java] Never treat @interface as annotation.
...
'@' followed by any keyword can't be an annotation, but @interface is currently
the only combination of '@' and a keyword that's allowed, so limit it to this
case. `@interface Foo` without a leading `public` was misformatted prior to
this patch.
llvm-svn: 221607
2014-11-10 16:30:02 +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
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
58fcf6df65
clang-format: [Java] Fix class declaration line breaks.
...
Before:
@SomeAnnotation()
abstract
class aaaaaaaaa<a> extends bbbbbbbbbbbb<b> implements cccccccccccc {
}
After:
@SomeAnnotation()
abstract class aaaaaaaaa<a> extends bbbbbbbbbbbb<b>
implements cccccccccccc {
}
llvm-svn: 221256
2014-11-04 10:53:14 +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
f056f45b77
clang-format: [Java] Fix more generics formatting.
...
Before:
< T extends B > T getInstance(Class<T> type);
After:
<T extends B> T getInstance(Class<T> type);
llvm-svn: 221124
2014-11-03 02:45:58 +00:00
Daniel Jasper
db9a7a2f5f
clang-format: [Java] Fix static generic methods.
...
Before:
public static<R> ArrayList<R> get() {}
After:
public static <R> ArrayList<R> get() {}
llvm-svn: 221122
2014-11-03 02:35:14 +00:00
Daniel Jasper
39af6cd5a4
clang-format: [Java] Fix class declaration formatting.
...
Before:
@SomeAnnotation()
abstract
class aaaaaaaaaaaa extends bbbbbbbbbbbbbbb implements cccccccccccc {
}
After:
@SomeAnnotation()
abstract class aaaaaaaaaaaa extends bbbbbbbbbbbbbbb
implements cccccccccccc {
}
llvm-svn: 221121
2014-11-03 02:27:28 +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
5e7be1d536
clang-format: [Java] Don't break imports.
...
This fixes llvm.org/PR21453.
llvm-svn: 221112
2014-11-02 22:13:03 +00:00
Daniel Jasper
b9d3db6b1b
clang-format: [Java] Add space between "synchronized" and "(".
...
Before:
synchronized(mData) {
// ...
}
After:
synchronized (mData) {
// ...
}
This fixes llvm.org/PR21455.
llvm-svn: 221110
2014-11-02 22:00:57 +00:00
Daniel Jasper
7bd618f5aa
clang-format: [Java] Support generics with "?".
...
Before:
@Override
public Map < String,
? > getAll() {
// ...
}
After:
@Override
public Map<String, ?> getAll() {
// ...
}
This fixes llvm.org/PR21454.
llvm-svn: 221109
2014-11-02 21:52:57 +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
e9ab42df0c
clang-format: [Java] Improve line breaks around annotations.
...
Before:
@SomeAnnotation("With some really looooooooooooooong text") private static final
long something = 0L;
void SomeFunction(@Nullable
String something) {}
After:
@SomeAnnotation("With some really looooooooooooooong text")
private static final long something = 0L;
void SomeFunction(@Nullable String something) {}
llvm-svn: 220984
2014-10-31 18:23:49 +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
Hans Wennborg
2f65f7ff58
Sink a #include while we're here. NFC.
...
Format.h doesn't use stack.
llvm-svn: 220879
2014-10-29 22:49:58 +00:00
Daniel Jasper
cb3e6188bc
Refactor libTooling to reduce required dependencies.
...
This moves classes for storing and applying replacements to separate
files. These classes specifically are used by clang-format which doesn't
have any other dependencies on clangAST. Thereby, the size of
clang-format's binary can be cut roughly in half and its build time sped
up.
llvm-svn: 220867
2014-10-29 18:55:09 +00:00
Daniel Jasper
49a9a2833b
clang-format: [JS] Support more regex literals.
...
Previously a regex-literal containing "/*" would through clang-format
off, e.g.:
var regex = /\/*$/;
Would lead to none of the following code to be formatted.
llvm-svn: 220860
2014-10-29 16:51:38 +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
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
b89fbe60e3
clang-format: Don't put functions on a single line in Google's Java
...
style.
llvm-svn: 220778
2014-10-28 16:15:52 +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
ce2fdb0a0a
clang-format: [Proto] Change formatting text-formatted options.
...
Before:
optional Type type = 1 [(mutate_options) = {vital : true
abc : false}];
After:
optional Type type = 1 [(mutate_options) = {
vital : true
abc : false
}];
llvm-svn: 220679
2014-10-27 13:25:59 +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
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
c0126864a0
clang-format: [Java] Understand string literal concatenation.
...
Before:
String someString = "abc" + "cde";
After:
String someString = "abc"
+ "cde";
llvm-svn: 220287
2014-10-21 11:34:53 +00:00
Daniel Jasper
d78c422378
clang-format: [Java] Fix formatting of multiple annotations.
...
Before:
@SuppressWarnings(value = "unchecked")
@Author(name = "abc") public void doSomething() {
}
After:
@SuppressWarnings(value = "unchecked")
@Author(name = "abc")
public void doSomething() {
}
llvm-svn: 220286
2014-10-21 11:17:56 +00:00
Daniel Jasper
5ffcb7fe90
clang-format: [Java] Fix space in generic method calls.
...
Before:
A.<B>doSomething();
After:
A.<B>doSomething();
llvm-svn: 220285
2014-10-21 11:13:31 +00:00
Daniel Jasper
fd68191db4
clang-format: [Java] Improve annotation handling.
...
Before:
@SuppressWarnings(
value = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") public static int iiiiiiiiiiiiiiiiiiiiiiii;
After:
@SuppressWarnings(value = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
public static int iiiiiiiiiiiiiiiiiiiiiiii;
llvm-svn: 220284
2014-10-21 10:58:14 +00:00
Daniel Jasper
c7d024ac53
clang-format: [Java] Make annotation formatting more consistent.
...
Before:
DoSomething(new A() {
@Override public String toString() {
}
});
After:
DoSomething(new A() {
@Override
public String toString() {
}
});
llvm-svn: 220282
2014-10-21 10:02:03 +00:00
Daniel Jasper
16b107e9f0
clang-format: [Java] Improve generic support.
...
Before:
Iterable< ? > a;
Iterable< ? extends SomeObject > a;
After:
Iterable<?> a;
Iterable<? extends SomeObject> a;
llvm-svn: 220281
2014-10-21 09:57:09 +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
f1f0c35632
clang-format: [Java] Support annotations with parameters.
...
Before:
@SuppressWarnings
(value = "unchecked") public void doSomething() { .. }
After:
@SuppressWarnings(value = "unchecked")
public void doSomething() { .. }
llvm-svn: 220279
2014-10-21 09:25:39 +00:00
Daniel Jasper
fab69ff095
clang-format: [Java] Wrap after each function annotation.
...
Before:
@Override public String toString() { .. }
After:
@Override
public String toString() { .. }
llvm-svn: 220274
2014-10-21 08:24:18 +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
f26c755d42
clang-format: [Java] Don't break immediately after "throws".
...
Before:
public void doSooooooooooooooooooooooooooomething() throws
LooooooooooooooooooooooooooooongException {}
After:
public void doSooooooooooooooooooooooooooomething()
throws LooooooooooooooooooooooooooooongException {}
llvm-svn: 220041
2014-10-17 13:36:14 +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
Benjamin Kramer
d0eed3a006
Format: ArrayRefize some implicit copies away.
...
NFC.
llvm-svn: 219000
2014-10-03 18:52:48 +00:00
Daniel Jasper
67f8ad258f
clang-format: [JS] Support AllowShortFunctionsOnASingleLine.
...
Specifically, this also counts for stuff like (with style "inline"):
var x = function() {
return 1;
};
llvm-svn: 218689
2014-09-30 17:57:06 +00:00
Daniel Jasper
1779d438bc
clang-format: [JS] Improve formatting of function literals in chains
...
Before:
getSomeLongPromise(.....)
.then(
function(value) {
body();
body();
})
.thenCatch(function(error) {
body();
body();
});
After:
getSomeLongPromise(.....)
.then(function(value) {
body();
body();
})
.thenCatch(function(error) {
body();
body();
});
llvm-svn: 218595
2014-09-29 07:54:54 +00:00
Nico Weber
7533b4dada
clang-format: Don't let -style=Chromium imply c++03 template formatting.
...
Chromium's now using some c++11 language features, so it's now fine that
clang-format produces vector<vector<int>>.
llvm-svn: 218392
2014-09-24 17:17:32 +00:00
Daniel Jasper
3549ea1a73
clang-format: [JS] add space before operator 'in'.
...
Before:
return ('aaa')in bbbb;
After:
return ('aaa') in bbbb;
llvm-svn: 218119
2014-09-19 10:48:15 +00:00
Daniel Jasper
540dbe29bc
clang-format: Prevent column layout if elements aren't uniform enough.
...
This patch only considers the difference between the length of the
shortest and longest element, but we might want to look at other
features (token count, etc.) in future.
Before:
std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{
aaaaaaa, aaaaaaaaaa,
aaaaa, aaaaaaaaaaaaaaa,
aaa, aaaaaaaaaa,
a, aaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa,
aaaaaaa, a};
After:
std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{
aaaaaaa, aaaaaaaaaa, aaaaa, aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a,
aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa, aaaaaaa, a};
llvm-svn: 218111
2014-09-19 08:28:43 +00:00
Daniel Jasper
a41aa536dc
clang-format: Undo r216377.
...
It has proven to not be a food idea in many case.
llvm-svn: 218107
2014-09-19 08:01:25 +00:00
Daniel Jasper
b23e20b7f5
clang-format: Allow unbroken ::: in inline assembly.
...
Before:
asm volatile("nop" :: : "memory");
After:
asm volatile("nop" ::: "memory");
Patch by Eugene Toder. Thank you.
llvm-svn: 217883
2014-09-16 16:36:57 +00:00
Daniel Jasper
c58c70e2f3
clang-format: Basic support for Java.
...
llvm-svn: 217759
2014-09-15 11:21:46 +00:00
Daniel Jasper
ac043c900c
clang-format: Add option to break before non-assignment operators.
...
This will allow:
int aaaaaaaaaaaaaa =
bbbbbbbbbbbbbb
+ ccccccccccccccc;
llvm-svn: 217757
2014-09-15 11:11:00 +00:00
Daniel Jasper
d6f17d83a3
clang-format: Improve line breaks at function calls.
...
Before:
EXPECT_CALL(SomeObject, SomeFunction(Parameter)).Times(2).WillRepeatedly(
Return(SomeValue));
After:
EXPECT_CALL(SomeObject, SomeFunction(Parameter))
.Times(2)
.WillRepeatedly(Return(SomeValue));
llvm-svn: 217687
2014-09-12 16:35:28 +00:00
Roman Kashitsyn
650ecb53ca
Fix bug 20892 - clang-format does not handle C-style comments
...
Summary:
http://llvm.org/bugs/show_bug.cgi?id=20892
Add support of C-style formatting enabling/disabling directives. Now the following two styles are supported:
// clang-format on
/* clang-format on */
The flexibility in comments (support of extra spaces and/or slashes, etc.) is deliberately avoided to simplify search in large code bases.
Reviewers: djasper
Reviewed By: djasper
Subscribers: cfe-commits, curdeius, klimek
Differential Revision: http://reviews.llvm.org/D5309
llvm-svn: 217588
2014-09-11 14:47:20 +00:00
Daniel Jasper
b87899b567
clang-format: Add option to allow short case labels on a single line.
...
On a single line:
switch (a) {
case 1: x = 1; return;
case 2: x = 2; return;
default: break;
}
Not on a single line:
switch (a) {
case 1:
x = 1;
return;
case 2:
x = 2;
return;
default:
break;
}
This partly addresses llvm.org/PR16535. In the long run, we probably want to
lay these out in columns.
llvm-svn: 217501
2014-09-10 13:11:45 +00:00
Daniel Jasper
23376259c0
clang-format: [JS] Support regex literals with trailing escaped slash.
...
Before:
var regex = / a\//; int i;
After:
var regex = /a\//;
int i;
This required pushing the Lexer into its wrapper class and generating a
new one in this specific case. Otherwise, the sequence get lexed as a
//-comment. This is hacky, but I don't know a better way (short of
supporting regex literals in the Lexer).
Pushing the Lexer down seems to make all the call sites simpler.
llvm-svn: 217444
2014-09-09 14:37:39 +00:00
Daniel Jasper
90ebc98e3d
clang-format: [JS] Format embedded function literals more efficently.
...
Before:
return {
a: a,
link:
function() {
f(); //
},
link:
function() {
f(); //
}
};
After:
return {
a: a,
link: function() {
f(); //
},
link: function() {
f(); //
}
};
llvm-svn: 217238
2014-09-05 09:27:38 +00:00
Daniel Jasper
3a038de3c8
clang-format: [JS] JavaScript does not have the */&/&& madness.
...
Before:
e&& e.SomeFunction();
After:
e && e.SomeFunction();
Yeah, this might be useful for C++, too, but it is not such a frequent
pattern there (plus the fix is much harder).
llvm-svn: 217237
2014-09-05 08:53:45 +00:00
Daniel Jasper
3f69ba1075
clang-format: [JS] Better support for empty function literals.
...
Before:
SomeFunction(function(){});
After:
SomeFunction(function() {});
llvm-svn: 217236
2014-09-05 08:42:27 +00:00
Daniel Jasper
97bfb7b1ba
clang-format: [JS] Fix indentation in dict literals.
...
Before:
return {
'finish':
//
a
};
After:
return {
'finish':
//
a
};
llvm-svn: 217235
2014-09-05 08:29:31 +00:00
Daniel Jasper
4db69bd542
clang-format: [JS] Support alternative operator names as identifiers.
...
Before:
not. and . or . not_eq = 1;
After:
not.and.or.not_eq = 1;
llvm-svn: 217179
2014-09-04 18:23:42 +00:00
Daniel Jasper
8f2e94c8ab
clang-format: [JS] Supprot "catch" as function name.
...
Before:
someObject.catch ();
After:
someObject.catch();
llvm-svn: 217158
2014-09-04 15:03:34 +00:00
Daniel Jasper
94e11d02d8
clang-format: [JS] Support comments in dict literals.
...
Before:
var stuff = {
// comment for update
update : false,
// comment for update
modules : false,
// comment for update
tasks : false
};
After:
var stuff = {
// comment for update
update : false,
// comment for update
modules : false,
// comment for update
tasks : false
};
llvm-svn: 217157
2014-09-04 14:58:30 +00:00
Daniel Jasper
db986eb6bb
clang-format: Add an option 'SpaceAfterCStyleCast'.
...
This permits to add a space after closing parenthesis of a C-style cast.
Defaults to false to preserve old behavior.
Fixes llvm.org/PR19982.
Before:
(int)i;
After:
(int) i;
Patch by Marek Kurdej.
llvm-svn: 217022
2014-09-03 07:37:29 +00:00
Daniel Jasper
73e171f76d
clang-format: Fix unary operator detection in corner case.
...
Before:
decltype(* ::std::declval<const T &>()) void F();
After:
decltype(*::std::declval<const T &>()) void F();
llvm-svn: 216724
2014-08-29 12:54:38 +00:00
David Blaikie
49cc3181a2
Overload SourceManager::overrideFileContents so that unconditionally passing ownership is explicitly done using unique_ptr.
...
Only those callers who are dynamically passing ownership should need the
3 argument form. Those accepting the default ("do pass ownership")
should do so explicitly with a unique_ptr now.
llvm-svn: 216614
2014-08-27 20:54:45 +00:00
Rafael Espindola
d87f8d76e0
Update for LLVM api change.
...
llvm-svn: 216585
2014-08-27 20:03:29 +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
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
Aaron Ballman
dd69ef38db
C++1y is now C++14!
...
Changes diagnostic options, language standard options, diagnostic identifiers, diagnostic wording to use c++14 instead of c++1y. It also modifies related test cases to use the updated diagnostic wording.
llvm-svn: 215982
2014-08-19 15:55:55 +00:00
Daniel Jasper
ea79ea1627
clang-format: Prefer breaking after return type over template param
...
Before:
typename aaaaaaaaaa<aaaaaa>::aaaaaaaaaaa aaaaaaaaaa<
aaaaaa>::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bool *aaaaaaaaaaaaaaaaaa,
bool *aa) {}
After:
typename aaaaaaaaaa<aaaaaa>::aaaaaaaaaaa
aaaaaaaaaa<aaaaaa>::aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
bool *aaaaaaaaaaaaaaaaaa, bool *aa) {}
llvm-svn: 215693
2014-08-15 05:00:39 +00:00
Daniel Jasper
497d9fdcf8
clang-format: [proto] Understand text-format nesting without :
...
Before:
option (MyProto.options) = {
field_c : "OK" msg_field{field_d : 123}
};
After:
option (MyProto.options) = {
field_c : "OK"
msg_field{field_d : 123}
};
(Note that the colon after "msg_field" is optional).
llvm-svn: 215692
2014-08-15 05:00:35 +00:00
Daniel Jasper
db76479d73
clang-format: Fix AlwaysBreakAfterDefinitionReturnType in Stroutrup style
...
Before:
template <class T>
T *f(T &c) // Problem here: no line break before f
{
return NULL;
}
After:
template <class T>
T *
f(T &c)
{
return NULL;
}
Patch by Marek Kurdej, thank you!
llvm-svn: 215633
2014-08-14 11:36:03 +00:00
Daniel Jasper
1904e9b98d
clang-format: Support chained dereferenced assignments.
...
Before:
x = * a(x) = *a(y);
After:
x = *a(x) = *a(y);
llvm-svn: 215632
2014-08-14 10:53:19 +00:00
Daniel Jasper
78b4533acf
clang-format: Support breaking arguments of function type typedefs.
...
Before:
typedef size_t (*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(
const aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
After:
typedef size_t (*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(
const aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
llvm-svn: 215631
2014-08-14 10:52:56 +00:00
Benjamin Kramer
2f5db8b3db
Header guard canonicalization, clang part.
...
Modifications made by clang-tidy with minor tweaks.
llvm-svn: 215557
2014-08-13 16:25:19 +00:00
Manuel Klimek
5f594f80f4
Fix crasher bug in clang-format.
...
llvm-svn: 215549
2014-08-13 14:00:41 +00:00
Daniel Jasper
839922e9d1
clang-format: Format long lists in columns if without bin-packing.
...
After (even with BinPacking = false):
const Aaaaaa aaaaa = {
aaaaa, bbbbb, ccccc, ddddd, eeeee, ffffff, ggggg, hhhhhh,
iiiiii, jjjjjj, kkkkkk, aaaaa, bbbbb, ccccc, ddddd, eeeee,
ffffff, ggggg, hhhhhh, iiiiii, jjjjjj, kkkkkk,
};
Before:
<each element on its own line>
This fixes http://llvm.org/PR20623 .
llvm-svn: 215529
2014-08-13 08:46:21 +00:00
Daniel Jasper
343643b979
clang-format: Understand #defines defining system includes.
...
Before:
#define MY_IMPORT < a / b >
After:
#define MY_IMPORT <a/b>
llvm-svn: 215527
2014-08-13 08:29:18 +00:00
Daniel Jasper
598dd330e8
clang-format: Avoid bad line break.
...
Before:
int
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(const
typename aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa);
After:
int aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
const typename aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa);
llvm-svn: 215442
2014-08-12 13:22:26 +00:00
Roman Kashitsyn
a043cedf0a
Fixes bug 20587 - Add K&R break before braces style
...
Summary:
http://llvm.org/bugs/show_bug.cgi?id=20587
Added K&R style. It could be enabled by the following option:
```
BreakBeforeBraces: KernighanRitchie
```
This style is like `Attach`, but break *only* before function
declarations.
As I can see, no additional logic required to support this style, any
style different from other styles automagically satisfies K&R.
Reviewers: djasper
Reviewed By: djasper
Subscribers: cfe-commits, klimek
Differential Revision: http://reviews.llvm.org/D4837
llvm-svn: 215354
2014-08-11 12:18:01 +00:00
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
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
NAKAMURA Takumi
7160c4d22f
FormatTokenLexer: Avoid non-static member initializer.
...
llvm-svn: 214976
2014-08-06 16:53: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
a382cbe4eb
clang-format: [proto] Improve formatting of text-proto options.
...
Initial patch and tests by Kaushik Sridharan, thank you!
llvm-svn: 214084
2014-07-28 14:08:09 +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
David Blaikie
3875a82d42
Remove uses of the redundant ".reset(nullptr)" of unique_ptr, in favor of ".reset()"
...
It's also possible to just write "= nullptr", but there's some question
of whether that's as readable, so I leave it up to authors to pick which
they prefer for now. If we want to discuss standardizing on one or the
other, we can do that at some point in the future.
llvm-svn: 213439
2014-07-19 01:06:45 +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
Alp Toker
958027b698
Fix typos
...
Also consolidate 'backward compatibility'
llvm-svn: 212974
2014-07-14 19:42:55 +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
Rafael Espindola
2d2b420ab9
Update for llvm api change.
...
llvm-svn: 212408
2014-07-06 17:43:24 +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
Saleem Abdulrasool
fbfbaf6a93
Permit -Wswitch coverage for enumerations.
...
Thanks to David Blakie and Richard Smith for pointing out that we can retain the
-Wswitch coverage while avoiding the warning from GCC by pushing the unreachable
outside of the switch!
llvm-svn: 210812
2014-06-12 19:33:26 +00:00
Saleem Abdulrasool
c9340d2575
Basic: fix warnings from GCC
...
tools/clang/lib/Basic/DiagnosticIDs.cpp: In function ‘clang::DiagnosticIDs::Level toLevel(clang::diag::Severity)’:
tools/clang/lib/Basic/DiagnosticIDs.cpp:382:1: warning: control reaches end of non-void function [-Wreturn-type]
tools/clang/lib/Format/Format.cpp: In member function ‘virtual std::string clang::format::ParseErrorCategory::message(int) const’:
tools/clang/lib/Format/Format.cpp:282:1: warning: control reaches end of non-void function [-Wreturn-type]
Add a default cases that asserts that we handle the severity, parse error.
llvm-svn: 210804
2014-06-12 17:43:37 +00:00
Rafael Espindola
c080917ec2
Replace llvm::error_code with std::error_code.
...
llvm-svn: 210780
2014-06-12 14:02:15 +00:00
Rafael Espindola
6d0d89b49c
Fix typo.
...
Thanks to Alp Toker for noticing.
llvm-svn: 210744
2014-06-12 03:31:26 +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
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