Skip to content

Commit c966010

Browse files
committed
swift-api-digester: remove some unused code. NFC
1 parent ba412a9 commit c966010

File tree

3 files changed

+35
-91
lines changed

3 files changed

+35
-91
lines changed

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 27 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,12 +1917,6 @@ struct ArrayTraits<ArrayRef<StringRef>> {
19171917
} // namespace swift
19181918

19191919
namespace {// Anonymous namespace.
1920-
// Serialize a forest of SDKNode trees to the given stream.
1921-
static void emitSDKNodeRoot(llvm::raw_ostream &os, SDKNode *&Root) {
1922-
json::Output yout(os);
1923-
yout << Root;
1924-
}
1925-
19261920
// Deserialize an SDKNode tree.
19271921
std::pair<std::unique_ptr<llvm::MemoryBuffer>, SDKNode*>
19281922
static parseJsonEmit(SDKContext &Ctx, StringRef FileName) {
@@ -1948,18 +1942,6 @@ static parseJsonEmit(SDKContext &Ctx, StringRef FileName) {
19481942
}
19491943
return {std::move(FileBufOrErr.get()), Result};
19501944
}
1951-
1952-
static std::string getDumpFilePath(StringRef OutputDir, StringRef FileName) {
1953-
std::string Path = OutputDir;
1954-
Path += "/";
1955-
Path += FileName;
1956-
int Suffix = 0;
1957-
auto ConstructPath = [&]() {
1958-
return Path + (Suffix == 0 ? "" : std::to_string(Suffix)) + ".js";
1959-
};
1960-
for (; fs::exists(ConstructPath()); Suffix ++);
1961-
return ConstructPath();
1962-
}
19631945
} // End of anonymous namespace
19641946

19651947
// Construct all roots vector from a given file where a forest was
@@ -1971,81 +1953,32 @@ void SwiftDeclCollector::deSerialize(StringRef Filename) {
19711953
}
19721954

