Commit Graph

2523 Commits

Author SHA1 Message Date
Joe Groff
4dc7628cfd ClangImporter: Drop the variadic parameter to UIKit variadic DIs.
Hack the clang importer to drop the 'otherButtonTitles:' argument when we see the UIActionSheet or UIAlertView init methods, so we'll end up importing them as the non-variadic initializers added by the overlay.

Swift SVN r16717
2014-04-23 21:28:08 +00:00
Jordan Rose
98cc7524bd [ClangImporter] Rewrite enum prefix stripping to use the camel_case helpers.
Previously, we didn't correctly handle acronyms as single words, leading to
importing the NS16BitLittleEndianBitmapFormat enumerator of NSBitmapFormat as
"S16BitLittleEndianBitmapFormat". Now we get "NS16BitLittleEndianBitmapFormat",
which is a little better. See the examples for a few more ways this shakes out.

<rdar://problem/16683848>

Swift SVN r16682
2014-04-23 00:32:39 +00:00
Chris Lattner
7de9c0802a Peel off almost all of the uses of MetaTypeExpr, replacing
them with uses of TypeExpr instead.  The remaining uses of 
MetaTypeExpr (which will be renamed soon) are places where we
are applying the ".dynamicType" virtual property to an expression.

Unadorned uses of types in code, e.g. the Int in "Int.self" are
now represented with TypeExpr.

One unfortunate travesty that doing this work revealed is that we
are extremely sloppy and terrible about maintaining location information
in implicitly generated decls, and our invariants vary quite a bit.  This
is really horrible, but I'm not sure whether I'll go fix the hacks or not.

This patch perpetuates the existing crimes, but makes them more visible.

NFC!




Swift SVN r16646
2014-04-22 05:15:44 +00:00
Joe Groff
5b7659fed9 ClangImporter: Stop building thunks for @objc properties and just use the imported getter/setter decls for the computed property.
This saves us some work producing dead thunks we no longer use, and also makes us correctly handle NS_RETURNS_INNER_POINTER getters.

Swift SVN r16639
2014-04-22 03:13:49 +00:00
Argyrios Kyrtzidis
b3f470ad16 [ClangImporter] Make getting the ClangNode from a swift Decl more efficient by
allocating extra memory and storing it directly before the swift AST object.

Reduces code-completion time for Cocoa by -25%.

Swift SVN r16615
2014-04-21 07:18:50 +00:00
Argyrios Kyrtzidis
b8051b7a8d [ClangImporter] Change an assertion to make sure we have a clang node at that point, which
means we don't need to set it.

Swift SVN r16614
2014-04-21 07:18:48 +00:00
Argyrios Kyrtzidis
a42ad947dc [ClangImporter] Make sure that the clang node is set at the point where the swift node is
created, and introduce Decl::updateClangNode() for when we want to update it.

Swift SVN r16612
2014-04-21 07:18:47 +00:00
Doug Gregor
82a7f1f87b Improve de-duplication logic for imported Objective-C class initializers.
Before we create a new initializer, check whether it would collide
with existing initializers. If it's better than the existing
initializer, mark the existing one as unavailable; if it's not better,
don't build it.

In support of this, we tweak a few things w.r.t. unavailble
declarations:
  - An unavailable declaration is shadowed by an available one,
  - Don't emit SIL unavailable, imported initializers

This fixes the last problem with <rdar://problem/16509024>.



Swift SVN r16611
2014-04-21 06:26:52 +00:00
Doug Gregor
40b2c9f7a4 Create ParamDecls for function parameters in more places.
Swift SVN r16584
2014-04-20 05:57:34 +00:00
Doug Gregor
d647719db2 Remove some unnecessary setDeclContext() calls.
Swift SVN r16576
2014-04-20 03:45:04 +00:00
Doug Gregor
6b3ef547ec Replace "Members" arrays with an intrusive linked list.
The use of ASTContext-allocated arrays to store the members of nominal
type declarations and the extensions thereof is an
abomination. Instead, introduce the notion of an "iterable"
declaration context, which keeps track of the declarations within that
context (stored as a singly-linked list) and allows iteration over
them. When a member is added, it will also make sure that the member
goes into the lookup table for its context immediately.

This eliminates a ton of wasted memory when we have to reallocate the
members arrays for types and extensions, and moves us toward a much
more sane model. The only functionality change here is that the Clang
importer no longer puts subscript declarations into the wrong class,
nor does it nested a C struct within another C struct.



Swift SVN r16572
2014-04-19 23:37:06 +00:00
Doug Gregor
36889a2b1a Introduce DeclIterator and DeclRange for iterating over decl members.
NFC. DeclRange is a range over DeclIterators, and is used rather than
ArrayRef<Decl*> to retrieve the members of a nominal type declaration
or extension thereof. The intent is to change the representation of
DeclRange next.


