summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Improve line wrapping around << operators.Daniel Jasper2015-05-171-4/+2
| | | | | | | | | | | | | | | | | | 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
* clang-format: Slightly change format decisions around macro annotations.Daniel Jasper2015-05-151-0/+3
| | | | | | | | | | | | Before: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa) = aaaaaaaaaaaaaaaaaaaaaaaaa; After: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa) = aaaaaaaaaaaaaaaaaaaaaaaaa; llvm-svn: 237430
* clang-format: Don't use column layout in lists that have separatingDaniel Jasper2015-05-151-4/+10
| | | | | | | | 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
* clang-format: Add missing space before ObjC selector.Daniel Jasper2015-05-151-0/+2
| | | | | | | | | | Before: [self aaaaa:(1 + 2)bbbbb:3]; After: [self aaaaa:(1 + 2) bbbbb:3]; llvm-svn: 237424
* clang-format: Improve nested block / lambda indentation when wrappingDaniel Jasper2015-05-131-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* clang-format: Fix incorrect */& classification.Daniel Jasper2015-05-131-0/+1
| | | | | | | | | | Before: void f() { f(new a(), c *d); } After: void f() { f(new a(), c * d); } llvm-svn: 237249
* clang-format: Fix semicolon less macro-detection.Daniel Jasper2015-05-131-0/+4
| | | | | | | | | | | | | | It was fooled by the comment. Before: SOME_UNRELATED_MACRO /*static*/ int i; After: SOME_UNRELATED_MACRO /*static*/ int i; llvm-svn: 237246
* clang-format: [ObjC] Further improve wrapping of methods calls without inputs.Daniel Jasper2015-05-131-0/+2
| | | | | | | | | | | | Before: [aaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaa[aaaaaaaaaaaaaaaaaaaaa] aaaaaaaaaaaaaaaaaaaaaa]; After: [aaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaa[aaaaaaaaaaaaaaaaaaaaa] aaaaaaaaaaaaaaaaaaaaaa]; llvm-svn: 237244
* clang-format: [ObjC] Make IndentWrappedFunctionNames work with ObjC functionsDaniel Jasper2015-05-131-0/+15
| | | | llvm-svn: 237241
* clang-format: Prefer formatting local lambdas like functions.Daniel Jasper2015-05-131-0/+3
| | | | | | | | | | | | | 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
* clang-format: Support column layout with comment after {.Daniel Jasper2015-05-131-0/+6
| | | | | | | | | | | | | | | | 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
* clang-format: Fix */& detection for lambdas in macros.Daniel Jasper2015-05-121-0/+1
| | | | | | | | | | Before: #define MACRO() [](A * a) { return 1; } After: #define MACRO() [](A *a) { return 1; } llvm-svn: 237109
* clang-format: Fix hanging nested blocks in macros.Daniel Jasper2015-05-121-0/+12
| | | | | | | | | | | | | | | | | | | | 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
* Refactor clang-format's formatter.Manuel Klimek2015-05-121-2/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* clang-format: Support aligning ObjC string literals.Daniel Jasper2015-05-111-3/+8
| | | | | | | | | | | | Before: NSString s = @"aaaa" @"bbbb"; After: NSString s = @"aaaa" @"bbbb"; llvm-svn: 237000
* clang-format: Improve column layout.Daniel Jasper2015-05-111-0/+5
| | | | | | | | | | | | | | | | | | | | | | 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
* clang-format: Don't merge subsequent lines into _asm blocks.Daniel Jasper2015-05-111-0/+6
| | | | | | | | | | | | | Before: _asm { } int i; After: _asm { } int i; llvm-svn: 236985
* clang-format: [JS] Parse exported functions as free-standing.Daniel Jasper2015-05-111-0/+6
| | | | | | | | | | | | | Before: export function foo() {} export function bar() {} After: export function foo() { } export function bar() { } llvm-svn: 236978
* clang-format: Improve wrapping of << operators.Daniel Jasper2015-05-101-0/+4
| | | | | | | | | | | | | | | | | 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
* clang-format: Preserve line break before } in __asm { ... }.Daniel Jasper2015-05-101-0/+8
| | | | | | | | 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
* clang-format: Fix bug in escaped newline calculation.Daniel Jasper2015-05-101-0/+2
| | | | | | | This prevents clang-format from inadvertently joining stuff into macro definitions as reported in llvm.org/PR23466. llvm-svn: 236944
* clang-format: Several improvements around formatting braced lists.Daniel Jasper2015-05-081-7/+29
| | | | | | | | | | | | | 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
* clang-format: [JS] Avoid bad line-warp around "function".Daniel Jasper2015-05-081-0/+6
| | | | | | | | | | | | | | | | | | | | Before: someLooooooooongFunction( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, function( aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) { // code }); After: someLooooooooongFunction( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, function(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) { // code }); llvm-svn: 236813
* clang-format: [JS] Fix regex literal detection.Daniel Jasper2015-05-081-0/+1
| | | | | | | | | | Before: var regex = /= / ; After: var regex = /=/; llvm-svn: 236811
* clang-format: Improve r236597, Properly indent method calls without inputs.Daniel Jasper2015-05-071-0/+2
| | | | | | | | | | | | Before: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; After: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; llvm-svn: 236730
* Implements a way to retrieve information about whether some lines were not ↵Manuel Klimek2015-05-071-27/+46
| | | | | | formatted due to syntax errors. llvm-svn: 236722
* clang-format: Don't indent 'signals' as access specifier if it isn't oneDaniel Jasper2015-05-061-0/+3
| | | | | | | | | | | | | | Before: { signals.set(0); } After: { signals.set(0); } llvm-svn: 236630
* clang-format: Merge labels and subsequent semicolons.Daniel Jasper2015-05-061-0/+10
| | | | | | | | | | | 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
* clang-format: Allow ternary expressions inside template parameters ifDaniel Jasper2015-05-061-0/+2
| | | | | | | | the template parameters aren't inside an expression context. This fixes llvm.org/PR23270. llvm-svn: 236603
* clang-format: Consider operator precedence as penalty when breakingDaniel Jasper2015-05-061-0/+4
| | | | | | | | before operators. This fixes llvm.org/23382. llvm-svn: 236602
* clang-format: Accept slightly more record declarations.Daniel Jasper2015-05-061-0/+2
| | | | | | This fixes llvm.org/PR23397. llvm-svn: 236599
* clang-format: Fix bad wrapping of ObjC method exprs.Daniel Jasper2015-05-061-0/+7
| | | | | | | | | | | | | | | | | 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
* clang-format: Properly indent method calls without inputs.Daniel Jasper2015-05-061-0/+2
| | | | | | | | | | | | Before: [aaaaaaaaaaa aaaaaaa]; After: [aaaaaaaaaaa aaaaaaa]; llvm-svn: 236597
* clang-format: Fix another assertion discovered by the fuzzer.Daniel Jasper2015-05-061-4/+2
| | | | | | | | | 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
* clang-format: Prevent assertion discovered by fuzzer.Daniel Jasper2015-05-061-0/+2
| | | | llvm-svn: 236578
* clang-format: Prevent exponential runtime in token annotator.Daniel Jasper2015-05-061-0/+1
| | | | llvm-svn: 236577
* clang-format: Fix bug in multiline comment wrapping.Daniel Jasper2015-05-061-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* clang-format: [JS] support optional methods.Daniel Jasper2015-05-051-0/+4
| | | | | | | | | | | | | | | 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
* clang-format: [JS] Do not collapse short interfaces.Daniel Jasper2015-05-051-0/+6
| | | | | | Patch by Martin Probst. llvm-svn: 236485
* clang-format: Force aligning different brackets relative to each other.Daniel Jasper2015-05-041-0/+7
| | | | | | | | | | | | Before: void SomeFunction(vector< // break int> v); After: void SomeFunction(vector< // break int> v); llvm-svn: 236412
* clang-format: [JS] Fix calculation of template string width.Daniel Jasper2015-05-021-0/+6
| | | | | | | | | | 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
* clang-format: [JS] Fix templated parameter default values.Daniel Jasper2015-05-021-0/+2
| | | | | | | | | | 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
* clang-format: Don't merge short else blocks.Daniel Jasper2015-04-301-0/+12
| | | | | | | | | | | | | | | | | | | | | 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
* clang-format: Add ability to align assignment operators.Daniel Jasper2015-04-291-332/+457
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* clang-format: Fix selective indentaiton in nested blocks.Daniel Jasper2015-04-291-0/+13
| | | | | | | | | | | | Buggy case: someFunction( [] { // comment int i; // invoke formatting here. }, // force line break aaa); llvm-svn: 236091
* clang-format: Don't wrap after short first segments of builder calls.Daniel Jasper2015-04-241-0/+12
| | | | | | | | | | | | | | | Before: a() .aaaaa() .aaaaa() .aaaaa(); After: a().aaaaa() .aaaaa() .aaaaa(); llvm-svn: 235707
* clang-format: More selectively detect QT's "signals".Daniel Jasper2015-04-241-0/+4
| | | | llvm-svn: 235702
* clang-format: Properly detect variable declarations with ObjC.Daniel Jasper2015-04-231-0/+2
| | | | | | | | | | | | Before: LoooooooooooooooooooooooooooooooooooooooongType LoooooooooooooooooooooooooooooooooooooongVariable([A a]); After: LoooooooooooooooooooooooooooooooooooooooongType LoooooooooooooooooooooooooooooooooooooongVariable([A a]); llvm-svn: 235599
* clang-format: Allow splitting "= default" and "= delete".Daniel Jasper2015-04-231-0/+8
| | | | | | Otherwise, this can violate the column limit. llvm-svn: 235592
* clang-format: Don't add unwanted space when creating new arrays.Daniel Jasper2015-04-231-4/+4
| | | | | | | | | | Before: char** newargv = new char* [argc]; After: char** newargv = new char*[argc]; llvm-svn: 235583
OpenPOWER on IntegriCloud