summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/WhitespaceManager.h
Commit message (Collapse)AuthorAgeFilesLines
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-18/+18
| | | | | | | | | | | | | | | | | | | 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] Format raw string literalsKrasimir Georgiev2017-10-301-0/+2
| | | | | | | | | | | | | | | Summary: This patch adds raw string literal formatting. Reviewers: djasper, klimek Reviewed By: klimek Subscribers: klimek, mgorny Differential Revision: https://reviews.llvm.org/D35943 llvm-svn: 316903
* [Format] Invert nestingAndIndentLevel pair in WhitespaceManager used forDaniel Jasper2017-08-251-4/+3
| | | | | | | | | | | | | alignments Indent should be compared before nesting level to determine if a token is on the same scope as the one we align with. Because it was inverted, clang-format sometimes tried to align tokens with tokens from outer scopes, causing the assert(Shift >= 0) to fire. This fixes bug #33507. Patch by Beren Minor, thank you! llvm-svn: 311792
* clang-format: Fix bug with ENAS_DontAlign and empty linesJacob Bandes-Storch2017-08-101-3/+3
| | | | | | | | This fixes a bug in `ENAS_DontAlign` (introduced in D32733) where blank lines had an EscapedNewlineColumn of 0, causing a subtraction to overflow when converted back to unsigned and leading to runaway memory allocation. Differential Revision: https://reviews.llvm.org/D36019 llvm-svn: 310539
* [clang-format] Document the StartOfTokenColumn parameter, NFCKrasimir Georgiev2017-06-131-0/+4
| | | | llvm-svn: 305293
* Fix issues in clang-format's AlignConsecutive modes.Nikola Smiljanic2017-03-231-0/+8
| | | | | | Patch by Ben Harper. llvm-svn: 298574
* [clang-format] Refactor WhitespaceManager and friendsDaniel Jasper2017-01-311-23/+13
| | | | | | | | | | | | | | | | | | | 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
* [Format] Remove dead code.Benjamin Kramer2016-12-191-3/+0
| | | | | | No functionality change. llvm-svn: 290135
* Addressed reviewer's post-submission comments from ↵Eric Liu2016-04-281-2/+2
| | | | | | | | | | | | | | http://reviews.llvm.org/D18551. Summary: Make SourceManager in Environment, WhitespaceManager, and FormatTokenAnalyzer etc constant members. Reviewers: djasper, klimek Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D19587 llvm-svn: 267859
* [clang-format] Fix comment aligning when there are changes within the commentBenjamin Kramer2016-01-111-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | As soon as a comment had whitespace changes inside of the token, we couldn't identify the whole comment as a trailing comment anymore and alignment stopped working. Add a new boolean to Change for this special case and fix trailing comment identification to use it. This also changes WhitespaceManager to sum the length of all Changes inside of a token into the first Change. Before this fix int xy; // a int z; //b became int xy; // a int z; // b with this patch we immediately get to: int xy; // a int z; // b Differential Revision: http://reviews.llvm.org/D16058 llvm-svn: 257341
* This fixes https://llvm.org/bugs/show_bug.cgi?id=25329, as well asDaniel Jasper2015-12-011-12/+1
| | | | | | | | | | | misalignments like the following: int a, b = 2; int c = 3; Patch by Beren Minor, thanks! llvm-svn: 254406
* SourceRanges are small and trivially copyable, don't them by reference.Craig Topper2015-10-041-2/+2
| | | | llvm-svn: 249259
* [clang-format] Add support of consecutive declarations alignmentDaniel Jasper2015-10-011-1/+10
| | | | | | | | | | | | | | | | | | | This allows clang-format to align identifiers in consecutive declarations. This is useful for increasing the readability of the code in the same way the alignment of assignations is. The code is a slightly modified version of the consecutive assignment alignment code. Currently only the identifiers are aligned, and there is no support of alignment of the pointer star or reference symbol. The patch also solve the issue of alignments not being possible due to the ColumnLimit for both the existing AlignConsecutiveAligments and the new AlignConsecutiveDeclarations. Patch by Beren Minor, thank you. Review: http://reviews.llvm.org/D12362 llvm-svn: 248999
* clang-format: clang-format (NFC)Daniel Jasper2015-06-171-2/+4
| | | | llvm-svn: 239903
* clang-format: Add ability to align assignment operators.Daniel Jasper2015-04-291-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | In Objective-C some style guides use a style where assignment operators are aligned, in an effort to increase code readability. This patch adds an option to the format library which allows this functionality. It is disabled by default for all the included styles, so it must be explicitly enabled. The option will change code such as: - (void)method { NSNumber *one = @1; NSNumber *twentyFive = @25; } to: - (void)method { NSNumber *one = @1; NSNumber *twentyFive = @25; } Patch by Matt Oakes. Thank you! Accidentally reformatted all the tests... llvm-svn: 236100
* 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-3/+23
| | | | | | | | | | | | | | | | | | | | | | 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
* Fix a tranche of comment, test and doc typosAlp Toker2013-12-051-1/+1
| | | | llvm-svn: 196510
* Support formatting of preprocessor branches.Manuel Klimek2013-10-111-1/+4
| | | | | | | | | | | | | | | | | | | | | 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
* Implemented tab usage only for indentation (http://llvm.org/PR17363)Alexander Kornienko2013-09-271-5/+12
| | | | | | | | | | | | | | | | | | | 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-1/+2
| | | | | | | | | | | | | | | | | | 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
* Support for CR LF newlines.Alexander Kornienko2013-09-111-7/+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
* Reformat clang-format's source files after r185822 and others.Daniel Jasper2013-07-081-3/+2
| | | | llvm-svn: 185823
* Insert a space at the start of a line comment in case it starts with an ↵Alexander Kornienko2013-06-111-11/+13
| | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | 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
* Major refactoring of BreakableToken.Manuel Klimek2013-05-271-8/+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
* Makes whitespace management more consistent.Manuel Klimek2013-05-221-53/+109
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Implements UseTab for clang-format.Manuel Klimek2013-05-131-0/+2
| | | | | | This is required for kernel linux kernel style formatting. llvm-svn: 181693
* Add option to align escaped newlines left.Daniel Jasper2013-04-251-10/+24
| | | | | | | | | | | | | | | 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
* Fix comment alignment behavior.Daniel Jasper2013-04-241-3/+3
| | | | | | | | | | | In the following snippet, clang-format incorrectly aligned the trailing comment, when only the last line was formatted: int aaaaaa; // comment int b; int c; // Formatting only this line moved this comment. llvm-svn: 180173
* Unified token breaking logic: support for line comments.Alexander Kornienko2013-04-171-15/+0
| | | | | | | | | | | | | | | | | | | 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/+120
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