summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Fix infinite loop in macro special case.Daniel Jasper2013-08-281-6/+4
| | | | | | | | | | | | | | If escaped newlines are aligned right (FormatStyle.AlignEscapedNewlinesLeft == false), and a line contained too many characters to fit into the column limit, this would result in a (virtually) endless loop creating a negative number of spaces. Instead, allow the escaped newlines to be pushed past the column limit in this case. This fixes llvm.org/PR16515. llvm-svn: 189459
* clang-format: Don't insert space in __has_includeDaniel Jasper2013-08-281-1/+2
| | | | | | | | | | | | | | | | Before: #if __has_include( <strstream>) #include <strstream> #endif After: #if __has_include(<strstream>) #include <strstream> #endif This fixes llvm.org/PR16516. llvm-svn: 189455
* clang-format: Fix corner case in ObjC interface definitions.Daniel Jasper2013-08-281-1/+7
| | | | | | | | | | | | | | | In @implementation ObjcClass - (void)method; { } @end the ObjC compiler seems to accept the superfluous comma after "method", but clang-format used to assert on the subsequent "{". This fixes llvm.org/PR16604. llvm-svn: 189453
* clang-format: Improve braced init list detection:Daniel Jasper2013-08-281-1/+5
| | | | | | | | | | | | | | | | Before: std::this_thread::sleep_for(std::chrono::nanoseconds{ std::chrono::seconds { 1 } } / 5); After: std::this_thread::sleep_for( std::chrono::nanoseconds{ std::chrono::seconds{ 1 } } / 5); This fixes llvm.org/PR16554. llvm-svn: 189451
* clang-format: Fix corner case in overloaded operator definitions.Daniel Jasper2013-08-281-1/+4
| | | | | | | | | | | | | | | | | | Before: SomeLoooooooooooooooooooooooooogType operator> >(const SomeLooooooooooooooooooooooooogType &other); SomeLoooooooooooooooooooooooooogType // break operator>>(const SomeLooooooooooooooooooooooooogType &other); After: SomeLoooooooooooooooooooooooooogType operator>>(const SomeLooooooooooooooooooooooooogType &other); SomeLoooooooooooooooooooooooooogType // break operator>>(const SomeLooooooooooooooooooooooooogType &other); This fixes llvm.org/PR16328. llvm-svn: 189450
* clang-format: Fix space in decltype-constexprs.Daniel Jasper2013-08-281-1/+2
| | | | | | | | | | Before: static constexpr bool Bar = decltype(bar()) ::value; After: static constexpr bool Bar = decltype(bar())::value; llvm-svn: 189449
* clang-format: Format segments of builder-type calls one per line.Daniel Jasper2013-08-274-12/+35
| | | | | | | | | | | | | | | | | | | | | | This fixes llvm.org/PR14818. Before: return llvm::StringSwitch<Reference::Kind>(name) .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR) .StartsWith(".eh_frame", ORDER_EH_FRAME) .StartsWith(".init", ORDER_INIT).StartsWith(".fini", ORDER_FINI) .StartsWith(".hash", ORDER_HASH).Default(ORDER_TEXT); After: return llvm::StringSwitch<Reference::Kind>(name) .StartsWith(".eh_frame_hdr", ORDER_EH_FRAMEHDR) .StartsWith(".eh_frame", ORDER_EH_FRAME) .StartsWith(".init", ORDER_INIT) .StartsWith(".fini", ORDER_FINI) .StartsWith(".hash", ORDER_HASH) .Default(ORDER_TEXT); llvm-svn: 189353
* clang-format: Revamp builder-type call formatting.Daniel Jasper2013-08-273-54/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously builder-type calls were only correctly recognized in top-level calls. This fixes llvm.org/PR16981. Before: someobj->Add((new util::filetools::Handler(dir))->OnEvent1( NewPermanentCallback(this, &HandlerHolderClass::EventHandlerCBA)) ->OnEvent2(NewPermanentCallback( this, &HandlerHolderClass::EventHandlerCBB)) ->OnEvent3(NewPermanentCallback( this, &HandlerHolderClass::EventHandlerCBC)) ->OnEvent5(NewPermanentCallback( this, &HandlerHolderClass::EventHandlerCBD)) ->OnEvent6(NewPermanentCallback( this, &HandlerHolderClass::EventHandlerCBE))); After: someobj->Add((new util::filetools::Handler(dir)) ->OnEvent1(NewPermanentCallback( this, &HandlerHolderClass::EventHandlerCBA)) ->OnEvent2(NewPermanentCallback( this, &HandlerHolderClass::EventHandlerCBB)) ->OnEvent3(NewPermanentCallback( this, &HandlerHolderClass::EventHandlerCBC)) ->OnEvent5(NewPermanentCallback( this, &HandlerHolderClass::EventHandlerCBD)) ->OnEvent6(NewPermanentCallback( this, &HandlerHolderClass::EventHandlerCBE))); llvm-svn: 189337
* clang-format: Fix bug in column layout.Daniel Jasper2013-08-271-2/+6
| | | | | | | | | | | | Before (with 60 character limit in Google style): return { {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}}; After: return {{aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}}; llvm-svn: 189327
* clang-format: Fix bug in column-layout formatting.Daniel Jasper2013-08-261-8/+8
| | | | | | | | | | Specific arrangements of comments after trailing commas could confuse the column width calculation, e.g. in: vector<int> x = { a, b, /* some */ /* comment */ }; llvm-svn: 189211
* clang-format: Fix indentation relative to unary expressions.Daniel Jasper2013-08-231-15/+56
| | | | | | | | | | | | | | | | | | | This should be done, only if we are still in the unary expression's scope. Before: bool aaaa = !aaaaaaaa( // break aaaaaaaaaaa); *aaaaaa = aaaaaaa( // break aaaaaaaaaaaaaaaa); After: bool aaaa = !aaaaaaaa( // break aaaaaaaaaaa); // <- (unchanged) *aaaaaa = aaaaaaa( // break aaaaaaaaaaaaaaaa); // <- (no longer indented relative to "*") llvm-svn: 189108
* clang-format: Fix corner case for string splitting ..Daniel Jasper2013-08-232-12/+25
| | | | | | | | .. in conjunction with Style.AlwaysBreakBeforeMultilineStrings. Also, simplify the implementation by handling newly split strings and already split strings by the same code. llvm-svn: 189102
* clang-format: Handle trailing commas in column layout of braced list.Daniel Jasper2013-08-232-0/+8
| | | | | | | | | | Before, this was causing errors. Also exit early in breakProtrudingToken() (before the expensive call to SourceManager::getSpellingColumnNumber()). This makes formatting huge (100k+-item) braced lists possible. llvm-svn: 189094
* Work around unused variable warning in release builds.Daniel Jasper2013-08-221-0/+1
| | | | llvm-svn: 189028
* clang-format: Add column layout formatting for braced listsDaniel Jasper2013-08-227-23/+315
| | | | | | | | | | | | | | | | | | | | With this patch, braced lists (with more than 3 elements are formatted in a column layout if possible). E.g.: static const uint16_t CallerSavedRegs64Bit[] = { X86::RAX, X86::RDX, X86::RCX, X86::RSI, X86::RDI, X86::R8, X86::R9, X86::R10, X86::R11, 0 }; Required other changes: - FormatTokens can now have a special role that contains extra data and can do special formattings. A comma separated list is currently the only implementation. - Move penalty calculation entirely into ContinuationIndenter (there was a last piece still in UnwrappedLineFormatter). Review: http://llvm-reviews.chandlerc.com/D1457 llvm-svn: 189018
* clang-format: Indent relative to unary operators.Daniel Jasper2013-08-213-12/+13
| | | | | | | | | | | | | | | | Before: if (!aaaaaaaaaa( // break aaaaa)) { } After: if (!aaaaaaaaaa( // break aaaaa)) { } Also cleaned up formatting using clang-format. llvm-svn: 188891
* clang-format: Format enum struct/class like enum.Daniel Jasper2013-08-201-0/+4
| | | | | | Patch by Joe Hermaszewski. Thank you! llvm-svn: 188794
* clang-format: Additional options for spaces around parentheses.Daniel Jasper2013-08-202-6/+28
| | | | | | | | | | | | This patch adds four new options to control: - Spaces after control keyworks (if(..) vs if (..)) - Spaces in empty parentheses (f( ) vs f()) - Spaces in c-style casts (( int )1.0 vs (int)1.0) - Spaces in other parentheses (f(a) vs f( a )) Patch by Joe Hermaszewski. Thank you for working on this! llvm-svn: 188793
* clang-format: Fix return type line break decision.Daniel Jasper2013-08-191-4/+7
| | | | | | | | | | | | | | | | | This accidentally introduced by r186077, as function names were not correctly recognized in templated declarations. Before: template <class TemplateIt> SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end, TemplateIt* stop) {} After: template <class TemplateIt> SomeReturnType SomeFunction(TemplateIt begin, TemplateIt end, TemplateIt* stop) {} llvm-svn: 188665
* Split UnwrappedLineFormatter into individual components.Daniel Jasper2013-08-164-901/+1004
| | | | | | | | | Goals: Structure code better and make components easier to use for future features (e.g. column layout for long braced initializers). No functional changes intended. llvm-svn: 188543
* clang-format: Add option for the offset of constructor initializers.Daniel Jasper2013-08-131-2/+11
| | | | | | | | | | | | Some coding styles use a different indent for constructor initializers. Patch by Klemens Baum. Thank you. Review: http://llvm-reviews.chandlerc.com/D1360 Post review changes: Changed data type to unsigned as a negative indent width does not make sense and added test for configuration parsing. llvm-svn: 188260
* clang-format: Improve boolean expression formatting in macros.Daniel Jasper2013-08-131-1/+2
| | | | | | | | | | Before: #define IF(a, b, c) if (a&&(b == c)) After: #define IF(a, b, c) if (a && (b == c)) llvm-svn: 188256
* clang-format: Slightly adapt line break penalties.Daniel Jasper2013-08-131-1/+1
| | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa) ->aaaaaaaaa()); After: aaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa)->aaaaaaaaa()); llvm-svn: 188253
* clang-format: Improve stream-formatting.Daniel Jasper2013-08-121-4/+6
| | | | | | | | | | | | | Before: CHECK(controller->WriteProto(FLAGS_row_key, FLAGS_proto)) << "\"" << FLAGS_proto << "\""; After: SemaRef.Diag(Loc, diag::note_for_range_begin_end) << BEF << IsTemplate << Description << E->getType(); llvm-svn: 188175
* clang-format: Correctly format alias declarations.Daniel Jasper2013-08-122-7/+8
| | | | | | | | | | | | | | Before: template <class CallbackClass> using MyCallback = void(CallbackClass::*)(SomeObject * Data);"); After: template <class CallbackClass> using MyCallback = void (CallbackClass::*)(SomeObject *Data);"); Also fix three wrong indentations. llvm-svn: 188172
* This change fixes the formatting of statements such as catch (E& e).Manuel Klimek2013-08-121-1/+2
| | | | | | | | | Previously these were formatting as catch (E & e) because the inner parenthesis was being marked as an expression. Patch by Thomas Gibson-Robinson. llvm-svn: 188153
* Revert r187935 "Support for double width characters."Arnold Schwaighofer2013-08-081-20/+9
| | | | | | It broke a public build bot. llvm-svn: 187957
* Support for double width characters.Alexander Kornienko2013-08-071-9/+20
| | | | | | | | | | | | | | Summary: Only works for UTF-8-encoded files. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1311 llvm-svn: 187935
* Fixes a couple of bugs with the Allman brace breaking.Manuel Klimek2013-08-072-0/+5
| | | | | | | | | | | In particular, left braces after an enum declaration now occur on their own line. Further, when short ifs/whiles are allowed these no longer cause the left brace to be on the same line as the if/while when a brace is included. Patch by Thomas Gibson-Robinson. llvm-svn: 187901
* clang-format: Fix corner case in OpenMP pragma formatting.Daniel Jasper2013-08-071-1/+2
| | | | | | | | | Before: #pragma omp reduction( | : var) After: #pragma omp reduction(| : var) llvm-svn: 187892
* clang-format: Improve formatting of builder-type calls.Daniel Jasper2013-08-071-2/+0
| | | | | | | | | | | This removes a formatting choice that was added at one point, but is not generally liked by users. Specifically, in builder-type calls, do (easily) break if the object before the ./-> is either a field or a parameter-less function call. I.e., don't break after "aa.aa.aa" or "aa.aa.aa()". In general, these sequences in builder-type calls are seen as a single entity and thus breaking them up is a bad idea. llvm-svn: 187865
* Implement Allman style.Manuel Klimek2013-08-022-6/+29
| | | | | | Patch by Frank Miller. llvm-svn: 187678
* clang-format: Fix string breaking after "<<".Daniel Jasper2013-08-021-1/+1
| | | | | | | | Before, clang-format would not break overly long string literals following a "<<" with FormatStyle::AlwaysBreakBeforeMultilineStrings being set. llvm-svn: 187650
* clang-format: Operator precendence in ObjC method exprs.Daniel Jasper2013-08-011-0/+5
| | | | | | | | | | | | | | | | | | | | Patch (mostly) by Adam Strzelecki. Thanks! Before: [self aaaaaa:bbbbbbbbbbbbb aaaaaaaaaa:bbbbbbbbbbbbbbbbb aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb aaaa:bbb]; After: [self aaaaaa:bbbbbbbbbbbbb aaaaaaaaaa:bbbbbbbbbbbbbbbbb aaaaa:bbbbbbbbbbb + bbbbbbbbbbbb aaaa:bbb]; This fixes llvm.org/PR16150. llvm-svn: 187631
* clang-format: Don't break empty 2nd operand of ternary expr.Daniel Jasper2013-08-012-4/+8
| | | | | | | | | | | | | | | | Before: some_quite_long_variable_name_ptr ? : argv[9] ? ptr : argv[8] ? : argv[7] ? ptr : argv[6]; After: some_quite_long_variable_name_ptr ?: argv[9] ? ptr : argv[8] ?: argv[7] ? ptr : argv[6]; Patch by Adam Strzelecki, thank you!! This fixed llvm.org/PR16758. llvm-svn: 187622
* Teach clang-format to understand static_asserts better.Daniel Jasper2013-08-012-1/+4
| | | | | | | | | | | | | | | | | | | Before: template <bool B, bool C> class A { static_assert(B &&C, "Something is wrong"); }; After: template <bool B, bool C> class A { static_assert(B && C, "Something is wrong"); }; (Note the spacing around '&&'). Also change the identifier table to always understand all C++11 keywords (which seems like the right thing to do). llvm-svn: 187589
* clang-format: Improve line breaks in @property.Daniel Jasper2013-08-011-1/+3
| | | | | | | | | | | | Before: @property(nonatomic, assign, readonly) NSString *looooooooooooooooooooooooooooongName; After: @property(nonatomic, assign, readonly) NSString *looooooooooooooooooooooooooooongName; llvm-svn: 187577
* clang-format: Make alignment of trailing comments optional ..Daniel Jasper2013-07-312-3/+7
| | | | | | .. in order to support WebKit style properly. llvm-svn: 187549
* clang-format: Add more options to namespace indentation.Daniel Jasper2013-07-313-9/+29
| | | | | | | | | | | | | With this patch, clang-format can be configured to: * not indent in namespace at all (former behavior). * indent in namespace as in other blocks. * indent only in inner namespaces (as required by WebKit style). Also fix alignment of access specifiers in WebKit style. Patch started by Marek Kurdej. Thank you! llvm-svn: 187540
* clang-format: Improve detection of templates.Daniel Jasper2013-07-301-1/+1
| | | | | | | | | | | Before: template <typename... Types> typename enable_if < 0<sizeof...(Types)>::type Foo() {} After: template <typename... Types> typename enable_if<0 < sizeof...(Types)>::type Foo() {} llvm-svn: 187458
* clang-format: Add two new style options to support WebKit style.Daniel Jasper2013-07-263-41/+82
| | | | | | | | | | | | | New options: * Break before the commas of constructor initializers and align the commas with the colon. * Break before binary operators Additionally, for styles without column limit, don't just accept linebreaks done by the user, but instead remove 'invalid' (according to the current style) linebreaks and add 'required' ones. llvm-svn: 187210
* clang-format: Fix switch/case interaction with macros.Daniel Jasper2013-07-251-5/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: #define OPERATION_CASE(name) \ case OP_name: \ return operations::Operation##name switch (OpCode) { CASE(Add); CASE(Subtract); default: return operations::Unknown; } After: #define OPERATION_CASE(name) \ case OP_name: \ return operations::Operation##name; switch (OpCode) { CASE(Add); CASE(Subtract); default: return operations::Unknown; } llvm-svn: 187118
* clang-format: Initial (incomplete) support for the WebKit coding style.Daniel Jasper2013-07-241-0/+28
| | | | | | | | | | | This is far from implementing all the rules given by http://www.webkit.org/coding/coding-style.html The important new feature is the support for styles that don't have a column limit. For such styles, clang-format will (at the moment) simply respect the input's formatting decisions within statements. llvm-svn: 187033
* clang-format: Fix bad line break with pointers to members.Daniel Jasper2013-07-181-1/+1
| | | | | | | | | | | | | | | | | | | Before: void f() { (a->* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)(aaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); } After: void f() { (a->*aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)( aaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb); } Also add missing test case. llvm-svn: 186583
* clang-format: Add space in corner case.Daniel Jasper2013-07-171-0/+4
| | | | | | | | | Before: SomeType s __attribute__((unused))(InitValue); After: SomeType s __attribute__((unused)) (InitValue); llvm-svn: 186535
* Improve line breaking before multi-line strings.Daniel Jasper2013-07-172-9/+11
| | | | | | | | | | | | | | | | The AlwaysBreakBeforeMultilineStrings rule does not really make sense if it does not a column gain. Before (in Google style): f( "aaaa" "bbbb"); After: f("aaaa" "bbbb"); llvm-svn: 186515
* Avoid breaking non-trailing block comments.Alexander Kornienko2013-07-161-1/+1
| | | | | | | | | | | | | | | | Motivating example: // column limit -------------------> void ffffffffffff(int aaaaaa /* test */); Formatting before the patch: void ffffffffffff(int aaaaaa /* test */); Formatting after the patch: void ffffffffffff(int aaaaaa /* test */); llvm-svn: 186471
* Don't break line comments with escaped newlines.Alexander Kornienko2013-07-162-2/+25
| | | | | | | | | | | | | | | | | | | | Summary: These can appear when comments contain command lines with quoted line breaks. As the text (including escaped newlines and '//' from consecutive lines) is a single line comment, we used to break it even when it didn't exceed column limit. This is a temporary solution, in the future we may want to support this case completely - at least adjust leading whitespace when changing indentation of the first line. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1146 llvm-svn: 186456
* clang-format: Improve handling of unterminated string literals.Daniel Jasper2013-07-163-29/+44
| | | | | | | Before, clang-format would simply eat these as they were recognized as whitespace. With this patch, they are mostly left alone. llvm-svn: 186454
* Revamp the formatting of C++11 braced init lists.Daniel Jasper2013-07-162-7/+9
| | | | | | | | | | | | | | The fundamental concept is: Format as if the braced init list was a function call (with parentheses replaced by braces). If there is no name/type before the opening brace (e.g. if the braced list is nested), assume a zero-length identifier just before the opening brace. This behavior is gated on a new style flag, which for now replaces the SpacesInBracedLists style flag. Activate this style flag for Google style to reflect recent style guide changes. llvm-svn: 186433
OpenPOWER on IntegriCloud