Commit Graph

767 Commits

Author SHA1 Message Date
Chris Lattner
d3c91387e9 Substantially simplify the API to LValueType now that nonsettable is gone.
Swift SVN r11703
2013-12-28 22:48:44 +00:00
Jordan Rose
69a51655c7 [ClangImporter] Instance methods on NSObject are also class methods.
More specifically, instance methods on root objects are also class methods,
because the metatype for that class will inherit from the root class.
(That is, NSObject's metatype extends NSObject.)

This is necessary to allow calling, say, -respondsToSelector: on a class.
Unfortunately, it also brings in every other method on NSObject, including
"informal protocol" category methods like -awakeFromNib. We should probably
disprefer these in code completion, especially if they're declared in another
module, but it is perfectly legal to call these methods on Class objects in
Objective-C.

<rdar://problem/13371711>

Swift SVN r11614
2013-12-24 01:34:07 +00:00
Argyrios Kyrtzidis
a4ed3e19d0 [ClangImporter] When creating the member declarations for NS_ENUM/NS_OPTIONS, also associate the
clang declaration that they came from.

rdar://15574386

Swift SVN r11543
2013-12-21 17:40:31 +00:00
Argyrios Kyrtzidis
3882ab6bd4 [ClangImporter] When checking for NS_ENUM/NS_OPTIONS enums, use clang::Preprocessor::getImmediateMacroName()
and check for CF_ENUM/CF_OPTIONS, which NS_ENUM/NS_OPTIONS expand to.

This:
- Simplifies code
- Handles CF_ENUM/CF_OPTIONS enums
- Handles correctly an NS_ENUM/NS_OPTIONS enum that was itself expanded from another macro.

Swift SVN r11542
2013-12-21 17:40:28 +00:00
Doug Gregor
be3463f32d Store a file-level DeclContext* in protocol conformances rather than a module.
We'll need to perform name lookup based on the file-level
DeclContext*, so the module no longer suffices. No functionality
change here yet.


Swift SVN r11523
2013-12-20 22:53:21 +00:00
Chris Lattner
b29748a6be remove the ASTContext argument from Type::transform,
(various) FunctionType::get's, ArrayType::get,
ArraySliceType::get, OptionalType::get, and a few
other places.

There is more to be done here, but this is all I plan to do
for now.


Swift SVN r11497
2013-12-20 02:23:21 +00:00
Chris Lattner
1472e4d914 Remove the ASTContext argument from LValueType::get(). It is already
only two loads away from the type argument passed in.



Swift SVN r11496
2013-12-20 01:28:50 +00:00
Doug Gregor
b9696e1c01 Create protocol conformances and then, separately, fill in the witnesses.
This is a structural baby step toward lazily filling in protocol
conformances. We always build a ProtocolConformance, then mark it
either "complete" (when it's well-formed) or "invalid" (when it's
ill-formed). At present, the only benefit to this is that it slows
diagnostic cascades from invalid conformances.


Swift SVN r11492
2013-12-20 00:29:00 +00:00
Jordan Rose
7a30de2efe Disallow inheritance clauses for concrete typealiases.
typealias MyInt: ForwardIndex = Int

There is no real reason to allow this; it's just a static_assert that Int
conforms to ForwardIndex, which would be better spelled some other way.

This only applies to concrete typealiases, i.e. those that simply alias an
underlying type. Associated types can still have both inheritance clauses
and a (default) underlying type.

Swift SVN r11481
2013-12-19 21:13:54 +00:00
Joe Groff
017440165e Fix the weird capitalization of MetaTypeType.
Swift SVN r11475
2013-12-19 18:43:08 +00:00
Dmitri Hrybenko
73875c77e0 Clang importer: don't import BOOL and SEL
Swift SVN r11474
2013-12-19 18:37:23 +00:00
Dmitri Hrybenko
0950901b1b Don't import 'id' and 'Class'
rdar://15693821


Swift SVN r11465
2013-12-19 02:42:13 +00:00
Joe Groff
a9570e2004 ClangImporter: Make NS_OPTIONS conform to LogicValue.
Until we can actually do the implementation work necessary to make 'if optionSetValue.Option {}' work, this is a reasonable affordance to allow the C 'if optionSetValue & .Option {}' pattern to work and bring us to parity with ObjC.

Swift SVN r11412
2013-12-18 02:47:06 +00:00
Dmitri Hrybenko
c54c979f95 Clang importer: don't add @objc *attribute* to imported decls, just set the objc bit
AST printer: print @objc attribute only on top-level imported decls to reduce
the amount of noise.


Swift SVN r11365
2013-12-17 00:50:12 +00:00
Joe Groff
44dcc43fa9 ClangImporter: Make NS_OPTIONS imports conform to RawOptionSet.
This makes the bitwise operations &|^~ work with NS_OPTIONS.

Swift SVN r11349
2013-12-16 19:22:27 +00:00
Doug Gregor
11b6d19dd3 Add a location to NormalProtocolConformance.
This will be used for diagnostics in an upcoming refactor.


Swift SVN r11348
2013-12-16 17:24:15 +00:00
Dmitri Hrybenko
531adcbf45 Remove unused variable
Swift SVN r11293
2013-12-14 02:22:48 +00:00
Dmitri Hrybenko
7e56d75a1e Clang importer: don't import superfluous typedefs to tag decls that have the same name
Not only this creates less ASTs, but this makes the resulting AST correct (it
is invalid to have a struct and a typealias with the same name).  But the
primary motivation is AST pretty-printing: we don't want to print those extra
useless typealiases.


Swift SVN r11289
2013-12-14 01:39:03 +00:00
Dmitri Hrybenko
9d45fe97f2 ClangImporter: factor out a routine to search in the cache
Swift SVN r11282
2013-12-14 00:03:02 +00:00
Doug Gregor
b4a739854d Stop using ProtocolConformance::getWitnesses().
It's going away, soon.


Swift SVN r11277
2013-12-13 23:44:42 +00:00
Chris Lattner
698380d6d3 Introduce a new bit in VarDecl, "isLet". Teach Sema that 'isLet' properties
are not settable (like get-only ones).  Set the 'isLet' bit in various 
places, but not the particularly interesting or useful places yet.



Swift SVN r11121
2013-12-11 06:45:40 +00:00
Dmitri Hrybenko
2f02b021df Remove accidentally committed debugging code
Swift SVN r11112
2013-12-11 01:32:30 +00:00
Dmitri Hrybenko
788912da16 Introduce AnyObject and AnyClass (for 'DynamicLookup' and 'DynamicLookup.metatype')
Also stop importing declarations that don't belong to a Clang module.  'id' and
'Class' were the last two that we cared about.


Swift SVN r11107
2013-12-11 01:07:13 +00:00
Dmitri Hrybenko
73c26e7e4c Clang importer: rename importDeclContext -> importDeclContextImpl to emphasize
that it should not be used directly.


Swift SVN r11043
2013-12-09 22:35:10 +00:00
Dmitri Hrybenko
e27001dbc7 Clang importer: determine the module for enums correctly while importing enum's
decl context


Swift SVN r11039
2013-12-09 22:19:47 +00:00
Argyrios Kyrtzidis
345564380c Rename 'ibaction/iboutlet' attributes to 'IBAction/IBOutlet'.
Swift SVN r10953
2013-12-07 00:14:51 +00:00
Doug Gregor
707d04c3d2 Clang importer: always expand out the (Objective-C) protocol list.
Fixes <rdar://problem/15246440>.


Swift SVN r10876
2013-12-05 19:18:57 +00:00
Jordan Rose
be12d86ddd Turn ClangModule into ClangModuleUnit.
Part of the FileUnit restructuring. A Clang module (whether from a framework
or a simple collection of headers) is now imported as a TranslationUnit
containing a single ClangModuleUnit.

One wrinkle in all this is that Swift very much wants to do searches on a
per-module basis, but Clang can only do lookups across the entire
TranslationUnit. Unless and until we get a better way to deal with this,
we're stuck with an inefficiency here. Previously, we used to hack around
this by ignoring the "per-module" bit and only performing one lookup into
all Clang modules, but that's not actually correct with respect to visibility.

Now, we're just taking the filtering hit for looking up a particular name,
and caching the results when we look up everything (for code completion).
This isn't ideal, but it doesn't seem to be costing too much in performance,
at least not right now, and it means we can get visibility correct.

In the future, it might make sense to include a ClangModuleUnit alongside a
SerializedASTFile for adapter modules, rather than having two separate
modules with the same name. I haven't really thought through this yet, though.

Swift SVN r10834
2013-12-05 01:51:11 +00:00
Jordan Rose
8b8cc8ee62 Turn SerializedModule into SerializedASTFile.
Part of the FileUnit restructuring. A serialized module is now represented as
a TranslationUnit containing a single SerializedASTFile.

As part of this change, the FileUnit interface has been made virtual, rather
than switching on the Kind in every accessor. We think the operations
performed on files are sufficiently high-level that this shouldn't affect us.

A nice side effect of all this is that we now properly model the visibility
of modules imported into source files. Previously, we would always consider
the top-level imports of all files within a target, whether re-exported or
not.

We may still end up wanting to distinguish properties of a complete Swift
module file from a partial AST file, but we can do that within
SerializedModuleLoader.

Swift SVN r10832
2013-12-05 01:51:09 +00:00
Dmitri Hrybenko
d076501cca Don't repeat Context.getIdentifier("self") everywhere in the code base
Swift SVN r10786
2013-12-04 18:42:34 +00:00
Joe Groff
111dd0c248 ClangImporter: Use type name to clip prefix from single-element enums.
Single-case enums actually come up a lot for NS_OPTIONS. Jordan suggested this approach, which works well for now.

Swift SVN r10473
2013-11-14 23:41:37 +00:00
Joe Groff
a1f123350f Enable NS_OPTIONS import by default.
Some work needs to be done on static member lookup and bitwise operations, but what's implemented now isn't a regression from what we have (except for an unfortunate case in Foundation.swift where we need to fully qualify a constant in a single-element NS_OPTIONS).

Swift SVN r10471
2013-11-14 23:21:28 +00:00
Joe Groff
fdd858dd21 ClangImporter: Import NS_OPTIONS constants as static properties.
Apply the same prefix-chopping logic as for NS_ENUM to produce static property names to put inside the Swift type we create. For now, continue importing NS_OPTIONS as structs with a single integer field; in the short term it's easy to put a C-like interface over them this way.

Swift SVN r10434
2013-11-13 23:19:32 +00:00
Joe Groff
975382599e ClangImporter: Rename 'EnumKind::Options' to 'Unknown'.
We're going to implement a newer, better path for 'Options'. No functionality change yet.

Swift SVN r10430
2013-11-13 20:58:06 +00:00
Joe Groff
4f2adbe7ed AST: Include 'static' bit in VarDecls.
And track the 'static' SourceLoc in the PatternBindingDecl. This lets isInstanceMember return the right thing for static vars.

Swift SVN r10369
2013-11-12 06:16:48 +00:00
Joe Groff
774db24a8a Enable importing of NS_ENUMs as Swift enums.
A problem with name lookup from Clang module contexts <rdar://problem/15410928> means I have to disable a ~= overload in the ObjectiveC overlay. Other than that, NS_ENUM import should be ready to go.

Swift SVN r10018
2013-11-07 03:49:37 +00:00
Joe Groff
65632a59a4 ClangImporter: Don't register imported case decls.
This keeps the unqualified enum constant name from sneaking back in after the enum has been imported.

Swift SVN r10016
2013-11-07 03:49:27 +00:00
Joe Groff
c16f7778e2 ClangImporter: Don't expose NS_ENUM cases by their unqualified names.
Only import NS_ENUM constants into Swift enum cases as part of the enum itself, not if the original C constant name is referenced by itself through the Clang module.

Swift SVN r10015
2013-11-07 01:16:08 +00:00
Joe Groff
96d1038c8c ClangImporter: Drop enum constant aliases.
Swift enums don't yet support aliasing of enum cases, so if we see multiple constants in an NS_ENUM with the same underlying value, drop all but the first. Hopefully the first one is the "proper" name for the constant.

Swift SVN r10008
2013-11-06 22:40:08 +00:00
Joe Groff
6370f91383 ClangImporter: Handle negative C enum constants.
We needed some patching up to convert negative enum constants into proper negative IntegerLiteralExprs in the imported Swift AST, to handle the obnoxious INT_MIN edge case, and to handle "negative" values of unsigned enums.

Swift SVN r10005
2013-11-06 21:28:24 +00:00
Doug Gregor
df2a6fe7df Import @optional methods in Objective-C protocols as optional methods/subscripts.
Clean up ListMaker and get it compiling again. Delete all of the
stubbed-out table view delegate methods now that they're optional,
fixing the crash when dragging items <rdar://problem/14582991>.


Swift SVN r9995
2013-11-06 18:39:31 +00:00
Joe Groff
1650a3d75b ClangImporter: Remove common prefix of C enum case names from Swift names.
Swift enum cases are already namespaced to their type, but Cocoa NS_ENUM constants are manually namespaced with a common prefix, so if we imported them as-is, we'd end up with expressions like 'NSStringSearchOptions.NSStringSearchCaseSensitive'. To make this a bit nicer, look for a common prefix of camel-case words among all of the constants in the enum, and remove that prefix from the enum case names in the Swift interface.

In the case of a single enum case, we have no basis for determining a prefix, so do nothing. This case doesn't come up in the frameworks (that I can see).

Swift SVN r9993
2013-11-06 18:15:07 +00:00
Joe Groff
38ceed4e76 ClangImporter: Provide a null SourceLocation when lexing NS_ENUM token.
Using the expansionLoc intermittently leads to an "offset overflow", and we don't really care about the token source location.

Swift SVN r9989
2013-11-06 06:31:22 +00:00
Anna Zaks
54524e622a Replace ExprStmtOrDecl with ASTNode and make it a struct.
Previously, the Parser and BranchStmt typedef-ed ExprStmtOrDecl as a pointer union. Using typedef made the objects compatible, but did not allow us to extend the type with helper methods, such as getSourceRange(), which is something you can get on all of the AST objects. This patch introduces ASTNode that subclasses from PointerUnion and is used by both parser and BranchStmt.

Swift SVN r9971
2013-11-05 21:46:59 +00:00
Joe Groff
5c5d67dd7c ClangImporter: Import enum raw types and values from NS_ENUMs.
Set up the derived RawRepresentable conformance for an imported enum using its C underlying type and constant initializer values.

Swift SVN r9957
2013-11-05 04:28:10 +00:00
Joe Groff
16c5d69e17 ClangImporter: Recognize NS_ENUM declarations and import as Swift enums.
When we see an enum declaration in the Clang importer, look at its source location to see if it was produced as part of an NS_ENUM macro expansion. If so, take the 'Enum' route through the Clang importer and import it as a Swift enum. This will break things until we have end-to-end support for Clang-imported enums, so hide it behind an -import-ns-enum switch for now.

Swift SVN r9951
2013-11-05 01:38:00 +00:00
Joe Groff
5ec3cad5f6 ClangImporter: Emit metadata for imported enums.
Whatever kind of Swift decl we cons up for a Clang enum, add it to the externals list so we can pick it up and emit Swift metadata for it in IRGen. Fixes <rdar://problem/15242452>.

Swift SVN r9801
2013-10-30 18:15:09 +00:00
Doug Gregor
bae79dd8a3 Give imported protocols a proper generic signature.
Swift SVN r9629
2013-10-23 21:20:16 +00:00
Argyrios Kyrtzidis
0dd411d3e8 [ClangImporter] Add appropriate protocol conformances when creating the methods from the inherited protocols.
Swift SVN r9586
2013-10-22 15:47:34 +00:00
Greg Parker
1dbe2ac503 Don't import constructors for class Protocol because they use a symbol that is absent on iOS.
Swift SVN r9500
2013-10-18 21:54:34 +00:00