summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* Let clang-format break after a function's return type.Daniel Jasper2013-01-281-7/+33
| | | | | | | | | | | | | | | | 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-1/+2
| | | | | | | | | | | | | | Before: Constructor : LooooooooooooooooooooongVariable( LooooooooooooooooooooongValue) {} After: Constructor : LooooooooooooooooooooongVariable( LooooooooooooooooooooongValue) {} llvm-svn: 173685
* Initial support for formatting range-based for-loops.Daniel Jasper2013-01-281-3/+19
| | | | | | | | | | | | | | | | 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-10/+22
| | | | | | | | | | | | | | | | | | | 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-26/+15
| | | | | | | | | | | | | | | | | 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-3/+4
| | | | | | | | | | | | | | 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-3/+30
| | | | | | | | | | | | | | 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/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | 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-4/+7
| | | | | | | | | | 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-3/+7
| | | | | | | | | | | | 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/+12
| | | | | | | | | | | | | 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-5/+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-1/+2
| | | | | | | Now correctly formats: #define A (1) llvm-svn: 173264
* Fixes layouting regression and invalid-read.Manuel Klimek2013-01-232-2/+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-1/+2
| | | | | | Before: for (int & a : Values) {} After: for (int &a : Values) {} llvm-svn: 173259
* Removing the penalty for breaking after "=".Daniel Jasper2013-01-231-5/+0
| | | | | | | | | | | | | | | | 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-11/+19
| | | | | | | | | | 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-1/+3
| | | | | | | | | 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-2/+2
| | | | llvm-svn: 173250
* Fix segfaults in the formatter.Manuel Klimek2013-01-231-2/+2
| | | | | Also: expletive deleted. llvm-svn: 173247
* Add option to allow putting all parameters onto the next line.Daniel Jasper2013-01-231-18/+17
| | | | | | | | | | | | | | | | | 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-233-19/+53
| | | | | | | | | | | 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
* Implements more principled comment parsing.Manuel Klimek2013-01-223-40/+67
| | | | | | | | | | | | | | | | | | 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-1/+11
| | | | | | | | | | | | 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/+10
| | | | | | Before: A = new int * [10](); After: A = new int *[10](); llvm-svn: 173150
* Remove "incorrect" aligning of trailing comments.Daniel Jasper2013-01-211-4/+11
| | | | | | | | | | | | | | | 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
* Formatter: Set MatchingParen for [], to match <>, (), {}. No functionality ↵Nico Weber2013-01-211-0/+2
| | | | | | change. llvm-svn: 173078
* Formatter: Rename LSquare to Left to make parseSquare() more consistent with ↵Nico Weber2013-01-211-8/+6
| | | | | | the other paren parsing methods. llvm-svn: 173077
* Fixes various problems around enum parsing.Manuel Klimek2013-01-211-31/+42
| | | | | | | | | | | | | | | | 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-212-41/+40
| | | | | | | | | | | | | | | | 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-1/+0
| | | | | | | | | | 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/+12
| | | | | | | | | | | We now indent: extern "C" { int a; } without additional indent inside the extern "C" block. llvm-svn: 173045
* Fix bug discovered by valgrind.Daniel Jasper2013-01-211-2/+3
| | | | | | | When trying to merge lines, we should not touch lines that are invalid, as we don't know how long they might be. llvm-svn: 173043
* Fixes detection of class template specializations.Manuel Klimek2013-01-211-1/+14
| | | | | | | Now correctly formats: template <> class A<int> {} a; llvm-svn: 173038
* Allow for nested name specifiers in record declarations.Manuel Klimek2013-01-211-1/+3
| | | | | | | Now correctly formats: class A::B {} n; llvm-svn: 173019
* Fix parsing of return statements.Manuel Klimek2013-01-212-0/+30
| | | | | | | | | 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
* Re-sort all the headers. Lots of regressions have crept in here.Chandler Carruth2013-01-192-2/+1
| | | | | | | | | | 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
* Fix comment.Manuel Klimek2013-01-181-2/+1
| | | | llvm-svn: 172831
* Fixes issues around pulling in the next line in simple if statements.Manuel Klimek2013-01-181-0/+4
| | | | llvm-svn: 172822
* Fixes problems with line merging in the face of preprocessor directives.Manuel Klimek2013-01-182-7/+48
| | | | | | | | | | | | | | | 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/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | ').' 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
* Also align trailing line comments in include directives.Daniel Jasper2013-01-181-8/+12
| | | | | | | | | | | 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-49/+129
| | | | | | | | | | | | 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-182-2/+4
| | | | | | | | | | | | | | | | | | | | | 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: The contents of @selector() should be formatted as a selector.Nico Weber2013-01-181-10/+43
| | | | | | Before: @selector(foo: ) Now: @selector(foo:) llvm-svn: 172781
* Formatter: Get bit tests in ifs right.Nico Weber2013-01-171-1/+24
| | | | | | | | | | | | | | | | | | | | | | | 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/+7
| | | | | | | | | | | | 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-4/+13
| | | | | | | | | | | | | | | | | 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-12/+1
| | | | | | | | | | 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-1/+1
| | | | | | | | | | | 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
OpenPOWER on IntegriCloud