summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Improve handling of trailing 'const'.Daniel Jasper2013-05-221-4/+9
| | | | | | | Reduce the preference for breaking before a trailing 'const' according to review comments on r182362. llvm-svn: 182455
* Cut-off clang-format analysis.Daniel Jasper2013-05-221-2/+0
| | | | | | | | | | | | | | | | If clang-format is confronted with long and deeply nested lines (e.g. complex static initializers or function calls), it can currently try too hard to find the optimal solution and never finish. The reason is that the memoization does not work effectively for deeply nested lines. This patch removes an earlier workaround and instead opts for accepting a non-optimal solution in rare cases. However, it only does so only in cases where it would have to analyze an excessive number of states (currently set to 10000 - the most complex line in Format.cpp requires ~800 states) so this should not change the behavior in a relevant way. llvm-svn: 182449
* Allow breaking before a trailing const.Daniel Jasper2013-05-211-1/+1
| | | | | | | | | | | | | | Before: void someLongFunction( int someLongParameter) const; After: void someLongFunction(int someLongParameter) const; Also slightly cleanup tests. llvm-svn: 182362
* Improve recognition of template definitions.Daniel Jasper2013-05-151-2/+4
| | | | | | | | | | | | | | | | | | | | | In the long run, this will probably be better fixed by a proper expression parser.. Before: template <typename F> Matcher(const Matcher<F> & Other, typename enable_if_c < is_base_of<F, T>::value && !is_same<F, T>::value > ::type * = 0) : Implementation(new ImplicitCastMatcher<F>(Other)) {} After: template <typename F> Matcher(const Matcher<F> & Other, typename enable_if_c<is_base_of<F, T>::value && !is_same<F, T>::value>::type * = 0) : Implementation(new ImplicitCastMatcher<F>(Other)) {} llvm-svn: 181884
* Improve formatting of function types.Daniel Jasper2013-05-151-3/+4
| | | | | | | | | | | The function type detection in r181438 and r181764 detected function types too eagerly. This led to inconsistent formatting of inline assembly and (together with r181687) to an incorrect formatting of calls in macros. Before: #define DEREF_AND_CALL_F(parameter) f (*parameter) After: #define DEREF_AND_CALL_F(parameter) f(*parameter) llvm-svn: 181870
* Fix uninitialized value bug found by valgrind.Daniel Jasper2013-05-141-2/+0
| | | | llvm-svn: 181779
* Don't format sizeof/alignof as function types.Daniel Jasper2013-05-141-1/+3
| | | | | | Before: A<sizeof (*x)> a; After: A<sizeof(*x)> a; llvm-svn: 181764
* Assume macros to contain declarations.Daniel Jasper2013-05-131-0/+1
| | | | | | | | | This seems to be the vastly more common case. If we find enough examples to the contrary, we can make it smarter. Before: #define MACRO void f(int * a) After: #define MACRO void f(int *a) llvm-svn: 181687
* Fix bug when formatting overloaded operators.Daniel Jasper2013-05-101-1/+4
| | | | | | | | | | | Before, the actual operator of an overloaded operator declaration was handled as a binary operator an thus, clang-format could not find valid formattings for many examples, e.g.: template <typename AAAAAAA, typename BBBBBBB> AAAAAAA operator/(const AAAAAAA &a, BBBBBBB &b); llvm-svn: 181585
* Further fix to pointer to member formatting.Daniel Jasper2013-05-081-1/+2
| | | | | | | | With style where the *s go with the type: Before: typedef bool* (Class:: *Member)() const; After: typedef bool* (Class::*Member)() const; llvm-svn: 181439
* Fix formatting of pointers to members.Daniel Jasper2013-05-081-7/+6
| | | | | | Before: int(S::*func)(void *); After: int (S::*func)(void *); llvm-svn: 181438
* Improve line breaking in binary expressions.Daniel Jasper2013-05-081-2/+3
| | | | | | | | | | | | | | | | | | | | | | | If the LHS of a binary expression is broken, clang-format should also break after the operator as otherwise: - The RHS can be easy to miss - It can look as if clang-format doesn't understand operator precedence Before: bool aaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa != bbbbbbbbbbbbbbbbbb && ccccccccc == ddddddddddd; After: bool aaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa != bbbbbbbbbbbbbbbbbb && ccccccccc == ddddddddddd; As an additional note, clang-format would also be ok with the following formatting, it just has a higher penalty (IMO correctly so). bool aaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa != bbbbbbbbbbbbbbbbbb && ccccccccc == ddddddddddd; llvm-svn: 181430
* Correctly recognize dereference after 'delete'.Daniel Jasper2013-05-071-3/+3
| | | | | | | | With certain styles: Before: delete* x; After: delete *x; llvm-svn: 181318
* Change indentation when breaking after a type.Daniel Jasper2013-05-061-16/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | clang-format did not indent any declarations/definitions when breaking after the type. With this change, it indents for all declarations but does not indent for function definitions, i.e.: Before: const SomeLongTypeName& some_long_variable_name; typedef SomeLongTypeName SomeLongTypeAlias; const SomeLongReturnType* SomeLongFunctionName(); const SomeLongReturnType* SomeLongFunctionName() { ... } After: const SomeLongTypeName& some_long_variable_name; typedef SomeLongTypeName SomeLongTypeAlias; const SomeLongReturnType* SomeLongFunctionName(); const SomeLongReturnType* SomeLongFunctionName() { ... } While it might seem inconsistent to indent function declarations, but not definitions, there are two reasons for that: - Function declarations are very similar to declarations of function type variables, so there is another side to consistency to consider. - There can be many function declarations on subsequent lines and not indenting can make them harder to identify. Function definitions are already separated by their body and not indenting makes the function name slighly easier to find. llvm-svn: 181187
* Break the class-inheritance ":" to the new line.Daniel Jasper2013-05-061-3/+1
| | | | | | | | | | | | | | | | | | This seems to be more common in LLVM, Google and Chromium. Before: class AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA : public BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, public CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC { }; After: class AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA : public BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB, public CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC { }; llvm-svn: 181183
* Don't put a space before ellipsis.Daniel Jasper2013-05-061-0/+2
| | | | | | Before: template <class ... Ts> void Foo(Ts ... ts) { Foo(ts ...); } After: template <class... Ts> void Foo(Ts... ts) { Foo(ts...); } llvm-svn: 181182
* Add space between ; and (.Daniel Jasper2013-05-031-1/+1
| | | | | | Before: for (int i = 0;(i < 10); ++i) {} After: for (int i = 0; (i < 10); ++i) {} llvm-svn: 181020
* Fix expression recognition in for-loops.Daniel Jasper2013-05-031-0/+3
| | | | | | Before: for (; a&& b;) {} After: for (; a && b;) {} llvm-svn: 181017
* Improve clang-format's memoization behavior.Daniel Jasper2013-04-251-0/+2
| | | | | | | | | | | | | | | Deeply nested expressions basically break clang-format's memoization. This patch slightly improves the situations and makes expressions like aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa( aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa( aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa( aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa(aaaaa( aaaaa(aaaaa()))))))))))))))))))))))))))))))))))))))); work. llvm-svn: 180264
* Fix formatting of complex #if expressions.Daniel Jasper2013-04-231-0/+5
| | | | | | | | | | | | | | Before: #if !defined(AAAAAAAAAAAAAAAA) && (defined CCCCCCCC || \ defined DDDDDDDD) && defined(BBBBBBBB) After: #if !defined(AAAAAAAAAAAAAAAA) && (defined CCCCCCCC || defined DDDDDDDD) && \ defined(BBBBBBBB) This fixes llvm.org/PR15828. llvm-svn: 180105
* 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
OpenPOWER on IntegriCloud