Commit Graph

784 Commits

Author SHA1 Message Date
Dave Zarzycki
735294a5c9 Make the lexing of '(', '[', and '.' consistent
The lexer now models tuples, patterns, subscripting, function calls, and
field access robustly. The output tokens are now better named as well:
l_paren and l_paren_call, and l_square and l_square_subscript. It
should be much more clear now which one to use. Also, the use of
l_paren or l_square will not arbitrarily flip flop if the token before
it is a keyword or if the token before it was the trailing ']' of an
attribute list. Similarly, tuples will always cause the lexer to produce
l_paren, regardless if the user typed '((x,y))' or '( (x,y))'.

When we someday add array literals, the right token is now naturally
falling out of the lexer.

Swift SVN r3840
2013-01-23 03:23:17 +00:00
Dave Zarzycki
ac4592fdca Part 2 of 2: make "for (;;)" work
This requires a gross but simple contract between pattern parsing and C
for loop parsing where pattern parsing will gracefully back out if and
only if we have a potential C for loop pattern AND assignment is
detected in the pattern (which isn't otherwise allowed outside of the
context of func decls).

If we ever want "for (((;;)))" to work, then this we'll need to
implement the fully general arbitrary token lookahead. But for now, the
common C style "just works".

Swift SVN r3831
2013-01-22 08:59:45 +00:00
Dave Zarzycki
041e91d6ad Part 1 of 2: make "for (;;)" work
Swift SVN r3830
2013-01-22 08:59:42 +00:00
Dave Zarzycki
2f31759280 Remove SemiStmt class
We have no intention of ever supporting actual semicolon statements
(separators, statements no), nor do we ever want to because that would
mean the behavior of the program would potentially change if semicolons
were naively removed.

This patch tracks the trailing semicolon now in the decl/expr/stmt,
which will enable someone to write a good "swift indent" tool in the
future.

Swift SVN r3824
2013-01-22 00:25:26 +00:00
Dave Zarzycki
9eb53f37f5 12641063 Fix the double-indent problem with properties
Swift SVN r3822
2013-01-21 22:43:19 +00:00
Joe Groff
759f18a329 Consume trailing semicolons at top level.
Instead of writing in an awkward special case for SemiStmt in ParseStmt, apply the existing semicolon-eating syntax in ParseDecl for types to the toplevel. Suggested by Jordan re: r3336.

Swift SVN r3342
2012-12-04 00:21:50 +00:00
Joe Groff
683ef3548b Allow ';' in a top-level form.
Swift SVN r3338
2012-12-03 23:18:50 +00:00
Doug Gregor
2583f419c9 'protocol<' does not start a declaration. Test case coming in a future patch.
Swift SVN r2716
2012-08-23 00:26:17 +00:00
Chris Lattner
b6f6eec106 implement rdar://11935352 - accepting closures with no body expression (the closure
just returns "()").


Swift SVN r2503
2012-08-02 20:08:51 +00:00
Eli Friedman
6b4a248f04 Parsing and AST support for destructors on classes.
Swift SVN r2348
2012-07-12 01:26:02 +00:00
Chris Lattner
db0cd646fc lexer/parser/ast/sema support for do/while statements. irgen next.
Swift SVN r2186
2012-06-17 02:29:54 +00:00
John McCall
8c46c69efa Lexically distinguish prefix, postfix, and binary operators
and use this information as cues in the language.  Right now,
we do not accept things like "-- *i" because the prefix
operator is not correctly right-bound;  instead you have to
write "--(*i)".  I'm okay with that;  I did add a specialized
diagnostic recognizing operator-binary in a place where we're
expecting a potential operator-prefix.

