This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Detect Objective-C for #import <Foundation/Foundation.h>
Needs ReviewPublic

Authored by benhamilton on Mar 19 2018, 9:28 AM.

Details

Reviewers
jolesiak
djasper
Summary

Previously, the Objective-C heuristic failed to detect
headers which #imported Objective-C system framework(s) and declared C
functions on top them.

This extends the heuristic to look for statements of the form:

and check if "Foo" is one of the known Objective-C system frameworks.

Test Plan: New tests added. Ran tests with:

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

Diff Detail

Event Timeline

benhamilton created this revision.Mar 19 2018, 9:28 AM

I'd really like to not parse include/import statements this way. Can you send me examples of headers where we fail to recognize them as ObjC and this matters (happy for you to send me examples offline).

clang-format

Add assert(std::is_sorted(...)). (We can't static_assert on is_sorted until C++2x.)

Wizard added a subscriber: Wizard.Mar 21 2018, 1:26 PM
This comment was removed by Wizard.

#import is perfectly legal in C and C++, it's just not commonly used.

Wizard added a comment.EditedMar 21 2018, 1:57 PM

For some ObjC headers it uses #import to import other headers instead of system framework, so I think we should also detect #import "*.h" as well.

The only usage of #import in C++ is to import type library, which won't have suffix of ".h" (https://msdn.microsoft.com/en-us/library/8etzzkb6.aspx)

I think we should reconsider applying this change, at least for a very common "#import <Foundation/Foundation.h>".