Commit Graph

1221 Commits

Author SHA1 Message Date
John McCall
6df6897756 Add an InjectIntoOptional implicit conversion expression
instead of generating ugly artificial calls to
_injectValueIntoOptional in the AST.

Swift SVN r8837
2013-10-02 05:48:30 +00:00
John McCall
298577676e Introduce the monadic ? operator.
A ? operator is interpreted as this if it's left-bound,
so ternary operators now have to be spaced on the left.

Swift SVN r8832
2013-10-02 01:27:45 +00:00
Joe Groff
4b5db0cd50 Parse trailing closure productions as expr-postfix.
This is more naturally where they belong in the grammar, allows for nice chained transformation calls like 'x.map { ... }.filter { ... }', and lets us remove a bunch of kludgy fixits to try to handle the 'wanted to parse postfix but didn't' case. Fixes <rdar://problem/14098078>. Also fix the special-case handling of "builder pattern" style method chains to parse 'x\n.method{' as a chained method call, like it does 'x\n.method(' or 'x\n.property['. (There's got to be a better way...)

Swift SVN r8828
2013-10-02 00:27:26 +00:00
Joe Groff
28f159b2d7 Remove '?' from 'as?'.
Doug points out it's not necessary. Even without a deeper syntactic renovation for casts this still signals that it's the preferred cast form going forward.

Swift SVN r8812
2013-10-01 21:11:38 +00:00
Joe Groff
f1993cf231 Parse and type-check 'x as? T' conditional cast syntax.
Though we plan to revamp the casting syntax, our general plan is for this form of cast, which does a conditional cast and returns an Optional<T> result, to be the one that survives. Parse the status-quo syntax 'x as? T' and type-check it. While we're here, refresh some fixits for redundant casts that referred to the now defunct 'as T' coercion syntax to completely remove whatever cast was in the source code.

Swift SVN r8805
2013-10-01 17:00:54 +00:00
Joe Groff
911929f1dd Parse and type check initializer closures after 'new T[n]' exprs.
Require that either T be default constructible or that the user provide a closure that maps indices to initial values. We don't actually call the closure yet to initialize the array; that's blocked on function abstraction difference <rdar://problem/13251236>.

Swift SVN r8801
2013-10-01 05:12:54 +00:00
Argyrios Kyrtzidis
35bd9d8caa Make sure VarDecls have locations, even the implicit ones.
Swift SVN r8761
2013-09-29 00:12:19 +00:00
Jordan Rose
e05c03d5bc Standardize terminology for "computed", "stored", "variable", and "property".
These are the terms sent out in the proposal last week and described in
StoredAndComputedVariables.rst.

variable
  anything declared with 'var'
member variable
  a variable inside a nominal type (may be an instance variable or not)
property
  another term for "member variable"
computed variable
  a variable with a custom getter or setter
stored variable
  a variable with backing storage; any non-computed variable

These terms pre-exist in SIL and IRGen, so I only attempted to solidify
their definitions. Other than the use of "field" for "tuple element",
none of these should be exposed to users.

field
  a tuple element, or
  the underlying storage for a stored variable in a struct or class
physical
  describes an entity whose value can be accessed directly
logical
  describes an entity whose value must be accessed through some accessor

Swift SVN r8698
2013-09-26 18:50:44 +00:00
Dmitri Hrybenko
55073757ad Remove a reference to 'as?' from a diagnostic and add test coverage
rdar://15042877


Swift SVN r8684
2013-09-26 01:18:46 +00:00
Argyrios Kyrtzidis
e224667315 Refactor Implicit'ness of expressions.
Introduce a bit in Expr to indicate whether the expression is implicit and decouple the implicitness
of an expression from whether it has a source location or not.

This allows implicit expressions to be able to point at the source location where they originated from.
It also allows decoupling the implicitness of a parent from its children, so for example, an implicit CallExpr
can have an explicit parameter value.

Swift SVN r8600
2013-09-24 20:42:29 +00:00
Doug Gregor
f67aa78d69 Dynamic lookup for subscripts: semantic analysis and ASTs.
Swift SVN r8591
2013-09-24 05:51:30 +00:00
Doug Gregor
62e84f59e4 s/constructor/initializer in diagnostics
Swift SVN r8506
2013-09-20 18:59:22 +00:00
Doug Gregor
978959ced8 Make the "init" and "constructor" keywords synonymns.
Swift SVN r8391
2013-09-18 04:23:28 +00:00
Dmitri Hrybenko
f1f189f4e0 Rename PipeClosureExpr -> ClosureExpr
Swift SVN r8321
2013-09-17 01:37:36 +00:00
Dmitri Hrybenko
c32b783740 Move closure parameter pattern to AbstractClosureExpr
Swift SVN r8316
2013-09-17 01:08:50 +00:00
Dmitri Hrybenko
b18c38a322 Rename ImplicitClosureExpr -> AutoClosureExpr
Swift SVN r8304
2013-09-16 23:03:50 +00:00
Dmitri Hrybenko
10291e0334 Make AbstractClosureExpr a DeclContext
(remove DeclContext base class from PipeClosureExpr and ImplicitClosureExpr)


Swift SVN r8303
2013-09-16 22:39:12 +00:00
Dmitri Hrybenko
536ed954ad Remove FuncExpr. Add CaptureInfo to FuncDecl. Introduce AnyFunctionRef.
AnyFunctionRef is a universal function reference that can wrap all AST nodes
that represent functions and exposes a common interface to them.  Use it in two
places in SIL where CapturingExpr was used previously.

AnyFunctionRef allows further simplifications in other places, but these will
be done separately.


Swift SVN r8239
2013-09-14 02:15:48 +00:00
Dmitri Hrybenko
45e654fbaa Make AbstractFunctionDecl a DeclContext
and remove DeclContext base class from FuncDecl, ConstructorDecl and
DestructorDecl

This decreases the number of DeclContexts to 7 and allows us to apply
alignas(8) to DeclContext.


Swift SVN r8186
2013-09-13 03:38:33 +00:00
Dmitri Hrybenko
0d6d9a0ffb Move the DeclContext base class from FuncExpr to FuncDecl
FuncDecl still has a FuncExpr because capture list is stored in FuncExpr
(which is a CapturingExpr).


Swift SVN r8179
2013-09-13 01:40:41 +00:00
Dmitri Hrybenko
7da84fd13d Make FuncExpr, PipeClosureExpr and ClosureExpr DeclContexts on their own.
This is a first step to detach them from CapturingExpr and eventually move them
in the AST class hierarchy.


Swift SVN r8171
2013-09-12 23:58:06 +00:00
Dmitri Hrybenko
c69c79084a Move result typeloc and body result type from FuncExpr to FuncDecl
Swift SVN r8153
2013-09-12 18:40:57 +00:00
Dmitri Hrybenko
3cc01cf7d6 Introduce AbstractFunctionDecl -- a base class for ConstructorDecl,
DestructorDecl, FuncDecl -- and move some of the common concepts and logic
into it

No functionality change.


Swift SVN r8090
2013-09-11 04:04:01 +00:00
Dmitri Hrybenko
fa063a43c0 Mark diagnostics from expr-super parsing as PointsToFirstBadToken
Swift SVN r8012
2013-09-06 22:51:44 +00:00
Doug Gregor
0dcca3aeda Eliminate CoerceExpr entirely.
Swift SVN r7876
2013-09-03 22:58:22 +00:00
Doug Gregor
1dea838517 Remove the "x as T" syntax from the language.
Swift SVN r7874
2013-09-03 22:47:33 +00:00
Doug Gregor
0554c944a2 Fold GenericSubscriptExpr into SubscriptExpr.
Swift SVN r7845
2013-09-03 16:25:07 +00:00
Doug Gregor
786f9d299b Fold GenericMemberRefExpr into MemberRefExpr.
MemberRefExpr now uses ConcreteDeclRef to refer to its member, which
includes the substitutions and obviates the need for
GenericMemberRefExpr.


Swift SVN r7842
2013-09-03 15:49:19 +00:00
Dmitri Hrybenko
53652960a6 Make 'self' and 'Self' real keywords.
Also, remove IDENTIFIER_KEYWORD macro because these two were the last
identifier keywords.


Swift SVN r7806
2013-08-30 22:07:47 +00:00
Dmitri Hrybenko
7c56b45973 Parser: fix a crash while doing recovery when we tried to reinterpret a binary
operator at the beginning of an unary expression as unary operator


Swift SVN r7765
2013-08-29 23:21:40 +00:00
Doug Gregor
b06e65c3b3 Add the DynamicLookup protocol for lookup across all classes and protocols.
When performing member lookup into an existential that involves the
DynamicLookup protocol, look into all classes and protocols for that
member. References to anything found via this lookup mechanism are
returned as instances of Optional.

This introduces the basic lookup mechanics into the type
checker. There are still numerous issues to work through:
  - Subscripting isn't supported yet
  - There's no SILGen or IRGen support
  - The ASTs probably aren't good enough for the above anyway
  - References to generics will be broken
  - Ambiguity resolution or non-resolution

Thanks to Jordan for the patch wiring up DynamicLookup.


Swift SVN r7689
2013-08-28 21:38:50 +00:00
Dmitri Hrybenko
53e0921e75 Make 'self' and 'Self' keywords
Add a test for recovery after misplaced 'self' and 'Self'.  We don't diagnose
many cases of invalid usage, and in some cases diagnostics are bad.  This will
be fixed separately.


Swift SVN r7661
2013-08-28 03:42:04 +00:00
Dmitri Hrybenko
d9035426ed Rename RebindThisInConstructorExpr -> RebindSelfInConstructorExpr
Swift SVN r7658
2013-08-28 03:02:30 +00:00
Dmitri Hrybenko
69cfa73640 More 'this' -> 'self' replacements
Swift SVN r7657
2013-08-28 02:57:21 +00:00
Dmitri Hrybenko
dd1c2f7477 Parser: consume tok::code_complete where it is handled
We did not consume it before because parseBraceItems() relied on seeing it to
do delayed parsing.


Swift SVN r7648
2013-08-27 23:48:54 +00:00
Ted Kremenek
8f5b8ccb02 Rename "This" to "Self" and "this" to "self".
This was not likely an error-free change.  Where you see problems
please correct them.  This went through a fairly tedious audit
before committing, but comments might have been changed incorrectly,
not changed at all, etc.

Swift SVN r7631
2013-08-27 21:58:27 +00:00
Dmitri Hrybenko
14f6b67797 Correctly propagate code completion bits from parseExprPostfix() during the
first parsing pass.  This allows us to remove a workaround in parseBraceItems()
that directly looks at the current token.


Swift SVN r7616
2013-08-27 01:06:48 +00:00
Dmitri Hrybenko
c6f0dd106d parseStmtReturn(): use ParserResult
This caught a bug in parseExprPostfix(): it did not return a code completion
status.


Swift SVN r7603
2013-08-26 23:18:51 +00:00
Dmitri Hrybenko
adaea00254 Actually propagate the code completion bit
No tests because code completion bits from parseExpr*() don't do anything
yet -- parseDecl() just ignores them.


Swift SVN r7441
2013-08-22 00:33:41 +00:00
Dmitri Hrybenko
caeddfdaf0 parseExprList(): use ParserResult
Swift SVN r7440
2013-08-22 00:27:43 +00:00
Dmitri Hrybenko
421b107091 parseExprCollection, parseExprArray, parseExprDictionary: use ParserResult
Swift SVN r7439
2013-08-21 23:47:07 +00:00
Dmitri Hrybenko
2bf010151b parseExprSequence(): use ParserResult
Swift SVN r7438
2013-08-21 23:30:47 +00:00
Dmitri Hrybenko
4957bca697 parseExprUnary(): use ParserResult
Swift SVN r7437
2013-08-21 23:20:23 +00:00
Dmitri Hrybenko
f9a24073a5 parseExprPostfix(): use ParserResult
Swift SVN r7430
2013-08-21 21:53:52 +00:00
Dmitri Hrybenko
04bcc5553e parseExprNew(): use ParserResult
Swift SVN r7429
2013-08-21 21:32:21 +00:00
Dmitri Hrybenko
2e3d313d6b parseExprSuper(): use ParserResult
Swift SVN r7427
2013-08-21 21:26:09 +00:00
Dmitri Hrybenko
faff10f310 Parser: use ParserResult in 'is' and 'as' expression parsing
Swift SVN r7426
2013-08-21 21:15:43 +00:00
Dmitri Hrybenko
ec7b2eb3db Parser: use ParserResult in the interface of parseExpr()
But the implementation of expression parsing still does not propagate the code
completion bits because it uses NullablePtr for results.


Swift SVN r7425
2013-08-21 21:10:09 +00:00
Dmitri Hrybenko
354c5f4a18 Parser: replace diagnose(Tok.getLoc(), ...) -> diagnose(Tok, ...)
We already had the Parser::diagnose(Token, ...) overload, but it was not used
in all these cases.


Swift SVN r7395
2013-08-21 00:26:30 +00:00
Dmitri Hrybenko
c3954987d6 Parser: use ParserResult in parseTypeSimple() and everything that uses it/
is used in it


Swift SVN r7355
2013-08-20 02:12:31 +00:00