Commit Graph

56 Commits

Author SHA1 Message Date
Dmitri Hrybenko
a75c7a427a stdlib/NSString APIs on String: add more tests and fix a crash in
_countFormatSpecifiers() that was triggered by non-BMP characters in the format
string


Swift SVN r21014
2014-08-04 15:37:58 +00:00
Dmitri Hrybenko
edc664c36f stdlib/NSString APIs on String: change return type of
stringByAddingPercentEncodingWithAllowedCharacters() and
stringByAddingPercentEscapesUsingEncoding() to String?, and add API notes for
NSString to the same effect


Swift SVN r21007
2014-08-04 14:13:46 +00:00
Jordan Rose
a627411b43 [ClangImporter] Imported NS_OPTIONS structs should not conform to BooleanType.
In general, RawOptionSetType no longer inherits from BooleanType.

Swift SVN r20846
2014-07-31 19:23:08 +00:00
Dmitri Hrybenko
3e32ff188f stdlib/String: change String.stringByAbbreviatingWithTildeInPath into a
property, to match recent Foundation headers


Swift SVN r20674
2014-07-29 16:08:39 +00:00
Joe Pamer
94dac129d4 Remove the BooleanType conformance from optional types (rdar://problem/17110911)
To limit user confusion when using conditional expressions of type Bool?, we've decided to remove the BooleanType (aka "LogicValue") conformance from optional types. (If users would like to use an expression of type Bool? as a conditional, they'll need to check against nil.)

Note: This change effectively regresses the "case is" pattern over types, since it currently demands a BooleanType conformance. I've filed rdar://problem/17791533 to track reinstating it if necessary.

Swift SVN r20637
2014-07-28 19:20:39 +00:00
Dmitri Hrybenko
ed855afb68 stdlib/String: use the Unicode collation algorithm in String's and Character's conformance to Comparable
rdar://17498444


Swift SVN r20554
2014-07-25 18:32:36 +00:00
Dmitri Hrybenko
aa929798d0 stdlib: eliminate an inconsistent overload of == on NSString that would
make == and != inconsistent in non-generic code, and that would not be
used at all in generic code.

Part of rdar://17498444

Swift SVN r20524
2014-07-24 22:38:41 +00:00
Dmitri Hrybenko
89420772a2 stdlib/String: move enough bridging machinery into the core standard
library so that core library can bridge a String to Objective-C

Part of rdar://17498444

Swift SVN r20485
2014-07-24 13:07:12 +00:00
Dave Abrahams
1a7648b04b [stdlib] String.stringWithBytes: drop length param
The length could already be given by the input sequence.  Also, make it
accept any generic Sequence of bytes, rather than requiring an array.

Fixes <rdar://problem/17034413>

Swift SVN r20480
2014-07-24 08:23:10 +00:00
Dmitri Hrybenko
766c9816de stdlib: underscore-prefix String.core
Swift SVN r20411
2014-07-23 16:28:57 +00:00
Dave Abrahams
1438d617cd [stdlib] Rename ConstUnsafePointer=>UnsafePointer
Swift SVN r20318
2014-07-22 17:10:54 +00:00
Dave Abrahams
21669b3aee [stdlib] Add "Mutable" to [Autoreleasing]UnsafePointer
UnsafePointer becomes UnsafeMutablePointer
AutoreleasingUnsafePointer becomes AutoreleasingUnsafeMutablePointer

Swift SVN r20316
2014-07-22 16:56:23 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Doug Gregor
2f3f6acf21 Make "true" and "false" Boolean literal constants for the BooleanLiteralConvertible protocol.
Introduce the new BooleanLiteralConvertible protocol for Boolean
literals. Take "true" and "false" as real keywords (which is most of the
reason for the testsuite churn). Make Bool BooleanLiteralConvertible
and the default Boolean literal type, and ObjCBool
BooleanLiteralConvertible. Fixes <rdar://problem/17405310> and the
recent regression that made ObjCBool not work with true/false.


Swift SVN r19728
2014-07-09 16:57:35 +00:00
Doug Gregor
0d6df5f78d Remove Bool <-> ObjCBool conversions.
There's a regression here because we can no longer use "true" or
"false" with ObjCBool. We'll get that back when true and false become
literals.


Swift SVN r19694
2014-07-08 20:17:35 +00:00
Jordan Rose
da29f099f0 Update stdlib for accessibility modifiers becoming context-sensitive keywords.
Swift SVN r19672
2014-07-08 02:17:46 +00:00
Dmitri Hrybenko
09bbec7464 stdlib: fix a crash in String.rangeOfString when the result is NSNotFound
rdar://17550857


Swift SVN r19611
2014-07-07 15:25:10 +00:00
Joe Groff
c34b4f6a9e Enable string-to-pointer conversions and remove CString.
There is some follow-up work remaining:

- test/stdlib/UnicodeTrie test kills the type checker without manual type annotations. <rdar://problem/17539704>
- test/Sema/availability test raises a type error on 'a: String == nil', which we want, but probably not as a side effect of string-to-pointer conversions. I'll fix this next.

