summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/ContinuationIndenter.cpp
Commit message (Collapse)AuthorAgeFilesLines
* clang-format: Undo unwanted format change done in r251405.Daniel Jasper2015-10-271-11/+13
| | | | | | | | Specifically, don't wrap between the {} of an empty constructor if the "}" falls on column 81 and ConstructorInitializerAllOnOneLineOrOnePerLine is set. llvm-svn: 251406
* clang-format: Add an additional value to AlignAfterOpenBracket: AlwaysBreak.Daniel Jasper2015-10-271-8/+21
| | | | | | | | | | | | | | | | | | | | Summary: If this option is set, clang-format will always insert a line wrap, e.g. before the first parameter of a function call unless all parameters fit on the same line. This obviates the need to make a decision on the alignment itself. Use this style for Google's JavaScript style and add some minor tweaks to correctly handle nested blocks etc. with it. Don't use this option for for/while loops. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D14104 llvm-svn: 251405
* clang-format: Don't let a leading "template <..>" lead to wrapped initializers.Daniel Jasper2015-08-271-0/+3
| | | | | | | | | | | | | | | | | Before: Constructor() : initializer(0) {} template <typename T> Constructor() : initializer(0) {} After: Constructor() : initializer(0) {} template <typename T> Constructor() : initializer(0) {} llvm-svn: 246146
* clang-format: Be more conservative about specially indenting blocks in C++.Daniel Jasper2015-08-211-0/+1
| | | | | | | | | | | | | | | | | | | | | | This is a bit of a step back of what we did in r222531, as there are some corner cases in C++, where this kind of formatting is really bad. Example: Before: virtual aaaaaaaaaaaaaaaa(std::function<bool()> IsKindWeWant = [&]() { return true; }, aaaaa aaaaaaaaa); After: virtual aaaaaaaaaaaaaaaa(std::function<bool()> IsKindWeWant = [&]() { return true; }, aaaaa aaaaaaaaa); The block formatting logic in JavaScript will probably go some other changes, too, and we'll potentially be able to make the rules more consistent again. For now, this seems to be the best approach for C++. llvm-svn: 245694
* clang-format: Respect IndentWrappedFunctionNames when aligning colonsDaniel Jasper2015-07-161-1/+6
| | | | | | | | | | | | | | | | Before: - (void)shortf:(GTMFoo *)theFoo dontAlignNamef:(NSRect)theRect { } After: - (void)shortf:(GTMFoo *)theFoo dontAlignNamef:(NSRect)theRect { } Patch by Kwasi Mensah, thank you! llvm-svn: 242484
* clang-format: Fix return type breaking with overloaded operator functionsBirunthan Mohanathas2015-07-151-1/+2
| | | | | | Differential Revision: http://reviews.llvm.org/D11177 llvm-svn: 242316
* clang-format: Fix formatting of multiple lambdas in initializers.Daniel Jasper2015-07-141-2/+4
| | | | | | | | | | | | | | | | | | | | Before: SomeFunction({[&] { // comment }, [&] { // comment }}); After: SomeFunction({[&] { // comment }, [&] { // comment }}); llvm-svn: 242138
* clang-format: [JS] Prevent confusing TypeScript parameters wraps.Daniel Jasper2015-07-061-1/+1
| | | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa): aaaaaaaaaaaaaaaaaaaaaa {} After: aaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa): aaaaaaaaaaaaaaaaaaaaaa {} llvm-svn: 241444
* clang-format: Add option to break after definition return type for top-level ↵Birunthan Mohanathas2015-06-291-1/+2
| | | | | | | | functions only Differential Revision: http://reviews.llvm.org/D10774 llvm-svn: 240959
* clang-format: Don't indent relative to unary operators (some more).Daniel Jasper2015-06-291-1/+1
| | | | | | | | | | | | | | | | Before: long aaaaaaaa = !aaaa( // break aaaaaa); long aaaaaaaa = !aa.aa( // break aaaaaa); After: long aaaaaaaa = !aaaa( // break aaaaaa); long aaaaaaaa = !aa.aa( // break aaaaaa); llvm-svn: 240934
* clang-format: Make exception to AlwaysBreakBeforeMultilineStrings moreDaniel Jasper2015-06-191-1/+1
| | | | | | | | | | | | | | | | | | conservative. In particular, this fixes an unwanted corner case. Before: string s = someFunction("aaaa" "bbbb"); After: string s = someFunction( "aaaa" "bbbb"); llvm-svn: 240129
* clang-format: Row back on the AlwaysBreakBeforeMultilineStrings change.Daniel Jasper2015-06-181-1/+2
| | | | | | | | | | | | | | | It was a bit too aggressive. With this patch, we keep on breaking here: aaaaaaaaaaaaa(aaaaaaa, "aaaaaaa" "bbbbbbb"); But don't break in: aaaaaaaaaaaaa(aaaaaaa, aaaaaaaa("aaaaaaa" "bbbbbbb")); llvm-svn: 240024
* clang-format: [JS] Add a special case for indenting function literals.Daniel Jasper2015-06-181-1/+15
| | | | | | | | | | | | | | | | | | | | Before: var func = function() { doSomething(); }; After: var func = function() { doSomething(); }; This is a very narrow special case which fixes most of the discrepency with what our users do. In the long run, we should try to come up with a more generic fix for indenting these. llvm-svn: 240014
* clang-format: Make AlwaysBreakBeforeMultilineStrings more conservative.Daniel Jasper2015-06-181-7/+9
| | | | | | | | | | | | | | | | | In essence this is meant to consistently indent multiline strings by a fixed amount of spaces from the start of the line. Don't do this in cases where it wouldn't help anyway. Before: someFunction(aaaaa, "aaaaa" "bbbbb"); After: someFunction(aaaaa, "aaaaa" "bbbbb"); llvm-svn: 240004
* clang-format: clang-format (NFC)Daniel Jasper2015-06-171-2/+2
| | | | llvm-svn: 239903
* clang-format: [JS] Tweak behavior for multiline array initializer parametersDaniel Jasper2015-06-151-1/+2
| | | | | | | | | | | | | | | | | | | | | Before: var someVariable = SomeFuntion(aaaa, [ aaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccc ], aaaa); After: var someVariable = SomeFuntion(aaaa, [ aaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccc ], aaaa); llvm-svn: 239722
* clang-format: More eagerly wrap trailing return types.Daniel Jasper2015-06-051-1/+1
| | | | | | | | | | | | | | | | | Before: template <typename T> auto aaaaaaaaaaaaaaaaaaaaaa(T t) -> decltype(eaaaaaaaaaaaaaaa<T>(t.a) .aaaaaaaa()); After: template <typename T> auto aaaaaaaaaaaaaaaaaaaaaa(T t) -> decltype(eaaaaaaaaaaaaaaa<T>(t.a).aaaaaaaa()); Also add a test case for a difficult template parsing case I stumbled accross. Needs fixing. llvm-svn: 239149
* clang-format: Properly reset BreakBeforeParameter when wrappingDaniel Jasper2015-06-031-0/+2
| | | | | | | | | | | | | | | | | operators to the new line. Before: LOG_IF(aaa == // bbb) << a << b; After: LOG_IF(aaa == // bbb) << a << b; llvm-svn: 238911
* clang-format: [JS] Fix incorrect line length calculation.Daniel Jasper2015-06-021-1/+2
| | | | llvm-svn: 238841
* clang-format: [JS] Making arrow function wrapping more consistent.Daniel Jasper2015-06-011-8/+4
| | | | | | | | | | | | | | | | | | | | | | Before: someFunction(() => { doSomething(); // break }) .doSomethingElse( // break ); After: someFunction(() => { doSomething(); // break }) .doSomethingElse( // break ); This is still bad, but at least it is consistent with what we do for other function literals. Added corresponding tests. llvm-svn: 238736
* clang-format: [JS] Fix incorrect detection of ternary expressions.Daniel Jasper2015-05-271-4/+3
| | | | | | | | | | | | | A definintion like this could not be formatted at all: constructor({aa}: { aa?: string, aaaaaaaa?: string, aaaaaaaaaaaaaaa?: boolean, aaaaaa?: List<string> }) { } llvm-svn: 238291
* clang-format: Guard the bin-packing in braced lists on BinPackArgumentsDaniel Jasper2015-05-261-1/+1
| | | | | | | | instead of BinPackParameters. Braced lists are used as constructor calls in many places and so the bin-packing should follow what is done for other calls and not what is done for function declarations. llvm-svn: 238184
* clang-format: Improve detection of macros annotating functions.Daniel Jasper2015-05-181-7/+7
| | | | | | | | | | | | | | | | Before: ASSERT("aaaaaaaaaaaaaaa") << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; After: ASSERT("aaaaaaaaaaaaaaa") << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; Also cleanup implementation a bit and only mark closing parenthesis of these annotations. llvm-svn: 237567
* clang-format: Support function annotations in macros.Daniel Jasper2015-05-181-2/+9
| | | | | | | | | | | | Before: DEPRECATED("Use NewClass::NewFunction instead.") string OldFunction(const string &parameter) {} After: DEPRECATED("Use NewClass::NewFunction instead.") string OldFunction(const string &parameter) {} llvm-svn: 237562
* clang-format: Properly align ObjC string literals.Daniel Jasper2015-05-171-8/+9
| | | | | | | | | | | | | | | | | | | | | | Before: NSString s = @"a" "b" "c"; NSString s = @"a" @"b" @"c"; After: NSString s = @"a" "b" "c"; NSString s = @"a" @"b" @"c"; This fixes llvm.org/PR23536. llvm-svn: 237538
* clang-format: Improve nested block / lambda indentation when wrappingDaniel Jasper2015-05-131-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | before binary/ternary operators. Basically, it doesn't seem right to indent a nested block aligned to a binary or ternary operator. Before: int i = aaaaaa ? 1 // : [] { return 2; // }(); llvm::errs() << "number of twos is " << std::count_if(v.begin(), v.end(), [](int x) { return x == 2; // force break }); After: int i = aaaaaa ? 1 // : [] { return 2; // }(); llvm::errs() << "number of twos is " << std::count_if(v.begin(), v.end(), [](int x) { return x == 2; // force break }); llvm-svn: 237263
* clang-format: [ObjC] Make IndentWrappedFunctionNames work with ObjC functionsDaniel Jasper2015-05-131-2/+9
| | | | llvm-svn: 237241
* clang-format: Support aligning ObjC string literals.Daniel Jasper2015-05-111-2/+5
| | | | | | | | | | | | Before: NSString s = @"aaaa" @"bbbb"; After: NSString s = @"aaaa" @"bbbb"; llvm-svn: 237000
* clang-format: Improve wrapping of << operators.Daniel Jasper2015-05-101-8/+9
| | | | | | | | | | | | | | | | | Before: llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; After: llvm::errs() << aaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa) << aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; Also, cleanup and simplify the operator wrapping logic. llvm-svn: 236960
* clang-format: Improve r236597, Properly indent method calls without inputs.Daniel Jasper2015-05-071-2/+6
| | | | | | | | | | | | Before: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; After: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; llvm-svn: 236730
* clang-format: Fix bad wrapping of ObjC method exprs.Daniel Jasper2015-05-061-3/+3
| | | | | | | | | | | | | | | | | Before: [aaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa: aaaaaaaa aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]; After: [aaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa:aaaaaaaa aaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]; Note that this might now violate the column limit and we probably need an alternative way of indenting these then. However, that is still strictly better than the messy formatting that clang-format did before. llvm-svn: 236598
* clang-format: Properly indent method calls without inputs.Daniel Jasper2015-05-061-2/+4
| | | | | | | | | | | | Before: [aaaaaaaaaaa aaaaaaa]; After: [aaaaaaaaaaa aaaaaaa]; llvm-svn: 236597
* clang-format: Force aligning different brackets relative to each other.Daniel Jasper2015-05-041-2/+14
| | | | | | | | | | | | Before: void SomeFunction(vector< // break int> v); After: void SomeFunction(vector< // break int> v); llvm-svn: 236412
* clang-format: Don't wrap after short first segments of builder calls.Daniel Jasper2015-04-241-1/+2
| | | | | | | | | | | | | | | Before: a() .aaaaa() .aaaaa() .aaaaa(); After: a().aaaaa() .aaaaa() .aaaaa(); llvm-svn: 235707
* clang-format: Support nested block formatting with ColumnLimit=0.Daniel Jasper2015-04-231-5/+19
| | | | llvm-svn: 235580
* clang-format: Improve nested block formatting.Daniel Jasper2015-04-071-1/+2
| | | | | | | | | | | | | | | | | | Before: functionA(functionB({ int i; int j; }), aaaa, bbbb, cccc); After: functionA(functionB({ int i; int j; }), aaaa, bbbb, cccc); llvm-svn: 234304
* clang-format: Indent relative to the ./-> and not the function name.Daniel Jasper2015-04-071-1/+1
| | | | | | | | | | | | | | | | | | Before: aaaaaaaaaaa // .aaaa( // bbbb) // This is different .. .aaaa( // cccc); // .. from this. After: aaaaaaaaaaa // .aaaa( // bbbb) // This is identical .. .aaaa( // cccc); // .. to this. llvm-svn: 234300
* clang-format: Force line break in trailing calls after multline exprs.Daniel Jasper2015-03-261-2/+3
| | | | | | | | | | | | | Before: aaaaaaaa(aaaaaaaaaa, bbbbbbbbbb).a(); After: aaaaaaaa(aaaaaaaaaa, bbbbbbbbbb) .a(); llvm-svn: 233304
* clang-format: [OBJC] Don't indent 8 spaces in method declarations.Daniel Jasper2015-03-121-7/+3
| | | | | | | | | | | | Before: - (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: (SoooooooooooooooooooooomeType *)bbbbbbbbbb; After: - (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: (SoooooooooooooooooooooomeType *)bbbbbbbbbb; llvm-svn: 232112
* clang-format: When putting */& next to types, also wrap before them.Daniel Jasper2015-03-121-1/+1
| | | | | | | | | | | | Before: LoooooooooooongType * loooooooooooongVariable; After: LoooooooooooongType *loooooooooooongVariable; llvm-svn: 232044
* clang-format: Slightly change indentation rules in for loops.Daniel Jasper2015-03-061-1/+2
| | | | | | | | | | | | | | | | | | | | | | There was already a TODO to double-check whether the extra indenation makes sense. A slightly different case reveals that it is actively harmful: for (int i = 0; i < aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbb < ccccccccccccccc; ++i) { } Here (and it is probably not a totally infrequent case, it just works out that "i < " is four spaces and so the four space extra indentation makes the operator precedence confusing. So, this will now instead be formatted as: for (int i = 0; i < aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || bbbbbbbbbbbbbbbbbbbb < ccccccccccccccc; ++i) { } llvm-svn: 231461
* clang-format: Make braced list formatting more consistent.Daniel Jasper2015-02-261-1/+0
| | | | | | | | | | | | | | | | | | | | | | Before: Aaaa aaaaaaaaaaa{ { a, // +1 indent weird. b, // trailing comma signals one per line. }, // trailing comma signals one per line. }; After: Aaaa aaaaaaaaaaa{ { a, // better!? b, // trailing comma signals one per line. }, // trailing comma signals one per line. }; Interesting that this apparently was entirely untested :-(. llvm-svn: 230627
* clang-format: Don't force a break after "endl" if everything fits on one line.Daniel Jasper2015-02-171-0/+4
| | | | llvm-svn: 229486
* clang-format: Fix crasher.Daniel Jasper2015-02-171-1/+1
| | | | llvm-svn: 229485
* clang-format: Fix incorrect handling of leading whitespace.Daniel Jasper2015-01-311-6/+12
| | | | | | | Added an assertion that triggered in an existing test case (without observable differences) and fixed the code. llvm-svn: 227677
* clang-format: Fix AlwaysBreakBeforeMultilineStrings with ColumnLimit=0Daniel Jasper2015-01-201-2/+3
| | | | | | | | | | | | | | Before: const char *x = "hello llvm"; After: const char *x = "hello llvm"; This fixes llvm.org/PR22245. Patch by Bill Meltsner, thank you! llvm-svn: 226564
* clang-format: Fix clang-format crash on invalid code.Daniel Jasper2015-01-191-1/+1
| | | | llvm-svn: 226449
* clang-format: Remove assert that isn't helpful.Daniel Jasper2015-01-191-1/+0
| | | | | | | This assert would trigger on: #d , = } llvm-svn: 226446
* clang-format: Improve format of lambdas in ctor initializers.Daniel Jasper2015-01-121-0/+1
| | | | | | | | | | | | | | | | Before: Constructor() : Constructor([] { // comment int i; }) {} After: Constructor() : Constructor([] { // comment int i; }) {} llvm-svn: 225625
* clang-format: [Java] Support formatting qualified annotations.Nico Weber2015-01-091-5/+6
| | | | llvm-svn: 225559
OpenPOWER on IntegriCloud