Commit Graph

2438 Commits

Author SHA1 Message Date
Joe Groff
c4b4db732f Parse and check raw values on enum cases.
Iff an enum declares a raw type, its cases may declare raw values or else have them assigned to them implicitly by autoincrementing from zero, like in C. If the raw type is float-, string-, or char-literal-convertible, there is no autoincrement, and the raw values must all be explicit. The raw type is rejected if any cases have payloads.

We don't yet diagnose duplicate raw values. That'll come next. We also don't yet serialize or deserialize the raw values. We don't strictly need to do this, since the RawRepresentable protocol conformance will be exported from the module as API, but Jordan pointed out that, for fragile raw values, this would be good for documents/jump-to-definition purposes, so we have a plan for only serializing the literals without having to deal with fully general expression serialization.

Swift SVN r8545
2013-09-21 04:31:26 +00:00
Joe Groff
f9480828e0 Remove EnumCaseDecl backreference from EnumElementDecl.
Swift SVN r8516
2013-09-20 20:50:24 +00:00
Joe Groff
ee2b55475e Update parseDeclEnumCase grammar comments and style.
Swift SVN r8514
2013-09-20 20:44:07 +00:00
Joe Groff
5d8a7ff9e7 Allow multiple comma-separated enum elements in a 'case' decl.
Introduce an EnumCaseDecl for source fidelity to track the 'case' location and ordering of EnumElementDecls. Parse a comma-separated list of EnumElementDecls after a 'case' token.

Swift SVN r8509
2013-09-20 19:51:13 +00:00
Doug Gregor
62e84f59e4 s/constructor/initializer in diagnostics
Swift SVN r8506
2013-09-20 18:59:22 +00:00
Doug Gregor
e52687f6ee Use "initial value" rather than "initializer" in diagnostics.
Swift SVN r8505
2013-09-20 18:45:15 +00:00
Doug Gregor
bc3f655105 s/constructor/init in a few more places.
Swift SVN r8504
2013-09-20 18:37:15 +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
Dmitri Hrybenko
37b7284e0c Code completion: don't crash when completing in constructors/destructors placed
in contexts where they are not allowed

We used to throw away the ConstrutorDecl/DestructorDecl, but code completion
captured the pointer as a DeclContext for the code completion point.  Then code
completion passed that AST node to type checker, which crashed.  Now we
properly mark the decl as invalid, pass it to the type checker, and have the
type checker set its type to ErrorType.


Swift SVN r8466
2013-09-19 23:01:26 +00:00
Dmitri Hrybenko
667969602b Code completion: implement completion of types in constructor parameter lists
Swift SVN r8439
2013-09-19 00:56:12 +00:00
Doug Gregor
bcf5345626 Eliminate the completely-broken implicit default constructor for classes.
When a given class definition has no constructors, the parser was
introducing an implicit-declared default constructor in the class. The
type checker ignored it. SILGen creating something that was completely
broken. Remove all of that and fix the fallout.




Swift SVN r8432
2013-09-18 23:58:34 +00:00
Dmitri Hrybenko
12b3583c27 Code completion inside function parameter lists: simplify code
Swift SVN r8427
2013-09-18 23:16:45 +00:00
Anna Zaks
ba3298e6b8 Add support for [transparent] attribute on property getters and setters
Addresses radar://14738227

Swift SVN r8405
2013-09-18 17:30:52 +00:00
Doug Gregor
978959ced8 Make the "init" and "constructor" keywords synonymns.
Swift SVN r8391
2013-09-18 04:23:28 +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
07e83ea49c Code completion: basic completion in constructor bodies
Swift SVN r8338
2013-09-17 18:20:26 +00:00
Dmitri Hrybenko
b9d9023b67 Replace AddConstructorArgumentsToScope() with a call to
addFunctionParametersToScope()

It is an exact copy of the other function.


Swift SVN r8323
2013-09-17 02:09:45 +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
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
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
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
Dmitri Hrybenko
4235c0c7ac Mark some "expected {" diagnostics as PointsToFirstBadToken
Swift SVN r7970
2013-09-06 00:32:23 +00:00
Dmitri Hrybenko
df5d0a0272 Point the diagnostic "expected '{' in body of func declaration" to the first
invalid token (used to point to the function name).


Swift SVN r7967
2013-09-06 00:09:26 +00:00
Dmitri Hrybenko
d52982cd0d Recovery from parsing extensions for non-nominal types: stop abusing the type
checker for what can be a simple syntactic check, when implemented on
appropriate level -- during type parsing.


