Commit Graph

594 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis
9b4c94d4c2 [AST] Walk body parameter patterns.
Swift SVN r8804
2013-10-01 15:37:47 +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
7bfebfbe03 [AST] Have the ASTWalker visit the indices pattern and element TypeRepr of a subscript decl.
Swift SVN r8782
2013-09-30 17:59:04 +00:00
Argyrios Kyrtzidis
5bec0390dd Syntax-annotate 'get'/set' in a getter/setter as keywords.
Also make sure that ColorASTWalker passes SyntaxNodes in source order.
This is a patch by Sonny with some modifications.

Swift SVN r8777
2013-09-30 16:26:00 +00:00
Joe Groff
92cce69e15 AST: Give NominalTypePattern a better AST-level representation.
Instead of relying on the subpattern being a well-formed TuplePattern, let's track our own subelements so we can associate them to properties and validate them ourselves.

Swift SVN r8771
2013-09-30 01:03:18 +00:00
Argyrios Kyrtzidis
b4d0d01071 [AST] Enable walking of all VarDecls.
This allows:
-The verifier to verify them.
-swiftIDE to annotate them.

Swift SVN r8767
2013-09-29 00:12:27 +00:00
Argyrios Kyrtzidis
4a91e28d11 [AST] For the ASTWalker add Module and Decl as a parent kind, and make ParentTy a class.
Swift SVN r8756
2013-09-29 00:12:11 +00:00
Doug Gregor
0d33ff3f40 Teach SILGen to directly emit optional injection operations for dynamic lookup.
... rather than synthesizing expressions in the AST.


Swift SVN r8723
2013-09-27 14:12:33 +00:00
Argyrios Kyrtzidis
4255aa64c9 [ASTWalker] When walking a SelfApplyExpr, walk the base expression first to get a source-order walk.
Swift SVN r8679
2013-09-25 23:55:47 +00:00
Doug Gregor
f67aa78d69 Dynamic lookup for subscripts: semantic analysis and ASTs.
Swift SVN r8591
2013-09-24 05:51:30 +00:00
Joe Groff
ae496fa64c ASTWalker: Walk the pre-type-checked raw literal expr of EnumElements.
As suggested by Dmitri, walk the expr so that clients such as syntax highlighting can see it, but discard the result if it doesn't come back as a LiteralExpr to avoid breaking the invariant.

Swift SVN r8573
2013-09-23 22:19:04 +00:00
Argyrios Kyrtzidis
ab82766a74 [AST] Walk the inherited TypeReprs of a nominal type declaration with the ASTWalker.
Swift SVN r8556
2013-09-23 15:39:44 +00:00
Argyrios Kyrtzidis
8e1538e110 [AST] Consolidate walking of NominalTypeDecl subclasses to reduce duplication.
Swift SVN r8555
2013-09-23 15:39:42 +00:00
Joe Groff
2c04f45912 Have the ASTWalker walk type-checked raw value exprs.
We don't let it see the pre-type-checked LiteralExpr yet because EnumElementDecls need to do its own checking.

Swift SVN r8547
2013-09-21 15:21:16 +00:00
Joe Groff
e109124186 Replace 'union' keyword with 'enum'.
This only touches the compiler and tests. Doc updates to follow.

Swift SVN r8478
2013-09-20 01:33:14 +00:00
Doug Gregor
90b8b3e499 Constructor selectors always start with 'init'.
Implement the new rules for mapping between selector names and
constructors. The selector for a given constructor is formed by
looking at the names of the constructor parameters:
  * For the first parameter, prepend "init" to the parameter name and
  uppercase the first letter of the parameter name. Append ':' if
  there are > 1 parameters or the parameter has non-empty-tuple type.
  * For the remaining parameters, the name of each parameter followed
  by ':'.

When a parameter doesn't exist, assume that the parameter name is the
empty string.

And, because I failed to commit it separately, support selector-style
declarations of constructor parameters so that we can actually write
constructors nicely, e.g.:

  // selector is initWithFoo:bar:
  constructor withFoo(foo : Foo) bar(bar : Bar) { ... }



