Commit Graph

687 Commits

Author SHA1 Message Date
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
Doug Gregor
a8702619bc Clang importer: use proper Clang context when omitting needless words.
When we're omitting needless words and building Swift name lookup
tables, make sure to use the proper Clang
Sema/Preprocessor/ASTContext. This still needs to be properly
detangled, but at least now we can handle omit-needless-words for
builtin Clang types (e.g., SEL) properly.

As part of this, put OmitNeedlessWords and InferDefaultArguments into
the module file extension hash for the Swift name lookup tables, since
those settings will affect the results.
2015-12-17 15:24:59 -08:00
Doug Gregor
b858ba3e1a Clang importer: factor out "should this declaration be imported?". NFC 2015-12-17 15:24:59 -08:00
Doug Gregor
f7fd6d4f59 Clang importer: use lookup table version number in the module file extension hash.
We were verifying the Swift full version information from the module
file extension metadata for the Swift name lookup tables, but not
actually putting it in the hash, which meant that having an older
module cache around would cause spurious failures when Swift name
lookup tables were enabled. Instead, use just the major/minor version
numbers of the lookup tables. When the lookup table format or contents
of the lookup table change, we'll bump the version number.
2015-12-17 10:27:13 -08:00
Doug Gregor
48ec67c324 Clang importer: filter out declarations found in the Standard Library.
With this, everything builds and runs properly when the Swift name
lookup tables are enabled for AnyObject and module-scope lookups.
2015-12-17 07:11:49 -08:00
Doug Gregor
d71de5d860 Clang importer: filter out hidden Clang entries from name lookup.
The Swift name lookup tables record name -> declaration mappings
without respect to submodule visibility. When we do name lookup via
those lookup tables, filter out declarations that are not visible.

Note that this implementation is broken in the same way that the
pre-name-lookup-tables implementation is broken, because it uses
Clang's declaration visibility indicators rather than filtering out
based on submodule lookups. We should fix this behavior to provide
proper submodule lookup, but not until after we've matched the
existing behavior with Swift's name lookup tables.
2015-12-17 07:11:48 -08:00
Doug Gregor
908e2ac721 Clang importer: Make sure we're building Swift lookup tables for the bridging header. 2015-12-17 07:11:48 -08:00
Doug Gregor
b8c530db06 Clang importer: implement global visible-declaration using the lookup tables.
Implement the lookup used by code completion, typo correction, etc. to
use the Swift name lookup tables when they are enabled.
2015-12-16 11:21:38 -08:00
Doug Gregor
2bd31a0e10 Clang importer: introduce "alternate declarations" for redundant imported decls.
There are some Clang declarations that end up being imported as
multiple declarations in Swift, e.g., CF types get imported both with
and without the "Ref" suffix, subscript getters get imported both as a
method and as a subscript, etc. Track this explicitly so it's easy to
query the alternate declaration of a given declaration for name
lookup.

In many of these cases, the alternate declarations should simply go
away, because they're bloating the API. But that's a Swift 3 change
that requires review. For now, we want parity between the behavior
without and with Swift name lookup tables.
2015-12-16 11:21:38 -08:00
Doug Gregor
fee4be3020 Swift name lookup tables: use lookup tables for module-scope lookup. 2015-12-16 11:21:38 -08:00
Doug Gregor
69940d166c Clang importer: use Swift name lookup tables for all dynamic lookup searches. 2015-12-15 14:09:44 -08:00
Doug Gregor
04bc410110 Clang importer: use StringRef to hash constant strings
... because we were hashing the pointer value of the constant string.
2015-12-15 14:09:44 -08:00
Doug Gregor
d421a4fc0a Clang importer: use Swift name lookup tables for AnyObject member lookup.
When we're building Swift name lookup tables, use them for AnyObject
member lookup rather than falling back to the Objective-C selector
table.
2015-12-14 22:05:04 -08:00
Doug Gregor
27fad7d21d Clang importer: feed a Clang prepprocessor through to canInferDefaultArgument.
Omitting needless words while importing the full name function
involves inference of default arguments, so we can get here while
building Swift name lookup tables. It takes a lot of machinery to
trigger this problem; tests forthcoming.