Swift SVN r7954
2013-09-05 20:22:31 +00:00
Dmitri Hrybenko
08ac7f8255 Use nullptr instead of '0'
Swift SVN r7950
2013-09-05 17:59:50 +00:00
Dmitri Hrybenko
61794481ad Remove dead code: BraceStmt::create never returns a null pointer
Swift SVN r7949
2013-09-05 17:57:36 +00:00
Dmitri Hrybenko
734fe3120d parseDeclFunc(): sink error recovery for bad signature into
parseFunctionSignature() and add more tests


Swift SVN r7922
2013-09-04 23:02:24 +00:00
Dmitri Hrybenko
20ad7d830b parseDeclFunc(): simplify a little bit and add a test
Swift SVN r7911
2013-09-04 21:28:11 +00:00
Dmitri Hrybenko
b49b9865c4 Remove unused overloads of parseIdentifierDeclName()
Swift SVN r7856
2013-09-03 19:30:11 +00:00
Dmitri Hrybenko
27f2279a9b Parser: fix recovery for 'case' with a keyword as a union element name
We used to skip too much code and produce confusing diagnostics.


Swift SVN r7855
2013-09-03 19:27:29 +00:00
Dmitri Hrybenko
3ed1303b91 Parser: improve recovery when the extension name is a keyword
Swift SVN r7827
2013-08-31 02:09:39 +00:00
Dmitri Hrybenko
23ced2fba3 Move the parseIdentifierDeclName() helper above parseDeclExtension()
(so that extension parsing can use these helpers)


Swift SVN r7824
2013-08-31 01:54:50 +00:00
Dmitri Hrybenko
d7cbadbff1 Parser: improve recovery when the protocol name is a keyword
Swift SVN r7822
2013-08-31 00:08:41 +00:00
Dmitri Hrybenko
71430d0f3f Parser: improve recovery when the union name is a keyword
Swift SVN r7820
2013-08-30 23:50:22 +00:00
Dmitri Hrybenko
dbbbe61295 Parser: improve recovery when the class name is a keyword
Swift SVN r7819
2013-08-30 23:46:56 +00:00
Dmitri Hrybenko
cc8cc64572 Parser: improve recovery when the struct name is a keyword
Swift SVN r7815
2013-08-30 23:40:43 +00:00
Jordan Rose
6d8a63756c Parse: reject [prefix] and [postfix] on the same function.
Swift SVN r7811
2013-08-30 23:20:32 +00:00
Dmitri Hrybenko
b8b02539af Parser: improve recovery when the typealias name is a keyword
Swift SVN r7810
2013-08-30 23:16:53 +00:00
Dmitri Hrybenko
35dd32fb58 Disallow 'self', 'Self', and other identifier keywords in decl names
The diagnostics are really bad, but this will be fixed in later commits.  This
commit is only about rejecting invalid code.


Swift SVN r7766
2013-08-29 23:53:30 +00:00
Dmitri Hrybenko
4a73138805 Parser: improve recovery when function name is a keyword
Swift SVN r7710
2013-08-29 01:10:42 +00:00
Dmitri Hrybenko
6d34a127ee parseDeclFunc(): improve recovery when the function parameter tuple is missing
Swift SVN r7708
2013-08-29 00:37:05 +00:00
Dmitri Hrybenko
3a6feb7814 Disallow constructors in protocols
Swift SVN r7701
2013-08-28 23:03:37 +00:00
Jordan Rose
fa3dd42c54 Don't parse function bodies in imported TUs.
...unless the functions are declared [transparent], or if we're in an
immediate mode (in which case we won't get a separate chance to link
against the imported TUs).

This is an optimization that will matter more when we start dealing with
Xcode projects with many cross-file dependencies, especially if we have
some kind of implicit import of the other source files in the project.

In the future, we may want to parse more function bodies for the purpose
of inlining, not just the transparent ones, but we weren't taking
advantage of that now, so it's not a regression. (We're still not taking
advantage of it even for [transparent] functions.)

Swift SVN r7698
2013-08-28 22:53:28 +00:00
Dmitri Hrybenko
2e98f855ad Parser: parse, discard and complain about parameter list in destructors
Swift SVN r7691
2013-08-28 21:56:12 +00:00
Dmitri Hrybenko
61783aeb74 Improve recovery and remove noise in diagnostics for 'constructor {}'
Swift SVN r7687
2013-08-28 21:22:22 +00:00
Dmitri Hrybenko
35ae80ae20 parseDeclConstructor(): don't give up on parsing the constructor if
constructors are not allowed in this context

Parse as much as we can for recovery.


Swift SVN r7682
2013-08-28 20:14:44 +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
69cfa73640 More 'this' -> 'self' replacements
Swift SVN r7657
2013-08-28 02:57:21 +00:00