Swift SVN r8361
2013-09-17 22:49:05 +00:00
Dmitri Hrybenko
7c408791cd Code completion: implement delayed parsing of destructors (and basic code completion)
Swift SVN r8352
2013-09-17 21:08:09 +00:00
Dmitri Hrybenko
f1f189f4e0 Rename PipeClosureExpr -> ClosureExpr
Swift SVN r8321
2013-09-17 01:37:36 +00:00
Dmitri Hrybenko
b18c38a322 Rename ImplicitClosureExpr -> AutoClosureExpr
Swift SVN r8304
2013-09-16 23:03:50 +00:00
Dmitri Hrybenko
f8bd657b2f ImplicitClosureExpr (AutoClosureExpr in future): store body as BraceStmt
This allows us to add AnyFunctionRef::getBody(), which returns the body
as a BraceStmt for every function-like AST node.


Swift SVN r8293
2013-09-16 20:52:12 +00:00
Dmitri Hrybenko
e7af4d6c72 Collapse ImplicitClosureExpr into its abstract base class, ClosureExpr
Swift SVN r8280
2013-09-16 18:31:05 +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
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
Doug Gregor
8c60d88f5a Provide DynamicMemberRefExpr with .Some(fn)/.None helper expressions.
These helper expressions will eventually be used by SILGen to help
package up the optional values. I expect that we'll eventually have
library builtins for this, so consider this a stop-gap until those
appear.

As part of this, make OpaqueValueExpr a bit more usable: it can now
persist in the AST as a placeholder, but its uses must be within AST
subtrees of some specific introduction point (similarly to how Clang's
OpaqueValueExpr works).


Swift SVN r8051
2013-09-09 19:58:51 +00:00
Dmitri Hrybenko
1e23c936e0 Rename FuncDecl::getBody() to FuncDecl::getFuncExpr()
ConstructorDecl::getBody() and DestructorDecl::getBody() return 'BraceStmt *'.
After changing the AST representation for functions, FuncDecl::getBody() will
return 'BraceStmt *' and FuncDecl::getFuncExpr() will be gone.


Swift SVN r8050
2013-09-09 19:57:27 +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
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
Argyrios Kyrtzidis
6d57b49e02 Have the ASTWalker walk protocol declarations.
Also make the implicit AssociatedTypeDecl, created for a protocol, to have the
location of its protocol, otherwise the verifier will complain that a decl has no
source range.

Swift SVN r7673
2013-08-28 18:22:06 +00:00
Dmitri Hrybenko
d9035426ed Rename RebindThisInConstructorExpr -> RebindSelfInConstructorExpr
Swift SVN r7658
2013-08-28 03:02:30 +00:00
Doug Gregor
7e5e154f87 Traversal: turn missing visit*Stmt methods into link-time errors.
Swift SVN r7508
2013-08-23 18:16:22 +00:00
Doug Gregor
7634cd292e Traversal: turn missing visit*Pattern methods into link-time errors.
Swift SVN r7506
2013-08-23 18:08:56 +00:00
Doug Gregor
d93056080e Traversal: turn missing visit*TypeRepr() methods into link errors.
Swift SVN r7505
2013-08-23 18:06:22 +00:00
Doug Gregor
b3064a0675 ASTWalker: Walk OptionalTypeReprs, and add TypeRepr::walk().
Swift SVN r7503
2013-08-23 17:52:58 +00:00
Dmitri Hrybenko
1fd528c15b Add ErrorTypeRepr, which is constructed during parser recovery for a type with
a syntax error.  Usually the type parsing can just return nullptr for the
TypeRepr, but when we want to construct an AST node that should have included
that type, we should provide a non-null TypeRepr.


Swift SVN r7375
2013-08-20 22:24:15 +00:00
Dmitri Hrybenko
5b952b080a Rename OOD and OOED variables that used to stand for OneOfDecl and
OneOfElementDecl


Swift SVN r7283
2013-08-16 18:11:28 +00:00
Dmitri Hrybenko
ce54da3123 Use NullablePtr in ForStmt
ForStmt::Cond is already a NullablePtr<>.  This patch changes
ForStmt::Initializer and ForStmt::Increment to be NullablePtr.  Otherwise it
looks like Cond can be null, while Initializer and Increment can not.


Swift SVN r7265
2013-08-15 17:51:32 +00:00
Doug Gregor
2749828bf9 Move the resolution of UnresolvedDeclRefExprs into the type checker.
The only visible change from this now is that diagnostics will come in
a more sensible order, because we do name resolution along with the
rest of type checking, rather than in a separate pass early
on. However, it's foundational for lazy type checking, type
refinement, and various other important features and bug fixes.