There *must* be a better way to ensure this never happens, but it
requires a bit more refactoring in the Clang importer.
2015-12-14 15:43:05 -08:00
Doug Gregor
563bdb9156 Clang importer: remove support for implicit properties.
We decided not to support "implicit" properties, where we import
getter/setter pairs as properties. Rather, we only import a property
when there is an explicit "@property" in Objective-C. Remove the flag
and supporting code for implicit properties.
2015-12-14 14:33:07 -08:00
Doug Gregor
f8a76d10c0 Clang importer: add macros to the Swift name lookup tables.
Refactor the storage within the name lookup tables to handle
declarations and macros together. Start populating the tables with
macro information.
2015-12-08 22:56:28 -08:00
Doug Gregor
86701de88a Clang importer: (de-)serialize Swift name lookup tables via module file extensions.
The recently-introduced module file extensions functionality in Clang
allows us to piggy-back the Swift name lookup tables in Clang's module
files. When the Swift name lookup tables are enabled, introduce such a
module file extension, and wire it into the SwiftLookupTable.

The actual contents of the extension block are simple: a single
on-disk hash table mapping base names to "full entries", which store
the context (e.g., a class, protocol, tag, or TU) and the set of
declarations.

Allow lazy resolution of declaration IDs deserialized from the
extension block to Clang declarations, to try to minimize the set of
declarations we must deserialize. Name lookup itself is only used to
dump the Swift name lookup tables and ensure we're round-tripping
properly.
2015-12-08 17:34:04 -08:00
Doug Gregor
8b82a674ec Clang importer: decouple importFullName from a specific Clang ASTContext. 2015-12-08 17:34:04 -08:00
Doug Gregor
c934bef1c5 Clang importer: C's bool is an integer type for the purposes of mapping nonzero error results. 2015-12-04 12:43:17 -08:00
Doug Gregor
8c84a067af Clang importer: include subscripts in the Swift name lookup tables. 2015-12-03 13:54:55 -08:00
Doug Gregor
1e432568bc Clang importer: Swift 2 lowercased subsequent argument names coming from Objective-C selectors. Mimic this. 2015-12-03 11:50:43 -08:00
Doug Gregor
d9ce07fa41 Clang importer: when dropping the variadic parameter, drop the variadic parameter.
Fixes iOS build.
2015-12-03 11:50:43 -08:00
Doug Gregor
2ea58f93b0 Clang importer: handle CF type renaming in importFullName.
Ensures that the Swift lookup tables get transformed name for imported
CF types, including original name (which is still
available). Otherwise, this is an NFC refactoring that gets the last
of the naming tricks into importFullName.
2015-12-03 11:50:43 -08:00
Doug Gregor
50eea9cdbc Clang importer: handle omit-needless-words for methods in importFullName. 2015-12-03 11:50:43 -08:00
Doug Gregor
2d7044c024 Clang importer: move name translation for throwing methods into importFullName.
The translation from the Objective-C NSError** convention into Swift
throwing methods alters the names of methods. Move that computation
into importFullName. This should be NFC refactoring for everything
except the Swift name lookup tables, which will now correctly reflect
this name translation.
2015-12-03 11:50:42 -08:00
Doug Gregor
4c50598916 Clang importer: switch method name import to importFullName().
This lets us kill the redundant Objective-C selector to DeclName
mapping used only for methods.
2015-12-03 11:50:42 -08:00
Doug Gregor
13c1805b90 Clang importer: teach importFullName about dropping certain variadics.
This moves the hack used for UIActionSheet and UIAlertView's variadic
designated initializers over into importFullName().
2015-12-03 11:50:42 -08:00
Doug Gregor
91d1c3b21a Clang importer: use importFullName for factory methods as initializers.
Eliminates one of the redundant places where we map Objective-C
selectors over to Swift names.
2015-12-03 11:50:42 -08:00
Doug Gregor
fedb6a8b8a Clang importer: give importFullName a richer result type.
Capture the imported name, as well as some information about it, in
the result of importFullName. Some of the clients need this
information.
2015-12-03 11:50:41 -08:00
Doug Gregor
ec912440e1 Clang importer: teach importFullName about factory methods as initializers. 2015-12-03 11:50:41 -08:00
Doug Gregor
eedf0fc1db Clang importer: teach importFullName to map init methods to initializers.
We're only using this in the Swift lookup tables at the moment.
2015-12-03 11:50:41 -08:00
Doug Gregor
9ee502bede Clang importer: omit non-accessibility property getters/setters from lookup table.
The getters and setters for Objective-C @property declarations are
never found by name lookup, so don't introduce them into the Swift
lookup tables. Note that we exclude some of the accessibility
declarations for unrelated reasons, as we do elsewhere in the
importer.
2015-12-03 11:50:41 -08:00
Doug Gregor
5776fa59c6 Clang importer: migrate "Protocol" suffix computation into importFullName.
Refactoring that lets the Swift lookup tables get the names right for
Objective-C protocols that would conflict with another entity in the
same module (or within the bridging header). It's an NFC cleanup
everywhere else.
2015-12-03 11:50:41 -08:00
Doug Gregor
2244cb4fc8 Swift lookup tables: start testing and cleaning up handling for Objective-C.
Start testing the construction of the Swift lookup tables in the Clang
importer for Objective-C entities. Fix some obvious issues, e.g.,
category and extension entries should be associated with the
corresponding class, and the categories/extensions shouldn't have
entries in the lookup table.
2015-12-03 11:50:41 -08:00
Doug Gregor
fa865c7165 Clang importer: handle enumerator prefix stripping in importFullName().
Centralize the mapping of C names to Swift names further by including
enumerator prefix stripping, rather than having that as a separate
path. The actual logic and code for computing the prefix is unchanged
(despite moving from one file to another). This corrects the name
computed for the Swift lookup tables, but is an NFC refactoring for
everything else.

