]> granicus.if.org Git - clang/commit
[clang-format] Fix ObjC style guesser to also iterate over child lines
authorBen Hamilton <benhamilton@google.com>
Thu, 22 Mar 2018 17:37:19 +0000 (17:37 +0000)
committerBen Hamilton <benhamilton@google.com>
Thu, 22 Mar 2018 17:37:19 +0000 (17:37 +0000)
commit6ef13cd268d2e88861e5240f6feb943d5c51b229
tree39e182a240f8d62137219f4b22ada6eb60ceb8a9
parent14d3260e442fbb80e956ef32be2a63c298933ef7
[clang-format] Fix ObjC style guesser to also iterate over child lines

Summary:
When I wrote `ObjCHeaderStyleGuesser`, I incorrectly assumed the
correct way to iterate over all tokens in `AnnotatedLine` was to
iterate over the linked list tokens starting with
`AnnotatedLine::First`.

However, `AnnotatedLine` also contains a vector
`AnnotedLine::Children` with child `AnnotedLine`s which have their own
tokens which we need to iterate over.

Because I didn't iterate over the tokens in the children lines, the
ObjC style guesser would fail on syntax like:

  #define FOO ({ NSString *s = ... })

as the statement(s) inside { ... } are child lines.

This fixes the bug and adds a test. I confirmed the test
failed before the fix, and passed after the fix.

Test Plan: New tests added. Ran tests with:
  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: djasper, jolesiak, Wizard

Reviewed By: djasper

Subscribers: klimek, cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328220 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Format/Format.cpp
unittests/Format/FormatTest.cpp