summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.h
Commit message (Collapse)AuthorAgeFilesLines
* 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
* Fixes handling of unbalances braces.Manuel Klimek2013-01-061-1/+1
| | | | | | | | | | | | | If we find an unexpected closing brace, we must not stop parsing, as we'd otherwise not layout anything beyond that point. If we find a structural error on the highest level we'll not re-indent anyway, but we'll still want to format within unwrapped lines. Needed to introduce a differentiation between an expected and unexpected closing brace. llvm-svn: 171666
* Fixes parsing of hash tokens in the middle of a line.Manuel Klimek2013-01-051-1/+5
| | | | | | | | | | | To parse # correctly, we need to know whether it is the first token in a line - we can deduct this either from the whitespace or seeing that the token is the first in the file - we already calculate this information. This patch moves the identification of the first token into the getNextToken method and stores it inside the FormatToken, so the UnwrappedLineParser can stay independent of the SourceManager. llvm-svn: 171640
* Fixes PR14801 - preprocessor directives shouldn't be indentedManuel Klimek2013-01-051-0/+3
| | | | | | | Uses indent 0 for macros for now and resets the indent state to the level prior to the preprocessor directive. llvm-svn: 171639
* Various fixes to clang-format's macro handling.Manuel Klimek2013-01-041-1/+5
| | | | | | | | | | | | | | | | | | | Some of this is still pretty rough (note the load of FIXMEs), but it is strictly an improvement and fixes various bugs that were related to macro processing but are also imporant in non-macro use cases. Specific fixes: - correctly puts espaced newlines at the end of the line - fixes counting of white space before a token when escaped newlines are present - fixes parsing of "trailing" tokens when eof() is hit - puts macro parsing orthogonal to parsing other structure - general support for parsing of macro definitions Due to the fix to format trailing tokens, this change also includes a bunch of fixes to the c-index tests. llvm-svn: 171556
* Fixes use of unescaped newlines when formatting preprocessor directives.Manuel Klimek2013-01-021-2/+10
| | | | | | | | | | | This is the first step towards handling preprocessor directives. This patch only fixes the most pressing issue, namely correctly escaping newlines for tokens within a sequence of a preprocessor directive. The next step will be to fix incorrect format decisions on #define directives. llvm-svn: 171393
* Let clang-format format itself.Daniel Jasper2012-12-241-1/+1
| | | | | | | | Apply all formatting changes that clang-format would apply to its own source code. All choices seem to improve readability (or at least not make it worse). No functional changes. llvm-svn: 171039
* Fix several formatting problems.Daniel Jasper2012-12-171-1/+1
| | | | | | | | | More specifically: - Improve formatting of static initializers. - Fix formatting of lines comments in enums. - Fix formmating of trailing line comments. llvm-svn: 170316
* Appease -Wnon-virtual-dtorMatt Beaumont-Gay2012-12-071-0/+2
| | | | llvm-svn: 169648
* Clang-format: extracted FormatTokenSource from UnwrappedLineParser.Alexander Kornienko2012-12-071-10/+7
| | | | | | | | | | | | | | Summary: FormatTokenLexer is here, FormatTokenBuffer is on the way. This will allow to re-parse unwrapped lines when needed. Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D186 llvm-svn: 169605
* Clang-format: IndentCaseLabels option, proper namespace handlingAlexander Kornienko2012-12-061-2/+6
| | | | | | | | | | | | | | Summary: + tests arranged in groups, as their number is already quite large. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D185 llvm-svn: 169520
* Clang-format: parse for and while loopsAlexander Kornienko2012-12-051-0/+1
| | | | | | | | | | | | | | Summary: Adds support for formatting for and while loops. Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D174 llvm-svn: 169387
* Follow-up to r169286, addresses comments in ↵Alexander Kornienko2012-12-051-1/+1
| | | | | | http://llvm-reviews.chandlerc.com/D164#comment-4 : comments and a method rename llvm-svn: 169382
* Add missing destructors found with -Wnon-virtual-dtor.Daniel Jasper2012-12-041-0/+2
| | | | llvm-svn: 169303
* Error recovery part 2Alexander Kornienko2012-12-041-3/+4
| | | | | | | | | | | | | | Summary: Adds recovery for structural errors in clang-format. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, silvas Differential Revision: http://llvm-reviews.chandlerc.com/D164 llvm-svn: 169286
* Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth2012-12-041-2/+2
| | | | | | | | | | | | | uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. llvm-svn: 169237
* Initial version of formatting library.Daniel Jasper2012-12-031-0/+119
This formatting library will be used by a stand-alone clang-format tool and can also be used when writing other refactorings. Manuel's original design document: https://docs.google.com/a/google.com/document/d/1gpckL2U_6QuU9YW2L1ABsc4Fcogn5UngKk7fE5dDOoA/edit The library can already successfully format itself. Review: http://llvm-reviews.chandlerc.com/D80 llvm-svn: 169137
OpenPOWER on IntegriCloud