Commit Graph

386 Commits

Author SHA1 Message Date
Doug Gregor
fff46fa27b Fix support for building with Clangs that do not support ObjC generics.
Swift SVN r24214
2015-01-06 17:54:41 +00:00
Doug Gregor
5db31c668f Push hash mark in the leading column
Swift SVN r24199
2015-01-06 00:21:34 +00:00
Doug Gregor
d3d4c8b8fb Only use specialized Objective-C collection types when Foundation supports them.
Rely on Foundation to provide NS_ARRAY/NS_DICTIONARY/NS_SET macros
that expand to either an unspecialized type (e.g., NSArray *) or a
specialized one (e.g., NSArray<T> *) as appropriate for the definition
of NSArray. Use these macros in the Objective-C printer.

The actual names and form of these macros is still to be debated, but
it's important to be able to handle both Clangs and Foundations with
and without parameterized NSArray/NSDictionary/NSSet.

Swift SVN r24198
2015-01-06 00:16:43 +00:00
Doug Gregor
83d4c3783d Teach the Objective-C printer to print specialized array/dictionary/set types.
Swift SVN r24197
2015-01-06 00:16:42 +00:00
Chris Willmore
43e112cdb0 Add Set->NSSet bridging to PrintAsObjC.
Swift SVN r23757
2014-12-06 04:44:10 +00:00
Doug Gregor
267f0ff756 Wrap context-sensitive nullability keywords in SWIFT_NULLABILITY.
Swift SVN r23533
2014-11-21 21:28:17 +00:00
Doug Gregor
96bdf90fcc Stop printing __null_unspecified per rdar://problem/18383574.
Swift SVN r23510
2014-11-21 05:06:53 +00:00
Doug Gregor
07740515c2 Emit nullability context-sensitive keywords for instancetype.
Swift SVN r23486
2014-11-20 21:16:00 +00:00
Joe Groff
944860adb0 PrintAsObjC: Handle forward declarations of @objc enums.
If enums are used as parameters or returns of @objc methods, we may need to forward declare those enums when printing the class @interface.

Swift SVN r23445
2014-11-19 22:27:48 +00:00
Doug Gregor
96a9751372 PrintAsObjC: Print nullability type specifiers to capture optionality.
Part of rdar://problem/19005653. There is still some work to do to
produce pretty output here, but the current output is correct.

Swift SVN r23444
2014-11-19 21:08:23 +00:00
Joe Groff
8b037275ff PrintAsObjC: Fix up mixed-language @objc enum annotations.
Thanks Jordan for pointing out that the test didn't in fact test that we imported ObjC-ified Swift decls back to the same type. Adjust things so that we do, putting the annotation attribute in the right place, and fixing a crash when we have superfluous typedefs for native Swift decls.

Swift SVN r23439
2014-11-19 17:53:59 +00:00
Ben Langmuir
e9e1666ab0 Update for upstream LLVM changes
* removal of StringMap's GetOrCreateValue
* SmallSet::insert now returns a pair like std::set

Swift SVN r23435
2014-11-19 16:49:30 +00:00
Joe Groff
b8d912c0db PrintAsObjC: Swap SWIFT_ENUM args around to match other *_ENUM macros.
And introduce a SWIFT_ENUM_EXTRA preprocessor hook for the Clang importer to inject its annotations.

Swift SVN r23425
2014-11-19 04:03:10 +00:00
Joe Groff
dc2ad382a2 Serialization: Serialize the raw values of @objc enums.
This is necessary for @objc enums because, for C compatibility, the representations of the cases must match their raw values. We might want to do this for sufficiently fragile Swift enums in the future too, but that can wait. This lets us successfully print the raw values as ObjC.

Swift SVN r23423
2014-11-19 04:03:06 +00:00
Joe Groff
5059bd4366 PrintAsObjC: Print @objc enums.
Predefine a SWIFT_ENUM macro that expands the same as NS_ENUM, but which we can use to recognize Swift-defined @objc enums that are imported back. Print enums as ObjC using this SWIFT_ENUM macro.

