Commit Graph

528 Commits

Author SHA1 Message Date
Doug Gregor
3ffbe020d7 [Clang importer] Handle name mapping for "getter:" and "setter:" in swift_name.
The swift_name string format now supports "getter:" and "setter:"
prefixes to indicate that a function is the getter or setter of a
Swift-synthesized property. Start parsing these DeclNames and make
sure they're reflected in the Swift name lookup tables.

[Clang update required]
2016-03-01 15:33:21 -08:00
Doug Gregor
7265328e07 [Clang importer] Generalize name lookup tables for globals-as-members.
A swift_name attribute on a global declaration can specify a dotted
name (e.g., SomeStruct.member) to map that global into a member of the
(Swift-)named type. Handle this mapping in DeclName parsing, plumb it
through importFullName, and cope with it in the Swift name lookup
tables (tested via the dump) and importing into a Swift DeclContext
(as-yet-untested). Part of SE-0033.
2016-03-01 15:33:20 -08:00
Doug Gregor
1d9da2e803 [Clang importer] Parse swift_name attribute before looking at the contents.
This reduces our dependency on the actual swift_name string format. NFC
2016-03-01 15:33:20 -08:00
AnnaZaks
767d9ca914 Merge pull request #1434 from apple/asan
[asan] Add basic support for Address Sanitizer function instrumentation
2016-02-29 18:58:40 -08:00
Doug Gregor
940a65a994 [Clang importer] Make the "effective context" a core part of ImportedName.
Previously, the "effective context" parameter to importFullName was
used only during the construction of Swift name lookup tables, so we
can associate each declaration with a context. Expand the role of
"effective context" so it is always a part of ImportedName and is also
used by importDecl when actually importing the enum declaration.

This is partially a cleanup, and partially staging for SE-0033, which
will require this functionality more broadly.
2016-02-29 15:32:34 -08:00
Andrew Trick
ff02652108 Move enums into AttrKind.h.
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.

PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.
2016-02-26 21:10:22 -08:00
zaks
f049c24a02 Introduce a helper to make switching on darwin platforms less error prone
Introduce DarwinPlatformKind, which would allow us to switch on darwin
platforms instead of copying and pasting the brittle logic in several places.
Use the helper method to simplify ClangImporter.
2016-02-23 19:09:25 -08:00
Doug Gregor
c1cc39accc [Clang importer] Rely on Clang's mapping of API notes to attributes directly.
Rather than managing API notes directly in the Clang importer, tell
Clang where to find the API notes files and let it map them directly
to attributes. Then, use the existing attribute-mapping
mechanisms---with minor extensions for cases where Clang previously
didn't map some Swift-specific API notes---to get at that information.

