Commit Graph

805 Commits

Author SHA1 Message Date
Dmitri Hrybenko
f7ad1c9b03 parseDeclVar(): use ParserStatus
Swift SVN r7421
2013-08-21 20:15:01 +00:00
Dmitri Hrybenko
354c5f4a18 Parser: replace diagnose(Tok.getLoc(), ...) -> diagnose(Tok, ...)
We already had the Parser::diagnose(Token, ...) overload, but it was not used
in all these cases.


Swift SVN r7395
2013-08-21 00:26:30 +00:00
Dmitri Hrybenko
c098cd1476 Parser: convert some pattern parsing functions to ParserResult
Swift SVN r7336
2013-08-19 22:38:34 +00:00
Dmitri Hrybenko
19a90b69f7 Parser: add ParserResult<T> -- a wrapper around the AST node plus extra bits
This allows the parser to recover, create an AST node, return it to the caller
*and* signal the caller that there was an error to trigger recovery in the
caller.  Until now the error was signalled with a nullptr result (any non-null
result was considered a success and no recovery was done in that case).

This also allows us to signal the caller if there was a code completion token
inside the production we tried to parse to trigger delayed parsing in the
caller while doing recovery in the callee.  Until now we could not do recovery
in the callee so that the caller could find the code completion token.

Right now we don't take any advantage of these features.  This commit just
replaces some uses of NullablePtr with ParserResult.


Swift SVN r7332
2013-08-19 22:11:23 +00:00
Dmitri Hrybenko
0fdb8acf09 Parser: don't drop the whole nominal decl from the AST if any member had a
syntax error

Will be tested by code completion.


Swift SVN r7272
2013-08-15 22:33:23 +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
Dmitri Hrybenko
c278805856 Parser: better recovery for statements with omitted controlling expression:
if { ... }  while { ... } for { ... } -- see tests for more.

Fixes rdar://14725151


