Commit Graph

2550 Commits

Author SHA1 Message Date
Doug Gregor
ea647624e3 Eliminate the notion of "selector-style" declarations in the AST.
We still parse them, but the distinction is no longer meaningful
beyond the parsing stage.



Swift SVN r16445
2014-04-17 05:42:58 +00:00
Doug Gregor
8e597cc695 Eliminate argument parameter patterns.
Swift SVN r16444
2014-04-17 05:20:14 +00:00
Ted Kremenek
6caa1d4ae8 Make 'NSInvocation' unavailable.
Implements <rdar://problem/16638093>.

Swift SVN r16441
2014-04-17 04:49:28 +00:00
Doug Gregor
367c69728c Eliminate more uses of ArgParamPatterns.
The code completion change is a (fairly minor) regression, because we
are now printing parameter names when we don't want to. I'll come back
to that.


Swift SVN r16438
2014-04-17 03:55:11 +00:00
Doug Gregor
129aa191a6 Remove the use of ArgParamPatterns in the AST printer and dumper.
Swift SVN r16436
2014-04-17 03:33:46 +00:00
Ted Kremenek
24b8044f19 Ban using performSelector* in Swift.
Swift SVN r16432
2014-04-17 01:22:59 +00:00
Doug Gregor
2d70fbad63 Give initializers compound names.
Swift SVN r16404
2014-04-16 07:44:31 +00:00
Ted Kremenek
2440796aeb Add logic to treat 'performSelector*' as unavailable, but disable it for now.
Turns out 'performSelector' is used in the SDK overlay; that needs
to be resolved first.

Swift SVN r16403
2014-04-16 06:52:12 +00:00
Ted Kremenek
fd864384df Imported '_attribute__((deprecated)' as 'unavailable'.
Swift SVN r16402
2014-04-16 06:52:10 +00:00
Doug Gregor
e12afa2e1d Start naming functions more uniformly.
For any function that has a name, ensure that the name is a compound
name with argument names for each of the parameters. 


Swift SVN r16398
2014-04-16 06:05:45 +00:00
Doug Gregor
db439c1a4a Start introducing declaration names for more function declarations.
Swift SVN r16396
2014-04-16 04:52:07 +00:00
Doug Gregor
54e12fb13b Clang importer: use the selector-based lookup table to avoid importing
methods with conflicting selectors.

We were doing this in a very ad hoc manner before; centralizing the
lookup table should make this significantly more robust. There's also
some scaffolding here to handle initializers better.

Fixes <rdar://problem/16516638>.

Swift SVN r16349
2014-04-15 00:35:41 +00:00
Doug Gregor
b09fbf73b8 Centralize our addition of @objc attributes in the Clang importer.
Swift SVN r16348
2014-04-15 00:35:40 +00:00
Doug Gregor
2dfed7538d Switch the Clang importer over to using ObjCSelector more often.
Swift SVN r16347
2014-04-15 00:35:40 +00:00
Doug Gregor
9520460449 Clean up the import of Objective-C init methods as Swift initializers.
Previously, we would import the init method as a FuncDecl, which
wasn't actually supposed to be used by anything, and then created a
separate ConstructorDecl via importSpecialMember(). That's insane:
just have VisitObjCMethodDecl() produce a ConstructorDecl directly
when given an init method. Should be NFC.

Swift SVN r16313
2014-04-14 14:30:08 +00:00
Ted Kremenek
35c2b6e469 PrintAsObjC: use protocol remapping in the importer to remap to the original protocol name.
Along the way, don't print out the same module import more than once.

Fixes <rdar://problem/16602327>.

Swift SVN r16308
2014-04-14 08:27:11 +00:00
Argyrios Kyrtzidis
e0209fd540 [ClangImporter] Don't update the clang node of the swift decl if one already exists.
If it already has a node it should be the node we want the swift decl to point to,
e.g. the @interface definition. Otherwise we may replace it with a @class forward declaration.

rdar://16560290

Swift SVN r16254
2014-04-12 16:33:40 +00:00
Jordan Rose
8582cc10d8 [ClangImporter] Fix the interface type of imported protocol initializers.
We should be returning the declared type of the implicit 'Self' parameter,
not the archetype.

<rdar://problem/16520667>

