Commit Graph

164 Commits

Author SHA1 Message Date
Doug Gregor
75617df37d PrintAsObjC: Stop printing SWIFT_NULLABILITY(keyword).
Everyone's Clang should support nullability qualifiers now.

Swift SVN r28649
2015-05-15 23:46:46 +00:00
Joe Groff
cef754de45 Update ClangImporter to map SIMD types to their C-like Swift counterparts.
Swift SVN r28386
2015-05-09 23:03:39 +00:00
Joe Groff
95d1cf5e6d Revert "ClangImporter etc.: Remap C vector types to nested BaseType.VectorN types."
Reverts r28087. We're going back to the C++ interface for SIMD, and the changes in this patch are needless complication for that design.

Swift SVN r28384
2015-05-09 23:03:33 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Joe Groff
d0473756ec ClangImporter etc.: Remap C vector types to nested BaseType.VectorN types.
The design we landed on for SIMD is to define the vector types as nested types of their element, e.g. Float.Vector4, Int32.Vector2, etc. Update the Clang importer and other mapping facilities to match.

Swift SVN r28087
2015-05-02 15:04:43 +00:00
Joe Groff
fbd76737a4 Clang Importer: Rename the special vector type module to "simd".
We want this to act as an overlay/replacement for the C "simd" module.

Swift SVN r28047
2015-05-01 20:11:01 +00:00
David Farler
ca5876a866 swiftMarkup Library
Replace ReST-flavored documentation comments with Markdown.

rdar://problem/20180412

In addition to full Markdown support, the following extensions are
supported. These appear as lists at the top level of the comment's
"document". All of these extensions are matched without regard to
case.

Parameter Outlines
------------------

- Parameters:
  - x: ...
  - y: ...

Separate Parameters
-------------------

- parameter x: ...
- parameter y: ...

- Note:
Parameter documentation may be broken up across the entire comment,
with a mix of parameter documentation kinds - they'll be consolidated
in the end.

Returns
-------

- returns: ...

The following extensions are also list items at the top level, which
will also appear in Xcode QuickHelp as first-class citizens:

- Attention: ...
- Author: ...
- Authors: ...
- Bug: ...
- Complexity: ...
- Copyright: ...
- Date: ...
- Experiment: ...
- Important: ...
- Invariant: ...
- Note: ...
- Postcondition: ...
- Precondition: ...
- Remark: ...
- Remarks: ...
- See: ...
- Since: ...
- Todo: ...
- Version: ...
- Warning: ...

These match most of the extra fields in Doxygen, plus a few more per request.

Other changes
-------------
- Remove use of rawHTML for all markup AST nodes except for those
not representable by the Xcode QuickHelp XSLT - <h>, <hr/>, and of
course inline/block HTML itself.

- Update the doc comment RNG schema to more accurately reflect Xcode
QuickHelp.

- Clean up cmark CMake configuration.

- Rename "FullComment" to "DocComment"

- Update the Swift Standard Documentation (in a follow-up commit)

- Update SourceKit for minor changes and link against cmark
  (in a follow-up commit).

Swift SVN r27727
2015-04-26 00:07:15 +00:00
Joe Groff
58660ec6ba PrintAsObjC: Support for SIMD types.
Splat out a bunch of typedefs for the small vector types we want to support, and map the SIMD.* types to them.

Swift SVN r27385
2015-04-16 22:07:09 +00:00
Doug Gregor
de427fce5d Print throwing @objc methods with the appropriate Objective-C signature.
When printing the Objective-C form of a throwing method, use the
appropriate result type (BOOL, nullable result, etc.) and include the
error parameter. As part of this, refactor the printing loop for
Objective-C method declarations to stop being based on splitting
strings: ObjCSelector has the pieces we need.

Swift SVN r27282
2015-04-14 18:16:18 +00:00
Joe Groff
ec47ebdd3a PrintAsObjC: Handle @convention(c) function types.
Swift SVN r27263
2015-04-13 23:13:14 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Doug Gregor
7c4823ec71 Convert PrintAsObjC over to conformance lookup table entrypoints.
Another step toward using the conformance lookup table for
everything. This uncovered a tricky little bug in the conformance
lookup table's filtering logic (when asking for only those
conformances explicitly specified within a particular context) that
would end up dropping non-explicit conformances from the table (rather
than just the result).

