summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
* clang-format: Support case ranges.Daniel Jasper2013-10-201-1/+1
| | | | | | | | | | | | | | | | | | | Before (note the missing space before "..." which can lead to compile errors): switch (x) { case 'A'... 'Z': case 1... 5: break; } After: switch (x) { case 'A' ... 'Z': case 1 ... 5: break; } llvm-svn: 193050
* clang-format: Improve formatting of ObjC dict literals.Daniel Jasper2013-10-201-2/+9
| | | | | | | | | | | | | | | | Before: NSDictionary *d = @{ @"nam" : NSUserNam(), @"dte" : [NSDate date], @"processInfo" : [NSProcessInfo processInfo] }; After: NSDictionary *d = @{ @"nam" : NSUserNam(), @"dte" : [NSDate date], @"processInfo" : [NSProcessInfo processInfo] }; llvm-svn: 193049
* clang-format: Be more aggressive on incorrect code.Daniel Jasper2013-10-181-4/+1
| | | | | | | | | | | | | | | | Before, clang-format would not adjust leading indents if it found a structural error (e.g. unmatched {}). It seems, however, that clang-format has gotten good enough at parsing the code structure that this hurts in almost all cases. Commonly, while writing code, it is very useful to be able to correclty indent incomplete if statements or for loops. In case this leads to errors that we don't anticipate, we need to find out and fix those. This fixed llvm.org/PR17594. llvm-svn: 192988
* clang-format: Don't force linebreak between return and multiline string.Daniel Jasper2013-10-181-2/+2
| | | | | | | | | | | | | | | This looks ugly and leads to llvm.org/PR17590. Before (with AlwaysBreakBeforeMultilineStrings): return "aaaa" "bbbb"; After: return "aaaa" "bbbb"; llvm-svn: 192984
* Make clang-format slightly more willing to break before trailing annotations.Daniel Jasper2013-10-181-1/+1
| | | | | | | | | | | | | | | | | Specifically, prefer breaking before trailing annotations over breaking before the first parameter. Before: void ffffffffffffffffffffffff( int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE; After: void ffffffffffffffffffffffff(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE; llvm-svn: 192983
* clang-format: Improve formatting of templated builder-type calls.Daniel Jasper2013-10-181-3/+6
| | | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaa().aaaaaaaaaaaaaaaaa().has< bbbbbbbbbbbbbbbbbbbbb>(); After: aaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaa() .aaaaaaaaaaaaaaaaaaaaaaaaaa() .has<bbbbbbbbbbbbbbbbbbbbb>(); llvm-svn: 192981
* clang-format: Make continuation indent width configurable.Daniel Jasper2013-10-182-11/+17
| | | | | | Patch by Kim Gräsman. Thank you! llvm-svn: 192964
* Keep track of indentation levels in static initializers for correct ↵Alexander Kornienko2013-10-143-28/+36
| | | | | | | | | | | | | | | | | | | indentation with tabs. Summary: Store IndentationLevel in ParentState and use it instead of the Line::Level when indening. Also fixed incorrect indentation level calculation in formatFirstToken. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1797 llvm-svn: 192563
* Automatically munch semicolons after blocks.Manuel Klimek2013-10-122-3/+8
| | | | | | | | While it is mostly a user error to have the extra semicolon, formatting it graciously will correctly format in the cases where we do not fully understand the code (macros). llvm-svn: 192543
* 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
OpenPOWER on IntegriCloud