Swift SVN r16081
2014-04-08 23:17:10 +00:00
Ted Kremenek
450effff23 Refactor check for animator proxy into helper method. NFC.
Swift SVN r16068
2014-04-08 19:43:39 +00:00
Ted Kremenek
79bddbc66f Import -animator (from NSAnimatablePropertyContainer) as returning 'id' instead of 'instancetype'.
Fixes <rdar://problem/16020273>.

Swift SVN r16050
2014-04-08 08:27:51 +00:00
Jordan Rose
1e14e28461 [ClangImporter] Don't look in protocols when seeing if a method is an accessor.
clang::ObjCMethodDecl::findPropertyDecl does a very general lookup to see if
a particular method /could/ be interpreted as a property accessor, but in
other places we were just using isPropertyAccessor() to decide whether a
method was /actually/ a property accessor. We should use the more conservative
of the two; I'm not sure if the former can /change/ if new protocols are
added (via categories).

This does cause one problem: the setter is now not available in any way on
the adopting class. We should still be exposing it as a method, even though
it's not available as a property.

Swift SVN r16035
2014-04-08 01:23:23 +00:00
Jordan Rose
835bfb15a9 [ClangImporter] Add an option (off by default) to infer "implicit properties".
In Objective-C, any method with no arguments can be used with dot syntax, as
can any method that takes one argument whose name starts with "set". This
commit adds a frontend-only flag -enable-objc-implicit-properties to look for
"setter-like" methods that match up with "getter-like" methods to import them
as Swift properties. By default, such methods are just considered unrelated
methods.

Part of <rdar://problem/16215476>

Swift SVN r16025
2014-04-07 21:49:37 +00:00
Jordan Rose
7810edea97 [ClangImporter] "NSPost" is not a prefix of "NSPostingStyle"
A small error in last week's enum changes.

<rdar://problem/16540910>

Swift SVN r16019
2014-04-07 20:49:54 +00:00
Doug Gregor
4130bb15ff Add a whitelist of designated initializers and use it in the Clang importer.
Seed the whitelist with the designated initializers for NSObject,
NSDocument, and UIDocument. We'll grow this list over time.
Fixes <rdar://problem/16521299>.


Swift SVN r16013
2014-04-07 15:06:59 +00:00
Jordan Rose
13e8d9d27d [ClangImporter] Import properties even if there is a similarly-named method.
...and teach the type-checker to prefer variables to functions.

This matters in Objective-C, where you may have these two members:

@property NSURL *URL;
- (void)URL:(NSURL *)url resourceDidFailLoadingWithReason:(NSString *)reason;

This doesn't happen often, but we should do the right thing when it does.

We still won't import a property named 'foo' if there is already a method
'-foo' that takes no arguments.

<rdar://problem/16383845>

Swift SVN r15963
2014-04-04 23:35:01 +00:00
Jordan Rose
531a3d794d [ClangImporter] Mark mirrored members from protocols as implicit.
Also class versions of instance methods on root classes.

No tests because nothing is actually using the implicit flag besides
SIL printing.

Swift SVN r15953
2014-04-04 20:57:28 +00:00
Jordan Rose
2c62cd4232 [ClangImporter] Maintain the invariant that new members come in last.
Enum elements were being added before the members already in the enum decl.
This was probably harmless, but just in case.

Swift SVN r15909
2014-04-04 01:17:51 +00:00
Doug Gregor
104cfe8919 Clang importer: add some statistics related to selector splitting.
Swift SVN r15873
2014-04-03 16:10:13 +00:00
Doug Gregor
708bb64c6f Migrate initializer importing over to importMethodType().
We now consistently use the method name to form the types of
Objective-C methods.


Swift SVN r15851
2014-04-03 03:32:09 +00:00
Doug Gregor
e418e93511 Start cleaning up method name importing.
Import a selector into a Swift method name, performing splitting at
that point. Use the resulting method name to determine the argument
names of the parameters, rather than trying to chop up the selector
again. There's more refactoring to do here.

This fixes a longstanding bug where the first argument of an
Objective-C method got the internal parameter name when it should
have gotten no name at all.

Swift SVN r15850
2014-04-03 00:34:40 +00:00
Doug Gregor
527b147ba7 Revert "Allow the first name of a selector-style function declaration to be separated."
This reverts r15140.

