Commit Graph

27 Commits

Author SHA1 Message Date
Slava Pestov
7c3cf1d17b ClangImporter: Fix mirroring of instance properties as static methods on NSObject
Because all metaclasses ultimately inherit from NSObject, instance
members of NSObject are also visible as static members of NSObject.

If the instance member is a property, we import the getter as an
ordinary static method, and not a static property.

The lazy loading path normally checks for the presence of alternate
decls with the same name, but it was failing to do this check if the
imported decl was a property and the alternate decl was attached to
the accessor and not the property itself.

This wasn't a problem until recently, because we weren't lazy loading
members of NSObject itself, since it had protocol conformances; now
that we are, this problem was exposed.

Fixes <rdar://problem/59170514>.
2020-02-08 00:06:21 -05:00
Jordan Rose
5c21e12fdb [API notes] Remove all API notes present in the Xcode 9 SDKs. (#10615)
The framework versions already superseded the files here, so let's not
even bother building and packaging them. There /are/ still a few
frameworks that aren't shipping their own API notes at the moment,
however, though some of them are deprecated in their entirety.

rdar://problem/32908357
2017-07-07 19:52:49 -07:00
Alex Hoppen
884af9ccab [Parser] Make #selector a primary expression
This allows #selector to be followed by a trailing `?` in case statements as reported in SR-1827
2016-06-27 22:11:58 +02:00
Joe Groff
08f9f11965 IRGen: Map Int and UInt to Clang types via NS[U]Integer.
If NSInteger and NSUInteger typedefs are available in the current Clang context, use them when mapping Swift's Int and UInt to Clang types. This gives us consistent method and property type encodings for @objc methods with Clang, fixing rdar://problem/17506068.
2016-05-02 16:11:36 -07:00
Jordan Rose
50e3b33739 [ClangImporter] Implement importing of ObjC class properties.
For the most part this was just "check isInstanceProperty"; the one feature not yet implemented
is the emission of ObjC metadata for class properties.

rdar://problem/16830785
2016-03-31 14:27:56 -07:00
Doug Gregor
284d8e52cf Introduce an option to omit needless words when importing from Clang.
The -enable-omit-needless-words option attempts to omit needless words
from method names imported from Clang. Broadly speaking, a word is
needless if it merely restates the type of the corresponding parameter,
using reverse camel-case matching of the type name to the
function/parameter name. The word "With" is also considered needless
if whether follows it is needless, e.g.,

  func copyWithZone(zone: NSZone)

gets reduced to

  func copy(zone: NSZone)

because "Zone" merely restates type information and the remaining,
trailing "With" is also needless.

There are some special type naming rules for builtin Objective-C types,
e.g.,

  id -> "Object"
  SEL -> "Selector"
  Block pointer types -> "Block"

as well as some very-Cocoa-specific matching rules, e.g., the type
"IndexSet" matches the name "Indexes" or "Indices".

Expect a lot of churn with these heuristics; this is part of
rdar://problem/22232287.

Swift SVN r31178
2015-08-12 18:21:45 +00:00
Jordan Rose
8410a9bdea [ClangImporter] Teach lookupValue to find top-level swift_private declarations.
Essentially, if we see a name that starts with "__", start the whole process
again.

Part of rdar://problem/20070465

Swift SVN r29428
2015-06-17 01:46:15 +00:00
Dmitri Hrybenko
e6f53a38cc stdlib: remove swift_createDate
It was added for testing and it is actually never used now.

Swift SVN r26195
2015-03-16 22:25:27 +00:00
Chris Willmore
f723b05672 Don't remove 'with' from ObjC method arg name if resulting name is keyword.
Also, remove calls to isSwiftReservedName in
ClangImporter::Implementation::importName(), since 'true' and 'false'
are now keywords and rdar://problem/13187570 is no longer a problem.

rdar://problem/18797808

Swift SVN r23244
2014-11-11 19:34:53 +00:00
Jordan Rose
657070a637 [ClangImporter] Recognize OBJC_ENUM/OPTIONS along with CF_ENUM/OPTIONS.
rdar://problem/18506964

Swift SVN r22885
2014-10-23 03:28:28 +00:00
Jordan Rose
ce1e02c6c0 [ClangImporter] Remove hack for non-property 'description' and 'hash'.
...and 'debugDescription'. All SDKs now have the updated NSObject.h.

<rdar://problem/17719783>

Swift SVN r20291
2014-07-22 02:38:58 +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
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
4de43af267 PrintAsObjC: Print Dictionary<K, V> as "NSDictionary *"
Swift SVN r17839
2014-05-10 20:07:57 +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
3b3d10707e Prefer class methods to curried instance methods.
That is, NSObject.isEqual(someObj) should call +isEqual:, not be equivalent
to someObj.isEqual, unless there's a type context that says otherwise.

<rdar://problem/16527717>

Swift SVN r15955
2014-04-04 20:57:31 +00:00
Ted Kremenek
16ffbc6f3a Extend @availability(*,unavailable) checking to protocol methods.
Protocols can declare methods as being unavailable, as they do
in NSObjectProtocol (e.g., 'retain').  We both need to flag these
uses, but understand this for protocol conformance.  For protocol
conformance, treat unavailable methods as if they were marked
optional.  The compiler will not allow you to use these methods
anyway.

This finishes up support for:

    <rdar://problem/16331335> Ban ObjC ARC entry points

Swift SVN r15644
2014-03-30 07:11:39 +00:00
Ted Kremenek
80df698ccc Teach ClangImporter to import __attribute__((unavailable)) as @availability(*,unavailable).
This is a direct translation which happens when a Clang declaration
gets translated to a Swift declaration.  This changed, coupled
with the current @availability checking (which is still limited)
now prohibits cases such as using 'NSDeallocateObject()' or
'- (BOOL) allowsWeakReference' from Swift.

Interestingly, it doesn't catch uses of -retain/-release yet, because
those methods are marked unavailable in the NSObject *protocol*.
While the attributes are being mapped over, the @availability
checking needs to be enhanced to replicate more of what Clang does
for this case.

Swift SVN r15643
2014-03-30 05:25:52 +00:00
Doug Gregor
e03cb7c0a0 Don't split when the preposition is the last word in the first selector piece.
Swift SVN r15244
2014-03-19 20:15:50 +00:00
Doug Gregor
e5fff12bf0 Add option to split Objective-C selectors based on the last preposition.
The frontend option -split-objc-selectors splits the first part of an
Objective-C selector into both a function name and the first parameter
name at the last preposition. For example, this Objective-C method:

  - (NSString *)stringByPaddingToLength:(NSUInteger)newLength withString:(NSString *)padString startingAtIndex:(NSUInteger)padIndex

is imported as

  func stringByPadding toLength(newLength: Int) withString(padString: String) startingAtIndex(padIndex: Int) -> String




Swift SVN r15156
2014-03-17 20:34:48 +00:00
Jordan Rose
3e846134e1 [ClangImporter] Don't mirror a protocol's methods if they're in the superclass.
Right now we have a hack to mirror ObjC protocol methods into an imported
ObjC class, because Swift's lookup only looks into superclasses, not into
protocols (by default, anyway). This already isn't great because it's wrong
for @optional, but it was particularly bad if /two/ superclasses conformed
to the same protocol (directly or indirectly). Because the mirrored methods
weren't marked as overrides, the type checker would consider them both as
possibilities, leading to strange errors like this:

  <REPL Input>:1:1: error: ambiguous use of 'description'
  w.description()
  ^
  AppKit.NSWindow:268:8: note: found this candidate
    func description() -> String
         ^
  ObjectiveC.NSObject:72:8: note: found this candidate
    func description() -> String
         ^

Now, we check to see if a superclass conforms to a protocol already before
mirroring its methods into the current class or category.

<rdar://problem/16102321> and possibly also <rdar://problem/16038085>

Swift SVN r14189
2014-02-21 00:35:49 +00:00
Jordan Rose
b67624567b [tests] Using %clang-importer-sdk implies -enable-source-modules.
It isn't great to get this by accident, but the importer SDK contains
more minimal overlay modules than the ones actually used for real SDKs.

Fix up some tests that weren't consistent about whether or not the
minimal overlays were being used.

<rdar://problem/16048012>

Swift SVN r13835
2014-02-12 19:12:42 +00:00
Doug Gregor
41b6a42067 Clang importer: whitelist certain Objective-C protocols for renaming.
Rather than append the "Proto" suffix to all imported Objective-C
protocols, which can be confusing, whitelist those protocols that we
do have to rename. Only NSObject falls into this category so far.

Fixes <rdar://problem/15741699>.

Swift SVN r11856
2014-01-03 07:04:44 +00:00
Jordan Rose
69a51655c7 [ClangImporter] Instance methods on NSObject are also class methods.
More specifically, instance methods on root objects are also class methods,
because the metatype for that class will inherit from the root class.
(That is, NSObject's metatype extends NSObject.)

This is necessary to allow calling, say, -respondsToSelector: on a class.
Unfortunately, it also brings in every other method on NSObject, including
"informal protocol" category methods like -awakeFromNib. We should probably
disprefer these in code completion, especially if they're declared in another
module, but it is perfectly legal to call these methods on Class objects in
Objective-C.

<rdar://problem/13371711>

Swift SVN r11614
2013-12-24 01:34:07 +00:00
Dmitri Hrybenko
3d5952383f Clang importer tests: move NSUInteger definition to ObjectiveC module to be
consistent with reality


Swift SVN r11296
2013-12-14 03:32:27 +00:00
Dmitri Hrybenko
d35cf945e6 Move Clang importer test SDK to a toplevel dir test/Inputs where it can be
shared between Clang importer and IDE tests


Swift SVN r11292
2013-12-14 02:20:32 +00:00