@@ -209,7 +209,9 @@ extern "C" void swift_ASTGen_buildTopLevelASTNodes(void *sourceFile,
209
209
void Parser::parseTopLevelItems (SmallVectorImpl<ASTNode> &items) {
210
210
#if SWIFT_SWIFT_PARSER
211
211
Optional<DiagnosticTransaction> existingParsingTransaction;
212
- parseSourceFileViaASTGen (items, existingParsingTransaction);
212
+ if (!SF.getParsingOptions ()
213
+ .contains (SourceFile::ParsingFlags::DisableSwiftParserASTGen))
214
+ parseSourceFileViaASTGen (items, existingParsingTransaction);
213
215
#endif
214
216
215
217
// Prime the lexer.
@@ -259,36 +261,39 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
259
261
}
260
262
261
263
#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
+ }
292
297
}
293
298
}
294
299
#endif
0 commit comments