Commit Graph

378 Commits

Author SHA1 Message Date
Jordan Rose
8643de9842 [PrintAsObjC] Respect private(set) on class properties.
rdar://problem/24564858
2016-06-09 18:25:15 -07:00
Jordan Rose
eeac42c13f Cache the Identifier for "_ObjectiveCType". NFC. 2016-05-26 17:55:18 -07:00
Jordan Rose
8547b545c9 [PrintAsObjC] Handle imported swift_newtype typedefs.
A typedef with the swift_newtype attribute is imported as a struct
wrapping the underlying type instead of just a typealias. If the
underlying type is a bridged type (like String), the newtype struct
is bridged as well. However, we don't want to use that type when
bridging back to Objective-C, because

(1) Objective-C header generation is done too late to fill out the
    _ObjectiveCBridgeable conformance for the type, so if it wasn't
    type-checked then the conformance won't have the original type
    in it.
(2) There's a perfectly good typedef we should be using anyway.

Just use the type as written in Objective-C (instead of crashing).

Finishes rdar://problem/26372925.
2016-05-25 12:03:28 -07:00
Jordan Rose
1bdd092cd9 [PrintAsObjC] Use C names when printing imported structs.
(and enums)

Previously this part of the compiler assumed that any imported
struct or enum would have the same name as it does in C, which is
no longer true.

Part of rdar://problem/26372925
2016-05-25 11:34:02 -07:00
Jordan Rose
135e9b99f1 [PrintAsObjC] Emit Xcode-7-compatible class properties.
There's not yet a released version of Apple Clang that supports
Objective-C class properties, so make sure the generated header
guards any uses of them with a __has_feature check, and provides
declarations of the accessor methods as well.

https://bugs.swift.org/browse/SR-1442
2016-05-09 14:13:57 -07:00
Jordan Rose
bc83940301 Make pointer nullability explicit using Optional.
Implements SE-0055: https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md

- Add NULL as an extra inhabitant of Builtin.RawPointer (currently
  hardcoded to 0 rather than being target-dependent).
- Import non-object pointers as Optional/IUO when nullable/null_unspecified
  (like everything else).
- Change the type checker's *-to-pointer conversions to handle a layer of
  optional.
- Use 'AutoreleasingUnsafeMutablePointer<NSError?>?' as the type of error
  parameters exported to Objective-C.
- Drop NilLiteralConvertible conformance for all pointer types.
- Update the standard library and then all the tests.

I've decided to leave this commit only updating existing tests; any new
tests will come in the following commits. (That may mean some additional
implementation work to follow.)

The other major piece that's missing here is migration. I'm hoping we get
a lot of that with Swift 1.1's work for optional object references, but
I still need to investigate.
2016-04-11 20:06:38 -07:00
David Farler
a9297eed9f Rename llvm::markup namespace to swift::markup
This was naming was cargoed from long ago and this functionality isn't
directly related to LLVM, it's specific to Swift.
2016-04-10 13:46:25 -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
Joe Groff
874dbd8de4 PrintAsObjC: Handle imported generic classes. 2016-03-28 09:50:30 -07:00
Stephen Canon
8187dfb140 Added uint[2,3,4] to simd, bridged to vector_uintN. 2016-03-24 07:56:59 -04:00
Doug Gregor
1322de08bc [PrintAsObjC] Use _ObjectiveCBridgeable conformances to print bridged types.
Rather than hardcoding String/Array/Dictionary/Set to print as
NSString/NSArray/NSDictionary/NSSet, use _ObjectiveCBridgeable
conformances to determine how to print them. Another step toward
generalized _ObjectiveCBridgeable, although the general form is not
yet useful.
2016-03-11 10:43:50 -08:00
Joe Groff
013aad13d4 Initial implementation of a @_cdecl attribute to export top-level functions to C.
There's an immediate need for this in the core libs, and we have most of the necessary pieces on hand to make it easy to implement. This is an unpolished initial implementation, with the following limitations, among others:

