Skip to content

Commit

Permalink
[NFC] Fixup InputFile Convenience Getters
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CodaFi committed Nov 12, 2020
1 parent a89f8e0 commit 76d25e7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
8 changes: 4 additions & 4 deletions include/swift/Frontend/InputFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ class InputFile final {
// FrontendInputsAndOutputs. They merely make the call sites
// a bit shorter. Add more forwarding methods as needed.

std::string dependenciesFilePath() const {
StringRef getDependenciesFilePath() const {
return getPrimarySpecificPaths().SupplementaryOutputs.DependenciesFilePath;
}
std::string loadedModuleTracePath() const {
StringRef getLoadedModuleTracePath() const {
return getPrimarySpecificPaths().SupplementaryOutputs.LoadedModuleTracePath;
}
std::string serializedDiagnosticsPath() const {
StringRef getSerializedDiagnosticsPath() const {
return getPrimarySpecificPaths().SupplementaryOutputs
.SerializedDiagnosticsPath;
}
std::string fixItsOutputPath() const {
StringRef getFixItsOutputPath() const {
return getPrimarySpecificPaths().SupplementaryOutputs.FixItsOutputPath;
}
};
Expand Down
38 changes: 21 additions & 17 deletions lib/FrontendTool/FrontendTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ getFileOutputStream(StringRef OutputFilename, ASTContext &Ctx) {
}

/// 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());
if (!os) return true;

Expand Down Expand Up @@ -221,8 +221,8 @@ class JSONFixitWriter
public:
JSONFixitWriter(std::string fixitsOutputPath,
const DiagnosticOptions &DiagOpts)
: FixitsOutputPath(fixitsOutputPath),
FixitAll(DiagOpts.FixitCodeForAllDiagnostics) {}
: FixitsOutputPath(std::move(fixitsOutputPath)),
FixitAll(DiagOpts.FixitCodeForAllDiagnostics) {}

private:
void handleDiagnostic(SourceManager &SM,
Expand Down Expand Up @@ -1612,10 +1612,13 @@ static void emitIndexDataForSourceFile(SourceFile *PrimarySourceFile,
if (moduleToken.empty())
moduleToken = opts.InputsAndOutputs.getSingleOutputFilename();

(void) index::indexAndRecord(Instance.getMainModule(), opts.InputsAndOutputs.copyOutputFilenames(),
(void) index::indexAndRecord(Instance.getMainModule(),
opts.InputsAndOutputs.copyOutputFilenames(),
moduleToken, opts.IndexStorePath,
opts.IndexSystemModules, opts.IndexIgnoreStdlib,
isDebugCompilation, Invocation.getTargetTriple(),
opts.IndexSystemModules,
opts.IndexIgnoreStdlib,
isDebugCompilation,
Invocation.getTargetTriple(),
*Instance.getDependencyTracker());
}
}
Expand Down Expand Up @@ -1683,11 +1686,12 @@ createSerializedDiagnosticConsumerIfNeeded(
return createDispatchingDiagnosticConsumerIfNeeded(
inputsAndOutputs,
[](const InputFile &input) -> std::unique_ptr<DiagnosticConsumer> {
std::string serializedDiagnosticsPath = input.serializedDiagnosticsPath();
if (serializedDiagnosticsPath.empty())
return nullptr;
return serialized_diagnostics::createConsumer(serializedDiagnosticsPath);
});
auto serializedDiagnosticsPath = input.getSerializedDiagnosticsPath();
if (serializedDiagnosticsPath.empty())
return nullptr;
return serialized_diagnostics::createConsumer(
serializedDiagnosticsPath);
});
}

/// Creates a diagnostic consumer that handles serializing diagnostics, based on
Expand All @@ -1704,12 +1708,12 @@ createJSONFixItDiagnosticConsumerIfNeeded(
return createDispatchingDiagnosticConsumerIfNeeded(
invocation.getFrontendOptions().InputsAndOutputs,
[&](const InputFile &input) -> std::unique_ptr<DiagnosticConsumer> {
std::string fixItsOutputPath = input.fixItsOutputPath();
if (fixItsOutputPath.empty())
return nullptr;
return std::make_unique<JSONFixitWriter>(
fixItsOutputPath, invocation.getDiagnosticOptions());
});
auto fixItsOutputPath = input.getFixItsOutputPath();
if (fixItsOutputPath.empty())
return nullptr;
return std::make_unique<JSONFixitWriter>(
fixItsOutputPath.str(), invocation.getDiagnosticOptions());
});
}

/// Print information about a
Expand Down
2 changes: 1 addition & 1 deletion lib/FrontendTool/LoadedModuleTrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
assert(!ctxt.hadError() &&
"We should've already exited earlier if there was an error.");

auto loadedModuleTracePath = input.loadedModuleTracePath();
auto loadedModuleTracePath = input.getLoadedModuleTracePath();
if (loadedModuleTracePath.empty())
return false;
std::error_code EC;
Expand Down
2 changes: 1 addition & 1 deletion lib/FrontendTool/MakeStyleDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool swift::emitMakeDependenciesIfNeeded(DiagnosticEngine &diags,
DependencyTracker *depTracker,
const FrontendOptions &opts,
const InputFile &input) {
const std::string &dependenciesFilePath = input.dependenciesFilePath();
auto dependenciesFilePath = input.getDependenciesFilePath();
if (dependenciesFilePath.empty())
return false;

Expand Down

0 comments on commit 76d25e7

Please sign in to comment.