]> granicus.if.org Git - clang/commit
[clang-format] Handle trailing comment sections in import statement lines
authorKrasimir Georgiev <krasimir@google.com>
Fri, 19 May 2017 10:34:57 +0000 (10:34 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Fri, 19 May 2017 10:34:57 +0000 (10:34 +0000)
commit354737f8645852565854935d0242f1ebc5860372
tree704abff03bf286d5a2717c689f5c500e9791b7e7
parent6343907e0876463fe8c81319d2cdb5166674c2b0
[clang-format] Handle trailing comment sections in import statement lines

Summary:
This patch updates the handling of multiline trailing comment sections in
import statement lines to make it more consistent with the case in general.
This includes updating the parsing logic to collect the trailing comment
sections and the formatting logic to not insert escaped newlines at the end of
comment lines in import statement lines.

Specifically, before this patch this code:
```
#include <a> // line 1
             // line 2
```
will be turned into two unwrapped lines, whereas this code:
```
int i; // line 1
       // line 2
```
is turned into a single unwrapped line, enabling reflowing across comments.

An example where the old behaviour is bad is when partially formatting the lines
3 to 4 of this code:
```
#include <a> // line 1
             // line 2

int i;
```
which gets turned into:
```
#include <a> // line 1
             // line 2

             int i;
```
because the two comment lines were independent and the indent was copied.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303415 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Format/ContinuationIndenter.cpp
lib/Format/TokenAnnotator.cpp
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestSelective.cpp