This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Handle trailing comment sections in import statement lines
ClosedPublic

Authored by krasimir on May 19 2017, 3:33 AM.

Details

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.

Diff Detail

Repository
rL LLVM

Event Timeline

krasimir created this revision.May 19 2017, 3:33 AM
krasimir added a subscriber: cfe-commits.
djasper accepted this revision.May 19 2017, 3:41 AM

nice

lib/Format/ContinuationIndenter.cpp
590 ↗(On Diff #99536)

Call this "ContinuePPDirective".

lib/Format/TokenAnnotator.cpp
713 ↗(On Diff #99536)

wat?

This revision is now accepted and ready to land.May 19 2017, 3:41 AM
krasimir updated this revision to Diff 99538.May 19 2017, 3:45 AM
krasimir marked 2 inline comments as done.
  • Address review comments
This revision was automatically updated to reflect the committed changes.