summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* 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-152-8/+8
| | | | | | | | | | | | | | | | 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-152-2/+2
| | | | | | | | | | | | | Before: llvm::outs() << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa; After: llvm::outs() << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa << "aaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaaaaa; llvm-svn: 186320
* Add 'static' and 'const' qualifiers to some arrays of strings.Craig Topper2013-07-151-1/+1
| | | | llvm-svn: 186314
* clang-format: Improve <<-formatting.Daniel Jasper2013-07-121-0/+5
| | | | | | | | | | | | | | | | This fixes a regression caused by r186115. Before: Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; After: Diag(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbb) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; llvm-svn: 186164
* clang-format: Fix string literal breaking.Daniel Jasper2013-07-121-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | Before this patch, it did not cooperate with Style::AlwaysBreakBeforeMultilineStrings. Thus, it would turn aaaaaaaaaaaa(aaaaaaaaaaaaa, "aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa"); into: aaaaaaaaaaaa(aaaaaaaaaaaaa, "aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa " "aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa"); and only a second format step would lead to the desired (with that option): aaaaaaaaaaaa(aaaaaaaaaaaaa, "aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa " "aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa"); This could even lead to clang-format breaking the string at a different character and thus leading to a completely different end result. llvm-svn: 186154
* clang-format: Break before/between array subscript expressions.Daniel Jasper2013-07-122-3/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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: Fix bug concerning the alignment of "}".Daniel Jasper2013-07-111-1/+1
| | | | | | | | | | | | | | | | Before: int i; // indented 2 space more than clang-format would use. SomeReturnType // clang-format invoked on this line. SomeFunctionMakingLBraceEndInColumn80() { } // This is the indent clang-format would prefer. After: int i; // indented 2 space more than clang-format would use. SomeReturnType // clang-format invoked on this line. SomeFunctionMakingLBraceEndInColumn80() { } llvm-svn: 186120
* 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
* clang-format: Avoid line breaks before the first <<.Daniel Jasper2013-07-111-9/+27
| | | | | | | | | | | | | | | | | This puts a slight penalty on the linebreak before the first "<<", so that clang-format generally tries to keep things on the first line. User feedback has shown that this is generally desirable. Before: llvm::outs() << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =" << aaaaaaaaaaaaaaaaaaaaaaaaaaa; After: llvm::outs() << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =" << aaaaaaaaaaaaaaaaaaaaaaaaaaa; llvm-svn: 186115
* 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
* Fix indentation problem for comments in call chainsDaniel Jasper2013-07-111-1/+2
| | | | | | | | | | | | | | Before: SomeObject // Calling someFunction on SomeObject .someFunction(); After: SomeObject // Calling someFunction on SomeObject .someFunction(); llvm-svn: 186085
* 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-103-12/+62
| | | | | | | | | | | | | | | | | | | | | | | | | 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-093-3/+13
| | | | | | | | | | | | 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
* Avoid confusing indentations for chained function calls.Daniel Jasper2013-07-091-4/+18
| | | | | | | | | | | | | | | | | | | Basically treat a function with a trailing call similar to a function with multiple parameters. Before: aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa)) .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(); After: aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa)) .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(); Also fix typo. llvm-svn: 185930
* Fix alignment of closing brace in braced initializers.Daniel Jasper2013-07-094-33/+36
| | | | | | | | | | | | | | | | | | | | | | Before: someFunction(OtherParam, BracedList{ // comment 1 (Forcing intersting break) param1, param2, // comment 2 param3, param4 }); After: someFunction(OtherParam, BracedList{ // comment 1 (Forcing intersting break) param1, param2, // comment 2 param3, param4 }); To do so, the UnwrappedLineParser now stores the information about the kind of brace in the FormatToken. llvm-svn: 185914
* Format overloaded operators like other functions.Daniel Jasper2013-07-092-5/+8
| | | | | | | | | | | | | | 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-089-59/+51
| | | | llvm-svn: 185823
* Prefer similar line breaks.Daniel Jasper2013-07-081-9/+15
| | | | | | | | | | | | | | | | | | | | | | | This adds a penalty for clang-format for each break that occurs in a set of parentheses (including fake parenthesis that determine the range of certain operator precendences) that have not yet been broken. Thereby, clang-format prefers similar line breaks. This fixes llvm.org/PR15506. Before: const int kTrackingOptions = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways; After: const int kTrackingOptions = NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways; Also removed ParenState::ForFakeParenthesis which has become unused. llvm-svn: 185822
* Fix for corner cases in code handling leading "* " decorations in block commentsAlexander Kornienko2013-07-082-28/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Fixes problems that lead to incorrect formatting of these and similar snippets: /* ** */ /* **/ /* * */ /* *test */ Clang-format used to think that all the cases above use "* " decoration, and failed to calculate insertion position properly. It also used to remove leading "* " in the last line. Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1113 llvm-svn: 185818
* Use SmallVectorImpl::reverse_iterator instead of SmallVector to avoid ↵Craig Topper2013-07-081-1/+1
| | | | | | specifying the vector size. llvm-svn: 185784
* 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
* Improve detection for preventing certain kind of formatting patterns.Daniel Jasper2013-07-051-14/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a better implementation of r183097. The main purpose is to prevent certain constructs to be formatted "like a block of text". Before: aaaaaaaaaaaaa< aaaaaaaaaa, aaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>* aaaa = new aaaaaaaaaaaaa< aaaaaaaaaa, aaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>(bbbbbbbbbbbbbbbbbbbbbbbb); aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (*cccccccccccccccc)[ dddddddddddddddddddddddddddddddddddddddddddddddddddddddd]; After: aaaaaaaaaaaaa<aaaaaaaaaa, aaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>* aaaa = new aaaaaaaaaaaaa<aaaaaaaaaa, aaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa>( bbbbbbbbbbbbbbbbbbbbbbbb); aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb] = (*cccccccccccccccc)[ dddddddddddddddddddddddddddddddddddddddddddddddddddddddd]; llvm-svn: 185687
* 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-043-26/+26
| | | | llvm-svn: 185640
* Added AlwaysBreakBeforeMultilineStrings option.Alexander Kornienko2013-07-042-0/+11
| | | | | | | | | | | | | | | | | 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
* Don't insert confusing line breaks in comparisons.Daniel Jasper2013-07-031-2/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In general, clang-format breaks after an operator if the LHS spans multiple lines. Otherwise, this can lead to confusing effects and effectively hide the operator precendence, e.g. in if (aaaaaaaaaaaaaa == bbbbbbbbbbbbbb && c) { ... This patch removes this rule for comparisons, if the LHS is not a binary expression itself as many users were wondering why clang-format inserts an unnecessary linebreak. Before: if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) > 5) { ... After: if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) > 5) { ... In the long run, we might: - Want to do this for other binary expressions as well. - Do this only if the RHS is short or even only if it is a literal. llvm-svn: 185530
* 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
* Fix incorrect token counting introduced by r185319.Daniel Jasper2013-07-011-1/+3
| | | | | | | | | | | | This lead to weird formatting. Before: DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } }); After: DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } }); llvm-svn: 185346
* Avoid column limit violation in block comments in certain cases.Alexander Kornienko2013-07-011-4/+10
| | | | | | | | | | | | | | | | | Summary: Add penalty when an excessively long line in a block comment can not be broken on a leading whitespace. Lack of this addition can lead to severe column width violations when they can be easily avoided. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1071 llvm-svn: 185337
* Don't align "} // namespace" comments.Daniel Jasper2013-07-011-7/+17
| | | | | | | | | | | | | | | | This is not all bad, but people are often surprised by it. Before: namespace { int SomeVariable = 0; // comment } // namespace After: namespace { int SomeVariable = 0; // comment } // namespace llvm-svn: 185327
* 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
* Fix braced-list detection in lieu of trailing comments.Daniel Jasper2013-07-011-1/+6
| | | | | | | | | | Before: DoSomethingWithVector({ } /* No data */); After: DoSomethingWithVector({} /* No data */); llvm-svn: 185319
* Put helper classes in an anonymous namespace.Craig Topper2013-07-011-0/+8
| | | | llvm-svn: 185303
* Use LLVM_DELETED_FUNCTION on unimplemented copy constructor and assignment ↵Craig Topper2013-07-011-2/+2
| | | | | | operator. llvm-svn: 185302
* Put helper classes in an anonymous namespace.Craig Topper2013-07-011-0/+4
| | | | llvm-svn: 185301
* Use static for helper functions instead of an anonymous namespace per coding ↵Craig Topper2013-07-011-11/+8
| | | | | | standards. llvm-svn: 185300
* Make string pointer const.Craig Topper2013-06-301-1/+1
| | | | llvm-svn: 185296
* Put helper classes into anonymous namespace.Craig Topper2013-06-301-0/+4
| | | | llvm-svn: 185295
* Use lexing mode based on FormatStyle.Standard.Alexander Kornienko2013-06-281-3/+4
| | | | | | | | | | | | | | | | | | | | | Summary: Some valid pre-C++11 constructs change meaning when lexed in C++11 mode, e.g. #define x(_a) printf("foo"_a); (example from http://llvm.org/bugs/show_bug.cgi?id=16342). "foo"_a is treated as a user-defined string literal when parsed in C++11 mode. In order to deal with this correctly, we need to set lexing mode according to which standard the code conforms to. We already have a configuration value for this (FormatStyle.Standard), which seems to be appropriate to use in this case as well. Reviewers: klimek CC: cfe-commits, gribozavr Differential Revision: http://llvm-reviews.chandlerc.com/D1028 llvm-svn: 185149
* Fix a comment.Nico Weber2013-06-261-1/+1
| | | | llvm-svn: 184905
* Run clang-format on lib/Format code after r184894. No other changes.Nico Weber2013-06-263-24/+23
| | | | 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
* Fix a comment.Nico Weber2013-06-251-1/+1
| | | | llvm-svn: 184873
* Formatter/ObjC: Correctly format casts in objc message send expressions.Nico Weber2013-06-251-3/+2
| | | | llvm-svn: 184804
* Add an option to not indent declarations when breaking after the type.Manuel Klimek2013-06-211-1/+6
| | | | | | Make that option the default for LLVM style. llvm-svn: 184563
OpenPOWER on IntegriCloud