summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
Commit message (Collapse)AuthorAgeFilesLines
* clang-format: Be slightly more aggressive on single-line functions.Daniel Jasper2014-05-071-2/+6
| | | | | | | | | | | | | | So that JS functions can also be merged into a single line. Before: var func = function() { return 1; }; After: var func = function() { return 1; }; llvm-svn: 208176
* Fix bug in clang-format while merging short functionDinesh Dwivedi2014-05-051-4/+5
| | | | | | | | | | | | | | | | | | | | | Before: #ifdef _DEBUG int foo( int i = 0 ) #else int foo( int i = 5 ) #endif { return i; } After: #ifdef _DEBUG int foo( int i = 0 ) #else int foo( int i = 5 ) #endif { return i; } llvm-svn: 207958
* clang-format: Remove accidentally added debug output.Daniel Jasper2014-04-291-2/+0
| | | | llvm-svn: 207533
* clang-format: Allow single-line function in WebKit style.Daniel Jasper2014-04-291-0/+2
| | | | | | | | | | | Before: void f() { return; } After: void f() { return; } llvm-svn: 207527
* [Modules] Fix potential ODR violations by sinking the DEBUG_TYPEChandler Carruth2014-04-221-2/+2
| | | | | | | | | | definition below all of the header #include lines, clang edition. If you want more details about this, you can see some of the commits to Debug.h in LLVM recently. This is just the clang section of a cleanup I've done for all uses of DEBUG_TYPE in LLVM. llvm-svn: 206849
* Format.cpp: Don't use initializer list.NAKAMURA Takumi2014-04-151-2/+2
| | | | llvm-svn: 206339
* clang-format: Understand proto text format without commas.Daniel Jasper2014-04-151-0/+1
| | | | | | | | | | | | | | | | Also removed spaces before colons as they don't seem to be used frequently. Before: optional int32 b = 2 [(foo_options) = {aaaaaaaaaaaaaaaaaaa : 123 bbbbbbbbbbbbbbbbbbbbbbbb : "baz"}]; After: optional int32 b = 2 [(foo_options) = {aaaaaaaaaaaaaaaaaaa: 123, bbbbbbbbbbbbbbbbbbbbbbbb:"baz"}]; llvm-svn: 206269
* clang-format: Basic support for C++1y.Daniel Jasper2014-04-151-0/+1
| | | | | | | | | | | Before: int bi{1 '000' 000}; After: int bi{1'000'000}; This fixes llvm.org/PR19342. llvm-svn: 206263
* clang-format: Early cut-off for inlining nested blocks.Daniel Jasper2014-04-151-0/+7
| | | | | | | | | | | | | | Specifically, for a nested block or lambda, don't try to put the single statement body inline, if it exceeds the column limit. This should not change any observable behavior (as those would never have led to the 'best' solution), but significantly speeds up formatting time. This fixes llvm.org/PR18761. Formatting time goes down from ~100s to a few ms. llvm-svn: 206260
* clang-format: Cache results of formatting nested blocks.Daniel Jasper2014-04-151-0/+14
| | | | | | | This somewhat improves the performance problem reported in llvm.org/PR18761. No other behavior changes intended. llvm-svn: 206258
* Format code around VCS conflict markers.Manuel Klimek2014-04-141-1/+71
| | | | | | | | | | | | | | | | | | | | | Now correctly formats: { int a; void f() { callme(some(parameter1, <<<<<<< text by the vcs parameter2), ||||||| text by the vcs parameter2), parameter3, ======= text by the vcs parameter2, parameter3), >>>>>>> text by the vcs otherparameter); } } llvm-svn: 206157
* Correctly handle escaped newlines when the next token starts without a space.Manuel Klimek2014-04-111-1/+3
| | | | | | | We will need this to correctly handle conflict markers inside macro definitions. llvm-svn: 206029
* clang-format: Fix bug where clang-format would break the code.Daniel Jasper2014-04-091-0/+4
| | | | | | | | | | | | Before, it would turn: SomeFunction([]() { // Cool function.. return 43; }); Into this: SomeFunction([]() { // Cool function.. return 43; }); llvm-svn: 205849
* clang-format: Extend AllowShortFunctions.. to only merge inline functions.Daniel Jasper2014-04-081-6/+22
| | | | | | | | | | | | | | | | | Before AllowShortFunctionsOnASingleLine could either be true, merging all functions, or false, merging no functions. This patch adds a third value "Inline", which can be used to only merge short functions defined inline in a class, i.e.: void f() { return 42; } class C { void f() { return 42; } }; llvm-svn: 205760
* clang-format: Don't merge simple blocks in case statements.Daniel Jasper2014-04-041-1/+1
| | | | | | | | | | | | | | | | Before: switch (a) { case 1: { return 'a'; } } After: switch (a) { case 1: { return 'a'; } } llvm-svn: 205611
* clang-format: Support configurable list of foreach-macros.Daniel Jasper2014-04-011-2/+17
| | | | | | | | This fixes llvm.org/PR17242. Patch by Brian Green, thank you! llvm-svn: 205307
* clang-format: Add flag for removing empty lines at the start of blocks.Daniel Jasper2014-03-211-1/+6
| | | | | | | This unbreaks polly-formatting-tests and we can make a decision for LLVM style independently. llvm-svn: 204467
* clang-format: Don't remove empty lines at the start of namespaces.Daniel Jasper2014-03-211-1/+2
| | | | llvm-svn: 204462
* clang-format: Remove empty lines at the beginning of blocks.Daniel Jasper2014-03-211-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | They very rarely aid readability. Formatting: void f() { if (a) { f(); } } Now leads to: void f() { if (a) { f(); } } llvm-svn: 204460
* [C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper2014-03-151-2/+2
| | | | | | class. llvm-svn: 203999
* Replace OwningPtr with std::unique_ptr.Ahmed Charles2014-03-071-1/+1
| | | | | | This compiles cleanly with lldb/lld/clang-tools-extra/llvm. llvm-svn: 203279
* [C++11] Switch the clang-format LLVM style to use C++11 style bracedChandler Carruth2014-03-021-3/+8
| | | | | | | | | init list formatting. This suggestion has now gone into the LLVM coding standards, and is particularly relevant now that we're using C++11. Updated a really ridiculous number of tests to reflect this change. llvm-svn: 202637
* clang-format: Fix alignment of comments inside statements.Daniel Jasper2014-02-111-3/+3
| | | | | | | | | | | | | | Before: auto result = SomeObject // Calling someFunction on SomeObject .someFunction(); After: auto result = SomeObject // Calling someFunction on SomeObject .someFunction(); llvm-svn: 201138
* clang-format: Fix column limit violation for merged lines in macros.Daniel Jasper2014-02-071-0/+15
| | | | | | | | | | | | | | | | Before (81 columns): #define A \ void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() { return aaaaaaaa; } \ int i; After: #define A \ void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() { \ return aaaaaaaa; \ } \ int i; llvm-svn: 200974
* clang-format: Let chromium style inherit google style's javascript tweaks.Nico Weber2014-02-021-30/+15
| | | | llvm-svn: 200652
* clang-format: (JavaScript) Don't crash on empty string literals.Daniel Jasper2014-01-311-4/+8
| | | | | | | Before, this would lead to a crash: f('', true); llvm-svn: 200540
* clang-format: Add support for a space after @propertyDaniel Jasper2014-01-281-0/+5
| | | | | | | | | Mozilla and WebKit seem to use a space after @property (verified by grepping their codebases) so we turn this on there as well. Change by Christian Legnitto. Thank you! llvm-svn: 200320
* clang-format: Leave 2 empty lines in Google's JavaScript style.Daniel Jasper2014-01-201-0/+1
| | | | | | | As per the style guide, two lines are required between top-level elements. llvm-svn: 199660
* clang-format: Better support and testing for protocol buffers.Daniel Jasper2014-01-191-2/+23
| | | | | | | | | With this patch, there is dedicated testing for protocol buffers (https://developers.google.com/protocol-buffers/). Also some minor tweaks formatting tweaks. llvm-svn: 199580
* clang-format: Fixed formatting of JavaScript container literalsDaniel Jasper2014-01-151-3/+4
| | | | | | | | | | | | Before: var arr = [ 1, 2, 3 ]; var obj = {a : 1, b : 2, c : 3}; After: var arr = [1, 2, 3]; var obj = {a: 1, b: 2, c: 3}; llvm-svn: 199317
* Sort all the #include lines with LLVM's utils/sort_includes.py whichChandler Carruth2014-01-071-1/+1
| | | | | | | encodes the canonical rules for LLVM's style. I noticed this had drifted quite a bit when cleaning up LLVM, so wanted to clean up Clang as well. llvm-svn: 198686
* Added an option to avoid splitting certain kinds of comments into lines.Alexander Kornienko2014-01-021-0/+2
| | | | | | | | | | | | | | Summary: Added CommentPragmas option for this. Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2460 llvm-svn: 198310
* Fix and reword some typosAlp Toker2013-12-301-1/+1
| | | | llvm-svn: 198191
* clang-format: (WebKit) Disallow 1-line constructors with initializers.Daniel Jasper2013-12-241-5/+16
| | | | | | | | | | | | | | | Before: Constructor() : a(a) {} After: Constructor() : a(a) { } This style guide is pretty precise about this. llvm-svn: 197980
* clang-format: Increase penalty for breaking comments.Daniel Jasper2013-12-191-1/+1
| | | | | | | | | | | | | 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: Don't adapt local format to macros.Daniel Jasper2013-12-171-7/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Always break before the colon in constructor initializers, whenAlexander Kornienko2013-12-161-5/+3
| | | | | | | | | | | 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
* Implemented GNU-style formatting for compound statements.Alexander Kornienko2013-12-121-2/+4
| | | | | | | | | | | | | | | | 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-101-4/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* 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: Improve selective formatting of nested statements.Daniel Jasper2013-11-281-23/+60
| | | | | | | | | | 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
OpenPOWER on IntegriCloud