Commit Graph

425 Commits

Author SHA1 Message Date
Chris Lattner
870df7f266 import noreturn objc methods as swift noreturn function type. I don't
know how to test this presently, but it should theoretically work.



Swift SVN r14727
2014-03-06 07:43:35 +00:00
Chris Lattner
4a827b7de4 enhance the clang importer to import noreturn functions like abort/exit as noreturn
swift functions.  Unfortunately, this can't be satisfactorily tested at the moment,
but that will be fixed soon.



Swift SVN r14709
2014-03-06 00:56:44 +00:00
Jordan Rose
3d313fb3f0 [ClangImporter] Import macros containing a single NSString literal as String.
Bonus goodness related to the previous commit.

Swift SVN r14665
2014-03-05 00:29:44 +00:00
Jordan Rose
a84f939545 [ClangImporter] Import string macros as CStrings.
Also, pass "-std=gnu11" so that we accept UTF-8 strings in these macros.

<rdar://problem/16198953>

Swift SVN r14664
2014-03-05 00:29:43 +00:00
Doug Gregor
9a3a9addd2 Mirror Objective-C initializers in subclasses that don't have designated inits.
This reverts part of r14563, which swapped out the mirroring of
Objective-C initializers into subclasses. We still need to do this
when a subclass does not declare it's designated initializers. At
least the mirroring code is more robust, and marks declarations as
implicit so they won't show up when printed.



Swift SVN r14633
2014-03-04 05:51:44 +00:00
Doug Gregor
6ef8e0792e When an Objective-C class that has designated initializers, mark the other initializers as complete object initializers.
This allows inheritance of complete object initializers from
Objective-C classes.

Swift SVN r14609
2014-03-03 21:38:26 +00:00
Jordan Rose
e02c02b403 [ClangImporter] Import libkern's UInt and SInt as CUnsignedInt and CInt.
This avoids an ambiguity when referring to "UInt" after importing Foundation.

<rdar://problem/14336263>

Swift SVN r14486
2014-02-27 23:32:59 +00:00
Jordan Rose
3e846134e1 [ClangImporter] Don't mirror a protocol's methods if they're in the superclass.
Right now we have a hack to mirror ObjC protocol methods into an imported
ObjC class, because Swift's lookup only looks into superclasses, not into
protocols (by default, anyway). This already isn't great because it's wrong
for @optional, but it was particularly bad if /two/ superclasses conformed
to the same protocol (directly or indirectly). Because the mirrored methods
weren't marked as overrides, the type checker would consider them both as
possibilities, leading to strange errors like this:

  <REPL Input>:1:1: error: ambiguous use of 'description'
  w.description()
  ^
  AppKit.NSWindow:268:8: note: found this candidate
    func description() -> String
         ^
  ObjectiveC.NSObject:72:8: note: found this candidate
    func description() -> String
         ^

Now, we check to see if a superclass conforms to a protocol already before
mirroring its methods into the current class or category.

<rdar://problem/16102321> and possibly also <rdar://problem/16038085>

Swift SVN r14189
2014-02-21 00:35:49 +00:00
Jordan Rose
065d7707f7 [ClangImporter] Import anonymous enums as Int rather than CInt.
More precisely, import anonymous enums with no fixed underlying type as Int
if they would have fit in a 32-bit signed integer. If not, we can't be sure
"Int" is a valid type for code that compiles for multiple architectures.