Swift SVN r19477
2014-07-02 19:15:10 +00:00
Dmitri Hrybenko
f3c7bdc273 stdlib/NSString APIs on String: change substringFromIndex() and
substringToIndex() to accept String.Index instead of Int

rdar://17306557


Swift SVN r19467
2014-07-02 15:58:59 +00:00
Dmitri Hrybenko
57df21cefe stdlib/comments: UTF-8 and UTF-16 are spelled with a dash
Swift SVN r19466
2014-07-02 15:45:38 +00:00
Dmitri Hrybenko
7e4c6782ee stdlib/String: rename String.utf16count -> .utf16Count to follow naming
conventions

rdar://17016806


Swift SVN r19463
2014-07-02 15:03:02 +00:00
Joe Groff
47fde864e9 Remove UnsafePointer.withUnsafePointer.
This is no longer necessary for API parity with CMutablePointer now that pointer conversions are in.

Swift SVN r19296
2014-06-27 16:54:51 +00:00
Joe Groff
39dbb30b57 Remove staging typealiases from the stdlib.
Swift SVN r19287
2014-06-27 02:48:38 +00:00
Doug Gregor
bea1d3d9b3 Use dictionary type sugar in the standard library.
Swift SVN r19264
2014-06-26 22:26:58 +00:00
Joe Groff
d1e7ff0590 Foundation: Add staging typealiases for C pointer types.
Swift SVN r19209
2014-06-26 01:30:50 +00:00
Doug Gregor
37df5c430c Update standard library to use [T] array syntax.
Swift SVN r19190
2014-06-25 23:39:20 +00:00
Jordan Rose
cca27d02a0 Tag everything in the standard library with accessibility attributes.
Keep calm: remember that the standard library has many more public exports
than the average target, and that this contains ALL of them at once.
I also deliberately tried to tag nearly every top-level decl, even if that
was just to explicitly mark things @internal, to make sure I didn't miss
something.

This does export more than we might want to, mostly for protocol conformance
reasons, along with our simple-but-limiting typealias rule. I tried to also
mark things private where possible, but it's really going to be up to the
standard library owners to get this right. This is also only validated
against top-level access control; I haven't fully tested against member-level
access control yet, and none of our semantic restrictions are in place.

Along the way I also noticed bits of stdlib cruft; to keep this patch
understandable, I didn't change any of them.

Swift SVN r19145
2014-06-24 21:32:18 +00:00
Chris Lattner
62cad3dce8 add a "..<" operator, which is an alias for ".." and switch the stdlib to use it.
Until I have a chance to update the testsuite, we'll accept both.



Swift SVN r18998
2014-06-19 05:42:29 +00:00
Doug Gregor
dd8c668aa8 Import NSDictionary as Dictionary<NSObject, AnyObject>
Fixes <rdar://problem/16870626>.


Swift SVN r18907
2014-06-15 10:44:23 +00:00
Dmitri Hrybenko
a69e341aa2 stdlib/NSString APIs on String: fix a bug and add tests for
rangeOfCharacterFromSet(_:options:range:)

The underlying Objective-C API could return an NSRange of NSNotFound.  Swift's
String.Index can not represent that, so change the API to return an optional
Swift Range<Index> instead.


Swift SVN r18679
2014-05-30 23:07:21 +00:00
Dmitri Hrybenko
df71a47fe4 stdlib/NSString APIs on String: fix two bugs and add more tests
stringWithBytes(_:length:encoding:) was passing an array to Objective-C
incorrectly, and a garbage NSString was being constructed as a result.

Unhide the initializer was accidentally hidden.


Swift SVN r18674
2014-05-30 20:30:57 +00:00
Dmitri Hrybenko
470fee7838 stdlib: correct a comment to be more explicit that this is a hack
Swift SVN r18644
2014-05-26 23:49:50 +00:00
Dmitri Hrybenko
fce7a8c4ff stdlib/NSString APIs on String: dataUsingEncoding:allowLossyConversion: can
return nil, change our API and add tests


Swift SVN r18597
2014-05-23 16:38:53 +00:00
Dmitri Hrybenko
c5f21546db stdlib/CString: fix two issues with CString.persist():
1. it crashed on a null pointer;

2. it crashed on a non-ASCII strings.

rdar://17016284


Swift SVN r18594
2014-05-23 15:18:21 +00:00
Dmitri Hrybenko
04dae74cd6 stdlib: correct comment
Swift SVN r18592
2014-05-23 13:07:46 +00:00
Dmitri Hrybenko
83f7bdc30e stdlib/NSString APIs for String: allow a nil locale to be passed to
capitalizedStringWithLocale(_:)


Swift SVN r18591
2014-05-23 09:51:30 +00:00
Doug Gregor
f305cd7946 Look through bridgeFromObjectiveC calls to find forced casts within optional injections.
Fixes <rdar://problem/17003302>.


Swift SVN r18563
2014-05-22 15:47:13 +00:00
Doug Gregor
67ca1c9ea1 Implement the new casting syntaxes "as" and "as?".
There's a bit of a reshuffle of the ExplicitCastExpr subclasses:
  - The existing ConditionalCheckedCastExpr expression node now represents
