Skip to content

Commit c813066

Browse files
David Ungardavidungar
David Ungar
authored andcommitted
Move top-level emitting into a class, ReferenceDependenciesEmitter.
1 parent ebf8713 commit c813066

File tree

1 file changed

+51
-30
lines changed

1 file changed

+51
-30
lines changed

Diff for: lib/FrontendTool/ReferenceDependencies.cpp

+51-30
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,33 @@ static std::string escape(DeclBaseName name) {
127127
return llvm::yaml::escape(name.userFacingName());
128128
}
129129

130-
static void emitProvides(const SourceFile *SF, llvm::raw_ostream &out);
131-
static void emitDepends(const SourceFile *SF,
132-
const DependencyTracker &depTracker,
133-
llvm::raw_ostream &out);
134-
static void emitInterfaceHash(SourceFile *SF, llvm::raw_ostream &out);
130+
namespace {
131+
class ReferenceDependenciesEmitter {
132+
SourceFile * const SF;
133+
const DependencyTracker &depTracker;
134+
llvm::raw_ostream &out;
135+
136+
ReferenceDependenciesEmitter(SourceFile *const SF, const DependencyTracker &depTracker, llvm::raw_ostream &out) :
137+
SF(SF), depTracker(depTracker), out(out) {}
138+
139+
public:
140+
/// \return true on error
141+
static bool emit(DiagnosticEngine &diags, SourceFile *const SF,
142+
const DependencyTracker &depTracker,
143+
StringRef outputPath);
144+
static void emit(SourceFile *const SF, const DependencyTracker &depTracker, llvm::raw_ostream &out);
145+
146+
private:
147+
static std::unique_ptr<llvm::raw_fd_ostream> openFile(DiagnosticEngine &diags,
148+
StringRef OutputPath);
149+
void emit();
150+
void emitProvides();
151+
void emitDepends();
152+
void emitInterfaceHash();
153+
};
154+
} // end anon namespace
135155

136-
static std::unique_ptr<llvm::raw_fd_ostream>openFile(DiagnosticEngine &diags, StringRef outputPath) {
156+
std::unique_ptr<llvm::raw_fd_ostream>ReferenceDependenciesEmitter::openFile(DiagnosticEngine &diags, StringRef outputPath) {
137157
// Before writing to the dependencies file path, preserve any previous file
138158
// that may have been there. No error handling -- this is just a nicety, it
139159
// doesn't matter if it fails.
@@ -151,32 +171,36 @@ static std::unique_ptr<llvm::raw_fd_ostream>openFile(DiagnosticEngine &diags, St
151171
return out;
152172
}
153173

154-
static void emitReferenceDependencies(SourceFile *const SF,
155-
const DependencyTracker &depTracker,
156-
llvm::raw_ostream &out);
157-
158-
bool swift::emitReferenceDependencies(DiagnosticEngine &diags,
159-
SourceFile *const SF,
160-
const DependencyTracker &depTracker,
161-
StringRef outputPath) {
174+
bool ReferenceDependenciesEmitter::emit(DiagnosticEngine &diags,
175+
SourceFile *const SF,
176+
const DependencyTracker &depTracker,
177+
StringRef outputPath) {
162178
std::unique_ptr<llvm::raw_ostream> out = openFile(diags, outputPath);
163179
if (!out.get())
164180
return true;
165-
::emitReferenceDependencies( SF, depTracker, *out);
166-
181+
ReferenceDependenciesEmitter::emit(SF, depTracker, *out);
167182
return false;
168183
}
169184

170-
static void emitReferenceDependencies(SourceFile *const SF,
171-
const DependencyTracker &depTracker,
172-
llvm::raw_ostream &out) {
173-
assert(SF && "Cannot emit reference dependencies without a SourceFile");
185+
void ReferenceDependenciesEmitter::emit(SourceFile *const SF,
186+
const DependencyTracker &depTracker,
187+
llvm::raw_ostream &out) {
188+
ReferenceDependenciesEmitter(SF, depTracker, out).emit();
189+
}
174190

191+
void ReferenceDependenciesEmitter::emit() {
192+
assert(SF && "Cannot emit reference dependencies without a SourceFile");
175193
out << "### Swift dependencies file v0 ###\n";
176-
177-
emitProvides(SF, out);
178-
emitDepends(SF, depTracker, out);
179-
emitInterfaceHash(SF, out);
194+
emitProvides();
195+
emitDepends();
196+
emitInterfaceHash();
197+
}
198+
199+
bool swift::emitReferenceDependencies(DiagnosticEngine &diags,
200+
SourceFile *const SF,
201+
const DependencyTracker &depTracker,
202+
StringRef outputPath) {
203+
return ReferenceDependenciesEmitter::emit(diags, SF, depTracker, outputPath);
180204
}
181205

182206
static void emitProvidesTopLevelNames(
@@ -197,8 +221,7 @@ static void emitProvidesMembers(
197221
static void emitProvidesDynamicLookupMembers(const SourceFile *SF,
198222
llvm::raw_ostream &out);
199223

200-
static void emitProvides(const SourceFile *const SF,
201-
llvm::raw_ostream &out) {
224+
void ReferenceDependenciesEmitter::emitProvides() {
202225
llvm::MapVector<const NominalTypeDecl *, bool> extendedNominals;
203226
llvm::SmallVector<const ExtensionDecl *, 8> extensionsWithJustMembers;
204227

@@ -466,9 +489,7 @@ static void emitDependsDynamicLookup(const ReferencedNameTracker *tracker,
466489
static void emitDependsExternal(const DependencyTracker &depTracker,
467490
llvm::raw_ostream &out);
468491

469-
static void emitDepends(const SourceFile *const SF,
470-
const DependencyTracker &depTracker,
471-
llvm::raw_ostream &out) {
492+
void ReferenceDependenciesEmitter::emitDepends() {
472493

473494
const ReferencedNameTracker *const tracker = SF->getReferencedNameTracker();
474495
assert(tracker && "Cannot emit reference dependencies without a tracker");
@@ -581,7 +602,7 @@ static void emitDependsExternal(const DependencyTracker &depTracker,
581602
}
582603
}
583604

584-
static void emitInterfaceHash(SourceFile *const SF, llvm::raw_ostream &out) {
605+
void ReferenceDependenciesEmitter::emitInterfaceHash() {
585606
llvm::SmallString<32> interfaceHash;
586607
SF->getInterfaceHash(interfaceHash);
587608
out << "interface-hash: \"" << interfaceHash << "\"\n";

0 commit comments

Comments
 (0)