@@ -182,6 +182,11 @@ extern "C" void swift_ASTGen_destroySourceFile(void *sourceFile);
182
182
// / round-trip succeeded, non-zero otherwise.
183
183
extern " C" int swift_ASTGen_roundTripCheck (void *sourceFile);
184
184
185
+ // / Emit parser diagnostics for given source file.. Returns non-zero if any
186
+ // / diagnostics were emitted.
187
+ extern " C" int swift_ASTGen_emitParserDiagnostics (
188
+ void *diagEngine, void *sourceFile
189
+ );
185
190
186
191
// Build AST nodes for the top-level entities in the syntax.
187
192
extern " C" void swift_ASTGen_buildTopLevelASTNodes (void *sourceFile,
@@ -203,6 +208,7 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
203
208
if ((Context.LangOpts .hasFeature (Feature::Macros) ||
204
209
Context.LangOpts .hasFeature (Feature::BuiltinMacros) ||
205
210
Context.LangOpts .hasFeature (Feature::ParserRoundTrip) ||
211
+ Context.LangOpts .hasFeature (Feature::ParserValidation) ||
206
212
Context.LangOpts .hasFeature (Feature::ParserASTGen)) &&
207
213
!SourceMgr.hasIDEInspectionTargetBuffer () &&
208
214
SF.Kind != SourceFileKind::SIL) {
@@ -281,16 +287,28 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
281
287
}
282
288
283
289
#if SWIFT_SWIFT_PARSER
284
- // Perform round-trip checking.
285
- if (Context.LangOpts .hasFeature (Feature::ParserRoundTrip) &&
290
+ // Perform round-trip and/or validation checking.
291
+ if ((Context.LangOpts .hasFeature (Feature::ParserRoundTrip) ||
292
+ Context.LangOpts .hasFeature (Feature::ParserValidation)) &&
286
293
SF.exportedSourceFile &&
287
- !L->lexingCutOffOffset () &&
288
- swift_ASTGen_roundTripCheck (SF.exportedSourceFile )) {
289
- SourceLoc loc;
290
- if (auto bufferID = SF.getBufferID ()) {
291
- loc = Context.SourceMgr .getLocForBufferStart (*bufferID);
294
+ !L->lexingCutOffOffset ()) {
295
+ if (Context.LangOpts .hasFeature (Feature::ParserRoundTrip) &&
296
+ swift_ASTGen_roundTripCheck (SF.exportedSourceFile )) {
297
+ SourceLoc loc;
298
+ if (auto bufferID = SF.getBufferID ()) {
299
+ loc = Context.SourceMgr .getLocForBufferStart (*bufferID);
300
+ }
301
+ diagnose (loc, diag::parser_round_trip_error);
302
+ } else if (Context.LangOpts .hasFeature (Feature::ParserValidation) &&
303
+ !Context.Diags .hadAnyError () &&
304
+ swift_ASTGen_emitParserDiagnostics (
305
+ &Context.Diags , SF.exportedSourceFile )) {
306
+ SourceLoc loc;
307
+ if (auto bufferID = SF.getBufferID ()) {
308
+ loc = Context.SourceMgr .getLocForBufferStart (*bufferID);
309
+ }
310
+ diagnose (loc, diag::parser_new_parser_errors);
292
311
}
293
- diagnose (loc, diag::parser_round_trip_error);
294
312
}
295
313
#endif
296
314
}
0 commit comments