summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Improve handling of unterminated string literals.Daniel Jasper2013-07-161-4/+3
| | | | | | | Before, clang-format would simply eat these as they were recognized as whitespace. With this patch, they are mostly left alone. llvm-svn: 186454
* Revamp the formatting of C++11 braced init lists.Daniel Jasper2013-07-161-1/+1
| | | | | | | | | | | | | | The fundamental concept is: Format as if the braced init list was a function call (with parentheses replaced by braces). If there is no name/type before the opening brace (e.g. if the braced list is nested), assume a zero-length identifier just before the opening brace. This behavior is gated on a new style flag, which for now replaces the SpacesInBracedLists style flag. Activate this style flag for Google style to reflect recent style guide changes. llvm-svn: 186433
* clang-format: Improve detection of function types.Daniel Jasper2013-07-161-1/+3
| | | | | | | | | | This fixes an incorrect detection that led to a formatting error. Before: some_var = function (*some_pointer_var)[0]; After: some_var = function(*some_pointer_var)[0]; llvm-svn: 186402
* clang-format: Improve c-style cast detection.Daniel Jasper2013-07-151-2/+3
| | | | | | | | | | | Before: #define x ((int) - 1) #define p(q) ((int *) & q) After: #define x ((int)-1) #define p(q) ((int *)&q) llvm-svn: 186324
* Improvement of change r186320.Daniel Jasper2013-07-151-2/+2
| | | | | | | | | | | | | | | | Fixed a test that by now passed for the wrong reason. Before: llvm::outs() << "aaaaaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: llvm::outs() << "aaaaaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa); Also reformatted Format.cpp with the latest changes (1 formatting fix and 1 layout change of a <<-chain). llvm-svn: 186322
* Improve formatting of operator<< chains.Daniel Jasper2013-07-151-1/+1
| | | | | | | | | | | | | Before: llvm::outs() << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa; After: llvm::outs() << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa; llvm-svn: 186320
* clang-format: Break before/between array subscript expressions.Daniel Jasper2013-07-121-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | clang-format used to treat array subscript expressions much like function call (just replacing () with []). However, this is not really appropriate especially for expressions with multiple subscripts. Although it might seem counter-intuitive, the most consistent solution seems to be to always (if necessary) break before a square bracket, never after it. Also, multiple subscripts of the same expression should be aligned if they are on subsequent lines. Before: aaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaaaaaaaaaaaaaaa][ bbbbbbbbbbbbbbbbbbbbbbbbb] = c; aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa][ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = ccccccccccc; After: aaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaaaaaaaaaaaaaaa] [bbbbbbbbbbbbbbbbbbbbbbbbb] = c; aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa] [bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = ccccccccccc; llvm-svn: 186153
* clang-format: Break before trailing annotations.Daniel Jasper2013-07-111-2/+4
| | | | | | | | | | | | | | (if they are not function-like). Before: SomeFunction(aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE; After: SomeFunction(aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE; llvm-svn: 186117
* Improve detection of trailing return types.Daniel Jasper2013-07-111-1/+2
| | | | | | | | | | | | Trailing return types can only occur in declaration contexts. Before: void f() { auto a = b -> c(); } After: void f() { auto a = b->c(); } llvm-svn: 186087
* Keep trailing annotations close to their argument.Daniel Jasper2013-07-111-0/+2
| | | | | | | | | | | | Before: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY( aaaaaaaaaaaa); After: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa); llvm-svn: 186077
* Add experimental flag for adaptive parameter bin-packing.Daniel Jasper2013-07-101-5/+22
| | | | | | | | | | | | | | | | | | | | | | | | | This is not activated for any style, might change or go away completely. For those that want to play around with it, set ExperimentalAutoDetectBinPacking to true. clang-format will then: Look at whether function calls/declarations/definitions are currently formatted with one parameter per line (on a case-by-case basis). If so, clang-format will avoid bin-packing the parameters. If all parameters are on one line (thus that line is "inconclusive"), clang-format will make the choice dependent on whether there are other bin-packed calls/declarations in the same file. The reason for this change is that bin-packing in some situations can be really bad and an author might opt to put one parameter on each line. If the author does that, he might want clang-format not to mess with that. If the author is unhappy with the one-per-line formatting, clang-format can easily be convinced to bin-pack by putting any two parameters on the same line. llvm-svn: 186003
* Initial support for formatting trailing return types.Daniel Jasper2013-07-091-2/+11
| | | | | | | | | | | | This fixes llvm.org/PR15170. For now, the basic formatting rules are (based on the C++11 standard): * Surround the "->" with spaces. * Break before "->". Also fix typo. llvm-svn: 185938
* Format overloaded operators like other functions.Daniel Jasper2013-07-091-2/+2
| | | | | | | | | | | | | | This fixes llvm.org/PR16328 (at least partially). Before: SomeLoooooooooooooooooooooooooooooogType operator<<( const SomeLooooooooogType &a, const SomeLooooooooogType &b); After: SomeLoooooooooooooooooooooooooooooogType operator<<(const SomeLooooooooogType &a, const SomeLooooooooogType &b); llvm-svn: 185908
* Fix incorrect incorrect cast identification in clang-format.Daniel Jasper2013-07-081-0/+1
| | | | | | | | | | | This fixes llvm.org/PR16534. Before: aaaaa& operator+(const aaaaa&)LLVM_DELETED_FUNCTION; After: aaaaa& operator+(const aaaaa&) LLVM_DELETED_FUNCTION; llvm-svn: 185828
* Reformat clang-format's source files after r185822 and others.Daniel Jasper2013-07-081-11/+10
| | | | llvm-svn: 185823
* Fix formatting for allocation of new pointer variables.Daniel Jasper2013-07-051-1/+2
| | | | | | | | | | | | Before: T **t = new T * ; T **q = new T * (); After: T **t = new T *; T **q = new T *(); llvm-svn: 185699
* Don't break after a "(" following a binary operator.Daniel Jasper2013-07-051-4/+10
| | | | | | | | | | | | | | | | Additionally, allow breaking after c-style casts, but with a high penalty. Before: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *foo = ( aaaaaaaaaaaaaaaaa *)bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; After: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *foo = (aaaaaaaaaaaaaaaaa *) bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; This fixes llvm.org/PR16049. llvm-svn: 185685
* Fixed typo: NoneComment -> NonComment, no other changes.Alexander Kornienko2013-07-041-14/+14
| | | | llvm-svn: 185640
* Added AlwaysBreakBeforeMultilineStrings option.Alexander Kornienko2013-07-041-0/+7
| | | | | | | | | | | | | | | | | Summary: Always breaking before multiline strings can help format complex expressions containing multiline strings more consistently, and avoid consuming too much horizontal space. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1097 llvm-svn: 185622
* Fix formatting of long declarations with const type.Daniel Jasper2013-07-021-7/+28
| | | | | | | | | | | Before (exceeding the column limit): LoooooooooooooooooooooooooooooooooooooooongType const LoooooooooooooooooooooooooooooooooooooooongVariable; After: LoooooooooooooooooooooooooooooooooooooooongType const LoooooooooooooooooooooooooooooooooooooooongVariable; llvm-svn: 185418
* Don't add an extra space before ellipsis after pointers.Daniel Jasper2013-07-011-2/+2
| | | | | | | | | | | Before (for styles where the pointer binds to the type): template <class... Ts> void Foo(Ts... ts) {} template <class... Ts> void Foo(Ts* ... ts) {} After: template <class... Ts> void Foo(Ts... ts) {} template <class... Ts> void Foo(Ts*... ts) {} llvm-svn: 185321
* Keep space between pointer and block comment.Daniel Jasper2013-07-011-1/+1
| | | | | | | | | | Before: void f(int */* unused */) {} After: void f(int * /* unused */) {} The previous version seems to be valid C++ code but confuses many syntax highlighters. llvm-svn: 185320
* Put helper classes in an anonymous namespace.Craig Topper2013-07-011-0/+4
| | | | llvm-svn: 185301
* Run clang-format on lib/Format code after r184894. No other changes.Nico Weber2013-06-261-2/+2
| | | | llvm-svn: 184896
* Formatter: Don't put a space after parameter-naming block comments.Nico Weber2013-06-261-0/+2
| | | | | | | | | | | | | Before: f(a, b, /*doFoo=*/ false); Now: f(a, b, /*doFoo=*/false); This style is a lot more common: $ ack -H '=\*\/\w' lib | wc -l 1281 $ ack -H '=\*\/ \w' lib | wc -l 70 llvm-svn: 184894
* Formatter/ObjC: Correctly format casts in objc message send expressions.Nico Weber2013-06-251-3/+2
| | | | llvm-svn: 184804
* Fix a problem in ExpressionParser leading to trailing comments affecting ↵Alexander Kornienko2013-06-171-7/+4
| | | | | | | | | | | | | | | | | | | | | | | | | indentation of an expression after a line break. Summary: E.g. the second line in return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + b; // is indented 4 characters more than in return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + b; Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D984 llvm-svn: 184078
* Preserve newlines before block comments in static initializers.Alexander Kornienko2013-06-121-1/+1
| | | | | | | | | | | | | | | | Summary: Basically, don't special-case line comments in this regard. And fixed an incorrect test, that relied on the wrong behavior. Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D962 llvm-svn: 183851
* Fixed calculation of penalty when breaking tokens.Alexander Kornienko2013-06-071-7/+10
| | | | | | | | | | | | | | | | | | | | | Summary: Introduced two new style parameters: PenaltyBreakComment and PenaltyBreakString. Add penalty for each character of a breakable token beyond the column limit (this relates mainly to comments, as they are broken only on whitespace). Tuned PenaltyBreakComment to prefer comment breaking over breaking inside most binary expressions. Fixed a bug that prevented *, & and && from being considered TT_BinaryOperator in the presense of adjacent comments. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D933 llvm-svn: 183530
* Fix incorrect line breaking before trailing block comments.Daniel Jasper2013-06-061-1/+1
| | | | | | | | | | | | | | | | | Before, clang-format would happily move a trailing block comment to a new line, which normally changes the perceived binding of that comment. E.g., it would move: void f() { /* comment */ ... } to: void f() { /* comment */ ... } llvm-svn: 183420
* Fix clang-format's expression parser for leading }s.Daniel Jasper2013-06-061-1/+5
| | | | | | | | The leading "}" in the construct "} else if (..) {" was confusing the expression parser. Thus, no fake parentheses were generated and the indentation was broken in some cases. llvm-svn: 183393
* Improve c-style cast detection.Daniel Jasper2013-06-061-1/+4
| | | | | | | | | | | | | | Before: return (my_int) aaaa; template <> void f<int>(int i)SOME_ANNOTATION; f("aaaa" SOME_MACRO(aaaa)"aaaa"); After: return (my_int)aaaa; template <> void f<int>(int i) SOME_ANNOTATION; f("aaaa" SOME_MACRO(aaaa) "aaaa"); llvm-svn: 183389
* UTF-8 support for clang-format.Alexander Kornienko2013-06-051-23/+16
| | | | | | | | | | | | | | | | | | | | Summary: Detect if the file is valid UTF-8, and if this is the case, count code points instead of just using number of bytes in all (hopefully) places, where number of columns is needed. In particular, use the new FormatToken.CodePointCount instead of TokenLength where appropriate. Changed BreakableToken implementations to respect utf-8 character boundaries when in utf-8 mode. Reviewers: klimek, djasper Reviewed By: djasper CC: cfe-commits, rsmith, gribozavr Differential Revision: http://llvm-reviews.chandlerc.com/D918 llvm-svn: 183312
* Let clang-format remove empty lines before "}".Daniel Jasper2013-06-031-1/+1
| | | | | | | | | | | | | | | | | These lines almost never aid readability. Before: void f() { int i; // some variable } After: void f() { int i; // some variable } llvm-svn: 183112
* Improve recognition of template parameters.Daniel Jasper2013-06-011-1/+8
| | | | | | Before: return a<b &&c> d; After: return a < b && c > d; llvm-svn: 183077
* Improve clang-format's c-style cast detection.Daniel Jasper2013-05-311-11/+27
| | | | | | | | | | | | | | | | Before: x[(uint8) y]; x = (uint8) y; void f() { x = (uint8) y; } #define AA(X) sizeof(((X *) NULL)->a) After: x[(uint8)y]; x = (uint8)y; void f() { x = (uint8)y; } #define AA(X) sizeof(((X *)NULL)->a) llvm-svn: 183014
* Properly format nested conditional operators.Daniel Jasper2013-05-311-5/+27
| | | | | | | | | | | | | | | | | | Before: bool aaaaaa = aaaaaaaaaaaaa // ? aaaaaaaaaaaaaaa : bbbbbbbbbbbbbbb // ? ccccccccccccccc : ddddddddddddddd; After: bool aaaaaa = aaaaaaaaaaaaa // ? aaaaaaaaaaaaaaa : bbbbbbbbbbbbbbb // ? ccccccccccccccc : ddddddddddddddd; llvm-svn: 183007
* The second step in the token refactoring.Manuel Klimek2013-05-291-229/+168
| | | | | | | | | | Gets rid of AnnotatedToken, putting everything into FormatToken. FormatTokens are created once, and only referenced by pointer. This enables multiple future features, like having tokens shared between multiple UnwrappedLines (while there's still work to do to fully enable that). llvm-svn: 182859
* Add option to always break template declarations.Daniel Jasper2013-05-291-0/+3
| | | | | | | | | | | | | | With option enabled (e.g. in Google-style): template <typename T> void f() {} With option disabled: template <typename T> void f() {} Enabling this for Google-style and Chromium-style, not sure which other styles would prefer that. llvm-svn: 182849
* Fix formatting regression regarding pointers to arrays.Daniel Jasper2013-05-281-1/+1
| | | | | | | | | Before: f( (*PointerToArray)[10]); After: f((*PointerToArray)[10]); This fixes llvm.org/PR16163 llvm-svn: 182777
* Make UnwrappedLines and AnnotatedToken contain pointers to FormatToken.Manuel Klimek2013-05-281-33/+34
| | | | | | The FormatToken is now not copyable any more. llvm-svn: 182772
* Initial support for designated initializers.Daniel Jasper2013-05-281-8/+14
| | | | llvm-svn: 182767
* Clean up formatting of function types.Daniel Jasper2013-05-281-6/+8
| | | | | | | | | | | | Before: int (*func)(void*); void f() { int(*func)(void*); } After (consistent space after "int"): int (*func)(void*); void f() { int (*func)(void*); } llvm-svn: 182756
* Improve formatting of templates.Daniel Jasper2013-05-271-1/+2
| | | | | | | | | Before: A < int&& > a; After: A<int &&> a; Also remove obsolete FIXMEs. llvm-svn: 182741
* Formatter/ObjC: In dictionary literals, break after ':', not before it.Nico Weber2013-05-261-5/+20
| | | | | | | | | | | | | | | | Before: @{ NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : regularFont, }; Now: @{ NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : regularFont, }; ':'s in dictionary literals (and the corresponding {}s) are now marked as TT_ObjCDictLiteral too, which makes further improvements to dict literal layout possible. llvm-svn: 182716
* More tests and a fix for braced init lists.Daniel Jasper2013-05-231-2/+2
| | | | | | Before: f(new vector<int> { 1, 2, 3 }); After: f(new vector<int>{ 1, 2, 3 }); llvm-svn: 182614
* Improve formatting of braced lists.Daniel Jasper2013-05-231-4/+3
| | | | | | Before: vector<int> v{ -1}; After: vector<int> v{-1}; llvm-svn: 182597
* Improve formatting of braced lists.Daniel Jasper2013-05-231-0/+5
| | | | | | | | | | | | | Before: vector<int> x { 1, 2, 3 }; After: vector<int> x{ 1, 2, 3 }; Also add a style option to remove the spaces inside braced lists, so that the above becomes: std::vector<int> v{1, 2, 3}; llvm-svn: 182570
* Makes whitespace management more consistent.Manuel Klimek2013-05-221-3/+20
| | | | | | | | | | | | | | | | | | | | | | | | | Instead of selectively storing some changes and directly generating replacements for others, we now notify the WhitespaceManager of the whitespace before every token (and optionally with more changes inside tokens). Then, we run over all whitespace in the very end in original source order, where we have all information available to correctly align comments and escaped newlines. The future direction is to pull more of the comment alignment implementation that is now in the BreakableToken into the WhitespaceManager. This fixes a bug when aligning comments or escaped newlines in unwrapped lines that are handled out of order: #define A \ f({ \ g(); \ }); ... now gets correctly layouted. llvm-svn: 182467
* Improve clang-format's stream formatting.Daniel Jasper2013-05-221-1/+1
| | | | | | | | | | | | | | | clang-format was a bit too aggressive when trying to keep labels and values on the same line. Before: llvm::outs() << "aaaaaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: llvm::outs() << "aaaaaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 182458
OpenPOWER on IntegriCloud