Commit Graph

6196 Commits

Author SHA1 Message Date
Joe Groff
527b97895a ClangImporter: Import void* parameters as C*VoidPointer.
Swift SVN r15878
2014-04-03 17:04:37 +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
08e7797f86 [Selector splitting] Drop non-directional prepositions from the beginning of imported argument names.
Swift SVN r15865
2014-04-03 14:22:20 +00:00
Doug Gregor
87144a8afa Make splitFirstSelectorPiece() static, now that it has just one caller
Swift SVN r15854
2014-04-03 04:20:10 +00:00
Doug Gregor
1dd795998f Imported C functions never have API names.
The parameter names in C functions are not API in C and can easily be
inconsistent from one redeclaration to another. Therefore, those
parameter names are not considered API.


Swift SVN r15853
2014-04-03 04:13:29 +00:00
Doug Gregor
a4e16bd8e2 Simple importFunctionType, now that it doesn't handle methods.
Swift SVN r15852
2014-04-03 03:38:35 +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
Doug Gregor
12d0eeb324 Move more of the Clang importer's camelCase logic to the new utilities.
Swift SVN r15843
2014-04-02 23:06:22 +00:00
Doug Gregor
6496d69cb8 Simplify down to a single command-line option for preposition splitting.
Swift SVN r15835
2014-04-02 21:44:19 +00:00
Argyrios Kyrtzidis
23bd9a1933 [ClangImporter] Add ClangImporter::getClangModuleHash().
Swift SVN r15809
2014-04-02 17:39:10 +00:00
Doug Gregor
d6a173fead Add some utilities for working with camelCase names.
Swift SVN r15802
2014-04-02 15:18:32 +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
John McCall
6634e4271d Add UncheckedOptional<T> even to special typedef types.
Swift SVN r15782
2014-04-02 09:37:11 +00:00
Doug Gregor
9189145cc5 Change DeclName over to basename(arg1:arg2:...argN:).
Swift will use the basename + argument names formulation for
names. Update the DeclName interfaces, printing, and __FUNCTION__ to
use the method syntax.

We'll still need to rework the "x.foo:bar:wibble:" syntax; that will
come (significantly) later.

Swift SVN r15763
2014-04-02 00:00:03 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +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
Joe Groff
9789ec1a9d Oops, fix logic inversion.
Swift SVN r15709
2014-03-31 23:41:00 +00:00
Joe Groff
53d9d93749 ClangImporter: Use clang::Type::isObjCObjectPointerType instead of isa<>.
Thanks Jordan!

Swift SVN r15707
2014-03-31 23:27:36 +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
Doug Gregor
2b9b1d0b58 Make preposition list actually match what I'm proposing
Swift SVN r15689
2014-03-31 17:58:37 +00:00
Dmitri Hrybenko
c2354eb365 USR generation: generate USRs for imported macros
I do feel bad about introducing ClangModuleLoader, but it is better than a
layering violation (using libClangImporter from libAST).


Swift SVN r15679
2014-03-31 15:13:00 +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
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
Joe Groff
71404091d4 Add Builtin.fixLifetime as a way for library code to fix object lifetimes.
Lowers directly to the SIL fix_lifetime instruction.

Swift SVN r15637
2014-03-29 22:59:24 +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
Dmitri Hrybenko
286b309970 Return macros in visible decl lookup
This affects code completion and module interface printing.


Swift SVN r15577
2014-03-28 11:15:12 +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
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
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
Argyrios Kyrtzidis
d084edd951 [ClangImporter] Add ClangImporter::getClangOwningModule() for a ClangNode.
Swift SVN r15549
2014-03-27 05:01:12 +00:00
Ted Kremenek
8162660be6 Wire up basic driver support for App Extension restrictions.
The frontend/driver flag is "-application-extension'.  This
activates a language option which will be used for more restrictive
availability checking.

Operationally, this also passes...
  - "-fapplication-extension" to the clang importer
  - "-application_extension" to ld

Swift SVN r15543
2014-03-27 01:05:43 +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
Dmitri Hrybenko
f3faddefb4 Don't return macros in visible decl lookup, this crashes inside Clang while
doing code completion from Cocoa module


Swift SVN r15529
2014-03-26 21:49:18 +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
Jordan Rose
c2f2e7f3c3 [ClangImporter] Handle categories on partial interfaces.
Make sure to resolve a class's signature (which includes its @objc-ness)
before seeing if we should even try to look it up in Clang.

Swift SVN r15524
2014-03-26 21:08:51 +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
30c6eeff16 Module interface printing: pass through documentation comments for imported
declarations

rdar://16408910


Swift SVN r15511
2014-03-26 16:16:02 +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
Dmitri Hrybenko
962c924ab1 Clang importer: put macros into correct module and return them in visible decl
lookup


Swift SVN r15500
2014-03-26 10:27:44 +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