Commit Graph

784 Commits

Author SHA1 Message Date
Ben Langmuir
b394e35fdd [codecomplete] Add completion of if after else
At some point we stopped completing keywords after `else` in an if
statement. Bring back the completion of `if`, which is the only valid
continuation other than a brace.

rdar://37467474
2018-07-10 11:45:10 -07:00
Alex Hoppen
1b3baf908f [incrParse] Add error nodes to the end of a CodeBlockItem
Creating a new CodeBlockItem meant that when doing an edit in the error
nodes, the prefix gets reused and thus the code is parsed as invalid
although it is not.
2018-05-22 09:07:55 -07:00
Alex Hoppen
e1a99efd57 [incrParse] Fix parsing of nodes covering no source text 2018-05-22 08:52:39 -07:00
Alex Hoppen
de9737c946 [incrParse] Support incremental parsing for edited files 2018-05-22 08:52:33 -07:00
Rintaro Ishizaki
df10afd1a2 [Parse] Discriminate local variables
Set local discriminator for all local `VarDecl`s. Otherwise, they cannot
be discriminated with USRs. This change is needed for rename refactoring which
uses USR for discrimiating variable names.

https://bugs.swift.org/browse/SR-7205,
rdar://problem/34701880
2018-05-11 15:34:42 +09:00
Doug Gregor
1ac8926467 [Parser] Don't lose outer "disabled" variables when checking a guard's "else".
When checking for uses of "disabled" variables within the "else"
statement of a "guard", keep track of the disabled variables from
outer scopes. This is a pattern used everywhere else in the parser,
but got missed here. Fixes SR-7567 / rdar://problem/39868144.
2018-05-04 12:57:24 -07:00
Xi Ge
e8c80878ed Merge pull request #16158 from nkcsgexi/synthesize-node
libSyntax: add a mechanism to synthesize syntax nodes in SyntaxParsingContext.
2018-04-26 11:24:50 -07:00
Xi Ge
a1a6c19959 libSyntax: add a mechanism to synthesize syntax nodes in SyntaxParsingContext.
To enhance the error-recovery of syntax parsing, this patch allows the
parser to synthesize missing nodes to satisfy the requirement of a
syntax node under parsing. As proof-of-concept, we synthesize r-braces
for function body to avoid regressing a function decl to an unknown
decl.
2018-04-26 10:48:57 -07:00
Alex Hoppen
3e9ae802c2 [libSyntax] Make parsing of attribute arguments more structured
This also fixes several issues where attribute arguments could not be
parsed as a TokenList since some of its arguments already had structure
and were not tokens
2018-04-24 13:18:15 -07:00
Rintaro Ishizaki
07fd8b8a4b [Parse] Handle edge case of '@unknown' for switch case
* Previously, hit assertion if '@unknown' has argument clause
* Diagnose multiple '@unknown' for single 'case'
2018-04-12 01:27:40 +09:00
Jordan Rose
701975ad1d Add parsing support for @unknown (SE-0192)
This is our first statement attribute, made more complicated by the
fact that a 'case'/'default' isn't really a normal statement. I've
chosen /not/ to implement a general statement attribute logic like we
have for types and decls at this time, but I did get the compiler
parsing arbitrary attributes before 'case' and 'default'. As a bonus,
we now treat all cases within functions as being switch-like rather
than enum-like, which is better for recovery when not in a switch.
2018-04-05 16:35:14 -07:00
Jordan Rose
f26664b1f1 [AST] Adjust the API of CaseLabelItem for unknown
Get these simple changes out of the way first. No functionality change.
2018-04-04 16:19:11 -07:00
Rintaro Ishizaki
4488e99a04 [Syntax] Parse 'switch' statement 2018-03-28 00:30:21 +09:00
Joe Groff
a146361389 SIL: Fix parse issues with sil_property declarations
- Properly detect the sil_property token at toplevel
- Avoid dereferencing null GenericEnvironment if property declaration has no generic environment
2018-03-22 13:58:52 -07:00
Harlan
aa1059c9a3 [Syntax] Parse WhileStmtSyntax nodes (#15186) 2018-03-12 17:50:07 -04:00
Rintaro Ishizaki
6c0af2a24f [Syntax] Introduce CodeBlockItem (#14458)
CodeBlockItem represents Decl, Stmt or Expr that optionally followed by
semi-colon.
SourceFile syntax holds a list of CodeBlockItem.
2018-02-08 10:31:01 +09:00
Harlan
5e02d2a877 Implement #warning and #error (#14048)
* Implement #warning and #error

* Fix #warning/#error in switch statements

* Fix AST printing for #warning/#error

* Add to test case

* Add extra handling to ParseDeclPoundDiagnostic

* fix dumping

* Consume the right paren even in the failure case

* Diagnose extra tokens on the same line after a diagnostic directive
2018-02-03 18:07:05 -05:00
Rintaro Ishizaki
2134f9f768 [Parse] Move SyntaxParsingContext to Parse (#14360)
This is only for the Parser.
Also, this resolves layering violation where libAST and libSyntax
depends on each other.
2018-02-03 10:43:52 +09:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Rintaro Ishizaki
39746a9e58 [Parse] Inline skipExtraTopLevelRBraces()
Removed from 'parseTopLevel()'. There's no particular reason to diagnose
it in 'parseTopLevel()'.
2017-12-25 23:32:55 +09:00
Rintaro Ishizaki
62ac618dc6 [Parse] small cleanup in parseBraceItems()
* Reorder 'if ... else if' branches to simplify conditions.
* use 'append()' instead of `for { push_back() }`
2017-12-25 22:48:58 +09:00
Rintaro Ishizaki
1dc6a3f775 [Syntax] Parse "for-in statement" node 2017-12-23 12:20:34 +09:00
Rintaro Ishizaki
1e83ad2cbf [Syntax] Parse "if statement" and "guard statement" nodes 2017-12-23 12:20:34 +09:00
Rintaro Ishizaki
d01f5d1da3 [Syntax] Parse "statement condition" nodes 2017-12-23 12:20:34 +09:00
Rintaro Ishizaki
02769d77c2 [Parse] Factor out StmtConditionElement parsing 2017-12-22 18:28:04 +09:00
Rintaro Ishizaki
cd5fdff9bb [Syntax] Parse "repeat-while statement" syntax node 2017-12-21 17:16:26 +09:00
Rintaro Ishizaki
8830fdda34 [Syntax] Parse "do statement" syntax node 2017-12-21 17:16:03 +09:00
Rintaro Ishizaki
f102636d85 [Syntax] Parse basic statement nodes
* ReturnStmt -> 'return' expr?
* BreakStmt -> 'break' identifier?
* ContinueStmt -> 'continue' identifier?
* FallthroughStmt -> 'fallthrough'
* ThrowStmt -> 'throw' expr
* DeferStmt -> 'defer' code-block
2017-12-21 13:30:55 +09:00
Rintaro Ishizaki
0a401b381c [Syntax] Rewrite SyntaxParsingContext
Read RawSyntaxToken along with Parser::consumeToken()

* Single Lexer pass
* Backtracking support
* Split token support
2017-11-18 15:35:46 +09:00
Harlan Haskins
c074dadebe Parse ReturnStmt Syntax nodes 2017-11-15 16:08:41 -05:00
Xi Ge
0390d452a6 libSyntax: parse function argument syntax node. (#12803)
This commit teaches parser to parse two libSyntax nodes: FunctionCallArgument and
FunctionCallArgumentList. Along with the change, some libSyntax parsing infrastructure changes
as well: (1) parser doesn't directly insert token into the buffer for libSyntax node creation;
instead, when creating a simple libSyntax node like integer literal expression, parser should indicate the location of the last token in the node; (2) implicit libSyntax nodes like empty
statement list must contain a source location indicating where the implicit nodes should appear
(immediately before the token at the given location).
2017-11-07 15:59:00 -08:00
Xi Ge
a448a7371f libSyntax: parse codeblock syntax node. (#12771)
This commit teaches parser to generate code block syntax node. As a support for this, 
SyntaxParsingContext can be created by a single syntax kind, indicating the whole context 
should be parsed into a node of that given syntax. Another change is to bridge created syntax 
node with the given context kind. For instance, if a statement context results into an expression 
node, the expression node will be bridged to a statement by wrapping it with a ExpressionStmt 
node.
2017-11-05 17:37:59 -08:00
Timothy J. Wood
03d6f25c45 Fix crash parsing #available with missing version.
In a multipart #available spec list, don't attempt to look at the SpecResult for the previous part if there wasn't one (a missing version number for example).

Added a test case that asserted before this change.
2017-10-21 12:37:58 -07:00
Rintaro Ishizaki
cd3bf0341e [Parse] Fix crash case in parseStmtForeach 2017-10-01 10:36:08 +09:00
gregomni
ed09da5094 When parsing a statement that expects a brace item list and the "{" isn't where we expect, try to recover by skipping tokens on the same line until we find an open brace, and use that as
the item list if we find it. (While still erroring that we expected a brace on the first bad token.) Improves recovery in general and in SR-5943 in particular.
2017-09-25 07:29:35 -07:00
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Ben Langmuir
05559b1b98 [parse] Remove debug code that snuck into my change 2017-08-18 08:49:25 -07:00
Ben Langmuir
48d191f600 [code-completion] Fix for-loop sequences containing collection syntax
This fixes various issues with getting no code-completion in top-level
code containing array/dictionary sugar, such as:
```
for x in [<HERE>] {}
for x in [1: 2, <HERE>] {}
```

And also removes the index variable from completions inside the sequence
(it was coming through as a local variable with <<error type>>).

rdar://problem/33884082
2017-08-17 14:57:57 -07:00
Rintaro Ishizaki
546aeb2336 [Parse] Remove Parser support for C-style for statement. 2017-08-04 23:27:15 +09:00
Rintaro Ishizaki
07957070cd [CodeComplete] Remove C-style-for specific facilities 2017-08-04 23:25:26 +09:00
Ben Langmuir
e32f9c56c1 Don't throw out AST for if/guard bindings during code-completion
It's hard to type-check `x` in `if let x = foo(), x.` after you throw
out the whole binding.

rdar://problem/32818340
2017-07-27 09:38:57 -07:00
Ben Langmuir
93d22c9ff0 [code-completion] Add a new custom completion context for a for-each sequence
For normal completions it behaves the same as PostfixExprBeginning, but
it provides a hook for clients to provide a custom completion for this
position.  For example, you might want to a x ..< y snippet in this
position.

rdar://problem/29910383
2017-07-19 13:29:36 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
Rintaro Ishizaki
056254be95 [QoI] Add fixit for missing 'else' in guard statement (#10702) 2017-06-30 01:09:29 +09:00
Robert Widmann
d07eb71d9c Merge pull request #9457 from rintaro/parse-ifconfig-switchcase
[Parse] Allow #if to guard switch case clauses
2017-06-28 10:18:37 -07:00
Rintaro Ishizaki
e8cc8b55d8 [Parse] Fix #sourceLocation parsing in Decl position (#10444)
Fixes: https://bugs.swift.org/browse/SR-5242
`#sourceLocation` directive at end of declaration list postion was
rejected.
2017-06-22 12:35:43 +09:00
Rintaro Ishizaki
5d478bdb3b [Parse] Allow #if to guard switch case clauses
Resolves:
https://bugs.swift.org/browse/SR-4196
https://bugs.swift.org/browse/SR-2
2017-06-17 10:03:03 +09:00
Rintaro Ishizaki
c8d717e5f4 [Parse] Cleanup #if directive parsing
Now that, IfConfigDecl holds ASTNode regardless statements position or
declarations postion. We can construct it in single method.
2017-05-16 20:52:46 +09:00
Rintaro Ishizaki
6fa84150c5 [AST] Eliminate IfConfigStmt
Resolves: https://bugs.swift.org/browse/SR-4426

* Make IfConfigDecl be able to hold ASTNodes
* Parse #if as IfConfigDecl
* Stop enclosing toplevel #if into TopLevelCodeDecl.
* Eliminate IfConfigStmt
2017-05-16 12:19:54 +09:00
Rintaro Ishizaki
f1b0285bbc [Parse] Don't Hoist IfConfig{Decl,Stmt} out of IfConfig{Decl,Stmt} 2017-05-16 12:09:56 +09:00