Commit Graph

549 Commits

Author SHA1 Message Date
Jordan Rose
3ba8808a6f [ClangImporter] When remapping an init method's name, change the selector too.
This is what we use to drop the variadic parameter on UIActionSheet and
UIAlertView's initializers, along with secretly adding a category to each
to provide the one-fewer-parameter init method implementation. However,
we haven't been using the Swift name for the method to generate Objective-C
calls for a while now--we use the @objc attribute. And that was still using
the original selector, and so we crashed.

Fixed by passing the new selector to the @objc attribute.

<rdar://problem/17012323>

Swift SVN r18582
2014-05-23 01:56:56 +00:00
Jordan Rose
f256d65669 [ClangImporter] NSProcessInfo.processInfo() is distinct from NSProcessInfo().
Thankfully, Doug already put in infrastructure for this, so it just required
adding one more entry to the table.

<rdar://problem/16995980>

Swift SVN r18537
2014-05-22 00:20:32 +00:00
Jordan Rose
e6db58a6ae [ClangImporter] Map u_int*_t [sic] to UInt*.
These types come from <sys/types.h> indirectly and show up in a few
interesting functions like arc4random_uniform.

This commit also introduces a new test file for mapping fixed-sized integers,
to eliminate boilerplate as we continue to rack up aliases for UInt*.

<rdar://problem/16978349>

Swift SVN r18505
2014-05-21 19:45:42 +00:00
Jordan Rose
8ef90ddf92 [test] Use __typeof__(__objc_yes) to get the right per-platform type for BOOL.
With this trick in place, re-enable test/IRGen/abitypes.swift.

<rdar://problem/16936814>

Swift SVN r18380
2014-05-19 01:14:29 +00:00
Doug Gregor
3b61830f81 Mark -[NSObject dealloc] as unavailable.
This is most of <rdar://problem/16486790>, solved trivially.

Swift SVN r18275
2014-05-17 21:43:34 +00:00
Doug Gregor
c0e218c982 Mark -[NSExtensionContext openURL:completion:] as unavailable <rdar://problem/16909180>
Swift SVN r18274
2014-05-17 21:37:14 +00:00
Doug Gregor
8b70f34ea8 Revert r18196: Clang importer: use T* type sugar when importing as UnsafePointer<T>.
Swift SVN r18254
2014-05-17 16:38:44 +00:00
Doug Gregor
2e499b8cdd Clang importer: use T* type sugar when importing as UnsafePointer<T>.
Swift SVN r18196
2014-05-16 15:44:25 +00:00
Joe Groff
8923d50f6a Revert "Define BOOL correctly for arm64 in the clang-importer-sdk."
This reverts commit r18159. There's a redundant definition in another header, and it's not worth messing with this now.

Swift SVN r18164
2014-05-16 02:43:35 +00:00
Joe Groff
45a6bbe831 Define BOOL correctly for arm64 in the clang-importer-sdk.
BOOL should also be _Bool on x86-64 simulator, but the clang importer preprocessor doesn't appear to have the necessary #defines to distinguish that currently.

Swift SVN r18159
2014-05-16 01:24:16 +00:00
Doug Gregor
d640eb4083 Introduce support for blacklisting factory-methods-as-inits.
Some fcactory methods shouldn't come in as initializers, per
<rdar://problem/16908950>.


Swift SVN r18101
2014-05-15 07:04:46 +00:00
Joe Groff
067f810be6 Parse and do basic checking for @UIApplicationMain.
Introduce the UIApplicationMain attribute, and check that it's only applied to nongeneric classes that conform to UIApplicationDelegate.

Swift SVN r18048
2014-05-14 01:06:52 +00:00
Jordan Rose
11947c4e86 [test] Change UTF-16 test to not mention the language name.
Just in case. I changed the emoji for "Swift" too, just for Joe.

Swift SVN r17985
2014-05-13 00:48:04 +00:00
Doug Gregor
2702c943aa When determining whether an imported initializer is a designated initializer, use the context it's being imported into.
Previously, we were using the context where the initializer was declared in Objective-C, rather than where it was being imported. This meant that we wouldn't treat an inherited designated initializer as a designated initializer if (for example) the designated-initializer marking came from our internal table of DIs. Fixes <rdar://problem/16838515>.