Swift SVN r2161
2012-06-07 01:00:06 +00:00
Eli Friedman
75907029f1 Add parsing and semantic analysis for a basic ConstructorDecl. Still missing: no IRGen, and semantic analysis to actually call them.
Swift SVN r2159
2012-06-05 23:51:19 +00:00
Eli Friedman
27f8a5ab62 Teach the parser's handling of scopes to handle local types correctly.
Swift SVN r2138
2012-06-04 19:14:58 +00:00
Eli Friedman
c404598fcb Parsing and semantic analysis for 'break' and 'continue'.
Swift SVN r2087
2012-05-31 00:55:33 +00:00
Eli Friedman
a5a39860cd Basic parsing plus a bit more of the AST for ClassDecls.
Swift SVN r1860
2012-05-15 22:07:31 +00:00
Chris Lattner
46c94377f1 Add support for var decls in the initializer of a c-style for loop,
implementing rdar://11360347 / 11349750.  C-style for loops could be
further enhanced by allowing a comma-separated list of statements in
the increment, but this isn't something I plan to do in the short term.


Swift SVN r1713
2012-05-02 05:44:58 +00:00
Chris Lattner
8c478d1cb7 remove the foreach keyword, switching foreach loops to use 'for' instead.
This uses one-token lookahead to distinguish between the two forms.


Swift SVN r1710
2012-05-02 01:06:06 +00:00
Chris Lattner
e205e1d2da change the subset of for statements we support: instead of *requiring* parens,
now we *do not allow* them.  This is progress towards unifying for and foreach.


Swift SVN r1709
2012-05-02 00:43:24 +00:00
Chris Lattner
54c7c6ea74 Add some helper functions to help treat "spaced" lparen and lsquares uniformly.
Swift SVN r1708
2012-05-02 00:30:45 +00:00
Chris Lattner
ab0c800e62 fix rdar://11344875, where we would reject "return;"
Swift SVN r1686
2012-04-30 03:52:04 +00:00
Eli Friedman
e33b1aac24 Don't try to synthesize an expression for a return statement which doesn't have one. <rdar://problem/11315114>.
Swift SVN r1639
2012-04-25 22:58:06 +00:00
Doug Gregor
f997a781bf Parsing and basic AST representation for 'foreach' statement.
Swift SVN r1594
2012-04-24 18:12:44 +00:00
Chris Lattner
cbc1eac438 irgen parser and sema support for for statements.
Swift SVN r1505
2012-04-19 21:43:46 +00:00
Eli Friedman
d5e7784010 Get rid of isModuleScope bit, since we don't like scattering bits across the AST; as a replacement, introduce TopLevelCodeDecl, which provides a DeclContext for all expressions and statements at the top level. <rdar://problem/11259941>.
Swift SVN r1503
2012-04-19 21:22:12 +00:00
Chris Lattner
df74bc03c0 lang ref and parser support for for statements. AST and sema next.
Swift SVN r1493
2012-04-19 18:25:48 +00:00
Chris Lattner
44af5d13ef refactor some code to expose a new expr-or-stmt-assign production.
Swift SVN r1492
2012-04-19 17:57:22 +00:00
Doug Gregor
6897b6ab44 Add support for parsing a subscripting declaration, e.g.,
subscript (i : Int) -> Double {
    get { /* get ith element of something */ }
    set { /* set ith element of something to value*/ }
  }



