summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/WhitespaceManager.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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
* Support formatting of preprocessor branches.Manuel Klimek2013-10-111-2/+13
| | | | | | | | | | | | | | | | | | | | | 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
* Added a comment and another test for the UT_ForIndentation optionAlexander Kornienko2013-09-271-0/+2
| | | | llvm-svn: 191530
* Implemented tab usage only for indentation (http://llvm.org/PR17363)Alexander Kornienko2013-09-271-15/+35
| | | | | | | | | | | | | | | | | | | 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
* Correctly indent with tabs when whitespace starts from the column not ↵Alexander Kornienko2013-09-271-2/+10
| | | | | | | | | | | | | | | | | | divisible by TabWidth. Summary: The width of the first inserted tab character depends on the initial column, so we need to handle the first tab in a special manner. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1763 llvm-svn: 191497
* When in pre-c++11 mode, treat _T("xxx") as a single string literal, repeat ↵Alexander Kornienko2013-09-161-5/+3
| | | | | | | | | | | | | | 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
* Support for CR LF newlines.Alexander Kornienko2013-09-111-25/+24
| | | | | | | | | | | | | | | | | | 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
* Handle zero-width and double-width characters in string literals and comments.Alexander Kornienko2013-09-051-2/+2
| | | | | | | | | | | | | | | | | | 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
* clang-format: Fix infinite loop in macro special case.Daniel Jasper2013-08-281-6/+4
| | | | | | | | | | | | | | If escaped newlines are aligned right (FormatStyle.AlignEscapedNewlinesLeft == false), and a line contained too many characters to fit into the column limit, this would result in a (virtually) endless loop creating a negative number of spaces. Instead, allow the escaped newlines to be pushed past the column limit in this case. This fixes llvm.org/PR16515. llvm-svn: 189459
* clang-format: Make alignment of trailing comments optional ..Daniel Jasper2013-07-311-3/+3
| | | | | | .. in order to support WebKit style properly. llvm-svn: 187549
* Reformat clang-format's source files after r185822 and others.Daniel Jasper2013-07-081-9/+8
| | | | llvm-svn: 185823
* Don't align "} // namespace" comments.Daniel Jasper2013-07-011-7/+17
| | | | | | | | | | | | | | | | This is not all bad, but people are often surprised by it. Before: namespace { int SomeVariable = 0; // comment } // namespace After: namespace { int SomeVariable = 0; // comment } // namespace llvm-svn: 185327
* Fixes incorrect indentation of line comments after break and re-alignment.Alexander Kornienko2013-06-171-4/+7
| | | | | | | | | | | | | | | | | | | Summary: Selectively propagate the information about token kind in WhitespaceManager::replaceWhitespaceInToken.For correct alignment of new segments of line comments in order to align them correctly. Don't set BreakBeforeParameter in breakProtrudingToken for line comments, as it introduces a break after the _next_ parameter. Added tests for related functions. Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D980 llvm-svn: 184076
* Insert a space at the start of a line comment in case it starts with an ↵Alexander Kornienko2013-06-111-17/+16
| | | | | | | | | | | | | | | | | | | | alphanumeric character. Summary: "//Test" becomes "// Test". This change is aimed to improve code readability and conformance to certain coding styles. If a comment starts with a non-alphanumeric character, the space isn't added, e.g. "//-*-c++-*-" stays unchanged. Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D949 llvm-svn: 183750
* The second step in the token refactoring.Manuel Klimek2013-05-291-4/+3
| | | | | | | | | | Gets rid of AnnotatedToken, putting everything into FormatToken. FormatTokens are created once, and only referenced by pointer. This enables multiple future features, like having tokens shared between multiple UnwrappedLines (while there's still work to do to fully enable that). llvm-svn: 182859
* Make UnwrappedLines and AnnotatedToken contain pointers to FormatToken.Manuel Klimek2013-05-281-4/+4
| | | | | | The FormatToken is now not copyable any more. llvm-svn: 182772
* Major refactoring of BreakableToken.Manuel Klimek2013-05-271-19/+0
| | | | | | | | | | | | | | | | | | | Unify handling of whitespace when breaking protruding tokens with other whitespace replacements. As a side effect, the BreakableToken structure changed significantly: - have a common base class for single-line breakable tokens, as they are much more similar - revamp handling of multi-line comments; we now calculate the information about lines in multi-line comments similar to normal tokens, and always issue replacements As a result, we were able to get rid of special casing of trailing whitespace deletion for comments in the whitespace manager and the BreakableToken and fixed bugs related to tab handling and escaped newlines. llvm-svn: 182738
* Fix aligning of comments.Manuel Klimek2013-05-231-4/+5
| | | | | | | | | | | | | | | | | Previously we started sequences to align for single line comments when the previous line had a trailing comment, but the sequence was broken for other reasons. Now we re-format: // a // b f(); // c to: // a // b f(); // c llvm-svn: 182608
* Fix aligning of comments that are at the start of the line.Manuel Klimek2013-05-231-3/+4
| | | | | | | | | | Now correctly leaves: f(); // comment // comment g(); // comment ... alone if the middle comment was aligned with g() before formatting. llvm-svn: 182605
* Stop aligning trailing comments which are aligned with the next line.Manuel Klimek2013-05-231-1/+15
| | | | | | | | | | | | | | | | | | | | | | | Previously we would align: f(); // comment // other comment g(); Even if // other comment was at the start of the line. Now we do not align trailing comments if they have been already aligned correctly with the next line. Thus, f(); // comment // other comment g(); will not be changed, while: f(); // comment // other commment g(); will lead to the two trailing comments being aligned. llvm-svn: 182577
* Use a SourceRange for the whitespace location in FormatToken.Manuel Klimek2013-05-231-11/+6
| | | | | | | | | | | Replaces the use of WhitespaceStart + WhitspaceLength. This made a bug in the formatter obvous where we would incorrectly calculate the next column. FIXME: There's a similar bug left regarding TokenLength. We should probably also move to have a TokenRange instead. llvm-svn: 182572
* Fix uninitialized access error found by valgrind.Manuel Klimek2013-05-221-0/+3
| | | | llvm-svn: 182476
* Makes whitespace management more consistent.Manuel Klimek2013-05-221-142/+200
| | | | | | | | | | | | | | | | | | | | | | | | | Instead of selectively storing some changes and directly generating replacements for others, we now notify the WhitespaceManager of the whitespace before every token (and optionally with more changes inside tokens). Then, we run over all whitespace in the very end in original source order, where we have all information available to correctly align comments and escaped newlines. The future direction is to pull more of the comment alignment implementation that is now in the BreakableToken into the WhitespaceManager. This fixes a bug when aligning comments or escaped newlines in unwrapped lines that are handled out of order: #define A \ f({ \ g(); \ }); ... now gets correctly layouted. llvm-svn: 182467
* Fix style according to post-commit review comments.Manuel Klimek2013-05-131-2/+2
| | | | llvm-svn: 181701
* Implements UseTab for clang-format.Manuel Klimek2013-05-131-2/+10
| | | | | | This is required for kernel linux kernel style formatting. llvm-svn: 181693
* Add option to align escaped newlines left.Daniel Jasper2013-04-251-38/+80
| | | | | | | | | | | | | | | This enables formattings like: #define A \ int aaaa; \ int b; \ int ccc; \ int dddddddddd; Enabling this for Google/Chromium styles only as I don't know whether it is desired for Clang/LLVM. llvm-svn: 180253
* Unified token breaking logic: support for line comments.Alexander Kornienko2013-04-171-63/+9
| | | | | | | | | | | | | | | | | | | Summary: Added BreakableLineComment, moved common code from BreakableBlockComment to newly added BreakableComment. As a side-effect of the rewrite, found another problem with escaped newlines and had to change code which removes trailing whitespace from line comments not to break after this patch. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D682 llvm-svn: 179693
* Unified token breaking logic for strings and block comments.Alexander Kornienko2013-04-151-0/+223
Summary: Both strings and block comments are broken into lines in breakProtrudingToken. Logic specific for strings or block comments is abstracted in implementations of the BreakToken interface. Among other goodness, this change fixes placement of backslashes after a block comment inside a preprocessor directive (see removed FIXMEs in unit tests). The code is far from being polished, and some parts of it will be changed for line comments support. Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D665 llvm-svn: 179526
OpenPOWER on IntegriCloud