Commit Graph

2523 Commits

Author SHA1 Message Date
Joe Groff
2b220bcc9d ClangImporter: Work around reentrancy bug importing enum constants.
When importing an enum constant, we import its enum type, which then recursively imports the same enum constant, returns, and finishes importing the enum constant--again. Oops. Hack around this by re-checking for a cached imported definition for an enum constant after importing its type.

Swift SVN r4963
2013-04-28 03:32:35 +00:00
Joe Groff
35f81da656 ClangImporter: Suppress importing no-argument constructors besides 'init'.
NSAppleEventDescriptor has multiple "default" init methods, -init, -initRecordDescriptor, and -initListDescriptor, and they were all getting imported as default constructors in Swift. I don't know what the right thing to do long-term about init methods like these, but short-term I think we can get away with suppressing them.

Swift SVN r4962
2013-04-28 03:32:33 +00:00
Doug Gregor
c057b21193 Ban the use of construction syntax T(x) for coercions and unchecked downcasts.
Use "x as T" for coercions and "x as! T" for unchecked downcasts.


Swift SVN r4683
2013-04-11 21:17:47 +00:00
Joe Groff
fdcd04cbc1 ClangImporter: Update constructor import comments.
We don't import 'new'-family methods as Swift ctors anymore.

Swift SVN r4287
2013-03-05 21:39:40 +00:00
Joe Groff
23aaa56143 IRGen: Emit type metadata for Clang structs.
We need type metadata symbols for Clang structs so that they have witness tables and can conform to protocols (or be part of structs that conform to protocols). Consider Clang struct metadata to be 'isClangThunk' like other Clang-emitted definitions so that it all gets linkonce_odr'ed to avoid linker issues when multiple TUs import the same modules. Fixes <rdar://problem/13187143>.

Swift SVN r4170
2013-02-23 21:13:50 +00:00
Joe Groff
67748972b7 ClangImporter: Value ctors for imported structs.
Emit a value constructor for imported structs so that stuff like NSRect(NSPoint(x, y), NSSize(w, h)) works.

Swift SVN r4168
2013-02-23 20:11:05 +00:00
Doug Gregor
7cc1b6341e Map 64-bit anonymous enums and their enumerators to Int.
Following up on the NS(U)Integer -> Int mapping change, also map
64-bit anonymous enums and their enumerators to Int rather than
directly mapping the underlying integer type. This improves
interoperability with NSInteger types, allowing (e.g.) comparisons of
NSIntegers to NSNotFound.


Swift SVN r4089
2013-02-19 23:04:29 +00:00
Doug Gregor
e6880810ac Map NS(U)Integer to Int in the module importer.
This makes NS(U)Integers fit better with more Swift code, although
it's unfortunate that NSNotFound doesn't get the right type. 


Swift SVN r4088
2013-02-19 22:41:46 +00:00
Joe Groff
74589d788e Make ObjC-ness implicit to ObjC-inherited classes.
Add 'isObjC' as a property of ValueDecl, and set it during type checking if a class is either explicitly annotated with an [objc] attribute or inherits from an isObjC class, or if a func is a method of an isObjC class. Tweak the ClangImporter and other places that summon magic ValueDecl nodes to set up the decls they synthesize as isObjC. Replace logic in typechecking and IRGen that branched on the 'isObjC' attribute to now branch on the 'isObjC' property of ValueDecls.

Swift SVN r4078
2013-02-19 02:11:09 +00:00
Doug Gregor
7ff6df658c Remove unused variable
Swift SVN r4074
2013-02-18 19:19:11 +00:00
Doug Gregor
8ffd2d4df0 Always rely on Clang lookups, not Swift lookups, to establish method overrides for imported methods.
r4035 introduced overridden-method searches into the Clang importer by
looking into the Swift declarations. However, because Objective-C
allows forward declarations, there's no order in which we could
populate the Swift declarations to ensure that all of the appropriate
overrides were found. Instead, we do the right (and lazy) thing of
performing the lookup within Clang, then importing the results. This
change also introduces caching for mirrored protocol imports, so they
can be imported lazily.

Fixes <rdar://problem/13219096>.



Swift SVN r4072
2013-02-18 19:14:56 +00:00
Doug Gregor
5c26e6cc3d Make sure that the output stream gets flushed before forming the result of getObjCSelector().
Swift SVN r4037
2013-02-13 21:03:11 +00:00
Doug Gregor
b660580f35 Don't permit calling static methods on an instance <rdar://problem/13206762>.
Swift SVN r4033
2013-02-13 19:27:39 +00:00
Jordan Rose
67eaa1abb4 Silence -Wunused-variable warnings.
No functionality change.

Swift SVN r3988
2013-02-08 00:19:54 +00:00
Doug Gregor
32855fa161 Handle negation in imported constants, for both macros and enumerators.
Swift SVN r3963
2013-02-06 01:35:04 +00:00
Doug Gregor
a9a90fd56a Track the Clang macros that were used to generate Swift constants.
Swift SVN r3960
2013-02-06 00:57:03 +00:00
Doug Gregor
03b1689b60 Import C enumerations into usable struct types in Swift.
Import C enumeration types as either structs wrapping the underlying
integral type (when the C enumeration type has a name) or as the
underlying integral type (when the C enumeration type has no
name). The structs have a constructor from the underlying integral
type, so one can write, e.g., NSStringCompareOptions(0) to get a
zero-valued enumeration.

Enumerators are imported as a global read-only properties.

Once oneofs start to work, we'll have a way to map some enumeration
types to oneofs, either via a Clang attribute or by sniffing out
NS_ENUM (most likely both).

Once we have static data members of structs working, we'll replace the
global constants with prefix-stripped static variables within the
struct, so we can use ".foo" notation with them.

Once we have constant declarations, we'll map to those instead of
properties.

We can add |, &, and ~ operations are part of
<rdar://problem/13028799> and have not yet been implemented.

Fixes <rdar://problem/13028891>.


Swift SVN r3945
2013-02-05 00:01:27 +00:00
Doug Gregor
0bb9f88793 Map user/library-level redefinitions of id, Class, and SEL in Objective-C to their built-in equivalents.
This makes sure that, when we load the real Foundation module, all
references to id/Class/SEL get mapped to NSObject/NSObject/ObjCSel.

Note that you'll need Clang r174234 for this to actually work
properly. Clang modules weren't coping with these redefinitions
appropriately.


Swift SVN r3934
2013-02-01 23:47:50 +00:00
Doug Gregor
299df79a43 Import Objective-C protocols properly, by introducing and using the This type
Swift SVN r3932
2013-02-01 22:28:04 +00:00
Doug Gregor
647912c3a3 "Inherit" constructors from imported Objective-C classes.
Addresses <rdar://problem/13028771>, so now we can do silly things like

  var x = new NSMutableString




Swift SVN r3931
2013-02-01 21:52:07 +00:00
Doug Gregor
272059ee55 Import init methods from protocols as constructors in classes that conform to those protocols.
Swift SVN r3927
2013-02-01 19:59:13 +00:00
Joe Groff
90afff0240 Typo in comment
Swift SVN r3924
2013-02-01 18:18:56 +00:00
Doug Gregor
d17b175a29 When importing an Objective-C class, category, or extension that
explicitly conforms to protocols, mirror any protocol methods that
aren't also declared in the class/category/extension within the
extension. Among other things, this makes sure that "-hash" and
"-isKindOfClass:" are available on NSObject (they come from the
NSObject protocol). 

Fixes <rdar://problem/13074691>.


Swift SVN r3920
2013-02-01 00:44:53 +00:00
Joe Groff
4f73bd5cb6 ClangImporter: Initializer type for imported ctors
Update the Clang importer to setInitializerType on the ConstructorDecls it creates.

Swift SVN r3863
2013-01-25 17:50:53 +00:00
Jordan Rose
2c86130a8f Remove ScriptingBridge compiler hack, tests, and adapter library.
It wasn't good enough and we're not going to use it.

Swift SVN r3834
2013-01-22 21:29:15 +00:00
Jordan Rose
fa197bff3a The latest OSX 10.9 SDKs have changed name of the ObjC module to ObjectiveC.
Update everywhere in Swift that refers to this module accordingly.

This change is backwards-incompatible and will require rebuilding any
Objective-C-based object files. I recommend a clean of swiftFoundation
and NSStringDemo at the very least. The swiftObjC target is also being
renamed to swiftObjectiveC for consistency.

Swift SVN r3784
2013-01-17 19:46:39 +00:00
Jordan Rose
bfa017d711 For now, don't import properties in protocols at all (for real this time).
Uncomment the commented-out-for-testing lines in r3733.

Swift SVN r3737
2013-01-11 01:50:16 +00:00
Jordan Rose
31cdecb624 For now, don't import properties in protocols at all.
We can't IRGen the getter and setter thunks, and we don't want to import
the getter and setter methods individually because that's not
source-compatible with properties in Swift. Support for importing
protocol properties properly is tracked in <rdar://problem/12993073>.

Swift SVN r3735
2013-01-11 01:46:34 +00:00
Jordan Rose
355dc02dd2 Fix import for SB(Typed)ElementArray.
Its owning module is ScriptingBridge, not Foundation.

Swift SVN r3722
2013-01-10 00:53:56 +00:00
Jordan Rose
f8ddd7c1b5 Add SBTypedElementArray as a typed variant of SBElementArray.
This uses the same hack as NSArray / NSTypedArray.

Swift SVN r3720
2013-01-09 22:53:27 +00:00
Doug Gregor
a6ca4cee66 Rename "objc" module to "ObjC", to match what we're doing in the SDK.
Swift SVN r3652
2013-01-03 00:28:46 +00:00
Doug Gregor
e224c49121 Using numbering of parameters to cope with Objective-C selector identifiers.
This maps methods with selectors that have repeated names, such
as performSelector:withObject:withObject:, to function types for which
one can meaningfully call with named arguments. Once an identifier has
been seen as a parameter name, subsequent parameters will have a
number appended to them, so we'll end up with calls like

  foo.performSelector(sel, withObject=x, withObject2=y)





Swift SVN r3645
2013-01-02 21:39:56 +00:00
Doug Gregor
394172aafe Import Objective-C protocols as Swift [objc] protocols.
When we import an Objective-C protocol, we add the "Proto" suffix to
the name to avoid collisions when a class and protocol have the same
name. Of course, one's "Proto"-suffixed declarations will still
conflict, so this rule isn't great.


Swift SVN r3642
2013-01-02 20:52:25 +00:00
Doug Gregor
2b2b2cfc31 Replace the constructor 'alllocates_this' attribute with an 'allocate-this' expression.
By splitting out the expression used to allocate 'this' (which exists
in the AST but cannot be written in the Swift language proper), we
make it possible to emit non-allocating constructors for imported
Objective-C classes, which are the only classes that have an
allocate-this expression.


Swift SVN r3558
2012-12-20 15:28:37 +00:00
Doug Gregor
aaea6d94cf Import Objective-C properties annotated with 'iboutletcollection' as typed collections.
This commit only covers semantic analysis. We're still not able to
IRgen a downcast from a concrete class to an archetype.


Swift SVN r3535
2012-12-18 23:12:33 +00:00
Doug Gregor
d2c40eeccd Move the ObjCBool type into the 'objc' module.
Swift SVN r3533
2012-12-18 22:06:48 +00:00
Doug Gregor
d4980b67b3 When naming a Swift type from the Clang importer, also provide a module to look in.
No actual functionality change, yet.


Swift SVN r3532
2012-12-18 21:56:14 +00:00
Doug Gregor
03482134f4 Use proper 'this' parameter types for Objective-C getter/setter thunks.
As part of this, also wire up overridden subscript declarations.


Swift SVN r3484
2012-12-13 22:24:03 +00:00
Doug Gregor
675204b5fd Don't map Objective-C methods in the 'new' family to Swift constructors.
Swift SVN r3435
2012-12-11 00:33:13 +00:00
Jordan Rose
8fba78fdba Import [ibaction] and [iboutlet] attributes from Clang.
...although we're not planning to use them for anything. (It's possible they
need to be inherited for ibtool to work correctly, but that's a long ways
off.)

Swift SVN r3433
2012-12-11 00:09:11 +00:00
Doug Gregor
48ac908a8e Map the Objective-C BOOL type to a new ObjCBool Swift type.
The ObjCBool type interoperates with Swift's native Bool type, so one
can use true/false as well as conditionals with Objective-C
functions/methods that involve BOOL.


Swift SVN r3410
2012-12-07 20:02:49 +00:00
Doug Gregor
60aecc415f Provide more bogus source information for synthesized ASTs.
This is just a band-aid to avoid freaking out the diagnostic
system. I'm looking into alternative solutions.



Swift SVN r3409
2012-12-07 19:46:17 +00:00
Doug Gregor
3c7d9d0f62 Don't import inline Clang functions; they won't work.
Eventually, we'll need to teach Swift's IRgen how to call into Clang's
IRgen to cover this case. <rdar://problem/12837078>


Swift SVN r3408
2012-12-07 19:20:12 +00:00
Doug Gregor
aecd8d4432 When accessing a member of a tuple rvalue, materialize the tuple.
Fixes <rdar://problem/12830375>.


Swift SVN r3395
2012-12-07 01:59:27 +00:00
Doug Gregor
4c71d7386a Implement getter/setter thunks for imported Objective-C properties.
With this, we are able to access Objective-C properties from within Swift.


Swift SVN r3393
2012-12-07 01:11:52 +00:00
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