Commit Graph

559 Commits

Author SHA1 Message Date
Joe Groff
df5f1f51dd Parse attribute list after enum 'case' keyword.
For consistency with our other decl types. There aren't any case-specific attributes yet, but if/when we add them, this is where they'll go.

Swift SVN r8779
2013-09-30 17:13:34 +00:00
Argyrios Kyrtzidis
c00fce9ad6 [Parser] Add the getter/setter of a computed variable in source order and after the pattern binding decl.
Swift SVN r8766
2013-09-29 00:12:26 +00:00
Argyrios Kyrtzidis
6b732c9db5 [Parser] If the name for the setter var is missing, use the 'get' as its location.
Swift SVN r8759
2013-09-29 00:12:16 +00:00
Argyrios Kyrtzidis
6942646f80 [AST] Make 'self' vars implicit and provide a source location for them.
Verifier expects all decls to have locations, let's keep it happy.

Swift SVN r8757
2013-09-29 00:12:13 +00:00
Anna Zaks
3e5c1f81d2 Support transparent attributes on struct and enum extensions.
Attribute [transparent] on extensions should apply to all members(functions, properties) of that extension.

Addresses radar://15035271.

Swift SVN r8735
2013-09-27 20:29:31 +00:00
Argyrios Kyrtzidis
b955d8e134 [Parser] Adjust the end source locations in a few places.
Swift SVN r8728
2013-09-27 17:24:33 +00:00
Dmitri Hrybenko
ba2e4732d0 Remove unused member EnumDecl::isEnum
Swift SVN r8710
2013-09-27 00:22:39 +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
5c142346c6 Destructor syntax: require an empty parameter list for destructors
rdar://14968738


Swift SVN r8694
2013-09-26 18:09:12 +00:00
John Garvin
c0b3277c33 Improve diagnostic for function attributes.
Swift SVN r8687
2013-09-26 01:31:06 +00:00
Anna Zaks
c2adc1e35b Restructure parsing to ensure that bodiless constructors/destructors/subscripts are fully diagnosed.
Previously, we followed an early exit for bodiless constructors/destructors/subscripts.
This prevented some diagnostics and full AST class setup in SIL parsing mode and for bodiless subscripts in general.

Thanks for the suggestion Dmitry!

Swift SVN r8672
2013-09-25 23:28:52 +00:00
John Garvin
4a8ac0d752 Parse kernel, vertex, and fragment function attributes. Metadata is not yet being generated.
This is part of <rdar://problem/14951602> AGP5 bring up: Parse AGP5 kernel function attributes.



Swift SVN r8670
2013-09-25 22:16:57 +00:00
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Dmitri Hrybenko
f10947654e AST Verifier: verify source locations on Patterns and fix bugs found by this
Swift SVN r8660
2013-09-25 20:53:28 +00:00
Anna Zaks
b30d11d8cd Allow bodiless constructors, destructors, and subscripts when parsing Decls in SIL mode.
Swift SVN r8659
2013-09-25 20:32:37 +00:00
Jordan Rose
c5322d4bf6 Record a back-pointer from a VarDecl to its containing PatternBindingDecl.
This will be used for lazy type-checking of global and member vars.

Swift SVN r8640
2013-09-25 20:08:07 +00:00
Anna Zaks
30039a59f1 Emit Swift declarations when printing SIL.
Only print function member declarations and skip the bodies since the bodies are already represented in SIL and ASTPrinter is not good enough to print arbitrary expressions.

In order to have valid output, make sure that ASTPrinter does not print references to DynamicLookup protocol.

Swift SVN r8627
2013-09-25 17:08:42 +00:00
Dmitri Hrybenko
33aada4b16 Set DeclContext for argument parameter patterns
Fixes a crash in Serializer, when processing a function with a selector-style signature.

Also added an AST verifier check that all Decls have a non-null DeclContext.


Swift SVN r8621
2013-09-25 01:47:27 +00:00
Doug Gregor
6a1db609e0 Allow [objc] subscripts and emit Objective-C thunks for the getters/setters.
Sema and SILGen; IRGen to follow.


Swift SVN r8589
2013-09-24 02:26:23 +00:00
Dmitri Hrybenko
10d8fdc64f AST/AbstractFunctionDecl: Remember if a function had a selector-style signature
... and use this information in AST printing


Swift SVN r8583
2013-09-24 00:56:33 +00:00
Dmitri Hrybenko
c9d1aa3f96 AST Printer: fix parameter name printing in setters
Also, add an AST verifier check that the parameter patterns in getters/setters
are sane.


Swift SVN r8574
2013-09-23 22:25:35 +00:00
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