summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
* clang-format: Fix assertion on unterminated #ifs.Daniel Jasper2013-10-121-1/+1
| | | | llvm-svn: 192535
* clang-format: No space in "<::" in C++11 mode.Daniel Jasper2013-10-122-6/+11
| | | | llvm-svn: 192524
* Don't break string literals inside preprocessor directives.Alexander Kornienko2013-10-112-3/+14
| | | | | | | | | | | | | | | | | | Summary: This way we avoid breaking code which uses unknown preprocessor directives with long string literals. The specific use case in http://llvm.org/PR17035 isn't very common, but it seems to be a good idea to avoid this kind of problem anyway. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1813 llvm-svn: 192507
* Support formatting of preprocessor branches.Manuel Klimek2013-10-1110-58/+211
| | | | | | | | | | | | | | | | | | | | | We now correctly format: void SomeFunction(int param1, #ifdef X NoTemplate param2, #else template < #ifdef A MyType<Some> > #else Type1, Type2> #endif param2, #endif param3) { f(); } llvm-svn: 192503
* clang-format: Don't remove 'unknown' tokens.Daniel Jasper2013-10-112-1/+18
| | | | | | | | | | | In certain macros or incorrect string literals, the token stream can contain 'unknown' tokens, e.g. a single backslash or a set of empty ticks. clang-format simply treated them as whitespace and removed them prior to this patch. This fixes llvm.org/PR17215 llvm-svn: 192490
* Correctly detect colon in bit fields. Fixes PR17333.Alexander Kornienko2013-10-102-4/+6
| | | | | | | | | | | | | | Summary: Colon was incorrectly detected as a start of inheritance list. Fixed. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1884 llvm-svn: 192349
* clang-format: Fix template declaration line breaking with comment.Daniel Jasper2013-10-091-1/+2
| | | | | | | | | Before, clang-format would always insert a linebreak before the comment in code like: template <typename T> // T can be A, B or C. struct S {}; llvm-svn: 192297
* clang-format: Improve indentation when deriving from templated classes.Daniel Jasper2013-10-082-3/+4
| | | | | | | | | | | | | | | | | Before: struct aaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa< // aaaaaaaaaaaaaaaa> {}; struct aaaaaaaaaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa< aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa> {}; After: struct aaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa< // aaaaaaaaaaaaaaaa> {}; struct aaaaaaaaaaaaaaaaaaaa : public aaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa> {}; llvm-svn: 192187
* clang-format: Improve constructor initializer linewrapping.Daniel Jasper2013-10-082-12/+21
| | | | | | | | | Specifically make ConstructorInitializerAllOnOneLineOrOnePerLine work nicely with BreakConstructorInitializersBeforeComma. This fixes llvm.org/PR17395. llvm-svn: 192168
* Fix incorrect detection of class definitions with alignas specification.Manuel Klimek2013-10-071-1/+2
| | | | llvm-svn: 192094
* clang-format: Remove empty lines after visibility modifiers.Daniel Jasper2013-10-061-6/+10
| | | | | | | | | | | | | | | | | Formatting: class C { public: f(); }; Now leads to: class C { public: f(); }; llvm-svn: 192062
* Refactoring: split addTokenToState into two methods.Alexander Kornienko2013-10-012-207/+237
| | | | | | | | | | | | | | Summary: Pure refactoring, should be no semantic changes. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1796 llvm-svn: 191772
* Moving style option formatting to libFormatEdwin Vane2013-09-301-0/+78
| | | | | | | | | The help text for clang-format's -style option and the function that processes its value is moved to libFormat in this patch. The goal is to enable other tools that use libFormat and also have a -style option to behave consistently with clang-format. llvm-svn: 191666
* clang-format: Improve alignment after 'return'.Daniel Jasper2013-09-302-9/+14
| | | | | | | | | | | | | | | | | Previously, comments, could totally confuse it. Before: return // true if code is one of a or b. code == a || code == b; After: return // true if code is one of a or b. code == a || code == b; llvm-svn: 191654
* clang-format: Fix assertion on incomplete string literals.Daniel Jasper2013-09-291-1/+5
| | | | | | | | Before, this could would lead to an assert: llvm::errs() << " << a; llvm-svn: 191639
* Added a comment and another test for the UT_ForIndentation optionAlexander Kornienko2013-09-271-0/+2
| | | | llvm-svn: 191530
* Implemented tab usage only for indentation (http://llvm.org/PR17363)Alexander Kornienko2013-09-276-90/+130
| | | | | | | | | | | | | | | | | | | Summary: Changed UseTab to be a enum with three options: Never, Always, ForIndentation (true/false are still supported when reading .clang-format). IndentLevel should currently be propagated correctly for all tokens, except for block comments. Please take a look at the general idea before I start dealing with block comments. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1770 llvm-svn: 191527
* Correctly indent with tabs when whitespace starts from the column not ↵Alexander Kornienko2013-09-272-3/+12
| | | | | | | | | | | | | | | | | | divisible by TabWidth. Summary: The width of the first inserted tab character depends on the initial column, so we need to handle the first tab in a special manner. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1763 llvm-svn: 191497
* clang-format: Improve formatting of functions with multiple trailing tokens.Daniel Jasper2013-09-271-1/+4
| | | | | | | | | | | | | Before: void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa) override final; After: void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa) override final; llvm-svn: 191494
* 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
OpenPOWER on IntegriCloud