Commit Graph

426 Commits

Author SHA1 Message Date
Dmitri Hrybenko
49fa6738b9 Remove CPointer<T>, it was almost equivalent to UnsafePointer<T>, but
implemented pointer arithmetic.  Enhanced UnsafePointer<T> to do pointer
arithmetic.

Also: update Clang importer to import T* as UsafePointer<T>, fix standard
library fallout.


Swift SVN r5616
2013-06-17 17:10:08 +00:00
Joe Groff
11c7a3a92d ClangImporter: Bridge NSString objc properties to String properties.
We had an inconsistency where the synthesized Swift getter/setters were bridged but the VarDecl wasn't, causing assertion failures in SILGen.

Swift SVN r5366
2013-05-28 22:53:14 +00:00
Jordan Rose
ca498e04ef More -Wdocumentation cleanup.
Swift SVN r5167
2013-05-13 21:41:28 +00:00
Doug Gregor
9a70c0ebf4 [Clang Importer] Refactor the handling of type import contexts.
The importer has always imported types differently in different
places, e.g., function parameter types have special rules for C++
references. Formalize this notion a bit, and make it work properly
when dealing with typedefs where the underlying type itself might be
imported differently in different contexts. 

As part of this, limit the import of C's 'void' type to the result of
a function type.


Swift SVN r5055
2013-05-06 18:10:46 +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
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
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
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
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