summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* Also align trailing line comments in include directives.Daniel Jasper2013-01-181-1/+4
| | | | | | | | | | | Before: #include <a> // for x #include <a/b/c> // for yz After: #include <a> // for x #include <a/b/c> // for yz llvm-svn: 172799
* Let the formatter align trailing line comments where possible.Daniel Jasper2013-01-181-5/+29
| | | | | | | | | | | | Before: int a; // comment int bbbbb; // comment After: int a; // comment int bbbbb; // comment llvm-svn: 172798
* Formatter: After case blocks, "break" goes on the same line as the "}", PR14907.Nico Weber2013-01-181-0/+26
| | | | | | | | | | | | | | | | | | | | | Before: switch (foo) { case a: { int a = g(); h(a); } break; } Now: switch (foo) { case a: { int a = g(); h(a); } break; } llvm-svn: 172789
* Formatter: Enable @encode test.Nico Weber2013-01-181-1/+3
| | | | | | | This doesn't work right with pointers to pointers, but that's likely just a dupe of PR14884. llvm-svn: 172785
* Formatter: The contents of @selector() should be formatted as a selector.Nico Weber2013-01-181-3/+3
| | | | | | Before: @selector(foo: ) Now: @selector(foo:) llvm-svn: 172781
* Formatter: Get bit tests in ifs right.Nico Weber2013-01-171-0/+8
| | | | | | | | | | | | | | | | | | | | | | | It's generally not possible to know if 'a' '*' 'b' is a multiplication expression or a variable declaration with a purely lexer-based approach. The formatter currently uses a heuristic that classifies this token sequence as a multiplication in rhs contexts (after '=' or 'return') and as a declaration else. Because of this, it gets bit tests in ifs, such as "if (a & b)" wrong. However, declarations in ifs always have to be followed by '=', so this patch changes the formatter to classify '&' as an operator if it's at the start of an if statement. Before: if (a& b) if (int* b = f()) Now: if (a & b) if (int* b = f()) llvm-svn: 172731
* Allow breaking after the trailing const after a function declaration.Daniel Jasper2013-01-171-0/+4
| | | | | | | | | | | | Before: void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const GUARDED_BY( aaaaaaaaaaaaa); After: void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const GUARDED_BY(aaaaaaaaaaaaa); llvm-svn: 172718
* Improve handling of comments in static initializers.Daniel Jasper2013-01-171-0/+38
| | | | | | | | | | | | | | | | | Also adding more tests. We can now keep the formatting of something like: static SomeType type = { aaaaaaaaaaaaaaaaaaaa, /* comment */ aaaaaaaaaaaaaaaaaaaa /* comment */, /* comment */ aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, // comment aaaaaaaaaaaaaaaaaaaa }; Note that the comment in the first line is handled like a trailing line comment as that is likely what the user intended. llvm-svn: 172711
* Revert most of r172140.Nico Weber2013-01-171-7/+7
| | | | | | | | | | r172140 changed the formatter to produce "-(id) foo" instead of "- (id)foo" in google style, with a link to http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml#Method_Declarations_and_Definitions as reference. But now that I look at that link again, it seems I didn't read it very carefully the first time round. llvm-svn: 172703
* Fix a bug where we would move a following line into a comment.Daniel Jasper2013-01-161-0/+5
| | | | | | | | | | | Before: Constructor() : a(a), // comment a(a) {} After: Constructor() : a(a), // comment a(a) {} Needed this as a quick fix. Will add more tests for this in a future commit. llvm-svn: 172624
* Fix parsing error in conditional expressions.Daniel Jasper2013-01-161-0/+3
| | | | | | | | | | | | | We used to incorrectly parse aaaaaa ? aaaaaa(aaaaaa) : aaaaaaaa; Due to an l_paren being followed by a colon, we assumed it to be part of a constructor initializer. Thus, we never found the colon belonging to the conditional expression, marked the line as bing incorrect and did not format it. llvm-svn: 172621
* Improve understanding of unary operators.Daniel Jasper2013-01-161-0/+5
| | | | | | Before: int x = ** a; After: int x = **a; llvm-svn: 172619
* Disable inlining of short ifs in Google style.Daniel Jasper2013-01-161-16/+24
| | | | | | | | | Various reasons seem to speak against it, so I am disabling this for now. Changed tests to still test this option. llvm-svn: 172618
* Add option to avoid "bin-packing" of parameters.Daniel Jasper2013-01-161-22/+38
| | | | | | | | | | | | | | | | "Bin-packing" here means allowing multiple parameters on one line, if a function call/declaration is spread over multiple lines. This is required by the Chromium style guide and probably desired for the Google style guide. Not making changes to LLVM style as I don't have enough data. With this enabled, we format stuff like: aaaaaaaaaaaaaaa(aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa(); llvm-svn: 172617
* Add debugging support for split penalties.Manuel Klimek2013-01-161-1/+9
| | | | llvm-svn: 172616
* Clang Format: A couple of tests for the trailing stuff caseAlexander Kornienko2013-01-161-0/+6
| | | | llvm-svn: 172607
* Clang Format: Handle missing semicolonAlexander Kornienko2013-01-161-1/+19
| | | | llvm-svn: 172606
* Never merge < and ::, as it produces different tokens.Daniel Jasper2013-01-161-0/+4
| | | | | | Before: vector<::Type> t; After: vector< ::Type> t; llvm-svn: 172601
* Remove errors were if statements were incorrectly put on a single line.Daniel Jasper2013-01-161-1/+11
| | | | | | | Before: if (a) // This comment confused clang-format f(); After: if (a) // No more confusion f(); llvm-svn: 172600
* Fix formatting of preprocessor directives (incluces, warnings & errors).Manuel Klimek2013-01-151-1/+9
| | | | | | | | | | | | | | | | | | Treat tokens inside <> for includes and everything from the second token of a warning / error on as an implicit string literal, e.g. do not change its whitespace at all. Now correctly formats: #include < path with space > #error Leave all white!!!!! space* alone! Note that for #error and #warning we still format the space up to the first token of the text, so: # error Text will become #error Text llvm-svn: 172536
* Improve operator kind detection in presence of comments.Daniel Jasper2013-01-151-0/+11
| | | | | | | | | | | We used to incorrectly identify some operators (*, &, +, -, etc.) if there were comments around them. Example: Before: int a = /**/ - 1; After: int a = /**/ -1; llvm-svn: 172533
* Fixes various bugs around the keywords class, struct and union.Manuel Klimek2013-01-151-1/+30
| | | | | | | | | | | | | | | | | | | | This switches to parsing record definitions only if we can clearly identify them. We're specifically allowing common patterns for visibility control through macros and attributes, but we cannot currently fix all instances. This fixes all known bugs we have though. Before: static class A f() { return g(); } int x; After: static class A f() { return g(); } int x; llvm-svn: 172530
* Fixes formatting of nested brace initializers.Manuel Klimek2013-01-141-0/+26
| | | | | | | | | | | | | | | | We now format this correctly: Status::Rep Status::global_reps[3] = { { kGlobalRef, OK_CODE, NULL, NULL, NULL }, { kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL }, { kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL } }; - fixed a bug where BreakBeforeClosingBrace would be set on the wrong state - added penalties for breaking between = and {, and between { and any other non-{ token llvm-svn: 172433
* Make single-line if statements optional.Daniel Jasper2013-01-141-10/+18
| | | | | | | | | Now, "if (a) return;" is only allowed, if this option is set. Also add a Chromium style which is currently identical to Google style except for this option. llvm-svn: 172431
* Fix a bug in the line merging.Daniel Jasper2013-01-141-0/+2
| | | | | | | If the first line of a merge would exactly fit into the column limit, an unsigned overflow made us not break. llvm-svn: 172426
* Fix bug that would lead to joining preprocessor directives.Daniel Jasper2013-01-141-6/+6
| | | | | | | Before: #include "a.h" #include "b.h" After: #include "a.h" #include "b.h" llvm-svn: 172424
* Put simple preprocessor directives on a single line.Daniel Jasper2013-01-141-10/+14
| | | | | | | Before: #define A \ A After: #define A A llvm-svn: 172423
* Put short if statements on a single line.Daniel Jasper2013-01-141-6/+6
| | | | | | | | | | | Before: if (a) return; After: if (a) return; Not yet sure, whether this is always desired, but we can add options and make this a style parameter as we go along. llvm-svn: 172413
* Improve understanding post increment and decrement.Daniel Jasper2013-01-141-0/+2
| | | | | | | | Before: (a->f()) ++; a[42] ++; After: (a->f())++; a[42]++; llvm-svn: 172400
* Custom DiagnosticConsumer parameter of reformat() + silence diagnostics in ↵Alexander Kornienko2013-01-141-5/+3
| | | | | | | | | | | | | | | | | | unit tests. Summary: Added tests for clang-format diagnostics. Added DiagnosticConsumer argument to clang::format::reformat(). Reviewers: klimek, djasper Reviewed By: djasper CC: cfe-commits, thakis, rafael.espindola Differential Revision: http://llvm-reviews.chandlerc.com/D290 llvm-svn: 172399
* Adds some more tests for * and &.Manuel Klimek2013-01-141-0/+6
| | | | | | | While reviewing r172303 I noticed that I wasn't sure whether we still format those correctly and didn't see any tests. llvm-svn: 172396
* Formatter: Add a test for bitfields.Nico Weber2013-01-141-0/+7
| | | | | | | | They work fine, but this fifth use of colons (after labels, in ?:, in initalizer lists in constructors, in objc method expressions, and in bitfields) wasn't covered by tests yet. llvm-svn: 172377
* Stronger respect the input codes line breaks wrt. comments.Daniel Jasper2013-01-131-0/+8
| | | | | | | | | | | | | | | | | | clang-format should not change whether or not there is a line break before a line comment as this strongly influences the percieved binding. User input: void f(int a, // b is awesome int b); void g(int a, // a is awesome int b); Before: void f(int a, // b is awesome int b); void g(int a, // a is awesome int b); After: <unchanged from input> llvm-svn: 172361
* Format unions like structs and classes.Daniel Jasper2013-01-131-0/+1
| | | | | | | | | | | Note that I don't know whether we should put {} on a single line in this case, but it is probably a theoretical issue as in practice such structs, classes or unions won't be empty. Before: union A {} a; After: union A {} a; llvm-svn: 172355
* Always put a space after ",".Daniel Jasper2013-01-131-0/+1
| | | | | | | | | | 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)); llvm-svn: 172351
* Don't put spaces around hyphens in include paths.Daniel Jasper2013-01-131-11/+12
| | | | | | Before: #include <a - a> After: #include <a-a> llvm-svn: 172350
* Improve identification of c-style casts.Daniel Jasper2013-01-131-3/+19
| | | | | | | | | 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 *) {} llvm-svn: 172349
* Formatter: Don't insert a space before unary operators after selector names.Nico Weber2013-01-121-0/+1
| | | | | | | | | | Before: [color getRed: &r green: &g blue: &b alpha: &a]; Now: [color getRed:&r green:&g blue:&b alpha:&a]; llvm-svn: 172337
* Formatter: Add a test for @selector in an ObjC method expression, which ↵Nico Weber2013-01-121-0/+1
| | | | | | happens to work already. llvm-svn: 172335
* Formatter: Remove debugging junk I accidentally landed in r172333.Nico Weber2013-01-121-3/+0
| | | | llvm-svn: 172334
* Formatter: Prefer breaking before ObjC selector names over breaking at their ':'Nico Weber2013-01-121-4/+11
| | | | | | | | | | | | Before: if ((self = [super initWithContentRect:contentRect styleMask: styleMask backing:NSBackingStoreBuffered defer:YES])) { Now: if ((self = [super initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:YES])) { llvm-svn: 172333
* Fix incorrect comparison operator causing loooong formatting times.Daniel Jasper2013-01-121-0/+18
| | | | llvm-svn: 172308
* Formatter: Remove a redundant CurrentLineType check.Nico Weber2013-01-121-1/+0
| | | | | | The containing if checks for this already. No functionality change. llvm-svn: 172306
* Formatter: Initial support for formatting Objective-C method expressions. ↵Nico Weber2013-01-121-0/+61
| | | | | | | | | | | | | | | | | | | | 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]; llvm-svn: 172304
* Formatter: * and & are binary operators before ( and [.Nico Weber2013-01-121-0/+3
| | | | llvm-svn: 172303
* Formatter: * and & are binary operators after ) and ].Nico Weber2013-01-121-0/+2
| | | | llvm-svn: 172302
* Formatter: + and - after { are unary operators.Nico Weber2013-01-121-0/+3
| | | | llvm-svn: 172301
* Formatter: add a test for :? in []Nico Weber2013-01-121-0/+7
| | | | llvm-svn: 172289
* Formatter: Format ObjC static and instance methods consistently, add a test ↵Nico Weber2013-01-111-0/+4
| | | | | | for that. llvm-svn: 172254
* Fix crashes in UnwrappedLineParser on missing parens.Manuel Klimek2013-01-111-1/+5
| | | | llvm-svn: 172239
OpenPOWER on IntegriCloud