With this, kill off importName(), because it's been entirely
superseded by importFullName().
2015-12-03 11:50:40 -08:00
Doug Gregor
c41535a7fb Clang importer: start computing the effective lookup context with the name.
This places enumerators that will become either cases of a Swift enum
or options in a Swift option into the context of the C enum type for
the name lookup table.
2015-12-03 11:50:40 -08:00
Doug Gregor
28dea3bc27 Clang importer: recursively add members to the Swift lookup tables.
This is needed for member lookup via the Swift lookup tables, although
the lookup part is not yet implemented. Note also that the results are
currently wrong for C enumerations mapped into Swift enums or option
sets. That will come shortly.
2015-12-03 11:50:40 -08:00
Doug Gregor
f798d53f92 Clang importer: convert more importName callers over to importFullName. NFC
The sole remaining caller to importName is for enumerators, which may
have prefixes that need stripping. That refactor will come in a
subsequent commit.
2015-12-03 11:50:40 -08:00
Doug Gregor
3caf703d47 Narrow the Clang importer's importDeclName to just importIdentifier. NFC
We never used it for non-identifier names, and the former is somewhat
ambiguous with the new importFullName.
2015-12-03 11:50:39 -08:00
Doug Gregor
a861a7345e Clang importer: introduce "importFullName" to centralize name-mapping logic.
The Swift lookup tables are the primary client and test vehicle right
now. This change adds the capability to use the swift_name attribute
to rename C functions when they are imported into Swift, as well as
handling the swift_private attribute more uniformly.

There are a few obvious places where I've applied this API to
eliminate redundancy. Expect it to broaden as the API fills out more.
2015-12-03 11:50:39 -08:00
Doug Gregor
c2bf16c0a9 Clang importer: start building a Swift name -> Clang declarations table.
When we parse a bridging header, start building a mapping from Swift
names (both base names and full names) to the Clang declarations that
have those names in particular Clang contexts. For now, just provide
the ability to build the table (barely) and dump it out; we'll grow
it's contents in time.
2015-12-03 11:50:39 -08:00
shrx
ea1ced5873 fix some cases
for consistency
2015-12-03 19:48:51 +01:00