- It doesn't support bridging error conventions,
- It relies on ObjC interop,
- It doesn't check for symbol name collisions,
- It has an underscored name with required symbol name `@cdecl("symbol_name")`, awaiting official bikeshed painting.
2016-03-10 13:27:39 -08:00
Max Moiseev
7fe6916bf6 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-07 12:10:47 -08:00
Doug Gregor
e16d6898ef [PrintAsObjC] Sentence-case the enum case name when appending it to the enum name.
Otherwise, we cram a conventionally UpperCamelCase thing with a
newly-conventinally-lowerCamelCased thing together and destroy the
word boundaries. Fixes rdar://problem/24947695.
2016-03-04 15:42:22 -08:00
Max Moiseev
cf4bafe9e3 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-03 13:22:03 -08:00
Kevin Ballard
00ccc9ddc3 [PrintAsObjC] Print argument names for function/block types
Including the argument names helps code completion in Xcode.

Fixes SR-365.

Also fixes an issue where a property of a block/function type whose name
is a clang keyword would produce an invalid declaration, e.g.

    var `struct`: (Int -> Int)?

was printing as

    @property (nonatomic, copy, getter=struct, setter=setStruct:) NSInteger (^ _Nullable struct)(NSInteger)_;
2016-03-02 21:02:32 -08:00
Max Moiseev
bb3eaaf308 Merging in latest master 2016-02-24 15:10:25 -08:00
Doug Gregor
6fe6266c99 [ObjC Interop] Map Swift @objc properties named isFoo to ObjC Cocoa conventions
The Objective-C Cocoa convention eschew "is" on property names, but
use it on the getter, while the Swift API guidelines state that
Boolean properties should read as assertions (e.g., "isEmpty" rather
than "empty"). Map Swift properties named "isFoo" to Objective-C by
removing the "is" from the resulting Objective-C property name (so it
will be named "foo") and from the setter (which will have the
Objective-C selector "setFoo:") while retaining the "is" for the
getter selector ("isFoo").

Fixes rdar://problem/17090661.
2016-02-23 20:49:20 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Kevin Ballard
4da629f1be [PrintAsObjC] Use @objc name for enums in enum references
Also make sure the `FooDomain` constant for `ErrorType` enums uses the
correct name.

Fixes SR-693: Custom named @objc enum still exposes original Swift name
in Objective-C
2016-02-09 13:10:47 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
practicalswift
6d0eee9b8c Remove unused variables. 2016-01-21 10:33:17 +01:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Doug Gregor
c4a6902589 Abstract the set of known Foundation entities into a .def-driven enum. NFC
Specifically, we don't want to hard-code the Swift names of these
Objective-C entities, because the importer renaming will affect them.
2016-01-17 23:40:14 -08:00
Max Moiseev
08e1e4a043 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-11 16:51:11 -08:00
Jordan Rose
6ef18cd0e1 Merge pull request #797 from kballard/enum-constant-objc
Implement support for @objc(name) on enum cases. Changelog update coming next.
2016-01-06 14:57:32 -08:00
Kevin Ballard
f473851148 [PrintObjC] Support @objc(name) on enum cases 2016-01-06 14:46:06 -08:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
Chris Lattner
6afe77d597 Eliminate the Parameter type completely - now ParameterList is just
an overblown array of ParamDecl*'s that also keeps track of parenlocs
and has helper methods.
2016-01-03 14:45:38 -08:00
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Kevin Ballard
2de24e167f [PrintObjC] Add SWIFT_ENUM_NAMED for enums with custom ObjC names 2015-12-23 15:52:16 -08:00
Dmitri Gribenko
feacbc4433 Rename ErrorType to ErrorProtocol 2015-12-09 17:12:19 -08:00
Maxim Moiseev
7372e9e045 COpaquePointer => OpaquePointer 2015-12-07 16:52:45 -08:00
Kevin Ballard
66369468aa Use new-style _Nullable keywords in obj-c header
Use the keywords `_Nullable`, `_Nonnull`, and `_Null_unspecified`
instead of the older compatibility forms `__nullable`, `__nonnull`, and
`__null_unspecified`.

Part of rdar://problem/23614638
2015-12-05 19:54:27 -08:00
Jordan Rose
fc2cdeeb31 [PrintAsObjC] Only define Swift-provided typedefs once.
Avoids a C99 warning.

Rest of rdar://problem/22702104