We currently don't serialize the raw value exprs of enums, so we fail to correctly bring raw values from the enum declaration to the ObjC version.

Swift SVN r23422
2014-11-19 04:03:05 +00:00
Andrew Trick
32b104abb2 Silence unannotated fall-through warnings.
Swift SVN r23342
2014-11-15 00:37:35 +00:00
Jordan Rose
5ad871ecd6 Adopt llvm::function_ref for callbacks that aren't persisted.
...removing a few other constructs that were doing the same thing
(mostly from me).

No functionality change.

Swift SVN r23294
2014-11-13 00:19:03 +00:00
Jordan Rose
c734630dc3 [PrintAsObjC] Generate headers as warning-free as possible.
...and use #pragma clang diagnostic when otherwise unavoidable.

As part of this change, start testing generated headers under
-Weverything -Werror, with targeted exceptions.

rdar://problem/18332948

Swift SVN r22010
2014-09-17 06:10:26 +00:00
Jordan Rose
d438ebc228 Sink Swift's adapter for NSZone into the ObjectiveC overlay.
While Foundation actually defines the NSZone typedef and what you can do with
it, the ObjectiveC module makes use of it in its raw form: "struct _NSZone *".
To avoid a circular dependency, sink our adapter down to the ObjectiveC
overlay.

Swift SVN r21827
2014-09-10 02:32:52 +00:00
Jordan Rose
b3dc2280a2 [PrintAsObjC] Only print inner classes if they are explicitly marked @objc.
This reduces the chances of conflict among inner class names. It's too easy
for a class to be implicitly marked @objc in Swift.

To make this work, correctly preserve the implicitness of @objc through
serialization. (We were probably intending to do this all along, since we
were serializing the flag but not doing anything with it at the other end.)

