summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/BreakableToken.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clang-format] Add @private to the list of jsdoc annotationsKrasimir Georgiev2018-08-011-1/+1
| | | | | | | | | | | | Reviewers: mprobst Reviewed By: mprobst Subscribers: acoomans, cfe-commits Differential Revision: https://reviews.llvm.org/D50138 llvm-svn: 338519
* Remove trailing spaceFangrui Song2018-07-301-1/+1
| | | | | | sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
* [clang-format] Indent after breaking Javadoc annotated lineKrasimir Georgiev2018-07-301-7/+47
| | | | | | | | | | | | | | | | Summary: This patch makes clang-format indent the subsequent lines created by breaking a long javadoc annotated line. Reviewers: mprobst Reviewed By: mprobst Subscribers: acoomans, cfe-commits Differential Revision: https://reviews.llvm.org/D49797 llvm-svn: 338232
* [clang-format] Fix crash while reflowing backslash in commentsKrasimir Georgiev2018-06-121-7/+38
| | | | | | | | | | | | | | | | | | | | | Summary: The added test case was currently crashing with an assertion: ``` krasimir@krasimir> cat test.cc ~ // How to run: // bbbbb run \ // rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr \ // <log_file> -- --output_directory="<output_directory>" krasimir@krasimir> ~/work/llvm-build/bin/clang-format test.cc ~ clang-format: /usr/local/google/home/krasimir/work/llvm/tools/clang/lib/Format/WhitespaceManager.cpp:117: void clang::format::WhitespaceManager::calculateLineBreakInformation(): Assertion `PreviousOriginalWhitespaceEndOffset <= OriginalWhitespaceStartOffset' failed. ``` The root cause was that BreakableToken was not considering the case of a reflow between an unescaped newline in a line comment. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D48089 llvm-svn: 334527
* [clang-format] Consider tok::hashhash in python-style commentsKrasimir Georgiev2018-06-071-1/+2
| | | | | | | | | | Summary: We were missing the case when python-style comments in text protos start with `##`. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D47870 llvm-svn: 334179
* [clang] Update uses of DEBUG macro to LLVM_DEBUG.Nicola Zaghen2018-05-151-3/+4
| | | | | | | | | | | | | The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM Explicitly avoided changing the strings in the clang-format tests. Differential Revision: https://reviews.llvm.org/D44975 llvm-svn: 332350
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-1/+1
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
* [format] Eliminate global destructors.Benjamin Kramer2018-03-201-7/+6
| | | | llvm-svn: 328047
* [clang-format] Ignore UnbreakableTailLength sometimes during breakingKrasimir Georgiev2018-01-231-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch fixes an issue where the UnbreakableTailLength would be counted towards the length of a token during breaking, even though we can break after the token. For example, this proto text with column limit 20 ``` # ColumnLimit: 20 V foo: { bar: { bazoo: "aaaaaaa" } } ``` was broken: ``` # ColumnLimit: 20 V foo: { bar: { bazoo: "aaaaaaa" } } ``` because the 2 closing `}` were counted towards the string literal's `UnbreakableTailLength`. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D42376 llvm-svn: 323188
* Fix bug where we wouldn't break columns over the limit.Manuel Klimek2017-12-041-2/+4
| | | | | | | | | | | | | | | | Before, we would not break: int a = foo(/* trailing */); when the end of /* trailing */ was exactly the column limit; the reason is that block comments can have an unbreakable tail length - in this case 2, for the trailing ");"; we would unconditionally account that when calculating the column state at the end of the token, but not correctly add it into the remaining column length before, as we do for string literals. The fix is to correctly account the trailing unbreakable sequence length into our formatting decisions for block comments. Line comments cannot have a trailing unbreakable sequence, so no change is needed for them. llvm-svn: 319642
* Fix 'control reaches end of non-void' warning by using llvm_unreachable.Manuel Klimek2017-11-291-3/+2
| | | | llvm-svn: 319318
* Restructure how we break tokens.Manuel Klimek2017-11-291-266/+171
| | | | | | | | | | | | | | | | | This fixes some bugs in the reflowing logic and splits out the concerns of reflowing from BreakableToken. Things to do after this patch: - Refactor the breakProtrudingToken function possibly into a class, so we can split it up into methods that operate on the common state. - Optimize whitespace compression when reflowing by using the next possible split point instead of the latest possible split point. - Retry different strategies for reflowing (strictly staying below the column limit vs. allowing excess characters if possible). Differential Revision: https://reviews.llvm.org/D40310 llvm-svn: 319314
* Implement more accurate penalty & trade-offs while breaking protruding tokens.Manuel Klimek2017-11-171-2/+2
| | | | | | | | For each line that we break in a protruding token, compute whether the penalty of breaking is actually larger than the penalty of the excess characters. Only break if that is the case. llvm-svn: 318515
* Refactor ContinuationIndenter's breakProtrudingToken logic.Manuel Klimek2017-11-141-0/+1
| | | | | | | | | | | Create more orthogonal pieces. The restructuring made it easy to try out several alternatives to D33589, and while none of the alternatives turned out to be the right solution, the underlying simplification of the structure is helpful. Differential Revision: https://reviews.llvm.org/D39900 llvm-svn: 318141
* [clang-format] Support python-style comments in text protosKrasimir Georgiev2017-11-101-6/+17
| | | | | | | | | | | | | | Summary: This patch adds support for python-style comments in text protos. Reviewers: djasper Reviewed By: djasper Subscribers: bkramer, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D39806 llvm-svn: 317886
* [clang-format] Break non-trailing comments, try 2Krasimir Georgiev2017-10-161-0/+6
| | | | | | | | | | | | | | | | | | | | Summary: This patch enables `BreakableToken` to manage the formatting of non-trailing block comments. It is a refinement of https://reviews.llvm.org/D37007. We discovered that the optimizer outsmarts us on cases where breaking the comment costs considerably less than breaking after the comment. This patch addresses this by ensuring that a newline is inserted between a block comment and the next token. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D37695 llvm-svn: 315893
* clang-format clang-format.Manuel Klimek2017-09-201-61/+50
| | | | llvm-svn: 313744
* [clang-format] Emit absolute splits before lines for comments, try 2Krasimir Georgiev2017-08-241-12/+10
| | | | | | | | | | | | | | | | Summary: This recommits https://reviews.llvm.org/D36956 with an update to the added test case to not use raw string literals, since this makes gcc unhappy. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D37109 llvm-svn: 311672
* Revert "[clang-format] Emit absolute splits before lines for comments"Krasimir Georgiev2017-08-231-10/+12
| | | | | | | | This reverts commit r311559, which added a test containing raw string literals in macros, which chokes gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55971 llvm-svn: 311566
* [clang-format] Emit absolute splits before lines for commentsKrasimir Georgiev2017-08-231-12/+10
| | | | | | | | | | | | | | | | | | | Summary: This patch makes the splits emitted for the beginning of comment lines during reformatting absolute. Previously, they were relative to the start of the non-whitespace content of the line, which messes up further TailOffset calculations in breakProtrudingToken. This fixes an assertion failure reported in bug 34236: https://bugs.llvm.org/show_bug.cgi?id=34236. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D36956 llvm-svn: 311559
* [clang-format] Put '/**' and '*/' on own lines in jsdocs ending in comment ↵Krasimir Georgiev2017-08-091-6/+12
| | | | | | | | | | | | | | | | | | pragmas Summary: This handles a case where the trailing '*/' of a multiline jsdoc eding in a comment pragma wouldn't be put on a new line. Reviewers: mprobst Reviewed By: mprobst Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D36359 llvm-svn: 310458
* [clang-format] Put '/**' and '*/' on own lines in multiline jsdocsKrasimir Georgiev2017-07-201-2/+41
| | | | | | | | | | | | Reviewers: mprobst Reviewed By: mprobst Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D35683 llvm-svn: 308684
* clang-format: do not reflow bullet listsFrancois Ferrand2017-05-221-2/+19
| | | | | | | | | | | | | | | | | | | Summary: This patch prevents reflowing bullet lists in block comments. It handles all lists supported by doxygen and markdown, e.g. bullet lists starting with '-', '*', '+', as well as numbered lists starting with -# or a number followed by a dot. Reviewers: krasimir Reviewed By: krasimir Subscribers: djasper, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D33285 llvm-svn: 303556
* clang-format: fix prefix for doxygen comments after memberKrasimir Georgiev2017-05-181-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Doxygen supports putting documentation blocks after member, by adding an additional < marker in the comment block. This patch makes sure this marker is used in lines which are introduced by breaking the comment. int foo; ///< Some very long comment. becomes: int foo; ///< Some very long ///< comment. Contributed by @Typz! Reviewers: krasimir Reviewed By: krasimir Subscribers: djasper, klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D33282 llvm-svn: 303330
* [clang-format] Handle NSString literals by merging tokens.Alexander Kornienko2017-04-111-9/+2
| | | | | | | | | | | | | | | | | | | | Summary: This fixes a few outstanding bugs: * incorrect breaking of NSString literals containing double-width characters; * inconsistent formatting of ObjC dictionary literals containing NSString literals; * AlwaysBreakBeforeMultilineStrings ignoring implicitly-concatenated NSString literals. Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D31706 llvm-svn: 299927
* [clang-format] Enable comment reflowing in multiline comments containing pragmasKrasimir Georgiev2017-03-081-4/+9
| | | | | | | | | | | | | | | | | Summary: This patch enables comment reflowing of lines not matching the comment pragma regex in multiline comments containing comment pragma lines. Previously, these comments were dumped without being reindented to the result. Reviewers: djasper, mprobst Reviewed By: mprobst Subscribers: klimek, mprobst, cfe-commits Differential Revision: https://reviews.llvm.org/D30697 llvm-svn: 297261
* [clang-format] Remove unused member variables from BreakableTokenKrasimir Georgiev2017-02-211-8/+4
| | | | llvm-svn: 295714
* [clang-format] Align block comment decorationsKrasimir Georgiev2017-02-161-2/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch implements block comment decoration alignment. source: ``` /* line 1 * line 2 */ ``` result before: ``` /* line 1 * line 2 */ ``` result after: ``` /* line 1 * line 2 */ ``` Reviewers: djasper, bkramer, klimek Reviewed By: klimek Subscribers: mprobst, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29943 llvm-svn: 295312
* [clang-format] Don't reflow across comment pragmas.Krasimir Georgiev2017-02-021-13/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The comment reflower wasn't taking comment pragmas as reflow stoppers. This patch fixes that. source: ``` // long long long long // IWYU pragma: ``` format with column limit = 20 before: ``` // long long long // long IWYU pragma: ``` format with column limit = 20 after: ``` // long long long // long // IWYU pragma: ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29450 llvm-svn: 293898
* [clang-format] Fix breaking of comment sections in unwrapped lines ↵Krasimir Georgiev2017-02-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | containing newlines. Summary: The breaking of line comment sections was misaligning the case where the first comment line is on an unwrapped line containing newlines. In this case, the breaking column must be based on the source column of the last token that is preceded by a newline, not on the first token of the unwrapped line. source: ``` enum A { a, // line 1 // line 2 }; ``` format before: ``` enum A { a, // line 1 // line 2 }; ``` format after: ``` enum A { a, // line 1 // line 2 }; ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29444 llvm-svn: 293891
* [clang-format] Don't reflow lines starting with TODO, FIXME or XXX.Krasimir Georgiev2017-02-021-3/+12
| | | | | | | | | | | | | | Summary: These lines commonly carry a special meaning. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29396 llvm-svn: 293878
* [clang-format] Fix regression about not aligning trailing comments in case ↵Krasimir Georgiev2017-02-011-12/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | they were previously aligned, but at different indent. Summary: Comment reflower was adding untouchable tokens in case two consecutive comment lines are aligned in the source code. This disallows the whitespace manager to re-indent them later. source: ``` int i = f(abc, // line 1 d, // line 2 // line 3 b); ``` Since line 2 and line 3 are aligned, the reflower was marking line 3 as untouchable; however the three comment lines need to be re-aligned. output before: ``` int i = f(abc, // line 1 d, // line 2 // line 3 b); ``` output after: ``` int i = f(abc, // line 1 d, // line 2 // line 3 b); ``` Reviewers: djasper Reviewed By: djasper Subscribers: sammccall, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29383 llvm-svn: 293755
* [clang-format] Fix regression about adding leading whitespace to the content ↵Krasimir Georgiev2017-01-311-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of line comments Summary: The reflower didn't measure precisely the line column of a line in the middle of a line comment section that has a prefix that needs to be adapted. source: ``` /// a //b ``` format before: ``` /// a //b ``` format after: ``` /// a // b ``` Reviewers: djasper Reviewed By: djasper Subscribers: sammccall, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29329 llvm-svn: 293641
* [clang-format] Fix reflow in block comment lines with leading whitespace.Krasimir Georgiev2017-01-311-4/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The reflower was not taking into account the additional leading whitespace in block comment lines. source: ``` { /* * long long long long * long * long long long long */ } ``` format (with column limit 20) before: ``` { /* * long long long * long long long long * long long */ } ``` format after: ``` { /* * long long long * long long long * long long long */ } ``` Reviewers: djasper, klimek Reviewed By: djasper Subscribers: cfe-commits, sammccall, klimek Differential Revision: https://reviews.llvm.org/D29326 llvm-svn: 293633
* [clang-format] Fix regression merging comments across newlines.Krasimir Georgiev2017-01-311-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This fixes a regression that causes example: ``` enum A { a, // line a // line b b }; ``` to be formatted as follows: ``` enum A { a, // line a // line b b }; ``` Reviewers: djasper, klimek Reviewed By: klimek Subscribers: cfe-commits, sammccall, djasper, klimek Differential Revision: https://reviews.llvm.org/D29322 llvm-svn: 293624
* [clang-format] Don't reflow comment lines starting with '@'.Krasimir Georgiev2017-01-311-1/+3
| | | | | | | | | | | | | | | | Summary: This patch stops reflowing comment lines starting with '@', since they commonly have a special meaning. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29323 llvm-svn: 293617
* [clang-format] Refactor WhitespaceManager and friendsDaniel Jasper2017-01-311-40/+30
| | | | | | | | | | | | | | | | | | | The main motivation behind this is to cleanup the WhitespaceManager and make it more extensible for future alignment etc. features. Specifically, WhitespaceManager has started to copy more and more code that is already present in FormatToken. Instead, I think it makes more sense to actually store a reference to each FormatToken for each change. This has as a consequence led to a change in the calculation of indent levels. Now, we actually compute them for each Token ahead of time, which should be more efficient as it removes an unsigned value for the ParenState, which is used during the combinatorial exploration of the solution space. No functional changes intended. Review: https://reviews.llvm.org/D29300 llvm-svn: 293616
* [clang-format] Fix regression that breaks comments without a comment prefixKrasimir Georgiev2017-01-301-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Consider formatting the following code fragment with column limit 20: ``` { // line 1 // line 2\ // long long long line } ``` Before this fix the output is: ``` { // line 1 // line 2\ // long long long line } ``` This patch fixes a regression that breaks the last comment line without adding the '//' prefix. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29298 llvm-svn: 293548
* [clang-format] Implement comment reflowing.Krasimir Georgiev2017-01-251-122/+510
| | | | | | | | | | | | | | | | | | Summary: This presents a version of the comment reflowing with less mutable state inside the comment breakable token subclasses. The state has been pushed into the driving breakProtrudingToken method. For this, the API of BreakableToken is enriched by the methods getSplitBefore and getLineLengthAfterSplitBefore. Reviewers: klimek Reviewed By: klimek Subscribers: djasper, klimek, mgorny, cfe-commits, ioeric Differential Revision: https://reviews.llvm.org/D28764 llvm-svn: 293055
* [clang-format] Add comment manipulation headerEric Liu2016-10-191-15/+1
| | | | | | | | | | | | | | | | | | | Summary: Introduces a separate target for comment manipulation. Currently, comment manipulation is in BreakableComment.cpp. Towards implementing comment reflowing, we want to factor out the comment-related functionality, so it can be reused. Start simple by just moving out getLineCommentIndentPrefix. Patch by Krasimir Georgiev! Reviewers: djasper Subscribers: klimek, beanz, mgorny, modocache Differential Revision: https://reviews.llvm.org/D25725 llvm-svn: 284573
* 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
OpenPOWER on IntegriCloud