summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Fix formatting bug with comment in weird place.Daniel Jasper2013-09-271-1/+4
| | | | | | | | | | | | | | Before: template <typename T> // T should be one of {A, B}. void f() {} After: template <typename T> // T should be one of {A, B}. void f() {} llvm-svn: 191492
* clang-format: Option to removing the space before assignment operators.Daniel Jasper2013-09-252-0/+7
| | | | | | Patch contributed by Aaron Wishnick. Thank you! llvm-svn: 191375
* clang-format: Improve address-of-operator detectionDaniel Jasper2013-09-211-1/+1
| | | | | | | | | | Before: size = sizeof * a; After: size = sizeof *a; llvm-svn: 191139
* clang-format: Don't accidentally move tokens into preprocessor directive.Daniel Jasper2013-09-172-29/+38
| | | | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR17265. Before: Foo::Foo() #ifdef BAR : baz(0) #endif { } After: Foo::Foo() #ifdef BAR : baz(0) #endif { } llvm-svn: 190861
* clang-format: Fix line breaking bug after empty ifs.Daniel Jasper2013-09-171-0/+1
| | | | | | | | | | | | | | | | | Before: if () { } else { } After: if () { } else { } This fixed llvm.org/PR17262. llvm-svn: 190855
* clang-format: Don't split a >>-operator.Daniel Jasper2013-09-171-0/+3
| | | | | | | | | | | | | | | Before (with column limit 60): aaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa > > aaaaa); After: aaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaa >> aaaaa); (Not sure how that could have stayed in that long without being detected..) llvm-svn: 190854
* When in pre-c++11 mode, treat _T("xxx") as a single string literal, repeat ↵Alexander Kornienko2013-09-165-31/+100
| | | | | | | | | | | | | | the _T() part around each fragment. This addresses http://llvm.org/PR17122 Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek, rsmith Differential Revision: http://llvm-reviews.chandlerc.com/D1640 llvm-svn: 190804
* clang-format: Fix bug in style option AlwaysBreakTemplateDeclarations.Daniel Jasper2013-09-141-0/+3
| | | | | | | | | | | | | | | Before: template <template <typename> class Fooooooo, template <typename> class Baaaaaaar> struct C {}; After: template <template <typename> class Fooooooo, template <typename> class Baaaaaaar> struct C {}; llvm-svn: 190747
* clang-format: Detect braced lists in subscript expressions.Daniel Jasper2013-09-131-1/+1
| | | | | | | | | | Before (even with Style.Cpp11BracedListStyle): f(MyMap[{ composite, key }]); After: f(MyMap[{composite, key}]); llvm-svn: 190678
* clang-format: Fix incorrect enum parsing / layouting.Daniel Jasper2013-09-136-46/+36
| | | | | | | | | | | | | | | Before: enum { Bar = Foo < int, int > ::value }; After: enum { Bar = Foo<int, int>::value }; llvm-svn: 190674
* clang-format: Fix bug in pointer detectionDaniel Jasper2013-09-111-1/+1
| | | | | | | | | Before: for (int i = 0; i* 2 < z; i *= 2) {} After: for (int i = 0; i * 2 < z; i *= 2) {} llvm-svn: 190546
* Support for CR LF newlines.Alexander Kornienko2013-09-113-35/+42
| | | | | | | | | | | | | | | | | | Summary: reformat() tries to determine the newline style used in the input (either LF or CR LF), and uses it for the output. Maybe not every single case is supported, but at least the bug described in http://llvm.org/PR17182 should be resolved. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1643 llvm-svn: 190519
* Don't divide L and #x in macro definitions. Fixes http://llvm.org/PR17144Alexander Kornienko2013-09-101-0/+2
| | | | | | | | | | | | Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1639 llvm-svn: 190408
* Correctly calculate OriginalColumn after multi-line tokens.Alexander Kornienko2013-09-103-36/+22
| | | | | | | | | | | | | | Summary: This also unifies the handling of escaped newlines for all tokens. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1638 llvm-svn: 190405
* clang-format: Understand function type typedefs with typeof.Daniel Jasper2013-09-101-0/+5
| | | | | | | | | | | Before: typedef typeof(int(int, int)) * MyFunc; After: typedef typeof(int(int, int)) *MyFunc; This fixes llvm.org/PR17178. llvm-svn: 190401
* Calculate and store ColumnWidth instead of CodePointCount in FormatTokens.Alexander Kornienko2013-09-106-70/+67
| | | | | | | | | | | | | | | | Summary: This fixes various issues with mixed tabs and spaces handling, e.g. when realigning block comments. Reviewers: klimek, djasper Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1608 llvm-svn: 190395
* clang-format: Keep empty lines and format 1-line nested blocks.Daniel Jasper2013-09-081-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | Let clang-format consistently keep up to one empty line (configured via FormatStyle::MaxEmptyLinesToKeep) in nested blocks, e.g. lambdas. Also, actually format single statements in nested blocks. Before: DEBUG({ int i; }); DEBUG({ int i; // an empty line here would just be removed. int j; }); After: DEBUG({ int i; }); DEBUG({ int i; int j; }); llvm-svn: 190278
* clang-format: Fix regression introduced by r190038.Daniel Jasper2013-09-061-1/+6
| | | | | | | | | | | | | Before: Constructor() : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) { } After: Constructor() : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) { } llvm-svn: 190209
* clang-format: Format typed enums with nested names.Daniel Jasper2013-09-061-1/+2
| | | | | | | | | The explicit type specified for an enum can actually have a nested name specifier. This fixes llvm.org/PR17125. llvm-svn: 190208
* clang-format: Don't confuse operator[] with lambdas.Daniel Jasper2013-09-061-1/+2
| | | | | | | | | | | | | Before: double &operator[](int i) { return 0; } int i; After: double &operator[](int i) { return 0; } int i; This fixes llvm.org/PR17134. llvm-svn: 190207
* Don't remove trailing escaped newline from line comments.Alexander Kornienko2013-09-061-1/+1
| | | | llvm-svn: 190175
* clang-format: Fix regression introduced by r189353.Daniel Jasper2013-09-062-3/+4
| | | | | | | | | | | | | | | | | | | | Before: FirstToken->WhitespaceRange.getBegin() .getLocWithOffset(First->LastNewlineOffset); After: FirstToken->WhitespaceRange.getBegin().getLocWithOffset( First->LastNewlineOffset); Re-add logic to prevent breaking after an empty set of parentheses. Basically it seems that calling a function without parameters is more like navigating along the same object than it is a separate step of a builder-type call. We might need to extends this in future to allow "short" parameters that e.g. are an index accessing a specific element. llvm-svn: 190126
* clang-format: Fix regression introduced by r189337.Daniel Jasper2013-09-063-16/+19
| | | | | | | | | | | | | | | Before: if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) ... After: if (aaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) == 5) ... Also precompute startsBinaryExpression() to improve performance. llvm-svn: 190124
* clang-format: Fix comment formatting bugs in nested blocks.Daniel Jasper2013-09-065-39/+54
| | | | | | | | | | | This fixes two issues: 1) The indent of a line comment was not adapted to the subsequent statement as it would be outside of a nested block. 2) A missing DryRun flag caused actualy breaks to be inserted in overly long comments while trying to come up with the best line breaking decisions. llvm-svn: 190123
* Unbreak build with libc++, whose std::list<T> requires T to be complete.Douglas Gregor2013-09-051-1/+4
| | | | llvm-svn: 190075
* Add ATTRIBUTE_UNUSED to silence unused-function warning in releaseDaniel Jasper2013-09-051-1/+2
| | | | | | builds. llvm-svn: 190061
* Fixes PR 17106 (explicitly typed enums are formatted differently).Manuel Klimek2013-09-051-3/+1
| | | | | | | | | | | | | | Before: enum X : int { A, B, C }; After: enum X : int { A, B, C }; llvm-svn: 190054
* Handle zero-width and double-width characters in string literals and comments.Alexander Kornienko2013-09-057-55/+115
| | | | | | | | | | | | | | | | | | Summary: Count column width instead of the number of code points. This also includes correct handling of tabs inside string literals and comments (with an exception of multiline string literals/comments, where tabs are present before the first escaped newline). Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1601 llvm-svn: 190052
* clang-format: Quickfix for braced init lists detected as lambdas.Daniel Jasper2013-09-051-0/+6
| | | | | | | | | | Before: constexpr char hello [] { "hello" }; After: constexpr char hello[]{ "hello" }; llvm-svn: 190046
* Address post-commit review comments from r190038.Daniel Jasper2013-09-053-5/+22
| | | | | | Mostly additional comments :-). llvm-svn: 190042
* clang-format: Fix parsing and indenting lambdas.Daniel Jasper2013-09-053-26/+36
| | | | | | | | | | | | | | | | Before: void f() { other(x.begin(), x.end(), // [&](int, int) { return 1; }); } After: void f() { other(x.begin(), x.end(), // [&](int, int) { return 1; }); } llvm-svn: 190039
* clang-format: Enable formatting of nested blocks.Daniel Jasper2013-09-058-193/+376
| | | | | | | | | | | | | | | | | | Among other things, this enables (better) formatting lambdas and constructs like: MACRO({ long_statement(); long_statement_2(); }, { long_statement(); long_statement_2(); }, { short_statement(); }, ""); This fixes llvm.org/PR15381. llvm-svn: 190038
* Handle 'Cpp03' and 'Cpp11' strings in LanguageStandard serialization forAlexander Kornienko2013-09-041-0/+2
| | | | | | | consistency of serialized form with the actual enum member names without a prefix. llvm-svn: 189936
* Remove code duplication in unwrapped line parser.Manuel Klimek2013-09-041-10/+1
| | | | llvm-svn: 189933
* Implement parsing of blocks (^{ ... }) in the unwrapped line parser.Manuel Klimek2013-09-042-14/+31
| | | | | | | | | | | | | | | | | | | | | | This patch makes sure we produce the right number of unwrapped lines, a follow-up patch will make the whitespace formatting consistent. Before: void f() { int i = {[operation setCompletionBlock : ^{ [self onOperationDone]; }] } ; } After: void f() { int i = {[operation setCompletionBlock : ^{ [self onOperationDone]; }] }; } llvm-svn: 189932
* Fix layout of lambda captures.Manuel Klimek2013-09-042-10/+18
| | | | | | | | | | | | | | | | | | Before: int c = [ &, &a, a]{ [ =, c, &d]{ return b++; }(); }(); After: int c = [&, &a, a] { [=, c, &d] { return b++; }(); }(); llvm-svn: 189924
* First step towards correctly formatting lambdas.Manuel Klimek2013-09-032-0/+82
| | | | | | | | | | Implements parsing of lambdas in the UnwrappedLineParser. This introduces the correct line breaks; the formatting of lambda captures are still incorrect, and the braces are also still formatted as if they were braced init lists instead of blocks. llvm-svn: 189818
* Added WebKit style to the BasedOnStyle handling and to the relevant help ↵Alexander Kornienko2013-09-021-1/+2
| | | | | | messages. llvm-svn: 189765
* Store first and last newline position in the token text for string literals ↵Alexander Kornienko2013-09-024-33/+36
| | | | | | | | | | | | | | | | | | and comments. Summary: Store first and last newline position in the token text for string literals and comments to avoid doing .find('\n') for each possible solution. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1556 llvm-svn: 189758
* clang-format: Fix segfault in overloaded operator parsing.Daniel Jasper2013-09-021-2/+3
| | | | | | | | | Before, constructs like: using A::operator+; caused a segfault. This fixes llvm.org/PR17050. llvm-svn: 189749
* clang-format: Fix case-indentation in macros.Daniel Jasper2013-09-021-4/+3
| | | | | | | | | | | | | | Before: #define OPERATION_CASE(name) \ case OP_name: \ return operations::Operation##name After: #define OPERATION_CASE(name) \ case OP_name: \ return operations::Operation##name llvm-svn: 189743
* clang-format: Enable formatting of protocol buffer definitions.Daniel Jasper2013-08-301-1/+2
| | | | | | | | | | | | | Almost by accident, clang-format seems to be able to format protocol buffer definitions (https://code.google.com/p/protobuf/). The only change is that a space is required between numeric constants and opening square brackets (for default values). While this might in theory be used for array subscripts (int val = 4[MyArray]), I have not seen this pattern in practice much. If this is wrong, we can make this smarter in the future. llvm-svn: 189663
* clang-format: Improve recovery from enums with errors.Daniel Jasper2013-08-301-0/+11
| | | | | | | | | | | | | | | | | | | | | | Before: namespace n { enum Type { One, Two, // missing }; int i; } void g() { } After: namespace n { enum Type { One, Two, // missing }; int i; } void g() {} llvm-svn: 189662
* clang-format: Fix incorrect indentation.Daniel Jasper2013-08-301-2/+1
| | | | | | | | | | | | | | | | | | | Before: aaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccc( dddddddddddddddddddddddddddddd)); aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb( dddddddddddddddddddddddddddddd)); After: aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccc( dddddddddddddddddddddddddddddd)); aaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb( dddddddddddddddddddddddddddddd)); This was overlooked when interducing the new builder-type call detection in r189337. Also, some minor reorganization of a test. llvm-svn: 189658
* clang-format: Don't indent builders relative to "return".Daniel Jasper2013-08-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | While this looks kind of nice, it wastes horizontal space and does not seem to be common in the LLVM codebase. Before: return llvm::StringSwitch<Reference::Kind>(name) .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR) .StartsWith(".eh_frame", ORDER_EH_FRAME) .StartsWith(".init", ORDER_INIT) .StartsWith(".fini", ORDER_FINI) .StartsWith(".hash", ORDER_HASH) .Default(ORDER_TEXT); After: return llvm::StringSwitch<Reference::Kind>(name) .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR) .StartsWith(".eh_frame", ORDER_EH_FRAME) .StartsWith(".init", ORDER_INIT) .StartsWith(".fini", ORDER_FINI) .StartsWith(".hash", ORDER_HASH) .Default(ORDER_TEXT); llvm-svn: 189657
* clang-format: Fix corner case in builder-type calls.Daniel Jasper2013-08-301-1/+3
| | | | | | | | | | | | | Before: aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa()->aaaaaaaaaaaaaae( 0)->aaaaaaaaaaaaaaa(); After: aaaaaaaaaaaaa->aaaaaaaaaaaaaaaaaaaaaaaa() ->aaaaaaaaaaaaaae(0) ->aaaaaaaaaaaaaaa(); llvm-svn: 189655
* Better support for multiline string literals (including C++11 raw string ↵Alexander Kornienko2013-08-295-22/+68
| | | | | | | | | | | | | | | | | | literals). Summary: Calculate characters in the first and the last line correctly so that we only break before the literal when needed. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1544 llvm-svn: 189595
* Fixes various problems with accounting for tabs in the original code.Manuel Klimek2013-08-292-19/+48
| | | | | | | | | | | | | | | We now count the original token's column directly when lexing the tokens, where we already have all knowledge about where lines start. Before this patch, formatting: void f() { \tg(); \th(); } would incorrectly count the \t's as 1 character if only the line containing h() was reformatted, and thus indent h() at offset 1. llvm-svn: 189585
* clang-format: Improve token breaking behavior.Daniel Jasper2013-08-282-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | Two changes: * Don't add an extra penalty on breaking the same token multiple times. Generally, we should prefer not to break, but once we break, the normal line breaking penalties apply. * Slightly increase the penalty for breaking comments. In general, the author has put some thought into how to break the comment and we should not overwrite this unnecessarily. With a 40-column column limit, formatting aaaaaa("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"); Leads to: Before: aaaaaa( "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa " "aaaaaaaaaaaaaaaa"); After: aaaaaa("aaaaaaaaaaaaaaaa " "aaaaaaaaaaaaaaaa " "aaaaaaaaaaaaaaaa"); llvm-svn: 189466
* clang-format: Fix segfault in 'incomplete' macros.Daniel Jasper2013-08-281-3/+4
| | | | | | | | | The code leading to a segfault was: #pragma omp threadprivate(y)), // long comment leading to a line break This fixes llvm.org/PR16513. llvm-svn: 189460
OpenPOWER on IntegriCloud