19731955
// Serialize the content of all roots to a given file using JSON format.
1974-
void SwiftDeclCollector::serialize(StringRef Filename) {
1956+
void SwiftDeclCollector::serialize(StringRef Filename, SDKNode *Root) {
19751957
std::error_code EC;
19761958
llvm::raw_fd_ostream fs(Filename, EC, llvm::sys::fs::F_None);
1977-
emitSDKNodeRoot(fs, RootNode);
1959+
json::Output yout(fs);
1960+
yout << Root;
19781961
}
19791962

1980-
int swift::ide::api::dumpSwiftModules(const CompilerInvocation &InitInvok,
1981-
const llvm::StringSet<> &ModuleNames,
1982-
StringRef OutputDir,
1983-
const std::vector<std::string> PrintApis,
1984-
CheckerOptions Opts) {
1985-
if (!fs::exists(OutputDir)) {
1986-
llvm::errs() << "Output directory '" << OutputDir << "' does not exist.\n";
1987-
return 1;
1988-
}
1989-
1990-
std::vector<ModuleDecl*> Modules;
1991-
CompilerInvocation Invocation(InitInvok);
1992-
CompilerInstance CI;
1993-
// Display diagnostics to stderr.
1994-
PrintingDiagnosticConsumer PrintDiags;
1995-
CI.addDiagnosticConsumer(&PrintDiags);
1996-
if (CI.setup(Invocation)) {
1997-
llvm::errs() << "Failed to setup the compiler instance\n";
1998-
return 1;
1999-
}
2000-
2001-
auto &Context = CI.getASTContext();
2002-
2003-
for (auto &Entry : ModuleNames) {
2004-
StringRef Name = Entry.first();
2005-
if (Opts.Verbose)
2006-
llvm::errs() << "Loading module: " << Name << "...\n";
2007-
auto *M = Context.getModuleByName(Name);
2008-
if (!M) {
2009-
if (Opts.Verbose)
2010-
llvm::errs() << "Failed to load module: " << Name << '\n';
2011-
if (Opts.AbortOnModuleLoadFailure)
2012-
return 1;
2013-
}
2014-
Modules.push_back(M);
2015-
}
2016-
2017-
PrintingDiagnosticConsumer PDC;
2018-
SDKContext Ctx(Opts);
2019-
Ctx.getDiags().addConsumer(PDC);
2020-
2021-
for (auto M : Modules) {
2022-
SwiftDeclCollector Collector(Ctx);
2023-
SmallVector<Decl*, 256> Decls;
2024-
M->getTopLevelDecls(Decls);
2025-
for (auto D : Decls) {
2026-
if (auto VD = dyn_cast<ValueDecl>(D))
2027-
Collector.foundDecl(VD, DeclVisibilityKind::VisibleAtTopLevel);
2028-
}
2029-
std::string Path = getDumpFilePath(OutputDir, M->getName().str());
2030-
Collector.serialize(Path);
2031-
if (Opts.Verbose)
2032-
llvm::errs() << "Dumped to "<< Path << "\n";
2033-
}
2034-
return 0;
1963+
// Serialize the content of all roots to a given file using JSON format.
1964+
void SwiftDeclCollector::serialize(StringRef Filename) {
1965+
SwiftDeclCollector::serialize(Filename, RootNode);
20351966
}
20361967

2037-
int swift::ide::api::dumpSDKContent(const CompilerInvocation &InitInvok,
2038-
const llvm::StringSet<> &ModuleNames,
2039-
StringRef OutputFile, CheckerOptions Opts) {
1968+
SDKNodeRoot*
1969+
swift::ide::api::getSDKNodeRoot(SDKContext &SDKCtx,
1970+
const CompilerInvocation &InitInvok,
1971+
const llvm::StringSet<> &ModuleNames,
1972+
CheckerOptions Opts) {
20401973
CompilerInvocation Invocation(InitInvok);
20411974

2042-
CompilerInstance CI;
1975+
CompilerInstance &CI = SDKCtx.getCompilerInstance();
20431976
// Display diagnostics to stderr.
20441977
PrintingDiagnosticConsumer PrintDiags;
20451978
CI.addDiagnosticConsumer(&PrintDiags);
20461979
if (CI.setup(Invocation)) {
20471980
llvm::errs() << "Failed to setup the compiler instance\n";
2048-
return 1;
1981+
return nullptr;
20491982
}
20501983

20511984
auto &Ctx = CI.getASTContext();
@@ -2055,7 +1988,7 @@ int swift::ide::api::dumpSDKContent(const CompilerInvocation &InitInvok,
20551988
auto *Stdlib = Ctx.getStdlibModule(/*loadIfAbsent=*/true);
20561989
if (!Stdlib) {
20571990
llvm::errs() << "Failed to load Swift stdlib\n";
2058-
return 1;
1991+
return nullptr;
20591992
}
20601993

20611994
std::vector<ModuleDecl *> Modules;
@@ -2067,19 +2000,29 @@ int swift::ide::api::dumpSDKContent(const CompilerInvocation &InitInvok,
20672000
if (!M) {
20682001
llvm::errs() << "Failed to load module: " << Name << '\n';
20692002
if (Opts.AbortOnModuleLoadFailure)
2070-
return 1;
2003+
return nullptr;
20712004
} else {
20722005
Modules.push_back(M);
20732006
}
20742007
}
20752008
if (Opts.Verbose)
20762009
llvm::errs() << "Scanning symbols...\n";
2077-
SDKContext SDKCtx(Opts);
2010+
20782011
SwiftDeclCollector Collector(SDKCtx);
20792012
Collector.lookupVisibleDecls(Modules);
2013+
return Collector.getSDKRoot();
2014+
}
2015+
2016+
int swift::ide::api::dumpSDKContent(const CompilerInvocation &InitInvok,
2017+
const llvm::StringSet<> &ModuleNames,
2018+
StringRef OutputFile, CheckerOptions Opts) {
2019+
SDKContext SDKCtx(Opts);
2020+
SDKNode *Root = getSDKNodeRoot(SDKCtx, InitInvok, ModuleNames, Opts);
2021+
if (!Root)
2022+
return 1;
20802023
if (Opts.Verbose)
20812024
llvm::errs() << "Dumping SDK...\n";
2082-
Collector.serialize(OutputFile);
2025+
SwiftDeclCollector::serialize(OutputFile, Root);
20832026
if (Opts.Verbose)
20842027
llvm::errs() << "Dumped to "<< OutputFile << "\n";
20852028
return 0;

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ struct CheckerOptions {
150150
};
151151

152152
class SDKContext {
153+
CompilerInstance CI;
153154
llvm::StringSet<> TextData;
154155
llvm::BumpPtrAllocator Allocator;
155156
SourceManager SourceMgr;
@@ -188,6 +189,7 @@ class SDKContext {
188189
DiagnosticEngine &getDiags() {
189190
return Diags;
190191
}
192+
CompilerInstance &getCompilerInstance() { return CI; }
191193
StringRef getPlatformIntroVersion(Decl *D, PlatformKind Kind);
192194
StringRef getLanguageIntroVersion(Decl *D);
193195
bool isEqual(const SDKNode &Left, const SDKNode &Right);
@@ -683,6 +685,7 @@ class SwiftDeclCollector: public VisibleDeclConsumer {
683685

684686
// Serialize the content of all roots to a given file using JSON format.
685687
void serialize(StringRef Filename);
688+
static void serialize(StringRef Filename, SDKNode *Root);
686689

687690
// After collecting decls, either from imported modules or from a previously
688691
// serialized JSON file, using this function to get the root of the SDK.
@@ -723,6 +726,11 @@ int dumpSwiftModules(const CompilerInvocation &InitInvok,
723726
const std::vector<std::string> PrintApis,
724727
CheckerOptions Opts);
725728

729+
SDKNodeRoot *getSDKNodeRoot(SDKContext &SDKCtx,
730+
const CompilerInvocation &InitInvok,
731+
const llvm::StringSet<> &ModuleNames,
732+
CheckerOptions Opts);
733+
726734
int dumpSDKContent(const CompilerInvocation &InitInvok,
727735
const llvm::StringSet<> &ModuleNames,
728736
StringRef OutputFile, CheckerOptions Opts);

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ namespace {
4040
enum class ActionType {
4141
None,
4242
DumpSDK,
43-
DumpSwiftModules,
4443
MigratorGen,
4544
DiagnoseSDKs,
4645
// The following two are for testing purposes
@@ -144,9 +143,6 @@ Action(llvm::cl::desc("Mode:"), llvm::cl::init(ActionType::None),
144143
clEnumValN(ActionType::DumpSDK,
145144
"dump-sdk",
146145
"Dump SDK content to JSON file"),
147-
clEnumValN(ActionType::DumpSwiftModules,
148-
"dump-swift",
149-
"dump swift modules in SDK"),
150146
clEnumValN(ActionType::MigratorGen,
151147
"generate-migration-script",
152148
"Compare SDK content in JSON file and generate migration script"),
@@ -2404,9 +2400,6 @@ int main(int argc, char *argv[]) {
24042400
for (auto Name : options::ApisPrintUsrs)
24052401
PrintApis.push_back(Name);
24062402
switch (options::Action) {
2407-
case ActionType::DumpSwiftModules:
2408-
return (prepareForDump(argv[0], InitInvok, Modules)) ? 1 :
2409-
dumpSwiftModules(InitInvok, Modules, options::OutputFile, PrintApis, Opts);
24102403
case ActionType::DumpSDK:
24112404
return (prepareForDump(argv[0], InitInvok, Modules)) ? 1 :
24122405
dumpSDKContent(InitInvok, Modules, options::OutputFile, Opts);

0 commit comments

Comments
 (0)