summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/WhitespaceManager.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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
* [clang] Change std::sort to llvm::sort in response to r327219Mandeep Singh Grang2018-03-271-1/+1
| | | | | | | | | | | r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. llvm-svn: 328636
* [clang-format] Format raw string literalsKrasimir Georgiev2017-10-301-0/+5
| | | | | | | | | | | | | | | 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
* clang-format clang-format.Manuel Klimek2017-09-201-9/+7
| | | | llvm-svn: 313744
* [Format] Invert nestingAndIndentLevel pair in WhitespaceManager used forDaniel Jasper2017-08-251-8/+8
| | | | | | | | | | | | | 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] Align trailing comments if ColumnLimit is 0Krasimir Georgiev2017-08-231-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: ColumnLimit = 0 means no limit, so comment should always be aligned if requested. This was broken with https://llvm.org/svn/llvm-project/cfe/trunk@304687 introduced via https://reviews.llvm.org/D33830 and is included in 5.0.0-rc2. This commit fixes it and adds a unittest for this property. Should go into clang-5.0 IMHO. Contributed by @pboettch! Reviewers: djasper, krasimir Reviewed By: djasper, krasimir Subscribers: hans, klimek Differential Revision: https://reviews.llvm.org/D36967 llvm-svn: 311532
* clang-format: Fix bug with ENAS_DontAlign and empty linesJacob Bandes-Storch2017-08-101-9/+11
| | | | | | | | 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] Fix alignment of preprocessor trailing commentsKrasimir Georgiev2017-06-071-8/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch is a follow-up of https://reviews.llvm.org/rL304687, which fixed an overflow in the comment alignment code in clang-format. The token length of trailing comments of preprocessor directives is calculated incorrectly by including the text between consecutive directives. That causes them to not being aligned. For example, in this code with column limit 20 ``` #if A #else // A int iiii; #endif // B ``` the length of the token `// A` was wrongly calculated as 14 = 5 (the size of `// A\n`) plus 9 (the size of `int iiii;`) and so `// A` wouldn't be aligned with `// B` and this was produced: ``` #if A #else // A int iiii; #endif // B ``` This patch fixes this case. Reviewers: alexfh Reviewed By: alexfh Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D33982 llvm-svn: 304912
* [clang-format] Don't align too long broken trailing commentsKrasimir Georgiev2017-06-041-2/+4
| | | | | | | | | | | | | | | | | | Summary: This patch fixes a bug where clang-format will align newly broken trailing comments even if this will make them exceed the line limit. The bug was caused by a combination of unsigned arithmetic overflow and an imprecise computation of the length of broken comment lines. Reviewers: djasper, alexfh Reviewed By: alexfh Subscribers: klimek Differential Revision: https://reviews.llvm.org/D33830 llvm-svn: 304687
* [clang-format] Convert AlignEscapedNewlinesLeft to an enum, addingDaniel Jasper2017-05-081-4/+7
| | | | | | | | | | | | | | | | | | | | DontAlign This converts the clang-format option AlignEscapedNewlinesLeft from a boolean to an enum, named AlignEscapedNewlines, with options Left (prev. true), Right (prev. false), and a new option DontAlign. When set to DontAlign, the backslashes are placed just after the last token in each line: #define EXAMPLE \ do { \ int x = aaaaa; \ int b; \ int dddddddddd; \ } while (0) Patch by jtbandes. Thank you! llvm-svn: 302428
* Fix issues in clang-format's AlignConsecutive modes.Nikola Smiljanic2017-03-231-43/+97
| | | | | | Patch by Ben Harper. llvm-svn: 298574
* [clang-format] Re-align broken comment lines where appropriate.Krasimir Georgiev2017-02-031-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The comment aligner was skipping over newly broken comment lines. This patch fixes that. source: ``` int ab; // line int a; // long long ``` format with column limit 15 before: ``` int ab; // line int a; // long // long ``` format with column limit 15 after: ``` int ab; // line int a; // long // long ``` Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29486 llvm-svn: 293997
* [clang-format] Refactor WhitespaceManager and friendsDaniel Jasper2017-01-311-59/+57
| | | | | | | | | | | | | | | | | | | 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-1/+32
| | | | | | | | | | | | | | | | | | 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
* Use after move bug fixesPiotr Padlewski2016-12-231-2/+3
| | | | | | | | | | | | Summary: Bunch of fixed bugs in Clang after running misc-use-after-move in clang-tidy. Reviewers: rsmith, mboehme Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D27752 llvm-svn: 290424
* [Format] Remove dead code.Benjamin Kramer2016-12-191-5/+0
| | | | | | No functionality change. llvm-svn: 290135
* Bug 28065 - clang-format incorrectly aligns backslash.Andi-Bogdan Postelnicu2016-10-261-1/+1
| | | | llvm-svn: 285178
* Implement tooling::Replacements as a class.Eric Liu2016-08-011-1/+6
| | | | | | | | | | | | | | | | | | | Summary: - Implement clang::tooling::Replacements as a class to provide interfaces to control how replacements for a single file are combined and provide guarantee on the order of replacements being applied. - tooling::Replacements only contains replacements for the same file now. Use std::map<std::string, tooling::Replacements> to represent multi-file replacements. - Error handling for the interface change will be improved in followup patches. Reviewers: djasper, klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D21748 llvm-svn: 277335
* clang-format: Implemented tab usage for continuation and indentationMarianne Mailhot-Sarrasin2016-04-141-0/+8
| | | | | | | | | | Use tabs to fill whitespace at the start of a line. Patch by Maxime Beaulieu Differential Revision: http://reviews.llvm.org/D19028 llvm-svn: 266320
* clang-format: Fix alignment of trailing multiline columns.Daniel Jasper2016-02-011-10/+14
| | | | llvm-svn: 259351
* [clang-format] Fix comment aligning when there are changes within the commentBenjamin Kramer2016-01-111-14/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* clang-format: Improve selective comment formatting.Daniel Jasper2016-01-091-7/+14
| | | | | | | | | | | | | | | | | | | Starting here: int x; // Format this line only. int xx; // int xxxxx; // Before: int x; // Format this line only. int xx; // int xxxxx; // After: int x; // Format this line only. int xx; // int xxxxx; // llvm-svn: 257258
* This fixes https://llvm.org/bugs/show_bug.cgi?id=25329, as well asDaniel Jasper2015-12-011-190/+132
| | | | | | | | | | | misalignments like the following: int a, b = 2; int c = 3; Patch by Beren Minor, thanks! llvm-svn: 254406
* [clang-format] Stop alignment sequences on open braces and parens whenDaniel Jasper2015-10-071-8/+28
| | | | | | | | | | | | | | | | | aligning assignments. This was done correctly when aligning the declarations, but not when aligning assignments. FIXME: The code between assignments and declarations alignment is roughly duplicated and would benefit from factorization. Bug 25090: https://llvm.org/bugs/show_bug.cgi?id=25090 Patch by Beren Minor. Thank you. llvm-svn: 249552
* 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-10/+133
| | | | | | | | | | | | | | | | | | | 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: Fix alignConsecutiveAssignments.Daniel Jasper2015-09-221-34/+44
| | | | | | | | | | | | | It wasn't correctly handling this case: int oneTwoThree = 123; int oneTwo = 12; method(); Review: http://reviews.llvm.org/D12369 Patch by Beren Minor. Thank you! llvm-svn: 248254
* [Format] Skip creating temporary std::strings when filling another string.Benjamin Kramer2015-05-281-6/+6
| | | | | | No functional change intended. llvm-svn: 238466
* clang-format: Add ability to align assignment operators.Daniel Jasper2015-04-291-0/+91
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* Make sure we initialize all values in WhitespaceManager::Change.Manuel Klimek2015-03-031-2/+3
| | | | llvm-svn: 231067
* clang-format: Fix access to uninitialized memory.Daniel Jasper2015-03-031-0/+1
| | | | | | | | | With incomplete code, we aren't guaranteed to generated changes for every token. In that case, we need to assume that even the very first change can continue a preprocessor directive and initialize values accordingly. llvm-svn: 231066
* clang-format: Fix crasher caused by not properly setting dry-run.Daniel Jasper2015-01-291-0/+5
| | | | llvm-svn: 227427
* clang-format: Understand single-line comments at the end of blocks.Daniel Jasper2015-01-071-4/+6
| | | | | | | | | | | This prevents clang-format from moving/aligning the comment in the snippet: void f() { int i; // some comment // some unrelated comment } llvm-svn: 225352
* clang-format: Refactoring.Daniel Jasper2014-11-251-1/+1
| | | | | | Re-apply r222638 and r222641 without variadic templates. llvm-svn: 222747
* Reverting r222638; it broke the MSVC build bots because Visual Studio 2012 ↵Aaron Ballman2014-11-241-1/+1
| | | | | | does not support variadic templates. Also reverting r222641 because it was relying on 222638. llvm-svn: 222656
* clang-format: Refactoring.Daniel Jasper2014-11-231-1/+1
| | | | | | | Provide more overloads to simplify testing the type of a token. No functional changes intended. llvm-svn: 222638
* clang-format: Fix bug introduced by r208392.Daniel Jasper2014-05-091-3/+2
| | | | | | Also run clang-format over clang-format's files. llvm-svn: 208409
* clang-format: Fix bug when aligning trailing /**/-comments in macros.Daniel Jasper2014-04-271-1/+2
| | | | | | | Previously this could lead to a column limit violation with the required escaped newlines. llvm-svn: 207351
* Fix alignment of trailing block comments.Alexander Kornienko2014-04-171-61/+85
| | | | | | | | | | | | | | | | | | | | | | 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
* clang-format: Fix aligning of comments and escaped newlines in macros.Daniel Jasper2014-03-281-0/+4
| | | | | | | | | | | | | | Before: #define A \ int i; /*a*/ \ int jjj; /*b*/ After: #define A \ int i; /*a*/ \ int jjj; /*b*/ llvm-svn: 205011
* 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
OpenPOWER on IntegriCloud