Commit Graph

2428 Commits

Author SHA1 Message Date
Doug Gregor
91960e4272 Support keyed subscripting for Objective-C classes as Swift subscripting.
As shown in the updated NSString demo, we can now subscript into
NSDictionary from Swift. No extra magic required.


Swift SVN r3386
2012-12-07 00:13:38 +00:00
Doug Gregor
aabff2b65b Create a getter thunk for Objective-C subscripts.
Swift SVN r3385
2012-12-06 23:52:16 +00:00
Doug Gregor
5bd1e928d1 The subscripting setter thunk is *not* an imported Clang declaration.
Swift SVN r3383
2012-12-06 19:33:04 +00:00
Doug Gregor
aa89f9185b Generate the required AST-level thunk for subscript setters.
An Objective-C subscript setter has a type of the form 

  (this) -> (value, index) -> ()

while a Swift subscript setter has a type of the form

  (this) -> (index) (value) -> ()

Introduce a Swift "thunk" with the latter signature that simply calls
the underlying Objective-C method, and make sure that thunk gets
type-checked and IR-generated appropriately.


Swift SVN r3382
2012-12-06 19:28:11 +00:00
Doug Gregor
e4c2d71632 Import Objective-C indexed subscripting methods as Swift subscript declarations.
This commit covers only the AST-building side of indexed
subscripting, mapping objectAtIndexedSubscript: and
setObject:atIndexedSubscript: to Swift 'subscript' declarations. IR
generation and support for keyed subscripting to follow.


Swift SVN r3377
2012-12-06 02:34:53 +00:00
Doug Gregor
c5c5fa9e35 Be more selective about creating constructors for Objective-C new/init methods.
Only create constructors for class 'new' methods (not instance methods
like
newScriptingObjectOfClass:forValueForKey:withContentsValue:properties:),
and only do so when the class type inherits from NSObject. The latter
occurs because we don't have a notion of a 'top' for Objective-C
classes, and is a temporary measure.


Swift SVN r3374
2012-12-05 23:46:47 +00:00
Doug Gregor
1f45f28837 Emit the constructors synthesized by the Clang importer for ObjC init/new methods.
Note that the constructors we emit don't function yet, since they rely
on the not-yet-implemented class message sends to Objective-C
methods.


Swift SVN r3370
2012-12-05 22:01:38 +00:00
Doug Gregor
9904844727 Move 'external definitions' vector into the Clang module; it only makes sense there.
Swift SVN r3367
2012-12-05 18:35:33 +00:00
Doug Gregor
85f690d086 Type-check the constructors synthesized for Objective-C init/new methods.
Swift SVN r3366
2012-12-05 18:15:48 +00:00
Doug Gregor
519091c30d Synthesize a body for Swift constructors that map down to alloc/init* or new invocations.
At present, the body of these constructors is neither type-checked nor
IR-generated.


Swift SVN r3358
2012-12-05 01:11:11 +00:00
Doug Gregor
a221a6986b Rename the "allocating" attribute to "allocates_this".
Swift SVN r3353
2012-12-04 20:20:58 +00:00
Doug Gregor
d04db691ec Retain the first selector piece when importing init/new methods as constructors.
This is the conservative solution that we can revisit later.


Swift SVN r3352
2012-12-04 20:00:01 +00:00
Doug Gregor
08c9b5c7b2 Allocating constructors are expected to allocate and assign 'this' on their own.
This implementation is very lame, because we don't currently have a
way to detect (in Sema or SIL) where 'this' gets uniquely assigned,
and turn that assignment into initialization.

Also, I'm starting to hate the name 'allocating' constructor, because
it's the opposite of the Itanium C++'s notion of the allocating
constructor. Will think up a better name.




Swift SVN r3347
2012-12-04 01:06:30 +00:00
Doug Gregor
98cc0555a3 Import Objective-C methods in the 'init' and 'new' family as Swift constructors.
This commit only covers the semantic analysis for this operation; IR
generation to follow.


Swift SVN r3341
2012-12-04 00:20:08 +00:00
Doug Gregor
629b06623d Import Objective-C categories and extensions as Swift extensions.
Swift SVN r3262
2012-11-27 22:19:16 +00:00
Doug Gregor
311520a3ec Implement support for calling Objective-C instance methods imported from Clang.
Tweak the import of Objective-C methods to build the proper FuncExpr
and tag the FuncDecl as an Objective-C method, along with a few other
tweaks, so calls to the imported Objective-C methods go through
objc_msgSend().

At this moment, this is aborting in the Objective-C runtime due to an
unrecognized selector. The issue does not appear related to the
importer.


Swift SVN r3255
2012-11-27 07:50:52 +00:00
Doug Gregor
83f2874ba1 Implement support for calling imported C functions from Swift.
There is no protection whatsoever if the Clang-to-Swift type
conversion produces something that Swift doesn't lower in an
ABI-compatible way. That will be dealt with later.


Swift SVN r3249
2012-11-27 00:34:48 +00:00
Doug Gregor
e41a89ab27 Record overridden Objective-C properties in the Swift AST.
Swift SVN r3247
2012-11-26 20:58:20 +00:00
Doug Gregor
8527126264 Import Objective-C properties as Swift variables.
Note that we have to be very careful not to introduce ambiguities
between the name of the getter and the name of the property, so we do
the following:
  - "Informal" properties (where there is no @property) are not
  mapped to Swift variables. The methods are just methods.
  - An @property suppresses name lookup's ability to find
  the getters and setters of that property, so having a "foo" property
  eliminates the "foo" and "setFoo" methods.
  - If an @property is added in a subclass, such that its getter or
  setter come from a superclass, than that property cannot be mapped
  to a Swift variable. Hopefully, this is rare.

As part of this, I had to make sure that Objective-C method overrides
were recorded as overrides in the Swift AST. The same will need to
happen for properties at some point.



Swift SVN r3245
2012-11-26 20:09:55 +00:00
Doug Gregor
f5eae6a60f Import Objective-C class methods into Swift.
Swift SVN r3244
2012-11-26 18:00:37 +00:00
Doug Gregor
9d299f8bec Import Objective-C instance methods into Swift.
Swift SVN r3240
2012-11-26 17:45:07 +00:00
Doug Gregor
c3801abeb4 Import Objective-C classes into Swift.
Only the class name and its superclass are imported at this
time. Properties and methods to follow.



Swift SVN r3239
2012-11-26 16:54:49 +00:00
Doug Gregor
1ed3e7b0d6 Put in stubs for Clang declaration kinds that won't be imported.
Swift SVN r3238
2012-11-26 16:09:36 +00:00
Doug Gregor
037ad8403d Import Clang global variables as Swift global variables.
Swift SVN r3237
2012-11-26 15:59:19 +00:00
Doug Gregor
3fcbfdd42a Import C structs and C++ classes as Swift structs.
Swift SVN r3236
2012-11-26 15:51:46 +00:00
Doug Gregor
1c6c67af5e Implement support for importing Clang enumeration types as Swift oneofs.
Swift SVN r3221
2012-11-17 00:33:37 +00:00
Doug Gregor
5fcca3dc0b Build out the infrastructure for importing declarations.
As part of this, import typedefs (and C++11 type aliases) as Swift
type aliases.


Swift SVN r3215
2012-11-16 23:41:54 +00:00
Doug Gregor
0afad51b4a Factor the declaration-importing code into its own file.
Swift SVN r3214
2012-11-16 23:08:25 +00:00