Swift SVN r1476
2012-04-18 21:43:54 +00:00
John McCall
e6d56fd718 Require an unspaced [ to start a subscript or array-type suffix.
Per discussion, this should probably be "no newline since the last
token", but that decision should be made simultaneously for ( and [.

Swift SVN r1461
2012-04-18 08:08:58 +00:00
Eli Friedman
ecb0f2bba4 Add a little bit of missing error-checking for libraries.
Swift SVN r1455
2012-04-18 01:50:24 +00:00
Eli Friedman
cf10f0096e Make the REPL allow mutually recursive functions spread across multiple lines, like we do in script mode.
Swift SVN r1453
2012-04-18 01:20:38 +00:00
Eli Friedman
37de44a35d Implement changes to parsing/sema/etc so that we can implement a REPL and the main module parses the same way as a REPL.
Next step: implement an actual REPL.



Swift SVN r1441
2012-04-16 23:52:01 +00:00
Chris Lattner
fbfb76a515 rename 'plus' methods to 'static' methods, resolving:
<rdar://problem/10718220> Need a better name than 'plus' for "static" functions



Swift SVN r1340
2012-04-06 17:50:43 +00:00
Eli Friedman
f477cf588e Introduce the notion of the "main" module, i.e. the module which defines main(). Disallow top-level statements in modules other than the main module. Fix IRGen to generate a main() function in the main module, and implement top-level statements. Get rid of the main() mangling hack. Part of <rdar://problem/11185451>.
I haven't really carefully considered whether existing type-checking etc. is correct for the main module (I think the name-binding rules need to be a bit different?), but it seems to work well enough for the obvious cases.

This is enough to get the one-liner "println(10)" to print "10" in "swift -i" mode, although the path to swift.swift still needs to be explicitly provided with -I.



Swift SVN r1325
2012-04-05 00:35:28 +00:00
Eli Friedman
862646c1dd Perform conversion to bool in conditionals by repeatedly calling ".getLogicValue()" on the value until we reach Builtin.Int1, instead of using convertToLogicValue(). <rdar://problem/10100856>.
Swift SVN r1173
2012-03-10 00:02:36 +00:00
Chris Lattner
601e401dfa document the forthcoming expr-anon-closure syntax, part of rdar://10666917
Swift SVN r1151
2012-03-02 01:30:18 +00:00
Chris Lattner
ce9d3c4398 remove Parser::isStartOfExpr, which is only used by one caller that can
be done in a simpler way.


Swift SVN r1150
2012-03-02 01:07:21 +00:00
Chris Lattner
58b4a5d7cc have the parser produce ErrorStmt nodes to handle semantic errors...
except that it never produces semantic errors.  How about that.


Swift SVN r1143
2012-03-01 22:54:41 +00:00
Chris Lattner
6692cba150 simplify expression parsing to return a NullablePtr<Expr> instead of a ParseError<Expr>.
The later could represent semantic errors, but we'd rather represent those with an
ExprError node instead.  This simplifies the code and allows the parser to build a more
fully-formed AST that IDE clients will like.


Swift SVN r1141
2012-03-01 22:34:32 +00:00
Chris Lattner
17ea0a6670 finish my pass over LangRef, updating it and changing it and the parser to keep the grammars in sync.
Swift SVN r1132
2012-03-01 16:55:09 +00:00
John McCall
2b65cf22d1 Make 'this' implicitly [byref] when the container type does
not have reference semantics.  Deciding whether the container
type has reference semantics requires us to perform
some amount of limited name-binding and type-checking first,
which introduces a few complexities.

Also, fix a bug in uncurried call emission.

Methods work now.



Swift SVN r1112
2012-02-11 07:37:57 +00:00
John McCall
d0f4d86f3e Use LValueType everywhere instead of the l-value value kind.
Kill off TypeJudgement.  Various fixes and improvements.



Swift SVN r1107
2012-02-06 22:47:08 +00:00
Chris Lattner
bab9ca384c switch TupleExpr to use MutableArrayRef.
Swift SVN r1090
2012-01-19 06:54:43 +00:00
Chris Lattner
27f47dd705 eliminate the concept of a singular expression, which is obsolete and not in lang ref.
Swift SVN r1084
2012-01-18 23:59:04 +00:00
John McCall
59bed696a5 Introduce a ParenExpr to represent the special case of
a tuple with one element and no labels.  This form is
treated specially in essentially every case, so it might
as well be its own expression kind.



Swift SVN r1021
2012-01-12 19:55:06 +00:00
Chris Lattner
17b11e9bbd implement parsing, AST, and LangRef support for 'plus' methods. Dot syntax will need some work though to actually use them.
Swift SVN r949
2011-12-21 23:21:58 +00:00
Chris Lattner
eef2f69637 improve AST modeling of dot syntax calls to follow the syntactic structure instead of being weird and broken and losing source loc info.
Swift SVN r938
2011-12-15 00:52:58 +00:00
Chris Lattner
3d4111475e fix a minor pasto.
Swift SVN r912
2011-12-07 00:10:42 +00:00
Chris Lattner
0b72409c9c ensure that extension members get the proper function type, and a 'this' argument.
Swift SVN r908
2011-12-06 20:23:53 +00:00
Chris Lattner
8d53c9f3b9 restrict 'extension' to only exist at file scope.
Swift SVN r899
2011-12-06 00:11:13 +00:00