Swift SVN r17968
2014-05-12 22:47:38 +00:00
Ted Kremenek
4479eb85c0 Import +class and -class as unavailable, suggesting ".type" and ".dynamicType" instead.
Implements <rdar://problem/16871007>.

Swift SVN r17883
2014-05-11 20:22:53 +00:00
Doug Gregor
77ca640d42 Add -objc-bridge-array option to import NSArray* as (AnyObject[])!
This should be the last of the compiler-side functionality for
<rdar://problem/16535097>; we lack any real testing of this.


Swift SVN r17871
2014-05-11 06:29:13 +00:00
Doug Gregor
dc3ca1145d Loosen the constraints on bridging Dictionary<K, V>.
We now allow bridging so long as both K and V can be bridged to
Objective-C, as determined by _BridgedToObjectiveC conformance. Note
that Dictionary's implementation still needs to handle this, which is
tracked separately.

Swift SVN r17859
2014-05-11 00:08:41 +00:00
Doug Gregor
ef1c1a8892 Import NSDictionary* as Dictionary<NSObject, AnyObject>.
Note that this is still under -objc-bridge-dictionary, but otherwise
this should be all of the functionality needed for
<rdar://problem/16870626>.

Swift SVN r17848
2014-05-10 21:39:46 +00:00
Doug Gregor
4de43af267 PrintAsObjC: Print Dictionary<K, V> as "NSDictionary *"
Swift SVN r17839
2014-05-10 20:07:57 +00:00
John McCall
c03b705dd0 Recognize CF "subclasses" and require CFTypeRef to specifically
be 'const void *', not just any 'void*'.

Swift SVN r17659
2014-05-08 00:51:27 +00:00
Jordan Rose
f4f8e7c127 [ClangImporter] Add a special case for AVVideoCompositionInstruction.
...which, like NSObject, is a protocol that has the same name as a class.

Doing this more generally is tracked in <rdar://problem/16206627>.

Swift SVN r17583
2014-05-06 23:34:42 +00:00
Jordan Rose
9ba37a07a3 [PrintAsObjC] Print imported CF types using their typedefs.
Swift SVN r17577
2014-05-06 22:50:37 +00:00
Jordan Rose
829d3e6de9 [ClangImporter] Handle macros that use bitshifts, like "(1 << 0)".
<rdar://problem/16202229>

Swift SVN r17462
2014-05-05 17:37:03 +00:00
Jordan Rose
ac15f949d2 [ClangImporter] Import macros that use ~.
This and the previous commit cover <rdar://problem/16521124>.

Swift SVN r17461
2014-05-05 17:37:02 +00:00
Jordan Rose
9e61c4bb62 [ClangImporter] Import NULL, nil, Nil, and ((void*)0) as Swift.nil.
Also, look through one layer of parentheses in general for macros, rather
than special-casing it for each token count.

<rdar://problem/16198517>

Swift SVN r17460
2014-05-05 17:37:00 +00:00
Jordan Rose
2b1a092c27 [ClangImporter] Prefer typedef sugar for blocks even in bridge-able contexts.
We'd rather show dispatch_async as

  // new
  func dispatch_async(queue: dispatch_queue_t!, block: dispatch_block_t!)

than

  // old
  func dispatch_async(queue: dispatch_queue_t!, block: (() -> Void)!)

which was only happening because we were trying to hide the @objc_block
annotation when possible. That's not necessary when we have a typealias.

<rdar://problem/16679280>

Swift SVN r17273
2014-05-02 21:36:59 +00:00
Jordan Rose
16f96f1139 [PrintAsObjC] Guard @import lines with __has_feature(modules).
Also, use "#include <objc/NSObject.h>" instead of "@import ObjectiveC;"
to get access to BOOL, SEL, NSObject, and NSString.

This allows generated headers to be used in Objective-C++ contexts, where
modules don't yet work. The dependencies will unfortunately need to be
imported separately (because there's not a direct mapping from module name
back to header file), but that's still better than just being incompatible.

<rdar://problem/16796627>

Swift SVN r17272
2014-05-02 21:36:55 +00:00
Jordan Rose
3b43187703 [ClangImporter] Strip 'k' prefix even when there is nothing else in common.
<rdar://problem/16768954>

