Daniel Jasper
56691b8cb9
clang-format: [JS] Ensure that formatting actually takes place in tests.
...
And fix formatting issue discovered by that :-).
llvm-svn: 239530
2015-06-11 13:29:20 +00:00
Manuel Klimek
f0c95b32ec
Fix crash in clang-format.
...
The following example used to crash clang-format.
#define a\
/**/}
Adjusting the indentation level cache for the line starting with the
comment would lead to an out-of-bounds array read.
llvm-svn: 239521
2015-06-11 10:14:13 +00:00
Daniel Jasper
229628b39e
clang-format: Don't add spaces in foreach macro definition.
...
Before clang-format would e.g. add a space into
#define Q_FOREACH(x, y)
which turns this into a non-function-like macro.
Patch by Strager Neds, thank you!
llvm-svn: 239513
2015-06-11 08:38:19 +00:00
Daniel Jasper
11ca263994
clang-format: [JS] Only special case top level object literal
...
assignments as enums.
Top level object literals are treated as enums, and their k/v pairs are put on
separate lines:
X.Y = {
A: 1,
B: 2
};
However assignments within blocks should not be affected:
function x() {
y = {a:1, b:2};
}
This change fixes the second case. Patch by Martin Probst.
llvm-svn: 239462
2015-06-10 09:21:09 +00:00
Daniel Jasper
dee894f6bb
clang-format: Support //!-comments, increase test coverage.
...
llvm-svn: 239404
2015-06-09 13:16:54 +00:00
Daniel Jasper
c83d76991c
clang-format: [JS] Hotfix for runtime issue with deeply nested JS code.
...
I have not succeeded in writing a proper test case for this yet and we
also need to solve the underlying fundamental problem of trying too
many combinations with nested blocks (basically this somewhat works
around our Dijkstra algorithm). Preventing this linebreak is good
anyways as usually the penalties never make us choose it (that's why I
can't create a test) and it also looks ugly.
Also cleaned up state comparison code that I discovered while hunting
this down.
llvm-svn: 239398
2015-06-09 11:39:22 +00:00
Daniel Jasper
6f2b88a398
clang-format: More eagerly wrap trailing return types.
...
Before:
template <typename T>
auto aaaaaaaaaaaaaaaaaaaaaa(T t) -> decltype(eaaaaaaaaaaaaaaa<T>(t.a)
.aaaaaaaa());
After:
template <typename T>
auto aaaaaaaaaaaaaaaaaaaaaa(T t)
-> decltype(eaaaaaaaaaaaaaaa<T>(t.a).aaaaaaaa());
Also add a test case for a difficult template parsing case I stumbled accross.
Needs fixing.
llvm-svn: 239149
2015-06-05 13:18:09 +00:00
Daniel Jasper
3b0f304517
clang-format: [JS] Let fat arrows have 'Assignment' precedence.
...
This is a more correct representation than using "Equality" introduced
in r238942 which was a quick fix to solve an actual regression.
According to the typescript spec, arrows behave like "low-precedence"
assignments.
Before:
var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) &&
aaaaaaaaaaaaaaaaaaaaa(bbbbbbb));
After:
var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) &&
aaaaaaaaaaaaaaaaaaaaa(bbbbbbb));
llvm-svn: 239137
2015-06-05 08:25:37 +00:00
Daniel Jasper
3c306e895e
clang-format: [JS] Let fat arrows have 'Equality' precedence.
...
This fixes a regression in literal formatting:
Before:
aaaaaaaaaaaaa = {
aaaaaaaaaaaaaaaaaaaaaaaaaaaa: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
};
After:
var aaaaaaaaaaaaaaaaaaaa = {
aaaaaaaaaaaaaaaaaaaaaaaaaaaa:
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
};
Also apply no-else-after-return policy.
llvm-svn: 238942
2015-06-03 17:08:40 +00:00
Daniel Jasper
5962fa80c2
clang-format: Properly reset BreakBeforeParameter when wrapping
...
operators to the new line.
Before:
LOG_IF(aaa == //
bbb)
<< a
<< b;
After:
LOG_IF(aaa == //
bbb)
<< a << b;
llvm-svn: 238911
2015-06-03 09:26:03 +00:00
Daniel Jasper
9970df1f79
clang-format: [JS] More aggressively keep array literals on one line.
...
Before:
var aaaaa: List<SomeThing> = [
new SomeThingAAAAAAAAAAAA(),
new SomeThingBBBBBBBBB()
];
After:
var aaaaa: List<SomeThing> =
[new SomeThingAAAAAAAAAAAA(), new SomeThingBBBBBBBBB()];
llvm-svn: 238909
2015-06-03 08:57:36 +00:00
Daniel Jasper
81dbb564a1
clang-format: [JS] Fix bug in type colon detection.
...
Before, this couldn't be formatted at all:
class X {
subs = {
'b': {
'c': 1,
},
};
}
llvm-svn: 238907
2015-06-03 08:43:18 +00:00
Daniel Jasper
e497beddb5
clang-format: [JS] Always add space after fat arrow.
...
Before:
return () =>[];
After:
return () => [];
llvm-svn: 238875
2015-06-02 22:06:07 +00:00
Daniel Jasper
d492b5ec03
clang-format: [JS] Array literal detection fix #4 .
...
llvm-svn: 238873
2015-06-02 21:57:51 +00:00
Daniel Jasper
1feab0f95e
clang-format: Don't try to detect C++ lambdas in other languages.
...
llvm-svn: 238845
2015-06-02 15:31:37 +00:00
Daniel Jasper
199d0c9e76
clang-format: [JS] Fix incorrect line length calculation.
...
llvm-svn: 238841
2015-06-02 15:14:21 +00:00
Daniel Jasper
40432cee93
clang-format: [JS] Array literal detection fix #3 .
...
llvm-svn: 238839
2015-06-02 15:04:29 +00:00
Daniel Jasper
4284e3623c
clang-format: [JS] Fix another regression when detecting array literals.
...
llvm-svn: 238835
2015-06-02 14:20:08 +00:00
Daniel Jasper
5ce80de4de
clang-format: [JS] Fix regression of detecting array literals.
...
llvm-svn: 238832
2015-06-02 13:56:43 +00:00
Manuel Klimek
21b4117a12
Remove error message when using the fallback style.
...
llvm-svn: 238822
2015-06-02 11:52:15 +00:00
Daniel Jasper
1699eca119
clang-format: [JS] Making arrow function wrapping more consistent.
...
Before:
someFunction(() =>
{
doSomething(); // break
})
.doSomethingElse( // break
);
After:
someFunction(() => {
doSomething(); // break
})
.doSomethingElse( // break
);
This is still bad, but at least it is consistent with what we do for other
function literals. Added corresponding tests.
llvm-svn: 238736
2015-06-01 09:56:32 +00:00
Benjamin Kramer
c7551a4843
[Format] Move UnwrappedLines instead of copying.
...
No functional change intended.
llvm-svn: 238673
2015-05-31 11:18:05 +00:00
Daniel Jasper
be520bd1a6
clang-format: NFC. Cleanup after r237895.
...
Specifically adhere to LLVM Coding Standards (no 'else' after
return/break/continue) and remove yet another implementation of
paren counting. We already have enough of those in the
UnwrappedLineParser.
No functional changes intended.
llvm-svn: 238672
2015-05-31 08:51:54 +00:00
Daniel Jasper
cd8d4ff985
clang-format: [JS] Fix line breaks in computed property names.
...
Before:
let foo = {
[someLongKeyHere]: 1,
someOtherLongKeyHere: 2, [keyLongEnoughToWrap]: 3,
lastLongKey: 4
};
After:
let foo = {
[someLongKeyHere]: 1,
someOtherLongKeyHere: 2,
[keyLongEnoughToWrap]: 3,
lastLongKey: 4
};
llvm-svn: 238671
2015-05-31 08:40:37 +00:00
Daniel Jasper
8c42d445e3
clang-format: [JS] Support ES6 computed property names.
...
Before:
var x = {
[a]: 1,
b: 2
};
After:
var x = {
[a]: 1,
b: 2
};
llvm-svn: 238544
2015-05-29 06:19:49 +00:00
Benjamin Kramer
ddf1cda2c2
[Format] Skip creating temporary std::strings when filling another string.
...
No functional change intended.
llvm-svn: 238466
2015-05-28 19:55:49 +00:00
Daniel Jasper
f841d3a6c1
clang-format: Lower binding strengths created by the [] created by ObjC
...
method expressions and array literals. They should not bind stronger
than regular parentheses or the braces of braced lists.
Specific test case in JavaScript:
Before:
var aaaaa: List<
SomeThing> = [new SomeThingAAAAAAAAAAAA(), new SomeThingBBBBBBBBB()];
After:
var aaaaa: List<SomeThing> = [
new SomeThingAAAAAAAAAAAA(),
new SomeThingBBBBBBBBB()
];
llvm-svn: 238400
2015-05-28 07:21:50 +00:00
Daniel Jasper
3e0dcc27d5
clang-format: [JS] Fix incorrect detection of ternary expressions.
...
A definintion like this could not be formatted at all:
constructor({aa}: {
aa?: string,
aaaaaaaa?: string,
aaaaaaaaaaaaaaa?: boolean,
aaaaaa?: List<string>
}) {
}
llvm-svn: 238291
2015-05-27 05:37:40 +00:00
Daniel Jasper
3273930d9a
clang-format: Fix false positive in function annotation detection.
...
llvm-svn: 238285
2015-05-27 04:55:47 +00:00
Daniel Jasper
0843434e74
clang-format: Guard the bin-packing in braced lists on BinPackArguments
...
instead of BinPackParameters. Braced lists are used as constructor
calls in many places and so the bin-packing should follow what is done
for other calls and not what is done for function declarations.
llvm-svn: 238184
2015-05-26 07:26:26 +00:00
Daniel Jasper
0805199185
clang-format: [JS] Support ES6 spread operator.
...
Specifically, don't add a space before it.
Before:
someFunction(... a);
var x = [1, 2, ... a];
After:
someFunction(...a);
var x = [1, 2, ...a];
llvm-svn: 238183
2015-05-26 07:18:56 +00:00
Daniel Jasper
1a02822704
clang-format: Fix child-formatting in macros.
...
This fixes a case where the column limit was incorrectly calculated
leading to a macro like this:
#define A \
[] { \
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx( \
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx); \
}
exceeding the column limit.
llvm-svn: 238182
2015-05-26 07:03:42 +00:00
Manuel Klimek
79e06081a3
clang-format: [JS] Better support for fat arrows.
...
Assigns a token type (TT_JsFatArrow) to => tokens, and uses that to
more easily recognize and format fat arrow functions.
Improves function parsing to better recognize formal parameter
lists and return type declarations.
Recognizes arrow functions and parse function bodies as child blocks.
Patch by Martin Probst.
llvm-svn: 237895
2015-05-21 12:23:34 +00:00
Anders Waldenborg
b09075a240
clang-format: Add space in function pointers with SpaceBeforeParens=Always
...
"void (*my_function)(void)" should become "void (*my_function) (void)" when
SpaceBeforeParens is set to 'Always'
Differential Revision: http://reviews.llvm.org/D9835
llvm-svn: 237704
2015-05-19 16:54:26 +00:00
Daniel Jasper
9310166a63
clang-format: Improve *-detection.
...
Before:
S << a *(10);
After:
S << a * (10);
This fixes llvm.org/PR16500.
llvm-svn: 237690
2015-05-19 12:29:27 +00:00
Daniel Jasper
d6e09e85f9
clang-format: Improve for-loop formatting.
...
Before:
for (SmallVectorImpl<TemplateIdAnnotationn *>::iterator I =
Container.begin(),
E = Container.end();
I != E; ++I)
After:
for (SmallVectorImpl<TemplateIdAnnotationn *>::iterator
I = Container.begin(),
E = Container.end();
I != E; ++I)
This fixes llvm.org/PR23544.
llvm-svn: 237688
2015-05-19 11:51:39 +00:00
Daniel Jasper
fa3f8fbed8
clang-format: Support #include_next
...
Before:
#include_next < test.h >
After:
#include_next <test.h>
This fixes llvm.org/PR23500
llvm-svn: 237686
2015-05-19 11:22:29 +00:00
Daniel Jasper
f5e5ee6d69
clang-format: Correctly detect casts to qualified types.
...
Before:
ns::E f() { return (ns::E) - 1; }
After:
ns::E f() { return (ns::E)-1; }
This fixes llvm.org/PR23503.
llvm-svn: 237684
2015-05-19 11:18:39 +00:00
Daniel Jasper
ed41f774fc
clang-format: Fix regression caused by r237244.
...
Before:
[call aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.
aaaaaaaa];
After:
[call aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa
.aaaaaaaa];
This merely papers over the fact that we aren't parsing ObjC method calls
correctly. Also, the indentation is weird.
llvm-svn: 237681
2015-05-19 11:06:33 +00:00
Daniel Jasper
3c883d1dcc
clang-format: Fix another regression caused by r237565.
...
Before:
class C : test {
class D : test{void f(){int i{2};
}
}
;
}
;
After:
class C : test {
class D : test {
void f() { int i{2}; }
};
};
llvm-svn: 237569
2015-05-18 14:49:19 +00:00
Daniel Jasper
cec9ffd2a2
clang-format: Fix regression introduced by r237565.
...
Before:
class C : public D {
SomeClass SC { 2 };
};
After:
class C : public D {
SomeClass SC{2};
};
llvm-svn: 237568
2015-05-18 14:12:24 +00:00
Daniel Jasper
47bbda0939
clang-format: Improve detection of macros annotating functions.
...
Before:
ASSERT("aaaaaaaaaaaaaaa")
<< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<< bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
After:
ASSERT("aaaaaaaaaaaaaaa") << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
<< bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
Also cleanup implementation a bit and only mark closing parenthesis of
these annotations.
llvm-svn: 237567
2015-05-18 13:47:23 +00:00
Daniel Jasper
adba2aadf2
clang-format: Allow braced initializers in template arguments of class
...
specializations.
Before:
template <class T>
struct S < std::is_arithmetic<T> {
} > {};
After:
template <class T> struct S<std::is_arithmetic<T>{}> {};
llvm-svn: 237565
2015-05-18 12:52:00 +00:00
Daniel Jasper
f090f031bc
clang-format: Support function annotations in macros.
...
Before:
DEPRECATED("Use NewClass::NewFunction instead.") string
OldFunction(const string ¶meter) {}
After:
DEPRECATED("Use NewClass::NewFunction instead.")
string OldFunction(const string ¶meter) {}
llvm-svn: 237562
2015-05-18 09:47:22 +00:00
Daniel Jasper
0928553eec
clang-format: Properly align ObjC string literals.
...
Before:
NSString s = @"a"
"b"
"c";
NSString s = @"a"
@"b"
@"c";
After:
NSString s = @"a"
"b"
"c";
NSString s = @"a"
@"b"
@"c";
This fixes llvm.org/PR23536.
llvm-svn: 237538
2015-05-17 08:13:23 +00:00
Daniel Jasper
2fd16632bc
clang-format: Improve line wrapping around << operators.
...
Generally, clang-format tries to keep label-value pairs on a single
line for stream operators. However, we should not do that if there is
just a single such pair, as that doesn't help much.
Before:
llvm::errs() << "aaaaaaaaaaaa: " << aaaaaaa(aaaaaaaaa,
aaaaaaaaa);
After:
llvm::errs() << "aaaaaaaaaaaa: "
<< aaaaaaa(aaaaaaaaa, aaaaaaaaa);
Also remove old test case that was testing actual behavior any more.
llvm-svn: 237535
2015-05-17 07:27:09 +00:00
Daniel Jasper
3ca283ada3
clang-format: Slightly change format decisions around macro annotations.
...
Before:
bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
GUARDED_BY(aaaaaaaaaaaa) = aaaaaaaaaaaaaaaaaaaaaaaaa;
After:
bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa) =
aaaaaaaaaaaaaaaaaaaaaaaaa;
llvm-svn: 237430
2015-05-15 09:58:11 +00:00
Daniel Jasper
731dde91db
clang-format: Don't use column layout in lists that have separating
...
comments. At some point, we might to want to a layout with a different
number of columns instead, but at the moment, this causes more
confusion than it's worth.
llvm-svn: 237427
2015-05-15 09:41:59 +00:00
Daniel Jasper
cdb58b2e45
clang-format: Add missing space before ObjC selector.
...
Before:
[self aaaaa:(1 + 2)bbbbb:3];
After:
[self aaaaa:(1 + 2) bbbbb:3];
llvm-svn: 237424
2015-05-15 09:05:31 +00:00
Daniel Jasper
c4144ea418
clang-format: Improve nested block / lambda indentation when wrapping
...
before binary/ternary operators.
Basically, it doesn't seem right to indent a nested block aligned to a
binary or ternary operator.
Before:
int i = aaaaaa ? 1 //
: [] {
return 2; //
}();
llvm::errs() << "number of twos is "
<< std::count_if(v.begin(), v.end(), [](int x) {
return x == 2; // force break
});
After:
int i = aaaaaa ? 1 //
: [] {
return 2; //
}();
llvm::errs() << "number of twos is "
<< std::count_if(v.begin(), v.end(), [](int x) {
return x == 2; // force break
});
llvm-svn: 237263
2015-05-13 16:09:21 +00:00
Daniel Jasper
3a26a8db5d
clang-format: Fix incorrect */& classification.
...
Before:
void f() { f(new a(), c *d); }
After:
void f() { f(new a(), c * d); }
llvm-svn: 237249
2015-05-13 12:54:30 +00:00
Daniel Jasper
e60cba1337
clang-format: Fix semicolon less macro-detection.
...
It was fooled by the comment.
Before:
SOME_UNRELATED_MACRO
/*static*/ int i;
After:
SOME_UNRELATED_MACRO
/*static*/ int i;
llvm-svn: 237246
2015-05-13 11:35:53 +00:00
Daniel Jasper
a7b142603d
clang-format: [ObjC] Further improve wrapping of methods calls without inputs.
...
Before:
[aaaaaaaaaaaaaaaaaaaaaaa
.aaaaaaaa[aaaaaaaaaaaaaaaaaaaaa] aaaaaaaaaaaaaaaaaaaaaa];
After:
[aaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaa[aaaaaaaaaaaaaaaaaaaaa]
aaaaaaaaaaaaaaaaaaaaaa];
llvm-svn: 237244
2015-05-13 10:23:03 +00:00
Daniel Jasper
a2a4d9c049
clang-format: [ObjC] Make IndentWrappedFunctionNames work with ObjC functions
...
llvm-svn: 237241
2015-05-13 09:38:25 +00:00
Daniel Jasper
0ad2814c89
clang-format: Prefer formatting local lambdas like functions.
...
Before:
auto my_lambda =
[](const string &some_parameter) { return some_parameter.size(); };
After:
auto my_lambda = [](const string &some_parameter) {
return some_parameter.size();
};
llvm-svn: 237235
2015-05-13 08:47:16 +00:00
Daniel Jasper
60c270764e
clang-format: Support column layout with comment after {.
...
Before:
vector<int> iiiiiiiiiiiiiii = { //
1111111111, 2222222222, 33333333333, 4444444444, //
111111111, 222222222, 3333333333, 444444444, //
11111111, 22222222, 333333333, 44444444};
After:
vector<int> iiiiiiiiiiiiiii = { //
1111111111, 2222222222, 33333333333, 4444444444, //
111111111, 222222222, 3333333333, 444444444, //
11111111, 22222222, 333333333, 44444444};
llvm-svn: 237233
2015-05-13 08:16:00 +00:00
Daniel Jasper
56807c19ac
clang-format: Make member introduced in r237108 const.
...
llvm-svn: 237114
2015-05-12 11:14:06 +00:00
Daniel Jasper
99b5a4648c
clang-format: Fix */& detection for lambdas in macros.
...
Before:
#define MACRO() [](A * a) { return 1; }
After:
#define MACRO() [](A *a) { return 1; }
llvm-svn: 237109
2015-05-12 10:20:32 +00:00
Daniel Jasper
5fc133e71e
clang-format: Fix hanging nested blocks in macros.
...
Before:
#define MACRO() \
Debug(aaa, /* force line break */ \
{ \
int i; \
int j; \
})
After:
#define MACRO() \
Debug(aaa, /* force line break */ \
{ \
int i; \
int j; \
})
llvm-svn: 237108
2015-05-12 10:16:02 +00:00
Manuel Klimek
3d3ea84a4f
Refactor clang-format's formatter.
...
Summary:
a) Pull out a class LevelIndentTracker whose responsibility is to keep track
of the indent of levels across multiple annotated lines.
b) Put all responsibility for merging lines into the LineJoiner; make the
LineJoiner iterate over the lines so we never operate on a line that might
be merged later; this makes the interface safer to use.
c) Move formatting of the end-of-file whitespace into formatFirstToken.
Fix bugs that became obvious after the refactoring:
1. We would not format lines with offsets correctly inside nested blocks if
only the outer expression was affected:
int x = s({ // clang-format only this line
class X {
public:
// ^ this starts at the non-modified indnent level; previously we would
// not fix this, now we correctly outdent it.
void f();
};
});
2. We would incorrectly align comments across lines that do not have comments
for lines with nested blocks:
int expression; // with comment
int x = s({
int y; // comment
int z; // we would incorrectly align this comment with the comment on
// 'expression'
});
llvm-svn: 237104
2015-05-12 09:23:57 +00:00
Daniel Jasper
015c7a91f1
clang-format: Support aligning ObjC string literals.
...
Before:
NSString s = @"aaaa"
@"bbbb";
After:
NSString s = @"aaaa"
@"bbbb";
llvm-svn: 237000
2015-05-11 15:15:48 +00:00
Daniel Jasper
d9ff035de8
clang-format: Appease the buildbots by including climits.
...
llvm-svn: 236995
2015-05-11 13:52:13 +00:00
Daniel Jasper
d57843d4e3
clang-format: Improve column layout.
...
Specifically, calculate the deviation between the shortest and longest
element (which is used to prevent excessive whitespace) per column, not
overall. This automatically handles the corner cases of a single column
and a single row so that the actualy implementation becomes simpler.
Before:
vector<int> x = {1,
aaaaaaaaaaaaaaaaaaaaaa,
2,
bbbbbbbbbbbbbbbbbbbbbb,
3,
cccccccccccccccccccccc};
After:
vector<int> x = {1, aaaaaaaaaaaaaaaaaaaaaa,
2, bbbbbbbbbbbbbbbbbbbbbb,
3, cccccccccccccccccccccc};
llvm-svn: 236992
2015-05-11 13:35:40 +00:00
Daniel Jasper
790d4f975e
clang-format: Don't merge subsequent lines into _asm blocks.
...
Before:
_asm {
} int i;
After:
_asm {
}
int i;
llvm-svn: 236985
2015-05-11 11:59:46 +00:00
Daniel Jasper
ec05fc7b16
clang-format: [JS] Clean up export declaration parsing.
...
NFC intended.
llvm-svn: 236982
2015-05-11 09:14:50 +00:00
Daniel Jasper
668c7bb34f
clang-format: [JS] Parse exported functions as free-standing.
...
Before:
export function foo() {} export function bar() {}
After:
export function foo() {
}
export function bar() {
}
llvm-svn: 236978
2015-05-11 09:03:10 +00:00
Manuel Klimek
d3585dbd1a
Refactor the formatter of clang-format.
...
Pull various parts of the UnwrappedLineFormatter into their own
abstractions. NFC.
There are two things left for subsequent changes (to keep this
reasonably small)
- the UnwrappedLineFormatter now has a bad name
- the UnwrappedLineFormatter::format function is still too large
llvm-svn: 236974
2015-05-11 08:21:35 +00:00
Daniel Jasper
173504e494
clang-format: Improve wrapping of << operators.
...
Before:
llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaa) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
After:
llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaa)
<< aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
Also, cleanup and simplify the operator wrapping logic.
llvm-svn: 236960
2015-05-10 21:15:07 +00:00
Daniel Jasper
c6366077ed
clang-format: Preserve line break before } in __asm { ... }.
...
Some compilers ignore everything after a semicolon in such inline asm
blocks and thus, the closing brace must not be moved to the previous
line.
llvm-svn: 236946
2015-05-10 08:42:04 +00:00
Daniel Jasper
f0fd1c66df
clang-format: Fix bug in escaped newline calculation.
...
This prevents clang-format from inadvertently joining stuff into macro
definitions as reported in llvm.org/PR23466.
llvm-svn: 236944
2015-05-10 08:00:25 +00:00
Daniel Jasper
e4c16c7ce3
clang-format: Several improvements around formatting braced lists.
...
In particular:
* If the difference between the longest and shortest element, we copped
out of column format completely. Now, we instead allow to arrange
these in a single column, essentially enforcing a one-per-line format.
* Allow column layout even if there are braced lists. Especially, if
there are many short lists, this can be beneficial. The bad case,
where there is a long nested init list is usually caught as we now
limit the length difference of the longest and shortest element.
llvm-svn: 236851
2015-05-08 13:51:14 +00:00
Daniel Jasper
7325aee167
clang-format: [JS] Avoid bad line-warp around "function".
...
Before:
someLooooooooongFunction(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, function(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {
// code
});
After:
someLooooooooongFunction(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
function(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {
// code
});
llvm-svn: 236813
2015-05-08 08:38:52 +00:00
Daniel Jasper
69694b0691
clang-format: [JS] Fix regex literal detection.
...
Before:
var regex = /= / ;
After:
var regex = /=/;
llvm-svn: 236811
2015-05-08 07:55:13 +00:00
Daniel Jasper
9c95013e8f
clang-format: Improve r236597, Properly indent method calls without inputs.
...
Before:
[aaaaaaaaaaaa(aaaaaa)
aaaaaaaaaaaaaaaaaaaa];
After:
[aaaaaaaaaaaa(aaaaaa)
aaaaaaaaaaaaaaaaaaaa];
llvm-svn: 236730
2015-05-07 14:19:59 +00:00
Manuel Klimek
ec5c3db7ac
Implements a way to retrieve information about whether some lines were not formatted due to syntax errors.
...
llvm-svn: 236722
2015-05-07 12:26:30 +00:00
Daniel Jasper
036181471c
clang-format: Don't indent 'signals' as access specifier if it isn't one
...
Before:
{
signals.set(0);
}
After:
{
signals.set(0);
}
llvm-svn: 236630
2015-05-06 19:21:23 +00:00
Daniel Jasper
1fe0d5ca59
clang-format: Merge labels and subsequent semicolons.
...
E.g.:
default:;
This can be used to get around restrictions as to what can follow a
label. It fixes llvm.org/PR19648.
llvm-svn: 236604
2015-05-06 15:19:47 +00:00
Daniel Jasper
112b50e6b6
clang-format: Allow ternary expressions inside template parameters if
...
the template parameters aren't inside an expression context.
This fixes llvm.org/PR23270.
llvm-svn: 236603
2015-05-06 14:53:50 +00:00
Daniel Jasper
e92bf6f141
clang-format: Consider operator precedence as penalty when breaking
...
before operators.
This fixes llvm.org/23382.
llvm-svn: 236602
2015-05-06 14:23:38 +00:00
Daniel Jasper
04785d0488
clang-format: Accept slightly more record declarations.
...
This fixes llvm.org/PR23397.
llvm-svn: 236599
2015-05-06 14:03:02 +00:00
Daniel Jasper
2746a308c2
clang-format: Fix bad wrapping of ObjC method exprs.
...
Before:
[aaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa:
aaaaaaaa aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];
After:
[aaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaa:aaaaaaaa
aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa];
Note that this might now violate the column limit and we probably need an
alternative way of indenting these then. However, that is still strictly better
than the messy formatting that clang-format did before.
llvm-svn: 236598
2015-05-06 13:13:03 +00:00
Daniel Jasper
eb53668c35
clang-format: Properly indent method calls without inputs.
...
Before:
[aaaaaaaaaaa
aaaaaaa];
After:
[aaaaaaaaaaa
aaaaaaa];
llvm-svn: 236597
2015-05-06 12:48:06 +00:00
Manuel Klimek
24a8f55857
Remove deprecated version of reformat.
...
llvm-svn: 236594
2015-05-06 12:12:22 +00:00
Manuel Klimek
20e0af6b62
Remove all computation of structural errors in clang-format's line parser.
...
We were already ignoring those already.
llvm-svn: 236591
2015-05-06 11:56:29 +00:00
Daniel Jasper
e2408e37db
clang-format: Fix another assertion discovered by the fuzzer.
...
In the process, fix an old todo that I don't really know how to write
tests for. The problem is that Clang's lexer creates very strange token
sequences for these. However, the new approach seems generally better
and easier to read so I am submitting it nonetheless.
llvm-svn: 236589
2015-05-06 11:16:43 +00:00
Daniel Jasper
62c78f5474
clang-format: Prevent assertion discovered by fuzzer.
...
llvm-svn: 236578
2015-05-06 08:58:57 +00:00
Daniel Jasper
4d9ec17f1e
clang-format: Prevent exponential runtime in token annotator.
...
llvm-svn: 236577
2015-05-06 08:38:24 +00:00
Daniel Jasper
6d9b88dd99
clang-format: Fix bug in multiline comment wrapping.
...
Splitting:
/**
* multiline block comment
*
*/
Before:
/**
* multiline block
*comment
*
*/
After:
/**
* multiline block
* comment
*
*/
The reason was that the empty line inside the comment (with just the "*") was
confusing the comment breaking logic.
llvm-svn: 236573
2015-05-06 07:17:22 +00:00
Daniel Jasper
9326f91922
clang-format: [JS] support optional methods.
...
Optional methods use ? tokens like this:
interface X { y?(): z; }
It seems easiest to detect and disambiguate these from ternary
expressions by checking if the code is in a declaration context. Turns
out that that didn't quite work properly for interfaces in Java and JS,
and for JS file root contexts.
Patch by Martin Probst, thank you.
llvm-svn: 236488
2015-05-05 08:40:32 +00:00
Daniel Jasper
2964749cfa
clang-format: [JS] Do not collapse short interfaces.
...
Patch by Martin Probst.
llvm-svn: 236485
2015-05-05 08:12:50 +00:00
Daniel Jasper
66cb8c503f
clang-format: NFC: Delete FormatToken::IsForEachMacro. Use a TokenType instead.
...
llvm-svn: 236415
2015-05-04 09:22:29 +00:00
Daniel Jasper
3cea45d079
clang-format: NFC: Use default member initializers and other cleanups.
...
llvm-svn: 236413
2015-05-04 08:51:40 +00:00
Daniel Jasper
de7ca75ca0
clang-format: Force aligning different brackets relative to each other.
...
Before:
void SomeFunction(vector< // break
int> v);
After:
void SomeFunction(vector< // break
int> v);
llvm-svn: 236412
2015-05-04 07:39:00 +00:00
Daniel Jasper
f69b922e57
clang-format: [JS] Fix calculation of template string width.
...
OriginalColumn might not be set, so fall back to Location and SourceMgr
in case it is missing. Also initialize end column in case the token is
multi line, but it's the ` token itself that starts the multi line.
Patch by Martin Probst, thank you!
llvm-svn: 236383
2015-05-02 08:05:38 +00:00
Daniel Jasper
d22190632c
clang-format: [JS] Fix templated parameter default values.
...
Parameters can have templated types and default values (= ...), which is
another location in which a template closer should be followed by
whitespace.
Patch by Martin Probst, thank you.
llvm-svn: 236382
2015-05-02 07:54:58 +00:00
Daniel Jasper
e9f5357f49
clang-format: Don't merge short else blocks.
...
Before (with the appropriate flags settings):
if (a) {
f();
} else { g(); }
Before (with other appropriate flags settings):
if (a) { f(); } else {
g();
}
After:
if (a) {
f();
} else {
g();
}
llvm-svn: 236217
2015-04-30 09:24:17 +00:00
Daniel Jasper
a4499133b1
clang-format: Add ability to align assignment operators.
...
In Objective-C some style guides use a style where assignment operators are
aligned, in an effort to increase code readability. This patch adds an option
to the format library which allows this functionality. It is disabled by
default for all the included styles, so it must be explicitly enabled.
The option will change code such as:
- (void)method {
NSNumber *one = @1 ;
NSNumber *twentyFive = @25;
}
to:
- (void)method {
NSNumber *one = @1;
NSNumber *twentyFive = @25;
}
Patch by Matt Oakes. Thank you!
Accidentally reformatted all the tests...
llvm-svn: 236100
2015-04-29 13:06:49 +00:00
Daniel Jasper
eb45cb7cf9
clang-format: Fix selective indentaiton in nested blocks.
...
Buggy case:
someFunction(
[] {
// comment
int i; // invoke formatting here.
}, // force line break
aaa);
llvm-svn: 236091
2015-04-29 08:29:26 +00:00
Daniel Jasper
775954be1e
clang-format: Don't wrap after short first segments of builder calls.
...
Before:
a()
.aaaaa()
.aaaaa()
.aaaaa();
After:
a().aaaaa()
.aaaaa()
.aaaaa();
llvm-svn: 235707
2015-04-24 10:08:09 +00:00
Daniel Jasper
de0d1f3c26
clang-format: More selectively detect QT's "signals".
...
llvm-svn: 235702
2015-04-24 07:50:34 +00:00
Daniel Jasper
0faa9136fa
clang-format: Properly detect variable declarations with ObjC.
...
Before:
LoooooooooooooooooooooooooooooooooooooooongType
LoooooooooooooooooooooooooooooooooooooongVariable([A a]);
After:
LoooooooooooooooooooooooooooooooooooooooongType
LoooooooooooooooooooooooooooooooooooooongVariable([A a]);
llvm-svn: 235599
2015-04-23 13:58:40 +00:00
Daniel Jasper
caf84fe21e
clang-format: Allow splitting "= default" and "= delete".
...
Otherwise, this can violate the column limit.
llvm-svn: 235592
2015-04-23 12:59:09 +00:00
Daniel Jasper
532a031422
clang-format: Don't add unwanted space when creating new arrays.
...
Before:
char** newargv = new char* [argc];
After:
char** newargv = new char*[argc];
llvm-svn: 235583
2015-04-23 10:23:53 +00:00
Daniel Jasper
1b998815a0
clang-format: [Proto] Don't linewrap top-level options.
...
They are very similar to import statements.
llvm-svn: 235582
2015-04-23 09:54:10 +00:00
Daniel Jasper
289afc071e
clang-format: Support nested block formatting with ColumnLimit=0.
...
llvm-svn: 235580
2015-04-23 09:23:17 +00:00
Daniel Jasper
ee4a8a140a
clang-format: Fix for #pragma option formatting.
...
Adapted patch from Sergey Razmetov. Thank you.
llvm-svn: 235492
2015-04-22 09:45:42 +00:00
Daniel Jasper
e4ab49e8d3
clang-format: Fix incorrect multi-var declstmt detection.
...
This is now obvious as the pointer alignment behavior was changed.
Before (even with pointer alignment "Left"):
MACRO Constructor(const int &i) : a(a), b(b) {}
After:
MACRO Constructor(const int& i) : a(a), b(b) {}
llvm-svn: 235301
2015-04-20 12:54:29 +00:00
Daniel Jasper
0d6ac27b86
clang-format: [JS] handle comments in template strings.
...
Patch by Martin Probst. Thank you.
llvm-svn: 235078
2015-04-16 08:20:51 +00:00
Daniel Jasper
20e15563ff
clang-format: Undo r214508. It was essentially always removing the
...
space where we already had the flag ObjCSpaceBeforeProtocolList to
control it. I don't know what I was thinking.
llvm-svn: 235076
2015-04-16 07:02:19 +00:00
Daniel Jasper
2b1865c251
clang-format: Determine "in" as a keyword in ObjC for loops more precisely
...
Before:
for (int i = 0; i < in [a]; ++i) ..
After:
for (int i = 0; i < in[a]; ++i) ..
Also do some related cleanups.
llvm-svn: 234980
2015-04-15 07:26:18 +00:00
Daniel Jasper
d9309774a6
clang-format: [JS] Support index signature types.
...
Patch by Martin Probst.
llvm-svn: 234754
2015-04-13 15:03:30 +00:00
Daniel Jasper
a74f5072e1
clang-format: [JS] support optionality markers in JS types.
...
Patch by Martin Probst. Thank you.
llvm-svn: 234753
2015-04-13 15:01:40 +00:00
Daniel Jasper
6a5d38d2ee
clang-format: [JS] Allow periods and commata in class declarations.
...
Patch by Martin Probst. Thank you.
llvm-svn: 234752
2015-04-13 14:56:54 +00:00
Alexander Kornienko
34eb20725d
Use 'override/final' instead of 'virtual' for overridden methods
...
Summary:
The patch is generated using clang-tidy misc-use-override check.
This command was used:
tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \
-checks='-*,misc-use-override' -header-filter='llvm|clang' -j=32 -fix
Reviewers: dblaikie
Reviewed By: dblaikie
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D8926
llvm-svn: 234678
2015-04-11 02:00:23 +00:00
Daniel Jasper
53395406da
clang-format: Fix regression formatting QT's "signals:" from r234318.
...
llvm-svn: 234320
2015-04-07 15:04:40 +00:00
Daniel Jasper
676e516354
clang-format: Don't allow labels when expecting declarations.
...
This fixes formatting unnamed bitfields (llvm.org/PR21999).
Before:
struct MyStruct {
uchar data;
uchar:
8;
uchar:
8;
uchar other;
};
After:
struct MyStruct {
uchar data;
uchar : 8;
uchar : 8;
uchar other;
};
llvm-svn: 234318
2015-04-07 14:36:33 +00:00
Daniel Jasper
acf67e3ecd
clang-format: Improve nested block formatting.
...
Before:
functionA(functionB({
int i;
int j;
}),
aaaa, bbbb, cccc);
After:
functionA(functionB({
int i;
int j;
}),
aaaa, bbbb, cccc);
llvm-svn: 234304
2015-04-07 08:20:35 +00:00
Daniel Jasper
9dedc775d7
clang-format: Indent relative to the ./-> and not the function name.
...
Before:
aaaaaaaaaaa //
.aaaa( //
bbbb) // This is different ..
.aaaa( //
cccc); // .. from this.
After:
aaaaaaaaaaa //
.aaaa( //
bbbb) // This is identical ..
.aaaa( //
cccc); // .. to this.
llvm-svn: 234300
2015-04-07 06:41:24 +00:00
Daniel Jasper
739ec534d2
clang-format: [JS] Understand object literals with only methods.
...
Before:
let theObject = {someMethodName() {
doTheThing();
doTheOtherThing();
},
someOtherMethodName() {
doSomething();
doSomethingElse();
}};
After:
let theObject = {
someMethodName() {
doTheThing();
doTheOtherThing();
},
someOtherMethodName() {
doSomething();
doSomethingElse();
}
};
llvm-svn: 234091
2015-04-04 07:56:55 +00:00
Daniel Jasper
1662bfe077
clang-format: [Proto] No alternate operator names.
...
llvm-svn: 234055
2015-04-03 21:15:46 +00:00
Daniel Jasper
f46dec86b6
clang-format: [JS] Support getters, setters and methods in object literals.
...
llvm-svn: 233698
2015-03-31 14:34:15 +00:00
Daniel Jasper
02c7bca5d1
clang-format: [JS] Fix comment formatting in goog.scopes.
...
Before:
goog.scope(function() {
// test
var x = 0;
// test
});
After:
goog.scope(function() {
// test
var x = 0;
// test
});
llvm-svn: 233530
2015-03-30 09:56:50 +00:00
Daniel Jasper
05cd92922d
clang-format: Force line break in trailing calls after multline exprs.
...
Before:
aaaaaaaa(aaaaaaaaaa,
bbbbbbbbbb).a();
After:
aaaaaaaa(aaaaaaaaaa,
bbbbbbbbbb)
.a();
llvm-svn: 233304
2015-03-26 18:46:28 +00:00
Daniel Jasper
e99c72fc2e
clang-format: Fix merging of _T macros.
...
NewlinesBefore and HasUnescapedNewline were not properly propagated
leading to llvm.org/PR23032.
llvm-svn: 233276
2015-03-26 14:47:35 +00:00
Benjamin Kramer
53f5e893c2
Explicitly include raw_ostream.h instead of relying on transitive inclusion.
...
NFC.
llvm-svn: 232975
2015-03-23 18:05:43 +00:00
Daniel Jasper
414c9c6fb0
clang-format: Fix another bug in wrapping around "*".
...
Before:
void aaaaa(
aaaaaaaaaaaa* aaaaaaaaaaaaaa) {} // even violation the column limit
After:
void aaaaa(aaaaaaaaaaaa*
aaaaaaaaaaaaaa) {}
llvm-svn: 232717
2015-03-19 09:40:16 +00:00
Daniel Jasper
1130981907
clang-format: Fix bad wrapping after "*" introduced in r232044.
...
Before:
void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa*
const aaaaaaaaaaaa) {}
After:
void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaa* const aaaaaaaaaaaa) {}
llvm-svn: 232635
2015-03-18 14:20:13 +00:00
Daniel Jasper
bc46b939e6
clang-format: [JS] support cast syntax and type arguments.
...
Casts in TS syntax (foo = <type>bar;) should not be followed by
whitespace.
Patch by Martin Probst. Thank you.
llvm-svn: 232321
2015-03-15 13:59:51 +00:00
Daniel Jasper
60948b12bb
clang-format: [JS] more precisely detect enums.
...
The current enum detection is overly aggressive. As NestingLevel only
applies per line (?) it classifies many if not most object literals as
enum declarations and adds superfluous line breaks into them. This
change narrows the heuristic by requiring an assignment just before the
open brace and requiring the line to start with an identifier.
Patch by Martin Probst. Thank you.
llvm-svn: 232320
2015-03-15 13:55:54 +00:00
Daniel Jasper
9ecb0e96b8
clang-format: Don't corrupt macros with open braces.
...
Formatting:
#define A { {
#define B } }
Before:
#define A \
{ \
{ #define B } \
}
After:
#define A \
{ \
{
#define B \
} \
}
This fixes llvm.org/PR22884.
llvm-svn: 232166
2015-03-13 13:32:11 +00:00
Daniel Jasper
55ca608cdc
clang-format: [OBJC] Don't indent 8 spaces in method declarations.
...
Before:
- (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
(SoooooooooooooooooooooomeType *)bbbbbbbbbb;
After:
- (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
(SoooooooooooooooooooooomeType *)bbbbbbbbbb;
llvm-svn: 232112
2015-03-12 22:13:45 +00:00
Daniel Jasper
b754a747be
clang-format: When putting */& next to types, also wrap before them.
...
Before:
LoooooooooooongType *
loooooooooooongVariable;
After:
LoooooooooooongType
*loooooooooooongVariable;
llvm-svn: 232044
2015-03-12 15:04:53 +00:00
Daniel Jasper
6acf513099
clang-format: [Java] Support anonymous classes after = and return.
...
Before:
A a = new A(){public String toString(){return "NotReallyA";
}
}
;
After:
A a = return new A() {
public String toString() {
return "NotReallyA";
}
};
This fixes llvm.org/PR22878.
llvm-svn: 232042
2015-03-12 14:44:29 +00:00
Daniel Jasper
8c68a64ec8
clang-format: Recognize the .ts (TypeScript) extension as JavaScript.
...
Patch by Martin Probst. Thank you.
llvm-svn: 231926
2015-03-11 14:58:38 +00:00
Daniel Jasper
dc4f725673
clang-format: Fix incorrect && recognition.
...
Before:
if (a &&(b = c)) ..
After:
if (a && (b = c)) ..
llvm-svn: 231920
2015-03-11 12:59:49 +00:00
Benjamin Kramer
8407df72a3
Make helper functions static. NFC.
...
Found by -Wmissing-prototypes.
llvm-svn: 231668
2015-03-09 16:47:52 +00:00
Daniel Jasper
ac5c97e36b
clang-format: Don't remove newline if macro ends in access specifier.
...
I.e.:
#define A public:
// The new line before this line would be removed.
int a;
llvm-svn: 231636
2015-03-09 08:13:55 +00:00
Benjamin Kramer
28b45ce151
Make constant static variables const so they can go into a read-only section
...
NFC.
llvm-svn: 231597
2015-03-08 16:06:46 +00:00
Daniel Jasper
98f8ae34da
clang-format: Slightly change indentation rules in for loops.
...
There was already a TODO to double-check whether the extra indenation
makes sense. A slightly different case reveals that it is actively harmful:
for (int i = 0; i < aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
bbbbbbbbbbbbbbbbbbbb < ccccccccccccccc;
++i) {
}
Here (and it is probably not a totally infrequent case, it just works out that
"i < " is four spaces and so the four space extra indentation makes the
operator precedence confusing. So, this will now instead be formatted
as:
for (int i = 0; i < aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ||
bbbbbbbbbbbbbbbbbbbb < ccccccccccccccc;
++i) {
}
llvm-svn: 231461
2015-03-06 10:57:12 +00:00
Manuel Klimek
2d29340095
Make sure we initialize all values in WhitespaceManager::Change.
...
llvm-svn: 231067
2015-03-03 14:21:48 +00:00
Daniel Jasper
0391e55650
clang-format: Fix access to uninitialized memory.
...
With incomplete code, we aren't guaranteed to generated changes for
every token. In that case, we need to assume that even the very first
change can continue a preprocessor directive and initialize values
accordingly.
llvm-svn: 231066
2015-03-03 13:59:49 +00:00
Daniel Jasper
e662316994
clang-format: Prefer wrapping a lambda's body over the lambda's return type.
...
Before:
aaaaaaaaaaaaaaaaaaaaaa(
[](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa)
-> aaaaaaaaaaaaaaaaaaaaa { return aaaaaaaaaaaaaaaaa; });
After:
aaaaaaaaaaaaaaaaaaaaaa(
[](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaaaaaaa {
return aaaaaaaaaaaaaaaaa;
});
llvm-svn: 230942
2015-03-02 10:35:13 +00:00
Benjamin Kramer
33335df819
Add missing include.
...
llvm-svn: 230910
2015-03-01 21:36:40 +00:00
Daniel Jasper
bea1ab46d9
clang-format: Always align */& in multi-var DeclStmts.
...
Seems like the most consistent thing to do and in multi-var DeclStmts,
it is especially important to point out that the */& bind to the
identifier.
llvm-svn: 230903
2015-03-01 18:55:26 +00:00
Daniel Jasper
308062bd0d
clang-format: Make trailing commas in array inits force one per line.
...
Before:
NSArray *array = @[ @"a", @"a", ];
After:
NSArray *array = @[
@"a",
@"a",
];
llvm-svn: 230741
2015-02-27 08:41:05 +00:00
Daniel Jasper
b812e323fa
clang-format: Make braced list formatting more consistent.
...
Before:
Aaaa aaaaaaaaaaa{
{
a, // +1 indent weird.
b, // trailing comma signals one per line.
}, // trailing comma signals one per line.
};
After:
Aaaa aaaaaaaaaaa{
{
a, // better!?
b, // trailing comma signals one per line.
}, // trailing comma signals one per line.
};
Interesting that this apparently was entirely untested :-(.
llvm-svn: 230627
2015-02-26 11:46:29 +00:00
Daniel Jasper
beaa322c36
clang-format: Fix space of arrays of pointers to templated types.
...
Before:
vector<int>(*foo_)[6];
After:
vector<int> (*foo_)[6];
llvm-svn: 230625
2015-02-26 11:30:50 +00:00
Daniel Jasper
a42de763ac
clang-format: Allow breaking after "else if(" as a last resort.
...
This isn't generally nice, but better than violating the column limit.
llvm-svn: 230620
2015-02-26 09:49:08 +00:00
Daniel Jasper
1c22048834
clang-format: Fix spacing for function with ref-qualification ..
...
.. when using SpacesInCStyleCastParentheses != SpacesInParentheses.
Before:
FormatStyle Spaces = getLLVMStyle();
Deleted &operator=(const Deleted &)& = default;
Spaces.SpacesInParentheses = true;
Deleted(const Deleted &)& = default;
Spaces.SpacesInCStyleCastParentheses = true;
Spaces.SpacesInParentheses= false;
Deleted( const Deleted & )& = default;
After:
FormatStyle Spaces = getLLVMStyle();
Deleted &operator=(const Deleted &)& = default;;
Spaces.SpacesInParentheses= true;
Deleted( const Deleted & )& = default;
Spaces.SpacesInCStyleCastParentheses = true;
Spaces.SpacesInParentheses= false;
Deleted(const Deleted &)& = default;
Patch by Jean-Philippe Dufraigne. Thank you!
llvm-svn: 230473
2015-02-25 10:30:06 +00:00
Jacques Pienaar
411b251cea
clang-format: Change location of stashed token
...
Commit of patch in http://reviews.llvm.org/D7871
llvm-svn: 230395
2015-02-24 23:23:24 +00:00
Jacques Pienaar
68a7dbf86d
Fix merging of << at end of input.
...
Commit of review http://reviews.llvm.org/D7766
llvm-svn: 230061
2015-02-20 21:09:01 +00:00
Daniel Jasper
a0ef4f36c8
clang-format: [js] Support template strings.
...
Merge template strings (marked by backticks ``).
Do not format any contents of template strings.
Patch by Martin Probst. Thank you.
llvm-svn: 230011
2015-02-20 13:47:38 +00:00
Daniel Jasper
fca735cd58
clang-format: [js] Support ES6 module exports.
...
Patch by Martin Probst, thank you!
llvm-svn: 229865
2015-02-19 16:14:18 +00:00
Daniel Jasper
354aa51587
clang-format: [js] Support ES6 module imports.
...
Patch by Martin Probst.
llvm-svn: 229863
2015-02-19 16:07:32 +00:00
Daniel Jasper
6fa9ec7885
clang-format: [js] Do not fall through for JS structural elements.
...
Patch by Martin Probst. Thank you.
llvm-svn: 229862
2015-02-19 16:03:16 +00:00
Jacques Pienaar
fc27511223
clang-format: Space and triple angle braces.
...
Committing patch http://reviews.llvm.org/D6800 .
llvm-svn: 229783
2015-02-18 23:48:37 +00:00
Daniel Jasper
3c42dba2dc
clang-format: [JS] support AtScript style annotations for JS.
...
Based on Java annotation support and style.
Patch by Martin Probst.
llvm-svn: 229703
2015-02-18 17:17:15 +00:00
Daniel Jasper
8370908667
clang-format: [JS] Support classes.
...
This adds support for JavaScript class definitions (again following
TypeScript & AtScript style). This only required support for
visibility modifiers in JS, everything else was already working.
Patch by Martin Probst, thank you.
llvm-svn: 229701
2015-02-18 17:14:05 +00:00
Daniel Jasper
b10bdff337
clang-format: [JS] Support type annotations.
...
This patch adds support for type annotations that follow TypeScript's,
Flow's, and AtScript's syntax style.
Patch by Martin Probst, thank you.
Review: http://reviews.llvm.org/D7721
llvm-svn: 229700
2015-02-18 17:09:53 +00:00
Daniel Jasper
699631298e
clang-format: Don't force a break after "endl" if everything fits on one line.
...
llvm-svn: 229486
2015-02-17 10:05:15 +00:00
Daniel Jasper
d97d5d5cf7
clang-format: Fix crasher.
...
llvm-svn: 229485
2015-02-17 09:58:03 +00:00
Aaron Ballman
abc1892057
Removing LLVM_DELETED_FUNCTION, as MSVC 2012 was the last reason for requiring the macro. NFC; Clang edition.
...
llvm-svn: 229339
2015-02-15 22:54:08 +00:00
Benjamin Kramer
c5bc3cd00b
Format: Make FormatToken's isOneOf a variadic template
...
llvm-svn: 229326
2015-02-15 20:11:14 +00:00
Daniel Jasper
29d39d54e7
clang-format: Correctly mark preprocessor lines in child blocks.
...
This prevents contracting:
auto lambda = []() {
int a = 2
#if A
+ 2
#endif
;
};
into:
auto lambda = []() { int a = 2
#if A + 2
#endif ; };
Which is obviously BAD.
This fixes llvm.org/PR22496.
llvm-svn: 228522
2015-02-08 09:34:49 +00:00
Nico Weber
33381f5e0b
clang-format: Format Objective-C try blocks like all the other try blocks.
...
Before:
@try {
// ...
}
@finally {
// ...
}
Now:
@try {
// ...
} @finally {
// ...
}
This is consistent with how we format C++ try blocks and SEH try blocks.
clang-format not doing this before was an implementation oversight.
This is dependent on BraceBreakingStyle. The snippet above is with the
Attach style. Style Stroustrip for example still results in the "Before:"
snippet, which makes sense since other blocks (try, else) break after '}' too.
llvm-svn: 228483
2015-02-07 01:57:32 +00:00
Daniel Jasper
30029c6b58
clang-format: Fix assert triggering on carriage returns.
...
llvm-svn: 228288
2015-02-05 11:05:31 +00:00
Nico Weber
fac2371be3
clang-format: Add support for SEH __try / __except / __finally blocks.
...
This lets clang-format format
__try {
} __except(0) {
}
and
__try {
} __finally {
}
correctly. __try and __finally are keywords if `LangOpts.MicrosoftExt` is set,
so this turns this on. This also enables a few other keywords, but it
shouldn't overly perturb regular clang-format operation. __except is a
context-sensitive keyword, so `AdditionalKeywords` needs to be passed around to
a few more places.
Fixes PR22321.
llvm-svn: 228148
2015-02-04 15:26:27 +00:00
Daniel Jasper
30526e79e8
clang-format: Fix incorrect handling of leading whitespace.
...
Added an assertion that triggered in an existing test case (without
observable differences) and fixed the code.
llvm-svn: 227677
2015-01-31 07:05:46 +00:00
Daniel Jasper
0955cb41eb
clang-format: FIXME that led to access of uninitialized memory.
...
I have so far not succeeded in finding a nicely reduced test case or an
observable difference which could help me create a test failure without
msan.
Committing without test to unblock kcc's further fuzzing progress.
llvm-svn: 227433
2015-01-29 13:11:47 +00:00
Daniel Jasper
47b35aeaa1
clang-format: Fix crasher caused by not properly setting dry-run.
...
llvm-svn: 227427
2015-01-29 10:47:14 +00:00
Daniel Jasper
d1c13736e0
clang-format: Fix another crasher caused by incomplete macro code.
...
We did't properly mark all of an AnnotatedLine's children as finalized
and thus would reformat the same tokens in different branches of #if/#else
sequences leading to invalid replacements.
llvm-svn: 226930
2015-01-23 19:37:25 +00:00
Daniel Jasper
7509216a41
clang-format: Fix incorrect classification of "*".
...
Before:
*a = b *c;
After:
*a = b * c;
llvm-svn: 226923
2015-01-23 19:04:49 +00:00
Daniel Jasper
e4b48c635c
clang-format: Fix crasher when splitting incomplete escape sequences.
...
llvm-svn: 226698
2015-01-21 19:50:35 +00:00
Daniel Jasper
04b979dd81
clang-format: Fix crasher caused by incorrect resetting of token info.
...
llvm-svn: 226685
2015-01-21 18:35:47 +00:00
Daniel Jasper
d1debfc2bb
clang-format: Fix bad memory access.
...
llvm-svn: 226680
2015-01-21 18:04:02 +00:00
Daniel Jasper
fd725c060b
clang-format: Fix use-heap-after-free bug.
...
Discovered by the awesome test case and ASAN.
llvm-svn: 226678
2015-01-21 17:35:29 +00:00
Daniel Jasper
6fd5d646cc
clang-format: Fix AlwaysBreakBeforeMultilineStrings with ColumnLimit=0
...
Before:
const char *x =
"hello llvm";
After:
const char *x = "hello llvm";
This fixes llvm.org/PR22245.
Patch by Bill Meltsner, thank you!
llvm-svn: 226564
2015-01-20 12:59:20 +00:00
Daniel Jasper
9b79efb51f
clang-format: Fix crasher on weird comments.
...
Crashing input:
/\
/ comment
llvm-svn: 226454
2015-01-19 11:49:32 +00:00
Daniel Jasper
193cdd381b
clang-format: Fix crasher on incomplete condition compilation.
...
Previously crashing input:
void f(
#if A
);
#else
#endif
llvm-svn: 226451
2015-01-19 10:52:16 +00:00
Daniel Jasper
20e8c3be3c
clang-format: Fix crash on invalid code.
...
Input "a<," made clang-format crash.
llvm-svn: 226450
2015-01-19 10:51:42 +00:00
Daniel Jasper
675b4f8350
clang-format: Fix clang-format crash on invalid code.
...
llvm-svn: 226449
2015-01-19 10:51:23 +00:00
Daniel Jasper
9d22bcc53e
clang-format: Fix assertion when trying to build a nullptr StringRef.
...
llvm-svn: 226448
2015-01-19 10:51:05 +00:00
Daniel Jasper
2bd7a64d12
clang-format: Fix endless loop on incomplete try-catch-block.
...
llvm-svn: 226447
2015-01-19 10:50:51 +00:00
Daniel Jasper
b1567c106f
clang-format: Remove assert that isn't helpful.
...
This assert would trigger on:
#d , = }
llvm-svn: 226446
2015-01-19 10:50:08 +00:00
Daniel Jasper
1cd3c71c01
clang-format: Disable flag for Google's Java and Javascript styles.
...
Disable AlwaysBreakBeforeMultilineString, as the style guides don't
really say to do so.
llvm-svn: 225982
2015-01-14 12:24:59 +00:00
Daniel Jasper
e189d46512
clang-format: [Java] Support try blocks with resources.
...
Before:
try
(SomeResource rs = someFunction()) {
Something();
}
After:
try (SomeResource rs = someFunction()) {
Something();
}
llvm-svn: 225973
2015-01-14 10:48:41 +00:00
Daniel Jasper
190fbda6de
clang-format: [Java] Prefer not to break in parameter annotations.
...
Before:
boolean someFunction(@Param(aaaaaaaaaaaaaaaa)
String aaaaa,
String bbbbbbbbbbbbbbb) {}
After:
boolean someFunction(
@Param(aaaaaaaaaaaaaaaa) String aaaaa,
String bbbbbbbbbbbbbbb) {}
llvm-svn: 225971
2015-01-14 10:36:31 +00:00
Daniel Jasper
16dbe0bc44
clang-format: [Java] Understand "import static".
...
llvm-svn: 225965
2015-01-14 10:02:49 +00:00
Daniel Jasper
404658aede
clang-format: [Java] Don't let annotations confuse return type analysis.
...
Before:
@Test
ReturnType
doSomething(String aaaaaaaaaaaaa, String bbbbbbbbbbbbbbb) {}
After:
@Test
ReturnType doSomething(
String aaaaaaaaaaaaa, String bbbbbbbbbbbbbbb) {}
llvm-svn: 225964
2015-01-14 10:00:20 +00:00
Daniel Jasper
3e1bd1407b
clang-format: [Java] Don't line-wrap before annotations' l_parens.
...
Before:
@SomeAnnotation
(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa)
int i;
After:
@SomeAnnotation(
aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa)
int i;
llvm-svn: 225963
2015-01-14 09:51:32 +00:00
Daniel Jasper
a831c58e53
clang-format: [Java] Don't get confused by leading annotations.
...
Before:
@Test(a)
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaa);
After:
@Test(a)
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =
aaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaa);
llvm-svn: 225962
2015-01-14 09:47:57 +00:00
Nico Weber
ed50166b6b
clang-format: [Java] Detect `native` keyword.
...
Before:
public native<X> Foo foo();
After:
public native <X> Foo foo();
llvm-svn: 225839
2015-01-13 22:32:50 +00:00
Alexander Kornienko
00691cf3bb
Fix assertion in BreakableBlockComment ( http://llvm.org/PR21916 ).
...
Reviewers: djasper
Reviewed By: djasper
Subscribers: klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D6894
llvm-svn: 225628
2015-01-12 13:11:12 +00:00
Daniel Jasper
d6a1cab1bc
clang-format: Improve format of lambdas in ctor initializers.
...
Before:
Constructor()
: Constructor([] { // comment
int i;
}) {}
After:
Constructor()
: Constructor([] { // comment
int i;
}) {}
llvm-svn: 225625
2015-01-12 10:23:24 +00:00
Daniel Jasper
2337f28063
clang-format: Fix formatting of inline asm.
...
Specifically, adjust the leading "__asm {" and trailing "}" while still
leaving the assembly inside it alone.
This fixes llvm.org/PR22190.
llvm-svn: 225623
2015-01-12 10:14:56 +00:00
Nico Weber
beb03938e9
clang-format: [Java] Support formatting qualified annotations.
...
llvm-svn: 225559
2015-01-09 23:25:06 +00:00
Daniel Jasper
d05d3a8919
clang-format: Force line break between "endl" and "<<".
...
This makes piped output easier to read in many instances.
Before:
llvm::errs() << aaaa << std::endl << bbbb << std::endl;
After:
llvm::errs() << aaaa << std::endl
<< bbbb << std::endl;
Also fix a few instance of "don't use else after return" as per the
coding standards.
llvm-svn: 225444
2015-01-08 13:56:57 +00:00
Daniel Jasper
b13135bc08
clang-format: Improve template parameter detection.
...
Before:
struct A < std::enable_if<sizeof(T2) <sizeof(int32)>::type>;
After:
struct A<std::enable_if<sizeof(T2) < sizeof(int32)>::type>;
llvm-svn: 225435
2015-01-08 08:48:21 +00:00
Nico Weber
ece3d3c26e
clang-format: Let Chromium use the Google default for AlignTrailingComments.
...
r225141 changed the defaults of AllowShortIfStatementsOnASingleLine and
AlignTrailingComments for Google style and added explicit overrides for
Chromium style to undo these changes. For AllowShortIfStatementsOnASingleLine
that's good as the Android style guide (which Chromium uses for Java) explicitly
permits single-line ifs. But it's silent on trailing comments, to it makes
sense for Chromium style to just follow Google style.
llvm-svn: 225363
2015-01-07 18:41:10 +00:00
Daniel Jasper
4953210478
clang-format: Understand single-line comments at the end of blocks.
...
This prevents clang-format from moving/aligning the comment in the
snippet:
void f() {
int i; // some comment
// some unrelated comment
}
llvm-svn: 225352
2015-01-07 14:00:11 +00:00
Daniel Jasper
6a9682038f
clang-format: Fix unary operator detection.
...
Before:
** outparam = 1;
After:
**outparam = 1;
llvm-svn: 225349
2015-01-07 12:19:53 +00:00
Daniel Jasper
77ef2be2e4
clang-format: [Java] Fix incorrect detection of cast.
...
After:
return (a instanceof List<?>) ? aaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaa)
: aaaaaaaaaaaaaaaaaaaaaaa;
After:
return (a instanceof List<?>)
? aaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa)
: aaaaaaaaaaaaaaaaaaaaaaa;
llvm-svn: 225161
2015-01-05 10:33:39 +00:00
Daniel Jasper
5f1fa85e5b
clang-format: [Java] Fix incorrect recognition of annonymous classes.
...
Before:
someFunction(new Runnable() { public void run() { System.out.println(42);
}
});
After:
someFunction(new Runnable() {
public void run() {
System.out.println(42);
}
});
llvm-svn: 225142
2015-01-04 20:40:51 +00:00
Daniel Jasper
fd4ed18402
clang-format: [Java] Change a few flags for Google's Java style.
...
No tests added as all of these are already tested separately.
llvm-svn: 225141
2015-01-04 20:40:45 +00:00
Daniel Jasper
428f0b1430
clang-format: Re-enable comment re-indentation for Java/JS.
...
This was broken by r224120.
llvm-svn: 225130
2015-01-04 09:11:17 +00:00
Daniel Jasper
3a623dbd2a
clang-format: Fix incorrect detection of ObjC "in" keyword.
...
Before:
for (auto v : in [1]) { ..
After:
for (auto v : in[1]) { ..
llvm-svn: 224513
2014-12-18 12:11:01 +00:00
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