summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* Only keep empty lines in unwrapped lines if they preceed a line comment.Daniel Jasper2013-02-262-5/+5
| | | | | | | | | | | | | | | | | | Empty lines followed by line comments are often used to highlight the comment. Empty lines somewhere else are usually left over from manual or automatic formatting and should probably be removed. Before (clang-format would keep): S s = { a, b }; After: S s = { a, b }; llvm-svn: 176086
* Only break string literals as a last resort.Daniel Jasper2013-02-261-1/+1
| | | | | | | | | | | | | | | | | We might want to move towards doing this if the formatting can be significantly improved, but we need to carefully evaluate the different situations first. Before (the string literal was split by clang-format here): aaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa, aaaaaa("aaa aaaaa aaa aaa aaaaa aaa " "aaaaa aaa aaa aaaaaa")); After: aaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaa, aaaaaa("aaa aaaaa aaa aaa aaaaa aaa aaaaa aaa aaa aaaaaa")); llvm-svn: 176084
* Re-add hack that caused regression.Daniel Jasper2013-02-251-1/+3
| | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR15350. Before: Constructor(int Parameter = 0) : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa), aaaaaaaaaaaa(aaaaaaaaaaaaaaaaa) {} After: Constructor(int Parameter = 0) : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa), aaaaaaaaaaaa(aaaaaaaaaaaaaaaaa) {} I think the correct solution is to put the VariablePos into ParenState, not LineState. Added FIXME. llvm-svn: 176027
* Allow breaking between a type and name in variable declarations.Daniel Jasper2013-02-243-45/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR14967 and is generall necessary to avoid situations where the column limit is exceeded. The challenge is restricting such lines splits, otherwise clang-format suddenly starts breaking at bad places. Before: ReallyLongReturnType<TemplateParam1, TemplateParam2> ReallyReallyLongFunctionName( const std::string &SomeParameter, const SomeType<string, SomeOtherTemplateParameter> &ReallyReallyLongParameterName, const SomeType<string, SomeOtherTemplateParameter> &AnotherLongParameterName) {} After: ReallyLongReturnType<TemplateParam1, TemplateParam2> ReallyReallyLongFunctionName( const std::string &SomeParameter, const SomeType<string, SomeOtherTemplateParameter> & ReallyReallyLongParameterName, const SomeType<string, SomeOtherTemplateParameter> & AnotherLongParameterName) {} llvm-svn: 175999
* Better formatting of conditional expressions.Daniel Jasper2013-02-232-50/+53
| | | | | | | | | | | | | | | | | | | | | | | In conditional expressions, if the condition is split over multiple lines, also break before both operands. This prevents formattings like: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? b : c; Which are bad, because they suggestion incorrect operator precedence: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? b : c); This lead to the discovery that the expression parser incorrectly handled conditional operators and that it could also handle semicolons (which in turn reduced the amount of special casing for for-loops). As a side-effect, we can now apply the bin-packing configuration to the sections of for-loops. llvm-svn: 175973
* Don't recognize unnamed pointer parameters as casts.Daniel Jasper2013-02-231-1/+2
| | | | | | | | This fixes llvm.org/PR15061. Before: virtual void f(int *)const; After: virtual void f(int *) const; llvm-svn: 175960
* Allow splitting between string literals and identifiers.Daniel Jasper2013-02-231-0/+6
| | | | | | | | | | | | | | | Also don't break in long include directives as that is not desired. We can now format: #include "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaa" #define LL_FORMAT "ll" printf("aaaaa: %d, bbbbbbbbb: %" LL_FORMAT "d, cccccccc: %" LL_FORMAT "d, ddddddddd: %" LL_FORMAT "d\n"); Before, this led to weird results. llvm-svn: 175959
* Remove accidentally introduced no-op line.Daniel Jasper2013-02-211-1/+0
| | | | | | | Was used during experiments, but another if-statements a few lines before makes it (intentionally) useless. llvm-svn: 175803
* Consistently put {} onto the same line for empty functions.Daniel Jasper2013-02-212-20/+20
| | | | | | | | | | | | | | | | | This fixes llvm.org/PR15167. Before: LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10), BBBBBBBBB(10) { } LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10) {} After: LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10), BBBBBBBBB(10) {} LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL() : AAAAAAAA(10) {} llvm-svn: 175800
* Allow breaking between type and name in for loops.Daniel Jasper2013-02-212-12/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR15033. Also: Always break before a parameter, if the previous parameter was split over multiple lines. This was necessary to make the right decisions in for-loops, almost always makes the code more readable and also fixes llvm.org/PR14873. Before: for (llvm::ArrayRef<NamedDecl *>::iterator I = FD->getDeclsInPrototypeScope() .begin(), E = FD->getDeclsInPrototypeScope().end(); I != E; ++I) { } foo(bar(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccc), d, bar(e, f)); After: for (llvm::ArrayRef<NamedDecl *>::iterator I = FD->getDeclsInPrototypeScope().begin(), E = FD->getDeclsInPrototypeScope().end(); I != E; ++I) { } foo(bar(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, ccccccccccccccccccccccccccccc), d, bar(e, f)); llvm-svn: 175741
* Fix regression in string literal alignment.Manuel Klimek2013-02-201-1/+1
| | | | | | | | | Now correctly indents (again): a = a + "a" "a" "a"; llvm-svn: 175630
* Fixes bug in string literal alignment.Manuel Klimek2013-02-201-2/+15
| | | | | | | | | We now indent the following correctly: 1. some + "literal" /* comment */ "literal"; 2. breaking string literals after which we have another string literal. llvm-svn: 175628
* Don't remove blank lines within unwrapped lines.Daniel Jasper2013-02-202-7/+12
| | | | | | | | | | | | | | | | | If the code author decides to put empty lines anywhere into the code we should treat them equally, i.e. reduce them to the configured MaxEmptyLinesToKeep. With this change, we e.g. keep the newline in: SomeType ST = { // First value a, // Second value b }; llvm-svn: 175620
* Implements breaking of string literals if they stick out.Manuel Klimek2013-02-201-17/+97
| | | | | | | | | | An alternative strategy to calculating the break on demand when hitting a token that would need to be broken would be to put all possible breaks inside the token into the optimizer. Currently only supports breaking at spaces; more break points to come. llvm-svn: 175613
* Add missing clang-format null pointer check..Daniel Jasper2013-02-191-1/+2
| | | | | | .. and a test that triggers it in valid albeit questionable code. llvm-svn: 175554
* Correctly format macro with unfinished template declaration.Daniel Jasper2013-02-191-1/+2
| | | | | | | | | We can now format: #define A template <typename T> Before this created a segfault :-/. llvm-svn: 175533
* Fix bug in LineState comparison function.Daniel Jasper2013-02-191-13/+13
| | | | | | | | | | | | | | The key bug was if (Other.StartOfLineLevel < StartOfLineLevel) .. instead of if (Other.StartOfLineLevel != StartOfLineLevel) .. Also cleaned up the function to be more consistent in the comparisons. llvm-svn: 175500
* Improve indentation of builder type calls.Daniel Jasper2013-02-182-2/+4
| | | | | | | | | | | | | | | | | | | | | | | In builder-type calls, it can be very confusing to just indent parameters from the start of the line. Instead, indent 4 from the correct function call. Before: aaaaaaaaaaaaaaaaaaa()->aaaaaa(bbbbb)->aaaaaaaaaaaaaaaaaaa( // break aaaaaaaaaaaaaa); aaaaaaaaaaaaaaaaaaaaaaa *aaaaaaaaa = aaaaaa->aaaaaaaaaaaa()->aaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) ->aaaaaaaaaaaaaaaaa(); After: aaaaaaaaaaaaaaaaaaa()->aaaaaa(bbbbb)->aaaaaaaaaaaaaaaaaaa( // break aaaaaaaaaaaaaa); aaaaaaaaaaaaaaaaaaaaaaa *aaaaaaaaa = aaaaaa->aaaaaaaaaaaa() ->aaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) ->aaaaaaaaaaaaaaaaa(); llvm-svn: 175444
* Improve formatting of builder-type calls.Daniel Jasper2013-02-181-1/+1
| | | | | | | | | | | | | Before: aaaaaaa->aaaaaaa->aaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaa(aaaaaaaaaaaaaaa); After: aaaaaaa->aaaaaaa ->aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) ->aaaaaaaa(aaaaaaaaaaaaaaa); llvm-svn: 175441
* Reformat lines if they were "moved around".Daniel Jasper2013-02-181-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | An unwrapped line can get moved around if there is no newline before it and the previous line was formatted. Example: template<typename T> // Cursor is on this line when hitting "format" T *getFETokenInfo() const { return static_cast<T*>(FETokenInfo); } "return .." is the second unwrapped line in this scenario. I does not touch any reformatted region. Thus, the result of formatting is: template <typename T> T *getFETokenInfo() const { return static_cast<T *>(FETokenInfo); } After second format (and arguably desired end-result): template <typename T> T *getFETokenInfo() const { return static_cast<T *>(FETokenInfo); } This fixes: llvm.org/PR15060. llvm-svn: 175440
* Correctly determine */& usage in more cases.Daniel Jasper2013-02-181-0/+8
| | | | | | | | | | | | | | This fixes llvm.org/PR15248. Before: Test::Test(int b) : a(b *b) {} for (int i = 0; i < a *a; ++i) {} After: Test::Test(int b) : a(b * b) {} for (int i = 0; i < a * a; ++i) {} llvm-svn: 175439
* Always break after multi-line string literals.Daniel Jasper2013-02-181-0/+1
| | | | | | | | | | | | | | | | Otherwise, other parameters can be quite hidden. Reformatted unittests/Format/FormatTest.cpp after this. Before: someFunction("Always break between multi-line" " string literals", and, other, parameters); After: someFunction("Always break between multi-line" " string literals", and, other, parameters); llvm-svn: 175436
* Prevent line breaks that make stuff hard to read.Daniel Jasper2013-02-181-0/+15
| | | | | | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaa).aaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: aaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa) .aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa) .aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 175432
* Use the correct type to hold enumeration valuesDmitri Gribenko2013-02-161-2/+2
| | | | llvm-svn: 175374
* Recognize < and > as binary expressions in builder-type calls.Daniel Jasper2013-02-151-3/+5
| | | | | | | | | | | | | | | | | The current heuristic assumes that there can't be binary operators in builder-type calls (excluding assigments). However, it also excluded < and > in general, which is wrong. Now they are only excluded if they are template parameters. Before: return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa()i .aaaaaa() < aaaaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa(); After: return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa() < aaaaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa(); llvm-svn: 175291
* Done break between 'operator' and '<<'.Daniel Jasper2013-02-151-1/+1
| | | | | | | | | | | | Before: ostream &operator <<(ostream &out, some::ns::SomeReallyLongType WithSomeReallyLongValue); After: ostream &operator<<(ostream &out, some::ns::SomeReallyLongType WithSomeReallyLongValue); llvm-svn: 175286
* Re-enable ConstructorInitializerAllOnOneLineOrOnePerLine option.Daniel Jasper2013-02-151-0/+3
| | | | | | | | | This got lost and was untested as the same effect is achieved by avoiding bin packing, which is active in Google style by default. However, moving forward, we want more control over the bin packing option(s) and thus, this flag should work as expected. llvm-svn: 175277
* Prevent only breaking before "?" in conditional expressions.Daniel Jasper2013-02-151-1/+12
| | | | | | | | | | | | | | | This is almost always more readable. Before: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? aaaaaaaaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaa; After: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? aaaaaaaaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaa; llvm-svn: 175262
* Fix counting of parameters so that r175162 works as expected.Daniel Jasper2013-02-142-9/+12
| | | | | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() .aaaaaaaaaaaaaaaaa()); After: aaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa().aaaaaaaaaaaaaaaaa()); Not sure which of the formattings above is better, but we should not pick one by accident. llvm-svn: 175165
* Reduce penalty for breaking before ./-> after complex calls.Daniel Jasper2013-02-142-9/+9
| | | | | | | | | | | | | | | | | This gives a clearer separation of the context, e.g. in GMOCK statements. Before: EXPECT_CALL(SomeObject, SomeFunction(Parameter)).WillRepeatedly(Return(SomeValue)); After: EXPECT_CALL(SomeObject, SomeFunction(Parameter)) .WillRepeatedly(Return(SomeValue)); Minor format cleanups. llvm-svn: 175162
* Remove the trailing whitespace of formatted lines.Daniel Jasper2013-02-141-13/+21
| | | | | | | | | | | | | | | So far, clang-format has always assumed the whitespace belonging to the subsequent token. This has the negative side-effect that when clang-format formats a line, it does not remove its trailing whitespace, as it belongs to the next token. Thus, this patch fixes most of llvm.org/PR15062. We are not zapping a file's trailing whitespace so far, as this does not belong to any token we see during formatting. We need to fix this in a subsequent patch. llvm-svn: 175152
* Get less confused by trailing comma in Google style.Daniel Jasper2013-02-141-1/+2
| | | | | | | | | | | | | | | | | The formatter can now format: void aaaaaaaaaaaaaaaaaa(int level, double *min_x, double *max_x, double *min_y, double *max_y, double *min_z, double *max_z, ) { } Although this is invalid code, it frequently happens during development and clang-format should be nicer :-). llvm-svn: 175151
* Align superclasses for multiple inheritence.Daniel Jasper2013-02-143-2/+14
| | | | | | | | | | | | | | | | This fixes llvm.org/PR15179. Before: class ColorChooserMac : public content::ColorChooser, public content::WebContentsObserver { }; After: class ColorChooserMac : public content::ColorChooser, public content::WebContentsObserver { }; llvm-svn: 175147
* Allow breaking after the return type in function declarations.Daniel Jasper2013-02-132-6/+9
| | | | | | | | | | | | | | | | | This has so far been disabled for Google style, but should be done before breaking at nested name specifiers or in template parameters. Before (in Google style): template <typename T> aaaaaaaa::aaaaa::aaaaaa<T, aaaaaaaaaaaaaaaaaaaaaaaaa> aaaaaaaaaaaaaaaaaaaaaaaa< T>::aaaaaaa() {} After: template <typename T> aaaaaaaa::aaaaa::aaaaaa<T, aaaaaaaaaaaaaaaaaaaaaaaaa> aaaaaaaaaaaaaaaaaaaaaaaa<T>::aaaaaaa() {} llvm-svn: 175074
* Fix comment alignment close to the column limit.Daniel Jasper2013-02-131-1/+1
| | | | | | | Due to an error in one of the expressions, we used to not align comments although it would have been possible. llvm-svn: 175068
* Pull search state out as class members.Manuel Klimek2013-02-131-17/+13
| | | | | | Fix some comments. llvm-svn: 175052
* An attempt to make the search algorithm easier to understand.Manuel Klimek2013-02-131-49/+86
| | | | | | | | | | | | | | | | | | | | - clear ownership: the SpecificBumpPtrAllocator owns all StateNodes - this allows us to simplify the memoization data structure into a std::set (FIXME: figure out whether we want to use a hash based data structure). - introduces StateNode as recursive data structure, instead of using Edge and the Seen-map combined to drill through the graph - using a count to stabilize the penalty instead of relying on the container - pulled out a method to forward-apply states in the end This leads to a ~40% runtime decrease on Nico's benchmark. Main FiXME is that the parameter lists of some function get too long. I'd vote for either pulling the Queue etc into the Formatter proper, or creating an inner class just for the search algorithm. llvm-svn: 175051
* Formatter: Refactor the cast detection code to be a bit more readable.Nico Weber2013-02-131-9/+10
| | | | | | No functionality change. Also add another cast test. llvm-svn: 175029
* Formatter: Detect ObjC method expressions after casts.Nico Weber2013-02-131-1/+1
| | | | | | Not all casts are correctly detected yet, but it helps in some cases. llvm-svn: 175028
* Replace 'signed' with 'int'. 'signed' is not typical for LLVM styleDmitri Gribenko2013-02-121-1/+1
| | | | llvm-svn: 175015
* 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
* Fixing the MSVC compiler warning a different way; removed use of static_cast ↵Aaron Ballman2013-02-121-2/+2
| | | | | | and instead used a signed integer parameter. llvm-svn: 174996
* Removing a signed/unsigned mismatch warning triggered in MSVC 11.Aaron Ballman2013-02-121-1/+1
| | | | llvm-svn: 174986
* Fix bug in the adjustment to existing lines.Daniel Jasper2013-02-121-6/+9
| | | | | | | | | | | | Before (if only the second line was reformatted): void f() {} void g() {} After: void f() {} void g() {} llvm-svn: 174978
* Formatter: Correctly format stars in `sizeof(int**)` and similar places.Nico Weber2013-02-121-14/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This redoes how '*' and '&' are classified as pointer / reference markers when followed by ')', '>', or ','. Previously, determineStarAmpUsage() marked a single '*' and '&' followed by ')', '>', or ',' as pointer or reference marker. Now, all '*'s and '&'s preceding ')', '>', or ',' are marked as pointer / reference markers. Fixes PR14884. Since only the last '*' in 'int ***' was marked as pointer before (the rest were unary operators, which don't reach spaceRequiredBetween()), spaceRequiredBetween() now had to be thought about handing multiple '*'s in sequence. Before: return sizeof(int * *); Type **A = static_cast<Type * *>(P); Now: return sizeof(int**); Type **A = static_cast<Type **>(P); While here, also make all methods of AnnotatingParser except parseLine() private. Review URL: http://llvm-reviews.chandlerc.com/D384 llvm-svn: 174975
* Formatter: Detect ObjC message expressions after 'in' in loopNico Weber2013-02-113-6/+22
| | | | | | | | | | | | | | | | Before: for (id foo in[self getStuffFor : bla]) { } Now: for (id foo in [self getStuffFor:bla]) { } "in" is treated as loop keyword if the line starts with "for", and as a regular identifier else. To check for "in", its IdentifierInfo is handed through a few layers. llvm-svn: 174889
* Get rid of manual debug output, now that the test runner supports it.Manuel Klimek2013-02-112-6/+0
| | | | | | You can run tests with -debug instead now. llvm-svn: 174880
* Fix invalid formatting with spaces before trailing comments.Daniel Jasper2013-02-113-9/+11
| | | | | | | | In google style, trailing comments are separated by two spaces. This patch fixes the counting of these spaces and prevents clang-format from creating a line with 81 columns. llvm-svn: 174879
* Fixes handling of empty lines in macros.Manuel Klimek2013-02-112-4/+6
| | | | | | | | | | | | | | 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
* Fix formatting of overloaded operator definitions.Daniel Jasper2013-02-112-17/+13
| | | | | | | | | | | | Before: operatorvoid*(); operator vector< A< A>>(); After: operator void *(); operator vector<A<A> >(); llvm-svn: 174863
OpenPOWER on IntegriCloud