mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
* visiting now happens in a later stage than fetching labels. While fetching a list of entities to be visited is created, and then acted upon in actual extraction. This partially flattens the recursive nature of `fetchLabel` into a loop inside `SwiftVisitor::extract`. Recursion in `fetchLabel` will only happen on labels fetched while naming an entity (calling into `SwiftMangler`). * The choice whether to name a declaration or type has been moved from the translators to `SwiftMangler`. Acting on this choice is contained in `SwiftDispatcher::createLabel`. * The choice whether to emit a body of a declaration has been moved from `DeclTranslator` to the dispatcher. This choice is also contained in `SwiftDispatcher::createLabel`. * The simple functionality of the `LabelStore` has been moved to the `SwiftDispatcher` as well.
32 lines
1.2 KiB
C++
32 lines
1.2 KiB
C++
#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>
|
|
#include <llvm/ADT/SmallString.h>
|
|
#include <llvm/Support/raw_ostream.h>
|
|
#include <string>
|
|
|
|
using namespace codeql;
|
|
|
|
void SwiftDiagnosticsConsumer::handleDiagnostic(swift::SourceManager& sourceManager,
|
|
const swift::DiagnosticInfo& diagInfo) {
|
|
auto message = getDiagMessage(sourceManager, diagInfo);
|
|
DiagnosticsTrap diag{};
|
|
diag.id = trap.createTypedLabel<DiagnosticsTag>();
|
|
diag.kind = translateDiagnosticsKind(diagInfo.Kind);
|
|
diag.text = message;
|
|
trap.emit(diag);
|
|
locationExtractor.attachLocation(sourceManager, diagInfo, diag.id);
|
|
}
|
|
|
|
std::string SwiftDiagnosticsConsumer::getDiagMessage(swift::SourceManager& sourceManager,
|
|
const swift::DiagnosticInfo& diagInfo) {
|
|
llvm::SmallString<256> text;
|
|
llvm::raw_svector_ostream out(text);
|
|
swift::DiagnosticEngine::formatDiagnosticText(out, diagInfo.FormatString, diagInfo.FormatArgs);
|
|
return text.str().str();
|
|
}
|