summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* 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
* Fixes various problems around enum parsing.Manuel Klimek2013-01-211-31/+42
| | | | | | | | | | | | | | | | Very similar to what we do for record definitions: - tighten down what is an enum definition, so that we don't mistake a function for an enum - allow common idioms around declarations (we'll want to handle that more centrally in the future) We now correctly format: enum X f() { a(); return 42; } llvm-svn: 173075
* Fixes formatting of empty blocks.Manuel Klimek2013-01-211-8/+6
| | | | | | | | | | | | | | | | We now only put empty blocks into a single line, if all of: - all tokens of the structural element fit into a single line - we're not in a control flow statement Note that we usually don't put record definitions into a single line, as there's usually at least one more token (the semicolon) after the closing brace. This doesn't hold when we are in a context where there is no semicolon, like "enum E {}". There were some missing tests around joining lines around the corner cases of the allowed number of columns, so this patch adds some. llvm-svn: 173055
* Fixes indent in linkage specification blocks.Manuel Klimek2013-01-211-0/+12
| | | | | | | | | | | We now indent: extern "C" { int a; } without additional indent inside the extern "C" block. llvm-svn: 173045
* Fixes detection of class template specializations.Manuel Klimek2013-01-211-1/+14
| | | | | | | Now correctly formats: template <> class A<int> {} a; llvm-svn: 173038
* Allow for nested name specifiers in record declarations.Manuel Klimek2013-01-211-1/+3
| | | | | | | Now correctly formats: class A::B {} n; llvm-svn: 173019
* Fix parsing of return statements.Manuel Klimek2013-01-211-0/+29
| | | | | | | | | 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/+1
| | | | | | | | | | 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
* Fixes problems with line merging in the face of preprocessor directives.Manuel Klimek2013-01-181-7/+33
| | | | | | | | | | | | | | | 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
* Formatter: After case blocks, "break" goes on the same line as the "}", PR14907.Nico Weber2013-01-181-0/+2
| | | | | | | | | | | | | | | | | | | | | Before: switch (foo) { case a: { int a = g(); h(a); } break; } Now: switch (foo) { case a: { int a = g(); h(a); } break; } llvm-svn: 172789
* Add debugging support for split penalties.Manuel Klimek2013-01-161-1/+0
| | | | llvm-svn: 172616
* Use standard llvm Debug.h support for debugging output.Manuel Klimek2013-01-161-17/+16
| | | | | | | | Leave a quick "// Uncomment this." hint to enable the debug output in tests. FIXME: figure out whether we want to enable debug command line handling for all tests. llvm-svn: 172608
* Clang Format: Handle missing semicolonAlexander Kornienko2013-01-161-2/+5
| | | | llvm-svn: 172606
* Change the datastructure for UnwrappedLines.Daniel Jasper2013-01-161-34/+15
| | | | | | | | | | | | | | 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-22/+23
| | | | | | | | | | | | | | | | | | | | 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
* Format unions like structs and classes.Daniel Jasper2013-01-131-1/+2
| | | | | | | | | | | Note that I don't know whether we should put {} on a single line in this case, but it is probably a theoretical issue as in practice such structs, classes or unions won't be empty. Before: union A {} a; After: union A {} a; llvm-svn: 172355
* Fix crashes in UnwrappedLineParser on missing parens.Manuel Klimek2013-01-111-2/+4
| | | | llvm-svn: 172239
* Fix crash on invalid.Manuel Klimek2013-01-111-1/+2
| | | | | | | if { foo; } would previously crash clang-format. llvm-svn: 172232
* Fix parsing of initializer lists with elaborated type specifier.Manuel Klimek2013-01-111-2/+8
| | | | | | | | Now we correctly parse and format: verifyFormat("struct foo a = { bar }; int n; llvm-svn: 172229
* clang-format: a bit nicer error message.Alexander Kornienko2013-01-111-1/+1
| | | | llvm-svn: 172211
* Basic support for diagnostics.Alexander Kornienko2013-01-101-6/+9
| | | | | | | | | | | | | | 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
* Do not add newline in empty blocks.Manuel Klimek2013-01-101-6/+8
| | | | | | | void f() {} now gets formatted in one line. llvm-svn: 172067
* Fix layout of blocks inside statements.Manuel Klimek2013-01-101-18/+70
| | | | | | | | | | | | | | | 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
* Introduce a define to switch on debug output.Manuel Klimek2013-01-101-0/+17
| | | | | | | After re-writing the same loop multiple times, we deicided it's time to add this as an optional debugging help. llvm-svn: 172050
* Formatter: @optional and @required go on their own line.Nico Weber2013-01-101-0/+5
| | | | | | | | | | | | | | | | | | | | Previously: @protocol myProtocol - (void)mandatoryWithInt:(int)i; @optional - (void) optional; @required - (void) required; @end Now: @protocol myProtocol - (void)mandatoryWithInt:(int)i; @optional - (void)optional; @required - (void)required; @end llvm-svn: 172023
OpenPOWER on IntegriCloud