Commit Graph

718 Commits

Author SHA1 Message Date
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
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
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
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
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
5071a1752f Import C pointers types as CPointer<T> specializations.
Swift SVN r3332
2012-12-03 17:48:28 +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
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
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
9d299f8bec Import Objective-C instance methods into Swift.
Swift SVN r3240
2012-11-26 17:45:07 +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
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