Swift SVN r7252
2013-08-15 01:39:42 +00:00
Dmitri Hrybenko
536723eca4 Code completion: implement delayed parsing of all (?) declarations
This allows us to show generic parameters in:
struct S<T> {
  func f(a: #^A^#
}

And show the type Z in:
struct S {
  func f(a: #^A^#
  typealias Z = Int
}


Swift SVN r7216
2013-08-13 23:53:39 +00:00
Dmitri Hrybenko
e6a445ca6b Fix comment.
Swift SVN r7209
2013-08-13 21:55:11 +00:00
Dmitri Hrybenko
48faba29f3 Simplify parser constructors
Constructor delegation in parser was useless, because the code was split
between the constructors arbitrarily.

There was no need to pass down IsMainModule because the parser could figure
that out on its own.  Also rename it to allowTopLevelCode() to better describe
what it actually affects.


Swift SVN r7098
2013-08-09 20:43:21 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Dmitri Hrybenko
02cf73dc30 Lexer: remove redundant parameters from the sublexer constructor
Swift SVN r7073
2013-08-09 00:15:01 +00:00
Dmitri Hrybenko
41723aeb30 Code completion: correctly delay parsing of the function body that did not have
a closing brace.

Fixes two bugs:
* delayed parsing was not correctly skipping over the function body because it
  stopped at the 'var' decl;
* parser was not creating a BraceStmt for the function body if it could not
  find the closing brace.


Swift SVN r7062
2013-08-08 22:57:25 +00:00
Dmitri Hrybenko
8c4699fedc Code completion: after delaying a top-level decl, skip the rest of the file to
prevent the parser from constructing the AST for it.  Forward references are
not allowed at the top level.

Resolves all FIXMEs in test/CodeCompletion/complete_at_top_level.swift.


Swift SVN r6829
2013-08-02 01:24:51 +00:00
Joe Groff
ba774364f1 SIL: Have SILModules track their SILStage.
Modules can be in either 'Raw' or 'Canonical' form, with different invariants on each. We don't actually distinguish those invariants yet, but this patch adds the field to SILModule and adds a "sil_stage" declaration to SIL printer/parser syntax.

Swift SVN r6793
2013-08-01 00:58:31 +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
Dmitri Hrybenko
5142210a3e Code completion: delay parsing of top-level var decls
This allows us to do code completion inside top-lever var initializers.

As a part of implementation, we make sure that error recovery does not
implicitly skip over the code completion token.  This also fixes a bug that
prevented us from doing code completion inside function argument list, added
tests for that.


Swift SVN r6708
2013-07-29 21:31:44 +00:00
Dmitri Hrybenko
c2e05bfcb9 REPL: use new code completion engine from libIDE
Swift SVN r6641
2013-07-26 04:05:28 +00:00
Dmitri Hrybenko
6beee6a62e Code completion: implement delayed parsing and code completion for
TopLevelCodeDecls


Swift SVN r6638
2013-07-26 01:44:23 +00:00
Doug Gregor
109cb0db74 Parse 'static' more permissively, but complain if it isn't used.
Fixes <rdar://problem/14446888>.


Swift SVN r6453
2013-07-22 16:35:57 +00:00
Joe Groff
d956fdbd9e Update 'oneof' syntax.
Give oneof bodies syntax consistent with other NominalTypes. Give oneof elements first-class declaration syntax using the 'case' introducer, as suggested by Jordan. Oneofs can contain 'case' decls, functions, properties, and constructors, but not physical ivars. Non-oneof scopes cannot contain 'case' decls. Add some QoI to the oneof 'case' parser to also parse and complain about things that resemble switch 'case' labels inside decl contexts.

Swift SVN r6211
2013-07-12 20:42:19 +00:00
Dmitri Hrybenko
02084efab7 Implement code completion for some function calls and member variable accesses
in expr-dot and expr-postfix that can be typechecked without typechecking the
beginning of the function body.


Swift SVN r6198
2013-07-12 02:00:41 +00:00
Doug Gregor
a40fdbfd8d Make 'in' a real keyword.
Swift SVN r6129
2013-07-10 21:37:50 +00:00
Doug Gregor
85231a5d16 Remove || closures.
Swift SVN r6119
2013-07-10 17:40:52 +00:00
Joe Groff
f7ad75fc7d AST: Remove unneeded implicit subject var from SwitchStmts.
Our implementation no longer requires an implicit representation of the entire subject value of switches.

Swift SVN r6087
2013-07-09 03:23:49 +00:00
Dmitri Hrybenko
1c0233efb1 Move lib/Parse/{Parser.h, Scope.h} -> include/swift/Parse/
Swift SVN r6062
2013-07-08 20:36:40 +00:00
Joe Groff
ce5eb80c33 Parse: Case blocks matching multiple patterns can't bind variables.
Similarly, "fallthrough" cannot transfer control into a case block that binds variables.

Swift SVN r5907
2013-06-30 19:10:11 +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
675de63208 Parse matching pattern specific productions at top level.
Parse 'var', '_', and 'is' pattern forms at the top level of a matching pattern context. Keep track of VarPatternDepth in the parser state and raise an error if 'var' appears in a 'var'.

Swift SVN r5839
2013-06-27 18:13:01 +00:00
Joe Groff
45a69154bd Parse: Parse switch statements (again).
Reimplement 'switch' parsing for our new AST representation, where cases contain patterns and 'where' guards, case blocks can have multiple cases, and 'default' is constrained to being the lone label of the last block if present. No type-checking or parsing of actual pattern productions yet.

Swift SVN r5834
2013-06-27 05:13:41 +00:00
Joe Groff
10f136f7d3 Parse: Remove 'OtherThanAssignment' from 'parseStmt'.
Assignment isn't a Stmt anymore.

Swift SVN r5832
2013-06-27 05:13:33 +00:00
Dmitri Hrybenko
efffe5c065 Don't add names to non-resolvable scopes
Currently not only we insert names in non-resolvable scopes, but every
overloaded name gets stored only once (the last one wins).  Everything just
happens to work, because we never do name lookup in these scopes.

I also added a ScopeKind to every Scope (instead of just adding the bit --
isResolvableScope), because this provides a better debugging experience, and
centralizes knowledge about what scope kind is resolvable in the function
isResolvableScope(ScopeKind).


Swift SVN r5822
2013-06-26 21:44:11 +00:00
Dmitri Hrybenko
5bc7242fb9 Followup to 5815: rename ParserState to ParserPosition. Missed a function and
a variable that used the word 'State'.


Swift SVN r5818
2013-06-26 18:20:16 +00:00
Dmitri Hrybenko
6eedf59e32 Rename ParserState to ParserPosition. A facility to restore parser *state*
(for example, the scope stack) will be added soon.


Swift SVN r5817
2013-06-26 18:04:58 +00:00
Joe Groff
a7db082ee9 Parse: Re-allow '_' in foreach statement patterns.
Missed a spot. Add a test for 'for _ in seq'.

Swift SVN r5814
2013-06-26 17:20:06 +00:00
Chris Lattner
71be5c9c60 fallthrough is a control flow transfer too.
Swift SVN r5810
2013-06-26 04:37:59 +00:00
Chris Lattner
1259e32913 - Update LangRef to mention stmt-break/continue/fallthrough. Factor the stmt
grammar description in LangRef and the parser to expose a new stmt-control-transfer.
- remove obsolete comment in ParseStmt.cpp talking about stmt-brace.

No behavior change.


Swift SVN r5809
2013-06-26 04:31:28 +00:00
Joe Groff
8deec52b17 Rework AST representation of CaseStmts.
A single case block can have one or more 'case ...:' labels. 'case' labels contain patterns instead of exprs. 'default:' is a funny spelling for 'case _:'. Change the CaseStmt representation and rip out all the parsing, type-checking, and SILGen built off the old representation.

Swift SVN r5795
2013-06-25 00:31:42 +00:00
Dmitri Hrybenko
a2ddd4e488 Refactor lexer backtracking. Introduce opaque types that encapsulate lexer and
parser state.  Backtracking will be used a lot when we implement delayed
parsing for function bodies, and we don't want to leak lexer and parser state
details to AST classes when we store the state for the first and last token for
the function body.


Swift SVN r5759
2013-06-21 22:26:41 +00:00
Doug Gregor
fad5c78484 Remove expr-func from the syntax of the language.
FuncExpr still lives on as the implementation mechanism for FuncDecl,
but it's not long for this world.


Swift SVN r5752
2013-06-21 18:54:18 +00:00
Joe Groff
6dcf8ae206 Parse assignments as part of expr-sequence.
Parse '=' as a binary operator with fixed precedence, parsing it into a temporary UnsequencedAssignExpr that gets matched to operands and turned into an AssignExpr during sequence expr folding. This makes '=' behave like library-defined assignment-like binary operators.

This temporarily puts '=' at the wrong precedence relative to 'as' and 'is', until 'as' and 'is' can be integrated into sequence parsing as well.

Swift SVN r5508
2013-06-07 16:15:40 +00:00
Joe Groff
cb1f81db84 Make assignment an expression.
Change AssignStmt into AssignExpr; this will make assignment behave more consistently with assignment-like operators, and is a first step toward integrating '=' parsing with SequenceExpr resolution so that '=' can obey precedence rules. This also nicely simplifies the AST representation of c-style ForStmts; the initializer and increment need only be Expr* instead of awkward Expr*/AssignStmt* unions.

This doesn't actually change any user-visible behavior yet; AssignExpr is still only parsed at statement scope, and typeCheckAssignment is still segregrated from the constraint checker at large. (In particular, a PipeClosureExpr containing a single assign expr in its body still doesn't use the assign expr to resolve its own type.) The parsing issue will be addressed by handling '=' during SequenceExpr resolution. typeCheckAssignment can hopefully be reworked to work within the constraint checker too.

Swift SVN r5500
2013-06-06 22:18:54 +00:00
Jordan Rose
8f845b6bc7 Fix doc comment typo.
Swift SVN r5327
2013-05-25 01:35:00 +00:00
Doug Gregor
c10b1cef65 Allow trailing closures without pipes wherever we don't expect curly braces.
This moves trailing closures from expr-postfix up to the level of
expr, and introduces an intermediate level (expr-basic) for places
that need to parse expressions followed by curly braces, such as
if/while/switch/for. Trailing closures are still restricted to occur
after expr-postfix, although the parser itself parses a slightly more
general and then complains if it got more than an expr-postfix.


Swift SVN r5256
2013-05-21 22:30:25 +00:00
Chris Lattner
b4eee19287 Switch the SIL parse to parse the file in a model similar to "immediate"
mode for normal .swift files.  We basically parse batches of non-sil function
decls, type check them as a batch, then process any SIL functions.  This allows
us to have mutually recursive types and other things that are fully sema'd and
that are referenced by SIL functions, without involving SIL functions too
intimately with type checking.

This does mean that SIL functions can't forward reference types, oh well.



Swift SVN r5243
2013-05-21 03:27:27 +00:00
Doug Gregor
6e64ca66f0 Treat '|' as a delimiter while parsing the signature of a closure.
'|' is part of the character set for operators, but within the
signature of a closure we need to treat the first non-nested '|' as
the closing delimiter for the closure parameter list. For example,

