Skip to content

Commit 235181f

Browse files
committed
Swift: share translateDiagnosticsKind with SwiftDiagnosticsConsumer
1 parent 7bcee6e commit 235181f

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
#include <swift/AST/DiagnosticConsumer.h>
4+
5+
namespace codeql {
6+
7+
inline int translateDiagnosticsKind(swift::DiagnosticKind kind) {
8+
using Kind = swift::DiagnosticKind;
9+
switch (kind) {
10+
case Kind::Error:
11+
return 1;
12+
case Kind::Warning:
13+
return 2;
14+
case Kind::Note:
15+
return 3;
16+
case Kind::Remark:
17+
return 4;
18+
default:
19+
return 0;
20+
}
21+
}
22+
23+
} // namespace codeql

swift/extractor/invocation/SwiftDiagnosticsConsumer.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "swift/extractor/invocation/SwiftDiagnosticsConsumer.h"
22
#include "swift/extractor/trap/generated/TrapEntries.h"
33
#include "swift/extractor/trap/TrapDomain.h"
4+
#include "swift/extractor/infra/SwiftDiagnosticKind.h"
45

56
#include <swift/AST/DiagnosticEngine.h>
67
#include <swift/Basic/SourceManager.h>
@@ -10,26 +11,12 @@
1011

1112
using namespace codeql;
1213

13-
static int diagnosticsKind(const swift::DiagnosticInfo& diagInfo) {
14-
switch (diagInfo.Kind) {
15-
case swift::DiagnosticKind::Error:
16-
return 1;
17-
case swift::DiagnosticKind::Warning:
18-
return 2;
19-
case swift::DiagnosticKind::Note:
20-
return 3;
21-
case swift::DiagnosticKind::Remark:
22-
return 4;
23-
}
24-
return 0;
25-
}
26-
2714
void SwiftDiagnosticsConsumer::handleDiagnostic(swift::SourceManager& sourceManager,
2815
const swift::DiagnosticInfo& diagInfo) {
2916
auto message = getDiagMessage(sourceManager, diagInfo);
3017
DiagnosticsTrap diag{};
3118
diag.id = trap.createLabel<DiagnosticsTag>();
32-
diag.kind = diagnosticsKind(diagInfo);
19+
diag.kind = translateDiagnosticsKind(diagInfo.Kind);
3320
diag.text = message;
3421
trap.emit(diag);
3522
locationExtractor.attachLocation(sourceManager, diagInfo.Loc, diagInfo.Loc, diag.id);

swift/extractor/translators/DeclTranslator.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <swift/AST/GenericParamList.h>
44
#include <swift/AST/ParameterList.h>
5+
#include "swift/extractor/infra/SwiftDiagnosticKind.h"
56

67
namespace codeql {
78
namespace {
@@ -401,23 +402,11 @@ std::optional<codeql::OpaqueTypeDecl> DeclTranslator::translateOpaqueTypeDecl(
401402
return std::nullopt;
402403
}
403404

404-
static int translateDiagnosticsKind(swift::DiagnosticKind kind) {
405-
switch (kind) {
406-
case swift::DiagnosticKind::Error:
407-
return 1;
408-
case swift::DiagnosticKind::Warning:
409-
return 2;
410-
default:
411-
return 0;
412-
}
413-
}
414-
415405
codeql::PoundDiagnosticDecl DeclTranslator::translatePoundDiagnosticDecl(
416406
const swift::PoundDiagnosticDecl& decl) {
417407
auto entry = createEntry(decl);
418408
entry.kind = translateDiagnosticsKind(decl.getKind());
419409
entry.message = dispatcher.fetchLabel(decl.getMessage());
420410
return entry;
421411
}
422-
423412
} // namespace codeql

0 commit comments

Comments
 (0)