summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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
* Added WebKit style to the BasedOnStyle handling and to the relevant help ↵Alexander Kornienko2013-09-021-1/+2
| | | | | | messages. llvm-svn: 189765
* Store first and last newline position in the token text for string literals ↵Alexander Kornienko2013-09-021-4/+10
| | | | | | | | | | | | | | | | | | and comments. Summary: Store first and last newline position in the token text for string literals and comments to avoid doing .find('\n') for each possible solution. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1556 llvm-svn: 189758
* Better support for multiline string literals (including C++11 raw string ↵Alexander Kornienko2013-08-291-1/+4
| | | | | | | | | | | | | | | | | | literals). Summary: Calculate characters in the first and the last line correctly so that we only break before the literal when needed. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1544 llvm-svn: 189595
* Fixes various problems with accounting for tabs in the original code.Manuel Klimek2013-08-291-18/+38
| | | | | | | | | | | | | | | We now count the original token's column directly when lexing the tokens, where we already have all knowledge about where lines start. Before this patch, formatting: void f() { \tg(); \th(); } would incorrectly count the \t's as 1 character if only the line containing h() was reformatted, and thus indent h() at offset 1. llvm-svn: 189585
* clang-format: Improve token breaking behavior.Daniel Jasper2013-08-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Two changes: * Don't add an extra penalty on breaking the same token multiple times. Generally, we should prefer not to break, but once we break, the normal line breaking penalties apply. * Slightly increase the penalty for breaking comments. In general, the author has put some thought into how to break the comment and we should not overwrite this unnecessarily. With a 40-column column limit, formatting aaaaaa("aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa"); Leads to: Before: aaaaaa( "aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa " "aaaaaaaaaaaaaaaa"); After: aaaaaa("aaaaaaaaaaaaaaaa " "aaaaaaaaaaaaaaaa " "aaaaaaaaaaaaaaaa"); llvm-svn: 189466
* 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-221-8/+3
| | | | | | | | | | | | | | | | | | | | 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-211-4/+3
| | | | | | | | | | | | | | | | Before: if (!aaaaaaaaaa( // break aaaaa)) { } After: if (!aaaaaaaaaa( // break aaaaa)) { } Also cleaned up formatting using clang-format. llvm-svn: 188891
* clang-format: Additional options for spaces around parentheses.Daniel Jasper2013-08-201-0/+15
| | | | | | | | | | | | 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
* Split UnwrappedLineFormatter into individual components.Daniel Jasper2013-08-161-901/+56
| | | | | | | | | 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 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-121-2/+2
| | | | | | | | | | | | | | 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
* Fixes a couple of bugs with the Allman brace breaking.Manuel Klimek2013-08-071-0/+3
| | | | | | | | | | | 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
* Implement Allman style.Manuel Klimek2013-08-021-0/+1
| | | | | | 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: Don't break empty 2nd operand of ternary expr.Daniel Jasper2013-08-011-1/+2
| | | | | | | | | | | | | | | | 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-011-1/+1
| | | | | | | | | | | | | | | | | | | 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: Make alignment of trailing comments optional ..Daniel Jasper2013-07-311-0/+4
| | | | | | .. in order to support WebKit style properly. llvm-svn: 187549
* clang-format: Add more options to namespace indentation.Daniel Jasper2013-07-311-2/+19
| | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud