Commit Graph

6196 Commits

Author SHA1 Message Date
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
8f005fbc63 Always provide Clang with a module cache path, so it doesn't end up in the working directory.
Swift SVN r3334
2012-12-03 19:08:09 +00:00
Doug Gregor
21327d3194 C array types effectively have different behavior in different contexts; don't try to map them now.
Swift SVN r3333
2012-12-03 18:29:46 +00:00
Doug Gregor
5071a1752f Import C pointers types as CPointer<T> specializations.
Swift SVN r3332
2012-12-03 17:48:28 +00:00
Doug Gregor
d26c63332b Provide "C"-prefixed types in the Swift standard library and map the C types over to those types.
Swift SVN r3328
2012-12-03 16:45:55 +00:00
Doug Gregor
a79f61a4a7 Add missing #include to fix compilation with mainline Clang
Swift SVN r3326
2012-12-03 15:34:03 +00:00
Doug Gregor
6e3c947529 Import 'const char *' as Swift's CString.
Swift SVN r3290
2012-11-29 15:25:46 +00:00
Doug Gregor
6c62db48f5 Fix up the Clang resource directory path for autoconf builds.
Swift SVN r3286
2012-11-28 21:42:17 +00:00
Doug Gregor
0be7dba9d2 Set Clang's resource directory appropriately, so it can find its headers.
With this change, I'm able to import Cocoa (using my hacked OSX 10.9 SDK,
naturally) into Swift and poke at various classes and methods with
-parse. Runtime tests still fail, however.



Swift SVN r3274
2012-11-28 00:13:23 +00:00
Doug Gregor
0af8040b78 Optimize memory allocation for the Clang-imported extension cache, somewhat.
Swift SVN r3270
2012-11-27 22:52:04 +00:00
Doug Gregor
e15f75f7e3 Support importing multiple Clang modules into Swift.
This is mostly a hack to work around differences between how Swift and
Clang name lookup into modules works. However, it allows us to load
multiple Clang modules into Swift without causing spurious
ambiguities. The generation-based versioning isn't stricly necessary,
since module imports are resolved up front. However, we may eventually
want to speculatively load modules as part of name binding or type
checking, in which case we'd rather not have stale caches. And it
costs us very little.


Swift SVN r3269
2012-11-27 22:47:31 +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
8b22cb0ff8 Don't reference ClangModule in the general ModuleLoader
Swift SVN r3261
2012-11-27 21:10:09 +00:00
Doug Gregor
a1250b0461 Map Objective-C's 'id' to Swift's NSObject.
Objective-C's 'id' is a very odd type, because it effectively acts as
both a "top" and a "bottom" for the lattice of Objective-C types,
where "top" is a type everything is a subtype of an "bottom" is a type
everything is a supertype of. We almost surely don't want the "bottom"
behavior in Swift, but we also don't have a suitable notion of "top"
yet. protocol<> is closest, but that's too general because it also
allows value types. NSObject is the closest thing we have, for now, so
we use it.


Swift SVN r3260
2012-11-27 21:05:47 +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
d726b3646c Don't import function pointers or member function pointers to Swift.
This functionality will come back when we get support for "thin"
function pointers in Swift, that don't capture anything from their
environment.


Swift SVN r3248
2012-11-26 22:47:15 +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
Joe Groff
3d6748bdd0 clangRewrite is now two libs
In a freshly built clang, clangRewriteCore and clangRewriteFrontend are now separate libs.

Swift SVN r3228
2012-11-17 01:23:59 +00:00
Doug Gregor
d7d9fd48dc When ordinary name lookup into a Clang module fails, try tag name lookup.
Note that we probably also want to do this if we're in a type context
and we found non-type declarations, so that "stat" referenced in a
value context finds the function, but in a type context finds the
type.


Swift SVN r3222
2012-11-17 00:41:55 +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
Doug Gregor
519a9f6942 Import the parameter names from a Clang function declaration.
Swift SVN r3213
2012-11-16 23:05:59 +00:00
Doug Gregor
b0d4242b38 Implement a proper Clang -> Swift type importer.
This importer handles all of the Clang structural types, e.g., builtin
types (int, float, void), function types, block pointer types, and
C pointer types. It does not yet handle nominal types such as enums,
structs, or Objective-C classes, and there are some questions about
(e.g.) array types.



Swift SVN r3212
2012-11-16 22:51:48 +00:00
Doug Gregor
84eee6b54b Factor the implementation of the Clang importer into its own header.
Swift SVN r3205
2012-11-16 20:56:30 +00:00
Doug Gregor
b27c6d94f1 Implement global, unqualified name lookup into Clang modules.
Currently, we only support C functions with the signature
void(void).


Swift SVN r3203
2012-11-16 19:42:03 +00:00
Doug Gregor
a0562f630c Remove unused code to steal resources from a Clang compiler instance
Swift SVN r3202
2012-11-16 18:35:52 +00:00
Doug Gregor
beba49506a Fix makefile build for Clang module imports.
Swift SVN r3200
2012-11-16 18:25:42 +00:00
Doug Gregor
bb26f52585 Initial support for loading Clang modules into Swift.
From a user's perspective, one imports Clang modules using the normal
Swift syntax for module imports, e.g.,

  import Cocoa

However, to enable importing Clang modules, one needs to point Swift
at a particular SDK with the -sdk= argument, e.g.,

  swift -sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9M.sdk

and, of course, that SDK needs to provide support for modules.

There are a number of moving parts here. The major pieces are:

CMake support for linking Clang into Swift: CMake users will now need
to set the SWIFT_PATH_TO_CLANG_SOURCE and SWIFT_PATH_TO_CLANG_BUILD
to the locations of the Clang source tree (which defaults to
tools/clang under your LLVM source tree) and the Clang build tree.

Makefile support for linking Clang into Swift: Makefile users will
need to have Clang located in tools/clang and Swift located in
tools/swift, and builds should just work.

Module loader abstraction: similar to Clang's module loader,
a module loader is responsible for resolving a module name to an
actual module, loading that module in the process. It will also be
responsible for performing name lookup into that module.

Clang importer: the only implementation of the module loader
abstraction, the importer creates a Clang compiler instance capable of
building and loading Clang modules. The approach we take here is to
parse a dummy .m file in Objective-C ARC mode with modules enabled,
but never tear down that compilation unit. Then, when we get a request
to import a Clang module, we turn that into a module-load request to
Clang's module loader, which will build an appropriate module
on-the-fly or used a cached module file.

Note that name lookup into Clang modules is not yet
implemented. That's the next major step.



Swift SVN r3199
2012-11-16 18:17:05 +00:00