Commit Graph

110 Commits

Author SHA1 Message Date
Yang Fan ad50c86333
[clang-format] Fix MSVC "unsafe use of type 'bool' in operation" warning (NFC)
MSVC warning:
```
\llvm-project\clang\lib\Format\BreakableToken.cpp(1002): warning C4804: '-': unsafe use of type 'bool' in operation
```
2021-02-03 10:50:59 +08:00
Björn Schäpers 772eb24e00 [clang-format] Add option to control the spaces in a line comment
Differential Revision: https://reviews.llvm.org/D92257
2021-02-01 22:48:50 +01:00
Björn Schäpers 4ad41f1daf Revert "[clang-format] Add option to control the spaces in a line comment"
This reverts commit 078f30e04d.
2021-01-29 09:30:52 +01:00
Björn Schäpers 078f30e04d [clang-format] Add option to control the spaces in a line comment
Differential Revision: https://reviews.llvm.org/D92257
2021-01-29 07:00:08 +01:00
Björn Schäpers 9aa38a0615 [clang-format] [NFC] Remove unsued arguments 2021-01-25 21:02:41 +01:00
Björn Schäpers 7c8b9c102f [clang-format] [NFC] Restructure getLineCommentIndentPrefix
When sorting the known prefixes after length the if in the loop will hit
at most once, so we can return from there.

Also replace the inner loop with an algorithm, that makes it more
readable.

Differential Revision: https://reviews.llvm.org/D95081
2021-01-25 21:02:40 +01:00
Björn Schäpers 6cb2887971 [clang-format] [NFC] Use some constexpr StringRef
Instead of const char*.

Differential Revision: https://reviews.llvm.org/D95078
2021-01-25 21:02:40 +01:00
Björn Schäpers 374f1d81fe [clang-format] Fix handling of TextProto comments
Differential Revision: https://reviews.llvm.org/D93163
2020-12-23 22:07:13 +01:00
mydeveloperday 031743cb5b [clang-format] PR48539 ReflowComments breaks Qt translation comments
https://bugs.llvm.org/show_bug.cgi?id=48539

Add support for Qt Translator Comments to reflow

When reflown and a part of the comments are added on a new line, it should repeat these extra characters as part of the comment token.

Reviewed By: curdeius, HazardyKnusperkeks

Differential Revision: https://reviews.llvm.org/D93490
2020-12-23 14:45:14 +00:00
Björn Schäpers 36306403d4 [clang-format] Remove double trim
Lines[i] is already trimmed 3 lines before

Differential Revision: https://reviews.llvm.org/D91996
2020-12-13 14:16:54 +01:00
Krasimir Georgiev 77b4841169 [clang-format] do not break before @tags in JS comments
In JavaScript breaking before a `@tag` in a comment puts it on a new line, and
machinery that parses these comments will fail to understand such comments.

This adapts clang-format to not break before `@`. Similar functionality exists
for not breaking before `{`.

Reviewed By: mprobst

