Commit Graph

888 Commits

Author SHA1 Message Date
Doug Gregor
f43ecceadd <rdar://problem/13037793> Remove the "ObjectiveC" module name hack now that Clang doesn't need it (per Clang r177621).
Unfortunately, we're replacing that hack with a different hack to work
around the complete lack of mapping from Swift source locations to
Clang source locations.


Swift SVN r4460
2013-03-21 01:29:17 +00:00
Doug Gregor
774b454e0d Fake a source location to pass to Clang when asking it to load a module
Swift SVN r4458
2013-03-20 23:17:43 +00:00
Joe Groff
2e15d99e80 CMake: Install Clang headers.
Move the path for the Clang headers to lib/swift/clang since that's a place swift can find them either in the build dir or in an installation. Arrange for the headers out of the Clang build dir to be installed in the Swift tree.

Swift SVN r4296
2013-03-06 01:29:49 +00:00
Doug Gregor
6adc44dac1 Fix for Clang r175585
Swift SVN r4106
2013-02-20 17:56:58 +00:00
Joe Groff
bd59da3e9e REPL: Find completions from Clang modules.
Integrating Clang's FindVisibleDecls with Swift's by importing every decl created too much per-repl-entry compile time overhead, so as a workaround, just wire completions directly to FindVisibleDecls on the clang translation unit itself. Unfortunately this means we get completions for things Swift can't import yet, but it also means we don't have to wait 30 seconds to compile every entry after doing a completion.

Swift SVN r4061
2013-02-15 22:30:29 +00:00
Doug Gregor
949067001a Don't import 'true' or 'false' from Clang modules <rdar://problem/13187570>.
Swift SVN r4028
2013-02-13 13:56:31 +00:00
Joe Groff
55997e255c ClangImporter: Update for Clang options change.
'-fmodule-cache-path foo' became '-fmodules-cache-path=foo' upstream.

Swift SVN r3982
2013-02-07 22:19:03 +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
Joe Groff
77fc671d91 ClangImporter: Groundwork for importing #defines.
When doing name lookup into a Clang module, look for a macro with the given name and try to convert it into a Swift decl. Turn simple literal macros with expansions <number>, -<number>, or (-<number>) into Swift read-only properties. Map integer literals to Swift 'Int' and float literals to Swift 'Double' for want of a better type to map them to--it would probably be better if we had a decl that behaved like Pascal 'const' and converted like a literal value. Codegen for the synthesized properties isn't wired up, so compiling code that tries to use macro values will currently die because of missing externals.

Swift SVN r3941
2013-02-03 19:06:11 +00:00
Jordan Rose
8f095564aa Update the module importer for Clang r172665.
Only import visible categories as extensions. Don't import hidden ones
(whether from submodules or elsewhere), and most importantly don't use
the raw category chain.

Swift SVN r3792
2013-01-18 00:40:27 +00:00
Jordan Rose
a0c019ed4d HACK: Search for modules in /usr/include/objc/ to find the ObjectiveC module.
The removal of this hack is tracked by <rdar://problem/13037793>.

Swift SVN r3790
2013-01-18 00:40:25 +00:00
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