summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/BreakableToken.h
Commit message (Collapse)AuthorAgeFilesLines
* [clang][NFC] Make various uses of Regex constThomas Preud'homme2019-11-191-10/+10
| | | | | | | | | | | | | | | | The const-correctness of match() was fixed in rL372764, which allows uses of Regex objects to be const in cases they couldn't be before. This patch tightens up the const-ness of Regex in various such cases. Reviewers: thopre Reviewed By: thopre Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68155
* [clang-format] Fix bug in block comment reflow that joins * and /Owen Pan2019-05-031-0/+3
| | | | | | | | Fixes PR41213 Differential Revision: https://reviews.llvm.org/D61276 llvm-svn: 359943
* [clang-format] Fix bug in reflow of block comments containing CR/LFOwen Pan2019-04-231-1/+1
| | | | | | | | Fix PR36119 Differential Revision: https://reviews.llvm.org/D60996 llvm-svn: 359029
* [clang-format] [NFC] clang-format the Format libraryPaul Hoad2019-03-011-6/+2
| | | | | | | | | | | Previously revisions commited non-clang-formatted changes to the Format library, this means submitting any revision e.g. {D55170} can cause additional whitespace changes to potentially be included in a revision. Commit a non functional change using latest build Windows clang-format r351376 with no other changes, to remove these differences All FormatTests pass [==========] 652 tests from 20 test cases ran. llvm-svn: 355182
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [clang-format] Silence -Wdocumentation warningsKrasimir Georgiev2018-07-301-6/+8
| | | | | | introduced in r338232 llvm-svn: 338245
* [clang-format] Indent after breaking Javadoc annotated lineKrasimir Georgiev2018-07-301-1/+24
| | | | | | | | | | | | | | | | 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
* NFC: Add the emacs c++ mode hint "-*- C++ -*-" to the headers that don't have itErik Pilkington2018-07-241-1/+1
| | | | | | https://llvm.org/docs/CodingStandards.html#file-headers llvm-svn: 337780
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-23/+23
| | | | | | | | | | | | | | | | | | | 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
* [clang-format] Fix clang-tidy readability problems, NFCIKrasimir Georgiev2018-04-231-2/+2
| | | | llvm-svn: 330574
* [clang-format] Ignore UnbreakableTailLength sometimes during breakingKrasimir Georgiev2018-01-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-0/+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
* Restructure how we break tokens.Manuel Klimek2017-11-291-154/+146
| | | | | | | | | | | | | | | | | 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-4/+4
| | | | | | | | 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
* [clang-format] Break non-trailing comments, try 2Krasimir Georgiev2017-10-161-0/+9
| | | | | | | | | | | | | | | | | | | | 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] Put '/**' and '*/' on own lines in jsdocs ending in comment ↵Krasimir Georgiev2017-08-091-4/+4
| | | | | | | | | | | | | | | | | | 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-0/+50
| | | | | | | | | | | | Reviewers: mprobst Reviewed By: mprobst Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D35683 llvm-svn: 308684
* [clang-format] Reformat BreakableToken.h; NFCKrasimir Georgiev2017-03-081-19/+14
| | | | llvm-svn: 297262
* [clang-format] Enable comment reflowing in multiline comments containing pragmasKrasimir Georgiev2017-03-081-5/+6
| | | | | | | | | | | | | | | | | 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-12/+2
| | | | llvm-svn: 295714
* [clang-format] Align block comment decorationsKrasimir Georgiev2017-02-161-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Move OriginalPrefix from base to subclass.Krasimir Georgiev2017-02-081-4/+8
| | | | | | | | | | | | | | | | Summary: OriginalPrefix is only needed for line comment sections. Moved from the base class to the child class. No functional changes. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29716 llvm-svn: 294457
* [clang-format] Don't reflow across comment pragmas.Krasimir Georgiev2017-02-021-4/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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] Refactor WhitespaceManager and friendsDaniel Jasper2017-01-311-24/+20
| | | | | | | | | | | | | | | | | | | 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] Implement comment reflowing.Krasimir Georgiev2017-01-251-75/+244
| | | | | | | | | | | | | | | | | | 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
* Roll-back r250822.Angel Garcia Gomez2015-10-201-1/+1
| | | | | | | | | | Summary: It breaks the build for the ASTMatchers Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D13893 llvm-svn: 250827
* Apply modernize-use-default to clang.Angel Garcia Gomez2015-10-201-1/+1
| | | | | | | | | | | | Summary: Replace empty bodies of default constructors and destructors with '= default'. Reviewers: bkramer, klimek Subscribers: klimek, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13890 llvm-svn: 250822
* Fix assertion in BreakableBlockComment (http://llvm.org/PR21916).Alexander Kornienko2015-01-121-0/+5
| | | | | | | | | | | | Reviewers: djasper Reviewed By: djasper Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D6894 llvm-svn: 225628
* Header guard canonicalization, clang part.Benjamin Kramer2014-08-131-3/+3
| | | | | | Modifications made by clang-tidy with minor tweaks. llvm-svn: 215557
* Fix alignment of trailing block comments.Alexander Kornienko2014-04-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | 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
* [C++11] Add 'override' keyword to virtual methods that override their base ↵Craig Topper2014-03-151-33/+28
| | | | | | class. llvm-svn: 203999
* Remove extra whitespace instead of breaking the line in comments when possible.Alexander Kornienko2013-11-121-0/+15
| | | | | | | | | | | | | | 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
* Implemented tab usage only for indentation (http://llvm.org/PR17363)Alexander Kornienko2013-09-271-18/+21
| | | | | | | | | | | | | | | | | | | 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-0/+1
| | | | | | | | | | | | | | 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
* Handle zero-width and double-width characters in string literals and comments.Alexander Kornienko2013-09-051-11/+15
| | | | | | | | | | | | | | | | | | 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
* Reformat clang-format's source files after r185822 and others.Daniel Jasper2013-07-081-2/+2
| | | | llvm-svn: 185823
* Fix for corner cases in code handling leading "* " decorations in block commentsAlexander Kornienko2013-07-081-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Don't remove backslashes from block comments.Alexander Kornienko2013-06-141-14/+12
| | | | | | | | | | | | | | | | | | | | | | | 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-2/+12
| | | | | | | | | | | | | | | | | | | | 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/+13
| | | | | | | | | | | | | | | | | | | | | 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-5/+11
| | | | | | | | | | | | | | | | | | | | 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
* Major refactoring of BreakableToken.Manuel Klimek2013-05-271-172/+131
| | | | | | | | | | | | | | | | | | | 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-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | 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-67/+81
| | | | | | | | | | | | | | | | | | | 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/+226
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