summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* 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
* Again macros without trailing semicolons: don't care about declaration context.Alexander Kornienko2013-04-091-3/+30
| | | | | | | | | | | | | | | | Summary: Some codebases use these kinds of macros in functions, e.g. Chromium's IPC_BEGIN_MESSAGE_MAP, IPC_BEGIN_MESSAGE_HANDLER, etc. Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D645 llvm-svn: 179099
* Recognize function-like macro usages without semicolon in declaration context.Alexander Kornienko2013-04-081-9/+16
| | | | | | | | | | | | | | | | | | | | Summary: Preserve line breaks after function-like macro usages without semicolon, e.g.: QQQ(xxx) class X { }; Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D638 llvm-svn: 179064
* Even better way to handle comments adjacent to preprocessor directives.Alexander Kornienko2013-04-031-3/+4
| | | | | | | | | | | | | | | | | | Summary: It turns out that we don't need to store CommentsBeforeNextToken in the line state, but rather flush them before we start parsing preprocessor directives. This fixes wrong comment indentation in code blocks in macro calls (the test is included). Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D617 llvm-svn: 178638
* Alternative handling of comments adjacent to preprocessor directives.Alexander Kornienko2013-04-021-1/+3
| | | | | | | | | | | | | | Summary: Store comments in ScopedLineState Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D609 llvm-svn: 178537
* Fixed handling of comments before preprocessor directives.Alexander Kornienko2013-03-281-0/+1
| | | | | | | | | Comments before preprocessor directives used to be stored with InPPDirective flag set, which prevented correct comment splitting in this case. Fixed by flushing comments before switching on InPPDirective. Added a new test and fixed one of the existing tests. llvm-svn: 178261
* Better fix for r177725.Daniel Jasper2013-03-221-2/+3
| | | | | | | | | | | | It turns out that -foo; can be an objective C method declaration. So instead of the previous solution, recognize objective C methods only if we are in a declaration scope. llvm-svn: 177740
* Fix infinite-loop in unwrapped line parser.Daniel Jasper2013-03-201-1/+1
| | | | | | Discovered when accidentally formatting a python file :-). llvm-svn: 177527
* Add extra indentation for multiline comparisons.Daniel Jasper2013-03-201-18/+12
| | | | | | | | | | | | | | | | This seems to be generally more desired. Before: if (aaaaaaaa && bbbbbbbb > cccccccc) {} After: if (aaaaaaaa && bbbbbbbb > cccccccc) {} Also: Some formatting cleanup on clang-format's files. llvm-svn: 177514
* Don't remove all indentation when in #defines.Daniel Jasper2013-03-201-1/+1
| | | | | | | | | | Otherwise, this can become hard to read. Before: #define A \ case 1: After: #define A \ case 1: llvm-svn: 177509
* Fix indentation for case: // comment.Daniel Jasper2013-03-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Before: switch (x) { case 1: // Do amazing stuff { g(); f(); } } After: switch (x) { case 1: // Do amazing stuff { g(); f(); } } llvm-svn: 177420
OpenPOWER on IntegriCloud