summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* Align superclasses for multiple inheritence.Daniel Jasper2013-02-141-0/+22
| | | | | | | | | | | | | | | | This fixes llvm.org/PR15179. Before: class ColorChooserMac : public content::ColorChooser, public content::WebContentsObserver { }; After: class ColorChooserMac : public content::ColorChooser, public content::WebContentsObserver { }; llvm-svn: 175147
* Allow breaking after the return type in function declarations.Daniel Jasper2013-02-131-0/+8
| | | | | | | | | | | | | | | | | This has so far been disabled for Google style, but should be done before breaking at nested name specifiers or in template parameters. Before (in Google style): template <typename T> aaaaaaaa::aaaaa::aaaaaa<T, aaaaaaaaaaaaaaaaaaaaaaaaa> aaaaaaaaaaaaaaaaaaaaaaaa< T>::aaaaaaa() {} After: template <typename T> aaaaaaaa::aaaaa::aaaaaa<T, aaaaaaaaaaaaaaaaaaaaaaaaa> aaaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaa() {} llvm-svn: 175074
* Fix comment alignment close to the column limit.Daniel Jasper2013-02-131-0/+3
| | | | | | | Due to an error in one of the expressions, we used to not align comments although it would have been possible. llvm-svn: 175068
* Formatter: And more cast tests (these don't pass yet).Nico Weber2013-02-131-0/+2
| | | | llvm-svn: 175031
* Formatter: Add more cast tests.Nico Weber2013-02-131-1/+9
| | | | llvm-svn: 175030
* Formatter: Refactor the cast detection code to be a bit more readable.Nico Weber2013-02-131-0/+1
| | | | | | No functionality change. Also add another cast test. llvm-svn: 175029
* Formatter: Detect ObjC method expressions after casts.Nico Weber2013-02-131-1/+2
| | | | | | Not all casts are correctly detected yet, but it helps in some cases. llvm-svn: 175028
* Fix crash for incomplete labels in macros.Daniel Jasper2013-02-121-0/+6
| | | | | | | Still the formatting can be improved, but at least we don't assert any more. This happened when trying to format lib/Sema/SemaType.cpp. llvm-svn: 175003
* Fix bug in the adjustment to existing lines.Daniel Jasper2013-02-121-0/+3
| | | | | | | | | | | | Before (if only the second line was reformatted): void f() {} void g() {} After: void f() {} void g() {} llvm-svn: 174978
* Formatter: Correctly format stars in `sizeof(int**)` and similar places.Nico Weber2013-02-121-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This redoes how '*' and '&' are classified as pointer / reference markers when followed by ')', '>', or ','. Previously, determineStarAmpUsage() marked a single '*' and '&' followed by ')', '>', or ',' as pointer or reference marker. Now, all '*'s and '&'s preceding ')', '>', or ',' are marked as pointer / reference markers. Fixes PR14884. Since only the last '*' in 'int ***' was marked as pointer before (the rest were unary operators, which don't reach spaceRequiredBetween()), spaceRequiredBetween() now had to be thought about handing multiple '*'s in sequence. Before: return sizeof(int * *); Type **A = static_cast<Type * *>(P); Now: return sizeof(int**); Type **A = static_cast<Type **>(P); While here, also make all methods of AnnotatingParser except parseLine() private. Review URL: http://llvm-reviews.chandlerc.com/D384 llvm-svn: 174975
* Formatter: Detect ObjC message expressions after 'in' in loopNico Weber2013-02-111-0/+4
| | | | | | | | | | | | | | | | Before: for (id foo in[self getStuffFor : bla]) { } Now: for (id foo in [self getStuffFor:bla]) { } "in" is treated as loop keyword if the line starts with "for", and as a regular identifier else. To check for "in", its IdentifierInfo is handed through a few layers. llvm-svn: 174889
* Get rid of manual debug output, now that the test runner supports it.Manuel Klimek2013-02-111-3/+0
| | | | | | You can run tests with -debug instead now. llvm-svn: 174880
* Fix invalid formatting with spaces before trailing comments.Daniel Jasper2013-02-111-0/+3
| | | | | | | | In google style, trailing comments are separated by two spaces. This patch fixes the counting of these spaces and prevents clang-format from creating a line with 81 columns. llvm-svn: 174879
* Fixes handling of empty lines in macros.Manuel Klimek2013-02-111-0/+20
| | | | | | | | | | | | | | Now correctly formats: #define A \ \ b; to #define A b; Added the state whether an unwrapped line is a macro to the debug output. llvm-svn: 174878
* Fix formatting of overloaded operator definitions.Daniel Jasper2013-02-111-0/+7
| | | | | | | | | | | | Before: operatorvoid*(); operator vector< A< A>>(); After: operator void *(); operator vector<A<A> >(); llvm-svn: 174863
* Formatter: Add a test for multi-line ObjC dict literals.Nico Weber2013-02-101-0/+3
| | | | | | | | | | | | | | | | | | | | As it turns out, this already works reasonably well. This example from http://clang.llvm.org/docs/ObjectiveCLiterals.html NSDictionary *dictionary = @{ @"name" : NSUserName(), @"date" : [NSDate date], @"processInfo" : [NSProcessInfo processInfo] }; is formatted like NSDictionary *dictionary = @{ @"name" : NSUserName(), @"date" : [NSDate date], @"processInfo" : [NSProcessInfo processInfo] }; There's already a FIXME in NestedStaticInitializers about supporting one initializer per line, which is really all that's missing here too. llvm-svn: 174842
* Formatter: Add another ObjC literal test.Nico Weber2013-02-101-0/+2
| | | | | | (From http://clang.llvm.org/docs/ObjectiveCLiterals.html.) llvm-svn: 174841
* Formatter: Initial support for ObjC dictionary literals.Nico Weber2013-02-101-2/+14
| | | | | | | | | | | | | | | | | | Before: @{ foo: bar } ; Now: @{ foo : bar }; parseBracedList() already does the right thing from an UnwrappedLineParser perspective, so check for "@{" in all loops that process constructs that can contain expressions and call parseBracedList() if found. llvm-svn: 174840
* Formatter: Detect ObjC array literals.Nico Weber2013-02-101-1/+6
| | | | | | | | Use this to add a space after "@[" and before "]" for now. Later, I want to use this to format multi-line array literals nicer, too. llvm-svn: 174822
* Formatter: Add test for default arguments.Nico Weber2013-02-091-0/+2
| | | | llvm-svn: 174816
* Fix indentation-detection at indent level 0.Manuel Klimek2013-02-081-1/+6
| | | | | | | | | | | This correctly formats: { a; } where { is incorrectly indented by 2, but is at level 0, when reformatting only 'a;'. llvm-svn: 174737
* Takes the context into account when re-indenting regions.Manuel Klimek2013-02-081-0/+51
| | | | | | Fixes llvm.org/PR14916. llvm-svn: 174720
* Fix handling of fake parenthesis during formatting.Daniel Jasper2013-02-081-0/+5
| | | | | | | | | | | | | | | | | | They are much easier to handle when attached to the previous token. Before: unsigned Indent = formatFirstToken(TheLine.First, IndentForLevel[TheLine.Level] >= 0 ? IndentForLevel[TheLine.Level] : TheLine.Level * 2, TheLine.InPPDirective, PreviousEndOfLineColumn); After: unsigned Indent = formatFirstToken( TheLine.First, IndentForLevel[TheLine.Level] >= 0 ? IndentForLevel[TheLine.Level] : TheLine.Level * 2, TheLine.InPPDirective, PreviousEndOfLineColumn); llvm-svn: 174718
* Implement a tiny expression parser to improve formatting decisions.Daniel Jasper2013-02-081-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | With this patch, the formatter introduces 'fake' parenthesis according to the operator precedence of binary operators. Before: return aaaa & AAAAAAAAAAAAAAAAAAAAAAAAAAAAA || bbbb & BBBBBBBBBBBBBBBBBBBBBBBBBBBBB || cccc & CCCCCCCCCCCCCCCCCCCCCCCCCC || dddd & DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD; f(aaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaa); After: return aaaa & AAAAAAAAAAAAAAAAAAAAAAAAAAAAA || bbbb & BBBBBBBBBBBBBBBBBBBBBBBBBBBBB || cccc & CCCCCCCCCCCCCCCCCCCCCCCCCC || dddd & DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD; f(aaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaa); Future improvements: - Get rid of some of the hacky ways to nicely format certain constructs. - Merge this parser and the AnnotatingParser as we now have several parsers that analyze (), [], etc. llvm-svn: 174714
* Avoid unnecessary line breaks in nested ObjC calls.Daniel Jasper2013-02-081-4/+1
| | | | | | | | | | | | Before: [pboard setData:[NSData dataWithBytes:&button length:sizeof(button)] forType:kBookmarkButtonDragType]; After: [pboard setData:[NSData dataWithBytes:&button length:sizeof(button)] forType:kBookmarkButtonDragType]; llvm-svn: 174701
* clang-format: Don't put useless space in f( ::g()).Daniel Jasper2013-02-071-1/+2
| | | | llvm-svn: 174662
* Formatter: Move ObjC literal tests to its own test case.Nico Weber2013-02-071-13/+21
| | | | | | | Slightly expand the boxed expressions test with a few more snippets from http://clang.llvm.org/docs/ObjectiveCLiterals.html llvm-svn: 174559
* Fix bug in the alignment of comments.Daniel Jasper2013-02-061-0/+7
| | | | | | | | | | | | | | | | | | | | Before: const char *test[] = { // A "aaaa", // B "aaaaa", }; After: const char *test[] = { // A "aaaa", // B "aaaaa", }; llvm-svn: 174549
* Become a little smarter with formatting long chains of pipes.Daniel Jasper2013-02-061-0/+7
| | | | | | | | | | | | | | | | | | | | | Assign a high penalty to breaking before "<<" if the previous token is a string literal ending in ":" or "=". Before: llvm::outs() << "aaaaaaaaaaaaaaaaa = " << aaaaaaaaaaaaaaaaa << "bbbbbbbbbbbbbbbbb = " << bbbbbbbbbbbbbbbbb << "ccccccccccccccccc = " << ccccccccccccccccc << "ddddddddddddddddd = " << ddddddddddddddddd << "eeeeeeeeeeeeeeeee = " << eeeeeeeeeeeeeeeee; After: llvm::outs() << "aaaaaaaaaaaaaaaaa = " << aaaaaaaaaaaaaaaaa << "bbbbbbbbbbbbbbbbb = " << bbbbbbbbbbbbbbbbb << "ccccccccccccccccc = " << ccccccccccccccccc << "ddddddddddddddddd = " << ddddddddddddddddd << "eeeeeeeeeeeeeeeee = " << eeeeeeeeeeeeeeeee; llvm-svn: 174545
* Align trailing block comments like trailing line comments.Daniel Jasper2013-02-061-0/+7
| | | | llvm-svn: 174537
* Formatter: Correctly detect ObjC message expressions preceded by a comment.Nico Weber2013-02-061-0/+6
| | | | llvm-svn: 174521
* Fix handling of comments in macros.Manuel Klimek2013-02-061-0/+26
| | | | | | | | | | | | | | | | We now correctly format: // Written as a macro, it is reformatted from: #define foo(a) \ do { \ /* Initialize num to zero. */ \ int num = 10; \ /* This line ensures a is never zero. */ \ int i = a == 0 ? 1 : a; \ i = num / i; /* This division is OK. */ \ return i; \ } while (false) llvm-svn: 174517
* Much semicolon after namespaces.Manuel Klimek2013-02-061-0/+9
| | | | | | | | | We now leave the semicolon in the line of the closing brace in: namespace { ... }; llvm-svn: 174514
* Fix formatting of ObjC method calls.Daniel Jasper2013-02-061-0/+6
| | | | | | | | | | | | | | This fixes llvm.org/PR15165. We now correctly align: [image_rep drawInRect:drawRect fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0 ssssssssdd:NO hints:nil]; llvm-svn: 174513
* Parse record declarations with token pasted identifiers.Manuel Klimek2013-02-061-0/+1
| | | | | | | This is pretty common in macros: #define A(X, Y) class X##Y {}; llvm-svn: 174512
* Fix a formatting bug caused by comments in expressions.Daniel Jasper2013-02-061-0/+15
| | | | | | | | | | | | | | | | | This fixes llvm.org/PR15162. Before: bool aaaaaaaaaaaaa = // comment aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaaa; After: bool aaaaaaaaaaaaa = // comment aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaaa; llvm-svn: 174508
* Optionally derive formatting information from the input file.Daniel Jasper2013-02-061-0/+21
| | | | | | | | | | | | | With this patch, clang-format can analyze the input file for two properties: 1. Is "int *a" or "int* a" more common. 2. Are non-C++03 constructs used, e.g. A<A<A>>. With Google-style, clang-format will now use the more common style for (1) and format C++03 compatible, unless it finds C++11 constructs in the input. llvm-svn: 174504
* Fix an issue with the formatting of stars in default values.Daniel Jasper2013-02-061-0/+1
| | | | | | Before: void f(int *a = d *e, int b = 0); After: void f(int *a = d * e, int b = 0); llvm-svn: 174500
* Handle nested ObjC calls.Daniel Jasper2013-02-061-2/+24
| | | | | | | | | | | | | | Properly handle annotation contexts while calculating extra information for each token. This enable nested ObjC calls and thus solves (most of) llvm.org/PR15164. E.g., we can now format: [contentsContainer replaceSubview:[subviews objectAtIndex:0] with:contentsNativeView]; Also fix a problem with the formatting of types in casts as this was trivial now. llvm-svn: 174498
* Formatter: No space after & and * in front of ObjC message expressions.Nico Weber2013-02-061-3/+2
| | | | | | | | | | | | | | 1. let determineStarAmp() check of unary operators before checking for "is next '['". That check was added in r173150, and the test from that revision passes either way. 2. change determineStarAmp() to categorize '*' and '&' after '=' as unary operator. 3. don't let parseSquare() overwrite the type of a '*' or '&' before the start of an objc message expression if has the role of unary operator. llvm-svn: 174489
* Formatter: Detect ObjC method expressions after unary operators.Nico Weber2013-02-051-0/+16
| | | | llvm-svn: 174384
* Initial support for formatting ObjC method declarations/calls.Daniel Jasper2013-02-051-20/+45
| | | | | | | | | | | | | | | | We can now format stuff like: - (void)doSomethingWith:(GTMFoo *)theFoo rect:(NSRect)theRect interval:(float)theInterval { [myObject doFooWith:arg1 // name:arg2 error:arg3]; } This seems to fix everything mentioned in llvm.org/PR14939. llvm-svn: 174364
* Fix some linebreak decisions in Google format.Daniel Jasper2013-02-051-0/+7
| | | | | | | | | | | | | | | | | | Before: f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaa); aaaaaaa(aaaaaaaaaaaaa, aaaaaaaaaaaaa, aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa)); After: f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaa); aaaaaaa(aaaaaaaaaaaaa, aaaaaaaaaaaaa, aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa)); llvm-svn: 174363
* Fix formatting regression introduced by r174307.Daniel Jasper2013-02-051-0/+2
| | | | | | | | | | In preprocessor definitions, we would not parse all the tokens and thus not annotate them anymore. This led to a wrong formatting of comments in google style: #endif // HEADER_GUARD -- requires two spaces llvm-svn: 174361
* Improve handling of trailing block commentsDaniel Jasper2013-02-041-2/+3
| | | | | | This is a follow up to r174309 to actually make it work. llvm-svn: 174314
* Improve formatting of stream operators.Daniel Jasper2013-02-041-0/+7
| | | | | | | | | | | | | | | If there are string literals on either side of a '<<', chances are high that they represent logically separate concepts. Otherwise, the author could just have just a single literal (possible split over multiple lines). So, we can now nicely format things like: cout << "somepacket = {\n" << " val a = " << ValueA << "\n" << " val b = " << ValueB << "\n" << "}"; llvm-svn: 174310
* Improve handling of trailing block comments.Daniel Jasper2013-02-041-0/+9
| | | | | | | | | | We can now (even in non-bin-packing modes) format: someFunction(1, /* comment 1 */ 2, /* comment 2 */ 3, /* comment 3 */ aaa); llvm-svn: 174309
* Fix an error in formatting of for-loops.Daniel Jasper2013-02-041-2/+15
| | | | | | | | | | | | | | | | Two minor changes: * Slight penalty for breaking at "," as opposed to ";". * Don't apply bin-packing rules to for-loops. Before: for (int aaaaaa = aaaaaaaaaa; aaaaaa < bbbbbbbb; ++aaaaaa, ++ccccccccccccccc) {} After: for (int aaaaaa = aaaaaaaaaa; aaaaaa < bbbbbbbb; ++aaaaaa, ++ccccccccccccccc) {} llvm-svn: 174308
* Restructuring of token annotation for formatting.Daniel Jasper2013-02-041-0/+4
| | | | | | | | | | This combines several changes: * Calculation token type (e.g. for * and &) in the AnnotatingParser. * Calculate the scope binding strength in the AnnotatingParser. * Let <> and [] scopes bind stronger than () and {} scopes. * Add minimal debugging output. llvm-svn: 174307
* Fix bug in formatting of nested initializers.Daniel Jasper2013-02-031-0/+6
| | | | | | | | | | | | | We can now format: SomeArrayOfSomeType a = { { { 1, 2, 3 } }, { { 1, 2, 3 } }, { { 111111111111111111111111111111, 222222222222222222222222222222, 333333333333333333333333333333 } }, { { 1, 2, 3 } }, { { 1, 2, 3 } } }; Before, we did strange things there. llvm-svn: 174291
OpenPOWER on IntegriCloud