Swift SVN r17126
2014-05-01 00:06:23 +00:00
Jordan Rose
8e44c2ee79 Break "NSUTF16" as "NSUTF, 16", not "NSUT, F16".
Previously, this declaration:

  typedef NS_OPTIONS(NSUInteger, NSABitmapFormat5) {
    NSAA16d,
    NSAB32d,
  };

...would import with members .A16d and .B32d, which is not necessarily
correct. (Is it "NS_AA_16d", or "NSA_A_16d"?) Be more conservative here.

Swift SVN r17125
2014-05-01 00:06:22 +00:00
Doug Gregor
00e4edb620 Test that @optional initializers are imported as required.
... because Swift doesn't have optional initializer requirements yet.

Swift SVN r16851
2014-04-25 23:39:05 +00:00
Jordan Rose
76c89fe1e2 [ClangImporter] Avoid Clang's isModuleVisible.
Swift sometimes has a different notion of visibility, even for Clang modules.
In particular, this was causing the C version of NSUTF8StringEncoding
(from Foundation) to show up in AppKit, bypassing the Swift version in the
overlay.

We still want to search for redeclarations of functions, typedefs, and globals,
since these are often repeated in multiple modules without harm. The decl will
still have a "home" module, but this should allow them to be found by lookup.

<rdar://problem/16396994> and possibly <rdar://problem/14665250>

Swift SVN r16762
2014-04-24 18:50:01 +00:00
Jordan Rose
7542b996d0 [ClangImporter] Fix NSDictionary NSCopying hack for non-nullable object refs.
<rdar://problem/16533816>

Swift SVN r16720
2014-04-23 21:37:34 +00:00
Joe Groff
4dc7628cfd ClangImporter: Drop the variadic parameter to UIKit variadic DIs.
Hack the clang importer to drop the 'otherButtonTitles:' argument when we see the UIActionSheet or UIAlertView init methods, so we'll end up importing them as the non-variadic initializers added by the overlay.

Swift SVN r16717
2014-04-23 21:28:08 +00:00
Jordan Rose
98cc7524bd [ClangImporter] Rewrite enum prefix stripping to use the camel_case helpers.
Previously, we didn't correctly handle acronyms as single words, leading to
importing the NS16BitLittleEndianBitmapFormat enumerator of NSBitmapFormat as
"S16BitLittleEndianBitmapFormat". Now we get "NS16BitLittleEndianBitmapFormat",
which is a little better. See the examples for a few more ways this shakes out.

<rdar://problem/16683848>

