summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/BreakableToken.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: clang-format (NFC)Daniel Jasper2015-06-171-7/+5
| | | | llvm-svn: 239903
* clang-format: Don't generate unnecessary replacements for \r\n line endings.Daniel Jasper2015-06-171-1/+1
| | | | | | Patch by Mathieu Champlon. Thank you. llvm-svn: 239900
* clang-format: Support //!-comments, increase test coverage.Daniel Jasper2015-06-091-1/+3
| | | | llvm-svn: 239404
* clang-format: Fix bug in multiline comment wrapping.Daniel Jasper2015-05-061-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Splitting: /** * multiline block comment * */ Before: /** * multiline block *comment * */ After: /** * multiline block * comment * */ The reason was that the empty line inside the comment (with just the "*") was confusing the comment breaking logic. llvm-svn: 236573
* clang-format: Fix crasher when splitting incomplete escape sequences.Daniel Jasper2015-01-211-1/+1
| | | | llvm-svn: 226698
* Fix assertion in BreakableBlockComment (http://llvm.org/PR21916).Alexander Kornienko2015-01-121-1/+2
| | | | | | | | | | | | Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D6894 llvm-svn: 225628
* clang-format: Fix bug introduced by r208392.Daniel Jasper2014-05-091-5/+3
| | | | | | Also run clang-format over clang-format's files. llvm-svn: 208409
* [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
* Fix alignment of trailing block comments.Alexander Kornienko2014-04-171-5/+3
| | | | | | | | | | | | | | | | | | | | | | Summary: This patch ensures that the lines of the block comments retain relative column offsets. In order to do this WhitespaceManager::Changes representing continuation of block comments keep a pointer on the change representing the whitespace change before the block comment, and a relative column offset to this change, so that the correct column can be reconstructed at the end of alignment process. Fixes http://llvm.org/PR19325 Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D3408 llvm-svn: 206472
* Preserve hanging indent when breaking line comments.Alexander Kornienko2014-03-101-7/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: If we need to break the second line here: // something: aaaaa aaaaa aaaaaa aaaaa aaaaa // aaaaa aaaaa aaaaaa aaaaa aaaaa aaaaa with the patch it will be turned to // something: aaaaa aaaaa aaaaaa aaaaa aaaaa // aaaaa aaaaa aaaaaa aaaaa aaaaa // aaaaa instead of // something: aaaaa aaaaa aaaaaa aaaaa aaaaa // aaaaa aaaaa aaaaaa aaaaa aaaaa // aaaaa Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D2988 llvm-svn: 203458
* clang-format: Fix bug introduced in r198871.Daniel Jasper2014-01-141-1/+8
| | | | | | | | | | | | We cannot simply change the start column to accomodate for the @ in an ObjC string literal as that will make clang-format happily violate the column limit. Use a different workaround instead. However, a better long-term solution might be to join the @ and the rest of the literal into a single token. llvm-svn: 199198
* clang-format: Add @s when breaking NSString literals.Daniel Jasper2014-01-091-1/+1
| | | | | | | | While it is allowed to not have an @ on subsequent lines, it seems general practice to add them. If undesired, the code author can easily remove them again and clang-format won't re-add them. llvm-svn: 198871
* Fix a tranche of comment, test and doc typosAlp Toker2013-12-051-1/+1
| | | | llvm-svn: 196510
* Fix crash in getStringSplit.Alexander Kornienko2013-11-261-4/+2
| | | | | | | | | | | | | | | | 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
* Remove extra whitespace instead of breaking the line in comments when possible.Alexander Kornienko2013-11-121-2/+25
| | | | | | | | | | | | | | 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
* clang-format: fix for \r\r\n produced in multiline block commentsDaniel Jasper2013-10-301-1/+2
| | | | | | Patch by Christopher Olsen. Thank you! llvm-svn: 193678
* Implemented tab usage only for indentation (http://llvm.org/PR17363)Alexander Kornienko2013-09-271-30/+23
| | | | | | | | | | | | | | | | | | | 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
* When in pre-c++11 mode, treat _T("xxx") as a single string literal, repeat ↵Alexander Kornienko2013-09-161-18/+15
| | | | | | | | | | | | | | 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
* Calculate and store ColumnWidth instead of CodePointCount in FormatTokens.Alexander Kornienko2013-09-101-2/+4
| | | | | | | | | | | | | | | | 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
* Handle zero-width and double-width characters in string literals and comments.Alexander Kornienko2013-09-051-25/+44
| | | | | | | | | | | | | | | | | | 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
* Revert r187935 "Support for double width characters."Arnold Schwaighofer2013-08-081-20/+9
| | | | | | It broke a public build bot. llvm-svn: 187957
* Support for double width characters.Alexander Kornienko2013-08-071-9/+20
| | | | | | | | | | | | | | Summary: Only works for UTF-8-encoded files. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1311 llvm-svn: 187935
* Add 'static' and 'const' qualifiers to some arrays of strings.Craig Topper2013-07-151-1/+1
| | | | llvm-svn: 186314
* Reformat clang-format's source files after r185822 and others.Daniel Jasper2013-07-081-10/+10
| | | | llvm-svn: 185823
* Fix for corner cases in code handling leading "* " decorations in block commentsAlexander Kornienko2013-07-081-28/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Fixes problems that lead to incorrect formatting of these and similar snippets: /* ** */ /* **/ /* * */ /* *test */ Clang-format used to think that all the cases above use "* " decoration, and failed to calculate insertion position properly. It also used to remove leading "* " in the last line. Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1113 llvm-svn: 185818
* Use static for helper functions instead of an anonymous namespace per coding ↵Craig Topper2013-07-011-11/+8
| | | | | | standards. llvm-svn: 185300
* Make string pointer const.Craig Topper2013-06-301-1/+1
| | | | llvm-svn: 185296
* Use the same set of whitespace characters for all operations in BreakableToken.Alexander Kornienko2013-06-201-11/+24
| | | | | | | | | | | | | | | | | Summary: Fixes a problem where \t,\v or \f could lead to a crash when placed as a first character in a line comment. The cause is that rtrim and ltrim handle these characters, but our code didn't, so some invariants could be broken. Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1013 llvm-svn: 184425
* Split long strings on word boundaries.Alexander Kornienko2013-06-191-0/+5
| | | | | | | | | | | | Summary: Split strings at word boundaries, when there are no spaces and slashes. Reviewers: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1003 llvm-svn: 184304
* Don't remove backslashes from block comments.Alexander Kornienko2013-06-141-17/+26
| | | | | | | | | | | | | | | | | | | | | | | Summary: Don't remove backslashes from block comments. Previously this /* \ \ \ \ \ \ */ would be turned to this: /* */ which spoils some kinds of ASCII-art, people use in their comments. The behavior was related to handling escaped newlines in block comments inside preprocessor directives. This patch makes handling it in a more civilized way. Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D979 llvm-svn: 183978
* Insert a space at the start of a line comment in case it starts with an ↵Alexander Kornienko2013-06-111-14/+43
| | | | | | | | | | | | | | | | | | | | 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
* Fixed calculation of penalty when breaking tokens.Alexander Kornienko2013-06-071-9/+7
| | | | | | | | | | | | | | | | | | | | | Summary: Introduced two new style parameters: PenaltyBreakComment and PenaltyBreakString. Add penalty for each character of a breakable token beyond the column limit (this relates mainly to comments, as they are broken only on whitespace). Tuned PenaltyBreakComment to prefer comment breaking over breaking inside most binary expressions. Fixed a bug that prevented *, & and && from being considered TT_BinaryOperator in the presense of adjacent comments. Reviewers: klimek, djasper Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D933 llvm-svn: 183530
* UTF-8 support for clang-format.Alexander Kornienko2013-06-051-87/+70
| | | | | | | | | | | | | | | | | | | | Summary: Detect if the file is valid UTF-8, and if this is the case, count code points instead of just using number of bytes in all (hopefully) places, where number of columns is needed. In particular, use the new FormatToken.CodePointCount instead of TokenLength where appropriate. Changed BreakableToken implementations to respect utf-8 character boundaries when in utf-8 mode. Reviewers: klimek, djasper Reviewed By: djasper CC: cfe-commits, rsmith, gribozavr Differential Revision: http://llvm-reviews.chandlerc.com/D918 llvm-svn: 183312
* More fixes for clang-format's multiline comment breaking.Daniel Jasper2013-05-301-3/+1
| | | | llvm-svn: 182940
* Fix another clang-format crasher related to multi-line comments.Daniel Jasper2013-05-301-0/+3
| | | | | | | | | | This fixes: /* * * something long going over the column limit. */ llvm-svn: 182932
* Add asserts to guard against regressions.Manuel Klimek2013-05-301-0/+2
| | | | llvm-svn: 182916
* Fix crasher when formatting certain block comments.Daniel Jasper2013-05-301-0/+5
| | | | | | | | | Smallest reproduction: /* ** */ llvm-svn: 182913
* Fixes error when splitting block comments.Manuel Klimek2013-05-291-2/+10
| | | | | | | | When trying to fall back to search from the end onwards, we would still find leading whitespace if the leading whitespace went on after the end of the line. llvm-svn: 182886
* Disable tab expansion when counting the columns in block comments.Manuel Klimek2013-05-281-10/+8
| | | | | | | | | | | | | | | | | To fully support this, we also need to expand tabs in the text before the block comment. This patch breaks indentation when there was a non-standard mixture of spaces and tabs used for indentation, but fixes a regression in the simple case: { /* * Comment. */ int i; } Is now formatted correctly, if there were tabs used for indentation before. llvm-svn: 182760
* Fixes indentation of empty lines in block comments.Manuel Klimek2013-05-281-2/+11
| | | | | | | | | | | Block comment indentation of empty lines regressed, as we did not have a test for it. /* Comment with... * * empty line. */ is now formatted correctly again. llvm-svn: 182757
* Major refactoring of BreakableToken.Manuel Klimek2013-05-271-120/+280
| | | | | | | | | | | | | | | | | | | 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
* Makes whitespace management more consistent.Manuel Klimek2013-05-221-7/+13
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Unified token breaking logic: support for line comments.Alexander Kornienko2013-04-171-56/+74
| | | | | | | | | | | | | | | | | | | 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/+161
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