Manuel Klimek
1fcbe675fa
Correctly handle escaped newlines when the next token starts without a space.
...
We will need this to correctly handle conflict markers inside macro
definitions.
llvm-svn: 206029
2014-04-11 12:27:47 +00:00
Daniel Jasper
220c0d1f5e
clang-format: Fix false positive in braced list detection in protos.
...
llvm-svn: 205954
2014-04-10 07:27:12 +00:00
Daniel Jasper
f9fc215f82
clang-format: Treat a trailing comment like a trailing comma in braced lists.
...
Before:
static StructInitInfo module = {MODULE_BUILTIN, /* type */
"streams" /* name */
};
After:
static StructInitInfo module = {
MODULE_BUILTIN, /* type */
"streams" /* name */
};
This fixes llvm.org/PR19378.
llvm-svn: 205851
2014-04-09 13:18:49 +00:00
Daniel Jasper
21397a3232
clang-format: Fix bug where clang-format would break the code.
...
Before, it would turn:
SomeFunction([]() { // Cool function..
return 43;
});
Into this:
SomeFunction([]() { // Cool function.. return 43; });
llvm-svn: 205849
2014-04-09 12:21:48 +00:00
Daniel Jasper
3ae6f5a47b
clang-format: Improve format of calls with several lambdas.
...
Before:
SomeFunction([]() {
int i = 42;
return i;
},
[]() {
int j = 43;
return j;
});
After:
SomeFunction([]() {
int i = 42;
return i;
},
[]() {
int j = 43;
return j;
});
llvm-svn: 205848
2014-04-09 12:08:39 +00:00
Daniel Jasper
f9a0906b98
clang-format: Allow breaking between trailing annotations in more cases.
...
Before:
void aaaaaaaaaaaaaa(aaaaaaaa aaa) override AAAAAAAAAAAAAAAAAAAAAAAA(
aaaaaaaaaaaaaaa);
After:
void aaaaaaaaaaaaaa(aaaaaaaa aaa) override
AAAAAAAAAAAAAAAAAAAAAAAA(aaaaaaaaaaaaaaa);
llvm-svn: 205846
2014-04-09 10:29:11 +00:00
Daniel Jasper
b48d3afcd5
clang-format: Keep more trailing annotations on the same line.
...
More precisely keep all short annotations (<10 characters) on the same
line if possible. Previously, clang-format would only prefer to do so
for "const", "override" and "final". However, it seems to be generally
preferable, especially because some codebases have to wrap those in
macros for backwards compatibility.
Before:
void someLongFunction(int someLongParameter)
OVERRIDE {}
After:
void someLongFunction(
int someLongParameter) OVERRIDE {}
This fixes llvm.org/PR19363.
llvm-svn: 205845
2014-04-09 10:01:49 +00:00
Daniel Jasper
b175d57edc
clang-format: Recognize lists ending in trailing commas correctly.
...
Previously, this did not look through trailing comments leading to a few
formatting oddities.
llvm-svn: 205843
2014-04-09 09:53:23 +00:00
Daniel Jasper
b77105d2ce
clang-format: Fix incorrect multi-block-parameter computation.
...
llvm-svn: 205763
2014-04-08 14:04:31 +00:00
Daniel Jasper
139d4a3875
clang-format: Correctly understand arrays of pointers.
...
Before:
A<int * []> a;
After:
A<int *[]> a;
This fixes llvm.org/PR19360.
llvm-svn: 205761
2014-04-08 13:07:41 +00:00
Daniel Jasper
d74cf40386
clang-format: Extend AllowShortFunctions.. to only merge inline functions.
...
Before AllowShortFunctionsOnASingleLine could either be true, merging
all functions, or false, merging no functions. This patch adds a third
value "Inline", which can be used to only merge short functions defined
inline in a class, i.e.:
void f() {
return 42;
}
class C {
void f() { return 42; }
};
llvm-svn: 205760
2014-04-08 12:46:38 +00:00
Daniel Jasper
922349cdba
clang-format: Don't merge simple blocks in case statements.
...
Before:
switch (a) {
case 1: { return 'a'; }
}
After:
switch (a) {
case 1: {
return 'a';
}
}
llvm-svn: 205611
2014-04-04 06:46:23 +00:00
Daniel Jasper
5c33265c9e
clang-format: Prefer an additional line-break over hanging indent.
...
Don't allow the RHS of an operator to be split over multiple
lines unless there is a line-break right after the operator.
Before:
if (aaaa && bbbbb || // break
cccc) {
}
After:
if (aaaa &&
bbbbb || // break
cccc) {
}
In most cases, this seems to increase readability.
llvm-svn: 205527
2014-04-03 12:00:33 +00:00
Daniel Jasper
2b7556ec16
x
...
llvm-svn: 205526
2014-04-03 12:00:27 +00:00
Daniel Jasper
cc7bf7fda1
clang-format: Understand that "auto" is a type.
...
Before:
MACRO(auto * a);
After:
MACRO(auto *a);
llvm-svn: 205517
2014-04-03 09:00:49 +00:00
Daniel Jasper
e1e4319ab7
clang-format: Support configurable list of foreach-macros.
...
This fixes llvm.org/PR17242.
Patch by Brian Green, thank you!
llvm-svn: 205307
2014-04-01 12:55:11 +00:00
Daniel Jasper
240dfda352
clang-format: Solve issues found and fixed by clang-tidy.
...
llvm-svn: 205193
2014-03-31 14:23:49 +00:00
Daniel Jasper
03b1bc7a2a
clang-format: Fix aligning of comments and escaped newlines in macros.
...
Before:
#define A \
int i; /*a*/ \
int jjj; /*b*/
After:
#define A \
int i; /*a*/ \
int jjj; /*b*/
llvm-svn: 205011
2014-03-28 15:06:01 +00:00
Manuel Klimek
9481556eb6
Get rid of the adapted isLiteral method.
...
We don't want to deviate from clang's standard terminology.
llvm-svn: 204997
2014-03-28 09:27:09 +00:00
Daniel Jasper
395193c7a0
clang-format: Recognize more ObjC blocks with parameters/return type.
...
llvm-svn: 204990
2014-03-28 07:48:59 +00:00
Manuel Klimek
1f9d80ac66
Improve handling of bool expressions in template arguments.
...
Now correctly formats:
foo<true && false>();
llvm-svn: 204950
2014-03-27 19:00:52 +00:00
Daniel Jasper
5d2587daa2
clang-format: Avoid line-breaks that increase the current column.
...
While these might make sense for some rule (e.g. break after multi-line
operand), they generally appear ugly and confusing.
Before:
fffffffffff(R\"x(
multiline raw string literal xxxxxxxxxxxxxx
)x\" + bbbbbb)
After:
fffffffffff(R\"x(
multiline raw string literal xxxxxxxxxxxxxx
)x\" +
bbbbbb)
llvm-svn: 204937
2014-03-27 16:14:13 +00:00
Daniel Jasper
9f388d0404
clang-format: Extract getNewLineColumn out of addTokenOnNewLine.
...
No functional changes intended.
llvm-svn: 204930
2014-03-27 14:33:30 +00:00
Manuel Klimek
f81e5c0e50
Fix bool expression special case.
...
Clang-format now correctly formats:
some_type<a * b> v;
template <bool a, bool b> typename enabled_if<a && b>::type f() {}
llvm-svn: 204913
2014-03-27 11:17:36 +00:00
Daniel Jasper
c13ee34378
clang-format: Correctly identify ObjC Block with return type.
...
llvm-svn: 204905
2014-03-27 09:43:54 +00:00
Daniel Jasper
a65e887587
clang-format: Fix incorrect &/* detection.
...
Before:
STATIC_ASSERT((a &b) == 0);
After:
STATIC_ASSERT((a & b) == 0);
llvm-svn: 204709
2014-03-25 10:52:45 +00:00
Daniel Jasper
a26fc5c9db
clang-format: Add flag for removing empty lines at the start of blocks.
...
This unbreaks polly-formatting-tests and we can make a decision for
LLVM style independently.
llvm-svn: 204467
2014-03-21 13:43:14 +00:00
Daniel Jasper
01b35482e5
clang-format: Don't remove empty lines at the start of namespaces.
...
llvm-svn: 204462
2014-03-21 13:03:33 +00:00
Daniel Jasper
11164bdaf5
clang-format: Remove empty lines at the beginning of blocks.
...
They very rarely aid readability.
Formatting:
void f() {
if (a) {
f();
}
}
Now leads to:
void f() {
if (a) {
f();
}
}
llvm-svn: 204460
2014-03-21 12:58:53 +00:00
Daniel Jasper
a125d53a7b
clang-format: Let a trailing comma in braced lists enforce linebreaks.
...
Before:
vector<int> x{1, 2, 3, 4, };
After:
vector<int> x{
1, 2, 3, 4,
};
This fixes llvm.org/PR18519.
llvm-svn: 204458
2014-03-21 12:38:57 +00:00
Daniel Jasper
28df0a356e
clang-format: Fix for r204456.
...
llvm-svn: 204457
2014-03-21 12:15:40 +00:00
Daniel Jasper
14e58e5290
clang-format: Preserve meaning of trailing comments on parameters.
...
Formatting:
SomeFunction(a,
b, // comment
c);
Before:
SomeFunction(a, b, // comment
c);
After:
SomeFunction(a,
b, // comment
c);
llvm-svn: 204456
2014-03-21 11:58:45 +00:00
Alexander Kornienko
ce08126733
clang-format: Detect function-like macros only when upper case is used.
...
Reviewers: djasper
Reviewed By: djasper
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D3110
llvm-svn: 204156
2014-03-18 14:35:20 +00:00
Manuel Klimek
819788da83
Fix crasher bug.
...
Due to not resetting the fake rparen data on the token when iterating
over annotated lines, we would pop the last element of the paren stack.
This patch fixes the underlying root cause, and makes the code more
robust against similar problems in the future:
- reset the first token when iterating on the same annotated lines due
to preprocessor branches
- never pop the last element from the paren stack, so we do not crash,
but rather incorrectly format
- add assert()s so we can figure out if our assumptions are violated
llvm-svn: 204140
2014-03-18 11:22:45 +00:00
Daniel Jasper
1fd6f1f8d6
clang-format: Indent from dict literal labels.
...
Before:
@{
NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :
regularFont,
};
After:
@{
NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee :
regularFont,
};
llvm-svn: 204041
2014-03-17 14:32:47 +00:00
Craig Topper
fb6b25b5e4
[C++11] Add 'override' keyword to virtual methods that override their base class.
...
llvm-svn: 203999
2014-03-15 04:29:04 +00:00
Alexander Kornienko
c2ee9cf861
Remove an unnecessary check for FormatTok not being null.
...
Summary:
This check hints clang analyzer, that FormatTok may be null, and it
reports a null pointer dereference error:
http://buildd-clang.debian.net/scan-build/report-827c64.html#Path28
Reviewers: djasper
Reviewed By: djasper
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D3040
llvm-svn: 203800
2014-03-13 13:59:48 +00:00
Daniel Jasper
ac7e34e778
clang-format: Prevent ObjC code from confusing the braced-init detection
...
This was leading to bad formatting, e.g.:
Before:
f(^{
@autoreleasepool {
if (a) {
g();
}
}
});
After:
f(^{
@autoreleasepool {
if (a) {
g();
}
}
});
llvm-svn: 203777
2014-03-13 10:11:17 +00:00
Daniel Jasper
da353cd5f1
clang-format: Fix crasher.
...
Caused by unknown tokens (e.g. "\n") not properly updating the state.
Example:
const char* c = STRINGIFY(
\na : b);
llvm-svn: 203645
2014-03-12 08:24:47 +00:00
Daniel Jasper
8f59ae537c
clang-format: Avoid unnecessary break before lambda return type.
...
Before:
auto aaaaaaaa = [](int i, // break
int j)
-> int {
return fffffffffffffffffffffffffffffffffffffff(i * j);
};
After:
auto aaaaaaaa = [](int i, // break
int j) -> int {
return fffffffffffffffffffffffffffffffffffffff(i * j);
};
llvm-svn: 203562
2014-03-11 11:03:26 +00:00
Daniel Jasper
a58dd5db29
clang-format: Fix another false positive in the lambda detection.
...
Before:
int i = (*b)[a] -> f();
After:
int i = (*b)[a]->f();
llvm-svn: 203557
2014-03-11 10:03:33 +00:00
Daniel Jasper
d3c7ab975f
clang-format: Fix incorrect lambda recognition exposed by r203452.
...
Before:
int i = a[a][a] -> f();
After:
int i = a[a][a]->f();
llvm-svn: 203556
2014-03-11 09:59:36 +00:00
Daniel Jasper
c580af96fa
clang-format: Detect weird macro lambda usage.
...
Before:
void f() {
MACRO((const AA & a) { return 1; });
}
After:
void f() {
MACRO((const AA &a) { return 1; });
}
llvm-svn: 203551
2014-03-11 09:29:46 +00:00
Daniel Jasper
84a12e18d3
clang-format: Add spaces between lambdas and comments.
...
Before:
void f() {
bar([]() {}// Does not respect SpacesBeforeTrailingComments
);
}
After:
void f() {
bar([]() {} // Does not respect SpacesBeforeTrailingComments
);
}
This fixes llvm.org/PR19017.
llvm-svn: 203466
2014-03-10 15:06:25 +00:00
Alexander Kornienko
4504f93901
Preserve hanging indent when breaking line comments.
...
Summary:
If we need to break the second line here:
// something: aaaaa aaaaa aaaaaa aaaaa aaaaa
// aaaaa aaaaa aaaaaa aaaaa aaaaa aaaaa
with the patch it will be turned to
// something: aaaaa aaaaa aaaaaa aaaaa aaaaa
// aaaaa aaaaa aaaaaa aaaaa aaaaa
// aaaaa
instead of
// something: aaaaa aaaaa aaaaaa aaaaa aaaaa
// aaaaa aaaaa aaaaaa aaaaa aaaaa
// aaaaa
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2988
llvm-svn: 203458
2014-03-10 13:14:56 +00:00
Daniel Jasper
81a20787db
clang-format: Add spaces around trailing/lambda return types.
...
Before:
int c = []()->int { return 2; }();
After:
int c = []() -> int { return 2; }();
llvm-svn: 203452
2014-03-10 10:02:02 +00:00
Ahmed Charles
dfca6f97bc
[C++11] Replace OwningPtr include with <memory>.
...
llvm-svn: 203389
2014-03-09 11:36:40 +00:00
Ahmed Charles
b89843299a
Replace OwningPtr with std::unique_ptr.
...
This compiles cleanly with lldb/lld/clang-tools-extra/llvm.
llvm-svn: 203279
2014-03-07 20:03:18 +00:00
Ahmed Charles
9a16beb8bc
Change OwningPtr::take() to OwningPtr::release().
...
This is a precursor to moving to std::unique_ptr.
llvm-svn: 203275
2014-03-07 19:33:25 +00:00
Alexander Kornienko
86b2dfdc3b
Fix operator<< recognition (PR19064).
...
llvm-svn: 203123
2014-03-06 15:13:08 +00:00