Skip to content

Commit 0a03259

Browse files
committed
Parser: disable lexer diagnostics during delayed parsing.
The lexer diagnostics have already been emitted during token skipping.
1 parent b02c7b1 commit 0a03259

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

include/swift/Parse/Parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ class Parser {
346346
SyntaxParsingContext *SyntaxContext;
347347

348348
public:
349+
Parser(unsigned BufferID, SourceFile &SF, DiagnosticEngine* LexerDiags,
350+
SILParserTUStateBase *SIL,
351+
PersistentParserState *PersistentState);
349352
Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
350353
PersistentParserState *PersistentState = nullptr);
351354
Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,

lib/Parse/ParseDecl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ void PersistentParserState::parseMembers(IterableDeclContext *IDC) {
192192
// the PersistentParserState will be used to continuously parse the rest of
193193
// the file linearly.
194194
llvm::SaveAndRestore<ParserPosition> Pos(MarkedPos, ParserPosition());
195-
Parser TheParser(BufferID, SF, nullptr, this);
195+
196+
// Lexer diaganostics have been emitted during skipping, so we disable lexer's
197+
// diagnostic engine here.
198+
Parser TheParser(BufferID, SF, /*No Lexer Diags*/nullptr, nullptr, this);
196199
// Disable libSyntax creation in the delayed parsing.
197200
TheParser.SyntaxContext->disable();
198201
TheParser.parseDeclListDelayed(IDC);
@@ -2292,7 +2295,8 @@ static unsigned skipUntilMatchingRBrace(Parser &P, bool &HasPoundDirective,
22922295
SyntaxParsingContext BodyContext(SyntaxContext, SyntaxKind::TokenList);
22932296
unsigned OpenBraces = 1;
22942297
while (OpenBraces != 0 && P.Tok.isNot(tok::eof)) {
2295-
HasPoundDirective |= P.Tok.isAny(tok::pound_sourceLocation, tok::pound_line);
2298+
HasPoundDirective |= P.Tok.isAny(tok::pound_sourceLocation, tok::pound_line,
2299+
tok::pound_if, tok::pound_else, tok::pound_endif, tok::pound_elseif);
22962300
if (P.consumeIf(tok::l_brace)) {
22972301
OpenBraces++;
22982302
continue;

lib/Parse/Parser.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,18 @@ swift::tokenizeWithTrivia(const LangOptions &LangOpts, const SourceManager &SM,
331331
// Setup and Helper Methods
332332
//===----------------------------------------------------------------------===//
333333

334+
334335
Parser::Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
335336
PersistentParserState *PersistentState)
337+
: Parser(BufferID, SF, &SF.getASTContext().Diags, SIL, PersistentState) {}
338+
339+
Parser::Parser(unsigned BufferID, SourceFile &SF, DiagnosticEngine* LexerDiags,
340+
SILParserTUStateBase *SIL,
341+
PersistentParserState *PersistentState)
336342
: Parser(
337343
std::unique_ptr<Lexer>(new Lexer(
338344
SF.getASTContext().LangOpts, SF.getASTContext().SourceMgr,
339-
BufferID, &SF.getASTContext().Diags,
345+
BufferID, LexerDiags,
340346
/*InSILMode=*/SIL != nullptr,
341347
SF.Kind == SourceFileKind::Main
342348
? HashbangMode::Allowed

0 commit comments

Comments
 (0)