Commit Graph

132 Commits

Author SHA1 Message Date
Michael Ilseman
08ac432d3c [Import as member] Don't pair up get/set pairs from other modules
While inferring get/set, we paired them up even when one of them was
available through a custom objc header (e.g. a private
header). Instead, fail to pair them up. Test case added.
2016-04-13 13:08:16 -07:00
Joe Groff
7feb60da04 SILGen: Handle C functions imported as labeled unit constructors. 2016-04-13 08:17:04 -07:00
Joe Groff
fe7c1ca670 Clang importer: Global vars imported as static member properties are final. 2016-04-12 10:03:48 -07:00
Ted Kremenek
6eb16f6550 Revert "Clang importer: Global vars imported as static member properties are final." (#2155) 2016-04-12 08:24:29 -07:00
Joe Groff
08a4267f66 Clang importer: Global vars imported as static member properties are final. 2016-04-11 18:02:41 -07:00
Michael Ilseman
1fdd1535d1 [Import as member] Simplified SILGen test for global assert 2016-04-11 15:29:23 -07:00
Michael Ilseman
151a19d3b8 [Import as member] Fixes to apinotes and tests
Fixes and clarifies a few API notes, and adds some test cases showing
current SILGen issues.
2016-04-11 11:31:12 -07:00
practicalswift
ea0ac3ac67 [gardening] Remove all tabs in C++ code 2016-04-08 21:22:57 +02:00
Doug Gregor
138bbe2167 [Clang importer] Delay resolution of import-as-member declarations when needed.
It's possible for swift_name to make a global declaration into a
member of another entity that has not been seen yet. In such cases,
delay resolution until the end of the translation unit (module). Fixes
the rest of rdar://problem/25502497.
2016-04-05 00:03:36 -07:00
Doug Gregor
398d216eca [Clang importer] Always pass an effective context to importDeclContextOf.
Some of the callers to importDeclContextOf could and should have
passed an effective context, but didn't, so (e.g.) an enum defined in
C couldn't be mapped to a nested type in Swift. Eliminate the
single-argument importDeclContextOf honeypot so we remember to pass
down the effective Clang context. Fixes rdar://problem/25502497.
2016-04-04 15:18:37 -07:00
Joe Groff
56ed71096f IRGen: Ignore generic parameters of SIL @convention(c) types.
That's the lowering we get for C functions imported as members of protocols.
2016-03-30 13:59:48 -07:00
Michael Ilseman
884155c09c [Import as member] Refactor testing.
Separate out error tests, so that we can more extensively test
protocol and non-prototype errors. NFC
2016-03-28 15:41:48 -07:00
Michael Ilseman
4e4c511cf0 [Import as error] Error on non-prototyped function declarations 2016-03-28 15:41:48 -07:00
Michael Ilseman
bb43d88792 [Import as member] Bring up to date with fixes from master 2016-03-23 17:02:03 -07:00
Michael Ilseman
47e73ad4f1 Merge branch 'master' of github.com:apple/swift into import-as-member 2016-03-23 17:01:47 -07:00
Michael Ilseman
b7bcc294ea [Clang importer] Fix obscure issue with submodule protocols.
In the Clang importer, and only in submodules, the first protocol
typedef with NSObject that we try to import results in a hidden lookup
result. So, allow hidden lookups, which is benign and failure is
actually an issue of a malformed header. Gracefully handles failure.

Test case included that will reproduce the issue if AllowHidden is
disabled.
2016-03-23 10:07:00 -07:00
Michael Ilseman
a94e07d820 [Import as member] Adjust test case to work around unknown bug
There's an odd, and unknown bug in the Clang Importer where we seem to
fail a Clang lookup of NSObject the very first time we try. While I'm
still diagnosing this, un-block SILGen work.
2016-03-22 15:09:42 -07:00
Joe Groff
5db097d098 SILGen: Fixes for C functions imported as CF class members. 2016-03-21 19:33:22 -07:00
Michael Ilseman
7953a5494c [Import as member] Test protocol setter, which exposes a different failure path 2016-03-21 17:26:20 -07:00
Michael Ilseman
9a5613a36d [Import as member] tests for import-as-protocol-member 2016-03-21 17:03:25 -07:00
Joe Groff
aec7be3930 SILGen: Handle C functions imported as property accessors. 2016-03-18 13:23:40 -07:00
Joe Groff
c4a69e9d5d SILGen: Basic code generation for C functions imported as methods.
Introduce abstraction patterns for curried C-functions-as-methods for type lowering, and plumb the "foreign self parameter index" through call emission so that we emit the "self" parameter in the right position. This gets us handling C functions imported as methods with explicit swift_name attributes in simple, fully-applied cases. There's still more work to be done for properties, partial applications, and initializers introduced by extensions.
2016-03-17 10:43:25 -07:00
Michael Ilseman
eab9f975f7 [Import as member] Fix test case to test class importing 2016-03-11 13:50:46 -08:00
Michael Ilseman
2fc931494e [Import as member] Desugar to find the effective Clang decl context.
Adds incremental de-sugaring to any non-CF typedefs we find in our
types when trying to determine the effective DC. Additionally, cleans
up some logic and allows us to fail earlier on types we cannot
possibly extend.
2016-03-10 16:42:47 -08:00
Michael Ilseman
c494f2478a [Import as member] Extend 'Mutable' skipping to method inference 2016-03-10 13:27:44 -08:00
Michael Ilseman
de913b3512 [Import as member] Ignore all case for unique-concat-ing labels 2016-03-10 12:49:30 -08:00
Michael Ilseman
3dbbd69912 [Import as member] Special case 'Mutable' types
Recognize the special word Mutable in type names and other matches, so
as to import them onto the mutable type despite word re-ordering.
2016-03-10 11:55:38 -08:00
Michael Ilseman
594cf05331 [Import as member] Omit needless words
This hooks up omitNeedlessWords to import as member.

Unfortunately, we are now left straddling different approaches to
handling our strings, I'll be refactoring that soon.
2016-03-10 11:21:59 -08:00
Michael Ilseman
81f16c311a [Import as member] Skip globals whose names begin with underscore 2016-03-09 15:40:11 -08:00
Michael Ilseman
32faa62502 [Import as member] Lower case initialisms 2016-03-09 14:26:43 -08:00
Michael Ilseman
ff2db64b6f [Clang importer] Infer import as member name uniquing
In many contexts we may end up concatinating strings which introduce
redundancy in the resulting names. This uniques them.
2016-03-08 18:25:26 -08:00
Michael Ilseman
bbe1f7a0a5 [Clang importer] Extra correctness checks for inferring as properties.
Introduces validToImportAsProperty, which has to perform extra
checking the make sure that a get/set pair are compatible with import
as a property. This includes matching up 'self' parameters, matching
get's return type with the set's argument type, etc. Includes more
extensive tests.
2016-03-08 16:35:30 -08:00
Michael Ilseman
73f7fd2eb6 [Clang importer] Infer get-only properties and static properties.
Expands support for inference of computed properties, whether instance
or static, to include get-only. Adds test cases for both inference and
manual annotation for static computed properties.
2016-03-07 16:51:34 -08:00
Michael Ilseman
c39aebce24 [Clang importer] Infer static properties and methods
Adds inference support for static properties and methods, requiring us
to accurately do longest-prefix typename searches.

Tests cases included.
2016-03-07 16:36:59 -08:00
Michael Ilseman
23c818ed57 [Clang importer] Support static methods in swift_name 2016-03-07 15:58:01 -08:00
Michael Ilseman
3b8f498324 [Clang importer] Lower camel-case inferred names 2016-03-07 10:50:08 -08:00
Michael Ilseman
ff03498797 [Clang importer] Hook up inference system
Import as member inference hooked up, though not producing the final
results we want, yet.

Basic test case included.
2016-03-07 10:37:34 -08:00
Doug Gregor
94ba6e7a16 [Clang importer] Test import-as-member with CF types. 2016-03-06 22:31:51 -08:00
Doug Gregor
47b2be3138 [Clang importer] Import a getter or getter/setter pair as a property.
When a global function is determined to be a lone getter or a
getter/setter pair, import it as a property. Handle global, instance,
and static properties.

As part of this, generalize importAsMethod to also handle static
methods and map pointer-to-non-const arguments to 'mutating' methods.
2016-03-06 21:25:43 -08:00
Doug Gregor
d88f546f0a [Clang importer / Interface printing] Print extensions in the appropriate submodule.
When printing the interface for a (sub)module, make sure that we only
print those extensions that were created to hold that submodule's
globals that were imported as members.
2016-03-04 17:21:13 -08:00
Michael Ilseman
e452b38119 [Clang Importer] Import as methods
Print module functionality hooked up to import global functions a
methods, if dictated by the swift_name attribute. Test case included.

No SILGen support yet.
2016-03-03 21:58:57 -08:00
Doug Gregor
42f0356aec [Clang importer] Wire up extensions for globals-as-members.
Wire up the extensions created when importing globals-as-members via
the same mechanisms we use for Objective-C categories, e.g.,
implementing loadAllExtensions() to find the extensions and lazily
loading their members via the member loader. Addresses most of my
comments on the way extensions were wired in.

Extend our testing for importing globals as members to two different
submodules, so we can see the separation of extensions.

As part of this, fold getOrCreateExtension into importDeclContextOf.
2016-03-03 17:22:47 -08:00
Michael Ilseman
c247bbf5b6 [Clang Importer] Import as member: bare bones variables.
Adds tentative and very basic functionality for importing global
variables as members of structs and classes. Test case added
2016-03-02 22:19:37 -08:00
Doug Gregor
f7ee0349ea [Clang importer] (De-)serialize globals-as-members for Swift name lookup tables.
Round-trip the globals-as-members table used by the Swift name lookup
tables. At present, there are no clients of this information except
the dumper.
2016-03-01 18:13:35 -08:00
Doug Gregor
b890e4c29f [Omit needless words] Use the property lists to restrict BaseNameSelf pruning.
This eliminates some apparent inconsistencies in the translation,
fixing rdar://problem/24860176.
2016-02-29 13:14:23 -08:00
Doug Gregor
a94e91f8ef [Omit needless words] Properly compute context names for ObjC protocols. 2016-02-17 23:35:41 -08:00
Doug Gregor
ca736fd27c [Omit needless words] Ensure Swift name consistency for overriding/overridden decalrations.
When we transform an Objective-C method or property name, we take into
account the parameter types, result type, and type of the enclosing
context. Doing so means that one can get different Swift names for a
particular method (or property) and one that overrides it, which leads
to dangerous inconsistencies in the Swift names. Address this
limitation by using the original declaration's name (i.e., one that
does not override any other).

It is possible that there is more than one "original declaration",
when the same method/property name comes from different
protocols. When this is the case, check for consistency and complain
if there are inconsistencies.

Amusingly, this changes exactly one method in Cocoa
(UINavigationController's showViewController:sender:), with no conflicts
detected. Fixes rdar://problem/24558337.
2016-02-17 23:35:41 -08:00
Doug Gregor
ecf6df6e71 [Omit needless words] More broadly recognize collection types 2016-02-17 19:58:23 -08:00
Doug Gregor
bc18e4521b [Omit needless words] After "by", recognize gerunds more liberally. 2016-02-12 16:40:10 -08:00
Doug Gregor
0e46850a66 [Omit needless words] "ObjectValue" in the name matches "Object" in the type.
Fixes rdar://problem/24618946.
2016-02-12 12:41:40 -08:00