Swift SVN r16571
2014-04-19 18:53:20 +00:00
Joe Pamer
7245e40825 The type checker collects all overloads for a given function application during the pre-type check phase, but equality conformances (and their associated '==' overloads) may be added to a type lazily during type resolution. This can lead to inconsistent behavior during type checking equality comparisons on imported enumeration types. (rdar://problem/16526249)
Basically, if an imported enumeration case is referenced without qualification as an argument to a '==' application (E.g., "foo.bar == .Baz"), and the enumeration type had not previously been resolved, overloads to '==' will be added to the global scope while performing overload resolution. This means the overloads will be ignored while solving for that application, but will be available for subsequent applications. (So you'll get an "expression does not type check" error the first time around, but not for subsequent applications of '==' to that enumeration type.)

The Equatable protocol is rather lightweight, however, and adding it to imported types directly results in no meaningful overhead to type check performance; we should just add it outright. As things evolve, though, it'll be worth considering how to make the type checker more amenable to lazy declarations.

Swift SVN r16557
2014-04-19 00:12:08 +00:00
Dmitri Hrybenko
e2e8db5f38 Migrate IB attributes to new decl attribute representation and fix a few bugs
along the way


Swift SVN r16542
2014-04-18 20:00:09 +00:00
Doug Gregor
7c6f689d4c Suppress duplicated initializers that come from importing class factories as initializers.
As noted in the FIXME, this is a hack. We need to do a bit of
infrastructure work before we can detect and suppress duplicates like
this in a meaningful way. Name lookup already does a similar thing for
ambiguity-resolution purposes. However, doing this here makes the
printed modules much cleaner.

look significantly more reasonable.


Swift SVN r16531
2014-04-18 17:03:08 +00:00
Doug Gregor
812dc091eb Introduce the notion of factory initializers.
Factory initializers express an initializer that produces an object of
the given type, but is not inherited and not designated. Although they
have a syntactic form for presentation purposes (-> ClassName), there
is no way to specify or implement them within Swift. Rather, factory
initializers are created when importing an Objective-C factory method
that returns the class type rather than instancetype.

Swift SVN r16528
2014-04-18 16:04:48 +00:00
Doug Gregor
d80b689c51 Introduce "convenience factory" initializers.
Convenience factory initializers are convenience initializers produced
by importing an Objective-C factory method as a convenience
initializer. The distinction is currently only used to eliminate the
awful layering violation I recently introduced in name lookup, which
was consulting Clang AST nodes directly. It will also be useful in
SILGen.

Swift SVN r16527
2014-04-18 15:34:26 +00:00
Doug Gregor
8bc2ea4ea1 Use designated/convenience initializer terminology throughout. NFC
Introduce CtorInitializerKind to describe the kind of an enum, rather
than a bool, to make way for more initializer kinds in the future.

Swift SVN r16525
2014-04-18 15:10:13 +00:00
Dmitri Hrybenko
0bfcd45eb7 Clang importer: import noreturn attribute on free functions
rdar://16630302


Swift SVN r16522
2014-04-18 14:40:02 +00:00
Doug Gregor
f700a114f4 Handle inheritance of factory methods imported as initializers.
Swift SVN r16500
2014-04-18 06:14:27 +00:00
Doug Gregor
f390f53151 When imported a factory method as an initializer, mark the factory method unavailable.
Help guide users over to the initializers with the 'unavailable' message, e.g.,

objc_factory_method.swift:24:18: error: 'hiveWithQueen' is unavailable: use 
    initializer 'Hive(withQueen:)'



Swift SVN r16498
2014-04-18 05:48:11 +00:00
Doug Gregor
f56c68386e Start importing factory methods as initializers.
When an Objective-C class method follows the naming convention of a
factory method, i.e., its starting words match the ending words of the
class name, import it as a convenience initializer when it also:
  - Returns instancetype (i.e., dynamic Self in Swift parlance)
  - Has no NSError** parameters, which indicate the potential for failures

This is under a new flag (-enable-objc-factory-method-constructors)
because it is not generally functional. However, this is a step toward
<rdar://problem/16509024>.

Swift SVN r16479
2014-04-17 23:34:00 +00:00
Doug Gregor
1178747fd5 Clang importer: clean up overriding and avoid adding implicit initializers.
Switch the "does this imported declaration override a declaration in
the superclass?" check to perform lookups based on what actually gets
into Swift, rather than looking into the Objective-C class, because
the Objective-C class isn't representative.

Additionally, explicitly avoid adding implicit initializers to an
Objective-C-imported class.

Problems fixed here are tested by an upcoming commit.

Swift SVN r16464
2014-04-17 21:27:58 +00:00
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