Skip to content

Commit 39c622f

Browse files
committed
[Diagnostics] Make sure the code builds without the new Swift parser
1 parent bdf1183 commit 39c622f

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

lib/Frontend/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ target_link_libraries(swiftFrontend PRIVATE
3333
swiftSymbolGraphGen)
3434

3535
set_swift_llvm_is_available(swiftFrontend)
36+
37+
if (SWIFT_SWIFT_PARSER)
38+
target_compile_definitions(swiftFrontend
39+
PRIVATE
40+
SWIFT_SWIFT_PARSER
41+
)
42+
endif()

lib/Frontend/PrintingDiagnosticConsumer.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ static void annotateSnippetWithInfo(SourceManager &SM,
952952
}
953953
}
954954

955+
#if SWIFT_SWIFT_PARSER
955956
/// Enqueue a diagnostic with ASTGen's diagnostic rendering.
956957
static void enqueueDiagnostic(
957958
void *queuedDiagnostics, const DiagnosticInfo &info, SourceManager &SM
@@ -988,6 +989,7 @@ static void enqueueDiagnostic(
988989

989990
// FIXME: Need a way to add highlights, Fix-Its, and so on.
990991
}
992+
#endif
991993

992994
// MARK: Main DiagnosticConsumer entrypoint.
993995
void PrintingDiagnosticConsumer::handleDiagnostic(SourceManager &SM,
@@ -1003,27 +1005,8 @@ void PrintingDiagnosticConsumer::handleDiagnostic(SourceManager &SM,
10031005
return;
10041006

10051007
switch (FormattingStyle) {
1006-
case DiagnosticOptions::FormattingStyle::Swift:
1007-
if (Info.Kind == DiagnosticKind::Note && currentSnippet) {
1008-
// If this is a note and we have an in-flight message, add it to that
1009-
// instead of emitting it separately.
1010-
annotateSnippetWithInfo(SM, Info, *currentSnippet);
1011-
} else {
1012-
// If we encounter a new error/warning/remark, flush any in-flight
1013-
// snippets.
1014-
flush(/*includeTrailingBreak*/ true);
1015-
currentSnippet = std::make_unique<AnnotatedSourceSnippet>(SM);
1016-
annotateSnippetWithInfo(SM, Info, *currentSnippet);
1017-
}
1018-
if (PrintEducationalNotes) {
1019-
for (auto path : Info.EducationalNotePaths) {
1020-
if (auto buffer = SM.getFileSystem()->getBufferForFile(path))
1021-
BufferedEducationalNotes.push_back(buffer->get()->getBuffer().str());
1022-
}
1023-
}
1024-
break;
1025-
10261008
case DiagnosticOptions::FormattingStyle::SwiftSyntax: {
1009+
#if SWIFT_SWIFT_PARSER
10271010
if (Info.Loc.isValid()) {
10281011
// Ignore "in macro expansion" diagnostics; we want to put them
10291012
// elsewhere.
@@ -1057,9 +1040,30 @@ void PrintingDiagnosticConsumer::handleDiagnostic(SourceManager &SM,
10571040
// Fall through to print using the LLVM style when there is no source
10581041
// location.
10591042
flush(/*includeTrailingBreak*/ false);
1043+
#endif
10601044
LLVM_FALLTHROUGH;
10611045
}
10621046

1047+
case DiagnosticOptions::FormattingStyle::Swift:
1048+
if (Info.Kind == DiagnosticKind::Note && currentSnippet) {
1049+
// If this is a note and we have an in-flight message, add it to that
1050+
// instead of emitting it separately.
1051+
annotateSnippetWithInfo(SM, Info, *currentSnippet);
1052+
} else {
1053+
// If we encounter a new error/warning/remark, flush any in-flight
1054+
// snippets.
1055+
flush(/*includeTrailingBreak*/ true);
1056+
currentSnippet = std::make_unique<AnnotatedSourceSnippet>(SM);
1057+
annotateSnippetWithInfo(SM, Info, *currentSnippet);
1058+
}
1059+
if (PrintEducationalNotes) {
1060+
for (auto path : Info.EducationalNotePaths) {
1061+
if (auto buffer = SM.getFileSystem()->getBufferForFile(path))
1062+
BufferedEducationalNotes.push_back(buffer->get()->getBuffer().str());
1063+
}
1064+
}
1065+
break;
1066+
10631067
case DiagnosticOptions::FormattingStyle::LLVM:
10641068
printDiagnostic(SM, Info);
10651069

@@ -1095,6 +1099,7 @@ void PrintingDiagnosticConsumer::flush(bool includeTrailingBreak) {
10951099
currentSnippet.reset();
10961100
}
10971101

1102+
#if SWIFT_SWIFT_PARSER
10981103
if (queuedDiagnostics) {
10991104
Stream << "=== " << queuedBufferName << " ===\n";
11001105

@@ -1113,6 +1118,7 @@ void PrintingDiagnosticConsumer::flush(bool includeTrailingBreak) {
11131118
if (includeTrailingBreak)
11141119
Stream << "\n";
11151120
}
1121+
#endif
11161122

11171123
for (auto note : BufferedEducationalNotes) {
11181124
printMarkdown(note, Stream, ForceColors);

0 commit comments

Comments
 (0)