Differential Revision: https://reviews.llvm.org/D91078
2020-11-11 12:27:15 +01:00
Krasimir Georgiev 7b7170fa57 [clang-format] avoid introducing multiline comments
In C++ with -Werror=comment, multiline comments are not allowed.
clang-format could accidentally introduce multiline comments when reflowing.
This adapts clang-format to not introduce multiline comments by not allowing a
break after `\`. Note that this does not apply to comment lines that already are
multiline comments, such as comments in macros.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90949
2020-11-09 15:29:09 +01:00
Krasimir Georgiev 2dbcbd357d [clang-format] do not break before { in JS comments
In JavaScript some @tags can be followed by `{`, and machinery that parses
these comments will fail to understand the comment if followed by a line break.

clang-format already handles this case by not breaking before `{` in comments.
However this was not working in cases when the column limit falls within `@tag`
or between `@tag` and `{`. This adapts clang-format for this case.

Reviewed By: mprobst

Differential Revision: https://reviews.llvm.org/D90908
2020-11-06 10:34:10 +01:00
mydeveloperday e8111502d8 [clang-format] use spaces for alignment with UT_ForContinuationAndIndentation
Summary:
Use spaces instead of tabs for alignment with UT_ForContinuationAndIndentation to make the code aligned for any tab/indent width.

Fixes https://bugs.llvm.org/show_bug.cgi?id=38381

Reviewed By: MyDeveloperDay

Patch By: fickert

Tags: #clang-format

Differential Revision: https://reviews.llvm.org/D75034
2020-04-13 15:14:26 +01:00
Benjamin Kramer 52dcbcbfe0 Simplify string joins. NFCI. 2020-04-11 17:20:11 +02:00
Benjamin Kramer adcd026838 Make llvm::StringRef to std::string conversions explicit.
This is how it should've been and brings it more in line with
std::string_view. There should be no functional change here.

This is mostly mechanical from a custom clang-tidy check, with a lot of
manual fixups. It uncovers a lot of minor inefficiencies.

This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-28 23:25:25 +01:00
Thomas Preud'homme b81cc60329 [clang][NFC] Make various uses of Regex const
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
2019-11-19 16:15:21 +00:00
Nico Weber ff9f4b5489 clang-format clang/lib/Format
llvm-svn: 367225
2019-07-29 13:26:48 +00:00
Owen Pan 3dcb892d2d [clang-format] Fix bug in block comment reflow that joins * and /
Fixes PR41213

Differential Revision: https://reviews.llvm.org/D61276

llvm-svn: 359943
2019-05-03 23:15:40 +00:00
Owen Pan 108cbbc262 [clang-format] Fix bug in reflow of block comments containing CR/LF
Fix PR36119

Differential Revision: https://reviews.llvm.org/D60996

llvm-svn: 359029
2019-04-23 20:29:46 +00:00
Paul Hoad 5bcf99b4bd [clang-format] [NFC] clang-format the Format library
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
2019-03-01 09:09:54 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
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
2019-01-19 08:50:56 +00:00
Martin Probst f326b6b975 clang-format: [JS] don't break comments before any '{'
Summary:
Previously, clang-format would avoid breaking before the first `{`
found, but then happily break before subsequent '{'s on the line. This
change fixes that by looking for the first location that has no opening
curly, if any.

This fixes the original commit by correcting the loop condition.

This reverts commit 66dc646e09b795b943668179c33d09da71a3b6bc.

Reviewers: krasimir

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D50249

llvm-svn: 338890
2018-08-03 13:58:33 +00:00
Tim Northover 608f136dbb Revert "clang-format: [JS] don't break comments before any '{'"
This reverts commit r338837, it introduced an infinite loop on all bots.

llvm-svn: 338879
2018-08-03 12:19:22 +00:00
Martin Probst ec45bc2fea clang-format: [JS] don't break comments before any '{'
Summary:
Previously, clang-format would avoid breaking before the first `{`
found, but then happily break before subsequent '{'s on the line. This
change fixes that by looking for the first location that has no opening
curly, if any.

Reviewers: krasimir

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D50230

llvm-svn: 338837
2018-08-03 09:34:41 +00:00
Martin Probst 9d7178139c clang-format: fix a crash in comment wraps.
Summary:
Previously, clang-format would crash if it tried to wrap an overlong
single line comment, because two parts of the code inserted a break in
the same location.

    /** heregoesalongcommentwithnospace */

This wasn't previously noticed as it could only trigger for an overlong
single line comment that did have no breaking opportunities except for a
whitespace at the very beginning.

This also introduces a check for JavaScript to not ever wrap a comment
before an opening curly brace:

    /** @mods {donotbreakbeforethecurly} */

This is because some machinery parsing these tags sometimes supports
breaks before a possible `{`, but in some other cases does not.
Previously clang-format was careful never to wrap a line with certain
tags on it. The better solution is to specifically disable wrapping
before the problematic token: this allows wrapping and aligning comments
but still avoids the problem.

Reviewers: krasimir

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D50177

llvm-svn: 338706
2018-08-02 11:52:08 +00:00
Krasimir Georgiev 186478d8e2 [clang-format] Add @private to the list of jsdoc annotations
Reviewers: mprobst

Reviewed By: mprobst

Subscribers: acoomans, cfe-commits

Differential Revision: https://reviews.llvm.org/D50138

llvm-svn: 338519
2018-08-01 11:48:04 +00:00
Fangrui Song 6907ce2f8f Remove trailing space
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h}

llvm-svn: 338291
2018-07-30 19:24:48 +00:00
Krasimir Georgiev 6a5c95bd66 [clang-format] Indent after breaking Javadoc annotated line
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
2018-07-30 08:45:45 +00:00
Krasimir Georgiev 4fc55a76b8 [clang-format] Fix crash while reflowing backslash in comments
Summary:
The added test case was currently crashing with an assertion:
```
krasimir@krasimir> cat test.cc                                                                                                                                                              ~
// How to run:
// bbbbb run \
// rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr \
// <log_file> -- --output_directory="<output_directory>"
krasimir@krasimir> ~/work/llvm-build/bin/clang-format test.cc                                                                                                                               ~
clang-format: /usr/local/google/home/krasimir/work/llvm/tools/clang/lib/Format/WhitespaceManager.cpp:117: void clang::format::WhitespaceManager::calculateLineBreakInformation(): Assertion `PreviousOriginalWhitespaceEndOffset <= OriginalWhitespaceStartOffset' failed.
```
The root cause was that BreakableToken was not considering the case of a reflow between an unescaped newline in a line comment.

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D48089

llvm-svn: 334527
2018-06-12 19:33:15 +00:00
Krasimir Georgiev 45dde418a9 [clang-format] Consider tok::hashhash in python-style comments
Summary: We were missing the case when python-style comments in text protos start with `##`.

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D47870

llvm-svn: 334179
2018-06-07 09:46:24 +00:00
Nicola Zaghen 3538b39ed5 [clang] Update uses of DEBUG macro to LLVM_DEBUG.
The DEBUG() macro is very generic so it might clash with other projects.
The renaming was done as follows:
- git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
- git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM

Explicitly avoided changing the strings in the clang-format tests.

Differential Revision: https://reviews.llvm.org/D44975

llvm-svn: 332350
2018-05-15 13:30:56 +00:00
Adrian Prantl 9fc8faf9e6 Remove \brief commands from doxygen comments.
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
2018-05-09 01:00:01 +00:00
Benjamin Kramer f76861c231 [format] Eliminate global destructors.
llvm-svn: 328047
2018-03-20 21:52:19 +00:00
Krasimir Georgiev 55c23a10c2 [clang-format] Ignore UnbreakableTailLength sometimes during breaking
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
2018-01-23 11:26:19 +00:00
Manuel Klimek 48c930cb1e Fix bug where we wouldn't break columns over the limit.
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
2017-12-04 08:53:16 +00:00
Manuel Klimek 477f369433 Fix 'control reaches end of non-void' warning by using llvm_unreachable.
llvm-svn: 319318
2017-11-29 15:09:12 +00:00
Manuel Klimek 93699f4d58 Restructure how we break tokens.
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
2017-11-29 14:29:43 +00:00
Manuel Klimek 7786614350 Implement more accurate penalty & trade-offs while breaking protruding tokens.
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
2017-11-17 11:17:15 +00:00
Manuel Klimek 45ab559ee7 Refactor ContinuationIndenter's breakProtrudingToken logic.
Create more orthogonal pieces. The restructuring made it easy to try out
several alternatives to D33589, and while none of the alternatives
turned out to be the right solution, the underlying simplification of
the structure is helpful.

Differential Revision: https://reviews.llvm.org/D39900

llvm-svn: 318141
2017-11-14 09:19:53 +00:00
Krasimir Georgiev 410ed245f6 [clang-format] Support python-style comments in text protos
Summary: This patch adds support for python-style comments in text protos.

Reviewers: djasper

Reviewed By: djasper

Subscribers: bkramer, cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D39806

llvm-svn: 317886
2017-11-10 12:50:09 +00:00
Krasimir Georgiev 35599fdfa0 [clang-format] Break non-trailing comments, try 2
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
2017-10-16 09:08:53 +00:00
Manuel Klimek 89628f6414 clang-format clang-format.
llvm-svn: 313744
2017-09-20 09:51:03 +00:00
Krasimir Georgiev 33bd852408 [clang-format] Emit absolute splits before lines for comments, try 2
Summary:
This recommits https://reviews.llvm.org/D36956 with an update to the added test
case to not use raw string literals, since this makes gcc unhappy.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D37109

llvm-svn: 311672
2017-08-24 16:41:10 +00:00
Krasimir Georgiev 48a9f36876 Revert "[clang-format] Emit absolute splits before lines for comments"
This reverts commit r311559, which added a test containing raw string
literals in macros, which chokes gcc:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55971

llvm-svn: 311566
2017-08-23 15:58:10 +00:00
Krasimir Georgiev 7f7c3dc0aa [clang-format] Emit absolute splits before lines for comments
Summary:
This patch makes the splits emitted for the beginning of comment lines during
reformatting absolute. Previously, they were relative to the start of the
non-whitespace content of the line, which messes up further TailOffset
calculations in breakProtrudingToken. This fixes an assertion failure reported
in bug 34236: https://bugs.llvm.org/show_bug.cgi?id=34236.

Reviewers: djasper

Reviewed By: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D36956

llvm-svn: 311559
2017-08-23 15:16:47 +00:00
Krasimir Georgiev 3b86534a63 [clang-format] Put '/**' and '*/' on own lines in jsdocs ending in comment 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
2017-08-09 09:42:32 +00:00
Krasimir Georgiev 22d7e6b08d [clang-format] Put '/**' and '*/' on own lines in multiline jsdocs
Reviewers: mprobst

Reviewed By: mprobst

Subscribers: cfe-commits, klimek

Differential Revision: https://reviews.llvm.org/D35683

llvm-svn: 308684
2017-07-20 22:29:39 +00:00
Francois Ferrand a881be87ca clang-format: do not reflow bullet lists
Summary:
This patch prevents reflowing bullet lists in block comments.

It handles all lists supported by doxygen and markdown, e.g. bullet
lists starting with '-', '*', '+', as well as numbered lists starting
with -# or a number followed by a dot.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: djasper, klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D33285

llvm-svn: 303556
2017-05-22 14:47:17 +00:00
Krasimir Georgiev ba6b315ea9 clang-format: fix prefix for doxygen comments after member
Summary:
Doxygen supports putting documentation blocks after member, by adding
an additional < marker in the comment block. This patch makes sure
this marker is used in lines which are introduced by breaking the
comment.

  int foo; ///< Some very long comment.

becomes:

  int foo; ///< Some very long
           ///< comment.

Contributed by @Typz!

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: djasper, klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D33282

llvm-svn: 303330
2017-05-18 07:36:21 +00:00