summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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
* 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-251-72/+110
| | | | | | | | 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
* Better implementation of JavaScript === and !== operators.Alexander Kornienko2013-11-211-7/+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
* Added an option to allow short function bodies be placed on a single line.Alexander Kornienko2013-11-201-24/+50
| | | | | | | | | | | | | | | | | | | 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
* 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
* 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: Make breaking before ternary operators configurable.Daniel Jasper2013-11-081-0/+4
| | | | llvm-svn: 194229
* clang-format: Separate line-merging logic into its own class.Daniel Jasper2013-11-061-151/+164
| | | | | | No functional changes (intended). llvm-svn: 194179
* clang-format: Allow line merging and partial formatting of nested blocksDaniel Jasper2013-11-051-404/+410
| | | | | | | | | | | | | | | | Before, clang-format would always format entire nested blocks, which can be unwanted e.g. for long DEBUG({...}) statements. Also clang-format would not allow to merge lines in nested blocks (e.g. to put "if (a) return;" on one line in Google style). This is the first step of several refactorings mostly focussing on the additional functionality (by reusing the "format many lines" code to format the children of a nested block). The next steps are: * Pull out the line merging into its own class. * Seperate the formatting of many lines from the formatting of a single line (and the analysis of the solution space). llvm-svn: 194090
* clang-format: Option to control spacing in template argument lists.Daniel Jasper2013-10-291-0/+3
| | | | | | | | | | | Same as SpacesInParentheses, this option allows adding a space inside the '<' and '>' of a template parameter list. Patch by Christopher Olsen. This fixes llvm.org/PR17301. llvm-svn: 193614
* I am about to change llvm::MemoryBuffer::getFile take take a Twine. ChangeRafael Espindola2013-10-251-1/+2
| | | | | | clang first so that the build still works. llvm-svn: 193428
* clang-format: Adapt line break penalties for LLVM style.Daniel Jasper2013-10-251-0/+4
| | | | | | | | | | | | | | | | | | | | Specifically make clang-format less eager to break after the opening parenthesis of a function call. Before: aaaaaaaaaaaaaaaaa( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); Apparently that is preferable. This penalties are adapted conservatively, we might have to increase them a little bit further. llvm-svn: 193410
* clang-format: Fix formatting of nested blocks after comment.Daniel Jasper2013-10-201-10/+11
| | | | | | | | | | | | | | | Before: DEBUG({ // Comment that used to confuse clang-format. fdafas(); }); Before: DEBUG({ // Comments are now fine. fdafas(); }); This fixed llvm.org/PR17619. llvm-svn: 193051
* clang-format: Be more aggressive on incorrect code.Daniel Jasper2013-10-181-4/+1
| | | | | | | | | | | | | | | | Before, clang-format would not adjust leading indents if it found a structural error (e.g. unmatched {}). It seems, however, that clang-format has gotten good enough at parsing the code structure that this hurts in almost all cases. Commonly, while writing code, it is very useful to be able to correclty indent incomplete if statements or for loops. In case this leads to errors that we don't anticipate, we need to find out and fix those. This fixed llvm.org/PR17594. llvm-svn: 192988
* clang-format: Make continuation indent width configurable.Daniel Jasper2013-10-181-0/+3
| | | | | | Patch by Kim Gräsman. Thank you! llvm-svn: 192964
* Keep track of indentation levels in static initializers for correct ↵Alexander Kornienko2013-10-141-15/+13
| | | | | | | | | | | | | | | | | | | indentation with tabs. Summary: Store IndentationLevel in ParentState and use it instead of the Line::Level when indening. Also fixed incorrect indentation level calculation in formatFirstToken. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1797 llvm-svn: 192563
* clang-format: No space in "<::" in C++11 mode.Daniel Jasper2013-10-121-4/+8
| | | | llvm-svn: 192524
* Support formatting of preprocessor branches.Manuel Klimek2013-10-111-17/+55
| | | | | | | | | | | | | | | | | | | | | We now correctly format: void SomeFunction(int param1, #ifdef X NoTemplate param2, #else template < #ifdef A MyType<Some> > #else Type1, Type2> #endif param2, #endif param3) { f(); } llvm-svn: 192503
* clang-format: Don't remove 'unknown' tokens.Daniel Jasper2013-10-111-0/+14
| | | | | | | | | | | In certain macros or incorrect string literals, the token stream can contain 'unknown' tokens, e.g. a single backslash or a set of empty ticks. clang-format simply treated them as whitespace and removed them prior to this patch. This fixes llvm.org/PR17215 llvm-svn: 192490
* clang-format: Remove empty lines after visibility modifiers.Daniel Jasper2013-10-061-6/+10
| | | | | | | | | | | | | | | | | Formatting: class C { public: f(); }; Now leads to: class C { public: f(); }; llvm-svn: 192062
* Moving style option formatting to libFormatEdwin Vane2013-09-301-0/+78
| | | | | | | | | The help text for clang-format's -style option and the function that processes its value is moved to libFormat in this patch. The goal is to enable other tools that use libFormat and also have a -style option to behave consistently with clang-format. llvm-svn: 191666
* Implemented tab usage only for indentation (http://llvm.org/PR17363)Alexander Kornienko2013-09-271-10/+24
| | | | | | | | | | | | | | | | | | | Summary: Changed UseTab to be a enum with three options: Never, Always, ForIndentation (true/false are still supported when reading .clang-format). IndentLevel should currently be propagated correctly for all tokens, except for block comments. Please take a look at the general idea before I start dealing with block comments. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1770 llvm-svn: 191527
* clang-format: Option to removing the space before assignment operators.Daniel Jasper2013-09-251-0/+4
| | | | | | Patch contributed by Aaron Wishnick. Thank you! llvm-svn: 191375
* When in pre-c++11 mode, treat _T("xxx") as a single string literal, repeat ↵Alexander Kornienko2013-09-161-1/+37
| | | | | | | | | | | | | | the _T() part around each fragment. This addresses http://llvm.org/PR17122 Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek, rsmith Differential Revision: http://llvm-reviews.chandlerc.com/D1640 llvm-svn: 190804
* clang-format: Fix incorrect enum parsing / layouting.Daniel Jasper2013-09-131-1/+1
| | | | | | | | | | | | | | | Before: enum { Bar = Foo < int, int > ::value }; After: enum { Bar = Foo<int, int>::value }; llvm-svn: 190674
* Support for CR LF newlines.Alexander Kornienko2013-09-111-3/+9
| | | | | | | | | | | | | | | | | | Summary: reformat() tries to determine the newline style used in the input (either LF or CR LF), and uses it for the output. Maybe not every single case is supported, but at least the bug described in http://llvm.org/PR17182 should be resolved. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1643 llvm-svn: 190519
* Correctly calculate OriginalColumn after multi-line tokens.Alexander Kornienko2013-09-101-14/+13
| | | | | | | | | | | | | | Summary: This also unifies the handling of escaped newlines for all tokens. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1638 llvm-svn: 190405
* Calculate and store ColumnWidth instead of CodePointCount in FormatTokens.Alexander Kornienko2013-09-101-18/+27
| | | | | | | | | | | | | | | | Summary: This fixes various issues with mixed tabs and spaces handling, e.g. when realigning block comments. Reviewers: klimek, djasper Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1608 llvm-svn: 190395
* clang-format: Keep empty lines and format 1-line nested blocks.Daniel Jasper2013-09-081-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | Let clang-format consistently keep up to one empty line (configured via FormatStyle::MaxEmptyLinesToKeep) in nested blocks, e.g. lambdas. Also, actually format single statements in nested blocks. Before: DEBUG({ int i; }); DEBUG({ int i; // an empty line here would just be removed. int j; }); After: DEBUG({ int i; }); DEBUG({ int i; int j; }); llvm-svn: 190278
* Don't remove trailing escaped newline from line comments.Alexander Kornienko2013-09-061-1/+1
| | | | llvm-svn: 190175
* clang-format: Fix regression introduced by r189353.Daniel Jasper2013-09-061-2/+2
| | | | | | | | | | | | | | | | | | | | Before: FirstToken->WhitespaceRange.getBegin() .getLocWithOffset(First->LastNewlineOffset); After: FirstToken->WhitespaceRange.getBegin().getLocWithOffset( First->LastNewlineOffset); Re-add logic to prevent breaking after an empty set of parentheses. Basically it seems that calling a function without parameters is more like navigating along the same object than it is a separate step of a builder-type call. We might need to extends this in future to allow "short" parameters that e.g. are an index accessing a specific element. llvm-svn: 190126
* clang-format: Fix comment formatting bugs in nested blocks.Daniel Jasper2013-09-061-30/+22
| | | | | | | | | | | This fixes two issues: 1) The indent of a line comment was not adapted to the subsequent statement as it would be outside of a nested block. 2) A missing DryRun flag caused actualy breaks to be inserted in overly long comments while trying to come up with the best line breaking decisions. llvm-svn: 190123
* Handle zero-width and double-width characters in string literals and comments.Alexander Kornienko2013-09-051-5/+10
| | | | | | | | | | | | | | | | | | Summary: Count column width instead of the number of code points. This also includes correct handling of tabs inside string literals and comments (with an exception of multiline string literals/comments, where tabs are present before the first escaped newline). Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1601 llvm-svn: 190052
* Address post-commit review comments from r190038.Daniel Jasper2013-09-051-4/+5
| | | | | | Mostly additional comments :-). llvm-svn: 190042
* clang-format: Enable formatting of nested blocks.Daniel Jasper2013-09-051-91/+182
| | | | | | | | | | | | | | | | | | Among other things, this enables (better) formatting lambdas and constructs like: MACRO({ long_statement(); long_statement_2(); }, { long_statement(); long_statement_2(); }, { short_statement(); }, ""); This fixes llvm.org/PR15381. llvm-svn: 190038
* Handle 'Cpp03' and 'Cpp11' strings in LanguageStandard serialization forAlexander Kornienko2013-09-041-0/+2
| | | | | | | consistency of serialized form with the actual enum member names without a prefix. llvm-svn: 189936
OpenPOWER on IntegriCloud