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