This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] make header guard identification stricter in header insertion.
AbandonedPublic

Authored by ioeric on Jun 1 2016, 4:54 AM.

Details

Reviewers
djasper
Summary

don't just identify first #define as header guard anymore. Use #ifndef
#define to tell if a #define belongs to header guard.

Diff Detail

Event Timeline

ioeric updated this revision to Diff 59199.Jun 1 2016, 4:54 AM
ioeric retitled this revision from to [clang-format] make header guard identification stricter in header insertion..
ioeric updated this object.
ioeric added a reviewer: djasper.
ioeric added a subscriber: cfe-commits.
ioeric updated this revision to Diff 59206.Jun 1 2016, 5:32 AM
  • Use iterator looping to simplify code.
djasper added inline comments.Jun 1 2016, 5:41 AM
lib/Format/Format.cpp
1472

I think there is too much in the regex group here. If there are trailing comments on the #ifndef or #define lines, this should still work. Also, there might actually be empty lines or comment lines in-between the two. I would for now just check that there:

  • Is no non-comment line before the first #ifndef
  • That there is a #ifndef
  • That the next non-comment line after the #ifndef is a #define

We can refine more if necessary.

I think we should be conservative here as this should only really ever affect .cc files (or else the header guard would be there and identified correctly) that don't have any #includes (or put them after unrelated #defines). So, we have to weigh this case being so rare against incorrectly identifying weird header guards in headers (which IMO might be more common).

ioeric added inline comments.Jun 1 2016, 6:11 AM
lib/Format/Format.cpp
1472

Okay.

I guess I should've work on the comment skipping FIXME first. I'll work on skipping comments first and then continue with this patch,

ioeric abandoned this revision.Jun 3 2016, 6:19 AM

Abandon this patch in favor of http://reviews.llvm.org/D20959