Swift SVN r7086
2013-08-09 18:26:14 +00:00
Argyrios Kyrtzidis
885c9ce119 [IDE] Highlight type identifiers.
Swift SVN r6862
2013-08-02 22:44:59 +00:00
Jordan Rose
674a03b085 Replace "oneof" with "union"...everywhere.
We haven't fully updated references to union cases, and enums still are not
their own thing yet, but "oneof" is gone. Long live "union"!

Swift SVN r6783
2013-07-31 21:33:33 +00:00
Doug Gregor
c4b121a11b Integrate type checking of default arguments into the type checking of the function/constructor body.
This eliminates the odd separate pass over default arguments, as well
as the isFirstPass distinction for type checking patterns,
centralizing default argument checking. It actually regresses us
slightly (see <rdar://problem/14488311>) due to name binding happening
too early (and, therefore, in the wrong context). This will be fixed
by moving name binding into constraint generation.


Swift SVN r6368
2013-07-19 00:28:35 +00:00
Joe Groff
844465d9b9 Resolve and type-check OneOfElementPatterns.
If we see '.Foo' or '.Foo(...)' in a case, resolve it as a OneOfElementPattern with element to be determined at type-checking time. If we see 'A.B' or 'A.B(...)', try to resolve 'A.B' as a qualified reference to a OneOfElementDecl, and resolve the expression as a OneOfElementPattern referencing that decl if we find one. During type-checking, resolve the element decl for unresolved OneOfElementPatterns, then match the subpattern to the type of the element's associated data (or void if it has none).

A few cases don't yet work right that ought to:

- Qualified references to generic oneof cases with generic arguments elided, e.g. 'case Optional.None:'
- Qualified references to generic oneof cases through a module, e.g. 'case swift.Optional<Int>.None:'

Swift SVN r6278
2013-07-16 01:25:34 +00:00
Joe Groff
3b21e6a201 Add a OneOfElementPattern AST node type.
Add a node for references to oneof cases in patterns. No user-facing functionality change yet.

Swift SVN r6239
2013-07-13 01:21:31 +00:00
Argyrios Kyrtzidis
3df3878490 [AST/TypeRepr] Address feedback by Doug.
-Add some FIXMEs
-Rename CompositeTypeRepr -> ProtocolCompositionTypeRepr
-Fix dumping of AttributedTypeRepr

Swift SVN r6150
2013-07-11 17:00:53 +00:00
Argyrios Kyrtzidis
a70eff6609 Introduce TypeRepr and related subclasses, that is a representation of a type as written in source.
This the first part for improving source location fidelity for types,
changes to follow:

-The Parser will not create any types, it will just create TypeReprs.
-The type checker will create the types by going through TypeReprs.
-IdentifierType will be removed.

Swift SVN r6112
2013-07-10 14:58:52 +00:00
Joe Groff
e0afea91b8 Sema: Build a full ApplyExpr for ExprPattern ~= operators.
Sema knows better how to call getLogicValue to get an i1 from a conditional than SILGen does. Fake up a placeholder variable we can slot into a 'expr ~= var' expression, and have the type-checker run on the entire apply expr to generate getLogicValue() conversions on the applied result.

Swift SVN r5995
2013-07-04 19:42:56 +00:00
Dave Abrahams
096ffc6eaf Silence warnings in the release build
Swift SVN r5950
2013-07-01 21:42:16 +00:00
Joe Groff
f6d1999569 Parse: Introduce pattern vars into case scopes.
Create a scope for each case block to contain bindings from its patterns, and invoke addVarsToScope after parsing case label patterns to introduce vars into that scope. Refactor addVarsToScope to use an ASTWalker so it finds pattern vars embedded in expr patterns.

Swift SVN r5899
2013-06-29 16:41:57 +00:00
Joe Groff
b5d6103bfc AST: Add an UnresolvedPatternExpr to parse patterns in expr position.
Because of '~=' lookahead and precedence parsing, we need to be able to parse pattern productions in expression position and validate them after name binding. Add an unresolved Expr node that can hold a subpattern for this purpose.

Swift SVN r5825
2013-06-27 00:01:14 +00:00