Skip to content

Commit 39746a9

Browse files
committed
[Parse] Inline skipExtraTopLevelRBraces()
Removed from 'parseTopLevel()'. There's no particular reason to diagnose it in 'parseTopLevel()'.
1 parent 62ac618 commit 39746a9

File tree

4 files changed

+9
-25
lines changed

4 files changed

+9
-25
lines changed

include/swift/Parse/Parser.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,6 @@ class Parser {
710710
/// Options that control the parsing of declarations.
711711
typedef OptionSet<ParseDeclFlags> ParseDeclOptions;
712712

713-
/// Skips the current token if it is '}', and emits a diagnostic.
714-
///
715-
/// \returns true if any tokens were skipped.
716-
bool skipExtraTopLevelRBraces();
717-
718713
void delayParseFromBeginningToHere(ParserPosition BeginParserPosition,
719714
ParseDeclOptions Flags);
720715
void consumeDecl(ParserPosition BeginParserPosition, ParseDeclOptions Flags,

lib/Parse/ParseDecl.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ bool Parser::parseTopLevel() {
196196
// Parse the body of the file.
197197
SmallVector<ASTNode, 128> Items;
198198

199-
skipExtraTopLevelRBraces();
200-
201199
// If we are in SIL mode, and if the first token is the start of a sil
202200
// declaration, parse that one SIL function and return to the top level. This
203201
// allows type declarations and other things to be parsed, name bound, and
@@ -280,19 +278,6 @@ bool Parser::parseTopLevel() {
280278
return FoundTopLevelCodeToExecute;
281279
}
282280

283-
bool Parser::skipExtraTopLevelRBraces() {
284-
if (!Tok.is(tok::r_brace))
285-
return false;
286-
while (Tok.is(tok::r_brace)) {
287-
diagnose(Tok, diag::extra_rbrace)
288-
.fixItRemove(Tok.getLoc());
289-
consumeToken();
290-
}
291-
return true;
292-
}
293-
294-
295-
296281
static Optional<StringRef>
297282
getStringLiteralIfNotInterpolated(Parser &P, SourceLoc Loc, const Token &Tok,
298283
StringRef DiagText) {

lib/Parse/ParseStmt.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ ParserStatus Parser::parseBraceItems(SmallVectorImpl<ASTNode> &Entries,
247247
ParserStatus BraceItemsStatus;
248248

249249
bool PreviousHadSemi = true;
250-
while ((Kind == BraceItemListKind::TopLevelLibrary ||
251-
Tok.isNot(tok::r_brace)) &&
250+
while ((IsTopLevel || Tok.isNot(tok::r_brace)) &&
252251
Tok.isNot(tok::pound_endif) &&
253252
Tok.isNot(tok::pound_elseif) &&
254253
Tok.isNot(tok::pound_else) &&
@@ -265,9 +264,13 @@ ParserStatus Parser::parseBraceItems(SmallVectorImpl<ASTNode> &Entries,
265264

266265
SyntaxParsingContext StmtContext(SyntaxContext, SyntaxContextKind::Stmt);
267266

268-
if (Kind == BraceItemListKind::TopLevelLibrary &&
269-
skipExtraTopLevelRBraces())
267+
if (Tok.is(tok::r_brace)) {
268+
assert(IsTopLevel);
269+
diagnose(Tok, diag::extra_rbrace)
270+
.fixItRemove(Tok.getLoc());
271+
consumeToken();
270272
continue;
273+
}
271274

272275
// Eat invalid tokens instead of allowing them to produce downstream errors.
273276
if (consumeIf(tok::unknown))

test/Parse/ConditionalCompilation/pound-if-top-level-3.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
#if arch(x86_64)
44
// expected-error@+2{{expected '{' in protocol type}}
5-
// expected-error@+1{{expected #else or #endif at end of conditional compilation block}}
5+
// expected-error@+1{{extraneous '}' at top level}}
66
public protocol CS}
7+
// expected-error@+1{{expected #else or #endif at end of conditional compilation block}}

0 commit comments

Comments
 (0)