"as?". 
  - A new ForcedCheckedCastExpr node represents "as" when it is a
  downcast.
  - CoerceExpr represents "as" when it is a coercion.
  - A new UnresolvedCheckedCastExpr node describes "as" before it has
  been type-checked down to ForcedCheckedCastExpr or CoerceExpr. This
  wasn't a strictly necessary change, but it helps us detangle what's
  going on.

There are a few new diagnostics to help users avoid getting bitten by
as/as? mistakes:
  - Custom errors when a forced downcast (as) is used as the operand
  of postfix '!' or '?', with Fix-Its to remove the '!' or make the
  downcast conditional (with as?), respectively.
  - A warning when a forced downcast is injected into an optional,
  with a suggestion to use a conditional downcast.
  - A new error when the postfix '!' is used for a contextual
  downcast, with a Fix-It to replace it with "as T" with the
  contextual type T.

Lots of test updates, none of which felt like regressions. The new
tests are in test/expr/cast/optionals.swift. 

Addresses <rdar://problem/17000058>


Swift SVN r18556
2014-05-22 06:15:29 +00:00
Dave Abrahams
0f9edadc41 [stdlib] String API Review: NSString API
Many changes in how we're presenting the NSString APIs on String, most
notably that we now traffic in String.Index and Range<String.Index>
rather than Int and NSRange.  Also we present NSString initializers that
can fail only as factory functions, and factory functions that can't
fail only as init functions.

About 25% of the API changes here have been reviewd by the Foundation
guys, and testing is, as it has always been, admittedly spotty.  Dmitri
is going to be writing some more comprehensive tests.

Swift SVN r18553
2014-05-22 04:21:55 +00:00
Dmitri Hrybenko
26630dbdc4 stdlib/NSString APIs for String: change hash() function into a property
Swift SVN r18281
2014-05-17 22:27:35 +00:00
Ted Kremenek
26320dc0ed Per API review, rename 'reserve' to 'reserveCapacity'.
Swift SVN r18272
2014-05-17 21:00:28 +00:00
Ted Kremenek
eab7f90a81 Per design discussion today, rename UnsafePointer ".pointee" to ".memory".
Swift SVN r18269
2014-05-17 20:35:16 +00:00
Dmitri Hrybenko
a4d9dcf1a7 stdlib: extinguish \brief and \c
Swift SVN r18261
2014-05-17 18:10:51 +00:00
Joe Groff
e8f71c12a2 Rename ObjCMutablePointer to AutoreleasingUnsafePointer.
This relates its interface and behavior to that of UnsafePointer, and draws an analogy to '__autoreleasing *' in ARC.

Swift SVN r18236
2014-05-17 04:44:44 +00:00
Arnold Schwaighofer
da6d9152b6 Differentiate between user assertion and preconditions and the like
assert() and fatalError()
These functions are meant to be used in user code. They are enabled in debug
mode and disabled in release or fast mode.

_precondition() and _preconditionFailure()
These functions are meant to be used in library code to check preconditions at
the api boundry. They are enabled in debug mode (with a verbose message) and
release mode (trap). In fast mode they are disabled.

_debugPrecondition() and _debugPreconditionFailure()
These functions are meant to be used in library code to check preconditions that
are not neccesarily comprehensive for safety (UnsafePointer can be null or an
invalid pointer but we can't check both). They are enabled only in debug mode.

_sanityCheck() and _fatalError()
These are meant to be used for internal consistency checks. They are only
enabled when the library is build with -DSWIFT_STDLIB_INTERNAL_CHECKS=ON.

I modified the code in the standard library to the best of my judgement.

rdar://16477198

Swift SVN r18212
2014-05-16 20:49:54 +00:00
Doug Gregor
b756fc29ec Don't require paretheses when mixing optional types and array types...
... unless we actually hit one of the confusing cases involving
multi-dimensional arrays (e.g., Int[]?[]), at which point one needs to
write parentheses <rdar://problem/16737035>.



Swift SVN r18181
2014-05-16 06:03:26 +00:00
Ted Kremenek
4bb475a1c8 Rename UnsafePointer.get/set to a "ptr.pointee" property.
Implements <rdar://problem/16531067>.

Swift SVN r18178
2014-05-16 05:48:05 +00:00
Doug Gregor
ad18ed81fb Start importing NSArray* as (AnyObject[])! by default <rdar://problem/16535097>.
Swift SVN r18157
2014-05-16 01:10:13 +00:00
Dave Abrahams
a8bbc4c89b [stdlib] String internal API review changes
I had to XFAIL test/ClangModules/cf.swift, which is failing for reasons
I can't understand.  <rdar://problem/16911496>

Swift SVN r18071
2014-05-14 14:18:52 +00:00
Ted Kremenek
9eea282719 Switch range operators ".." and "...".
- 1..3 now means 1,2
- 1...3 now means 1,2,3

Implements <rdar://problem/16839891>

Swift SVN r18066
2014-05-14 07:36:00 +00:00