Swift SVN r16682
2014-04-23 00:32:39 +00:00
Joe Pamer
7245e40825 The type checker collects all overloads for a given function application during the pre-type check phase, but equality conformances (and their associated '==' overloads) may be added to a type lazily during type resolution. This can lead to inconsistent behavior during type checking equality comparisons on imported enumeration types. (rdar://problem/16526249)
Basically, if an imported enumeration case is referenced without qualification as an argument to a '==' application (E.g., "foo.bar == .Baz"), and the enumeration type had not previously been resolved, overloads to '==' will be added to the global scope while performing overload resolution. This means the overloads will be ignored while solving for that application, but will be available for subsequent applications. (So you'll get an "expression does not type check" error the first time around, but not for subsequent applications of '==' to that enumeration type.)

The Equatable protocol is rather lightweight, however, and adding it to imported types directly results in no meaningful overhead to type check performance; we should just add it outright. As things evolve, though, it'll be worth considering how to make the type checker more amenable to lazy declarations.

Swift SVN r16557
2014-04-19 00:12:08 +00:00
Doug Gregor
c56d50a12c Introduce a named argument for imported nullary factory methods with long names.
We started tracking statistics for these in r16529, but because we've
"always" done this for initializers, it's trivial to just implement
the splitting. As with initializers, we synthesize a named argument of
type '()' to capture the part of the first selector piece that follows
the class name.


Swift SVN r16530
2014-04-18 16:41:18 +00:00
Doug Gregor
812dc091eb Introduce the notion of factory initializers.
Factory initializers express an initializer that produces an object of
the given type, but is not inherited and not designated. Although they
have a syntactic form for presentation purposes (-> ClassName), there
is no way to specify or implement them within Swift. Rather, factory
initializers are created when importing an Objective-C factory method
that returns the class type rather than instancetype.

Swift SVN r16528
2014-04-18 16:04:48 +00:00
Doug Gregor
f700a114f4 Handle inheritance of factory methods imported as initializers.
Swift SVN r16500
2014-04-18 06:14:27 +00:00
Doug Gregor
f56c68386e Start importing factory methods as initializers.
When an Objective-C class method follows the naming convention of a
factory method, i.e., its starting words match the ending words of the
class name, import it as a convenience initializer when it also:
  - Returns instancetype (i.e., dynamic Self in Swift parlance)
  - Has no NSError** parameters, which indicate the potential for failures

This is under a new flag (-enable-objc-factory-method-constructors)
because it is not generally functional. However, this is a step toward
<rdar://problem/16509024>.

Swift SVN r16479
2014-04-17 23:34:00 +00:00
Ted Kremenek
6caa1d4ae8 Make 'NSInvocation' unavailable.
Implements <rdar://problem/16638093>.

Swift SVN r16441
2014-04-17 04:49:28 +00:00
Ted Kremenek
fd864384df Imported '_attribute__((deprecated)' as 'unavailable'.
Swift SVN r16402
2014-04-16 06:52:10 +00:00
Doug Gregor
54e12fb13b Clang importer: use the selector-based lookup table to avoid importing
methods with conflicting selectors.

We were doing this in a very ad hoc manner before; centralizing the
lookup table should make this significantly more robust. There's also
some scaffolding here to handle initializers better.

Fixes <rdar://problem/16516638>.

Swift SVN r16349
2014-04-15 00:35:41 +00:00
Doug Gregor
6e5ca8a91f Clean up a number of Cocoa selector -> method name mappings.
Swift SVN r16302
2014-04-14 05:15:10 +00:00
Doug Gregor
9d7f0b6211 Rework the selector-splitting heuristics.
This makes a number of changes to the selector-splitting
heuristics. Specifically:

  - Eliminate last-word splitting, and with it the notion of
    multi-words. We only split at prepositions now.
  - Introduce the notion of "linking verbs" such as "will" or
    "should"; when these show up, we refuse to split a selector, which
    helps with delegates.
  - Eliminate the special case for "get" and "set". It wasn't
    helping.
  




Swift SVN r16265
2014-04-12 20:32:16 +00:00
Ted Kremenek
656fd1a2ee Add blacklist for imported macros, which can be extended over time.
Implements:

<rdar://problem/16454306> NS_BLOCKS_AVAILABLE probably should not be imported since by default it's true

Swift SVN r16067
2014-04-08 19:26:17 +00:00
Ted Kremenek
79bddbc66f Import -animator (from NSAnimatablePropertyContainer) as returning 'id' instead of 'instancetype'.
Fixes <rdar://problem/16020273>.

Swift SVN r16050
2014-04-08 08:27:51 +00:00
Jordan Rose
684e4d7b80 [ClangImporter] Move implicit properties test helpers to their own header file.
No functionality change.

Swift SVN r16034
2014-04-08 01:23:21 +00:00
Jordan Rose
835bfb15a9 [ClangImporter] Add an option (off by default) to infer "implicit properties".
In Objective-C, any method with no arguments can be used with dot syntax, as
can any method that takes one argument whose name starts with "set". This
commit adds a frontend-only flag -enable-objc-implicit-properties to look for
"setter-like" methods that match up with "getter-like" methods to import them
as Swift properties. By default, such methods are just considered unrelated
methods.

Part of <rdar://problem/16215476>

Swift SVN r16025
2014-04-07 21:49:37 +00:00
Jordan Rose
7810edea97 [ClangImporter] "NSPost" is not a prefix of "NSPostingStyle"
A small error in last week's enum changes.

<rdar://problem/16540910>

Swift SVN r16019
2014-04-07 20:49:54 +00:00
Doug Gregor
49387beb25 Selector splitting: don't split selectors in the middle of whitelisted "multi-words".
Swift SVN r16016
2014-04-07 19:17:23 +00:00