Commit Graph

784 Commits

Author SHA1 Message Date
Dmitri Hrybenko
f24063da4e Parser: don't try to parse the expression after 'return' if we see the
beginning of decl (we used to only check for the beginning of statement).
This is going to be a parse error anyway.


Swift SVN r8003
2013-09-06 21:24:28 +00:00
Dmitri Hrybenko
b38d8e38b8 Code completion: basic completion inside closures
This does not mean that it works well, we just don't crash like we used to.


Swift SVN r7889
2013-09-04 01:31:20 +00:00
Dmitri Hrybenko
dfec888b1c Parser: build AST for 'for <expr>; {}' and improve partial type checking of
function bodies

Allows us to fix a few FIXMEs in code completion.


Swift SVN r7883
2013-09-04 00:23:20 +00:00
Dmitri Hrybenko
d24a5d7aa4 Improve recovery in parsing the c-style for statement
Allows code completion to see declarations in the init part of the for
statement.


Swift SVN r7878
2013-09-03 23:10:13 +00:00
Dmitri Hrybenko
47629bf856 Revert unintended change
Swift SVN r7825
2013-08-31 01:58:05 +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
47f529d8a4 Fix variable name case. The rest of the file seems consistent.
Swift SVN r7755
2013-08-29 22:22:34 +00:00
Dmitri Hrybenko
ddfa9bc8d8 Parser::skip*() routines: don't stop on code completion token anymore
Our recovery is better now, and we don't skip that much.  Actually, even if we
would stop at code completion token during recovery, completion results would
be something very generic anyway (because there is no interesting parser state
to observe), and these results can be produced as a fallback separately (not
implemented).


Swift SVN r7754
2013-08-29 22:15:12 +00:00
Dmitri Hrybenko
d98408425e Remove unused OwningPtr.h includes
Swift is C++11 and uses std::unique_ptr.


Swift SVN r7731
2013-08-29 20:09:49 +00:00
Dmitri Hrybenko
cfe695166a Parser: if we parsed a bare closure as an expression, it will be a discarded
value expression and the type checker will complain anyway.

Instead, recover by unwrapping the BraceStmt that is contained inside, and
produce a specialized diagnostic.


Swift SVN r7680
2013-08-28 19:37:51 +00:00
Dmitri Hrybenko
9447f6c73f parseBraceItems(): don't skip over braced lists of statements during recovery
This increases the amount of noise in diagnostics.  But we did not get these
diagnostics before because we were just skipping these brace statements.  We
shoud improve recovery in parsing of whatever declaration that precedes the
brace statement so that it is picked up as a body of that declaration.


Swift SVN r7679
2013-08-28 19:33:43 +00:00
Dmitri Hrybenko
dd1c2f7477 Parser: consume tok::code_complete where it is handled
We did not consume it before because parseBraceItems() relied on seeing it to
do delayed parsing.


Swift SVN r7648
2013-08-27 23:48:54 +00:00
Dmitri Hrybenko
567d120803 parseStmtIf(): Actually propagate error bits from condition.
Swift SVN r7645
2013-08-27 23:04:25 +00:00
Dmitri Hrybenko
15a4a10cfe parseStmtIf(): propagate error bits correctly
This decreases noise in diagnostics.


Swift SVN r7644
2013-08-27 22:59:52 +00:00
Dmitri Hrybenko
db44574605 parseBraceItemList(): use ParserResult
Now we propagate error bits better, which decreases noise in diagnostics in one
case.


Swift SVN r7628
2013-08-27 19:01:15 +00:00
Dmitri Hrybenko
d07a5e82cc parseStmtCase(): use ParserResult
Swift SVN r7620
2013-08-27 02:09:08 +00:00
Dmitri Hrybenko
c3c5d7d5f3 parseStmt(): use ParserResult
Swift SVN r7617
2013-08-27 01:08:02 +00:00
Dmitri Hrybenko
14f6b67797 Correctly propagate code completion bits from parseExprPostfix() during the
first parsing pass.  This allows us to remove a workaround in parseBraceItems()
that directly looks at the current token.


Swift SVN r7616
2013-08-27 01:06:48 +00:00
Dmitri Hrybenko
78d2f03a8d parseStmtSwitch(): use ParserResult
Swift SVN r7614
2013-08-27 00:48:24 +00:00
Dmitri Hrybenko
cadc9016c5 parseExprOrStmt(): use ParserStatus
Swift SVN r7613
2013-08-27 00:41:37 +00:00
Dmitri Hrybenko
e1d39e5052 parseStmtFor(): use ParserResult
Swift SVN r7612
2013-08-27 00:20:29 +00:00
Dmitri Hrybenko
09ad614035 parseStmtDoWhile(): use ParserResult
Swift SVN r7608
2013-08-26 23:43:09 +00:00
Dmitri Hrybenko
a9f56c4839 parseStmtWhile(): use ParserResult
Swift SVN r7606
2013-08-26 23:38:52 +00:00
Dmitri Hrybenko
45c46314ab parseStmtIf(): use ParserResult
Swift SVN r7605
2013-08-26 23:33:32 +00:00
Dmitri Hrybenko
c6f0dd106d parseStmtReturn(): use ParserResult
This caught a bug in parseExprPostfix(): it did not return a code completion
status.


Swift SVN r7603
2013-08-26 23:18:51 +00:00
Dmitri Hrybenko
a677146247 switch 'case' parsing: don't stop on the first error, leaving the rest of the
switch body not consumed and confusing the rest of the parser

Allows us to complete expressions and types inside 'case'.


Swift SVN r7599
2013-08-26 22:47:43 +00:00
Dmitri Hrybenko
4c210e8d47 Improve error recovery for switch statement
Swift SVN r7595
2013-08-26 21:28:06 +00:00
Dmitri Hrybenko
a56893dec2 parseDecl(): use ParserResult
Now we make the desicion to delay parsing if the parsed production contained a
code completion token, not if we just stopped at the code completion token.


Swift SVN r7442
2013-08-22 00:39:45 +00:00
Dmitri Hrybenko
ec7b2eb3db Parser: use ParserResult in the interface of parseExpr()
But the implementation of expression parsing still does not propagate the code
completion bits because it uses NullablePtr for results.


Swift SVN r7425
2013-08-21 21:10:09 +00:00
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