summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: Improve handling of raw string literals.Daniel Jasper2013-12-163-4/+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-124-25/+52
| | | | | | | | | | | | | | | | 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
* Remove IndentBlocks, which sneaked winto the previous commitAlexander Kornienko2013-12-101-2/+0
| | | | llvm-svn: 196929
* Early attempts to format in GNU style.Alexander Kornienko2013-12-101-36/+21
| | | | | | | | | | | | | | | | 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
* Allow predefined styles to define different options for different languages.Alexander Kornienko2013-12-101-57/+74
| | | | | | | | | | | | | | | | | | | | | | | 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
* Trivial change: added 'using clang::format::FormatStyle;'Alexander Kornienko2013-12-101-68/+54
| | | | llvm-svn: 196903
* Support GNU style rule to put a space before opening parenthesis.Alexander Kornienko2013-12-102-6/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [CMake] clang/lib: Prune redundant dependencies.NAKAMURA Takumi2013-12-101-5/+0
| | | | llvm-svn: 196864
* [CMake] clang/lib: Satisfy dependencies to add *actually used* libraries on ↵NAKAMURA Takumi2013-12-091-2/+3
| | | | | | | | target_link_libraries() and LLVM_LINK_COMPONENTS. I will prune redundant dependencies later. llvm-svn: 196800
* clang-format: Be more conservative about braced list column layout.Daniel Jasper2013-12-093-7/+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-1/+1
| | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<int> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [aaaaaaaaaaaa]; After: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<int> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[aaaaaaaaaaaa]; llvm-svn: 196582
* Fix a tranche of comment, test and doc typosAlp Toker2013-12-054-5/+5
| | | | llvm-svn: 196510
* Fix the regression caused by r196378Alexander Kornienko2013-12-041-3/+3
| | | | llvm-svn: 196380
* Leave constructor initializer lists on one line in styles with no column limit.Alexander Kornienko2013-12-041-6/+16
| | | | | | | | | | | | | | | | | 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
* Added an option to specify fallback style.Alexander Kornienko2013-12-021-10/+12
| | | | | | | | | | | | | | | | Summary: Added -fallback-style option. Changed clang-format to stop searching for .clang-format when an invalid file is found. Reviewers: djasper, klimek Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2292 llvm-svn: 196108
* clang-format: Fix excessive formatting caused by r195954.Daniel Jasper2013-12-021-0/+1
| | | | | | | 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-19/+156
| | | | | | | | | | | | | | | | 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-8/+14
| | | | | | | | | | | | | | | | 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-1/+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-1/+2
| | | | | | | | | | | | | | | 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-282-24/+64
| | | | | | | | | | 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
* Fix crash in getStringSplit.Alexander Kornienko2013-11-262-7/+7
| | | | | | | | | | | | | | | | 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: Fix formatting of empty files (fixes c-index-tests).Daniel Jasper2013-11-251-2/+3
| | | | llvm-svn: 195638
* clang-format: Refactor calculation of lines intersecting with -lines.Daniel Jasper2013-11-253-75/+122
| | | | | | | | 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/+3
| | | | | | This fixes llvm.org/PR17241. llvm-svn: 195555
* clang-format: Fix incorrect space in parameters named by comment.Daniel Jasper2013-11-231-2/+2
| | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | 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-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+2
| | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | 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-212-14/+30
| | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-204-24/+53
| | | | | | | | | | | | | | | | | | | 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
* Simplify fix proposed in r195240.Daniel Jasper2013-11-202-18/+10
| | | | llvm-svn: 195253
* Support for JavaScript === and !== operators.Alexander Kornienko2013-11-201-0/+7
| | | | | | | | | | | | 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-202-8/+18
| | | | | | | | | | | | | | | | | Before: void f() { CHECK_EQ(aaaa, ( *bbbbbbbbb)->cccccc) << "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"; } After: void f() { CHECK_EQ(aaaa, (*bbbbbbbbb)->cccccc) << "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq"; } llvm-svn: 195240
* Refactoring: replaced (*(I + x)) with I[x].Alexander Kornienko2013-11-191-21/+18
| | | | | | | | | | | | | | Summary: Pure refactoring, no semantic changes intended. Reviewers: klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2220 llvm-svn: 195128
* Correctly mark first token in the presence of UTF-8 BOM.Alexander Kornienko2013-11-131-3/+4
| | | | | | | | | | | | | | 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-123-2/+49
| | | | | | | | | | | | | | 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-8/+9
| | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | 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-13/+15
| | | | | | | | | | | | | | | | | | 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-4/+6
| | | | | | | | | | | | | | | | | | | | | | | 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
* clang-format: Don't auto-break short macros in WebKit style.Daniel Jasper2013-11-081-1/+3
| | | | | | This fixes llvm.org/PR17842. llvm-svn: 194268
* clang-format: Improve linebreaking and indentation for ObjC calls.Daniel Jasper2013-11-082-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | Before: popup_wdow_.reset([[RenderWidgetPopupWindow alloc] iniithContentRect: NSMakRet(origin_global.x, origin_global.y, pos.width(), pos.height()) syeMask:NSBorderlessWindowMask bking:NSBackingStoreBuffered der:NO]); [self param:function( // parameter)] After: popup_wdow_.reset([[RenderWidgetPopupWindow alloc] iniithContentRect:NSMakRet(origin_global.x, origin_global.y, pos.width(), pos.height()) syeMask:NSBorderlessWindowMask bking:NSBackingStoreBuffered der:NO]); [self param:function( // parameter)] llvm-svn: 194267
* clang-format: Properly indent ObjC calls wrapped before first selectorDaniel Jasper2013-11-081-1/+5
| | | | | | | | | | | | | | | | Before: [self // break a:a aa:aa aaaaa:aaa]; After: [self // break a:a aa:aa aaaaa:aaa]; llvm-svn: 194241
* clang-format: Make breaking before ternary operators configurable.Daniel Jasper2013-11-083-16/+30
| | | | llvm-svn: 194229
* clang-format: Improve binary operator detection in macros.Daniel Jasper2013-11-071-1/+1
| | | | | | | | | | | | Before: #define M(NAME) assert(!Context.Verifying &&#NAME); After: #define M(NAME) assert(!Context.Verifying && #NAME); This fixes llvm.org/PR16156. llvm-svn: 194216
* clang-format: Improve ObjC variadic and binary expression parameters.Daniel Jasper2013-11-072-6/+9
| | | | | | | | | | | | | | | | | | | | | | Before: [self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa]; [self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa]; After: [self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa | aaaaaaaaaaaaaaa]; [self aaaaaaaaaaaaaaa:aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa, aaaaaaaaaaaaaaa]; This addresses llvm.org/PR15349 and llvm.org/PR16185. llvm-svn: 194214
OpenPOWER on IntegriCloud