Commit Graph

44 Commits

Author SHA1 Message Date
Daniel Jasper e6fcf7d372 clang-format: clang-format (NFC)
llvm-svn: 239903
2015-06-17 13:08:06 +00:00
Daniel Jasper d6e618892f clang-format: Don't generate unnecessary replacements for \r\n line endings.
Patch by Mathieu Champlon. Thank you.

llvm-svn: 239900
2015-06-17 12:23:15 +00:00
Daniel Jasper dee894f6bb clang-format: Support //!-comments, increase test coverage.
llvm-svn: 239404
2015-06-09 13:16:54 +00:00
Daniel Jasper 6d9b88dd99 clang-format: Fix bug in multiline comment wrapping.
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
2015-05-06 07:17:22 +00:00
Daniel Jasper e4b48c635c clang-format: Fix crasher when splitting incomplete escape sequences.
llvm-svn: 226698
2015-01-21 19:50:35 +00:00
Alexander Kornienko 00691cf3bb Fix assertion in BreakableBlockComment (http://llvm.org/PR21916).
Reviewers: djasper

Reviewed By: djasper

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D6894

llvm-svn: 225628
2015-01-12 13:11:12 +00:00
Daniel Jasper b05a81debb clang-format: Fix bug introduced by r208392.
Also run clang-format over clang-format's files.

llvm-svn: 208409
2014-05-09 13:11:16 +00:00
Chandler Carruth 1034666777 [Modules] Fix potential ODR violations by sinking the DEBUG_TYPE
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
2014-04-22 03:17:02 +00:00
Alexander Kornienko 67d9c8c87e Fix alignment of trailing block comments.
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
2014-04-17 16:12:46 +00:00
Alexander Kornienko 4504f93901 Preserve hanging indent when breaking line comments.
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
2014-03-10 13:14:56 +00:00
Daniel Jasper d07c2ee99e clang-format: Fix bug introduced in r198871.
We cannot simply change the start column to accomodate for the @ in an
ObjC string literal as that will make clang-format happily violate the
column limit.

Use a different workaround instead. However, a better long-term
solution might be to join the @ and the rest of the literal into a
single token.

llvm-svn: 199198
2014-01-14 09:53:07 +00:00
Daniel Jasper 174b012524 clang-format: Add @s when breaking NSString literals.
While it is allowed to not have an @ on subsequent lines, it seems
general practice to add them. If undesired, the code author can easily
remove them again and clang-format won't re-add them.

llvm-svn: 198871
2014-01-09 14:18:12 +00:00
Alp Toker f6a24ce40f Fix a tranche of comment, test and doc typos
llvm-svn: 196510
2013-12-05 16:25:25 +00:00
Alexander Kornienko 71d95d6e51 Fix crash in getStringSplit.
Summary:
getStringSplit used to crash, when trying to split a long string
literal containing both printable and unprintable multi-byte UTF-8 characters.

Reviewers: djasper, klimek

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D2268

llvm-svn: 195728
2013-11-26 10:38:53 +00:00
Alexander Kornienko 875395f9f8 Remove extra whitespace instead of breaking the line in comments when possible.
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
2013-11-12 17:50:13 +00:00
Daniel Jasper 580da27616 clang-format: fix for \r\r\n produced in multiline block comments
Patch by Christopher Olsen. Thank you!

llvm-svn: 193678
2013-10-30 07:36:40 +00:00
Alexander Kornienko 3c3d09c885 Implemented tab usage only for indentation (http://llvm.org/PR17363)
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
2013-09-27 16:14:22 +00:00
Alexander Kornienko 81e3294e7e When in pre-c++11 mode, treat _T("xxx") as a single string literal, repeat 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
2013-09-16 20:20:49 +00:00
Alexander Kornienko 39856b71a6 Calculate and store ColumnWidth instead of CodePointCount in FormatTokens.
Summary:
This fixes various issues with mixed tabs and spaces handling, e.g.
when realigning block comments.

Reviewers: klimek, djasper

Reviewed By: djasper

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1608

llvm-svn: 190395
2013-09-10 09:38:25 +00:00
Alexander Kornienko ebb43caae2 Handle zero-width and double-width characters in string literals and comments.
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
2013-09-05 14:08:34 +00:00
Arnold Schwaighofer a8177a02ca Revert r187935 "Support for double width characters."
It broke a public build bot.

llvm-svn: 187957
2013-08-08 02:19:56 +00:00
Alexander Kornienko ca3e6311a1 Support for double width characters.
Summary: Only works for UTF-8-encoded files.

Reviewers: djasper

Reviewed By: djasper

CC: cfe-commits, klimek

Differential Revision: http://llvm-reviews.chandlerc.com/D1311

llvm-svn: 187935
2013-08-07 23:29:01 +00:00
Craig Topper d6d31aceea Add 'static' and 'const' qualifiers to some arrays of strings.
llvm-svn: 186314
2013-07-15 08:24:27 +00:00
Daniel Jasper 3ac9b9e258 Reformat clang-format's source files after r185822 and others.
llvm-svn: 185823
2013-07-08 14:34:09 +00:00
Alexander Kornienko 614d96a1f6 Fix for corner cases in code handling leading "* " decorations in block comments
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
2013-07-08 14:12:07 +00:00
Craig Topper bfb5c40bee Use static for helper functions instead of an anonymous namespace per coding standards.
llvm-svn: 185300
2013-07-01 03:38:29 +00:00
Craig Topper 6862dcc6da Make string pointer const.
llvm-svn: 185296
2013-06-30 22:44:02 +00:00
Alexander Kornienko b93062e236 Use the same set of whitespace characters for all operations in BreakableToken.
Summary:
Fixes a problem where \t,\v or \f could lead to a crash when placed as
a first character in a line comment. The cause is that rtrim and ltrim handle
these characters, but our code didn't, so some invariants could be broken.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1013

llvm-svn: 184425
2013-06-20 13:58:37 +00:00
Alexander Kornienko 7285207486 Split long strings on word boundaries.
Summary: Split strings at word boundaries, when there are no spaces and slashes.

Reviewers: klimek

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D1003

llvm-svn: 184304
2013-06-19 14:22:47 +00:00
Alexander Kornienko be633908be Don't remove backslashes from block comments.
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
2013-06-14 11:46:10 +00:00
Alexander Kornienko 555efc36d0 Insert a space at the start of a line comment in case it starts with an 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
2013-06-11 16:01:49 +00:00
Alexander Kornienko dd7ece53a2 Fixed calculation of penalty when breaking tokens.
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
2013-06-07 16:02:52 +00:00
Alexander Kornienko ffcc010767 UTF-8 support for clang-format.
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
2013-06-05 14:09:10 +00:00
Daniel Jasper ce257f296b More fixes for clang-format's multiline comment breaking.
llvm-svn: 182940
2013-05-30 17:27:48 +00:00
Daniel Jasper 58dd2f0652 Fix another clang-format crasher related to multi-line comments.
This fixes:
/*
*
* something long going over the column limit.
*/

llvm-svn: 182932
2013-05-30 15:20:29 +00:00
Manuel Klimek 8910d192d0 Add asserts to guard against regressions.
llvm-svn: 182916
2013-05-30 07:45:53 +00:00
Daniel Jasper 51fb2b2151 Fix crasher when formatting certain block comments.
Smallest reproduction:
/*
**
*/

llvm-svn: 182913
2013-05-30 06:40:07 +00:00
Manuel Klimek ae1fbfb740 Fixes error when splitting block comments.
When trying to fall back to search from the end onwards, we
would still find leading whitespace if the leading whitespace
went on after the end of the line.

llvm-svn: 182886
2013-05-29 22:06:18 +00:00
Manuel Klimek 34d15151c4 Disable tab expansion when counting the columns in block comments.
To fully support this, we also need to expand tabs in the text before
the block comment. This patch breaks indentation when there was a
non-standard mixture of spaces and tabs used for indentation, but
fixes a regression in the simple case:
{
  /*
   * Comment.
   */
  int i;
}
Is now formatted correctly, if there were tabs used for indentation
before.

llvm-svn: 182760
2013-05-28 10:01:59 +00:00
Manuel Klimek 281dcbe026 Fixes indentation of empty lines in block comments.
Block comment indentation of empty lines regressed, as we did not
have a test for it.
 /* Comment with...
  *
  * empty line. */
is now formatted correctly again.

llvm-svn: 182757
2013-05-28 08:55:01 +00:00
Manuel Klimek 9043c74f49 Major refactoring of BreakableToken.
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
2013-05-27 15:23:34 +00:00
Manuel Klimek 4fe43002f8 Makes whitespace management more consistent.
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
2013-05-22 12:51:29 +00:00
Alexander Kornienko 9e90b62e01 Unified token breaking logic: support for line comments.
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
2013-04-17 17:34:05 +00:00
Alexander Kornienko cb45bc1861 Unified token breaking logic for strings and block comments.
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
2013-04-15 14:28:00 +00:00