summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix parsing error in conditional expressions.Daniel Jasper2013-01-161-4/+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-1/+1
| | | | | | Before: int x = ** a; After: int x = **a; llvm-svn: 172619
* Disable inlining of short ifs in Google style.Daniel Jasper2013-01-161-1/+1
| | | | | | | | | 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-8/+60
| | | | | | | | | | | | | | | | "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-162-2/+41
| | | | llvm-svn: 172616
* Use standard llvm Debug.h support for debugging output.Manuel Klimek2013-01-161-17/+16
| | | | | | | | Leave a quick "// Uncomment this." hint to enable the debug output in tests. FIXME: figure out whether we want to enable debug command line handling for all tests. llvm-svn: 172608
* Clang Format: Handle missing semicolonAlexander Kornienko2013-01-161-2/+5
| | | | llvm-svn: 172606
* Calculate the total length of a line up to each token up front.Daniel Jasper2013-01-162-57/+34
| | | | | | | | | | This makes the tedious fitsIntoLimit() method unnecessary and I can replace one hack (constructor initializers) by a slightly better hack. Furthermore, this will enable calculating whether a certain part of a line fits into the limit for future modifications. llvm-svn: 172604
* Change the datastructure for UnwrappedLines.Daniel Jasper2013-01-163-62/+43
| | | | | | | | | | | | | | It was quite convoluted leading to us accidentally introducing O(N^2) complexity while copying from UnwrappedLine to AnnotatedLine. We might still want to improve the datastructure in AnnotatedLine (most importantly not put them in a vector where they need to be copied on vector resizing but that will be done as a follow-up. This fixes most of the regression in llvm.org/PR14959. No formatting changes intended. llvm-svn: 172602
* Never merge < and ::, as it produces different tokens.Daniel Jasper2013-01-161-4/+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-0/+7
| | | | | | | Before: if (a) // This comment confused clang-format f(); After: if (a) // No more confusion f(); llvm-svn: 172600
* Do not traverse the break-state when we know we cannot break anyway.Manuel Klimek2013-01-151-5/+6
| | | | | | | | | This is an optimization that djasper spottet. For now, we do not format anything after the first token that belongs to such an implicit string literal. All our state is not made for handling that anyway, so we'll revisit this if we find a problem. llvm-svn: 172537
* Fix formatting of preprocessor directives (incluces, warnings & errors).Manuel Klimek2013-01-151-6/+30
| | | | | | | | | | | | | | | | | | 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-28/+56
| | | | | | | | | | | 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-152-23/+24
| | | | | | | | | | | | | | | | | | | | 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-7/+18
| | | | | | | | | | | | | | | | 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-0/+10
| | | | | | | | | 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-1/+2
| | | | | | | 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-0/+16
| | | | | | | Before: #define A \ A After: #define A A llvm-svn: 172423
* Put short if statements on a single line.Daniel Jasper2013-01-141-30/+57
| | | | | | | | | | | 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
* Refactor datastructure used in clang-format.Daniel Jasper2013-01-141-123/+138
| | | | | | | | | | | Main difference, add an AnnotatedLine class to hold information about a line while formatting. At the same time degrade the UnwrappedLine class to a class solely used for communicating between the UnwrappedLineParser and the Formatter. No functional changes intended. llvm-svn: 172403
* Improve understanding post increment and decrement.Daniel Jasper2013-01-141-1/+4
| | | | | | | | 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-6/+11
| | | | | | | | | | | | | | | | | | 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
* Stronger respect the input codes line breaks wrt. comments.Daniel Jasper2013-01-131-4/+10
| | | | | | | | | | | | | | | | | | 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-1/+2
| | | | | | | | | | | 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/+2
| | | | | | | | | | 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-10/+6
| | | | | | Before: #include <a - a> After: #include <a-a> llvm-svn: 172350
* Improve identification of c-style casts.Daniel Jasper2013-01-131-1/+5
| | | | | | | | | 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-2/+3
| | | | | | | | | | Before: [color getRed: &r green: &g blue: &b alpha: &a]; Now: [color getRed:&r green:&g blue:&b alpha:&a]; llvm-svn: 172337
* Formatter: Remove debugging junk I accidentally landed in r172333.Nico Weber2013-01-121-1/+1
| | | | llvm-svn: 172334
* Formatter: Prefer breaking before ObjC selector names over breaking at their ':'Nico Weber2013-01-121-1/+20
| | | | | | | | | | | | 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
* Remove useless 'llvm::' qualifier from names like StringRef and others that areDmitri Gribenko2013-01-122-5/+5
| | | | | | brought into 'clang' namespace by clang/Basic/LLVM.h llvm-svn: 172323
* Remove unused private field.Rafael Espindola2013-01-121-7/+3
| | | | llvm-svn: 172314
* Fix incorrect comparison operator causing loooong formatting times.Daniel Jasper2013-01-121-1/+3
| | | | llvm-svn: 172308
* Formatter: Remove an always-false condition.Nico Weber2013-01-121-2/+1
| | | | | | | | canBreakBefore() does not allow breaking after ':' for LT_ObjCMethodDecl lines, so if Newline is true in addTokenToState() for ':' then LT_ObjCMethodDecl cannot be set. No functionality change. llvm-svn: 172307
* Formatter: Remove a redundant CurrentLineType check.Nico Weber2013-01-121-2/+2
| | | | | | 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-6/+48
| | | | | | | | | | | | | | | | | | | | 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/+1
| | | | llvm-svn: 172303
* Formatter: * and & are binary operators after ) and ].Nico Weber2013-01-121-1/+2
| | | | llvm-svn: 172302
* Formatter: + and - after { are unary operators.Nico Weber2013-01-121-1/+1
| | | | llvm-svn: 172301
* Formatter: Format ObjC static and instance methods consistently, add a test ↵Nico Weber2013-01-111-2/+3
| | | | | | for that. llvm-svn: 172254
* Fix crashes in UnwrappedLineParser on missing parens.Manuel Klimek2013-01-111-2/+4
| | | | llvm-svn: 172239
* Fix single-line optimization for ObjC.Manuel Klimek2013-01-111-4/+6
| | | | | | | Puts blocks always into multiple lines when they start with an ObjC keyword or minus. llvm-svn: 172238
* Fix crash on invalid.Manuel Klimek2013-01-111-1/+2
| | | | | | | if { foo; } would previously crash clang-format. llvm-svn: 172232
* Fix parsing of initializer lists with elaborated type specifier.Manuel Klimek2013-01-112-3/+9
| | | | | | | | Now we correctly parse and format: verifyFormat("struct foo a = { bar }; int n; llvm-svn: 172229
* Implements pulling simple blocks into a single line.Manuel Klimek2013-01-111-16/+83
| | | | | | | | void f() { return 42; } The final change that implements the feature. llvm-svn: 172225
* Correct spacing around new and delete.Daniel Jasper2013-01-111-1/+2
| | | | | | | | This fixes llvm.org/PR14913. Before: A *a = new(placement) A; After: A *a = new (placement) A; llvm-svn: 172212
* clang-format: a bit nicer error message.Alexander Kornienko2013-01-111-1/+1
| | | | llvm-svn: 172211
* Improve handling of trailing declaration annotations.Daniel Jasper2013-01-111-13/+11
| | | | | | | | | | | | | | 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. llvm-svn: 172200
OpenPOWER on IntegriCloud