summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Improve formatting of constructor initializers.Daniel Jasper2013-11-072-6/+13
| | | | | | | | | | | | | Before: Constructor() : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa(aaaa, aaaa)) {} After: Constructor() : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaa(aaaa, aaaa)) {} llvm-svn: 194210
* clang-format: Remove old hack that mainly made incorrect tests pass.Daniel Jasper2013-11-071-5/+3
| | | | | | | | As a side-effect, constructors definitions will correctly be recognized and formatted as function declarations. Tests will be added in a follow-up patch actually using the correct recognition. llvm-svn: 194209
* clang-format: Fix corner case for brace alignment.Daniel Jasper2013-11-071-1/+3
| | | | | | | | | | | | | | | | Before: Constructor::Constructor() : some_value{ // aaaaaaa // } {} After: Constructor::Constructor() : some_value{ // aaaaaaa // } {} llvm-svn: 194204
* clang-format: Separate line-merging logic into its own class.Daniel Jasper2013-11-061-151/+164
| | | | | | No functional changes (intended). llvm-svn: 194179
* clang-format: Allow line merging and partial formatting of nested blocksDaniel Jasper2013-11-052-414/+419
| | | | | | | | | | | | | | | | Before, clang-format would always format entire nested blocks, which can be unwanted e.g. for long DEBUG({...}) statements. Also clang-format would not allow to merge lines in nested blocks (e.g. to put "if (a) return;" on one line in Google style). This is the first step of several refactorings mostly focussing on the additional functionality (by reusing the "format many lines" code to format the children of a nested block). The next steps are: * Pull out the line merging into its own class. * Seperate the formatting of many lines from the formatting of a single line (and the analysis of the solution space). llvm-svn: 194090
* clang-format: Fix indenting corner case with comment and else.Daniel Jasper2013-10-301-1/+2
| | | | | | | | | | | | | | | | | | | | | | Before: if (a) { f(); } // or else .. else { g(); } After: if (a) { f(); } // or else .. else { g(); } llvm-svn: 193684
* clang-format: Fix whitespaces in include directives.Daniel Jasper2013-10-302-2/+11
| | | | | | | | | | | | | | Before (clang-format wouldn't change): #include "a.h" #include<a> After: #include "a.h" #include <a> This fixes llvm.org/PR16151. llvm-svn: 193683
* clang-format: fix for \r\r\n produced in multiline block commentsDaniel Jasper2013-10-301-1/+2
| | | | | | Patch by Christopher Olsen. Thank you! llvm-svn: 193678
* clang-format: Option to control spacing in template argument lists.Daniel Jasper2013-10-292-1/+7
| | | | | | | | | | | Same as SpacesInParentheses, this option allows adding a space inside the '<' and '>' of a template parameter list. Patch by Christopher Olsen. This fixes llvm.org/PR17301. llvm-svn: 193614
* clang-format: Fix overloaded operator for global-scoped conversions.Daniel Jasper2013-10-291-1/+1
| | | | | | | | | | Before: operator::A(); After: operator ::A(); llvm-svn: 193605
* clang-format: Fix ObjC method exprs with variadic parameters.Daniel Jasper2013-10-261-1/+4
| | | | | | | | | | | | | | | | | Before: _versionLabel.text = [ NSString stringWithFormat:NSLocalizedString(@"version: %@", @"Label"), [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"] ]; After: _versionLabel.text = [NSString stringWithFormat:NSLocalizedString(@"version: %@", @"Label"), [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"]]; This fixed llvm.org/PR17695. llvm-svn: 193475
* I am about to change llvm::MemoryBuffer::getFile take take a Twine. ChangeRafael Espindola2013-10-251-1/+2
| | | | | | clang first so that the build still works. llvm-svn: 193428
* clang-format: Adapt line break penalties for LLVM style.Daniel Jasper2013-10-252-1/+6
| | | | | | | | | | | | | | | | | | | | Specifically make clang-format less eager to break after the opening parenthesis of a function call. Before: aaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); Apparently that is preferable. This penalties are adapted conservatively, we might have to increase them a little bit further. llvm-svn: 193410
* clang-format: Properly reset nested AnnotatedLine structure.Daniel Jasper2013-10-241-0/+1
| | | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR17682. Without this patch, the following code leads to invalid reads/writes: DEBUG({ return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; }); #if a #else #endif Because of the #if-#else structure, the code is formatted and annotated twice and becauce of the nested block, the annotated lines form a hierarchical structure. This structure was not properly reset between runs. llvm-svn: 193352
* clang-format: Be more conservative about column layout formatting.Daniel Jasper2013-10-241-1/+9
| | | | | | | | | | | Specifically, if a braced list has at least one nested braced list, format it either all on one line or in one column (i.e. one item per line). This seems in general to be an improvement as the structure of nested braced lists can make a tightly packed outer braced list hard to read. llvm-svn: 193345
* clang-format: Cleanup array initializer and dict initializer formatting.Daniel Jasper2013-10-244-21/+18
| | | | | | | | Significant changes: - Also recognize these literals with missing "@" for robustness. - Reorganize tests. llvm-svn: 193325
* clang-format: Fix ObjC literal indentation in Google style.Daniel Jasper2013-10-222-11/+14
| | | | | | | | | | | | | | | | | | | | | | Style guide demands a two-space indent. Before: NSArray *arguments = @[ kind == kUserTicket ? @"--user-store" : @"--system-store", @"--print-tickets", @"--productid", @"com.google.Chrome" ]; After: NSArray *arguments = @[ kind == kUserTicket ? @"--user-store" : @"--system-store", @"--print-tickets", @"--productid", @"com.google.Chrome" ]; llvm-svn: 193168
* clang-format: Improve formatting of ObjC array literals.Daniel Jasper2013-10-223-43/+56
| | | | | | | | | | | | | | | | | | Before: NSArray *arguments = @[ kind == kUserTicket ? @"--user-store" : @"--system-store", @"--print-tickets", @"--productid", @"com.google.Chrome" ]; After: NSArray *arguments = @[ kind == kUserTicket ? @"--user-store" : @"--system-store", @"--print-tickets", @"--productid", @"com.google.Chrome" ]; This fixes llvm.org/PR15231. llvm-svn: 193167
* Remove incorrect assert.Manuel Klimek2013-10-221-1/+0
| | | | | | | | | | If we run into the second preprocessor branch chain, the first branch chain might have already set the maximum branch count on that level to something > 0. Fixes PR17645. llvm-svn: 193153
* Fixes PR17617: Crash on joining short if statements.Manuel Klimek2013-10-211-0/+6
| | | | | | | | Now that we iterate on the formatting multiple times when we have chains of preprocessor branches, we need to correctly reset the token's previous and next pointer for the first / last token. llvm-svn: 193071
* clang-format: Better understand Lambda poarameters.Daniel Jasper2013-10-201-1/+8
| | | | | | | | | | | | Before: auto PointerBinding = [](const char * S) {}; After: auto PointerBinding = [](const char *S) {}; This fixes llvm.org/PR17618. llvm-svn: 193054
* clang-format: Fix formatting of nested blocks after comment.Daniel Jasper2013-10-201-10/+11
| | | | | | | | | | | | | | | Before: DEBUG({ // Comment that used to confuse clang-format. fdafas(); }); Before: DEBUG({ // Comments are now fine. fdafas(); }); This fixed llvm.org/PR17619. llvm-svn: 193051
* 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
OpenPOWER on IntegriCloud