summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Fix various problems in formatting ObjC blocks.Daniel Jasper2013-12-231-0/+43
| | | | | | Among other things, this fixes llvm.org/PR15269. llvm-svn: 197900
* clang-format: Better support for multi-line wide string literals.Daniel Jasper2013-12-201-0/+11
| | | | | | | | | | | Before: SomeFunction(L"A" L"B"); After: SomeFunction(L"A" L"B"); llvm-svn: 197785
* clang-format: Add special case for leading comments in braced lists.Daniel Jasper2013-12-191-8/+36
| | | | | | | | | | | | | | | | | | | A comment following the "{" of a braced list seems to almost always refer to the first element of the list and thus should be aligned to it. Before (with Cpp11 braced list style): SomeFunction({ // Comment 1 "first entry", // Comment 2 "second entry"}); After: SomeFunction({// Comment 1 "first entry", // Comment 2 "second entry"}); llvm-svn: 197725
* clang-format: Increase penalty for breaking comments.Daniel Jasper2013-12-191-9/+9
| | | | | | | | | | | | | Unexpectedly, it seems that people commonly know what they were doing when writing a comment. Also, being more conservative about comment breaking has the advantage of giving more flexibility. If a linebreak within the comment can improve formatting, the author can add it (after which clang-format won't undo it). There is no way to override clang-format's behavior if it breaks a comment. llvm-svn: 197698
* clang-format: Slightly adapt decision of when to break before <<.Daniel Jasper2013-12-191-0/+2
| | | | | | | | | | | | Before: Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa) << aaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaa); After: Diag(aaaaaaaaaaaaaaaaaaaa, aaaaaaaa) << aaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaa); llvm-svn: 197690
* clang-format: Fix indentation corner case.Daniel Jasper2013-12-181-0/+6
| | | | | | | | | | | | | | | | | | | | | | Before: aaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); aaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(); After: aaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); aaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(); Probably still not ideal, but should be a step into the right direction. llvm-svn: 197557
* clang-format: Fix ObjC method expr in binary expressions.Daniel Jasper2013-12-181-0/+2
| | | | | | | | | | | | | | Before: bool a = ([aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaa || [aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaaaaa); After: bool a = ([aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaa || [aaaaaaaa aaaaa] == aaaaaaaaaaaaaaaaaaaa); This fixes llvm.org/PR18271. llvm-svn: 197552
* clang-format: Don't adapt local format to macros.Daniel Jasper2013-12-171-1/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Formatting this: void f() { // 1 space initial indent. int i; #define A \ int i; \ int j; int k; // Format this line. } void f() { #define A 1 // Format this line. } Before: void f() { // 1 space initial indent. int i; #define A \ int i; \ int j; int k; // Format this line. } void f() { #define A 1 // Format this line. } After: void f() { // 1 space initial indent. int i; #define A \ int i; \ int j; int k; // Format this line. } void f() { #define A 1 // Format this line. } llvm-svn: 197494
* clang-format: Keep trailing annotations together.Daniel Jasper2013-12-161-0/+5
| | | | | | | | | | | | | | | | Before: virtual void aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa, aaaaaaaaaaa aaaaa) const override; virtual void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() const override; After: virtual void aaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaa aaaa, aaaaaaaaaaa aaaaa) const override; virtual void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() const override; llvm-svn: 197391
* Always break before the colon in constructor initializers, whenAlexander Kornienko2013-12-161-12/+56
| | | | | | | | | | | BreakConstructorInitializersBeforeComma is true. This option is used in WebKit style, so this also ensures initializer lists are not put on a single line, as per the WebKit coding guidelines. Patch by Florian Sowade! llvm-svn: 197386
* clang-format: Fix formatting of function type parameters.Daniel Jasper2013-12-161-0/+1
| | | | | | | | | Before: void f() { typedef void (*f)(int * a); } After: void f() { typedef void (*f)(int *a); } llvm-svn: 197369
* clang-format: Improve handling of raw string literals.Daniel Jasper2013-12-161-1/+11
| | | | | | | | | | | | | | | | Especially try to keep existing line breaks before raw string literals, as the code author might have aligned content to it. Thereby, clang-format now keeps things like: parseStyle(R"( BasedOnStyle: Google, ColumnLimit: 100)"); parseStyle( R"(BasedOnStyle: Google, ColumnLimit: 100)"); llvm-svn: 197368
* Implemented GNU-style formatting for compound statements.Alexander Kornienko2013-12-121-0/+88
| | | | | | | | | | | | | | | | Summary: Added BraceBreakingStyle::BS_GNU. I'm not sure about the correctness of static initializer formatting, but compound statements should be fine. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2372 llvm-svn: 197138
* Early attempts to format in GNU style.Alexander Kornienko2013-12-101-0/+5
| | | | | | | | | | | | | | | | Summary: This still misses a few important features, so there's no mention of this style in the help message, but a few style rules are implemented. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2371 llvm-svn: 196928
* [CMake] Update target_link_libraries() and LLVM_LINK_COMPONENTS for each ↵NAKAMURA Takumi2013-12-101-7/+1
| | | | | | CMakeLists.txt. llvm-svn: 196916
* Allow predefined styles to define different options for different languages.Alexander Kornienko2013-12-102-39/+100
| | | | | | | | | | | | | | | | | | | | | | | Summary: Allow predefined styles to define different options for different languages so that one can run: clang-format -style=google file1.cpp file2.js or use a single .clang-format file with "BasedOnStyle: Google" for both c++ and JS files. Added Google style for JavaScript with "BreakBeforeTernaryOperators" set to false. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2364 llvm-svn: 196909
* Support GNU style rule to put a space before opening parenthesis.Alexander Kornienko2013-12-101-4/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The rule from the GNU style states: "We find it easier to read a program when it has spaces before the open-parentheses and after the commas." http://www.gnu.org/prep/standards/standards.html#index-spaces-before-open_002dparen This patch makes clang-format adds an option to put spaces before almost all open parentheses, except the cases, where different behavior is dictated by the style rules or language syntax: * preprocessor: ** function-like macro definitions can't have a space between the macro name and the parenthesis; ** `#if defined(...)` can have a space, but it seems, that it's more frequently used without a space in GCC, for example; * never add spaces after unary operators; * adding spaces between two opening parentheses is controlled with the `SpacesInParentheses` option; * never add spaces between `[` and `(` (there's no option yet). Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2326 llvm-svn: 196901
* clang-format: Be more conservative about braced list column layout.Daniel Jasper2013-12-091-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically disable it for nested braced lists as it commonly can look really weird. Eventually, we'll want to become smarter and format some of the nested lists better. Before: SomeStruct my_struct_array = { { aaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaa, aaaaaaa, aaa }, { aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa }, { aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa }, }; After: SomeStruct my_struct_array = { { aaaaaa, aaaaaaaa, aaaaaaaaaa, aaaaaaaaa, aaaaaaaaa, aaaaaaaaaa, aaaaaaaaaaaa, aaaaaaa, aaa }, { aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaaa, aaa }, { aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, a, aaaaaaaaaa, aaaaaaaaa, aaa }, }; llvm-svn: 196783
* clang-format: Change line break decisions for array subscripts.Daniel Jasper2013-12-061-0/+3
| | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<int> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [aaaaaaaaaaaa]; After: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<int> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaa]; llvm-svn: 196582
* Fix a tranche of comment, test and doc typosAlp Toker2013-12-051-2/+2
| | | | llvm-svn: 196510
* Added a regression test for the change in r196380Alexander Kornienko2013-12-041-0/+8
| | | | llvm-svn: 196384
* Leave constructor initializer lists on one line in styles with no column limit.Alexander Kornienko2013-12-041-6/+34
| | | | | | | | | | | | | | | | | Summary: Allow tryFitMultipleLinesInOne join unwrapped lines when ContinuationIndenter::mustBreak doesn't agree. But don't merge any lines, that are separate in the input. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2321 llvm-svn: 196378
* Create a separate file for JS-specific unit tests.Alexander Kornienko2013-12-034-82/+164
| | | | | | | | | | | | Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2307 llvm-svn: 196266
* clang-format: Fix excessive formatting caused by r195954.Daniel Jasper2013-12-021-0/+7
| | | | | | | Due to a bug in the patch, clang-format would more or less simply format all multi-line comments. llvm-svn: 196080
* Added LanguageStandard::LS_JavaScript to gate all JS-specific parsing.Alexander Kornienko2013-11-291-11/+132
| | | | | | | | | | | | | | | | Summary: Use LS_JavaScript for files ending with ".js". Added support for ">>>=" operator. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2242 llvm-svn: 195961
* clang-format: Extends formatted ranges to subsequent lines comments.Daniel Jasper2013-11-291-5/+35
| | | | | | | | | | | | | | | | Before: int aaaa; // This line is formatted. // The comment continues .. // .. here. Before: int aaaa; // This line is formatted. // The comment continues .. // .. here. This fixes llvm.org/PR17914. llvm-svn: 195954
* clang-format: Correctly handle Qt's Q_SLOTS.Daniel Jasper2013-11-291-0/+2
| | | | | | This should fix llvm.org/PR17241. Maybe it sticks this time :-). llvm-svn: 195953
* clang-format: Fix bad indentation of nested blocks.Daniel Jasper2013-11-291-0/+17
| | | | | | | | | | | | | | | Before: DEBUG( // { f(); }); After: DEBUG( // { f(); }); Also add additional test to selected formatting of individual statements in nested blocks. llvm-svn: 195952
* clang-format: Improve selective formatting of nested statements.Daniel Jasper2013-11-281-10/+48
| | | | | | | | | | Previously, clang-format could create quite corrupt formattings if individual lines of nested blocks (e.g. in "DEBUG({})" or lambdas) were used. With this patch, it tries to extend the formatted regions to leave around some reasonable format without always formatting the entire surrounding statement. llvm-svn: 195925
* Changed non-printable characters in the test to the escaped form. ↵Alexander Kornienko2013-11-261-6/+6
| | | | | | Apparently, not all tools display non-printable characters ;) llvm-svn: 195761
* Fix crash in getStringSplit.Alexander Kornienko2013-11-261-0/+12
| | | | | | | | | | | | | | | | Summary: getStringSplit used to crash, when trying to split a long string literal containing both printable and unprintable multi-byte UTF-8 characters. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2268 llvm-svn: 195728
* clang-format: Refactor calculation of lines intersecting with -lines.Daniel Jasper2013-11-251-2/+2
| | | | | | | | No functional changes intended. However, it seems to have found a buggy behavior in one of the tests. I think this structure is generally desirable and it will make a planned bugfix significantly easier. llvm-svn: 195634
* clang-format: Support Qt's slot access specifiers.Daniel Jasper2013-11-231-0/+4
| | | | | | This fixes llvm.org/PR17241. llvm-svn: 195555
* clang-format: Fix incorrect space in parameters named by comment.Daniel Jasper2013-11-231-0/+1
| | | | | | | | | | | | This fixes llvm.org/PR17979. Before: void f() { g(/*aaa=*/x, /*bbb=*/ !y); } After: void f() { g(/*aaa=*/x, /*bbb=*/!y); } llvm-svn: 195553
* clang-format: The "<" of a template argument is not a binary operator.Daniel Jasper2013-11-231-0/+4
| | | | | | | | | | | | | | | With Style.BreakBeforeBinaryOperators, clang-format breaks incorrectly. This fixes llvm.org/PR17994. Before: return boost::fusion::at_c<0>(iiii).second == boost::fusion::at_c <1>(iiii).second; After: return boost::fusion::at_c<0>(iiii).second == boost::fusion::at_c<1>(iiii).second; llvm-svn: 195552
* clang-format: Fix bug in ObjC method declaration formatting.Daniel Jasper2013-11-231-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Also disallow breaking between "@" and "{" or "[". Before: - (NSAttributedString *)attributedStringForSegment:(NSUInteger)segment index:(NSUInteger)index attributes:(NSDictionary *)attributes nonDigitAttributes:(NSDictionary *) nonDigitAttributes; [mailComposeViewController setToRecipients:@ [ NSBundle.mainBundle.infoDictionary[@"ABBFeedbackEmail"] ]]; After: - (NSAttributedString *)attributedStringForSegment:(NSUInteger)segment index:(NSUInteger)index attributes:(NSDictionary *)attributes nonDigitAttributes: (NSDictionary *)nonDigitAttributes; [mailComposeViewController setToRecipients: @[ NSBundle.mainBundle.infoDictionary[@"ABBFeedbackEmail"] ]]; This fixes llvm.org/PR18030. llvm-svn: 195550
* clang-format: Prefer column layout if possible.Daniel Jasper2013-11-231-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | Add a severe penalty for not using column layout for braced lists. If there are solutions with column layout, these are generally preferable over bin-packed solutions. Before: std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{ aaaaaaa, aaaaaaaaaa, aaaaa, aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a, aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa, aaaaaaa, a }; After: std::vector<MyValues> aaaaaaaaaaaaaaaaaaa{ aaaaaaa, aaaaaaaaaa, aaaaa, aaaaaaaaaaaaaaa, aaa, aaaaaaaaaa, a, aaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaa, aaaaaaa, a }; llvm-svn: 195546
* clang-format: Fix bug in alignment of complex template parameters.Daniel Jasper2013-11-221-0/+4
| | | | | | | | | | | | | | | Before: template <typename aaaaaaaaaaa, typename bbbbbbbbbbbbb, template <typename> class cccccccccccccccccccccc, typename ddddddddddddd> class C {}; After: template <typename aaaaaaaaaaa, typename bbbbbbbbbbbbb, template <typename> class cccccccccccccccccccccc, typename ddddddddddddd> class C {}; llvm-svn: 195418
* clang-format: Recognize braced lists with trailing function call.Daniel Jasper2013-11-221-0/+2
| | | | | | | | | | | Before: int count = set<int> { f(), g(), h() } .size(); After: int count = set<int>{f(), g(), h()}.size(); llvm-svn: 195417
* Better implementation of JavaScript === and !== operators.Alexander Kornienko2013-11-211-3/+10
| | | | | | | | | | | | | | | | Summary: Now based on token merging. Now they are not only prevented from being split, but are actually formatted as comparison operators. Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2240 llvm-svn: 195354
* clang-format: Improve formatting of ObjC method expressions.Daniel Jasper2013-11-211-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In particular, make breaking after a parameter's ":" more of a last resort choice as it significantly affects the readability gained by aligning the parameters. Before (in Chromium style - which doesn't allow bin-packing): { popup_window_.reset([[RenderWidgetPopupWindow alloc] initWithContentRect: NSMakeRect( origin_global.x, origin_global.y, pos.width(), pos.height()) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]); } After: { popup_window_.reset([[RenderWidgetPopupWindow alloc] initWithContentRect:NSMakeRect(origin_global.x, origin_global.y, pos.width(), pos.height()) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]); } llvm-svn: 195301
* Added an option to allow short function bodies be placed on a single line.Alexander Kornienko2013-11-201-13/+19
| | | | | | | | | | | | | | | | | | | Summary: The AllowShortFunctionsOnASingleLine option now controls short function body placement on a single line independent of the BreakBeforeBraces option. Updated tests using BreakBeforeBraces other than BS_Attach. Addresses http://llvm.org/PR17888 Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2230 llvm-svn: 195256
* Support for JavaScript === and !== operators.Alexander Kornienko2013-11-201-0/+8
| | | | | | | | | | | | Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2231 llvm-svn: 195251
* Fix bug where optimization would lead to strange line breaks.Manuel Klimek2013-11-201-0/+5
| | | | | | | | | | | | | | | | | Before: void f() { CHECK_EQ(aaaa, ( *bbbbbbbbb)->cccccc) << "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"; } After: void f() { CHECK_EQ(aaaa, (*bbbbbbbbb)->cccccc) << "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"; } llvm-svn: 195240
* Correctly mark first token in the presence of UTF-8 BOM.Alexander Kornienko2013-11-131-0/+8
| | | | | | | | | | | | | | Summary: Fixes http://llvm.org/PR17753 Reviewers: klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2159 llvm-svn: 194576
* Remove extra whitespace instead of breaking the line in comments when possible.Alexander Kornienko2013-11-121-0/+16
| | | | | | | | | | | | | | Summary: Solves the problem described in http://llvm.org/PR17756 Reviewers: klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2131 llvm-svn: 194493
* Do not insert backslashes, when breaking line comments after preprocessor ↵Alexander Kornienko2013-11-121-0/+8
| | | | | | | | | | | | | | | | directives. Summary: This solves http://llvm.org/PR17536 Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2142 llvm-svn: 194491
* clang-format: Fix alignment of ObjC string literals.Daniel Jasper2013-11-091-0/+7
| | | | | | | | This used to interfere with AlwaysBreakBeforeMultilineStrings. This fixes llvm.org/PR17856. llvm-svn: 194310
* clang-format: Improve clang-format's detection about comment binding.Daniel Jasper2013-11-081-0/+20
| | | | | | | | | | | | | | | | | | Before, existing code in the form of: int a; // this is a. // This is // b. int b; Got turned into: int a; // this is a. // This is // b. int b; llvm-svn: 194294
* clang-format: Improve formatting of operators forced to new lines.Daniel Jasper2013-11-081-0/+8
| | | | | | | | | | | | | | | | | | | | | | | Before: unsigned ContentSize = sizeof(int16_t) // DWARF ARange version number + sizeof(int32_t) // Offset of CU in the .debug_info section + sizeof(int8_t) // Pointer Size (in bytes) + sizeof(int8_t); // Segment Size (in bytes) After: unsigned ContentSize = sizeof(int16_t) // DWARF ARange version number + sizeof(int32_t) // Offset of CU in the .debug_info section + sizeof(int8_t) // Pointer Size (in bytes) + sizeof(int8_t); // Segment Size (in bytes) This fixes llvm.org/PR17687. llvm-svn: 194276
OpenPOWER on IntegriCloud