Ween a few tests off of -enable-source-import, because they'll break
otherwise.

Swift SVN r27021
2015-04-05 13:44:47 +00:00
Doug Gregor
5c8fde3f2e Make PrintAsObjC more tolerant of non-@objc classes within collections.
Swift's bridged collections are allowed to store objects of non-@objc
classes, e.g., an array of (non-@objc) Swift classes is still bridged
to NSArray. Deal with such cases by printing out the type as "NSArray
*", since we cannot name the type in Objective-C to provide a more
specialized NSArray type.

This is a fairly narrow fix for rdar://problem/20392771 that needs
more discussion.

Swift SVN r26905
2015-04-02 21:56:58 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Jordan Rose
f74bc7122c Split getAccessibility() into getFormalAccess() and getEffectiveAccess().
Currently a no-op, but effective access for entities within the current
module will soon need to take testability into account. This declaration:

  internal func foo() {}

has a formal access of 'internal', but an effective access of 'public' if
we're in a testable mode.

Part of rdar://problem/17732115 (testability)

Swift SVN r26472
2015-03-24 02:16:58 +00:00
John McCall
080b7dfabf Remove the default handle-all Decl and DeclAttribute
cases from ASTVisitor and privatize SILGen's statement
emitter.  NFC.

Swift SVN r26402
2015-03-22 03:22:45 +00:00
Doug Gregor
f6e95b0a34 Fix printing of Objective-C @properties for @objc-renamed properties.
Finishes rdar://problem/19963219.

Swift SVN r25624
2015-02-27 22:54:46 +00:00
Doug Gregor
db51abba9a Fix Objective-C printing of init(forFun: ()) initializers.
This is the rest of rdar://problem/19973250, thank you Jordan!

Swift SVN r25623
2015-02-27 22:54:45 +00:00
Doug Gregor
96a2659223 Serialize initializer stub implementations.
Fixes the cross-module initializer inheritance issues implied by
rdar://problem/19794036.

Swift SVN r25336
2015-02-17 00:38:21 +00:00
Jordan Rose
4d7d6bbfc6 [PrintAsObjC] Don't forward-declare @objc enums using typedefs.
That's a C11 feature, and we can't force everyone to enable C11 just yet.
Instead, go back to the old way of using "enum Foo" to refer to @objc enums
defined in Swift. Just don't do it unilaterally for non-@objc enums.

Should unstick the buildbot.

