summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/TokenAnnotator.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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: Improve detection of macros annotating functions.Daniel Jasper2015-05-181-13/+9
| | | | | | | | | | | | | | | | 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-1/+14
| | | | | | | | | | | | 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: 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: 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: 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: [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: 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: 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: Support aligning ObjC string literals.Daniel Jasper2015-05-111-13/+19
| | | | | | | | | | | | Before: NSString s = @"aaaa" @"bbbb"; After: NSString s = @"aaaa" @"bbbb"; llvm-svn: 237000
* clang-format: Preserve line break before } in __asm { ... }.Daniel Jasper2015-05-101-1/+4
| | | | | | | | 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: [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: Improve r236597, Properly indent method calls without inputs.Daniel Jasper2015-05-071-1/+1
| | | | | | | | | | | | Before: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; After: [aaaaaaaaaaaa(aaaaaa) aaaaaaaaaaaaaaaaaaaa]; llvm-svn: 236730
* clang-format: Merge labels and subsequent semicolons.Daniel Jasper2015-05-061-1/+1
| | | | | | | | | | | 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
* clang-format: Allow ternary expressions inside template parameters ifDaniel Jasper2015-05-061-2/+7
| | | | | | | | the template parameters aren't inside an expression context. This fixes llvm.org/PR23270. llvm-svn: 236603
* clang-format: Consider operator precedence as penalty when breakingDaniel Jasper2015-05-061-0/+3
| | | | | | | | before operators. This fixes llvm.org/23382. llvm-svn: 236602
* clang-format: Prevent assertion discovered by fuzzer.Daniel Jasper2015-05-061-2/+10
| | | | llvm-svn: 236578
* clang-format: Prevent exponential runtime in token annotator.Daniel Jasper2015-05-061-1/+11
| | | | llvm-svn: 236577
* clang-format: [JS] support optional methods.Daniel Jasper2015-05-051-15/+37
| | | | | | | | | | | | | | | Optional methods use ? tokens like this: interface X { y?(): z; } It seems easiest to detect and disambiguate these from ternary expressions by checking if the code is in a declaration context. Turns out that that didn't quite work properly for interfaces in Java and JS, and for JS file root contexts. Patch by Martin Probst, thank you. llvm-svn: 236488
* clang-format: NFC: Delete FormatToken::IsForEachMacro. Use a TokenType instead.Daniel Jasper2015-05-041-7/+6
| | | | llvm-svn: 236415
* clang-format: Force aligning different brackets relative to each other.Daniel Jasper2015-05-041-2/+6
| | | | | | | | | | | | Before: void SomeFunction(vector< // break int> v); After: void SomeFunction(vector< // break int> v); llvm-svn: 236412
* clang-format: [JS] Fix templated parameter default values.Daniel Jasper2015-05-021-1/+1
| | | | | | | | | | Parameters can have templated types and default values (= ...), which is another location in which a template closer should be followed by whitespace. Patch by Martin Probst, thank you. llvm-svn: 236382
* clang-format: Properly detect variable declarations with ObjC.Daniel Jasper2015-04-231-1/+2
| | | | | | | | | | | | Before: LoooooooooooooooooooooooooooooooooooooooongType LoooooooooooooooooooooooooooooooooooooongVariable([A a]); After: LoooooooooooooooooooooooooooooooooooooooongType LoooooooooooooooooooooooooooooooooooooongVariable([A a]); llvm-svn: 235599
* clang-format: Allow splitting "= default" and "= delete".Daniel Jasper2015-04-231-1/+2
| | | | | | Otherwise, this can violate the column limit. llvm-svn: 235592
* clang-format: Don't add unwanted space when creating new arrays.Daniel Jasper2015-04-231-1/+2
| | | | | | | | | | Before: char** newargv = new char* [argc]; After: char** newargv = new char*[argc]; llvm-svn: 235583
* clang-format: [Proto] Don't linewrap top-level options.Daniel Jasper2015-04-231-2/+10
| | | | | | They are very similar to import statements. llvm-svn: 235582
* clang-format: Fix for #pragma option formatting.Daniel Jasper2015-04-221-2/+5
| | | | | | Adapted patch from Sergey Razmetov. Thank you. llvm-svn: 235492
* clang-format: Fix incorrect multi-var declstmt detection.Daniel Jasper2015-04-201-3/+3
| | | | | | | | | | | | This is now obvious as the pointer alignment behavior was changed. Before (even with pointer alignment "Left"): MACRO Constructor(const int &i) : a(a), b(b) {} After: MACRO Constructor(const int& i) : a(a), b(b) {} llvm-svn: 235301
* clang-format: Undo r214508. It was essentially always removing theDaniel Jasper2015-04-161-1/+1
| | | | | | | space where we already had the flag ObjCSpaceBeforeProtocolList to control it. I don't know what I was thinking. llvm-svn: 235076
* clang-format: Determine "in" as a keyword in ObjC for loops more preciselyDaniel Jasper2015-04-151-23/+21
| | | | | | | | | | | | Before: for (int i = 0; i < in [a]; ++i) .. After: for (int i = 0; i < in[a]; ++i) .. Also do some related cleanups. llvm-svn: 234980
* clang-format: [JS] Support index signature types.Daniel Jasper2015-04-131-1/+2
| | | | | | Patch by Martin Probst. llvm-svn: 234754
* clang-format: [JS] support optionality markers in JS types.Daniel Jasper2015-04-131-10/+22
| | | | | | Patch by Martin Probst. Thank you. llvm-svn: 234753
* clang-format: [JS] Understand object literals with only methods.Daniel Jasper2015-04-041-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Before: let theObject = {someMethodName() { doTheThing(); doTheOtherThing(); }, someOtherMethodName() { doSomething(); doSomethingElse(); }}; After: let theObject = { someMethodName() { doTheThing(); doTheOtherThing(); }, someOtherMethodName() { doSomething(); doSomethingElse(); } }; llvm-svn: 234091
* clang-format: Force line break in trailing calls after multline exprs.Daniel Jasper2015-03-261-3/+3
| | | | | | | | | | | | | Before: aaaaaaaa(aaaaaaaaaa, bbbbbbbbbb).a(); After: aaaaaaaa(aaaaaaaaaa, bbbbbbbbbb) .a(); llvm-svn: 233304
* clang-format: Fix another bug in wrapping around "*".Daniel Jasper2015-03-191-3/+3
| | | | | | | | | | | | Before: void aaaaa( aaaaaaaaaaaa* aaaaaaaaaaaaaa) {} // even violation the column limit After: void aaaaa(aaaaaaaaaaaa* aaaaaaaaaaaaaa) {} llvm-svn: 232717
* clang-format: Fix bad wrapping after "*" introduced in r232044.Daniel Jasper2015-03-181-3/+1
| | | | | | | | | | | | Before: void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa* const aaaaaaaaaaaa) {} After: void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaa* const aaaaaaaaaaaa) {} llvm-svn: 232635
* clang-format: [JS] support cast syntax and type arguments.Daniel Jasper2015-03-151-0/+7
| | | | | | | | | Casts in TS syntax (foo = <type>bar;) should not be followed by whitespace. Patch by Martin Probst. Thank you. llvm-svn: 232321
* clang-format: [JS] more precisely detect enums.Daniel Jasper2015-03-151-1/+7
| | | | | | | | | | | | The current enum detection is overly aggressive. As NestingLevel only applies per line (?) it classifies many if not most object literals as enum declarations and adds superfluous line breaks into them. This change narrows the heuristic by requiring an assignment just before the open brace and requiring the line to start with an identifier. Patch by Martin Probst. Thank you. llvm-svn: 232320
* clang-format: When putting */& next to types, also wrap before them.Daniel Jasper2015-03-121-4/+11
| | | | | | | | | | | | Before: LoooooooooooongType * loooooooooooongVariable; After: LoooooooooooongType *loooooooooooongVariable; llvm-svn: 232044
* clang-format: Fix incorrect && recognition.Daniel Jasper2015-03-111-0/+2
| | | | | | | | | | Before: if (a &&(b = c)) .. After: if (a && (b = c)) .. llvm-svn: 231920
* Make constant static variables const so they can go into a read-only sectionBenjamin Kramer2015-03-081-2/+2
| | | | | | NFC. llvm-svn: 231597
* clang-format: Prefer wrapping a lambda's body over the lambda's return type.Daniel Jasper2015-03-021-0/+2
| | | | | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaa( [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaaaaaaa { return aaaaaaaaaaaaaaaaa; }); After: aaaaaaaaaaaaaaaaaaaaaa( [](aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &aaa) -> aaaaaaaaaaaaaaaaaaaaa { return aaaaaaaaaaaaaaaaa; }); llvm-svn: 230942
* clang-format: Always align */& in multi-var DeclStmts.Daniel Jasper2015-03-011-4/+12
| | | | | | | | Seems like the most consistent thing to do and in multi-var DeclStmts, it is especially important to point out that the */& bind to the identifier. llvm-svn: 230903
* clang-format: Make trailing commas in array inits force one per line.Daniel Jasper2015-02-271-2/+5
| | | | | | | | | | | | | Before: NSArray *array = @[ @"a", @"a", ]; After: NSArray *array = @[ @"a", @"a", ]; llvm-svn: 230741
OpenPOWER on IntegriCloud