summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Recognize braced lists with trailing function call.Daniel Jasper2013-11-221-1/+1
| | | | | | | | | | | Before: int count = set<int> { f(), g(), h() } .size(); After: int count = set<int>{f(), g(), h()}.size(); llvm-svn: 195417
* Added an option to allow short function bodies be placed on a single line.Alexander Kornienko2013-11-201-0/+1
| | | | | | | | | | | | | | | | | | | Summary: The AllowShortFunctionsOnASingleLine option now controls short function body placement on a single line independent of the BreakBeforeBraces option. Updated tests using BreakBeforeBraces other than BS_Attach. Addresses http://llvm.org/PR17888 Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2230 llvm-svn: 195256
* Remove incorrect assert.Manuel Klimek2013-10-221-1/+0
| | | | | | | | | | If we run into the second preprocessor branch chain, the first branch chain might have already set the maximum branch count on that level to something > 0. Fixes PR17645. llvm-svn: 193153
* Automatically munch semicolons after blocks.Manuel Klimek2013-10-121-2/+6
| | | | | | | | While it is mostly a user error to have the extra semicolon, formatting it graciously will correctly format in the cases where we do not fully understand the code (macros). llvm-svn: 192543
* clang-format: Fix assertion on unterminated #ifs.Daniel Jasper2013-10-121-1/+1
| | | | llvm-svn: 192535
* Support formatting of preprocessor branches.Manuel Klimek2013-10-111-26/+80
| | | | | | | | | | | | | | | | | | | | | We now correctly format: void SomeFunction(int param1, #ifdef X NoTemplate param2, #else template < #ifdef A MyType<Some> > #else Type1, Type2> #endif param2, #endif param3) { f(); } llvm-svn: 192503
* Fix incorrect detection of class definitions with alignas specification.Manuel Klimek2013-10-071-1/+2
| | | | llvm-svn: 192094
* clang-format: Detect braced lists in subscript expressions.Daniel Jasper2013-09-131-1/+1
| | | | | | | | | | Before (even with Style.Cpp11BracedListStyle): f(MyMap[{ composite, key }]); After: f(MyMap[{composite, key}]); llvm-svn: 190678
* clang-format: Fix incorrect enum parsing / layouting.Daniel Jasper2013-09-131-38/+15
| | | | | | | | | | | | | | | Before: enum { Bar = Foo < int, int > ::value }; After: enum { Bar = Foo<int, int>::value }; llvm-svn: 190674
* clang-format: Format typed enums with nested names.Daniel Jasper2013-09-061-1/+2
| | | | | | | | | The explicit type specified for an enum can actually have a nested name specifier. This fixes llvm.org/PR17125. llvm-svn: 190208
* clang-format: Don't confuse operator[] with lambdas.Daniel Jasper2013-09-061-1/+2
| | | | | | | | | | | | | Before: double &operator[](int i) { return 0; } int i; After: double &operator[](int i) { return 0; } int i; This fixes llvm.org/PR17134. llvm-svn: 190207
* Add ATTRIBUTE_UNUSED to silence unused-function warning in releaseDaniel Jasper2013-09-051-1/+2
| | | | | | builds. llvm-svn: 190061
* Fixes PR 17106 (explicitly typed enums are formatted differently).Manuel Klimek2013-09-051-3/+1
| | | | | | | | | | | | | | Before: enum X : int { A, B, C }; After: enum X : int { A, B, C }; llvm-svn: 190054
* clang-format: Quickfix for braced init lists detected as lambdas.Daniel Jasper2013-09-051-0/+6
| | | | | | | | | | Before: constexpr char hello [] { "hello" }; After: constexpr char hello[]{ "hello" }; llvm-svn: 190046
* clang-format: Fix parsing and indenting lambdas.Daniel Jasper2013-09-051-24/+32
| | | | | | | | | | | | | | | | Before: void f() { other(x.begin(), x.end(), // [&](int, int) { return 1; }); } After: void f() { other(x.begin(), x.end(), // [&](int, int) { return 1; }); } llvm-svn: 190039
* clang-format: Enable formatting of nested blocks.Daniel Jasper2013-09-051-18/+40
| | | | | | | | | | | | | | | | | | Among other things, this enables (better) formatting lambdas and constructs like: MACRO({ long_statement(); long_statement_2(); }, { long_statement(); long_statement_2(); }, { short_statement(); }, ""); This fixes llvm.org/PR15381. llvm-svn: 190038
* Remove code duplication in unwrapped line parser.Manuel Klimek2013-09-041-10/+1
| | | | llvm-svn: 189933
* Implement parsing of blocks (^{ ... }) in the unwrapped line parser.Manuel Klimek2013-09-041-14/+30
| | | | | | | | | | | | | | | | | | | | | | This patch makes sure we produce the right number of unwrapped lines, a follow-up patch will make the whitespace formatting consistent. Before: void f() { int i = {[operation setCompletionBlock : ^{ [self onOperationDone]; }] } ; } After: void f() { int i = {[operation setCompletionBlock : ^{ [self onOperationDone]; }] }; } llvm-svn: 189932
* Fix layout of lambda captures.Manuel Klimek2013-09-041-8/+11
| | | | | | | | | | | | | | | | | | Before: int c = [ &, &a, a]{ [ =, c, &d]{ return b++; }(); }(); After: int c = [&, &a, a] { [=, c, &d] { return b++; }(); }(); llvm-svn: 189924
* First step towards correctly formatting lambdas.Manuel Klimek2013-09-031-0/+80
| | | | | | | | | | Implements parsing of lambdas in the UnwrappedLineParser. This introduces the correct line breaks; the formatting of lambda captures are still incorrect, and the braces are also still formatted as if they were braced init lists instead of blocks. llvm-svn: 189818
* clang-format: Fix case-indentation in macros.Daniel Jasper2013-09-021-4/+3
| | | | | | | | | | | | | | Before: #define OPERATION_CASE(name) \ case OP_name: \ return operations::Operation##name After: #define OPERATION_CASE(name) \ case OP_name: \ return operations::Operation##name llvm-svn: 189743
* clang-format: Improve recovery from enums with errors.Daniel Jasper2013-08-301-0/+11
| | | | | | | | | | | | | | | | | | | | | | Before: namespace n { enum Type { One, Two, // missing }; int i; } void g() { } After: namespace n { enum Type { One, Two, // missing }; int i; } void g() {} llvm-svn: 189662
* clang-format: Fix corner case in ObjC interface definitions.Daniel Jasper2013-08-281-1/+7
| | | | | | | | | | | | | | | In @implementation ObjcClass - (void)method; { } @end the ObjC compiler seems to accept the superfluous comma after "method", but clang-format used to assert on the subsequent "{". This fixes llvm.org/PR16604. llvm-svn: 189453
* clang-format: Improve braced init list detection:Daniel Jasper2013-08-281-1/+5
| | | | | | | | | | | | | | | | Before: std::this_thread::sleep_for(std::chrono::nanoseconds{ std::chrono::seconds { 1 } } / 5); After: std::this_thread::sleep_for( std::chrono::nanoseconds{ std::chrono::seconds{ 1 } } / 5); This fixes llvm.org/PR16554. llvm-svn: 189451
* clang-format: Format enum struct/class like enum.Daniel Jasper2013-08-201-0/+4
| | | | | | Patch by Joe Hermaszewski. Thank you! llvm-svn: 188794
* Fixes a couple of bugs with the Allman brace breaking.Manuel Klimek2013-08-071-0/+2
| | | | | | | | | | | In particular, left braces after an enum declaration now occur on their own line. Further, when short ifs/whiles are allowed these no longer cause the left brace to be on the same line as the if/while when a brace is included. Patch by Thomas Gibson-Robinson. llvm-svn: 187901
* Implement Allman style.Manuel Klimek2013-08-021-6/+28
| | | | | | Patch by Frank Miller. llvm-svn: 187678
* clang-format: Add more options to namespace indentation.Daniel Jasper2013-07-311-6/+9
| | | | | | | | | | | | | With this patch, clang-format can be configured to: * not indent in namespace at all (former behavior). * indent in namespace as in other blocks. * indent only in inner namespaces (as required by WebKit style). Also fix alignment of access specifiers in WebKit style. Patch started by Marek Kurdej. Thank you! llvm-svn: 187540
* clang-format: Fix switch/case interaction with macros.Daniel Jasper2013-07-251-5/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: #define OPERATION_CASE(name) \ case OP_name: \ return operations::Operation##name switch (OpCode) { CASE(Add); CASE(Subtract); default: return operations::Unknown; } After: #define OPERATION_CASE(name) \ case OP_name: \ return operations::Operation##name; switch (OpCode) { CASE(Add); CASE(Subtract); default: return operations::Unknown; } llvm-svn: 187118
* Fix alignment of closing brace in braced initializers.Daniel Jasper2013-07-091-16/+17
| | | | | | | | | | | | | | | | | | | | | | Before: someFunction(OtherParam, BracedList{ // comment 1 (Forcing intersting break) param1, param2, // comment 2 param3, param4 }); After: someFunction(OtherParam, BracedList{ // comment 1 (Forcing intersting break) param1, param2, // comment 2 param3, param4 }); To do so, the UnwrappedLineParser now stores the information about the kind of brace in the FormatToken. llvm-svn: 185914
* Fix incorrect token counting introduced by r185319.Daniel Jasper2013-07-011-1/+3
| | | | | | | | | | | | This lead to weird formatting. Before: DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } }); After: DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } }); llvm-svn: 185346
* Fix braced-list detection in lieu of trailing comments.Daniel Jasper2013-07-011-1/+6
| | | | | | | | | | Before: DoSomethingWithVector({ } /* No data */); After: DoSomethingWithVector({} /* No data */); llvm-svn: 185319
* Put helper classes in an anonymous namespace.Craig Topper2013-07-011-0/+8
| | | | llvm-svn: 185303
* Run clang-format on lib/Format code after r184894. No other changes.Nico Weber2013-06-261-17/+16
| | | | llvm-svn: 184896
* Improve clang-format's error recovery.Daniel Jasper2013-05-311-13/+16
| | | | | | | | | | | | | If a "}" is found inside parenthesis, this is probably a case of missing parenthesis. This enables continuing to format after stuff code like: class A { void f( }; .. llvm-svn: 183009
* Fix detection/formatting of braced lists in ternary expressions.Daniel Jasper2013-05-311-2/+2
| | | | | | | | | | | | | | | | Before: foo = aaaaaaaaaaa ? vector<int> { aaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, aaaaa } : vector<int>{ bbbbbbbbbbbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbb, bbbbb }; After: foo = aaaaaaaaaaa ? vector<int>{ aaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, aaaaa } : vector<int>{ bbbbbbbbbbbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbb, bbbbb }; llvm-svn: 182992
* Add return missing in r182855.Daniel Jasper2013-05-291-0/+1
| | | | llvm-svn: 182856
* Leave some macros on their own lineDaniel Jasper2013-05-291-1/+7
| | | | | | | | | | | | | | | | | | | If an identifier is on its own line and it is all upper case, it is highly likely that this is a macro that is meant to stand on a line by itself. Before: class A : public QObject { Q_OBJECT A() {} }; Ater: class A : public QObject { Q_OBJECT A() {} }; llvm-svn: 182855
* Remove obsolete variable as discovered in post-commit review.Daniel Jasper2013-05-281-4/+0
| | | | llvm-svn: 182796
* Support uniform inits in braced lists.Daniel Jasper2013-05-281-5/+0
| | | | | | | | | | | | | This made it necessary to remove an error detection which would let us bail out of braced lists in certain situations of missing "}". However, as we always entirely escape from the braced list on finding ";", this should not be a big problem. With this, we can no format braced lists with uniformat inits: return { arg1, SomeType { parameter } }; llvm-svn: 182788
* Make UnwrappedLines and AnnotatedToken contain pointers to FormatToken.Manuel Klimek2013-05-281-5/+5
| | | | | | The FormatToken is now not copyable any more. llvm-svn: 182772
* A first step towards giving format tokens pointer identity.Manuel Klimek2013-05-281-129/+138
| | | | | | | | | | | With this patch, we create all tokens in one go before parsing and pass an ArrayRef<FormatToken*> to the UnwrappedLineParser. The UnwrappedLineParser is switched to use pointer-to-token internally. The UnwrappedLineParser still copies the tokens into the UnwrappedLines. This will be fixed in an upcoming patch. llvm-svn: 182768
* Ignore contents of #if 0 blocks.Alexander Kornienko2013-05-241-0/+64
| | | | | | | | | | | | | | | | Summary: Added stack of preprocessor branching directives, and ignore all tokens inside #if 0 except for preprocessor directives. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D855 llvm-svn: 182658
* Increase test coverage for braced init lists.Daniel Jasper2013-05-231-1/+1
| | | | | | Also fix a minor bug for constructor initializers with braced init lists. llvm-svn: 182601
* Use a SourceRange for the whitespace location in FormatToken.Manuel Klimek2013-05-231-1/+2
| | | | | | | | | | | Replaces the use of WhitespaceStart + WhitspaceLength. This made a bug in the formatter obvous where we would incorrectly calculate the next column. FIXME: There's a similar bug left regarding TokenLength. We should probably also move to have a TokenRange instead. llvm-svn: 182572
* Expand parsing of braced init lists.Manuel Klimek2013-05-231-18/+139
| | | | | | | | | | | | | | | | Allows formatting of C++11 braced init list constructs, like: vector<int> v { 1, 2, 3 }; f({ 1, 2 }); This involves some changes of how tokens are handled in the UnwrappedLineFormatter. Note that we have a plan to evolve the design of the token flow into one where we create all tokens up-front and then annotate them in the various layers (as we currently already have to create all tokens at once anyway, the current abstraction does not help). Thus, this introduces FIXMEs towards that goal. llvm-svn: 182568
* Remove diagnostics from clang-format.Daniel Jasper2013-05-151-8/+4
| | | | | | | We only ever implemented one and that one is not actually all that helpful (e.g. gets incorrectly triggered by macros). llvm-svn: 181871
* Implements brace breaking styles.Manuel Klimek2013-05-131-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We now support "Linux" and "Stroustrup" brace breaking styles, which gets us one step closer to support formatting WebKit, KDE & Linux code. Linux brace breaking style: namespace a { class A { void f() { if (x) { f(); } else { g(); } } } } Stroustrup brace breaking style: namespace a { class A { void f() { if (x) { f(); } else { g(); } } } } llvm-svn: 181700
* Revamps structural error detection / handling.Manuel Klimek2013-04-121-28/+27
| | | | | | | | | | | | | | | | | | | | | Previously we'd only detect structural errors on the very first level. This leads to incorrectly balanced braces not being discovered, and thus incorrect indentation. This change fixes the problem by: - changing the parser to use an error state that can be detected anywhere inside the productions, for example if we get an eof on SOME_MACRO({ some block <eof> - previously we'd never break lines when we discovered a structural error; now we break even in the case of a structural error if there are two unwrapped lines within the same line; thus, void f() { while (true) { g(); y(); } } will still be re-formatted, even if there's missing braces somewhere in the file - still exclude macro definitions from generating structural error; macro definitions are inbalanced snippets llvm-svn: 179379
* Fixes recovering from errors when parsing braced init lists.Manuel Klimek2013-04-101-0/+25
| | | | | | | Before we would build huge unwrapped lines which take a long time to optimze. llvm-svn: 179168
OpenPOWER on IntegriCloud