Swift SVN r21678
2014-09-03 18:19:00 +00:00
Jordan Rose
1c7b8f2972 [PrintAsObjC] Don't print nested classes as nested in Objective-C.
There are still problems with nested classes:
- They're much more likely to have colliding compile-time names
  (since the outer class's name is dropped).
- They're only picked up if the outer class is also @objc.

But at least now we won't generate invalid Objective-C. Unless the inner
classes have the same name.

rdar://problem/18187877

Swift SVN r21677
2014-09-03 18:18:59 +00:00
Jordan Rose
c35312815a [PrintAsObjC] @import required explicit submodules.
...but prefer the base module for implicit submodules.

rdar://problem/18097120

Swift SVN r21555
2014-08-29 00:39:24 +00:00
Jordan Rose
2f988f48d1 [PrintAsObjC] Don't use OBJC_DESIGNATED_INITIALIZER for protocol initializers.
<rdar://problem/17793674>

Swift SVN r20903
2014-08-01 18:06:33 +00:00
Jordan Rose
0331b7298c [PrintAsObjC] Don't print extensions of CF types.
Although Swift thinks of these as Objective-C classes, Objective-C itself
does not.

<rdar://problem/17867708>

Swift SVN r20867
2014-08-01 00:26:58 +00:00
Fariborz Jahanian
f93cee960c Reapply patch for rdar://17023083 which I reverted
earlier because clang patch for waninrg goupr name is in.
Also run %check-in-clang on the translated output.



Swift SVN r20786
2014-07-30 23:12:46 +00:00
Fariborz Jahanian
f6dc791df1 Revert patch in r20767
Swift SVN r20770
2014-07-30 20:36:24 +00:00
Fariborz Jahanian
81b2f47268 Patch to silence warnings about mismatched property
ownership attributes by bracketting
header with specific group warning pragma clang.
This patch also requires patch for rdar://17845264
which is currently in TOT. This is //rdar://17023083


Swift SVN r20767
2014-07-30 20:15:10 +00:00
Jordan Rose
66890d5d5f [PrintAsObjC] Mark 'internal(set)' properties as 'readonly' for frameworks.
"...because the generated header for a framework is part of the framework's
public Objective-C interface, only declarations marked public appear in the
generated header for a Swift framework."

Just missed a case here when we decided to do things this way.

<rdar://problem/17796727>

Swift SVN r20653
2014-07-28 22:49:41 +00:00
Dave Abrahams
1438d617cd [stdlib] Rename ConstUnsafePointer=>UnsafePointer
Swift SVN r20318
2014-07-22 17:10:54 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Jordan Rose
a419138a7a [PrintAsObjC] Print 'struct Foo' or 'enum Foo' instead of 'Foo' when necessary.
To do this, we keep track of decls with superfluous typedefs (rather than
just the typedefs), and check for that. Tag decls without typedefs are
printed with the tag.

<rdar://problem/17569385>

Swift SVN r20221
2014-07-20 17:26:20 +00:00
Jordan Rose
52f7cd48b0 [PrintAsObjC] Print ownership qualifiers on properties.
weak => 'weak', unless the type is a CF type. I'm not sure weak references to
        CF types work anyway, but until we have that cleared up this works.

unowned => 'assign'. In Objective-C, use of 'assign' for object properties is
           largely deprecated in favor of 'unsafe_unretained', but unowned
           properties behave more like a 'safe_unretained'. Since they don't
           auto-update like 'weak', though, this should hint to clients to
           be careful about lifetimes.

unowned(unsafe) => 'unsafe_unretained'

As before, Arrays, Dictionaries, and Strings are considered 'copy' properties;
blocks are now considered 'copy' properties as well.

All other types get their (implied)  default: 'strong' for objects, 'assign'
for primitives.

<rdar://problem/17346846>

Swift SVN r20112
2014-07-17 20:59:53 +00:00
Joe Groff
c4fbf674da PrintAsObjC: Handle CFunctionPointer.
Swift SVN r20048
2014-07-16 22:13:27 +00:00
Jordan Rose
f35e50e017 [PrintAsObjC] Include IBOutlet/IBAction/IBOutletCollection in the header.
Also, fix a bug where value properties weren't getting marked as "copy"
if wrapped in IUOs, and replace some identifier-based comparisons with
pointer comparisons against ASTContext-cached decls.

<rdar://problem/17007235>

Swift SVN r19874
2014-07-12 01:52:01 +00:00
Jordan Rose
b24e19b4f0 [PrintAsObjC] Handle unparenthesized closure input types.
<rdar://problem/17358809>

Swift SVN r19837
2014-07-10 23:57:26 +00:00
Chris Lattner
fe95f81397 introduce a new 'DeclModifier' flag on attributes, which mark that the
attribute is a "modifier" of a decl, not an "attribute" and thus shouldn't
be spelt with an @ sign.  Teach the parser to parse "@foo" but reject it with
a nice diagnostic and a fixit if "foo" is a decl modifier.

Move 'dynamic' over to this (since it simplifies some code), and switch the
@optional and @required attributes to be declmodifiers (eliminating their @'s).



Swift SVN r19787
2014-07-10 05:49:10 +00:00
Chris Lattner
35dcc3aa10 Move the @optional attribute to being a SIMPLE_DECL_ATTR, which
simplifies a bunch of code, makes them more consistent with the
other attributes, and is generally the newfangled way to do things.



Swift SVN r19779
2014-07-10 04:34:00 +00:00
Jordan Rose
c90cd11aff [PrintAsObjC] Only include internal decls if we have a bridging header.
The upshot of this is that internal decls in an app target will be in the
generated header but internal decls in a framework target will not. This
is important since the generated header is part of a framework's public
interface. Users always have the option to add members via category to an
internal framework type they need to use from Objective-C, or to write the
@interface themselves if the entire type is missing. Only internal protocols
are left out by this.

The presence of the bridging header isn't a /perfect/ way to decide this,
but it's close enough. In an app target without a bridging header, it's
unlikely that there will be ObjC sources depending on the generated header.

Swift SVN r19763
2014-07-09 23:58:57 +00:00
Jordan Rose
3e994a24cf [PrintAsObjC] Don't print private protocols in the generated header.
Swift SVN r19735
2014-07-09 19:01:34 +00:00
Jordan Rose
9e970f313e [PrintAsObjC] Handle dictionary sugar syntax.
<rdar://problem/17594798>

Swift SVN r19734
2014-07-09 18:44:47 +00:00
Jordan Rose
cf53b747d0 Don't infer @objc on private members.
You can still mark them @objc explicitly (or @IBOutlet, or anything else that
would require ObjC interop).

Also, don't print private decls in the generated header, whether @objc or not.
not.

Swift SVN r19733
2014-07-09 18:44:46 +00:00
Jordan Rose
f18dc4101f [Accessibility] Honor private(set) with -enable-access-control.
...for both variables and subscripts.

Swift SVN r19549
2014-07-04 01:53:49 +00:00
Jordan Rose
1b7a384252 Fix a multitude of issues with extensions exposed to Objective-C (r19116).
- Category names weren't unique.
- We were using an attribute to detect if something was a Swift category,
  but attributes can't be used on categories.
- The test that this was all working was failing in a way that wasn't caught.

To solve these problems:

- We're using a macro to generate category names based on __LINE__ in addition
  to the current module.
- The importer uses the macro to detect that the category comes from Swift
  (no attribute needed).
- The test now has a deliberate error for -verify to catch.

<rdar://problem/17342287&17538553>

Swift SVN r19479
2014-07-02 20:35:25 +00:00
Joe Groff
f722d3f6a6 Remove tons of now-dead code for dealing with the C*Pointer bridging types.
Swift SVN r19280
2014-06-27 00:11:36 +00:00
Joe Groff
17d27e6529 PrintAsObjC: Print ConstUnsafePointer as a const pointer.
Swift SVN r19266
2014-06-26 22:37:25 +00:00
Jordan Rose
7fc8ecd919 [PrintAsObjC] Mark String, Array, and Dictionary properties as 'copy'.
<rdar://problem/17012159>

Swift SVN r19118
2014-06-24 01:23:03 +00:00
Jordan Rose
c6226159c5 Allow class properties to be @objc, and expose them as class methods.
<rdar://problem/17164696>

Swift SVN r19117
2014-06-24 01:23:02 +00:00
Jordan Rose
347f330d15 Don't import the ObjC representation of Swift extensions in frameworks.
Because extensions don't have any identity we can check against, we can't
tell when we see an Objective-C category if it came from a Swift extension.
Change PrintAsObjC to mark all such categories with SWIFT_EXTENSION, and
just skip them unilaterally when importing Objective-C code.

Also, actually give Swift extensions a name when writing them as Objective-C
categories. Previously, they were nameless categories ("class extensions"),
but methods in a class extension are supposed to be implemented in the class's
main @implementation, so people were getting unexpected warnings about missing
implementations.

<rdar://problem/17342287>

Swift SVN r19116
2014-06-24 01:23:00 +00:00
Jordan Rose
a4ea927426 [ClangImporter] If a protocol and a class have the same name, add "Protocol".
.../if/ the protocol and the class are from the same top-level Clang module.
If not, the protocol is /not/ renamed, and users will have to disambiguate
with module qualification.

This kills our hardcoded "RenamedProtocols" list; it turns out this pattern
is more common than we thought /and/ leads to cross-referencing issues.

<rdar://problem/16206627>

Swift SVN r18809
2014-06-11 23:00:00 +00:00
Jordan Rose
03eacc2931 [PrintAsObjC] Forward-declare things for the generated header when possible...
...and just outright import the bridging header if that's what's needed.

This means we'll use @class and @protocol whenever we're just using a class
or protocol in a type, but still import the enclosing module when we need
the definition. We'll also fall back to the module (or bridging header) if
we need something /else/ from C: a struct, a typedef, whatever.

<rdar://problem/17183425>

Swift SVN r18795
2014-06-11 00:01:58 +00:00