summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* 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: Fix false positive in function annotation detection.Daniel Jasper2015-05-271-1/+1
| | | | llvm-svn: 238285
* clang-format: Guard the bin-packing in braced lists on BinPackArgumentsDaniel Jasper2015-05-262-4/+4
| | | | | | | | 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: [JS] Support ES6 spread operator.Daniel Jasper2015-05-261-0/+2
| | | | | | | | | | | | | | Specifically, don't add a space before it. Before: someFunction(... a); var x = [1, 2, ... a]; After: someFunction(...a); var x = [1, 2, ...a]; llvm-svn: 238183
* clang-format: Fix child-formatting in macros.Daniel Jasper2015-05-261-4/+8
| | | | | | | | | | | | | | | This fixes a case where the column limit was incorrectly calculated leading to a macro like this: #define A \ [] { \ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx( \ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx); \ } exceeding the column limit. llvm-svn: 238182
* clang-format: [JS] Better support for fat arrows.Manuel Klimek2015-05-214-18/+70
| | | | | | | | | | | | Assigns a token type (TT_JsFatArrow) to => tokens, and uses that to more easily recognize and format fat arrow functions. Improves function parsing to better recognize formal parameter lists and return type declarations. Recognizes arrow functions and parse function bodies as child blocks. Patch by Martin Probst. llvm-svn: 237895
* clang-format: Add space in function pointers with SpaceBeforeParens=AlwaysAnders Waldenborg2015-05-191-1/+1
| | | | | | | | | "void (*my_function)(void)" should become "void (*my_function) (void)" when SpaceBeforeParens is set to 'Always' Differential Revision: http://reviews.llvm.org/D9835 llvm-svn: 237704
* clang-format: Improve *-detection.Daniel Jasper2015-05-191-0/+3
| | | | | | | | | | | | Before: S << a *(10); After: S << a * (10); This fixes llvm.org/PR16500. llvm-svn: 237690
* clang-format: Improve for-loop formatting.Daniel Jasper2015-05-191-1/+2
| | | | | | | | | | | | | | | | | | Before: for (SmallVectorImpl<TemplateIdAnnotationn *>::iterator I = Container.begin(), E = Container.end(); I != E; ++I) After: for (SmallVectorImpl<TemplateIdAnnotationn *>::iterator I = Container.begin(), E = Container.end(); I != E; ++I) This fixes llvm.org/PR23544. llvm-svn: 237688
* clang-format: Support #include_nextDaniel Jasper2015-05-191-0/+1
| | | | | | | | | | | | Before: #include_next < test.h > After: #include_next <test.h> This fixes llvm.org/PR23500 llvm-svn: 237686
* clang-format: Correctly detect casts to qualified types.Daniel Jasper2015-05-191-1/+2
| | | | | | | | | | | | Before: ns::E f() { return (ns::E) - 1; } After: ns::E f() { return (ns::E)-1; } This fixes llvm.org/PR23503. llvm-svn: 237684
* clang-format: Fix regression caused by r237244.Daniel Jasper2015-05-191-1/+1
| | | | | | | | | | | | | | | Before: [call aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa. aaaaaaaa]; After: [call aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa.aaaaaaaa .aaaaaaaa]; This merely papers over the fact that we aren't parsing ObjC method calls correctly. Also, the indentation is weird. llvm-svn: 237681
* clang-format: Fix another regression caused by r237565.Daniel Jasper2015-05-182-7/+10
| | | | | | | | | | | | | | | | | | | | Before: class C : test { class D : test{void f(){int i{2}; } } ; } ; After: class C : test { class D : test { void f() { int i{2}; } }; }; llvm-svn: 237569
* clang-format: Fix regression introduced by r237565.Daniel Jasper2015-05-181-1/+2
| | | | | | | | | | | | | | Before: class C : public D { SomeClass SC { 2 }; }; After: class C : public D { SomeClass SC{2}; }; llvm-svn: 237568
* clang-format: Improve detection of macros annotating functions.Daniel Jasper2015-05-183-21/+17
| | | | | | | | | | | | | | | | 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: Allow braced initializers in template arguments of classDaniel Jasper2015-05-182-12/+14
| | | | | | | | | | | | | | specializations. Before: template <class T> struct S < std::is_arithmetic<T> { } > {}; After: template <class T> struct S<std::is_arithmetic<T>{}> {}; llvm-svn: 237565
* clang-format: Support function annotations in macros.Daniel Jasper2015-05-183-3/+24
| | | | | | | | | | | | 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 line wrapping around << operators.Daniel Jasper2015-05-171-1/+2
| | | | | | | | | | | | | | | | | | Generally, clang-format tries to keep label-value pairs on a single line for stream operators. However, we should not do that if there is just a single such pair, as that doesn't help much. Before: llvm::errs() << "aaaaaaaaaaaa: " << aaaaaaa(aaaaaaaaa, aaaaaaaaa); After: llvm::errs() << "aaaaaaaaaaaa: " << aaaaaaa(aaaaaaaaa, aaaaaaaaa); Also remove old test case that was testing actual behavior any more. llvm-svn: 237535
* clang-format: Slightly change format decisions around macro annotations.Daniel Jasper2015-05-151-1/+1
| | | | | | | | | | | | Before: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa) = aaaaaaaaaaaaaaaaaaaaaaaaa; After: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa GUARDED_BY(aaaaaaaaaaaa) = aaaaaaaaaaaaaaaaaaaaaaaaa; llvm-svn: 237430
* clang-format: Don't use column layout in lists that have separatingDaniel Jasper2015-05-151-5/+7
| | | | | | | | comments. At some point, we might to want to a layout with a different number of columns instead, but at the moment, this causes more confusion than it's worth. llvm-svn: 237427
* clang-format: Add missing space before ObjC selector.Daniel Jasper2015-05-151-1/+6
| | | | | | | | | | Before: [self aaaaa:(1 + 2)bbbbb:3]; After: [self aaaaa:(1 + 2) bbbbb:3]; llvm-svn: 237424
* 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: Fix incorrect */& classification.Daniel Jasper2015-05-131-0/+4
| | | | | | | | | | Before: void f() { f(new a(), c *d); } After: void f() { f(new a(), c * d); } llvm-svn: 237249
* clang-format: Fix semicolon less macro-detection.Daniel Jasper2015-05-131-5/+9
| | | | | | | | | | | | | | It was fooled by the comment. Before: SOME_UNRELATED_MACRO /*static*/ int i; After: SOME_UNRELATED_MACRO /*static*/ int i; llvm-svn: 237246
* clang-format: [ObjC] Further improve wrapping of methods calls without inputs.Daniel Jasper2015-05-131-1/+2
| | | | | | | | | | | | Before: [aaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaa[aaaaaaaaaaaaaaaaaaaaa] aaaaaaaaaaaaaaaaaaaaaa]; After: [aaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaa[aaaaaaaaaaaaaaaaaaaaa] aaaaaaaaaaaaaaaaaaaaaa]; llvm-svn: 237244
* clang-format: [ObjC] Make IndentWrappedFunctionNames work with ObjC functionsDaniel Jasper2015-05-131-2/+9
| | | | llvm-svn: 237241
* clang-format: Prefer formatting local lambdas like functions.Daniel Jasper2015-05-131-0/+3
| | | | | | | | | | | | | Before: auto my_lambda = [](const string &some_parameter) { return some_parameter.size(); }; After: auto my_lambda = [](const string &some_parameter) { return some_parameter.size(); }; llvm-svn: 237235
* clang-format: Support column layout with comment after {.Daniel Jasper2015-05-131-4/+6
| | | | | | | | | | | | | | | | Before: vector<int> iiiiiiiiiiiiiii = { // 1111111111, 2222222222, 33333333333, 4444444444, // 111111111, 222222222, 3333333333, 444444444, // 11111111, 22222222, 333333333, 44444444}; After: vector<int> iiiiiiiiiiiiiii = { // 1111111111, 2222222222, 33333333333, 4444444444, // 111111111, 222222222, 3333333333, 444444444, // 11111111, 22222222, 333333333, 44444444}; llvm-svn: 237233
* clang-format: Make member introduced in r237108 const.Daniel Jasper2015-05-121-2/+1
| | | | llvm-svn: 237114
* clang-format: Fix */& detection for lambdas in macros.Daniel Jasper2015-05-121-5/+5
| | | | | | | | | | Before: #define MACRO() [](A * a) { return 1; } After: #define MACRO() [](A *a) { return 1; } llvm-svn: 237109
* clang-format: Fix hanging nested blocks in macros.Daniel Jasper2015-05-121-2/+4
| | | | | | | | | | | | | | | | | | | | Before: #define MACRO() \ Debug(aaa, /* force line break */ \ { \ int i; \ int j; \ }) After: #define MACRO() \ Debug(aaa, /* force line break */ \ { \ int i; \ int j; \ }) llvm-svn: 237108
* Refactor clang-format's formatter.Manuel Klimek2015-05-122-164/+220
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: a) Pull out a class LevelIndentTracker whose responsibility is to keep track of the indent of levels across multiple annotated lines. b) Put all responsibility for merging lines into the LineJoiner; make the LineJoiner iterate over the lines so we never operate on a line that might be merged later; this makes the interface safer to use. c) Move formatting of the end-of-file whitespace into formatFirstToken. Fix bugs that became obvious after the refactoring: 1. We would not format lines with offsets correctly inside nested blocks if only the outer expression was affected: int x = s({ // clang-format only this line class X { public: // ^ this starts at the non-modified indnent level; previously we would // not fix this, now we correctly outdent it. void f(); }; }); 2. We would incorrectly align comments across lines that do not have comments for lines with nested blocks: int expression; // with comment int x = s({ int y; // comment int z; // we would incorrectly align this comment with the comment on // 'expression' }); llvm-svn: 237104
* clang-format: Support aligning ObjC string literals.Daniel Jasper2015-05-113-15/+25
| | | | | | | | | | | | Before: NSString s = @"aaaa" @"bbbb"; After: NSString s = @"aaaa" @"bbbb"; llvm-svn: 237000
* clang-format: Appease the buildbots by including climits.Daniel Jasper2015-05-111-0/+1
| | | | llvm-svn: 236995
* clang-format: Improve column layout.Daniel Jasper2015-05-111-14/+18
| | | | | | | | | | | | | | | | | | | | | | Specifically, calculate the deviation between the shortest and longest element (which is used to prevent excessive whitespace) per column, not overall. This automatically handles the corner cases of a single column and a single row so that the actualy implementation becomes simpler. Before: vector<int> x = {1, aaaaaaaaaaaaaaaaaaaaaa, 2, bbbbbbbbbbbbbbbbbbbbbb, 3, cccccccccccccccccccccc}; After: vector<int> x = {1, aaaaaaaaaaaaaaaaaaaaaa, 2, bbbbbbbbbbbbbbbbbbbbbb, 3, cccccccccccccccccccccc}; llvm-svn: 236992
* clang-format: Don't merge subsequent lines into _asm blocks.Daniel Jasper2015-05-111-0/+1
| | | | | | | | | | | | | Before: _asm { } int i; After: _asm { } int i; llvm-svn: 236985
* clang-format: [JS] Clean up export declaration parsing.Daniel Jasper2015-05-111-7/+4
| | | | | | NFC intended. llvm-svn: 236982
* clang-format: [JS] Parse exported functions as free-standing.Daniel Jasper2015-05-111-2/+10
| | | | | | | | | | | | | Before: export function foo() {} export function bar() {} After: export function foo() { } export function bar() { } llvm-svn: 236978
* Refactor the formatter of clang-format.Manuel Klimek2015-05-113-306/+347
| | | | | | | | | | | | Pull various parts of the UnwrappedLineFormatter into their own abstractions. NFC. There are two things left for subsequent changes (to keep this reasonably small) - the UnwrappedLineFormatter now has a bad name - the UnwrappedLineFormatter::format function is still too large llvm-svn: 236974
* clang-format: Improve wrapping of << operators.Daniel Jasper2015-05-102-9/+10
| | | | | | | | | | | | | | | | | 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: Preserve line break before } in __asm { ... }.Daniel Jasper2015-05-103-1/+7
| | | | | | | | Some compilers ignore everything after a semicolon in such inline asm blocks and thus, the closing brace must not be moved to the previous line. llvm-svn: 236946
* clang-format: Fix bug in escaped newline calculation.Daniel Jasper2015-05-101-1/+1
| | | | | | | This prevents clang-format from inadvertently joining stuff into macro definitions as reported in llvm.org/PR23466. llvm-svn: 236944
* clang-format: Several improvements around formatting braced lists.Daniel Jasper2015-05-081-3/+4
| | | | | | | | | | | | | In particular: * If the difference between the longest and shortest element, we copped out of column format completely. Now, we instead allow to arrange these in a single column, essentially enforcing a one-per-line format. * Allow column layout even if there are braced lists. Especially, if there are many short lists, this can be beneficial. The bad case, where there is a long nested init list is usually caught as we now limit the length difference of the longest and shortest element. llvm-svn: 236851
* clang-format: [JS] Avoid bad line-warp around "function".Daniel Jasper2015-05-081-1/+1
| | | | | | | | | | | | | | | | | | | | Before: someLooooooooongFunction( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, function( aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) { // code }); After: someLooooooooongFunction( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, function(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) { // code }); llvm-svn: 236813
* clang-format: [JS] Fix regex literal detection.Daniel Jasper2015-05-081-1/+1
| | | | | | | | | | Before: var regex = /= / ; After: var regex = /=/; llvm-svn: 236811
* clang-format: Improve r236597, Properly indent method calls without inputs.Daniel Jasper2015-05-072-3/+7
| | | | | | | | | | | | Before: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; After: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; llvm-svn: 236730
* Implements a way to retrieve information about whether some lines were not ↵Manuel Klimek2015-05-073-12/+20
| | | | | | formatted due to syntax errors. llvm-svn: 236722
* clang-format: Don't indent 'signals' as access specifier if it isn't oneDaniel Jasper2015-05-061-1/+3
| | | | | | | | | | | | | | Before: { signals.set(0); } After: { signals.set(0); } llvm-svn: 236630
* clang-format: Merge labels and subsequent semicolons.Daniel Jasper2015-05-062-1/+3
| | | | | | | | | | | E.g.: default:; This can be used to get around restrictions as to what can follow a label. It fixes llvm.org/PR19648. llvm-svn: 236604
OpenPOWER on IntegriCloud