Swift SVN r25161
2015-02-11 03:15:06 +00:00
Jordan Rose
d397a323a3 [PrintAsObjC] Output nullability for CF types and non-retainable pointers.
For pointer types that Swift doesn't currently import using Optional
(see rdar://problem/15189170 and its dups), use __null_unspecified.

rdar://problem/19775335

Swift SVN r25144
2015-02-10 23:52:48 +00:00
Jordan Rose
6a50a12bef [PrintAsObjC] Don't assume typedef'd enums have a name themselves.
...and then fix our forward-declaration logic that assumed that they did.

This fixes a rare case where we would end up printing "enum" twice if the
user (benignly) misused NS_ENUM.

rdar://problem/19769964

Swift SVN r25143
2015-02-10 23:52:44 +00:00
Doug Gregor
883911c767 Define __null_unspecified to nothing when the underlying Clang doesn't support nullability.
Fixes rdar://problem/19730896.

Swift SVN r25000
2015-02-05 17:35:45 +00:00
Jordan Rose
82c8d9b3dc [PrintAsObjC] Preserve NSUInteger in overridden decls when easy to do.
If a property, method, or subscript overrides an imported property, method,
or subscript that was originally declared using NSUInteger as a property,
parameter, or return type, print the subclass's member using "NSUInteger"
in the generated header to prevent override warnings.

This doesn't handle all cases--in particular, it doesn't handle the
NSUInteger being nested inside a larger type--but it does get the easy
ones correct. I think the easiest way to be more correct would be to mark
NSUInteger-as-Int somehow using a distinct type. (Hidden attribute?
Another typealias? Not sure.)

rdar://problem/19321126

Swift SVN r24771
2015-01-28 01:37:04 +00:00
Doug Gregor
f0eec4d9d5 Don't rely on overriding nullability in Objective-C; it's banned now.
Fixes rdar://problem/19610107.

Swift SVN r24750
2015-01-27 16:52:03 +00:00
Doug Gregor
fe5fe16c46 PrintAsObjC: Start printing __null_unspecified where needed.
Fixes rdar://problem/19499467.

Swift SVN r24643
2015-01-22 19:26:21 +00:00
Jordan Rose
0c182d73a3 [PrintAsObjC] Prefer the Clang name of imported typedefs.
Previously, when dealing with CF typedefs of other CF types, we would strip
off the "Ref" suffix...and then leave it off when it came time to print the
Objective-C header.

rdar://problem/19446942

Swift SVN r24562
2015-01-20 20:42:01 +00:00
Doug Gregor
b642c555be Allow one to change the argument labels of curried function parameters.
Curried function parameters (i.e., those past the first written
parameter list) default to having argument labels (which they always
have), but any attempt to change or remove the argument labels would
fail. Use the fact that we keep both the argument labels and the
parameter names in patterns to generalize our handling of argument
labels to address this problem.

The IDE changes are due to some positive fallout from this change: we
were using the body parameters as labels in code completions for
subscript operations, which was annoying and wrong.

Fixes rdar://problem/17237268.

Swift SVN r24525
2015-01-19 22:15:14 +00:00
Doug Gregor
fff46fa27b Fix support for building with Clangs that do not support ObjC generics.
Swift SVN r24214
2015-01-06 17:54:41 +00:00
Doug Gregor
5db31c668f Push hash mark in the leading column
Swift SVN r24199
2015-01-06 00:21:34 +00:00
Doug Gregor
d3d4c8b8fb Only use specialized Objective-C collection types when Foundation supports them.
Rely on Foundation to provide NS_ARRAY/NS_DICTIONARY/NS_SET macros
that expand to either an unspecialized type (e.g., NSArray *) or a
specialized one (e.g., NSArray<T> *) as appropriate for the definition
of NSArray. Use these macros in the Objective-C printer.

The actual names and form of these macros is still to be debated, but
it's important to be able to handle both Clangs and Foundations with
and without parameterized NSArray/NSDictionary/NSSet.

Swift SVN r24198
2015-01-06 00:16:43 +00:00
Doug Gregor
83d4c3783d Teach the Objective-C printer to print specialized array/dictionary/set types.
Swift SVN r24197
2015-01-06 00:16:42 +00:00
Chris Willmore
43e112cdb0 Add Set->NSSet bridging to PrintAsObjC.
Swift SVN r23757
2014-12-06 04:44:10 +00:00
Doug Gregor
267f0ff756 Wrap context-sensitive nullability keywords in SWIFT_NULLABILITY.
Swift SVN r23533
2014-11-21 21:28:17 +00:00
Doug Gregor
96bdf90fcc Stop printing __null_unspecified per rdar://problem/18383574.
Swift SVN r23510
2014-11-21 05:06:53 +00:00
Doug Gregor
07740515c2 Emit nullability context-sensitive keywords for instancetype.
Swift SVN r23486
2014-11-20 21:16:00 +00:00
Joe Groff
944860adb0 PrintAsObjC: Handle forward declarations of @objc enums.
If enums are used as parameters or returns of @objc methods, we may need to forward declare those enums when printing the class @interface.

Swift SVN r23445
2014-11-19 22:27:48 +00:00
Doug Gregor
96a9751372 PrintAsObjC: Print nullability type specifiers to capture optionality.
Part of rdar://problem/19005653. There is still some work to do to
produce pretty output here, but the current output is correct.

Swift SVN r23444
2014-11-19 21:08:23 +00:00
Joe Groff
8b037275ff PrintAsObjC: Fix up mixed-language @objc enum annotations.
Thanks Jordan for pointing out that the test didn't in fact test that we imported ObjC-ified Swift decls back to the same type. Adjust things so that we do, putting the annotation attribute in the right place, and fixing a crash when we have superfluous typedefs for native Swift decls.

Swift SVN r23439
2014-11-19 17:53:59 +00:00
Ben Langmuir
e9e1666ab0 Update for upstream LLVM changes
* removal of StringMap's GetOrCreateValue
* SmallSet::insert now returns a pair like std::set

Swift SVN r23435
2014-11-19 16:49:30 +00:00
Joe Groff
b8d912c0db PrintAsObjC: Swap SWIFT_ENUM args around to match other *_ENUM macros.
And introduce a SWIFT_ENUM_EXTRA preprocessor hook for the Clang importer to inject its annotations.

Swift SVN r23425
2014-11-19 04:03:10 +00:00
Joe Groff
dc2ad382a2 Serialization: Serialize the raw values of @objc enums.
This is necessary for @objc enums because, for C compatibility, the representations of the cases must match their raw values. We might want to do this for sufficiently fragile Swift enums in the future too, but that can wait. This lets us successfully print the raw values as ObjC.

Swift SVN r23423
2014-11-19 04:03:06 +00:00
Joe Groff
5059bd4366 PrintAsObjC: Print @objc enums.
Predefine a SWIFT_ENUM macro that expands the same as NS_ENUM, but which we can use to recognize Swift-defined @objc enums that are imported back. Print enums as ObjC using this SWIFT_ENUM macro.

We currently don't serialize the raw value exprs of enums, so we fail to correctly bring raw values from the enum declaration to the ObjC version.

Swift SVN r23422
2014-11-19 04:03:05 +00:00
Andrew Trick
32b104abb2 Silence unannotated fall-through warnings.
Swift SVN r23342
2014-11-15 00:37:35 +00:00
Jordan Rose
5ad871ecd6 Adopt llvm::function_ref for callbacks that aren't persisted.
...removing a few other constructs that were doing the same thing
(mostly from me).

No functionality change.

Swift SVN r23294
2014-11-13 00:19:03 +00:00
Jordan Rose
c734630dc3 [PrintAsObjC] Generate headers as warning-free as possible.
...and use #pragma clang diagnostic when otherwise unavoidable.

As part of this change, start testing generated headers under
-Weverything -Werror, with targeted exceptions.

rdar://problem/18332948

Swift SVN r22010
2014-09-17 06:10:26 +00:00
Jordan Rose
d438ebc228 Sink Swift's adapter for NSZone into the ObjectiveC overlay.
While Foundation actually defines the NSZone typedef and what you can do with
it, the ObjectiveC module makes use of it in its raw form: "struct _NSZone *".
To avoid a circular dependency, sink our adapter down to the ObjectiveC
overlay.

Swift SVN r21827
2014-09-10 02:32:52 +00:00
Jordan Rose
b3dc2280a2 [PrintAsObjC] Only print inner classes if they are explicitly marked @objc.
This reduces the chances of conflict among inner class names. It's too easy
for a class to be implicitly marked @objc in Swift.

To make this work, correctly preserve the implicitness of @objc through
serialization. (We were probably intending to do this all along, since we
were serializing the flag but not doing anything with it at the other end.)

Swift SVN r21678
2014-09-03 18:19:00 +00:00
Jordan Rose
1c7b8f2972 [PrintAsObjC] Don't print nested classes as nested in Objective-C.
There are still problems with nested classes:
- They're much more likely to have colliding compile-time names
  (since the outer class's name is dropped).
- They're only picked up if the outer class is also @objc.

But at least now we won't generate invalid Objective-C. Unless the inner
classes have the same name.

rdar://problem/18187877

Swift SVN r21677
2014-09-03 18:18:59 +00:00
Jordan Rose
c35312815a [PrintAsObjC] @import required explicit submodules.
...but prefer the base module for implicit submodules.

rdar://problem/18097120

Swift SVN r21555
2014-08-29 00:39:24 +00:00