Skip to content

Commit 1c2ac8e

Browse files
committed
Parse: Parse entire top level in one shot
1 parent 72018db commit 1c2ac8e

File tree

4 files changed

+6
-24
lines changed

4 files changed

+6
-24
lines changed

lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ bool Parser::isTerminatorForBraceItemListKind(BraceItemListKind Kind,
202202
ArrayRef<ASTNode> ParsedDecls) {
203203
switch (Kind) {
204204
case BraceItemListKind::Brace:
205+
case BraceItemListKind::TopLevelCode:
206+
case BraceItemListKind::TopLevelLibrary:
205207
return false;
206208
case BraceItemListKind::Case: {
207209
if (Tok.is(tok::pound_if)) {
@@ -220,26 +222,6 @@ bool Parser::isTerminatorForBraceItemListKind(BraceItemListKind Kind,
220222
}
221223
return isAtStartOfSwitchCase(*this);
222224
}
223-
case BraceItemListKind::TopLevelCode:
224-
// When parsing the top level executable code for a module, if we parsed
225-
// some executable code, then we're done. We want to process (name bind,
226-
// type check, etc) decls one at a time to make sure that there are not
227-
// forward type references, etc. There is an outer loop around the parser
228-
// that will reinvoke the parser at the top level on each statement until
229-
// EOF. In contrast, it is ok to have forward references between classes,
230-
// functions, etc.
231-
for (auto I : ParsedDecls) {
232-
if (isa<TopLevelCodeDecl>(I.get<Decl*>()))
233-
// Only bail out if the next token is at the start of a line. If we
234-
// don't, then we may accidentally allow things like "a = 1 b = 4".
235-
// FIXME: This is really dubious. This will reject some things, but
236-
// allow other things we don't want.
237-
if (Tok.isAtStartOfLine())
238-
return true;
239-
}
240-
return false;
241-
case BraceItemListKind::TopLevelLibrary:
242-
return false;
243225
case BraceItemListKind::ActiveConditionalBlock:
244226
case BraceItemListKind::InactiveConditionalBlock:
245227
return Tok.isNot(tok::pound_else) && Tok.isNot(tok::pound_endif) &&

test/Parse/confusables.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
let number Int // expected-note {{operator '⁚' contains possibly confused characters; did you mean to use ':'?}} {{11-14=:}}
88

99
// expected-warning @+3 2 {{integer literal is unused}}
10-
// expected-error @+2 2 {{invalid character in source file}}
10+
// expected-error @+2 {{invalid character in source file}}
1111
// expected-error @+1 {{consecutive statements on a line must be separated by ';'}}
12-
55 // expected-note 2 {{unicode character '‒' looks similar to '-'; did you mean to use '-'?}} {{3-6=-}}
12+
55 // expected-note {{unicode character '‒' looks similar to '-'; did you mean to use '-'?}} {{3-6=-}}
1313

1414
// expected-error @+2 {{use of unresolved identifier 'ꝸꝸꝸ'}}
1515
// expected-error @+1 {{expected ',' separator}}

test/Parse/identifiers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func s̈pin̈al_tap̈() {}
2626
() // expected-error{{invalid character in source file}} {{1-4= }}
2727

2828
// Placeholders are recognized as identifiers but with error.
29-
func <#some name#>() {} // expected-error 2 {{editor placeholder in source file}}
29+
func <#some name#>() {} // expected-error {{editor placeholder in source file}}
3030

3131
// Keywords as identifiers
3232
class switch {} // expected-error {{keyword 'switch' cannot be used as an identifier here}} expected-note {{if this name is unavoidable, use backticks to escape it}} {{7-13=`switch`}}

test/Parse/recovery.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ let curlyQuotes2 = “hello world!"
754754

755755

756756
// <rdar://problem/21196171> compiler should recover better from "unicode Specials" characters
757-
let tryx = 123 // expected-error 2 {{invalid character in source file}} {{5-8= }}
757+
let tryx = 123 // expected-error {{invalid character in source file}} {{5-8= }}
758758

759759

760760
// <rdar://problem/21369926> Malformed Swift Enums crash playground service

0 commit comments

Comments
 (0)