Commit Graph

996 Commits

Author SHA1 Message Date
Jordan Rose
97627b1812 [ClangImporter] When matching enum prefixes, handle plural enum names.
...so that the enumerators of this declaration:

typedef NS_OPTIONS(NSUInteger, NSKeyValueObservingOptions) {
    NSKeyValueObservingOptionNew = 0x01,
    NSKeyValueObservingOptionOld = 0x02,
    NSKeyValueObservingOptionInitial NS_ENUM_AVAILABLE(10_5, 2_0) = 0x04,
    NSKeyValueObservingOptionPrior NS_ENUM_AVAILABLE(10_5, 2_0) = 0x08
};

...come in as .New, .Old, .Initial, and .Prior. The code checks for plurals
of the form -s, -es, and -ies, which covers all of the NS_OPTIONS in our SDK.

<rdar://problem/16448966>

Swift SVN r15712
2014-04-01 00:13:27 +00:00
Jordan Rose
e9499430de [ClangImporter] Drop the 'k' prefix of an enumerator named 'kConstant'.
This is more common for static constants, but still occurs sometimes in Cocoa.

<rdar://problem/16451607>

Swift SVN r15711
2014-04-01 00:13:26 +00:00
Jordan Rose
fdbfd2439a [ClangImporter] Revise enum splitting to not stop right before a number.
Otherwise we'd import NSNumberFormatterBehavior10_0 of
NSNumberFormatterBehavior as '10_0'. (Yes, you could escape it, but...)

<rdar://problem/16452174>

Swift SVN r15710
2014-04-01 00:13:25 +00:00
Joe Groff
b9299ed04d ClangImporter: Import pointer parameters as CMutablePointer/CConstPointer.
When we see pointer types in function or method parameters, import them as the bridged CMutablePointer/CConstPointer types instead of UnsafePointer, enabling the array and inout conversions with imported APIs.

Swift SVN r15705
2014-03-31 23:06:50 +00:00
Dmitri Hrybenko
2c96263f02 Clang importer: when importing a macro A that resolves to another macro B, put
the imported macro into the module that owns A, not B

rdar://16449405


Swift SVN r15675
2014-03-31 12:11:19 +00:00
Ted Kremenek
16ffbc6f3a Extend @availability(*,unavailable) checking to protocol methods.
Protocols can declare methods as being unavailable, as they do
in NSObjectProtocol (e.g., 'retain').  We both need to flag these
uses, but understand this for protocol conformance.  For protocol
conformance, treat unavailable methods as if they were marked
optional.  The compiler will not allow you to use these methods
anyway.

This finishes up support for:

    <rdar://problem/16331335> Ban ObjC ARC entry points

Swift SVN r15644
2014-03-30 07:11:39 +00:00
Ted Kremenek
80df698ccc Teach ClangImporter to import __attribute__((unavailable)) as @availability(*,unavailable).
This is a direct translation which happens when a Clang declaration
gets translated to a Swift declaration.  This changed, coupled
with the current @availability checking (which is still limited)
now prohibits cases such as using 'NSDeallocateObject()' or
'- (BOOL) allowsWeakReference' from Swift.

Interestingly, it doesn't catch uses of -retain/-release yet, because
those methods are marked unavailable in the NSObject *protocol*.
While the attributes are being mapped over, the @availability
checking needs to be enhanced to replicate more of what Clang does
for this case.

Swift SVN r15643
2014-03-30 05:25:52 +00:00
Dmitri Hrybenko
1d6c76c352 Module interface printing: pass through documentation comments for imported
declarations

rdar://16408910


Swift SVN r15576
2014-03-28 10:54:06 +00:00
Dmitri Hrybenko
a422886e6f Clang importer: add a workaround so that we don't import literals with ud-suffix
Workaround for rdar://16445608


Swift SVN r15559
2014-03-27 17:59:19 +00:00
Dmitri Hrybenko
92b29ef045 Revert "Module interface printing: pass through documentation comments for
imported declarations"

rdar://16408910


Swift SVN r15527
2014-03-26 21:28:42 +00:00
Dmitri Hrybenko
30c6eeff16 Module interface printing: pass through documentation comments for imported
declarations

rdar://16408910


Swift SVN r15511
2014-03-26 16:16:02 +00:00
Jordan Rose
d98030b9d9 [ClangImporter] Include the enum type name in enum prefix stripping.
This keeps us from accidentally stripping off something semantically
meaningful, like in Foundation's NSDirectoryEnumerationOptions:

  NSDirectoryEnumerationSkipsSubdirectoryDescendants
  NSDirectoryEnumerationSkipsPackageDescendants
  NSDirectoryEnumerationSkipsHiddenFiles

<rdar://problem/15496513>

Swift SVN r15436
2014-03-25 01:43:20 +00:00
Doug Gregor
1a25251ea6 Selector splitting: "scaleXBy" is three words, not two.
Swift SVN r15299
2014-03-20 21:38:04 +00:00
Doug Gregor
5d0abd9849 Another preposition splitting option: directional prepositions.
Swift SVN r15297
2014-03-20 21:24:57 +00:00
Doug Gregor
e03cb7c0a0 Don't split when the preposition is the last word in the first selector piece.
Swift SVN r15244
2014-03-19 20:15:50 +00:00
Doug Gregor
e5fff12bf0 Add option to split Objective-C selectors based on the last preposition.
The frontend option -split-objc-selectors splits the first part of an
Objective-C selector into both a function name and the first parameter
name at the last preposition. For example, this Objective-C method:

  - (NSString *)stringByPaddingToLength:(NSUInteger)newLength withString:(NSString *)padString startingAtIndex:(NSUInteger)padIndex

is imported as

  func stringByPadding toLength(newLength: Int) withString(padString: String) startingAtIndex(padIndex: Int) -> String




Swift SVN r15156
2014-03-17 20:34:48 +00:00
Doug Gregor
163d2fa24d [Clang importer] Go back to mirroring superclass initializers in subclasses.
When importing an Objective-C class, import all of the initializers in
all of its superclasses. When we have no information about designated
initializers for a class, the initializers come in as subobject
initializers. When we do have information about designated
initializers, we (1) use it to sort out subobject from complete object
initializers in that class, and (2) assume that all initializers from
superclasses are complete object initializers. Overall, this better
matches Objective-C's semantics.



Swift SVN r14841
2014-03-09 08:01:37 +00:00
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
1cce7b57bb Add an overlay for AppKit in the clang-importer-sdk.
We don't want to pick up the global overlay.

Swift SVN r14669
2014-03-05 01:51:07 +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
Jordan Rose
9163bc3233 [test] Put a single empty.swift in test/Inputs.
Swift SVN r13666
2014-02-08 00:13:49 +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
Chris Lattner
86d6e4b72d rework this test again to not rely on relative paths. This should unbreak the bot.
Swift SVN r5996
2013-07-04 21:17:16 +00:00
Chris Lattner
4cc4629561 move a helper file for a test into an Inputs/ subdirectory at Jordan's request.
Swift SVN r5994
2013-07-04 19:24:10 +00:00