Commit Graph

1224 Commits

Author SHA1 Message Date
Devin Coughlin
0d7996f4ee Add parsing of availability query expressions (#os(...))
This patch adds a new 'pound_os' token, a new case for it in parseExprPostfix, and parsing of platform version constraints, e.g., OSX >= 10.10. 

It also adds enough type checking and SILGen to get the parsing tests to run without triggering "Unimplemented" assertions.


Swift SVN r21865
2014-09-11 02:59:05 +00:00
Joe Pamer
5136dc3df9 RebindSelfInConstructorExpr nodes should only be created for self init calls within initializers. (rdar://problem/17281900)
Swift SVN r21494
2014-08-27 22:57:30 +00:00
Doug Gregor
51c1433ddd Add magic "literal" __DSO_HANDLE__ to refer to the DSO handle.
__DSO_HANDLE__ can be used as a callee-side default
argument. Addresses rdar://problem/17878114.


Swift SVN r21440
2014-08-25 16:33:54 +00:00
Chris Lattner
48687380b7 now that DeclAttributes is a single word, there is no reason to deal with
it indirectly through another pointer from Decl, just embed DeclAttributes
directly into Decl and get rid of the "getMutableAttrs" nonsense.



Swift SVN r20216
2014-07-20 04:09:42 +00:00
Dmitri Hrybenko
b0c3a56c96 Code completion: fix some type checking issues of closures
Completely disable the AST transformation for single-expression closures.  When
this transformation picks up an incomplete expression, the resulting AST is
almost guaranteed to have type mismatches, and the type checker just marks
everything with error types.

rdar://17193319 rdar://17086137


Swift SVN r20153
2014-07-18 14:49:34 +00:00
Dmitri Hrybenko
31f0b0a145 Code completion: fix crash when a closure is called in place
rdar://17164209


Swift SVN r20152
2014-07-18 11:58:57 +00:00
Dmitri Hrybenko
8234c70f88 Code completion: fix delayed parsing of closures
The delayed parsing was in place, but the expressions were being thrown away by
"recovery" in the parser.

rdar://16274593


Swift SVN r20151
2014-07-18 11:43:38 +00:00
Chris Lattner
6592366f23 switch weak/unowned/unowned(unsafe) to the new declattributes machinery.
Swift SVN r20032
2014-07-16 19:46:00 +00:00
Chris Lattner
8078fecd18 fix <rdar://problem/17625253> Remove the 'strong' context-sensitive keyword
Swift SVN r19819
2014-07-10 19:46:22 +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
Chris Lattner
02999cac51 Reinstate the @ on the @objc attribute. This is largely a revert of r19555 with a few tweaks.
Swift SVN r19706
2014-07-08 21:50:34 +00:00
Chris Lattner
7a56499d61 Start making @objc not start with an @ sign:
- Change the parser to accept "objc" without an @ sign as a contextual
   keyword, including the dance to handle the general parenthesized case.
 - Update all comments to refer to "objc" instead of "@objc".
 - Update all diagnostics accordingly.
 - Update all tests that fail due to the diagnostics change.
 - Switch the stdlib to use the new syntax.

This does not switch all tests to use the new syntax, nor does it warn about
the old syntax yet.  That will be forthcoming.  Also, this needs a bit of 
refactoring, which will be coming up.



Swift SVN r19555
2014-07-04 05:57:57 +00:00
Joe Groff
ba15e5c835 Warn when a trailing closure is separated from its call site by more than one line.
Swift SVN r19325
2014-06-28 18:51:28 +00:00
Joe Groff
88f2632a44 Allow trailing closures with a line break before '{'.
Swift SVN r19322
2014-06-28 05:12:48 +00:00
Dave Abrahams
b7a8fc7d4c Revert "Allow trailing closures with a line break before '{'."
This reverts r19315, which broke my build:

-- Testing: 1 tests, 1 threads --
FAIL: Swift :: Interpreter/arrays.swift (1 of 1)
******************** TEST 'Swift :: Interpreter/arrays.swift' FAILED ********************
Script:
--
rm -rf /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp && mkdir -p /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp && xcrun -sdk macosx10.10 /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/bin/swift -target x86_64-apple-macosx10.9 -resource-dir '/Users/dave/build/swift/Ninja-RelWithDebInfo/swift/lib/swift' -module-cache-path /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/swift-module-cache -module-cache-path /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/clang-module-cache /Users/dave/src/s/swift/test/Interpreter/arrays.swift -o /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/a.out &&  /Users/dave/build/swift/Ninja-RelWithDebInfo/swift/test/Interpreter/Output/arrays.swift.tmp/a.out | FileCheck /Users/dave/src/s/swift/test/Interpreter/arrays.swift
--
Exit Code: 1

Command Output (stderr):
--
/Users/dave/src/s/swift/test/Interpreter/arrays.swift:54:1: error: invalid use of '()' to call a value of non-function type '()'
println()
^

Swift SVN r19317
2014-06-28 01:51:45 +00:00
Joe Groff
0c9fc15ae1 Allow trailing closures with a line break before '{'.
Swift SVN r19315
2014-06-28 00:36:45 +00:00
Doug Gregor
5a08a69ebc Remove NewArrayExpr entirely; reject "new" expressions in the parser.
Swift SVN r19293
2014-06-27 15:57:48 +00:00
Doug Gregor
461cde049a Teach parseMatchingToken() to set a matched location even when it wasn't matched.
We were working around this in several different places, which was
error-prone (see <rdar://problem/17479771>). This way, we always have
usable left/right delimiter locations.

Swift SVN r19292
2014-06-27 15:17:05 +00:00
Chris Lattner
60fc0e6cd2 Implement <rdar://problem/16951729> nil should be a literal type
This is all goodness, and eliminates a major source of implicit conversions.
One thing this regresses on though, is that we now reject "x == nil" where
x is an option type and the element of the optional is not Equtatable.  If
this is important, there are ways to enable this, but directly testing it as
a logic value is more straight-forward.

This does not include support for pattern matching against nil, that will be
a follow on patch.



Swift SVN r18918
2014-06-15 22:59:03 +00:00
Jordan Rose
bb5b2f4a70 [Parse] Allow shadowing the variable a closure expr is being assigned to.
Do this by only warning on self-referential uses of a variable when there's
not another binding found in the local scope. This probably still restricts
some reasonable edge cases, but it at least allows shadowing the variable
with a local name.

<rdar://problem/17087232>

Swift SVN r18771
2014-06-10 01:14:29 +00:00
Chris Lattner
2dc1df52d1 Implement <rdar://problem/16954464> Cannot make a strong IBOutlet
This adds support for the "strong" ownership modifier, and specifically 
make it override the "implicit weak" behavior of @IBOutlet.



Swift SVN r18737
2014-06-08 20:49:21 +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
Argyrios Kyrtzidis
bab5188d7d [Parser] Follow-up on r18532, to prevent code-completion giving any results with an invalid 'super.' inside an enum.
Swift SVN r18543
2014-05-22 00:59:38 +00:00
Argyrios Kyrtzidis
7f1f1a459b [Parser] Fix crash when having "super.init()" at top-level.
rdar://16981275

Swift SVN r18532
2014-05-21 23:26:31 +00:00
Ted Kremenek
fe0dbb701d Remove shorthand "x as T!" instead of "(x as T)!"
Implements <rdar://problem/16806243>.

Swift SVN r18156
2014-05-16 01:07:53 +00:00
Doug Gregor
f11e992f23 A local cannot be captured before it is declared <rdar://problem/16747992>.
Swift SVN r18025
2014-05-13 21:28:09 +00:00
Chris Lattner
bca1634958 fix rdar://16889886 - Assert when trying to weak capture a property of self in a lazy closure
also improve error recovery.


Swift SVN r18008
2014-05-13 16:45:15 +00:00
Argyrios Kyrtzidis
19aeaf94fc Fully embrace ParamDecls instead of AnyPattern at function creation time, thus removing the need to create param decls at SILGen or Sema.
Swift SVN r17829
2014-05-10 18:23:50 +00:00
Argyrios Kyrtzidis
a5eeb9617a [Parser] Create ParamDecls even for unnamed parameters.
This preserves more of source info (e.g. API name location) and simplifies things since
we don't have to construct ParamDecls for the unnamed parameters later on.

Swift SVN r17828
2014-05-10 18:23:47 +00:00
Chris Lattner
2426134853 improve hte AST representation of capture lists to build VarDecls and
PatternBindingDecls, and inject the vardecls into the name resolution
scope while parsing the body of the closure.  This allows references
from the body of the closure to be resolved to the capture list,
e.g. in cases like the testcase.


Swift SVN r17760
2014-05-09 05:39:28 +00:00
Dmitri Hrybenko
69464ac0a2 Parser/code completion: don't drop code completion bits
rdar://16813332

Swift SVN r17630
2014-05-07 14:53:02 +00:00
Chris Lattner
8f9aeecd9c implement <rdar://problem/16835718> Ban multiple trailing closures
Swift SVN r17606
2014-05-07 05:42:26 +00:00
Chris Lattner
40a8fda572 inline hasExprCallSuffix into its two callers now that it is trivial. NFC.
Swift SVN r17605
2014-05-07 05:31:24 +00:00
Chris Lattner
d2a604ab66 Remove trailing closure parsing from 'parseExprCallSuffix'. This is
leftovers from one of the old selector syntaxes.  The general expression
suffix parsing loop handles trailing closures in a superset of the cases
that this code does.  NFC.


Swift SVN r17604
2014-05-07 05:30:00 +00:00
Chris Lattner
fcb3b0e98c Rework capture list parsing and generalize it. Now the preparse is
much fuzzier, and the real parse is stricter.  Also, generalize this
to support the full "unowned name = expr" syntax in the capture list.

There is still a lot missing here.



Swift SVN r17499
2014-05-05 23:53:53 +00:00
Chris Lattner
0bab49db70 use consumeIdentifier a bit more to simplify parser logic, NFC.
Swift SVN r17452
2014-05-05 16:32:14 +00:00
Chris Lattner
d230228cdd store the capture list of a ClosureExpr in the AST and print it out
in the AST dumper.


Swift SVN r17451
2014-05-05 16:25:33 +00:00
Chris Lattner
1262105e61 Start parsing capture lists in closure expressions. Still much work
to go.



Swift SVN r17367
2014-05-04 05:39:22 +00:00
Chris Lattner
8f444a4a61 simplify some parsing logic by using Token::isIdentifierOrNone more,
and rearrange some closure parsing logic to tidy it up, NFC.


Swift SVN r17363
2014-05-04 04:42:53 +00:00
Ted Kremenek
4e70269c53 More renaming 'unchecked optional' to 'implicitly unwrapped optional'.
Swift SVN r17236
2014-05-02 06:22:01 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Doug Gregor
3d3ff6811a Add a pile of missing #includes exposed by pruning includes in top-of-tree LLVM.
Swift SVN r17157
2014-05-01 14:26:34 +00:00
Doug Gregor
9cfb1b5ca4 Keep track of the locations of the element names in a TupleExpr.
As part of this, use tail allocation to reduce the memory footprint of
TupleExprs. Use factory methods to make it easier to construct.

I'll be using this information in a follow-on patch. SourceKit
probably wants it as well.


Swift SVN r17129
2014-05-01 00:16:36 +00:00
Doug Gregor
72e32c93af Make argument names default to keyword arguments in the cases where Objective-C has names.
Introduce a model where an argument name is a keyword argument if: 

  - It is an argument to an initializer, or
  - It is an argument to a method after the first argument, or
  - It is preceded by a back-tick (`), or
  - Both a keyword argument name and an internal parameter name are
    specified. 

Provide diagnostics Fix-Its to clean up cases where the user is
probably confused, i.e.,

  - "_ x: Int" -> "x: Int" where "x" would not have been a keyword
  argument anyway
  - "x x: Int" -> "`x: Int"

This covers the compiler side of <rdar://problem/16741975> and
<rdar://problem/16742001>.

Update the AST printer to print in this form, never printing just 
a type for a parameter name because we're also going to adopt
<rdar://problem/16737312> and it was easier to move the tests once
rather than twice.

Standard library and test updates coming separately.




Swift SVN r17056
2014-04-30 00:04:04 +00:00
Chris Lattner
db876399ad create a helper function for creating a TypeExpr from a
specialized declref, factoring some code.  NFC


Swift SVN r17021
2014-04-29 05:33:32 +00:00
Chris Lattner
30915de98f Form TypeExprs for non-specialized unqualified declrefs that refer to types... like "Int".
Building on previous work, this allows us to properly handle things like Int?() and Int[]().

Of course doing this exposed that TypeExpr was not correct in lots of ways, so this also:
 - Revamps TypeExpr processing to carry a decl in the TypeLoc instead of 
   carrying a Type.  This allows us to correctly handle more complex generics case.  
 - Enhances CSGen to properly open generic types so we can infer generic type parameters from
   context.


Swift SVN r17019
2014-04-29 05:25:21 +00:00
Chris Lattner
c45e6b75fd Rip out logic added to me misunderstanding ExistentialMetatypeType,
and teach type checking to resolve TypeExprs that lack TypeReprs.

This gets us debugged enough to start shoving all local type references
down the TypeExpr path, which is significant progress.


Swift SVN r16958
2014-04-28 04:42:44 +00:00
Ted Kremenek
6caf910d32 Implement new syntactic sugar for UncheckedOptional<T>.
This leaves in the existing syntax for @unchecked T?.  That will
be addressed in later patches.

There's still a mysterious case where some of the SIL output
includes UncheckedOptional<T> and some places T!.

Moreover, this doesn't handle SourceKit's behavior for printing
for overrides.  This just handles parsing the 'T!' syntax.

Swift SVN r16945
2014-04-27 21:59:29 +00:00
Dmitri Hrybenko
fe185d78d3 Parser: rework dictionary literal parser not to rely on skipUntil
Swift SVN r16752
2014-04-24 11:14:51 +00:00
Doug Gregor
57b2146c0b Remove the separated call syntax.
We had our transition path, and now it's time to kill it because it's
causing problems <rdar://problem/16672558>.

Amusing note: the SILGen test change is actually an improvement. We
weren't rebinding self when performing initializer delegation with the
separated call syntax.

Swift SVN r16707
2014-04-23 18:20:34 +00:00