summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* Never break inside something that was a preprocessor directive.Manuel Klimek2013-01-311-2/+4
| | | | | | Just put it in one unwrapped line and let the formatter handle it. llvm-svn: 174063
* Several improvements to the formatting of static initializers.Daniel Jasper2013-01-311-5/+30
| | | | | | | | | | | | | 1. Never avoid bin packing in static initializers as this can lead to terrible results. 2. If an element has to be broken over multiple lines, break after the following comma. This should be a step forward, but there are still many cases especially with nested static initializers that we handle badly. More patches will follow. llvm-svn: 174061
* Don't generate no-op replacements.Daniel Jasper2013-01-301-0/+16
| | | | | | No functional changes. llvm-svn: 173916
* Improve formatting of code with comments.Daniel Jasper2013-01-291-0/+8
| | | | | | | | | | | | | | | | | | | | Before: aaaaaaa(aaaaaa( // comment aaaaaaa)); <big mess> After: aaaaaaa(aaaaaa( // comment aaaaaaaa)); function(/* parameter 1 */ aaaaaaa, /* parameter 2 */ aaaaaaa, /* parameter 3 */ aaaaaaa, /* parameter 4 */ aaaaaaa); (the latter example was only wrong in the one-arg-per-line mode, e.g. in Google style). llvm-svn: 173821
* Allow all parameters on next line for function calls in Chrome.Daniel Jasper2013-01-291-3/+8
| | | | | | | | | | | | The style guide only forbids this for function declarations. So, now someFunction( aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaa); Is allowed in Chromium mode. llvm-svn: 173806
* Initial support for multiple variable declarations.Daniel Jasper2013-01-291-0/+18
| | | | | | | | | | | Before: SomeType aaaaaaaaaaaaaaaaa = aaaaaa->aaaaaaaaaaaaaaaaa(), aaaaaaaaaaa = aaaaaa->aaaaaaaaaaa(); After: SomeType aaaaaaaaaaaaaaaaa = aaaaaa->aaaaaaaaaaaaaaaaa(), aaaaaaaaaaa = aaaaaa->aaaaaaaaaaa(); llvm-svn: 173792
* Reverting changes from r173785 (removing empty lines before "}").Daniel Jasper2013-01-291-1/+0
| | | | | | | This needs some more thinking, e.g. for namespaces, chains of if-else if, ... llvm-svn: 173787
* Remove empty lines before "}".Daniel Jasper2013-01-291-0/+1
| | | | | | | | | | | | | | | | | | Those empty lines waste vertical whitespace and almost never increase readability. Before: void f() { DoSomething(); } After: void f() { DoSomething(); } llvm-svn: 173785
* Fix a bug that would lead to bad line break decisions in for loops.Daniel Jasper2013-01-281-0/+12
| | | | | | | | | | | | | | Before: for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa = aaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaa; aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {} After: for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa = aaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaa; aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {} llvm-svn: 173695
* Don't put a function's return type on its own line in Google style.Daniel Jasper2013-01-281-0/+3
| | | | | | | | | | This would be against the style guide: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Function_Declarations_and_Definitions#Function_Declarations_and_Definitions Not sure what to do as a last resort if the function signature does not fit onto a single line in Google style .. llvm-svn: 173690
* Let clang-format break after a function's return type.Daniel Jasper2013-01-281-6/+6
| | | | | | | | | | | | | | | | Before: TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *II, Type *T) {} After: TypeSpecDecl * TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *II, Type *T) {} This fixes llvm.org/PR14717. llvm-svn: 173688
* Make continuations in constructor initializers consistent.Daniel Jasper2013-01-281-0/+4
| | | | | | | | | | | | | | Before: Constructor : LooooooooooooooooooooongVariable( LooooooooooooooooooooongValue) {} After: Constructor : LooooooooooooooooooooongVariable( LooooooooooooooooooooongValue) {} llvm-svn: 173685
* Initial support for formatting range-based for-loops.Daniel Jasper2013-01-281-0/+7
| | | | | | | | | | | | | | | | Before (in good cases): for (auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} for (auto aaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa, aaaa)) {} After: for (auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} for (auto aaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa, aaaa)) {} llvm-svn: 173684
* Improve formatting of conditional expressions.Daniel Jasper2013-01-281-7/+31
| | | | | | | | | | | | | | | | | | | Before we did not really systematically format those. Now, we format the different cases as: - 1 Line: a ? b : c; - 2 Lines: short ? loooooooooong : loooooooooong - 2 Lines: loooooooooooooooong ? short : short - 3 Lines: loooooooooooooooong ? loooooooooooooong : loooooooooooooong Not sure whether "?" and ":" should go on the new line, but it seems to be the most consistent approach. llvm-svn: 173683
* Several small changes in formatting decisions.Daniel Jasper2013-01-281-1/+4
| | | | | | | | | | | | | | | | | 1. Use a hanging ident for function calls nested in binary expressions. E.g.: int aaaaa = aaaaaaaaa && aaaaaaaaaa( aaaaaaaaaa); 2. Slightly improve heuristic for builder type expressions and reduce penalty for breaking before "." and "->" in those. 3. Remove mostly obsolete metric of decreasing indent level. This fixes: llvm.org/PR14931. Changes #1 and #2 were necessary to keep tests passing after #3. llvm-svn: 173680
* Improve indentation after breaking at nested name specifiers.Daniel Jasper2013-01-281-1/+1
| | | | | | | | | | | | | | These always represent a continuation and we should increase the ident. Before: aaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa:: aaaaaaaaaaaaaaaaaaaa); After: aaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa:: aaaaaaaaaaaaaaaaaaaa); llvm-svn: 173675
* Avoid confusing identations for multi-parameter functions.Daniel Jasper2013-01-281-8/+28
| | | | | | | | | | | | | | Before: aaaaaaaa(aaaaaaaaa( aaaaaaaaaa(), aaaaaaaaa); After: aaaaaaaa(aaaaaaaaa( aaaaaaaaaa(), aaaaaaaaa); llvm-svn: 173673
* Fix some alignment and line break decisions.Daniel Jasper2013-01-251-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | This combines two small changes: 1) Put a penalty on breaking after "<" 2) Only produce a hanging indent when parameters are separated by commas. Before: aaaaaaaaaaaaaaaaaaaaaaaa< aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa>(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); aaaaaa(new Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaa)); After: aaaaaaaaaaaaaaaaaaaaaaaa<aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa>( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); aaaaaa(new Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaa)); This changes one ObjC test, but AFAICT this is not according to any style guide (neither before nor after). We probably should be aligning on the ":" there according to: http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml?showone=Method_Invocations#Method_Invocations llvm-svn: 173457
* Allow breaking after "::" if absolutely necessary.Daniel Jasper2013-01-251-0/+27
| | | | | | | | | | Otherwise, really long nested name specifiers can easily lead to a violation of the column limit. Not sure about the rules for indentation in those cases, so input is appreciated (see tests.). llvm-svn: 173438
* Add extra indent for nested calls inside if's.Daniel Jasper2013-01-231-0/+3
| | | | | | | | | | | | Before: if (aaaaaaaaaa( aaaaaaaaaa)) {} After: if (aaaaaaaaaa( aaaaaaaaaa)) {} llvm-svn: 173290
* Don't try to align builder-type continuations on assignments.Daniel Jasper2013-01-231-4/+8
| | | | | | | | | | | | | Before: int aaaa = aaaaa().aaaaa() // force break .aaaaa(); After: int aaaa = aaaaa().aaaaa() // force break .aaaaa(); The other indent is just wrong and confusing. llvm-svn: 173273
* Don't try to do a hanging ident after assignments.Daniel Jasper2013-01-231-3/+2
| | | | | | | | | | | | | | | | | | | | | | | Before: bool aaaa = aaaaaaaaaaa( aaaaaaaaaaaaaaaaa); After: bool aaaa = aaaaaaaaaaa( aaaaaaaaaaaaaaaaa); The other indentation was a nice attempt but doesn't work in many cases. Not sure what the right long term solution is as the "After: " is still not nice. We either need to figure out what to do in the cases where it "doesn't work" or come up with a third solution, e.g. falling back to: bool aaaa = aaaaaaaaaaa( aaaaaaaaaaaaaaaaa); which should always work and nicely highlight the structure. llvm-svn: 173268
* Fix handling of macro definitions.Manuel Klimek2013-01-231-0/+4
| | | | | | | Now correctly formats: #define A (1) llvm-svn: 173264
* Fixes layouting regression and invalid-read.Manuel Klimek2013-01-231-0/+7
| | | | | | | | | | Layouting would prevent breaking before + in a[b + c] = d; Regression detected by code review. Also fixes an invalid-read found by the valgrind bot. llvm-svn: 173262
* Fix the formatting of pointer/reference types in range-based for loops.Daniel Jasper2013-01-231-0/+4
| | | | | | Before: for (int & a : Values) {} After: for (int &a : Values) {} llvm-svn: 173259
* Removing the penalty for breaking after "=".Daniel Jasper2013-01-231-13/+12
| | | | | | | | | | | | | | | | Having seen more cases, this actually was not a good thing to do in the first place. We can still improve on what we do now, but breaking after the "=" is good in many cases. Before: aaaaaaaaaaaaa = aa->aaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaa)); After: aaaaaaaaaaaaa = aa->aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaa)); llvm-svn: 173257
* Fix another regression for pointer types.Daniel Jasper2013-01-231-52/+56
| | | | | | | | | | Before: if (int * a = &b) ... After: if (int *a = &b) ... Also changed all the existing tests to test the expressions in question both in a declaration and in an expression context. llvm-svn: 173256
* Fix regression in formatting pointer types.Daniel Jasper2013-01-231-0/+1
| | | | | | | | | We will need a more principled solution, but we should not leave this unfixed until we come up with one. Before: void f() { int * a; } After: void f() { int *a; } llvm-svn: 173252
* Fixes incorrect handling of the declaration context stack.Manuel Klimek2013-01-231-0/+10
| | | | llvm-svn: 173250
* Fix segfaults in the formatter.Manuel Klimek2013-01-231-1/+6
| | | | | Also: expletive deleted. llvm-svn: 173247
* Add option to allow putting all parameters onto the next line.Daniel Jasper2013-01-231-3/+16
| | | | | | | | | | | | | | | | | This only affects styles where BinPackParameters is false. With AllowAllParametersOnNextLine: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaa, aaaaaaaaaaa); Without it: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaa, aaaaaaaaaaa); llvm-svn: 173246
* Allow us to better guess the context of an unwrapped line.Manuel Klimek2013-01-231-0/+5
| | | | | | | | | | | This gives us the ability to guess better defaults for whether a * between identifiers is a pointer dereference or binary operator. Now correctly formats: void f(a *b); void f() { f(a * b); } llvm-svn: 173243
* Formatter: Remove a fixme klimek fixed in r173168.Nico Weber2013-01-221-3/+2
| | | | | | Add a few comments to the ObjC test cases. llvm-svn: 173169
* Implements more principled comment parsing.Manuel Klimek2013-01-221-0/+41
| | | | | | | | | | | | | | | | | | Changing nextToken() in the UnwrappedLineParser to get the next non-comment token. This allows us to correctly layout a whole class of snippets, like: if /* */(/* */ a /* */) /* */ f() /* */; /* */ else /* */ g(); Fixes a bug in the formatter where we would assume there is a previous non-comment token. Also adds the indent level of an unwrapped line to the debug output in the parser. llvm-svn: 173168
* Let the formatter be more restrictive for breaking around . and ->Daniel Jasper2013-01-221-2/+3
| | | | | | | | | | | | Before: aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaa) .aaaaaaaaaaaaaaaaaa(); After: aaaaaaaaaaaaaaa(aaaaaaaaa, aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaa(); llvm-svn: 173160
* Fix "*" formatting when creating arrays of pointers.Daniel Jasper2013-01-221-0/+3
| | | | | | Before: A = new int * [10](); After: A = new int *[10](); llvm-svn: 173150
* Remove "incorrect" aligning of trailing comments.Daniel Jasper2013-01-211-0/+15
| | | | | | | | | | | | | | | We used to align trailing comments belong to different things. Before: void f() { // some function.. } int a; // some variable.. After: void f() { // some function.. } int a; // some variable.. llvm-svn: 173100
* Fixes various problems around enum parsing.Manuel Klimek2013-01-211-0/+4
| | | | | | | | | | | | | | | | Very similar to what we do for record definitions: - tighten down what is an enum definition, so that we don't mistake a function for an enum - allow common idioms around declarations (we'll want to handle that more centrally in the future) We now correctly format: enum X f() { a(); return 42; } llvm-svn: 173075
* Fixes formatting of empty blocks.Manuel Klimek2013-01-211-67/+84
| | | | | | | | | | | | | | | | We now only put empty blocks into a single line, if all of: - all tokens of the structural element fit into a single line - we're not in a control flow statement Note that we usually don't put record definitions into a single line, as there's usually at least one more token (the semicolon) after the closing brace. This doesn't hold when we are in a context where there is no semicolon, like "enum E {}". There were some missing tests around joining lines around the corner cases of the allowed number of columns, so this patch adds some. llvm-svn: 173055
* Fix parsing of templated declarations.Daniel Jasper2013-01-211-2/+1
| | | | | | | | | | Before: template <template <typename T>, typename P > class X; After: template <template <typename T>, typename P> class X; More importantly, the token annotations for the second ">" are now computed correctly. llvm-svn: 173047
* Fixes indent in linkage specification blocks.Manuel Klimek2013-01-211-0/+4
| | | | | | | | | | | We now indent: extern "C" { int a; } without additional indent inside the extern "C" block. llvm-svn: 173045
* Add regression test.Manuel Klimek2013-01-211-0/+7
| | | | llvm-svn: 173042
* Fixes detection of class template specializations.Manuel Klimek2013-01-211-0/+8
| | | | | | | Now correctly formats: template <> class A<int> {} a; llvm-svn: 173038
* Allow for nested name specifiers in record declarations.Manuel Klimek2013-01-211-1/+5
| | | | | | | Now correctly formats: class A::B {} n; llvm-svn: 173019
* Fix parsing of return statements.Manuel Klimek2013-01-211-0/+4
| | | | | | | | | Previously, we would not detect brace initializer lists in return statements, thus: return (a)(b) { 1, 2, 3 }; would put the semicolon onto the next line. llvm-svn: 173017
* fix the unit tests too.Chris Lattner2013-01-192-1/+2
| | | | llvm-svn: 172907
* Re-sort all the headers. Lots of regressions have crept in here.Chandler Carruth2013-01-191-2/+2
| | | | | | | | | | Manually fix the order of UnwrappedLineParser.cpp as that one didn't have its associated header as the first header. This also uncovered a subtle inclusion order dependency as CLog.h didn't include LLVM.h to pick up using declarations it relied upon. llvm-svn: 172892
* Fixes issues around pulling in the next line in simple if statements.Manuel Klimek2013-01-181-12/+15
| | | | llvm-svn: 172822
* Fixes problems with line merging in the face of preprocessor directives.Manuel Klimek2013-01-181-0/+10
| | | | | | | | | | | | | | | This patch prepares being able to test for and fix more problems (see FIXME in the test for example). Previously we would output unwrapped lines for preprocessor directives at the point where we also parsed the hash token. Since often projections only terminate (and thus output their own unwrapped line) after peeking at the next token, this would lead to the formatter seeing the preprocessor directives out-of-order (slightly earlier). To be able to correctly identify lines to merge, the formatter needs a well-defined order of unwrapped lines, which this patch introduces. llvm-svn: 172819
* Reduce penalty for splitting between ")" and ".".Daniel Jasper2013-01-181-5/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | ').' is likely part of a builder pattern statement. This is based upon a patch developed by Nico Weber. Thank you! Before: int foo() { return llvm::StringSwitch<Reference::Kind>(name).StartsWith( ".eh_frame_hdr", ORDER_EH_FRAMEHDR).StartsWith( ".eh_frame", ORDER_EH_FRAME).StartsWith(".init", ORDER_INIT).StartsWith( ".fini", ORDER_FINI).StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT); } After: int foo() { return llvm::StringSwitch<Reference::Kind>(name) .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR) .StartsWith(".eh_frame", ORDER_EH_FRAME) .StartsWith(".init", ORDER_INIT).StartsWith(".fini", ORDER_FINI) .StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT); } Probably not ideal, but makes many cases much more readable. The changes to overriding-ftemplate-comments.cpp don't seem better or worse. We should address those soon. llvm-svn: 172804
OpenPOWER on IntegriCloud