summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix formatting of overloaded assignment operators.Daniel Jasper2013-04-111-0/+1
| | | | | | Before: SomeType &operator=(const SomeType & S); After: SomeType &operator=(const SomeType &S); llvm-svn: 179270
* Fixes recovering from errors when parsing braced init lists.Manuel Klimek2013-04-101-0/+14
| | | | | | | Before we would build huge unwrapped lines which take a long time to optimze. llvm-svn: 179168
* Fix labels with trailing comments and cleanup.Daniel Jasper2013-04-101-0/+1
| | | | | | | | | | | | | | | | | | Before: class A { public : // test }; After: class A { public: // test }; Also remove duplicate methods calculating properties of AnnotatedTokens and make them members of AnnotatedTokens so that they are in a common place. llvm-svn: 179167
* Fix comments before labels.Daniel Jasper2013-04-091-0/+1
| | | | | | | | | | | | | | | | | | | | | | Before: switch (...) { // a // b // c case first: break; } After: switch (...) { // a // b // c case first: break; } llvm-svn: 179107
* Again macros without trailing semicolons: don't care about declaration context.Alexander Kornienko2013-04-091-0/+93
| | | | | | | | | | | | | | | | 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-0/+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
* Revamp indentation behavior for complex binary expressions.Daniel Jasper2013-04-081-7/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The idea is to indent according to operator precedence and pretty much identical to how stuff would be indented with parenthesis. Before: bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > ccccccccccccccccccccccccccccccccccccccccc; After: bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > ccccccccccccccccccccccccccccccccccccccccc; llvm-svn: 179049
* Revert accidental commit r179015.Daniel Jasper2013-04-081-11/+11
| | | | llvm-svn: 179016
* xDaniel Jasper2013-04-081-11/+11
| | | | llvm-svn: 179015
* Allow breaking after 'class' for classes with looong names.Daniel Jasper2013-04-051-1/+5
| | | | | | (Don't ask, this was a user request). llvm-svn: 178888
* Fix bad formatting of overloaded operator definitions.Daniel Jasper2013-04-051-0/+4
| | | | | | | | | | | | | | | | Before: bool operator< (const aaaaaaaaaaaaaaaaaaaaa &left, const aaaaaaaaaaaaaaaaaaaaa &right) { return left.group < right.group; } After: bool operator<(const aaaaaaaaaaaaaaaaaaaaa &left, const aaaaaaaaaaaaaaaaaaaaa &right) { return left.group < right.group; } llvm-svn: 178887
* Improve formatting of multi-variable DeclStmts.Daniel Jasper2013-04-051-1/+16
| | | | | | | | | | | | | | | | | | | | This fixed llvm.org/PR15670 Before: aaaaaaaaa a = aaaaaaaaaaaaaaaaaaaa, b = bbbbbbbbbbbbbbbbbbbb, c = cccccccccccccccccccc, d = dddddddddddddddddddd; aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb, *c = ccccccccccccccccccc, *d = ddddddddddddddddddd; After: aaaaaaaaa a = aaaaaaaaaaaaaaaaaaaa, b = bbbbbbbbbbbbbbbbbbbb, c = cccccccccccccccccccc, d = dddddddddddddddddddd; aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb, *c = ccccccccccccccccccc, *d = ddddddddddddddddddd; llvm-svn: 178860
* Improve formatting of for loops and multi-variable DeclStmts.Daniel Jasper2013-04-031-10/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This combines several related changes: a) Don't break before after the variable types in for loops with a single variable. b) Better indent DeclStmts defining multiple variables. Before: bool aaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa), bbbbbbbbbbbbbbbbbbbbbbbbb = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb); for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa = aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa; aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) { } After: bool aaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa), bbbbbbbbbbbbbbbbbbbbbbbbb = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb); for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa = aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa; aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) { } llvm-svn: 178641
* Even better way to handle comments adjacent to preprocessor directives.Alexander Kornienko2013-04-031-0/+8
| | | | | | | | | | | | | | | | | | 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
* Fix some inconsistent use of indentation.Daniel Jasper2013-04-021-2/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Basically we have always special-cased the top-level statement of an unwrapped line (the one with ParenLevel == 0) and that lead to several inconsistencies. All added tests were formatted in a strange way, for example: Before: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(); if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()) { } After: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(); if (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()) { } llvm-svn: 178542
* Alternative handling of comments adjacent to preprocessor directives.Alexander Kornienko2013-04-021-0/+9
| | | | | | | | | | | | | | 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
* Improve formatting of function types.Daniel Jasper2013-04-011-2/+4
| | | | | | Before: void * (*a)(int *, SomeType *); After: void *(*a)(int *, SomeType *); llvm-svn: 178474
* Fixed handling of comments before preprocessor directives.Alexander Kornienko2013-03-281-2/+9
| | | | | | | | | 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
* Insert extra new line before access specifiers.Alexander Kornienko2013-03-271-0/+22
| | | | | | | | | | | | | | Summary: Insert extra new line before access specifiers. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D581 llvm-svn: 178149
* Split line commentsAlexander Kornienko2013-03-271-5/+25
| | | | | | | | | | | | | | | | Summary: Split line comments that exceed column limit + fixed leading whitespace handling when splitting block comments. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D577 llvm-svn: 178133
* Better fix for r177725.Daniel Jasper2013-03-221-0/+1
| | | | | | | | | | | | 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
* Align comments to surrounding unformatted comments.Daniel Jasper2013-03-221-0/+15
| | | | | | | | | | | | | | | Before: int a; // not formatted // formatting this line only After: int a; // not formatted // formatting this line only This makes clang-format stable independent of whether the whole file or single lines are formatted in most cases. llvm-svn: 177739
* More precisely recognize ObjC method declarations.Daniel Jasper2013-03-221-0/+2
| | | | | | | | | Otherwise, +/- and the beginning of constants can be recognized incorrectly. Before: #define A - 1 After: #define A -1 llvm-svn: 177725
* Make clang-format understand more line comments.Daniel Jasper2013-03-221-0/+1
| | | | | | | | | | | Apparently one needs to set LangOptions.LineComment. Before "//* */" got reformatted to "/ /* */" as the lexer was returning the token sequence (slash, comment). This could also lead to weird other stuff, e.g. for people that like to using comments like: //**************** llvm-svn: 177720
* Better block comment formatting.Alexander Kornienko2013-03-211-13/+38
| | | | | | | | | | | | | | | | | Summary: 1. When splitting one-line block comment, use indentation and *s. 2. Remove trailing whitespace from all lines of a comment, not only the ones being splitted. 3. Add backslashes for all lines if a comment is used insed a preprocessor directive. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D557 llvm-svn: 177635
* Support for pointers-to-members usage via .*Alexander Kornienko2013-03-201-1/+12
| | | | | | | | | | | | | | Summary: Added support for pointers-to-members usage via .* and a few tests. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D556 llvm-svn: 177537
* Remove assertion that can be triggered on bad input.Daniel Jasper2013-03-201-1/+4
| | | | | | | clang-format can't do anything useful, so it should leave the remainder of the line unchanged, but it should not assert/segfault. llvm-svn: 177530
* Fix infinite-loop in unwrapped line parser.Daniel Jasper2013-03-201-0/+3
| | | | | | Discovered when accidentally formatting a python file :-). llvm-svn: 177527
* Do not consider comments when adjusting to local indent style.Daniel Jasper2013-03-201-0/+7
| | | | | | | | | | | | | | | | Before (when only reformatting "int b"): int a; // comment // comment int b; After: int a; // comment // comment int b; This also fixes llvm.org/PR15433. llvm-svn: 177524
* Reduce penalty for breaks after "(" for functions with parameters.Daniel Jasper2013-03-201-1/+5
| | | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: aaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 177521
* Add extra indentation for multiline comparisons.Daniel Jasper2013-03-201-3/+3
| | | | | | | | | | | | | | | | 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/+6
| | | | | | | | | | Otherwise, this can become hard to read. Before: #define A \ case 1: After: #define A \ case 1: llvm-svn: 177509
* Improve formatting of function types in template parameters.Daniel Jasper2013-03-201-0/+3
| | | | | | Before: A<int * (int)>; After: A<int *(int)>; llvm-svn: 177505
* Fix indentation for case: // comment.Daniel Jasper2013-03-191-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | Before: switch (x) { case 1: // Do amazing stuff { g(); f(); } } After: switch (x) { case 1: // Do amazing stuff { g(); f(); } } llvm-svn: 177420
* Split long lines in multi-line comments.Alexander Kornienko2013-03-191-0/+128
| | | | | | | | | | | | | | Summary: This is implementation for /* */ comments only. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D547 llvm-svn: 177415
* Fix clang-format segfault.Daniel Jasper2013-03-181-0/+2
| | | | | | | | When annotating "lines" starting with ":", clang-format would segfault. This could actually happen in valid code, e.g. #define A : llvm-svn: 177283
* Improve formatting of chained calls.Daniel Jasper2013-03-151-0/+10
| | | | | | | | | | | | | | | | clang-format already prevented sequences like: ... SomeParameter).someFunction( ... as those are quite confusing. This failed on: ... SomeParameter).someFunction(otherFunction( ... Fixed in this patch. llvm-svn: 177157
* Indent all lines in a multi-line comment by the same amount.Alexander Kornienko2013-03-151-8/+16
| | | | | | | | | | | | | | | | Summary: Do this to avoid spoling nicely formatted multi-line comments (e.g. with code examples or similar stuff). Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D544 llvm-svn: 177153
* Multi-line comment alignmentAlexander Kornienko2013-03-141-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | Summary: Aligns continuation lines of multi-line comments to the base indentation level +1: class A { /* * test */ void f() {} }; The first revision is work in progress. The implementation is not yet complete. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D541 llvm-svn: 177080
* Slightly improve formatting of longer pipe statements.Daniel Jasper2013-03-141-0/+2
| | | | | | | | | | | | | | | The stronger binding of a string ending in :/= does not really make sense if it is the only character. Before: llvm::outs() << aaaaaaaaaaaaaaaaaaaaaaaa << "=" << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; After: llvm::outs() << aaaaaaaaaaaaaaaaaaaaaaaa << "=" << bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; llvm-svn: 177075
* Basic support for formatting asm() statments.Daniel Jasper2013-03-141-0/+10
| | | | llvm-svn: 177073
* Fix dereference formatting in for-loops.Daniel Jasper2013-03-141-0/+1
| | | | | | Before: for (char **a = b; * a; ++a) {} After: for (char **a = b; *a; ++a) {} llvm-svn: 177037
* Improve formatting of trailing annotations.Daniel Jasper2013-03-141-3/+11
| | | | | | | | | | | | Before: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__(( unused)); After: bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa __attribute__((unused)); llvm-svn: 177034
* Fix incorrect cast identification.Daniel Jasper2013-03-131-0/+2
| | | | | | Before: int a = sizeof(int *)+ b;" After: int a = sizeof(int *) + b; llvm-svn: 176957
* Fix comment indentation before labels.Daniel Jasper2013-03-131-0/+5
| | | | | | | | | | | | | | | | | | Before: switch (x) { // if 1, do f() case 1: f(); } After: switch (x) { // if 1, do f() case 1: f(); } llvm-svn: 176953
* Fix formatting issue with builder-type calls.Daniel Jasper2013-03-131-0/+4
| | | | | | | | | | | | Before: ->aaaaaa()->aaaaaaaaaaa(aaaaaaaa()->aaaaaa()->aaaaa() - aaaaaaaaa()->aaaaaa() ->aaaaa()); After: a->aaaaaa()->aaaaaaaaaaa(aaaaaaaa()->aaaaaa()->aaaaa() - aaaaaaaaa()->aaaaaa()->aaaaa()); llvm-svn: 176952
* Fix formatting of new arrays of pointers.Daniel Jasper2013-03-131-0/+2
| | | | | | | | | | | | | | Before: A = new SomeType * [Length]; A = new SomeType *[Length](); After: A = new SomeType *[Length]; A = new SomeType *[Length](); Small formatting cleanups with clang-format. llvm-svn: 176936
* Implemented formatting of rvalue referencesAlexander Kornienko2013-03-121-5/+24
| | | | | | | | | | | | | | | | | | Summary: Handle "&&" usage as rvalue reference, added tests and fixed incorrect tests that interfere with this feature. http://llvm.org/bugs/show_bug.cgi?id=15051 Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D531 llvm-svn: 176874
* Remove bad space after "default".Daniel Jasper2013-03-121-0/+4
| | | | | | | | | | | | | | Before: switch (x) { default : {} } After: switch (x) { default: {} } llvm-svn: 176861
* Fixes breaking of string literals.Manuel Klimek2013-03-081-0/+39
| | | | | | | | | 1. We now ignore all non-default string literals, including raw literals. 2. We do not break inside escape sequences any more. FIXME: We still break in trigraphs. llvm-svn: 176710
OpenPOWER on IntegriCloud