Skip to content

Commit 76d25e7

Browse files
committed
[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.
1 parent a89f8e0 commit 76d25e7

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

include/swift/Frontend/InputFile.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,17 @@ class InputFile final {
121121
// FrontendInputsAndOutputs. They merely make the call sites
122122
// a bit shorter. Add more forwarding methods as needed.
123123

124-
std::string dependenciesFilePath() const {
124+
StringRef getDependenciesFilePath() const {
125125
return getPrimarySpecificPaths().SupplementaryOutputs.DependenciesFilePath;
126126
}
127-
std::string loadedModuleTracePath() const {
127+
StringRef getLoadedModuleTracePath() const {
128128
return getPrimarySpecificPaths().SupplementaryOutputs.LoadedModuleTracePath;
129129
}
130-
std::string serializedDiagnosticsPath() const {
130+
StringRef getSerializedDiagnosticsPath() const {
131131
return getPrimarySpecificPaths().SupplementaryOutputs
132132
.SerializedDiagnosticsPath;
133133
}
134-
std::string fixItsOutputPath() const {
134+
StringRef getFixItsOutputPath() const {
135135
return getPrimarySpecificPaths().SupplementaryOutputs.FixItsOutputPath;
136136
}
137137
};

lib/FrontendTool/FrontendTool.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ getFileOutputStream(StringRef OutputFilename, ASTContext &Ctx) {
127127
}
128128

129129
/// Writes the Syntax tree to the given file
130-
static bool emitSyntax(SourceFile &SF, StringRef OutputFilename) {
130+
static bool emitSyntax(const SourceFile &SF, StringRef OutputFilename) {
131131
auto os = getFileOutputStream(OutputFilename, SF.getASTContext());
132132
if (!os) return true;
133133

@@ -221,8 +221,8 @@ class JSONFixitWriter
221221
public:
222222
JSONFixitWriter(std::string fixitsOutputPath,
223223
const DiagnosticOptions &DiagOpts)
224-
: FixitsOutputPath(fixitsOutputPath),
225-
FixitAll(DiagOpts.FixitCodeForAllDiagnostics) {}
224+
: FixitsOutputPath(std::move(fixitsOutputPath)),
225+
FixitAll(DiagOpts.FixitCodeForAllDiagnostics) {}
226226

227227
private:
228228
void handleDiagnostic(SourceManager &SM,
@@ -1612,10 +1612,13 @@ static void emitIndexDataForSourceFile(SourceFile *PrimarySourceFile,
16121612
if (moduleToken.empty())
16131613
moduleToken = opts.InputsAndOutputs.getSingleOutputFilename();
16141614

1615-
(void) index::indexAndRecord(Instance.getMainModule(), opts.InputsAndOutputs.copyOutputFilenames(),
1615+
(void) index::indexAndRecord(Instance.getMainModule(),
1616+
opts.InputsAndOutputs.copyOutputFilenames(),
16161617
moduleToken, opts.IndexStorePath,
1617-
opts.IndexSystemModules, opts.IndexIgnoreStdlib,
1618-
isDebugCompilation, Invocation.getTargetTriple(),
1618+
opts.IndexSystemModules,
1619+
opts.IndexIgnoreStdlib,
1620+
isDebugCompilation,
1621+
Invocation.getTargetTriple(),
16191622
*Instance.getDependencyTracker());
16201623
}
16211624
}
@@ -1683,11 +1686,12 @@ createSerializedDiagnosticConsumerIfNeeded(
16831686
return createDispatchingDiagnosticConsumerIfNeeded(
16841687
inputsAndOutputs,
16851688
[](const InputFile &input) -> std::unique_ptr<DiagnosticConsumer> {
1686-
std::string serializedDiagnosticsPath = input.serializedDiagnosticsPath();
1687-
if (serializedDiagnosticsPath.empty())
1688-
return nullptr;
1689-
return serialized_diagnostics::createConsumer(serializedDiagnosticsPath);
1690-
});
1689+
auto serializedDiagnosticsPath = input.getSerializedDiagnosticsPath();
1690+
if (serializedDiagnosticsPath.empty())
1691+
return nullptr;
1692+
return serialized_diagnostics::createConsumer(
1693+
serializedDiagnosticsPath);
1694+
});
16911695
}
16921696

16931697
/// Creates a diagnostic consumer that handles serializing diagnostics, based on
@@ -1704,12 +1708,12 @@ createJSONFixItDiagnosticConsumerIfNeeded(
17041708
return createDispatchingDiagnosticConsumerIfNeeded(
17051709
invocation.getFrontendOptions().InputsAndOutputs,
17061710
[&](const InputFile &input) -> std::unique_ptr<DiagnosticConsumer> {
1707-
std::string fixItsOutputPath = input.fixItsOutputPath();
1708-
if (fixItsOutputPath.empty())
1709-
return nullptr;
1710-
return std::make_unique<JSONFixitWriter>(
1711-
fixItsOutputPath, invocation.getDiagnosticOptions());
1712-
});
1711+
auto fixItsOutputPath = input.getFixItsOutputPath();
1712+
if (fixItsOutputPath.empty())
1713+
return nullptr;
1714+
return std::make_unique<JSONFixitWriter>(
1715+
fixItsOutputPath.str(), invocation.getDiagnosticOptions());
1716+
});
17131717
}
17141718

17151719
/// Print information about a

lib/FrontendTool/LoadedModuleTrace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ bool swift::emitLoadedModuleTraceIfNeeded(ModuleDecl *mainModule,
699699
assert(!ctxt.hadError() &&
700700
"We should've already exited earlier if there was an error.");
701701

702-
auto loadedModuleTracePath = input.loadedModuleTracePath();
702+
auto loadedModuleTracePath = input.getLoadedModuleTracePath();
703703
if (loadedModuleTracePath.empty())
704704
return false;
705705
std::error_code EC;

lib/FrontendTool/MakeStyleDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool swift::emitMakeDependenciesIfNeeded(DiagnosticEngine &diags,
9191
DependencyTracker *depTracker,
9292
const FrontendOptions &opts,
9393
const InputFile &input) {
94-
const std::string &dependenciesFilePath = input.dependenciesFilePath();
94+
auto dependenciesFilePath = input.getDependenciesFilePath();
9595
if (dependenciesFilePath.empty())
9696
return false;
9797

0 commit comments

Comments
 (0)