Commit Graph

354 Commits

Author SHA1 Message Date
Dave Zarzycki
942b490342 Copy and paste error: we do not have a ** operator
Swift SVN r10819
2013-12-04 23:46:51 +00:00
Dave Zarzycki
ecb3563628 11242731 simplify precedence of binary operators
Swift SVN r10815
2013-12-04 23:31:16 +00:00
Doug Gregor
4d3e475973 Fix typo in example
Swift SVN r10784
2013-12-04 17:36:25 +00:00
Doug Gregor
627f0ae447 Allow "x as T" to perform implicit conversions from x to T.
Fixes <rdar://problem/15283100>.


Swift SVN r10783
2013-12-04 17:31:44 +00:00
Doug Gregor
002038ad8e Allow a comma-separated list of init expressions in C-style for loops.
Swift SVN r10748
2013-12-03 15:14:54 +00:00
Dave Zarzycki
83f953b80a 15242776 docs: Replace "Slice" with "Array"
Swift SVN r10710
2013-12-01 08:16:54 +00:00
Doug Gregor
19759529db Allow delayed identifier expressions (.foo) with static variables and methods.
This allows expressions such as ".foo" and ".foo(1)" to refer to
static variables and static methods, respectively, as well as enum
cases. 

To get here, rework the parsing of delayed identifier expressions a
bit, so that the argument itself is part of the delayed argument
expression rather than a separate call expression. This simplifies
both the handling of patterns of this form and the type checker, which
can now user simpler constraints.

If we really want to support (.foo)(1), we can make that work, but it
seems unnecessary and perhaps confusing.


Swift SVN r10626
2013-11-21 06:24:06 +00:00
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +00:00
Doug Gregor
5bdaf96a9b Update grammar for comma-separated increment expressions in C-style for loops.
The actual language change went into r10399.


Swift SVN r10409
2013-11-13 03:54:20 +00:00
Dmitri Hrybenko
91ce21666d Change 'func' keyword to 'def'
I tried hard find all references to 'func' in documentation, comments and
diagnostics, but I am sure that I missed a few.  If you find something, please
let me know.

rdar://15346654


Swift SVN r9886
2013-11-02 01:00:42 +00:00
Mark Lacey
eaa7018ed0 Fixup attribute syntax in LangRef.html.
There are still some [infix_left=] in the text. Based on
r4627 it looks like these can just be deleted, but I haven't
done so at this time.

Swift SVN r9616
2013-10-23 08:12:21 +00:00
Greg Parker
5708b8b6ec Remove mention of Optional.get().
Swift SVN r9605
2013-10-22 23:11:58 +00:00
Dmitri Hrybenko
dd66c7e455 Update LangRef for 'as' syntax change that happened some time ago
Swift SVN r9379
2013-10-15 21:52:34 +00:00
Chris Lattner
9f439292b6 Implement support for type-attributes on the result of a function type or decl.
Also, improve error recovery for new-syntax attributes.

This means that we now compile the testcase into:

t.swift:3:16: error: unknown attribute 'xyz'
var x : () -> @xyz Int
               ^
