Commit Graph

1877 Commits

Author SHA1 Message Date
Jordan Rose
3e5332217b Forward -I option on to the module importer.
This allows us to add additional module import paths besides those provided
in the sysroot. This is necessary for the demo (so we can import our custom
ScriptingBridge header file) and will probably be needed in some form in the
long run to support mixed Swift/Objective-C projects.

Swift SVN r3721
2013-01-10 00:53:55 +00:00
Doug Gregor
f40f990d9d Improve our logic to emit all of the thunks generated by the Clang importer.
Swift SVN r3651
2013-01-03 00:18:34 +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
319a100189 Allow diagnostics to accept declarations in lieu of source locations.
Swift's diagnostic system is built on the quaint notion that every
declaration known to the front end has a valid source location to
which diagnostics mentioning that declaration (say, in a "here is a
candidate" note) can point. However, with a real module system, the
source corresponding to a declaration in a module does not need to be
present, so we can't rely on source locations.

Instead of source locations, allow diagnostics to be anchored at a
declaration. If that declaration has source-location information, it
is used. Otherwise, we just drop source-location information for
now. In the future, we'll find a better way to render this information
so it feels natural for the programmer.


Swift SVN r3413
2012-12-07 22:51:11 +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
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
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
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
a79f61a4a7 Add missing #include to fix compilation with mainline Clang
Swift SVN r3326
2012-12-03 15:34:03 +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
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
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