Conflicts:
	include/swift/Serialization/ModuleFormat.h
	lib/Parse/ParsePattern.cpp

Swift SVN r15846
2014-04-02 23:27:52 +00:00
John McCall
c163b30f1e Enable importing ObjC pointers as UncheckedOptional.
There's no point in maintaining a driver option for this
because of the extent of the library changes required to
make it work.

Swift SVN r15784
2014-04-02 09:37:16 +00:00
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
Ted Kremenek
39dc97738b For "unknown declared type" errors involving remapped types, suggest the remapped type as a fixit.
For example:

  func foo(a: id)

now gets a fixit to turn 'id' into 'AnyObject'.

This relies on the ClangImporter recording the translation as it
processes declarations whose types are remapped.

Swift SVN r15668
2014-03-31 07:10:32 +00:00
Doug Gregor
4f9f945d62 Teach the Clang importer to add @objc(selector) attributes for imported methods and initializers.
With this in place, remove the hacks that peeked at the imported Clang
node to determine the selector for a method. We're all
attribute-driven now. Part of <rdar://problem/16019773>.


Swift SVN r15663
2014-03-31 04:26:32 +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
Doug Gregor
d51744e396 Clang importer: add @objc(name) attributes to imported classes and protocols.
Now that we represent the Objective-C runtime names of classes and
protocols in a uniform way, stop peeking into the Clang AST nodes to
get this information for imported classes and protocols. This is
better layering and helps test that new code path.


Swift SVN r15632
2014-03-29 21:15:29 +00:00
Joe Groff
9f7dab725c Make the ASTContext parameter to MetatypeType::get optional for type-checked types.
We can just get it from the instance type, if the instance type has been fully initialized, which is the case except during parsing of type decls when the decls' own types are being formed.

Swift SVN r15598
2014-03-29 02:50:30 +00:00
John McCall
c3958ea8d7 Import DynamicSelf types as unchecked optionals
when that import mode is enabled.

Patch by Jordan, thanks.

Swift SVN r15574
2014-03-28 05:39:25 +00:00
Doug Gregor
831b444aa1 If only C++ had a definite initialization pass...
Swift SVN r15535
2014-03-26 22:54:16 +00:00
Joe Pamer
bcab632730 When requesting members or protocols from a type declaration, force any delayed members by default. This allows us to pretty-print otherwise unresolved implicit members of imported enums. (rdar://problem/16430343)
Swift SVN r15534
2014-03-26 22:31:02 +00:00
Jordan Rose
3057645677 [ClangImporter] Resolve @partial_interface to a Swift class, like @class.
@partial_interface is like @class, but it allows the user to write categories
or (eventually) subclasses in their Objective-C headers even though the
class will be implemented in Swift. The resolution rules are thus exactly the
same as for class.

I've included a template hack to allow you to keep building without switching
to the new internal Clang repo; in this case you will see one test failure.

<rdar://problem/16426884>

Swift SVN r15523
2014-03-26 21:08:50 +00:00
Doug Gregor
019bb049a1 [Clang importer] Import initializer methods in protocols as initializers.
You can't actually call these initializers with an existential yet, but nor could you safely call the init methods anyway. At least you'll be able to conform to NSCoding with an initializer rather than an "init method". Fixes <rdar://problem/15595471>.

Swift SVN r15521
2014-03-26 21:02:35 +00:00
Dmitri Hrybenko
a15acc0536 Remove duplicated type name in comment and fix some questionable formatting
Swift SVN r15503
2014-03-26 10:59:12 +00:00
Joe Pamer
eebe1ebf37 When importing external enum types, delay the creation of implicit members and their associated support functions until after the types are actually referenced.
This significantly reduces the amount of overhead incurred when naively importing large external modules without referencing many of its members, which should directly improve response times in the playground. For example, the repro code attached to rdar://problem/16387393 imports Foundation but references none of its members, and with these changes its total compilation time is almost 2.5x faster.

Swift SVN r15479
2014-03-26 01:06:27 +00:00
Jordan Rose
5779d43238 [ClangImporter] Resolve forward @protocol declarations like we do @class.
When we see an unresolved @protocol in a Clang module, we now check the name
against the protocols in the Swift module with the same name like we do for
classes.

More <rdar://problem/16295994>

Swift SVN r15472
2014-03-25 23:16:01 +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