aboutsummaryrefslogtreecommitdiff
path: root/unittests/Format
AgeCommit message (Collapse)Author
2013-01-13Always put a space after ",".Daniel Jasper
I am not aware of a case where that would be wrong. The specific case I am fixing are function parameters wrapped in parenthesis (e.g. in macros). Before: function(a,(b)); After: function(a, (b)); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172351 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-13Don't put spaces around hyphens in include paths.Daniel Jasper
Before: #include <a - a> After: #include <a-a> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172350 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-13Improve identification of c-style casts.Daniel Jasper
A ")" before any of "=", "{" or ";" won't be a cast. This fixes issues with the formatting of unnamed parameters. Before: void f(int *){} After: void f(int *) {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172349 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Formatter: Don't insert a space before unary operators after selector names.Nico Weber
Before: [color getRed: &r green: &g blue: &b alpha: &a]; Now: [color getRed:&r green:&g blue:&b alpha:&a]; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172337 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Formatter: Add a test for @selector in an ObjC method expression, which ↵Nico Weber
happens to work already. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172335 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Formatter: Remove debugging junk I accidentally landed in r172333.Nico Weber
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172334 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Formatter: Prefer breaking before ObjC selector names over breaking at their ':'Nico Weber
Before: if ((self = [super initWithContentRect:contentRect styleMask: styleMask backing:NSBackingStoreBuffered defer:YES])) { Now: if ((self = [super initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:YES])) { git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172333 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Fix incorrect comparison operator causing loooong formatting times.Daniel Jasper
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172308 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Formatter: Remove a redundant CurrentLineType check.Nico Weber
The containing if checks for this already. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172306 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Formatter: Initial support for formatting Objective-C method expressions. ↵Nico Weber
This follows the approach suggested by djasper in PR14911: When a '[' is seen that's at the start of a line, follows a binary operator, or follows one of : [ ( return throw, that '[' and its closing ']' are marked as TT_ObjCMethodExpr and every ':' in that range that isn't part of a ternary ?: is marked as TT_ObjCMethodExpr as well. Update the layout routines to not output spaces around ':' tokens that are marked TT_ObjCMethodExpr, and only allow breaking after such tokens, not before. Before: [self adjustButton : closeButton_ ofKind : NSWindowCloseButton]; Now: [self adjustButton:closeButton_ ofKind:NSWindowCloseButton]; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172304 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Formatter: * and & are binary operators before ( and [.Nico Weber
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172303 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Formatter: * and & are binary operators after ) and ].Nico Weber
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172302 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Formatter: + and - after { are unary operators.Nico Weber
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172301 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-12Formatter: add a test for :? in []Nico Weber
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172289 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-11Formatter: Format ObjC static and instance methods consistently, add a test ↵Nico Weber
for that. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172254 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-11Fix crashes in UnwrappedLineParser on missing parens.Manuel Klimek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172239 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-11Fix single-line optimization for ObjC.Manuel Klimek
Puts blocks always into multiple lines when they start with an ObjC keyword or minus. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172238 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-11Fix crash on invalid.Manuel Klimek
if { foo; } would previously crash clang-format. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172232 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-11Fix parsing of initializer lists with elaborated type specifier.Manuel Klimek
Now we correctly parse and format: verifyFormat("struct foo a = { bar }; int n; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172229 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-11Implements pulling simple blocks into a single line.Manuel Klimek
void f() { return 42; } The final change that implements the feature. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172225 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-11Correct spacing around new and delete.Daniel Jasper
This fixes llvm.org/PR14913. Before: A *a = new(placement) A; After: A *a = new (placement) A; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172212 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-11Improve handling of trailing declaration annotations.Daniel Jasper
Before: void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) GUARDED_BY( aaaaaaaaaaaaa); After: void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) GUARDED_BY(aaaaaaaaaaaaa); Also did some formatting cleanups with clang-format on the way. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172200 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-11Improved formatting of constructor initializersDaniel Jasper
Added option to put each constructor initializer on its own line if not all initializers fit on a single line. Enabling this for Google style now as the style guide (arguable) suggests it. Not sure whether we also want it for LLVM. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172196 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Formatter: Remove a fixme, Jordy says @synthesize is good as is.Nico Weber
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172141 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Formatter: Put spaces in ObjC method decls in the right place for Google style.Nico Weber
Objective-C method declarations look like this: - (returntype)name:(type)argname anothername:(type)arg2name; In google style, there's no space after the leading '-' but one after "(returntype)" instead (but none after the argument types), see http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml#Method_Declarations_and_Definitions Not inserting the space after '-' is easy, but to insert the space after the return type, the formatter needs to know that a closing parenthesis ends the return type. To do this, I tweaked the code in parse() to check for this, which in turn required moving detection of TT_ObjCMethodSpecifier from annotate() to parse(), because parse() runs before annotate(). (To keep things interesting, the return type is optional, but it's almost always there in practice.) http://llvm-reviews.chandlerc.com/D280 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172140 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Formatter: No spaces around '=' in @property lines.Nico Weber
Before: @property(assign, getter = isEditable) BOOL editable; Now: @property(assign, getter=isEditable) BOOL editable; It'd be nice if some Apple person could let me know if spaces are preferred around '=' in @synthesize lines (see FIXME in the test). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172110 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Formatter: Add test for template and protocol parameters in ObjC method ↵Nico Weber
declarations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172100 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Formatting: In @implementation etc lines, put a space before protocol lists.Nico Weber
Don't do this in Google style though: http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml#Protocols Most other places (function declarations, variable declarations) still get this wrong, and since this looks very similiar to template instantiations to the lexer (`id <MyProtocol> a = ...`), it's going to be hard to fix in some places. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172099 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Formatter: Don't put a space in ObjC number literals like @+50Nico Weber
Before: @ -4.5 Now: @-4.5 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172095 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Formatter: Add space before '(' in @implemenation, @interface, @protocol linesNico Weber
The first token in @implementation, @interface, and @protocol lines is now marked TT_ObjCDecl, and lines starting with a TT_ObjCDecl token are now marked LT_ObjCMethodDecl. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172093 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Fixes layout of right braces.Manuel Klimek
We now decide whether a newline should go before the closing brace depending on whether a newline was inserted after the opening brace. For example, we now insert a newline before '};' in: static SomeClass WithALoooooooooooooooooooongName = { 100000000, \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" }; ... while not inserting a newline here: static SomeClass = { a, b, c, d, e, f, g, h, i, j, looooooooooooooooooooooooooooooooooongname, looooooooooooooooooooooooooooooong }; Also fixes the formating of (column limit 25): int x = { avariable, b(alongervariable) }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172076 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Fixes formatting of function calls etc inside an initializer list.Manuel Klimek
We're now formatting (column limit 25): int x = { avariable, b(alongervariable) }; This also fixes: Aaa({ int i; }, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccc)); ... where we would previously break after the '},'. Putting the closing curly into an extra line when there's a break directly after the first curly will be done in a subsequent patch. Paired with djasper. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172070 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Do not add newline in empty blocks.Manuel Klimek
void f() {} now gets formatted in one line. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172067 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Improvements to function type and ObjC block formatting.Daniel Jasper
Before: int (^myBlock) (int) = ^(int num) {} A<void ()>; int (*b)(int); After: int (^myBlock)(int) = ^(int num) {} A<void()>; int(*b)(int); For function types and function pointer types, this patch only makes the behavior consistent (for types that are keywords and other types). For the latter function pointer type declarations, we'll probably want to add a space after "int". Also added LangOpts.Bool = 1, so we handle "A<bool()>" appropriately Moved the LangOpts-settings to a public place for use by tests and clang-format binary. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172065 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Fix layout of blocks inside statements.Manuel Klimek
Previously, we would not indent: SOME_MACRO({ int i; }); correctly. This is fixed by adding the trailing }); to the unwrapped line starting with SOME_MACRO({, so the formatter can correctly match the braces and indent accordingly. Also fixes incorrect parsing of initializer lists, like: int a[] = { 1 }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172058 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Improve clang-format's understanding of casts.Daniel Jasper
This fixes llvm.org/PR14684. Before: int *pa = (int *) & a; After: int *pa = (int *)&a; We still don't understand all kinds of casts. I added a FIXME to address that. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172056 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Do more error checking for '{}'.Daniel Jasper
This fixes llvm.org/PR14883, where clang-format would run into an assertion on: void f() { return } 42 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172049 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Formatter: Remove unused @-formatting code.Nico Weber
@optional @property is put on two different unwrapped lines now, so this is no longer necessary. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172024 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-10Formatter: @optional and @required go on their own line.Nico Weber
Previously: @protocol myProtocol - (void)mandatoryWithInt:(int)i; @optional - (void) optional; @required - (void) required; @end Now: @protocol myProtocol - (void)mandatoryWithInt:(int)i; @optional - (void)optional; @required - (void)required; @end git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172023 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-09Formatter: Add support for @implementation.Nico Weber
Just reuse the @interface code for this. It accepts slightly more than necessary (@implementation cannot have protocol lists), but that's ok. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172019 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-09Formatter: Make parseObjCUntilAtEnd() actually work.Nico Weber
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172003 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-09Formatting: Add support for @protocol.Nico Weber
Pull pieces of the @interface code into reusable methods. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172001 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-09Formatter: Add support for @interface.Nico Weber
Previously: @interface Foo + (id)init; @end Now: @interface Foo + (id)init; @end Some tweaking remains, but this is a good first step. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171995 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-09Enables layouting unwrapped lines around preprocessor directives.Manuel Klimek
Previously, we'd always start at indent level 0 after a preprocessor directive, now we layout the following snippet (column limit 69) as follows: functionCallTo(someOtherFunction( withSomeParameters, whichInSequence, areLongerThanALine(andAnotherCall, B withMoreParamters, whichStronglyInfluenceTheLayout), andMoreParameters), trailing); Note that the different jumping indent is a different issue that will be addressed separately. This is the first step towards handling #ifdef->#else->#endif chains correctly. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171974 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-09Only align after assignments on the top level.Daniel Jasper
This fixes llvm.org/PR14870 and we no longer mess up: template <typename T1, typename T2 = char, typename T3 = char, typename T4 = char> void f(); It removes the nice aligment for assignments inside other expressions, but I am not sure those are actually practically relevant. If so, we can fix those later. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171966 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-09Don't simply give up when exceeding 80cols, choose an "ok" option.Daniel Jasper
This addresses llvm.org/PR14847. We can now format something like: int aaaaaaaaaaaaaaaaaaaaaaaaaaa = // aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; clang-format unavoidably exceeds the column limit, but does not just flush everything into a single line. Moreover, it tries to minimize the number of characters beyond the column limit. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171964 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-09Correctly format wrapped function call parameters in templated functions.Daniel Jasper
This fixes llvm.org/PR14846. Before: template <typename T> void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( int aaaaaaaaaaaaaaaaa); After: template <typename T> void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( int aaaaaaaaaaaaaaaaa); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171963 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-09Allow comments in the middle of statements to be on their own line.Daniel Jasper
This fixes llvm.org/PR14860. Before, we messed up the format of: if (DeclaratorInfo.isFunctionDeclarator() && //getDeclSpecContextFromDeclaratorContext(Context) == DSC_top_level && Tok.is(tok::semi) && NextToken().is(tok::l_brace)) { } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171961 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-09Fix ObjC block declarations.Daniel Jasper
Before: int ( ^ Block1) (int, int) = ^ (int i, int j) After: int (^Block1) (int, int) = ^(int i, int j) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171959 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-09Improve formatting of conditional operators.Daniel Jasper
This addresses llvm.org/PR14864. We used to completely mess this up and now format as: Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ? diag::ext_function_specialization_in_class : diag::err_function_specialization_in_class) << NewFD->getDeclName(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171957 91177308-0d34-0410-b5e6-96231b3b80d8