[Frontend] Allow additional files for diagnostic verifier

This change adds a frontend flag, -verify-additional-file, which can be used to pass extra files directly to the diagnostic verifier. These files are not otherwise considered to be Swift source files; they are not compiled or even properly parsed.

This feature can be used to verify diagnostics emitted in non-source files, such as in module interfaces or header files.
This commit is contained in:
Brent Royal-Gordon
2020-09-18 17:52:38 -07:00
committed by Alexis Laferrière
parent ba00258c66
commit 5036a55550
7 changed files with 50 additions and 12 deletions

View File

@@ -290,15 +290,31 @@ void CompilerInstance::setupStatsReporter() {
Stats = std::move(Reporter);
}
void CompilerInstance::setupDiagnosticVerifierIfNeeded() {
bool CompilerInstance::setupDiagnosticVerifierIfNeeded() {
auto &diagOpts = Invocation.getDiagnosticOptions();
bool hadError = false;
if (diagOpts.VerifyMode != DiagnosticOptions::NoVerify) {
DiagVerifier = std::make_unique<DiagnosticVerifier>(
SourceMgr, InputSourceCodeBufferIDs,
diagOpts.VerifyMode == DiagnosticOptions::VerifyAndApplyFixes,
diagOpts.VerifyIgnoreUnknown);
for (const auto &filename : diagOpts.AdditionalVerifierFiles) {
auto result = getFileSystem().getBufferForFile(filename);
if (!result) {
Diagnostics.diagnose(SourceLoc(), diag::error_open_input_file,
filename, result.getError().message());
hadError |= true;
}
auto bufferID = SourceMgr.addNewSourceBuffer(std::move(result.get()));
DiagVerifier->appendAdditionalBufferID(bufferID);
}
addDiagnosticConsumer(DiagVerifier.get());
}
return hadError;
}
void CompilerInstance::setupDependencyTrackerIfNeeded() {
@@ -347,7 +363,9 @@ bool CompilerInstance::setup(const CompilerInvocation &Invok) {
return true;
setupStatsReporter();
setupDiagnosticVerifierIfNeeded();
if (setupDiagnosticVerifierIfNeeded())
return true;
return false;
}