Commit Graph

252 Commits

Author SHA1 Message Date
Doug Gregor
5c8fde3f2e Make PrintAsObjC more tolerant of non-@objc classes within collections.
Swift's bridged collections are allowed to store objects of non-@objc
classes, e.g., an array of (non-@objc) Swift classes is still bridged
to NSArray. Deal with such cases by printing out the type as "NSArray
*", since we cannot name the type in Objective-C to provide a more
specialized NSArray type.

This is a fairly narrow fix for rdar://problem/20392771 that needs
more discussion.

Swift SVN r26905
2015-04-02 21:56:58 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00
John McCall
080b7dfabf Remove the default handle-all Decl and DeclAttribute
cases from ASTVisitor and privatize SILGen's statement
emitter.  NFC.

Swift SVN r26402
2015-03-22 03:22:45 +00:00
Doug Gregor
f6e95b0a34 Fix printing of Objective-C @properties for @objc-renamed properties.
Finishes rdar://problem/19963219.

Swift SVN r25624
2015-02-27 22:54:46 +00:00
Doug Gregor
db51abba9a Fix Objective-C printing of init(forFun: ()) initializers.
This is the rest of rdar://problem/19973250, thank you Jordan!

Swift SVN r25623
2015-02-27 22:54:45 +00:00
Doug Gregor
96a2659223 Serialize initializer stub implementations.
Fixes the cross-module initializer inheritance issues implied by
rdar://problem/19794036.

Swift SVN r25336
2015-02-17 00:38:21 +00:00
Jordan Rose
4d7d6bbfc6 [PrintAsObjC] Don't forward-declare @objc enums using typedefs.
That's a C11 feature, and we can't force everyone to enable C11 just yet.
Instead, go back to the old way of using "enum Foo" to refer to @objc enums
defined in Swift. Just don't do it unilaterally for non-@objc enums.

Should unstick the buildbot.

Swift SVN r25161
2015-02-11 03:15:06 +00:00
Jordan Rose
d397a323a3 [PrintAsObjC] Output nullability for CF types and non-retainable pointers.
For pointer types that Swift doesn't currently import using Optional
(see rdar://problem/15189170 and its dups), use __null_unspecified.

rdar://problem/19775335

Swift SVN r25144
2015-02-10 23:52:48 +00:00
Jordan Rose
6a50a12bef [PrintAsObjC] Don't assume typedef'd enums have a name themselves.
...and then fix our forward-declaration logic that assumed that they did.

This fixes a rare case where we would end up printing "enum" twice if the
user (benignly) misused NS_ENUM.

rdar://problem/19769964

Swift SVN r25143
2015-02-10 23:52:44 +00:00
Doug Gregor
883911c767 Define __null_unspecified to nothing when the underlying Clang doesn't support nullability.
Fixes rdar://problem/19730896.

Swift SVN r25000
2015-02-05 17:35:45 +00:00
Jordan Rose
82c8d9b3dc [PrintAsObjC] Preserve NSUInteger in overridden decls when easy to do.
If a property, method, or subscript overrides an imported property, method,
or subscript that was originally declared using NSUInteger as a property,
parameter, or return type, print the subclass's member using "NSUInteger"
in the generated header to prevent override warnings.

This doesn't handle all cases--in particular, it doesn't handle the
NSUInteger being nested inside a larger type--but it does get the easy
ones correct. I think the easiest way to be more correct would be to mark
NSUInteger-as-Int somehow using a distinct type. (Hidden attribute?
Another typealias? Not sure.)

rdar://problem/19321126

Swift SVN r24771
2015-01-28 01:37:04 +00:00
Doug Gregor
f0eec4d9d5 Don't rely on overriding nullability in Objective-C; it's banned now.
Fixes rdar://problem/19610107.

Swift SVN r24750
2015-01-27 16:52:03 +00:00
Doug Gregor
fe5fe16c46 PrintAsObjC: Start printing __null_unspecified where needed.
Fixes rdar://problem/19499467.

Swift SVN r24643
2015-01-22 19:26:21 +00:00
Jordan Rose
0c182d73a3 [PrintAsObjC] Prefer the Clang name of imported typedefs.
Previously, when dealing with CF typedefs of other CF types, we would strip
off the "Ref" suffix...and then leave it off when it came time to print the
Objective-C header.

rdar://problem/19446942

Swift SVN r24562
2015-01-20 20:42:01 +00:00
Doug Gregor
b642c555be Allow one to change the argument labels of curried function parameters.
Curried function parameters (i.e., those past the first written
parameter list) default to having argument labels (which they always
have), but any attempt to change or remove the argument labels would
fail. Use the fact that we keep both the argument labels and the
parameter names in patterns to generalize our handling of argument
labels to address this problem.

The IDE changes are due to some positive fallout from this change: we
were using the body parameters as labels in code completions for
subscript operations, which was annoying and wrong.

Fixes rdar://problem/17237268.

Swift SVN r24525
2015-01-19 22:15:14 +00:00
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