summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.h
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Fix various problems in formatting ObjC blocks.Daniel Jasper2013-12-231-1/+2
| | | | | | Among other things, this fixes llvm.org/PR15269. llvm-svn: 197900
* Implemented GNU-style formatting for compound statements.Alexander Kornienko2013-12-121-0/+1
| | | | | | | | | | | | | | | | Summary: Added BraceBreakingStyle::BS_GNU. I'm not sure about the correctness of static initializer formatting, but compound statements should be fine. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2372 llvm-svn: 197138
* Automatically munch semicolons after blocks.Manuel Klimek2013-10-121-1/+2
| | | | | | | | 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
* Support formatting of preprocessor branches.Manuel Klimek2013-10-111-2/+24
| | | | | | | | | | | | | | | | | | | | | 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
* clang-format: Fix incorrect enum parsing / layouting.Daniel Jasper2013-09-131-1/+1
| | | | | | | | | | | | | | | Before: enum { Bar = Foo < int, int > ::value }; After: enum { Bar = Foo<int, int>::value }; llvm-svn: 190674
* Unbreak build with libc++, whose std::list<T> requires T to be complete.Douglas Gregor2013-09-051-1/+4
| | | | llvm-svn: 190075
* clang-format: Enable formatting of nested blocks.Daniel Jasper2013-09-051-4/+14
| | | | | | | | | | | | | | | | | | 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
* Implement parsing of blocks (^{ ... }) in the unwrapped line parser.Manuel Klimek2013-09-041-0/+1
| | | | | | | | | | | | | | | | | | | | | | 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
* First step towards correctly formatting lambdas.Manuel Klimek2013-09-031-0/+2
| | | | | | | | | | 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: Add more options to namespace indentation.Daniel Jasper2013-07-311-1/+1
| | | | | | | | | | | | | 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
* Fix alignment of closing brace in braced initializers.Daniel Jasper2013-07-091-12/+0
| | | | | | | | | | | | | | | | | | | | | | 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
* Reformat clang-format's source files after r185822 and others.Daniel Jasper2013-07-081-6/+4
| | | | llvm-svn: 185823
* Moved FormatToken to a separate header.Alexander Kornienko2013-06-031-255/+1
| | | | llvm-svn: 183115
* The second step in the token refactoring.Manuel Klimek2013-05-291-1/+193
| | | | | | | | | | Gets rid of AnnotatedToken, putting everything into FormatToken. FormatTokens are created once, and only referenced by pointer. This enables multiple future features, like having tokens shared between multiple UnwrappedLines (while there's still work to do to fully enable that). llvm-svn: 182859
* Make UnwrappedLines and AnnotatedToken contain pointers to FormatToken.Manuel Klimek2013-05-281-1/+6
| | | | | | The FormatToken is now not copyable any more. llvm-svn: 182772
* A first step towards giving format tokens pointer identity.Manuel Klimek2013-05-281-19/+6
| | | | | | | | | | | 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
* Remove unreachable returnDavid Blaikie2013-05-271-1/+0
| | | | llvm-svn: 182742
* Major refactoring of BreakableToken.Manuel Klimek2013-05-271-6/+8
| | | | | | | | | | | | | | | | | | | Unify handling of whitespace when breaking protruding tokens with other whitespace replacements. As a side effect, the BreakableToken structure changed significantly: - have a common base class for single-line breakable tokens, as they are much more similar - revamp handling of multi-line comments; we now calculate the information about lines in multi-line comments similar to normal tokens, and always issue replacements As a result, we were able to get rid of special casing of trailing whitespace deletion for comments in the whitespace manager and the BreakableToken and fixed bugs related to tab handling and escaped newlines. llvm-svn: 182738
* Address post-review comment from dblakie.Manuel Klimek2013-05-271-1/+1
| | | | llvm-svn: 182732
* Ignore contents of #if 0 blocks.Alexander Kornienko2013-05-241-1/+16
| | | | | | | | | | | | | | | | 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
* Use a SourceRange for the whitespace location in FormatToken.Manuel Klimek2013-05-231-11/+4
| | | | | | | | | | | 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
* Fix no-assert compiles.Manuel Klimek2013-05-231-1/+4
| | | | llvm-svn: 182569
* Expand parsing of braced init lists.Manuel Klimek2013-05-231-0/+25
| | | | | | | | | | | | | | | | 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-6/+1
| | | | | | | We only ever implemented one and that one is not actually all that helpful (e.g. gets incorrectly triggered by macros). llvm-svn: 181871
* Unified token breaking logic: support for line comments.Alexander Kornienko2013-04-171-1/+13
| | | | | | | | | | | | | | | | | | | Summary: Added BreakableLineComment, moved common code from BreakableBlockComment to newly added BreakableComment. As a side-effect of the rewrite, found another problem with escaped newlines and had to change code which removes trailing whitespace from line comments not to break after this patch. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D682 llvm-svn: 179693
* Revamps structural error detection / handling.Manuel Klimek2013-04-121-3/+7
| | | | | | | | | | | | | | | | | | | | | 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
* Format a line if a range in its leading whitespace was selected.Daniel Jasper2013-03-041-2/+6
| | | | | | | | | | | With [] marking the selected range, clang-format invoked on [ ] int a; Would so far not reformat anything. With this patch, it formats a line if its leading whitespace is touched. llvm-svn: 176435
* 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
* Allow us to better guess the context of an unwrapped line.Manuel Klimek2013-01-231-2/+8
| | | | | | | | | | | 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-1/+8
| | | | | | | | | | | | | | | | | | 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
* Fix parsing of return statements.Manuel Klimek2013-01-211-0/+1
| | | | | | | | | 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-191-1/+0
| | | | | | | | | | 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 problems with line merging in the face of preprocessor directives.Manuel Klimek2013-01-181-0/+15
| | | | | | | | | | | | | | | 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
* Calculate the total length of a line up to each token up front.Daniel Jasper2013-01-161-0/+1
| | | | | | | | | | This makes the tedious fitsIntoLimit() method unnecessary and I can replace one hack (constructor initializers) by a slightly better hack. Furthermore, this will enable calculating whether a certain part of a line fits into the limit for future modifications. llvm-svn: 172604
* Change the datastructure for UnwrappedLines.Daniel Jasper2013-01-161-10/+3
| | | | | | | | | | | | | | It was quite convoluted leading to us accidentally introducing O(N^2) complexity while copying from UnwrappedLine to AnnotatedLine. We might still want to improve the datastructure in AnnotatedLine (most importantly not put them in a vector where they need to be copied on vector resizing but that will be done as a follow-up. This fixes most of the regression in llvm.org/PR14959. No formatting changes intended. llvm-svn: 172602
* Fixes various bugs around the keywords class, struct and union.Manuel Klimek2013-01-151-1/+1
| | | | | | | | | | | | | | | | | | | | This switches to parsing record definitions only if we can clearly identify them. We're specifically allowing common patterns for visibility control through macros and attributes, but we cannot currently fix all instances. This fixes all known bugs we have though. Before: static class A f() { return g(); } int x; After: static class A f() { return g(); } int x; llvm-svn: 172530
* Remove useless 'llvm::' qualifier from names like StringRef and others that areDmitri Gribenko2013-01-121-1/+1
| | | | | | brought into 'clang' namespace by clang/Basic/LLVM.h llvm-svn: 172323
* Fix parsing of initializer lists with elaborated type specifier.Manuel Klimek2013-01-111-1/+1
| | | | | | | | Now we correctly parse and format: verifyFormat("struct foo a = { bar }; int n; llvm-svn: 172229
* Basic support for diagnostics.Alexander Kornienko2013-01-101-1/+6
| | | | | | | | | | | | | | Summary: Uses DiagnosticsEngine to output diagnostics. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D278 llvm-svn: 172071
* Fix layout of blocks inside statements.Manuel Klimek2013-01-101-0/+3
| | | | | | | | | | | | | | | Previously, we would not indent: SOME_MACRO({ int i; }); correctly. This is fixed by adding the trailing }); to the unwrapped line starting with SOME_MACRO({, so the formatter can correctly match the braces and indent accordingly. Also fixes incorrect parsing of initializer lists, like: int a[] = { 1 }; llvm-svn: 172058
* Formatter: Add support for @implementation.Nico Weber2013-01-091-1/+1
| | | | | | | Just reuse the @interface code for this. It accepts slightly more than necessary (@implementation cannot have protocol lists), but that's ok. llvm-svn: 172019
* Formatting: Add support for @protocol.Nico Weber2013-01-091-0/+3
| | | | | | Pull pieces of the @interface code into reusable methods. llvm-svn: 172001
* Formatter: Add support for @interface.Nico Weber2013-01-091-0/+1
| | | | | | | | | | | | | | Previously: @interface Foo + (id)init; @end Now: @interface Foo + (id)init; @end Some tweaking remains, but this is a good first step. llvm-svn: 171995
* Enables layouting unwrapped lines around preprocessor directives.Manuel Klimek2013-01-091-2/+9
| | | | | | | | | | | | | | | | | | | | | | | Previously, we'd always start at indent level 0 after a preprocessor directive, now we layout the following snippet (column limit 69) as follows: functionCallTo(someOtherFunction( withSomeParameters, whichInSequence, areLongerThanALine(andAnotherCall, B withMoreParamters, whichStronglyInfluenceTheLayout), andMoreParameters), trailing); Note that the different jumping indent is a different issue that will be addressed separately. This is the first step towards handling #ifdef->#else->#endif chains correctly. llvm-svn: 171974
* Change the data structure used in clang-format.Daniel Jasper2013-01-081-1/+10
| | | | | | | | | | | | This is a first step towards supporting more complex structures such as #ifs inside unwrapped lines. This patch mostly converts the array-based UnwrappedLine into a linked-list-based UnwrappedLine. Future changes will allow multiple children for each Token turning the UnwrappedLine into a tree. No functional changes intended. llvm-svn: 171856
* Fix parsing of variable declarations directly after a class / struct.Manuel Klimek2013-01-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previous indent: class A { } a; void f() { }; With this patch: class A { } a; void f() { } ; The patch introduces a production for classes and structs, and parses the rest of the line to the semicolon after the class scope. This allowed us to remove a long-standing wart in the parser that would just much the semicolon after any block. Due to this suboptimal formating some tests were broken. Some unrelated formatting tests broke; those hit a bug in the ast printing, and need to be fixed separately. llvm-svn: 171761
* s/parseStatement/parseStructuralElement/g in the UnwrappedLineParser.Manuel Klimek2013-01-071-1/+1
| | | | llvm-svn: 171737
* Reformat clang-formats source code.Daniel Jasper2013-01-071-3/+3
| | | | | | All changes done by clang-format itself. No functional changes. llvm-svn: 171732
* Fix layouting of tokens with a leading escaped newline.Manuel Klimek2013-01-071-1/+6
| | | | | | | | | | | If a token follows directly on an escaped newline, the escaped newline is stored with the token. Since we re-layout escaped newlines, we need to treat them just like normal whitespace - thus, we need to increase the whitespace-length of the token, while decreasing the token length (otherwise the token length contains the length of the escaped newline and we double-count it while indenting). llvm-svn: 171706
OpenPOWER on IntegriCloud