Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions include/swift/DependencyScan/DependencyScanningTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ class DependencyScannerDiagnosticCollectingConsumer : public DiagnosticConsumer

void handleDiagnostic(SourceManager &SM,
const DiagnosticInfo &Info) override;
ScannerDiagnosticInfo convertDiagnosticInfo(SourceManager &SM,
const DiagnosticInfo &Info);
void addDiagnostic(SourceManager &SM, const DiagnosticInfo &Info);
std::vector<ScannerDiagnosticInfo> Diagnostics;
// FIXME: For now, we isolate access to shared state of this object
// but we really should make sure that it doesn't get shared.
llvm::sys::SmartMutex<true> ScanningDiagnosticConsumerStateLock;
};


Expand Down Expand Up @@ -91,8 +92,8 @@ class DependencyScanningTool {
bool loadCache(llvm::StringRef path);
/// Discard the tool's current `SharedCache` and start anew.
void resetCache();

const std::vector<DependencyScannerDiagnosticCollectingConsumer::ScannerDiagnosticInfo>& getDiagnostics() const { return CDC.Diagnostics; }
/// Query diagnostics consumed so far.
std::vector<DependencyScannerDiagnosticCollectingConsumer::ScannerDiagnosticInfo> getDiagnostics();
/// Discared the collection of diagnostics encountered so far.
void resetDiagnostics();

Expand Down
8 changes: 8 additions & 0 deletions lib/DependencyScan/DependencyScanningTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void DependencyScannerDiagnosticCollectingConsumer::handleDiagnostic(SourceManag
}

void DependencyScannerDiagnosticCollectingConsumer::addDiagnostic(SourceManager &SM, const DiagnosticInfo &Info) {
llvm::sys::SmartScopedLock<true> Lock(ScanningDiagnosticConsumerStateLock);
// Determine what kind of diagnostic we're emitting.
llvm::SourceMgr::DiagKind SMKind;
switch (Info.Kind) {
Expand Down Expand Up @@ -219,6 +220,13 @@ void DependencyScanningTool::resetCache() {
ScanningService.reset(new SwiftDependencyScanningService());
}

std::vector<
DependencyScannerDiagnosticCollectingConsumer::ScannerDiagnosticInfo>
DependencyScanningTool::getDiagnostics() {
llvm::sys::SmartScopedLock<true> Lock(DependencyScanningToolStateLock);
return CDC.Diagnostics;
}

void DependencyScanningTool::resetDiagnostics() {
llvm::sys::SmartScopedLock<true> Lock(DependencyScanningToolStateLock);
CDC.reset();
Expand Down
7 changes: 4 additions & 3 deletions tools/libSwiftScan/libSwiftScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,15 @@ swiftscan_compiler_supported_features_query() {
swiftscan_diagnostic_set_t*
swiftscan_scanner_diagnostics_query(swiftscan_scanner_t scanner) {
DependencyScanningTool *ScanningTool = unwrap(scanner);
auto NumDiagnostics = ScanningTool->getDiagnostics().size();

auto Diagnostics = ScanningTool->getDiagnostics();
auto NumDiagnostics = Diagnostics.size();

swiftscan_diagnostic_set_t *Result = new swiftscan_diagnostic_set_t;
Result->count = NumDiagnostics;
Result->diagnostics = new swiftscan_diagnostic_info_t[NumDiagnostics];

for (size_t i = 0; i < NumDiagnostics; ++i) {
const auto &Diagnostic = ScanningTool->getDiagnostics()[i];
const auto &Diagnostic = Diagnostics[i];
swiftscan_diagnostic_info_s *DiagnosticInfo = new swiftscan_diagnostic_info_s;
DiagnosticInfo->message = swift::c_string_utils::create_clone(Diagnostic.Message.c_str());
switch (Diagnostic.Severity) {
Expand Down