This is an archive of the discontinued LLVM Phabricator instance.

[clang-format/ObjC] Correctly annotate single-component ObjC method invocations
ClosedPublic

Authored by benhamilton on May 17 2018, 12:59 PM.

Details

Summary

Previously, clang-format's parser would fail to annotate the
selector in a single-component Objective-C method invocation with
TT_SelectorName. For example, the following:

[foo bar];

would parse bar as TT_Unknown:

M=0 C=1 T=Unknown S=0 B=0 BK=0 P=140 Name=identifier L=34 PPK=2
FakeLParens= FakeRParens=0 II=0x559d5db51770 Text='bar'

This caused us to fail to insert a space after a closing cast rparen,
so the following:

[((Foo *)foo) bar];

would format as:

[((Foo *)foo)bar];

This diff fixes the issue by ensuring we annotate the selector
in a single-component Objective-C method invocation as
TT_SelectorName.

Test Plan: New tests added. Ran tests with:

% make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests

Diff Detail

Repository
rC Clang

Event Timeline

benhamilton created this revision.May 17 2018, 12:59 PM
jolesiak accepted this revision.May 18 2018, 7:28 AM
jolesiak added inline comments.
lib/Format/TokenAnnotator.cpp
510

I'd remove braces for consistency.

This revision is now accepted and ready to land.May 18 2018, 7:28 AM
benhamilton marked an inline comment as done.

Style

lib/Format/TokenAnnotator.cpp
510

Thanks, done.

This revision was automatically updated to reflect the committed changes.