summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/WhitespaceManager.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [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
* Reformat clang-format's source files after r185822 and others.Daniel Jasper2013-07-081-9/+8
| | | | llvm-svn: 185823
* Don't align "} // namespace" comments.Daniel Jasper2013-07-011-7/+17
| | | | | | | | | | | | | | | | This is not all bad, but people are often surprised by it. Before: namespace { int SomeVariable = 0; // comment } // namespace After: namespace { int SomeVariable = 0; // comment } // namespace llvm-svn: 185327
* Fixes incorrect indentation of line comments after break and re-alignment.Alexander Kornienko2013-06-171-4/+7
| | | | | | | | | | | | | | | | | | | Summary: Selectively propagate the information about token kind in WhitespaceManager::replaceWhitespaceInToken.For correct alignment of new segments of line comments in order to align them correctly. Don't set BreakBeforeParameter in breakProtrudingToken for line comments, as it introduces a break after the _next_ parameter. Added tests for related functions. Reviewers: klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D980 llvm-svn: 184076
* Insert a space at the start of a line comment in case it starts with an ↵Alexander Kornienko2013-06-111-17/+16
| | | | | | | | | | | | | | | | | | | | 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-4/+3
| | | | | | | | | | 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
* Make UnwrappedLines and AnnotatedToken contain pointers to FormatToken.Manuel Klimek2013-05-281-4/+4
| | | | | | The FormatToken is now not copyable any more. llvm-svn: 182772
* Major refactoring of BreakableToken.Manuel Klimek2013-05-271-19/+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
* Fix aligning of comments.Manuel Klimek2013-05-231-4/+5
| | | | | | | | | | | | | | | | | Previously we started sequences to align for single line comments when the previous line had a trailing comment, but the sequence was broken for other reasons. Now we re-format: // a // b f(); // c to: // a // b f(); // c llvm-svn: 182608
* Fix aligning of comments that are at the start of the line.Manuel Klimek2013-05-231-3/+4
| | | | | | | | | | Now correctly leaves: f(); // comment // comment g(); // comment ... alone if the middle comment was aligned with g() before formatting. llvm-svn: 182605
OpenPOWER on IntegriCloud