Swift SVN r32232
2015-09-25 17:53:48 +00:00
Jordan Rose
239b84395a [PrintAsObjC] Use 'struct _NSZone' rather than redeclaring the typedef.
Part of rdar://problem/22702104

Swift SVN r32231
2015-09-25 17:53:46 +00:00
Jordan Rose
cddd26477e [PrintAsObjC] Enum domain string constants are __nonnull.
(And they are '__nonnull' rather than '_Nonnull' for two reasons:
it's a very cheap concession to preserve compatibility with Xcode 6.3,
and the existing code works this way.)

rdar://problem/22805286

Swift SVN r32228
2015-09-25 17:53:37 +00:00
Jordan Rose
2b229aa9c7 [PrintAsObjC] Fix infinite loop on typedefs of CFTypeRef.
Swift SVN r31427
2015-08-24 17:48:29 +00:00
Jordan Rose
f2ad7be511 [PrintAsObjC] Add PrettyStackTraces. NFC.
Swift SVN r31314
2015-08-18 22:05:28 +00:00
Jordan Rose
fa2211d834 [PrintAsObjC] Print 'strong' on properties with class type.
...so that our headers can be imported into MRR code.

rdar://problem/17214904

Swift SVN r31230
2015-08-13 22:14:57 +00:00
Jordan Rose
bca4b12f60 [PrintAsObjC] Handle blocks whose parameters come from a typealias.
...instead of crashing.

rdar://problem/21974146

Swift SVN r30753
2015-07-29 04:06:17 +00:00
Jordan Rose
177588d1a8 Only allow collections to contain @objc types in @objc methods and properties.
We allow any array of bridgeable types to be converted to NSArray (and
similar for Dictionary and Set), but to be part of an API is a little
stricter. Previously, '[MySwiftObject]' as a parameter would get exposed
to Objective-C as 'NSArray *', but that's not type-safe at all---and in
corner cases, crashd in the ObjC printer. Now we just don't allow that.

On the plus side, '[Int]' is now exposed as 'NSArray<NSNumber *> *',
which is a fair amount better than just 'NSArray *'.

rdar://problem/19787270

Swift SVN r30719
2015-07-28 18:46:07 +00:00
Jordan Rose
fdc927e8d7 [PrintAsObjC] Add missing SWIFT_COMPILE_NAME for classes renamed with @objc.
This could prevent mixed-source frameworks from being properly imported
into Swift.

rdar://problem/21930630

Swift SVN r30541
2015-07-23 17:28:20 +00:00
Jordan Rose
df93e366f1 [PrintAsObjC] Make sure to use a class's custom name when extended or subclassed.
Otherwise, we end up with an invalid generated header.

rdar://problem/21929752

Swift SVN r30474
2015-07-21 23:56:35 +00:00
Jordan Rose
5f4ad8722f Unmanaged<T> is ObjC-compatible if T is an Objective-C-compatible object type.
rdar://problem/16832080

Swift SVN r30079
2015-07-10 19:05:21 +00:00
Jordan Rose
0b5428fcd3 Import DarwinBoolean as Bool in fully-bridgeable contexts.
These are contexts where we have enough information to bridge /back/
properly; that is, where we can distinguish CBool, ObjCBool, and
DarwinBoolean. In cases where we can't, we keep the three separate;
only CBool is really the same type as Bool.

This also affects current import behavior for ObjCBool, which was previously
incorrectly conflated with CBool in certain cases.

More rdar://problem/19013551

Swift SVN r30051
2015-07-10 01:11:30 +00:00
Jordan Rose
e1ffbbbcf5 Import MacTypes.Boolean as a dedicated DarwinBoolean type.
Like ObjCBool is a legitimate boolean type rather than a typealias for Int8,
DarwinBoolean is better than a typealias for UInt8. It's a BooleanType
(meaning you can use it directly in if/while/?:) and BooleanLiteralConvertible
(meaning you can use 'true' and 'false').

The next commit goes even further, so that you only have to deal with
DarwinBoolean when ABI is important. At all other times it should be
bridged with Bool, just like ObjCBool.

rdar://problem/19013551

Swift SVN r30050
2015-07-10 01:11:25 +00:00