  { |x = 1| 2 + x}

parses with the default value of '1' for x, with the body 2 + x. If
the '|' operator is needed in the default value, it can be wrapped in
parentheses:

  { |x = (1|2)| x }

Note that we have problems with both name binding and type checking
for default values in closures (<rdar://problem/13372694>), so they
aren't actually enabled. However, this allows us to parse them and
recover better in their presence.



Swift SVN r5202
2013-05-17 16:02:44 +00:00
Chris Lattner
bde8f753da wire up minimal sil function parsing (still not validating or creating
a SIL function).  This introduces contextual lexing state for SIL function 
bodies for SIL-specific lexing rules.


Swift SVN r5179
2013-05-16 18:46:46 +00:00
Chris Lattner
15f40068d4 remove stmt-brace. If you need something like it for scoping purposes, you can always use "if true {}".
Swift SVN r5034
2013-05-03 05:59:27 +00:00
Doug Gregor
e27deb1494 Remove the least liked of the message-send syntaxes, e.g.,
foo.bar(1) wibble(true)

because it is ridiculously ambiguous.


Swift SVN r4996
2013-04-30 17:05:33 +00:00
Jordan Rose
790248d8b4 Diagnostics: use builder pattern instead of streaming for ranges/fix-its.
Per Chris's feedback and suggestions on the verbose fix-it API, convert
diagnostics over to using the builder pattern instead of Clang's streaming
pattern (<<) for fix-its and ranges. Ranges are included because
otherwise it's syntactically difficult to add a fix-it after a range.

New syntax:

  diagnose(Loc, diag::warn_problem)
    .highlight(E->getRange())
    .fixItRemove(E->getLHS()->getRange())
    .fixItInsert(E->getRHS()->getLoc(), "&")
    .fixItReplace(E->getOp()->getRange(), "++");

These builder functions only exist on InFlightDiagnostic; while you can
still modify a plain Diagnostic, you have to do it with plain accessors
and a raw DiagnosticInfo::FixIt.

Swift SVN r4894
2013-04-24 23:15:53 +00:00