t.swift:6:16: error: unknown attribute 'xyz'
func foo() -> @xyz Int {
               ^

instead of:

t.swift:4:15: error: expected type for function result
func foo() -> @xyz Int {
              ^
t.swift:4:14: error: consecutive statements on a line must be separated by ';'
func foo() -> @xyz Int {
             ^
             ;
t.swift:4:16: error: unknown attribute 'xyz'
func foo() -> @xyz Int {
               ^
t.swift:7:1: error: expected declaration

^

this is part of rdar://15183765


Swift SVN r9260
2013-10-12 21:27:16 +00:00
Joe Groff
1bdbc97056 Drop the 'x as! T' cast syntax.
Now that we have a solid Optional-based story for dynamic casts, it's no longer needed, and can be expressed as '(x as T)!'. Future refinement of the 'as' syntax will deal with the unfortunate extra parens.

Swift SVN r9181
2013-10-10 23:47:59 +00:00
Chris Lattner
efe1ff3fd4 update example for the "new" syntax.
Swift SVN r9024
2013-10-08 16:59:42 +00:00
Doug Gregor
611a5cce4b Replace the library-defined postfix '!' with an expr-postfix production.
As with the monadic '?', we treat any left-bound '!' as a postfix
operator. Currently, it extracts the value of its optional
subexpression, failing at run-time if the optional is empty.


Swift SVN r8948
2013-10-06 23:09:58 +00:00
Chris Lattner
2f3f76f582 update langref to describe the new attribute syntax. Drop the old syntax, even
though the parser still eats it temporarily.


Swift SVN r8911
2013-10-04 05:17:14 +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
5049dbbc13 Update LangRef for 'x as T'.
Swift SVN r8813
2013-10-01 21:11:40 +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
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
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
8b1628bad0 Update LangRef for destructor syntax change
Swift SVN r8695
2013-09-26 18:12:07 +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
Joe Groff
b398492e23 LangRef: Elaborate on interaction of closure capture and inout.
Swift SVN r8666
2013-09-25 21:23:40 +00:00
Joe Groff
0621b811ad Describe inout semantics in more detail in LangRef.
Swift SVN r8663
2013-09-25 21:12:11 +00:00
Joe Groff
3d4c1251f1 Rename 'byref' attribute to 'inout'.
Swift SVN r8661
2013-09-25 20:56:52 +00:00
Joe Groff
8d0d6ff1be LangRef: Demonstrate comma-separated case syntax.
The grammar already until-now-incorrectly claimed that 'case A, B' worked, but insert an example now that it actually works.

Swift SVN r8515
2013-09-20 20:44:11 +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
Chris Lattner
1928361a5a Change the list of usecases for structs.
Swift SVN r8402
2013-09-18 16:12:14 +00:00
Dave Zarzycki
fa8792d8a8 LangRef: Discuss why structs do not support inheritance
Swift SVN r8399
2013-09-18 15:18:48 +00:00
Doug Gregor
a14ddd41ba Minimally update LangRef for "constructor" -> "init" changes.
Swift SVN r8396
2013-09-18 05:49:34 +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
Doug Gregor
ca31b28e0f LangRef: add some basic documentation for generics.
Swift SVN r8240
2013-09-14 03:22:56 +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
Howard Hinnant
c6d960c3df Minor type-o in Reserved Punctuation Tokens.
Swift SVN r7800
2013-08-30 21:02:39 +00:00
Dmitri Hrybenko
453205f5c2 LangRef: fix the only instance of missing this -> self rename that I could find
Swift SVN r7669
2013-08-28 17:21:40 +00:00
Jordan Rose
d40f74f2c1 [Parse] Treat ! as a postfix operator when both left- and right-bound.
For most operators, an expression like "a@b" is lexed with '@' as a binary
operation on 'a' and 'b'. However, we want to make sure we can support
calling optional functions using the syntax "a!()". Consequently, if there
are no spaces around a single '!' token, it is treated as a postfix operator
instead of an infix operator. The infix interpretation can still be requested
by using spaces on both sides of the operator.

Swift SVN r7651
2013-08-28 00:18:19 +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
Joe Groff
2d8a16331d Update union discussion in LangRef and add a section on union element patterns.
Swift SVN r7519
2013-08-23 19:36:52 +00:00
John McCall
329a5e47db Permit attribute lists to be split into multiple clauses.
This is particularly convenient for dealing with generated
code (e.g. as produced by the SIL printer), but it's also
quite defensible as a way for users to logically group
related attributes and split unrelated ones out, should
users find themselves using a lot of verbose attributes
(and prior experience with e.g. user-defined attributes
is that they definitely do sometimes turn into walls of
text...).

Swift SVN r7376
2013-08-20 22:37:38 +00:00
Jordan Rose
6f5d463d18 LangRef: include "T?" syntax.
This documents the current state of affairs, where "Int?[]" is allowed but
"Int[]?" is not. I'll update this again if/when we reach a new decision.

Swift SVN r7269
2013-08-15 18:59:06 +00:00
Dmitri Hrybenko
19298233af Update grammar for stmt-for-c-style: add optional parentheses
Swift SVN r7253
2013-08-15 01:59:08 +00:00
Jordan Rose
35f84dfbee Remove "import foo, bar" syntax.
We never really discussed this and it doesn't really buy us much. If we
want to have a compact way to import many things, it may not even end
up looking like this.

Swift SVN r7015
2013-08-07 22:56:58 +00:00
Jordan Rose
757cf9826f Add Parse and AST support for the new import syntax.
Also, update LangRef.

Note that an explicit "import module" has been left out for now, since
it's not strictly necessary and "module" isn't a keyword yet.

Swift SVN r6786
2013-07-31 23:23:26 +00:00
Jordan Rose
43e9cd7bb4 LangRef: Update union grammar and code examples.
Note: the new grammar allows the multiple-case syntax "case A, B".
This is <rdar://problem/14595749>.

Swift SVN r6784
2013-07-31 21:33:46 +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
0842fb5cf8 Rename "base class" to "superclass" and "derived class" to "subclass".
Standardize on the more-common "superclass" and "subclass" terminology
throughout the compiler, rather than the odd mix of base/derived and
super/sub. 

Also, have ClassDecl only store the Type of the superclass. Location
information will be part of the inheritance clause for parsed classes.




Swift SVN r6687
2013-07-29 15:48:34 +00:00
Joe Groff
69d3392191 Accept underscore separators in numeric literals.
This makes long literals like 1_000_000_000 or 0x7FFF_FFFF_FFFF_FFFF much easier to read, and has precedent in Perl, OCaml, Python, Ruby, Rust, ... Fixes <rdar://problem/14247571>.

Swift SVN r6681
2013-07-28 18:56:30 +00:00