summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* Formatter/ObjC: In dictionary literals, break after ':', not before it.Nico Weber2013-05-262-5/+21
| | | | | | | | | | | | | | | | Before: @{ NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : regularFont, }; Now: @{ NSFontAttributeNameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee : regularFont, }; ':'s in dictionary literals (and the corresponding {}s) are now marked as TT_ObjCDictLiteral too, which makes further improvements to dict literal layout possible. llvm-svn: 182716
* Ignore contents of #if 0 blocks.Alexander Kornienko2013-05-242-1/+80
| | | | | | | | | | | | | | | | 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
* More tests and a fix for braced init lists.Daniel Jasper2013-05-231-2/+2
| | | | | | Before: f(new vector<int> { 1, 2, 3 }); After: f(new vector<int>{ 1, 2, 3 }); llvm-svn: 182614
* Fix aligning of comments.Manuel Klimek2013-05-231-4/+5
| | | | | | | | | | | | | | | | | Previously we started sequences to align for single line comments when the previous line had a trailing comment, but the sequence was broken for other reasons. Now we re-format: // a // b f(); // c to: // a // b f(); // c llvm-svn: 182608
* Fix aligning of comments that are at the start of the line.Manuel Klimek2013-05-231-3/+4
| | | | | | | | | | Now correctly leaves: f(); // comment // comment g(); // comment ... alone if the middle comment was aligned with g() before formatting. llvm-svn: 182605
* Increase test coverage for braced init lists.Daniel Jasper2013-05-231-1/+1
| | | | | | Also fix a minor bug for constructor initializers with braced init lists. llvm-svn: 182601
* Improve formatting of braced lists.Daniel Jasper2013-05-232-7/+5
| | | | | | Before: vector<int> v{ -1}; After: vector<int> v{-1}; llvm-svn: 182597
* Stop aligning trailing comments which are aligned with the next line.Manuel Klimek2013-05-231-1/+15
| | | | | | | | | | | | | | | | | | | | | | | Previously we would align: f(); // comment // other comment g(); Even if // other comment was at the start of the line. Now we do not align trailing comments if they have been already aligned correctly with the next line. Thus, f(); // comment // other comment g(); will not be changed, while: f(); // comment // other commment g(); will lead to the two trailing comments being aligned. llvm-svn: 182577
* Use a SourceRange for the whitespace location in FormatToken.Manuel Klimek2013-05-234-41/+47
| | | | | | | | | | | 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
* Improve formatting of braced lists.Daniel Jasper2013-05-232-0/+9
| | | | | | | | | | | | | Before: vector<int> x { 1, 2, 3 }; After: vector<int> x{ 1, 2, 3 }; Also add a style option to remove the spaces inside braced lists, so that the above becomes: std::vector<int> v{1, 2, 3}; llvm-svn: 182570
* Fix no-assert compiles.Manuel Klimek2013-05-231-1/+4
| | | | llvm-svn: 182569
* Expand parsing of braced init lists.Manuel Klimek2013-05-232-18/+164
| | | | | | | | | | | | | | | | 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
* Fix uninitialized access error found by valgrind.Manuel Klimek2013-05-221-0/+3
| | | | llvm-svn: 182476
* Makes whitespace management more consistent.Manuel Klimek2013-05-227-285/+408
| | | | | | | | | | | | | | | | | | | | | | | | | Instead of selectively storing some changes and directly generating replacements for others, we now notify the WhitespaceManager of the whitespace before every token (and optionally with more changes inside tokens). Then, we run over all whitespace in the very end in original source order, where we have all information available to correctly align comments and escaped newlines. The future direction is to pull more of the comment alignment implementation that is now in the BreakableToken into the WhitespaceManager. This fixes a bug when aligning comments or escaped newlines in unwrapped lines that are handled out of order: #define A \ f({ \ g(); \ }); ... now gets correctly layouted. llvm-svn: 182467
* Improve clang-format's stream formatting.Daniel Jasper2013-05-221-1/+1
| | | | | | | | | | | | | | | clang-format was a bit too aggressive when trying to keep labels and values on the same line. Before: llvm::outs() << "aaaaaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: llvm::outs() << "aaaaaaaaaaaaaaaaaaa: " << aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 182458
* Fix function declaration behavior.Daniel Jasper2013-05-221-1/+1
| | | | | | | | | | | | | | | | | | This only affects styles that prevent bin packing. There, a break after a template declaration also forced a line break after the function name. Before: template <class SomeType, class SomeOtherType> SomeType SomeFunction(SomeType Type, SomeOtherType OtherType) {} After: template <class SomeType, class SomeOtherType> SomeType SomeFunction(SomeType Type, SomeOtherType OtherType) {} This fixes llvm.org/PR16072. llvm-svn: 182457
* Improve handling of trailing 'const'.Daniel Jasper2013-05-221-4/+9
| | | | | | | Reduce the preference for breaking before a trailing 'const' according to review comments on r182362. llvm-svn: 182455
* Cut-off clang-format analysis.Daniel Jasper2013-05-223-29/+24
| | | | | | | | | | | | | | | | If clang-format is confronted with long and deeply nested lines (e.g. complex static initializers or function calls), it can currently try too hard to find the optimal solution and never finish. The reason is that the memoization does not work effectively for deeply nested lines. This patch removes an earlier workaround and instead opts for accepting a non-optimal solution in rare cases. However, it only does so only in cases where it would have to analyze an excessive number of states (currently set to 10000 - the most complex line in Format.cpp requires ~800 states) so this should not change the behavior in a relevant way. llvm-svn: 182449
* Allow breaking before a trailing const.Daniel Jasper2013-05-211-1/+1
| | | | | | | | | | | | | | Before: void someLongFunction( int someLongParameter) const; After: void someLongFunction(int someLongParameter) const; Also slightly cleanup tests. llvm-svn: 182362
* Minor fix: don't crash on empty configuration file, consider empty ↵Alexander Kornienko2013-05-201-0/+2
| | | | | | configuration files invalid. llvm-svn: 182290
* Clang-format: allow -style="{yaml/json}" on command lineAlexander Kornienko2013-05-191-13/+19
| | | | | | | | | | | | | | Summary: + improved handling of default style and predefined styles. Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D813 llvm-svn: 182205
* Slightly modify the formatting rules for braced lists.Daniel Jasper2013-05-171-2/+10
| | | | | | | | | | | | | Basically, the new rule is: The opening "{" always has to be on the same line as the first element if the braced list is nested (e.g. in another braced list or in a function). The solution that clang-format produces almost always adheres to this rule anyway and this makes clang-format significantly faster for larger lists. Added a test cases for the only exception I could find (which doesn't seem to be very important at first sight). llvm-svn: 182082
* Don't insert a break into include lines with trailing comments.Daniel Jasper2013-05-161-1/+2
| | | | llvm-svn: 182003
* Add option to put short loops on a single line.Daniel Jasper2013-05-161-9/+19
| | | | | | | | | | This enables things like: for (int &v : vec) v *= 2; Enabled for Google style. llvm-svn: 182000
* Add a more convenient interface to use clang-format.Daniel Jasper2013-05-161-0/+26
| | | | | | | | | | | | It turns out that several implementations go through the trouble of setting up a SourceManager and Lexer and abstracting this into a function makes usage easier. Also abstracts SourceManager-independent ranges out of tooling::Refactoring and provides a convenience function to create them from line ranges. llvm-svn: 181997
* Comments should not prevent single-line functions.Daniel Jasper2013-05-161-2/+2
| | | | | | | | | | | | | Before: void f() {} void g() { } // comment After: void f() {} void g() {} // comment llvm-svn: 181996
* Add back accidentally deleted line and add test for it.Daniel Jasper2013-05-161-0/+1
| | | | | | | | | | | Before: f("a", "b" "c"); After: f("a", "b" "c"); llvm-svn: 181980
* Don't put short namespace on a single line.Daniel Jasper2013-05-151-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | Before: namespace abc { class SomeClass; } namespace def { void someFunction() {} } After: namespace abc { class Def; } namespace def { void someFunction() {} } Rationale: a) Having anything other than forward declaration on the same line as a namespace looks confusing. b) Formatting namespace-forward-declaration-combinations different from other stuff is inconsistent. c) Wasting vertical space close to such forward declarations really does not affect readability. llvm-svn: 181887
* Improve recognition of template definitions.Daniel Jasper2013-05-151-2/+4
| | | | | | | | | | | | | | | | | | | | | In the long run, this will probably be better fixed by a proper expression parser.. Before: template <typename F> Matcher(const Matcher<F> & Other, typename enable_if_c < is_base_of<F, T>::value && !is_same<F, T>::value > ::type * = 0) : Implementation(new ImplicitCastMatcher<F>(Other)) {} After: template <typename F> Matcher(const Matcher<F> & Other, typename enable_if_c<is_base_of<F, T>::value && !is_same<F, T>::value>::type * = 0) : Implementation(new ImplicitCastMatcher<F>(Other)) {} llvm-svn: 181884
* Break function declarations after multi-line return types.Daniel Jasper2013-05-151-0/+7
| | | | | | | | | | | | | | | Before: template <typename A> SomeLoooooooooooooooooooooongType< typename some_namespace::SomeOtherType<A>::Type> Function() {} After: template <typename A> SomeLoooooooooooooooooooooongType< typename some_namespace::SomeOtherType<A>::Type> Function() {} llvm-svn: 181877
* Don't merge one-line functions in weird brace styles.Daniel Jasper2013-05-151-1/+2
| | | | llvm-svn: 181872
* Remove diagnostics from clang-format.Daniel Jasper2013-05-153-35/+10
| | | | | | | We only ever implemented one and that one is not actually all that helpful (e.g. gets incorrectly triggered by macros). llvm-svn: 181871
* Improve formatting of function types.Daniel Jasper2013-05-151-3/+4
| | | | | | | | | | | The function type detection in r181438 and r181764 detected function types too eagerly. This led to inconsistent formatting of inline assembly and (together with r181687) to an incorrect formatting of calls in macros. Before: #define DEREF_AND_CALL_F(parameter) f (*parameter) After: #define DEREF_AND_CALL_F(parameter) f(*parameter) llvm-svn: 181870
* Fix expression breaking for one-parameter-per-line styles.Daniel Jasper2013-05-141-1/+2
| | | | | | | | | | | | | | Before: if (aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} After: if (aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} llvm-svn: 181828
* Fix uninitialized value bug found by valgrind.Daniel Jasper2013-05-142-6/+5
| | | | llvm-svn: 181779
* Correctly determine ranges for clang-format.Daniel Jasper2013-05-141-2/+2
| | | | | | | | | | | We have been assuming that CharSourceRange::getTokenRange() by itself expands a range until the end of a token, but in fact it only sets IsTokenRange to true. Thus, we have so far only considered the first character of the last token to belong to an unwrapped line. This did not really manifest in symptoms as all edit integrations expand ranges to fully lines. llvm-svn: 181778
* Fix clang-format bug in unwrapped-line merging.Daniel Jasper2013-05-141-15/+13
| | | | | | | | | | | | | | | Before (in styles that allow it), clang-format would not merge an if statement onto a single line, if only the second line was format (e.g. in an editor integration): if (a) return; // clang-format invoked on this line. With this patch, this gets properly merged to: if (a) return; // ... llvm-svn: 181770
* Implement string literal breaking on unbreakable token sequences.Manuel Klimek2013-05-141-10/+31
| | | | | | | | | | | | This fixes indentation where there are for example multiple closing parentheses after a string literal, and where those parentheses run over the end of the line. During testing this revealed a bug in the implementation of breakProtrudingToken: we don't want to change the state if we didn't actually do anything. llvm-svn: 181767
* Don't format sizeof/alignof as function types.Daniel Jasper2013-05-141-1/+3
| | | | | | Before: A<sizeof (*x)> a; After: A<sizeof(*x)> a; llvm-svn: 181764
* Align a multiline string literal with the first part.Daniel Jasper2013-05-131-3/+3
| | | | | | | | | | | | | | Before: #define A(X) \ "aaaaa" #X "bbbbbb" \ "ccccc" After: #define A(X) \ "aaaaa" #X "bbbbbb" \ "ccccc" llvm-svn: 181732
* A better version of r181699: use raw_string_ostream.str() instead of ↵Alexander Kornienko2013-05-131-2/+1
| | | | | | manually calling .flush(). llvm-svn: 181702
* Fix style according to post-commit review comments.Manuel Klimek2013-05-131-2/+2
| | | | llvm-svn: 181701
* Implements brace breaking styles.Manuel Klimek2013-05-132-6/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We now support "Linux" and "Stroustrup" brace breaking styles, which gets us one step closer to support formatting WebKit, KDE & Linux code. Linux brace breaking style: namespace a { class A { void f() { if (x) { f(); } else { g(); } } } } Stroustrup brace breaking style: namespace a { class A { void f() { if (x) { f(); } else { g(); } } } } llvm-svn: 181700
* Fixes [Bug 15960] YAMLTraits doesn't roundtrip on Windows.Alexander Kornienko2013-05-131-0/+1
| | | | | | Thanks to Kim Gräsman for help! llvm-svn: 181699
* Implements UseTab for clang-format.Manuel Klimek2013-05-133-2/+15
| | | | | | This is required for kernel linux kernel style formatting. llvm-svn: 181693
* Further improve optimization for nested calls.Daniel Jasper2013-05-131-10/+22
| | | | | | | | Fake parentheses (i.e. emulated parentheses used to correctly handle binary expressions) used to prevent the optimization implemented in r180264. llvm-svn: 181692
* Implements IndentWidth.Manuel Klimek2013-05-131-3/+11
| | | | | | | This is required for various styles that are for example based on 8-indent. llvm-svn: 181690
* Assume macros to contain declarations.Daniel Jasper2013-05-131-0/+1
| | | | | | | | | This seems to be the vastly more common case. If we find enough examples to the contrary, we can make it smarter. Before: #define MACRO void f(int * a) After: #define MACRO void f(int *a) llvm-svn: 181687
* When breaking at function calls, indent from function name.Daniel Jasper2013-05-101-1/+4
| | | | | | | | | | | | | | | | Otherwise (when indenting from the wrapped -> or .), this looks like a confusing indent. Before: aaaaaaa // .aaaaaaa( // aaaaaaa); After: aaaaaaa // .aaaaaaa( // aaaaaaa); llvm-svn: 181595
* Always format entire macro definitions.Daniel Jasper2013-05-101-1/+21
| | | | | | | | Thereby, the macro is consistently formatted (including the trailing escaped newlines) even if clang-format is invoked only on single lines of the macro. llvm-svn: 181590
OpenPOWER on IntegriCloud