(Currently that means we'll fall back to the C type, which is probably /also/
wrong for multiple architectures. We could try to be smarter here, since we
have the number of required bits, but let's start with just this.)

Also, remove existing code that assumed that any 64-bit underlying type was
compatible with Int, which it definitely isn't any more on 32-bit platforms.

Part of <rdar://problem/15368372>

Swift SVN r14089
2014-02-19 18:29:45 +00:00
Jordan Rose
11e4afaad0 [ClangImporter] Import "CFIndex" as "Int", just like "NSInteger".
<rdar://problem/16102896>

Swift SVN r14070
2014-02-19 01:12:51 +00:00
Jordan Rose
d71cff5d16 [ClangImporter] Don't create typealiases for NSInteger, uint16_t, etc.
Just use the native Swift names for these: Int, UInt16, etc.

<rdar://problem/16067854>

Swift SVN r14069
2014-02-19 01:12:48 +00:00
Jordan Rose
b67624567b [tests] Using %clang-importer-sdk implies -enable-source-modules.
It isn't great to get this by accident, but the importer SDK contains
more minimal overlay modules than the ones actually used for real SDKs.

Fix up some tests that weren't consistent about whether or not the
minimal overlays were being used.

<rdar://problem/16048012>

Swift SVN r13835
2014-02-12 19:12:42 +00:00
Doug Gregor
eaf410f9f5 Import Objective-C instancetype methods as DynamicSelf methods.
This eliminates a pile of extra casting when interacting with
Objective-C APIs. Addresses the majority of <rdar://problem/14044307>,
but there is still cleanup to do.


Swift SVN r13780
2014-02-11 06:42:53 +00:00
Doug Gregor
a47917246c Import Objective-C properties with custom getter/setter methods.
Retrieve the getter/setter selector from the underlying Clang node,
when there is one. This allows using and overriding Objective-C
properties that have custom getters and setters (i.e., for Boolean
properties where the getter is named isPropName), which narrowly
addresses <rdar://problem/15877160>.

One cannot declare a property in Swift and give it a different
selector. That would require a more general attribute such as
<rdar://problem/16019773>.



Swift SVN r13680
2014-02-08 17:04:31 +00:00
Dmitri Hrybenko
cf1a1b901c Clang importer: add tests for importing some standard C types as word-sized types
Swift SVN r13431
2014-02-04 12:45:17 +00:00
Jordan Rose
d6281b74f8 [ClangImporter] For now, don't import properties with custom accessor names.
Instead, just import them as a pair of methods. This is obviously suboptimal,
but better than the alternative in which you can see the property, but
attempting to use the accessor with the customized name results in a crash
at runtime.

Swift SVN r12755
2014-01-22 18:27:58 +00:00
Jordan Rose
b49b91eee0 Don't import Objective-C ivars at all.
Direct access to ivars is very rare in our frameworks, and they can conflict
with property names (which we should prefer). On top of that, we weren't
even emitting the right code to access them correctly.

<rdar://problem/15818047>

Swift SVN r12604
2014-01-20 19:06:07 +00:00
Jordan Rose
11311d7ce3 [swift2objc] Add tests for structs and typealiases that come from Clang.
We can look through typealiases that come from Swift, but once we get one
from Clang we should be able to just use it.

This was already working in the last commit, but had no tests.

Swift SVN r12086
2014-01-09 01:20:03 +00:00
Doug Gregor
41b6a42067 Clang importer: whitelist certain Objective-C protocols for renaming.
Rather than append the "Proto" suffix to all imported Objective-C
protocols, which can be confusing, whitelist those protocols that we
do have to rename. Only NSObject falls into this category so far.

Fixes <rdar://problem/15741699>.

Swift SVN r11856
2014-01-03 07:04:44 +00:00
Jordan Rose
69a51655c7 [ClangImporter] Instance methods on NSObject are also class methods.
More specifically, instance methods on root objects are also class methods,
because the metatype for that class will inherit from the root class.
(That is, NSObject's metatype extends NSObject.)

This is necessary to allow calling, say, -respondsToSelector: on a class.
Unfortunately, it also brings in every other method on NSObject, including
"informal protocol" category methods like -awakeFromNib. We should probably
disprefer these in code completion, especially if they're declared in another
module, but it is perfectly legal to call these methods on Class objects in
Objective-C.

<rdar://problem/13371711>

Swift SVN r11614
2013-12-24 01:34:07 +00:00
Argyrios Kyrtzidis
3882ab6bd4 [ClangImporter] When checking for NS_ENUM/NS_OPTIONS enums, use clang::Preprocessor::getImmediateMacroName()
and check for CF_ENUM/CF_OPTIONS, which NS_ENUM/NS_OPTIONS expand to.

This:
- Simplifies code
- Handles CF_ENUM/CF_OPTIONS enums
- Handles correctly an NS_ENUM/NS_OPTIONS enum that was itself expanded from another macro.

Swift SVN r11542
2013-12-21 17:40:28 +00:00
Dmitri Hrybenko
c92e1176d4 Add a test for importing bitfields
It does not matter what we actually do, just make sure we don't crash -- we did
not have tests for bitfields previously.  Related: rdar://15671755


Swift SVN r11363
2013-12-16 21:39:34 +00:00
Dmitri Hrybenko
eee1711b0d AST printing: add printing tests for NS_ENUM and NS_OPTIONS
This change moves the swift overlay modules from Clang importer mock sdk to a
central location.  (Otherwise we try to deserialize the Foundation overlay for
the system framework, and crash because we don't find all declarations in
our mock sdk.)


Swift SVN r11297
2013-12-14 04:12:49 +00:00
Dmitri Hrybenko
3d5952383f Clang importer tests: move NSUInteger definition to ObjectiveC module to be
consistent with reality


Swift SVN r11296
2013-12-14 03:32:27 +00:00
Dmitri Hrybenko
d35cf945e6 Move Clang importer test SDK to a toplevel dir test/Inputs where it can be
shared between Clang importer and IDE tests


Swift SVN r11292
2013-12-14 02:20:32 +00:00