mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Swift: share translateDiagnosticsKind with SwiftDiagnosticsConsumer
This commit is contained in:
23
swift/extractor/infra/SwiftDiagnosticKind.h
Normal file
23
swift/extractor/infra/SwiftDiagnosticKind.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <swift/AST/DiagnosticConsumer.h>
|
||||
|
||||
namespace codeql {
|
||||
|
||||
inline int translateDiagnosticsKind(swift::DiagnosticKind kind) {
|
||||
using Kind = swift::DiagnosticKind;
|
||||
switch (kind) {
|
||||
case Kind::Error:
|
||||
return 1;
|
||||
case Kind::Warning:
|
||||
return 2;
|
||||
case Kind::Note:
|
||||
return 3;
|
||||
case Kind::Remark:
|
||||
return 4;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace codeql
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "swift/extractor/invocation/SwiftDiagnosticsConsumer.h"
|
||||
#include "swift/extractor/trap/generated/TrapEntries.h"
|
||||
#include "swift/extractor/trap/TrapDomain.h"
|
||||
#include "swift/extractor/infra/SwiftDiagnosticKind.h"
|
||||
|
||||
#include <swift/AST/DiagnosticEngine.h>
|
||||
#include <swift/Basic/SourceManager.h>
|
||||
@@ -10,26 +11,12 @@
|
||||
|
||||
using namespace codeql;
|
||||
|
||||
static int diagnosticsKind(const swift::DiagnosticInfo& diagInfo) {
|
||||
switch (diagInfo.Kind) {
|
||||
case swift::DiagnosticKind::Error:
|
||||
return 1;
|
||||
case swift::DiagnosticKind::Warning:
|
||||
return 2;
|
||||
case swift::DiagnosticKind::Note:
|
||||
return 3;
|
||||
case swift::DiagnosticKind::Remark:
|
||||
return 4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SwiftDiagnosticsConsumer::handleDiagnostic(swift::SourceManager& sourceManager,
|
||||
const swift::DiagnosticInfo& diagInfo) {
|
||||
auto message = getDiagMessage(sourceManager, diagInfo);
|
||||
DiagnosticsTrap diag{};
|
||||
diag.id = trap.createLabel<DiagnosticsTag>();
|
||||
diag.kind = diagnosticsKind(diagInfo);
|
||||
diag.kind = translateDiagnosticsKind(diagInfo.Kind);
|
||||
diag.text = message;
|
||||
trap.emit(diag);
|
||||
locationExtractor.attachLocation(sourceManager, diagInfo.Loc, diagInfo.Loc, diag.id);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <swift/AST/GenericParamList.h>
|
||||
#include <swift/AST/ParameterList.h>
|
||||
#include "swift/extractor/infra/SwiftDiagnosticKind.h"
|
||||
|
||||
namespace codeql {
|
||||
namespace {
|
||||
@@ -401,17 +402,6 @@ std::optional<codeql::OpaqueTypeDecl> DeclTranslator::translateOpaqueTypeDecl(
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
static int translateDiagnosticsKind(swift::DiagnosticKind kind) {
|
||||
switch (kind) {
|
||||
case swift::DiagnosticKind::Error:
|
||||
return 1;
|
||||
case swift::DiagnosticKind::Warning:
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
codeql::PoundDiagnosticDecl DeclTranslator::translatePoundDiagnosticDecl(
|
||||
const swift::PoundDiagnosticDecl& decl) {
|
||||
auto entry = createEntry(decl);
|
||||
@@ -419,5 +409,4 @@ codeql::PoundDiagnosticDecl DeclTranslator::translatePoundDiagnosticDecl(
|
||||
entry.message = dispatcher.fetchLabel(decl.getMessage());
|
||||
return entry;
|
||||
}
|
||||
|
||||
} // namespace codeql
|
||||
|
||||
Reference in New Issue
Block a user