summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Change clang-format's affinity for breaking after return types.Daniel Jasper2013-04-111-3/+7
| | | | | | | | | | | | | Function declarations are now broken with the following preferences: 1) break amongst arguments. 2) break after return type. 3) break after (. 4) break before after nested name specifiers. Options #2 or #3 are preferred over #1 only if a substantial number of lines can be saved by that. llvm-svn: 179287
* Fix formatting of overloaded assignment operators.Daniel Jasper2013-04-111-1/+2
| | | | | | Before: SomeType &operator=(const SomeType & S); After: SomeType &operator=(const SomeType &S); llvm-svn: 179270
* Fix labels with trailing comments and cleanup.Daniel Jasper2013-04-101-50/+39
| | | | | | | | | | | | | | | | | | Before: class A { public : // test }; After: class A { public: // test }; Also remove duplicate methods calculating properties of AnnotatedTokens and make them members of AnnotatedTokens so that they are in a common place. llvm-svn: 179167
* Revamp indentation behavior for complex binary expressions.Daniel Jasper2013-04-081-17/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The idea is to indent according to operator precedence and pretty much identical to how stuff would be indented with parenthesis. Before: bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > ccccccccccccccccccccccccccccccccccccccccc; After: bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > ccccccccccccccccccccccccccccccccccccccccc; llvm-svn: 179049
* Revert accidental commit r179015.Daniel Jasper2013-04-081-25/+10
| | | | llvm-svn: 179016
* xDaniel Jasper2013-04-081-10/+25
| | | | llvm-svn: 179015
* Allow breaking after 'class' for classes with looong names.Daniel Jasper2013-04-051-1/+4
| | | | | | (Don't ask, this was a user request). llvm-svn: 178888
* Fix bad formatting of overloaded operator definitions.Daniel Jasper2013-04-051-1/+2
| | | | | | | | | | | | | | | | Before: bool operator< (const aaaaaaaaaaaaaaaaaaaaa &left, const aaaaaaaaaaaaaaaaaaaaa &right) { return left.group < right.group; } After: bool operator<(const aaaaaaaaaaaaaaaaaaaaa &left, const aaaaaaaaaaaaaaaaaaaaa &right) { return left.group < right.group; } llvm-svn: 178887
* Improve formatting of for loops and multi-variable DeclStmts.Daniel Jasper2013-04-031-2/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This combines several related changes: a) Don't break before after the variable types in for loops with a single variable. b) Better indent DeclStmts defining multiple variables. Before: bool aaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa), bbbbbbbbbbbbbbbbbbbbbbbbb = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb); for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa = aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa; aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) { } After: bool aaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa), bbbbbbbbbbbbbbbbbbbbbbbbb = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb); for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa = aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa; aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) { } llvm-svn: 178641
* Improve formatting of function types.Daniel Jasper2013-04-011-8/+4
| | | | | | Before: void * (*a)(int *, SomeType *); After: void *(*a)(int *, SomeType *); llvm-svn: 178474
* Better fix for r177725.Daniel Jasper2013-03-221-5/+1
| | | | | | | | | | | | It turns out that -foo; can be an objective C method declaration. So instead of the previous solution, recognize objective C methods only if we are in a declaration scope. llvm-svn: 177740
* More precisely recognize ObjC method declarations.Daniel Jasper2013-03-221-3/+5
| | | | | | | | | Otherwise, +/- and the beginning of constants can be recognized incorrectly. Before: #define A - 1 After: #define A -1 llvm-svn: 177725
* Support for pointers-to-members usage via .*Alexander Kornienko2013-03-201-2/+4
| | | | | | | | | | | | | | Summary: Added support for pointers-to-members usage via .* and a few tests. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D556 llvm-svn: 177537
* Reduce penalty for breaks after "(" for functions with parameters.Daniel Jasper2013-03-201-1/+1
| | | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: aaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 177521
* Add extra indentation for multiline comparisons.Daniel Jasper2013-03-201-2/+2
| | | | | | | | | | | | | | | | This seems to be generally more desired. Before: if (aaaaaaaa && bbbbbbbb > cccccccc) {} After: if (aaaaaaaa && bbbbbbbb > cccccccc) {} Also: Some formatting cleanup on clang-format's files. llvm-svn: 177514
* Improve formatting of function types in template parameters.Daniel Jasper2013-03-201-3/+9
| | | | | | Before: A<int * (int)>; After: A<int *(int)>; llvm-svn: 177505
* Fix clang-format segfault.Daniel Jasper2013-03-181-0/+2
| | | | | | | | When annotating "lines" starting with ":", clang-format would segfault. This could actually happen in valid code, e.g. #define A : llvm-svn: 177283
* Slightly improve formatting of longer pipe statements.Daniel Jasper2013-03-141-4/+5
| | | | | | | | | | | | | | | The stronger binding of a string ending in :/= does not really make sense if it is the only character. Before: llvm::outs() << aaaaaaaaaaaaaaaaaaaaaaaa << "=" << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; After: llvm::outs() << aaaaaaaaaaaaaaaaaaaaaaaa << "=" << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; llvm-svn: 177075
* Basic support for formatting asm() statments.Daniel Jasper2013-03-141-16/+24
| | | | llvm-svn: 177073
* Fix dereference formatting in for-loops.Daniel Jasper2013-03-141-1/+1
| | | | | | Before: for (char **a = b; * a; ++a) {} After: for (char **a = b; *a; ++a) {} llvm-svn: 177037
* Improve formatting of trailing annotations.Daniel Jasper2013-03-141-4/+4
| | | | | | | | | | | | Before: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__(( unused)); After: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((unused)); llvm-svn: 177034
* Fix incorrect cast identification.Daniel Jasper2013-03-131-2/+6
| | | | | | Before: int a = sizeof(int *)+ b;" After: int a = sizeof(int *) + b; llvm-svn: 176957
* Fix formatting issue with builder-type calls.Daniel Jasper2013-03-131-1/+1
| | | | | | | | | | | | Before: ->aaaaaa()->aaaaaaaaaaa(aaaaaaaa()->aaaaaa()->aaaaa() - aaaaaaaaa()->aaaaaa() ->aaaaa()); After: a->aaaaaa()->aaaaaaaaaaa(aaaaaaaa()->aaaaaa()->aaaaa() - aaaaaaaaa()->aaaaaa()->aaaaa()); llvm-svn: 176952
* Added AnnotatedToken::isOneOf + a few other refactoringsAlexander Kornienko2013-03-131-87/+69
| | | | | | | | | | | | | | Summary: <subj> Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D536 llvm-svn: 176951
* Fix formatting of new arrays of pointers.Daniel Jasper2013-03-131-9/+14
| | | | | | | | | | | | | | Before: A = new SomeType * [Length]; A = new SomeType *[Length](); After: A = new SomeType *[Length]; A = new SomeType *[Length](); Small formatting cleanups with clang-format. llvm-svn: 176936
* Implemented formatting of rvalue referencesAlexander Kornienko2013-03-121-12/+10
| | | | | | | | | | | | | | | | | | Summary: Handle "&&" usage as rvalue reference, added tests and fixed incorrect tests that interfere with this feature. http://llvm.org/bugs/show_bug.cgi?id=15051 Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D531 llvm-svn: 176874
* Remove bad space after "default".Daniel Jasper2013-03-121-1/+2
| | | | | | | | | | | | | | Before: switch (x) { default : {} } After: switch (x) { default: {} } llvm-svn: 176861
* Correctly format arrays of pointers and function types.Daniel Jasper2013-03-011-0/+8
| | | | | | | | | | | | Before: void f(Type(*parameter)[10]) {} int(*func)(void *); After: void f(Type (*parameter)[10]) {} int (*func)(void *); llvm-svn: 176356
* Normal indent for last element of builder-type call.Daniel Jasper2013-03-011-3/+8
| | | | | | | | | | | | | | | | | | | | | | In builder type call, we indent to the laster function calls. However, for the last element of such a call, we don't need to do so, as that normally just wastes space and does not increase readability. Before: aaaaaa->aaaaaa->aaaaaa( // break aaaaaa); aaaaaaaaaaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaa ->aaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: aaaaaa->aaaaaa->aaaaaa( // break aaaaaa); aaaaaaaaaaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 176352
* Reduce penalty for splitting after "{" in static initializers.Daniel Jasper2013-02-281-3/+1
| | | | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR15379. Before: const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment 0x00, 0x00, 0x00, 0x00 // comment }; After: const uint8_t aaaaaaaaaaaaaaaaaaaaaa[0] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // comment 0x00, 0x00, 0x00, 0x00 // comment }; llvm-svn: 176262
* Dont break between (( in __attribute__((.Daniel Jasper2013-02-281-1/+4
| | | | | | | | | | | | | | Before: void aaaaaaaaaaaaaaaaaa() __attribute__( (aaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaa)); After: void aaaaaaaaaaaaaaaaaa() __attribute__((aaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaa)); llvm-svn: 176260
* No spaces around pointers to members.Daniel Jasper2013-02-281-2/+5
| | | | | | Before: (a ->* f)() After: (a->*f)() llvm-svn: 176252
* Fix spacing after binary operator as macro parameter.Daniel Jasper2013-02-281-1/+2
| | | | | | Before: COMPARE(a, == , b); After: COMPARE(a, ==, b); llvm-svn: 176241
* Fix formatting of multiplications in array subscripts.Daniel Jasper2013-02-271-0/+3
| | | | | | | | | | Before: a[a* a] = 1; After: a[a * a] = 1; llvm-svn: 176180
* Fix bad line break decision.Daniel Jasper2013-02-261-3/+3
| | | | | | | | | | | | Before: if (Intervals[i].getRange().getFirst() < Intervals[i - 1] .getRange().getLast()) {} After: if (Intervals[i].getRange().getFirst() < Intervals[i - 1].getRange().getLast()) {} llvm-svn: 176092
* In range-based for-loops, prefer splitting after ":".Daniel Jasper2013-02-261-1/+1
| | | | | | | | | | | | Before: for (const aaaaaaaaaaaaaaaaaaaaa & aaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} After: for (const aaaaaaaaaaaaaaaaaaaaa &aaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} llvm-svn: 176087
* Only keep empty lines in unwrapped lines if they preceed a line comment.Daniel Jasper2013-02-261-2/+0
| | | | | | | | | | | | | | | | | | Empty lines followed by line comments are often used to highlight the comment. Empty lines somewhere else are usually left over from manual or automatic formatting and should probably be removed. Before (clang-format would keep): S s = { a, b }; After: S s = { a, b }; llvm-svn: 176086
* Allow breaking between a type and name in variable declarations.Daniel Jasper2013-02-241-32/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR14967 and is generall necessary to avoid situations where the column limit is exceeded. The challenge is restricting such lines splits, otherwise clang-format suddenly starts breaking at bad places. Before: ReallyLongReturnType<TemplateParam1, TemplateParam2> ReallyReallyLongFunctionName( const std::string &SomeParameter, const SomeType<string, SomeOtherTemplateParameter> &ReallyReallyLongParameterName, const SomeType<string, SomeOtherTemplateParameter> &AnotherLongParameterName) {} After: ReallyLongReturnType<TemplateParam1, TemplateParam2> ReallyReallyLongFunctionName( const std::string &SomeParameter, const SomeType<string, SomeOtherTemplateParameter> & ReallyReallyLongParameterName, const SomeType<string, SomeOtherTemplateParameter> & AnotherLongParameterName) {} llvm-svn: 175999
* Better formatting of conditional expressions.Daniel Jasper2013-02-231-8/+24
| | | | | | | | | | | | | | | | | | | | | | | In conditional expressions, if the condition is split over multiple lines, also break before both operands. This prevents formattings like: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? b : c; Which are bad, because they suggestion incorrect operator precedence: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? b : c); This lead to the discovery that the expression parser incorrectly handled conditional operators and that it could also handle semicolons (which in turn reduced the amount of special casing for for-loops). As a side-effect, we can now apply the bin-packing configuration to the sections of for-loops. llvm-svn: 175973
* Don't recognize unnamed pointer parameters as casts.Daniel Jasper2013-02-231-1/+2
| | | | | | | | This fixes llvm.org/PR15061. Before: virtual void f(int *)const; After: virtual void f(int *) const; llvm-svn: 175960
* Allow splitting between string literals and identifiers.Daniel Jasper2013-02-231-0/+6
| | | | | | | | | | | | | | | Also don't break in long include directives as that is not desired. We can now format: #include "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaa" #define LL_FORMAT "ll" printf("aaaaa: %d, bbbbbbbbb: %" LL_FORMAT "d, cccccccc: %" LL_FORMAT "d, ddddddddd: %" LL_FORMAT "d\n"); Before, this led to weird results. llvm-svn: 175959
* Remove accidentally introduced no-op line.Daniel Jasper2013-02-211-1/+0
| | | | | | | Was used during experiments, but another if-statements a few lines before makes it (intentionally) useless. llvm-svn: 175803
* Consistently put {} onto the same line for empty functions.Daniel Jasper2013-02-211-2/+2
| | | | | | | | | | | | | | | | | This fixes llvm.org/PR15167. Before: LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10), BBBBBBBBB(10) { } LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10) {} After: LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10), BBBBBBBBB(10) {} LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10) {} llvm-svn: 175800
* Allow breaking between type and name in for loops.Daniel Jasper2013-02-211-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR15033. Also: Always break before a parameter, if the previous parameter was split over multiple lines. This was necessary to make the right decisions in for-loops, almost always makes the code more readable and also fixes llvm.org/PR14873. Before: for (llvm::ArrayRef<NamedDecl *>::iterator I = FD->getDeclsInPrototypeScope() .begin(), E = FD->getDeclsInPrototypeScope().end(); I != E; ++I) { } foo(bar(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccc), d, bar(e, f)); After: for (llvm::ArrayRef<NamedDecl *>::iterator I = FD->getDeclsInPrototypeScope().begin(), E = FD->getDeclsInPrototypeScope().end(); I != E; ++I) { } foo(bar(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccc), d, bar(e, f)); llvm-svn: 175741
* Don't remove blank lines within unwrapped lines.Daniel Jasper2013-02-201-1/+3
| | | | | | | | | | | | | | | | | If the code author decides to put empty lines anywhere into the code we should treat them equally, i.e. reduce them to the configured MaxEmptyLinesToKeep. With this change, we e.g. keep the newline in: SomeType ST = { // First value a, // Second value b }; llvm-svn: 175620
* Add missing clang-format null pointer check..Daniel Jasper2013-02-191-1/+2
| | | | | | .. and a test that triggers it in valid albeit questionable code. llvm-svn: 175554
* Correctly format macro with unfinished template declaration.Daniel Jasper2013-02-191-1/+2
| | | | | | | | | We can now format: #define A template <typename T> Before this created a segfault :-/. llvm-svn: 175533
* Improve indentation of builder type calls.Daniel Jasper2013-02-181-2/+1
| | | | | | | | | | | | | | | | | | | | | | | In builder-type calls, it can be very confusing to just indent parameters from the start of the line. Instead, indent 4 from the correct function call. Before: aaaaaaaaaaaaaaaaaaa()->aaaaaa(bbbbb)->aaaaaaaaaaaaaaaaaaa( // break aaaaaaaaaaaaaa); aaaaaaaaaaaaaaaaaaaaaaa *aaaaaaaaa = aaaaaa->aaaaaaaaaaaa()->aaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) ->aaaaaaaaaaaaaaaaa(); After: aaaaaaaaaaaaaaaaaaa()->aaaaaa(bbbbb)->aaaaaaaaaaaaaaaaaaa( // break aaaaaaaaaaaaaa); aaaaaaaaaaaaaaaaaaaaaaa *aaaaaaaaa = aaaaaa->aaaaaaaaaaaa() ->aaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) ->aaaaaaaaaaaaaaaaa(); llvm-svn: 175444
* Improve formatting of builder-type calls.Daniel Jasper2013-02-181-1/+1
| | | | | | | | | | | | | Before: aaaaaaa->aaaaaaa->aaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaa(aaaaaaaaaaaaaaa); After: aaaaaaa->aaaaaaa ->aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) ->aaaaaaaa(aaaaaaaaaaaaaaa); llvm-svn: 175441
* Correctly determine */& usage in more cases.Daniel Jasper2013-02-181-0/+8
| | | | | | | | | | | | | | This fixes llvm.org/PR15248. Before: Test::Test(int b) : a(b *b) {} for (int i = 0; i < a *a; ++i) {} After: Test::Test(int b) : a(b * b) {} for (int i = 0; i < a * a; ++i) {} llvm-svn: 175439
OpenPOWER on IntegriCloud