@@ -209,7 +209,9 @@ extern "C" void swift_ASTGen_buildTopLevelASTNodes(void *sourceFile,
209209void Parser::parseTopLevelItems (SmallVectorImpl<ASTNode> &items) {
210210#if SWIFT_SWIFT_PARSER
211211 Optional<DiagnosticTransaction> existingParsingTransaction;
212- parseSourceFileViaASTGen (items, existingParsingTransaction);
212+ if (!SF.getParsingOptions ()
213+ .contains (SourceFile::ParsingFlags::DisableSwiftParserASTGen))
214+ parseSourceFileViaASTGen (items, existingParsingTransaction);
213215#endif
214216
215217 // Prime the lexer.
@@ -259,36 +261,39 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
259261 }
260262
261263#if SWIFT_SWIFT_PARSER
262- if (existingParsingTransaction)
263- existingParsingTransaction->abort ();
264-
265- // Perform round-trip and/or validation checking.
266- if ((Context.LangOpts .hasFeature (Feature::ParserRoundTrip) ||
267- Context.LangOpts .hasFeature (Feature::ParserValidation)) &&
268- SF.exportedSourceFile ) {
269- if (Context.LangOpts .hasFeature (Feature::ParserRoundTrip) &&
270- swift_ASTGen_roundTripCheck (SF.exportedSourceFile )) {
271- SourceLoc loc;
272- if (auto bufferID = SF.getBufferID ()) {
273- loc = Context.SourceMgr .getLocForBufferStart (*bufferID);
274- }
275- diagnose (loc, diag::parser_round_trip_error);
276- } else if (Context.LangOpts .hasFeature (Feature::ParserValidation) &&
277- !Context.Diags .hadAnyError () &&
278- swift_ASTGen_emitParserDiagnostics (
279- &Context.Diags , SF.exportedSourceFile ,
280- /* emitOnlyErrors=*/ true ,
281- /* downgradePlaceholderErrorsToWarnings=*/
282- Context.LangOpts .Playground ||
283- Context.LangOpts .WarnOnEditorPlaceholder )) {
284- // We might have emitted warnings in the C++ parser but no errors, in
285- // which case we still have `hadAnyError() == false`. To avoid emitting
286- // the same warnings from SwiftParser, only emit errors from SwiftParser
287- SourceLoc loc;
288- if (auto bufferID = SF.getBufferID ()) {
289- loc = Context.SourceMgr .getLocForBufferStart (*bufferID);
290- }
291- diagnose (loc, diag::parser_new_parser_errors);
264+ if (!SF.getParsingOptions ().contains (
265+ SourceFile::ParsingFlags::DisableSwiftParserASTGen)) {
266+ if (existingParsingTransaction)
267+ existingParsingTransaction->abort ();
268+
269+ // Perform round-trip and/or validation checking.
270+ if ((Context.LangOpts .hasFeature (Feature::ParserRoundTrip) ||
271+ Context.LangOpts .hasFeature (Feature::ParserValidation)) &&
272+ SF.exportedSourceFile ) {
273+ if (Context.LangOpts .hasFeature (Feature::ParserRoundTrip) &&
274+ swift_ASTGen_roundTripCheck (SF.exportedSourceFile )) {
275+ SourceLoc loc;
276+ if (auto bufferID = SF.getBufferID ()) {
277+ loc = Context.SourceMgr .getLocForBufferStart (*bufferID);
278+ }
279+ diagnose (loc, diag::parser_round_trip_error);
280+ } else if (Context.LangOpts .hasFeature (Feature::ParserValidation) &&
281+ !Context.Diags .hadAnyError () &&
282+ swift_ASTGen_emitParserDiagnostics (
283+ &Context.Diags , SF.exportedSourceFile ,
284+ /* emitOnlyErrors=*/ true ,
285+ /* downgradePlaceholderErrorsToWarnings=*/
286+ Context.LangOpts .Playground ||
287+ Context.LangOpts .WarnOnEditorPlaceholder )) {
288+ // We might have emitted warnings in the C++ parser but no errors, in
289+ // which case we still have `hadAnyError() == false`. To avoid emitting
290+ // the same warnings from SwiftParser, only emit errors from SwiftParser
291+ SourceLoc loc;
292+ if (auto bufferID = SF.getBufferID ()) {
293+ loc = Context.SourceMgr .getLocForBufferStart (*bufferID);
294+ }
295+ diagnose (loc, diag::parser_new_parser_errors);
296+ }
292297 }
293298 }
294299#endif
0 commit comments