There is a minor regression where we can no longer apply API notes to
declarations that don't have a specific Clang declaration. The
specific example (NSError's inherited init()) comes from
rdar://problem/21042412; we've regressed here, but the correct fix is
(and has always been) on the Objective-C side
(rdar://problem/19977891).

Finishes rdar://problem/24447420.
2016-02-18 16:48:02 -08:00
Doug Gregor
a94e91f8ef [Omit needless words] Properly compute context names for ObjC protocols. 2016-02-17 23:35:41 -08:00
Doug Gregor
ca736fd27c [Omit needless words] Ensure Swift name consistency for overriding/overridden decalrations.
When we transform an Objective-C method or property name, we take into
account the parameter types, result type, and type of the enclosing
context. Doing so means that one can get different Swift names for a
particular method (or property) and one that overrides it, which leads
to dangerous inconsistencies in the Swift names. Address this
limitation by using the original declaration's name (i.e., one that
does not override any other).

It is possible that there is more than one "original declaration",
when the same method/property name comes from different
protocols. When this is the case, check for consistency and complain
if there are inconsistencies.

Amusingly, this changes exactly one method in Cocoa
(UINavigationController's showViewController:sender:), with no conflicts
detected. Fixes rdar://problem/24558337.
2016-02-17 23:35:41 -08:00
Doug Gregor
2604cbe400 [Omit needless words] Don't split subscript accessors. 2016-02-11 16:44:06 -08:00
Michael Ilseman
464c265010 Fix 80 columns 2016-02-10 13:44:32 -08:00
Xi Ge
9ff84e145d [CodeCompletion] For submodules, also use ASTContext to collect their visibility. 2016-02-10 13:03:17 -08:00
Doug Gregor
293d130272 [Omit needless words] Add a flag -enable-strip-ns-prefix to control NS stripping
Stripping "NS" is a massively invasive change; separate it out into
another flag.
2016-02-08 22:41:16 -08:00
Doug Gregor
03c1ac4593 [Omit needless words] Lowercase enum cases/option set members consistently. 2016-02-08 10:32:19 -08:00
Michael Gottesman
150042f246 Pass in clang as arg[0] when invoking clang via the clang importer. Clang is expecting an argv[0] argument. 2016-02-06 11:22:25 -08:00
Michael Gottesman
5e36b3c1c6 Make sure we enable implicit module maps. 2016-02-06 11:22:25 -08:00
Michael Ilseman
283bfefb14 Merge pull request #1196 from milseman/error_enum
[Clang Importer] Import ns_error_domain attribute with _BridgedNSError
2016-02-04 20:45:29 -08:00
Michael Ilseman
c8be2873e8 [Clang Importer] Refactor information pertaining to enums out
Introduces new class, EnumInfo, just for the implementation of the
ClangImporter to encapsulate various computed information about the
enum we're importing.

This helps refactor some functionality, aids clarity, and also
prevents us from repeating calculations multiple times, as we were
doing with classifyEnum's macro-expansion tracking. Provides a base
where we can add more heavy lifting in classifyEnum in the future.
2016-02-04 16:57:22 -08:00
Doug Gregor
319e2a7462 [Clang importer] Strip "NS" prefix from macro names, too 2016-02-03 21:03:09 -08:00
Doug Gregor
74d4ccbf4f Bring back ClangImporter::shouldIgnoreMacro() 2016-02-03 20:06:32 -08:00
Doug Gregor
16deb28eac [Clang importer] Function-like macros are ignored. 2016-02-03 19:50:25 -08:00
Slava Pestov
1396251f3d ClangImporter: Fix a warning, NFC 2016-02-03 16:42:01 -08:00
Doug Gregor
1dec2f1f34 [Clang importer] After stripping a prefix, lowercase initialisms as well. 2016-02-03 16:11:59 -08:00
Doug Gregor
1a2c0b063e [Clang importer] Be more careful when stripping module prefixes.
Clean up our handling of the removal of the "NS" prefix from
Foundation-defined entities in a few ways:

* If the "NS" is followed by a "_", strip that too
* Make sure that the result is still an identifier ("NS123" shouldn't
  become "123"!)
* Don't lowercase ALL_CAPS_NAMES
2016-02-03 16:11:59 -08:00
Doug Gregor
8e000fb738 [Clang importer] Factor mapping of macro names into a single location. NFC 2016-02-03 16:11:59 -08:00
Doug Gregor
d690ca4ae3 [Clang importer] Clean up creation and conflict checking of CF "Ref" type aliases.
CF types are generally imported twice, once with the "Ref" and once
without the "Ref", unless the non-"Ref" version would conflict with
some other declaration (e.g., an Objective-C class of the same name).

The logic to create both versions was a bit convoluted, and tended to
return the "Ref" version as the primary declaration, which conflicts
with our general inclination to use the non-"Ref" version. Now we create
the non-"Ref" version directly and then create the aliased "Ref" version
as an alternate declaration. The "Ref" version is a typealias of the
non-"Ref" version, and the "Ref" version is never used anywhere else
in the AST.

Also, improve the conflict resolution for cases where the only
conflicting declaration is an opaque tag used to declare the CF type
itself, e.g.,

  typedef struct CGImage *CGImageRef;

These cases used to be considered conflicts, but they are benign
because the underlying struct will never actually be imported. Make
them not conflicts, so we get the preferred name "CGImage" rather than
"CGImageRef".
2016-02-01 23:54:27 -08:00
Doug Gregor
1a830fa541 SE-0022: Deprecate string-literal-as-selector in favor of #selector.
Introduce Fix-Its to aid migration from selectors spelled as string
literals ("foo:bar:", which is deprecated), as well as from
construction of Selector instances from string literals
(Selector("foo:bar"), which is still acceptable but not recommended),
to the #selector syntax. Jump through some hoops to disambiguate
method references if there are overloads:

    fixits.swift:51:7: warning: use of string literal for Objective-C
         selectors is deprecated; use '#selector' instead
      _ = "overloadedWithInt:" as Selector
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          #selector(Bar.overloaded(_:) as (Bar) -> (Int) -> ())

In the cases where we cannot provide a Fix-It to a #selector
expression, we wrap the string literal in a Selector(...) construction
to suppress the deprecation warning. These are also easily searchable
in the code base.

This also means we're doing more validation of the string literals
that go into Selector, i.e., that they are well-formed selectors and
that we know about some method that is @objc and has that
selector. We'll warn if either is untrue.
2016-01-28 10:58:27 -08:00
Jordan Rose
9a657f7160 [ClangImporter] Wait until a bridging header is fully parsed to import names.
The presence of one name may affect the import of another name.

https://bugs.swift.org/browse/SR-624
2016-01-27 14:55:16 -08:00
Doug Gregor
312a7f0aea [Clang importer] Strip the "NS" prefix from entities in Foundation.
As part of the improved import of Objective-C APIs into Swift, strip
the "NS" prefix from entities defined in the Foundation
framework. Addresses rdar://problem/24050011, which is part of
SE-0005. Naturally, this is hidden behind -enable-omit-needless-words.
2016-01-20 15:02:54 -08:00
Doug Gregor
72aabcb6f3 Revert "[Clang importer] Strip the "NS" prefix from entities in Foundation"
This reverts commit e51e969b35. This is
a temporary revert to aid in merging to the swift-3-api-guidelines branch.
2016-01-20 13:26:05 -08:00
Doug Gregor
679ee11898 [Clang importer] Eliminate retain cycle involving the Clang importer implementation.
The Clang importer implementation held on to a Clang instance, which
held a list of module file extensions, which included the Clang
importer implementation... break the cycle by separating out the
module file extension from the Clang importer. Fixes SR-562 /
rdar://problem/24225173.
2016-01-20 11:50:55 -08:00
Doug Gregor
e51e969b35 [Clang importer] Strip the "NS" prefix from entities in Foundation
As part of the improved import of Objective-C APIs into Swift, strip
the "NS" prefix from entities defined in the Foundation
framework. Addresses rdar://problem/24050011, which is part of
SE-0005. Naturally, this is hidden behind -enable-omit-needless-words.
2016-01-17 23:40:14 -08:00
Jordan Rose
621edeb664 [ClangImporter] Don't drop "Ref" from a CF types if it creates a conflict.
https://bugs.swift.org/browse/SR-545
2016-01-15 20:12:35 -08:00
Doug Gregor
4971674665 [Clang importer] Teach importFullName to provide argument labels for functions.
importFullName was inconsistent in the kinds of names it produced for
imported C functions. swift_name'd functions would get argument
labels, but non-swift_name'd functions would not, and other parts of
the important were working around the oddity. Make importFullName()
always provide the argument labels.
2016-01-14 11:50:27 -08:00
Doug Gregor
67c81154af Add a swift3_migration attribute to describe how an API gets migrated.
Introduce a new attribute, swift3_migration, that lets us describe the
transformation required to map a Swift 2.x API into its Swift 3
equivalent. The only transformation understood now is "renamed" (to
some other declaration name), but there's a message field where we can
record information about other changes. The attribute can grow
somewhat (e.g., to represent parameter reordering) as we need it.

Right now, we do nothing but store and validate this attribute.
2016-01-13 16:53:01 -08:00
Doug Gregor
4d2480086e [Omit needless words] Use the getter name for BOOL properties.
Rather than employ complicated heuristics to determine when to add
"is" to the name of a Booleam property, just trust the name of the
getter.
2016-01-05 10:43:32 -08:00
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -08:00
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Jordan Rose
c217f01bd6 Merge pull request #743 from kballard/enum-constant-prefix
[ClangImporter] Ignore swift_name when calculating enum constant prefix
2015-12-23 11:14:16 -08:00
practicalswift
81e7439a9a Fix typos. 2015-12-23 11:16:34 +01:00
Kevin Ballard
f047c45ae7 [ClangImporter] Ignore swift_name when calculating enum constant prefix
Enum constants are naturally going to be named after their ObjC name,
not their Swift name. As such, ignore the swift_name attr on the enum
decl when calculating the common prefix. It turns out this is actually
simpler anyway as it also bypasses the swift_private handling that the
code was already trying to work around.
2015-12-22 22:07:06 -08:00
Doug Gregor
a320b6cdc4 Clang importer: centralize the "suppress declaration import" logic.
The Swift name lookup tables and the complete Objective-C "container"
to Swift DeclContext mapping code used similar-but-different logic to
determine when to suppress a declaration (e.g., when suppressing the
accessors for a property). Centralize the logic so we get the same
behavior in both places.
2015-12-22 21:47:01 -08:00
Doug Gregor
6ddce0b042 Clang importer: centralize the logic for importing instance methods as class methods.
Objective-C instance methods of root classes can also be used as class
methods, which we handle by performing a redundant import, the code
for which was scattered. Centralize this import as part of importing
the original (instance) method, and record it as an alternate
declaration to the original instance method. This eliminates a number
of special cases in the Clang importer.
2015-12-22 17:32:44 -08:00
Arsen Gasparyan
be738abb7c Fix else code style 2015-12-22 11:13:26 +03:00
Doug Gregor
3932797480 Implement Clang module's "getTopLevelDecls" using the Swift lookup tables.
Various interface-printing facilities use getTopLevelDecls to
enumerate the top-level declarations of a given module. For modules
imported from Clang, this walked a giant cached list of all
declarations known from Clang, then filtered out those that didn't
fit. Instead, just use the information provided by the Swift name
lookup tables, which is inherently module-specific and complete.
2015-12-21 16:01:21 -08:00
Doug Gregor
f9f9d2db98 Clang importer: add a list of Objective-C categories/extensions to the Swift name lookup table.
We need to be able to query this when enumerating “all declarations”, which is coming soon.
2015-12-21 16:01:21 -08:00
Doug Gregor
68e819069f Clang importer: bring back lookupValue() for LLDB's sake.
... but implemented in terms of the lookup tables.
2015-12-21 11:31:17 -08:00
Doug Gregor
19894754d4 Clang importer: delete most of the old name lookup path. NFC
We now use the Swift name lookup tables for all of these lookups, so
start deleting the older, more ad hoc paths.
2015-12-21 10:30:38 -08:00