summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* 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
* Remove whitespace at end of file.Daniel Jasper2013-03-011-3/+8
| | | | | | This fixes the rest of llvm.org/PR15062. llvm-svn: 176361
* Fix crash for incomplete labels in macros.Daniel Jasper2013-02-121-2/+2
| | | | | | | Still the formatting can be improved, but at least we don't assert any more. This happened when trying to format lib/Sema/SemaType.cpp. llvm-svn: 175003
* Get rid of manual debug output, now that the test runner supports it.Manuel Klimek2013-02-111-3/+0
| | | | | | You can run tests with -debug instead now. llvm-svn: 174880
* Fixes handling of empty lines in macros.Manuel Klimek2013-02-111-1/+2
| | | | | | | | | | | | | | Now correctly formats: #define A \ \ b; to #define A b; Added the state whether an unwrapped line is a macro to the debug output. llvm-svn: 174878
* Formatter: Initial support for ObjC dictionary literals.Nico Weber2013-02-101-1/+16
| | | | | | | | | | | | | | | | | | Before: @{ foo: bar } ; Now: @{ foo : bar }; parseBracedList() already does the right thing from an UnwrappedLineParser perspective, so check for "@{" in all loops that process constructs that can contain expressions and call parseBracedList() if found. llvm-svn: 174840
* Reformat formatter code. No functionality change.Nico Weber2013-02-101-10/+9
| | | | llvm-svn: 174823
* Fix handling of comments in macros.Manuel Klimek2013-02-061-3/+3
| | | | | | | | | | | | | | | | We now correctly format: // Written as a macro, it is reformatted from: #define foo(a) \ do { \ /* Initialize num to zero. */ \ int num = 10; \ /* This line ensures a is never zero. */ \ int i = a == 0 ? 1 : a; \ i = num / i; /* This division is OK. */ \ return i; \ } while (false) llvm-svn: 174517
* Much semicolon after namespaces.Manuel Klimek2013-02-061-0/+4
| | | | | | | | | We now leave the semicolon in the line of the closing brace in: namespace { ... }; llvm-svn: 174514
* Parse record declarations with token pasted identifiers.Manuel Klimek2013-02-061-2/+4
| | | | | | | This is pretty common in macros: #define A(X, Y) class X##Y {}; llvm-svn: 174512
* Never break inside something that was a preprocessor directive.Manuel Klimek2013-01-311-1/+1
| | | | | | Just put it in one unwrapped line and let the formatter handle it. llvm-svn: 174063
* Move the token annotator into separate files.Daniel Jasper2013-01-291-3/+0
| | | | | | | No functional changes. Also removed experimental-warning from all of clang-format's files, as it is no longer accurate. llvm-svn: 173830
* 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-231-1/+4
| | | | | | | | | | 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
* Fixes incorrect handling of the declaration context stack.Manuel Klimek2013-01-231-2/+2
| | | | llvm-svn: 173250
* Allow us to better guess the context of an unwrapped line.Manuel Klimek2013-01-231-14/+39
| | | | | | | | | | | 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-221-38/+56
| | | | | | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud