Skip to content

Commit bb1b479

Browse files
authored
Merge pull request swiftlang#34716 from CodaFi/front-end-back
[NFC] More Light Frontend(Tool) Refactoring
2 parents 40b3843 + 76d25e7 commit bb1b479

File tree

4 files changed

+27
-34
lines changed

4 files changed

+27
-34
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 & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@
4141
#include "swift/Basic/Dwarf.h"
4242
#include "swift/Basic/Edit.h"
4343
#include "swift/Basic/FileSystem.h"
44-
#include "swift/Basic/JSONSerialization.h"
4544
#include "swift/Basic/LLVMInitialize.h"
4645
#include "swift/Basic/Platform.h"
4746
#include "swift/Basic/PrettyStackTrace.h"
4847
#include "swift/Basic/SourceManager.h"
4948
#include "swift/Basic/Statistic.h"
5049
#include "swift/Basic/UUID.h"
5150
#include "swift/Option/Options.h"
52-
#include "swift/Frontend/DiagnosticVerifier.h"
5351
#include "swift/Frontend/Frontend.h"
5452
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
5553
#include "swift/Frontend/SerializedDiagnosticConsumer.h"
@@ -64,29 +62,20 @@
6462
#include "swift/Serialization/SerializationOptions.h"
6563
#include "swift/Serialization/SerializedModuleLoader.h"
6664
#include "swift/SILOptimizer/PassManager/Passes.h"
67-
#include "swift/SIL/SILRemarkStreamer.h"
6865
#include "swift/Syntax/Serialization/SyntaxSerialization.h"
6966
#include "swift/Syntax/SyntaxNodes.h"
7067
#include "swift/TBDGen/TBDGen.h"
7168

72-
#include "clang/AST/ASTContext.h"
73-
#include "clang/Basic/Module.h"
74-
7569
#include "llvm/ADT/Statistic.h"
7670
#include "llvm/IR/LLVMContext.h"
7771
#include "llvm/IR/Module.h"
7872
#include "llvm/IRReader/IRReader.h"
7973
#include "llvm/Option/Option.h"
8074
#include "llvm/Option/OptTable.h"
81-
#include "llvm/Remarks/RemarkSerializer.h"
8275
#include "llvm/Support/Error.h"
8376
#include "llvm/Support/ErrorHandling.h"
8477
#include "llvm/Support/Path.h"
8578
#include "llvm/Support/raw_ostream.h"
86-
#include "llvm/Support/TargetSelect.h"
87-
#include "llvm/Support/Timer.h"
88-
#include "llvm/Support/YAMLTraits.h"
89-
#include "llvm/Target/TargetMachine.h"
9079

9180
#include <algorithm>
9281
#include <memory>
@@ -138,7 +127,7 @@ getFileOutputStream(StringRef OutputFilename, ASTContext &Ctx) {
138127
}
139128

140129
/// Writes the Syntax tree to the given file
141-
static bool emitSyntax(SourceFile &SF, StringRef OutputFilename) {
130+
static bool emitSyntax(const SourceFile &SF, StringRef OutputFilename) {
142131
auto os = getFileOutputStream(OutputFilename, SF.getASTContext());
143132
if (!os) return true;
144133

@@ -232,8 +221,8 @@ class JSONFixitWriter
232221
public:
233222
JSONFixitWriter(std::string fixitsOutputPath,
234223
const DiagnosticOptions &DiagOpts)
235-
: FixitsOutputPath(fixitsOutputPath),
236-
FixitAll(DiagOpts.FixitCodeForAllDiagnostics) {}
224+
: FixitsOutputPath(std::move(fixitsOutputPath)),
225+
FixitAll(DiagOpts.FixitCodeForAllDiagnostics) {}
237226

238227
private:
239228
void handleDiagnostic(SourceManager &SM,
@@ -1623,10 +1612,13 @@ static void emitIndexDataForSourceFile(SourceFile *PrimarySourceFile,
16231612
if (moduleToken.empty())
16241613
moduleToken = opts.InputsAndOutputs.getSingleOutputFilename();
16251614

1626-
(void) index::indexAndRecord(Instance.getMainModule(), opts.InputsAndOutputs.copyOutputFilenames(),
1615+
(void) index::indexAndRecord(Instance.getMainModule(),
1616+
opts.InputsAndOutputs.copyOutputFilenames(),
16271617
moduleToken, opts.IndexStorePath,
1628-
opts.IndexSystemModules, opts.IndexIgnoreStdlib,
1629-
isDebugCompilation, Invocation.getTargetTriple(),
1618+
opts.IndexSystemModules,
1619+
opts.IndexIgnoreStdlib,
1620+
isDebugCompilation,
1621+
Invocation.getTargetTriple(),
16301622
*Instance.getDependencyTracker());
16311623
}
16321624
}
@@ -1694,11 +1686,12 @@ createSerializedDiagnosticConsumerIfNeeded(
16941686
return createDispatchingDiagnosticConsumerIfNeeded(
16951687
inputsAndOutputs,
16961688
[](const InputFile &input) -> std::unique_ptr<DiagnosticConsumer> {
1697-
std::string serializedDiagnosticsPath = input.serializedDiagnosticsPath();
1698-
if (serializedDiagnosticsPath.empty())
1699-
return nullptr;
1700-
return serialized_diagnostics::createConsumer(serializedDiagnosticsPath);
1701-
});
1689+
auto serializedDiagnosticsPath = input.getSerializedDiagnosticsPath();
1690+
if (serializedDiagnosticsPath.empty())
1691+
return nullptr;
1692+
return serialized_diagnostics::createConsumer(
1693+
serializedDiagnosticsPath);
1694+
});
17021695
}
17031696

17041697
/// Creates a diagnostic consumer that handles serializing diagnostics, based on
@@ -1715,12 +1708,12 @@ createJSONFixItDiagnosticConsumerIfNeeded(
17151708
return createDispatchingDiagnosticConsumerIfNeeded(
17161709
invocation.getFrontendOptions().InputsAndOutputs,
17171710
[&](const InputFile &input) -> std::unique_ptr<DiagnosticConsumer> {
1718-
std::string fixItsOutputPath = input.fixItsOutputPath();
1719-
if (fixItsOutputPath.empty())
1720-
return nullptr;
1721-
return std::make_unique<JSONFixitWriter>(
1722-
fixItsOutputPath, invocation.getDiagnosticOptions());
1723-
});
1711+
auto fixItsOutputPath = input.getFixItsOutputPath();
1712+
if (fixItsOutputPath.empty())
1713+
return nullptr;
1714+
return std::make_unique<JSONFixitWriter>(
1715+
fixItsOutputPath.str(), invocation.getDiagnosticOptions());
1716+
});
17241717
}
17251718

17261719
/// 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)