[NFC] Fixup InputFile Convenience Getters

Follow programming guidelines for these getters more closely and have them return a non-owning view of the underlying data instead of relying on callers to take const references to the copy that is returned here.
This commit is contained in:
Robert Widmann
2020-11-12 12:43:43 -08:00
parent a89f8e04d6
commit 76d25e7097
4 changed files with 27 additions and 23 deletions

View File

@@ -121,17 +121,17 @@ public:
// FrontendInputsAndOutputs. They merely make the call sites // FrontendInputsAndOutputs. They merely make the call sites
// a bit shorter. Add more forwarding methods as needed. // a bit shorter. Add more forwarding methods as needed.
std::string dependenciesFilePath() const { StringRef getDependenciesFilePath() const {
return getPrimarySpecificPaths().SupplementaryOutputs.DependenciesFilePath; return getPrimarySpecificPaths().SupplementaryOutputs.DependenciesFilePath;
} }
std::string loadedModuleTracePath() const { StringRef getLoadedModuleTracePath() const {
return getPrimarySpecificPaths().SupplementaryOutputs.LoadedModuleTracePath; return getPrimarySpecificPaths().SupplementaryOutputs.LoadedModuleTracePath;
} }
std::string serializedDiagnosticsPath() const { StringRef getSerializedDiagnosticsPath() const {
return getPrimarySpecificPaths().SupplementaryOutputs return getPrimarySpecificPaths().SupplementaryOutputs
.SerializedDiagnosticsPath; .SerializedDiagnosticsPath;
} }
std::string fixItsOutputPath() const { StringRef getFixItsOutputPath() const {
return getPrimarySpecificPaths().SupplementaryOutputs.FixItsOutputPath; return getPrimarySpecificPaths().SupplementaryOutputs.FixItsOutputPath;
} }
}; };

View File

@@ -127,7 +127,7 @@ getFileOutputStream(StringRef OutputFilename, ASTContext &Ctx) {
} }
/// Writes the Syntax tree to the given file /// Writes the Syntax tree to the given file
static bool emitSyntax(SourceFile &SF, StringRef OutputFilename) { static bool emitSyntax(const SourceFile &SF, StringRef OutputFilename) {
auto os = getFileOutputStream(OutputFilename, SF.getASTContext()); auto os = getFileOutputStream(OutputFilename, SF.getASTContext());
if (!os) return true; if (!os) return true;
@@ -221,8 +221,8 @@ class JSONFixitWriter
public: public:
JSONFixitWriter(std::string fixitsOutputPath, JSONFixitWriter(std::string fixitsOutputPath,
const DiagnosticOptions &DiagOpts) const DiagnosticOptions &DiagOpts)
: FixitsOutputPath(fixitsOutputPath), : FixitsOutputPath(std::move(fixitsOutputPath)),
FixitAll(DiagOpts.FixitCodeForAllDiagnostics) {} FixitAll(DiagOpts.FixitCodeForAllDiagnostics) {}
private: private:
void handleDiagnostic(SourceManager &SM, void handleDiagnostic(SourceManager &SM,
@@ -1612,10 +1612,13 @@ static void emitIndexDataForSourceFile(SourceFile *PrimarySourceFile,
if (moduleToken.empty()) if (moduleToken.empty())
moduleToken = opts.InputsAndOutputs.getSingleOutputFilename(); moduleToken = opts.InputsAndOutputs.getSingleOutputFilename();
(void) index::indexAndRecord(Instance.getMainModule(), opts.InputsAndOutputs.copyOutputFilenames(), (void) index::indexAndRecord(Instance.getMainModule(),
opts.InputsAndOutputs.copyOutputFilenames(),
moduleToken, opts.IndexStorePath, moduleToken, opts.IndexStorePath,
opts.IndexSystemModules, opts.IndexIgnoreStdlib, opts.IndexSystemModules,
isDebugCompilation, Invocation.getTargetTriple(), opts.IndexIgnoreStdlib,
isDebugCompilation,
Invocation.getTargetTriple(),
*Instance.getDependencyTracker()); *Instance.getDependencyTracker());
} }
} }
@@ -1683,11 +1686,12 @@ createSerializedDiagnosticConsumerIfNeeded(
return createDispatchingDiagnosticConsumerIfNeeded( return createDispatchingDiagnosticConsumerIfNeeded(
inputsAndOutputs, inputsAndOutputs,
[](const InputFile &input) -> std::unique_ptr<DiagnosticConsumer> { [](const InputFile &input) -> std::unique_ptr<DiagnosticConsumer> {
std::string serializedDiagnosticsPath = input.serializedDiagnosticsPath(); auto serializedDiagnosticsPath = input.getSerializedDiagnosticsPath();
if (serializedDiagnosticsPath.empty()) if (serializedDiagnosticsPath.empty())
return nullptr; return nullptr;
return serialized_diagnostics::createConsumer(serializedDiagnosticsPath); return serialized_diagnostics::createConsumer(
}); serializedDiagnosticsPath);
});
} }
/// Creates a diagnostic consumer that handles serializing diagnostics, based on /// Creates a diagnostic consumer that handles serializing diagnostics, based on
@@ -1704,12 +1708,12 @@ createJSONFixItDiagnosticConsumerIfNeeded(
return createDispatchingDiagnosticConsumerIfNeeded( return createDispatchingDiagnosticConsumerIfNeeded(
invocation.getFrontendOptions().InputsAndOutputs, invocation.getFrontendOptions().InputsAndOutputs,
[&](const InputFile &input) -> std::unique_ptr<DiagnosticConsumer> { [&](const InputFile &input) -> std::unique_ptr<DiagnosticConsumer> {
std::string fixItsOutputPath = input.fixItsOutputPath(); auto fixItsOutputPath = input.getFixItsOutputPath();
if (fixItsOutputPath.empty()) if (fixItsOutputPath.empty())
return nullptr; return nullptr;
return std::make_unique<JSONFixitWriter>( return std::make_unique<JSONFixitWriter>(
fixItsOutputPath, invocation.getDiagnosticOptions()); fixItsOutputPath.str(), invocation.getDiagnosticOptions());
}); });
} }
/// Print information about a /// Print information about a

View File

@@ -699,7 +699,7 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
assert(!ctxt.hadError() && assert(!ctxt.hadError() &&
"We should've already exited earlier if there was an error."); "We should've already exited earlier if there was an error.");
auto loadedModuleTracePath = input.loadedModuleTracePath(); auto loadedModuleTracePath = input.getLoadedModuleTracePath();
if (loadedModuleTracePath.empty()) if (loadedModuleTracePath.empty())
return false; return false;
std::error_code EC; std::error_code EC;

View File

@@ -91,7 +91,7 @@ bool swift::emitMakeDependenciesIfNeeded(DiagnosticEngine &diags,
DependencyTracker *depTracker, DependencyTracker *depTracker,
const FrontendOptions &opts, const FrontendOptions &opts,
const InputFile &input) { const InputFile &input) {
const std::string &dependenciesFilePath = input.dependenciesFilePath(); auto dependenciesFilePath = input.getDependenciesFilePath();
if (dependenciesFilePath.empty()) if (dependenciesFilePath.empty())
return false; return false;