Files
swift-mirror/lib/SymbolGraphGen/SymbolGraphGen.cpp
Ashley Garland f0887fa245 [SymbolGraph] Emit synthesized members
Emit copies of default implementations in protocol extensions and superclass declarations in conforming types and subclasses respectively using a virtual USR, i.e. `${REAL_USR}::SYNTHESIZED::${CONFORMING_OR_SUBCLASS_TYPE_USR}`.

- Add a -skip-synthesized-members option to skip these synthesized members.

- Create a new wrapping `Symbol` type that can also contain a base type declaration as well as the inherited declaration for those synthesized cases. Move some symbol-specific APIs there.

- Doc comments can “cascade” down to protocol extensions or refinements in concrete types. When emitting the doc comment for a symbol, look up through to superclasses or protocol requirements for where a doc comment is actually written.

- Clean up filtering of implicitly private (e.g. “public underscored”) types

rdar://problem/59128787
2020-03-04 16:04:21 -08:00

82 lines
2.4 KiB
C++

//===--- SymbolGraphGen.cpp - Symbol Graph Generator Entry Point ----------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "llvm/Support/JSON.h"
#include "llvm/Support/Path.h"
#include "swift/SymbolGraphGen/SymbolGraphGen.h"
#include "SymbolGraphASTWalker.h"
using namespace swift;
using namespace symbolgraphgen;
namespace {
int serializeSymbolGraph(SymbolGraph &SG,
const SymbolGraphOptions &Options) {
SmallString<256> FileName(SG.M.getNameStr());
if (SG.ExtendedModule.hasValue()) {
FileName.push_back('@');
FileName.append(SG.ExtendedModule.getValue()->getNameStr());
}
FileName.append(".symbols.json");
SmallString<1024> OutputPath(Options.OutputDir);
llvm::sys::path::append(OutputPath, FileName);
std::error_code Error;
llvm::raw_fd_ostream OS(OutputPath, Error, llvm::sys::fs::FA_Write);
if (Error) {
llvm::errs() << "Couldn't open output file '" << OutputPath
<< " for writing: "
<< Error.message() << "\n";
return EXIT_FAILURE;
}
llvm::json::OStream J(OS, Options.PrettyPrint ? 2 : 0);
SG.serialize(J);
return EXIT_SUCCESS;
}
} // end anonymous namespace
// MARK: - Main Entry Point
/// Emit a symbol graph JSON file for a `ModuleDecl`.
int
symbolgraphgen::emitSymbolGraphForModule(ModuleDecl *M,
const SymbolGraphOptions &Options) {
SymbolGraphASTWalker Walker(*M, Options);
SmallVector<Decl *, 64> ModuleDecls;
M->getDisplayDecls(ModuleDecls);
llvm::errs() << ModuleDecls.size()
<< " top-level declarations in this module.\n";
for (auto *Decl : ModuleDecls) {
Walker.walk(Decl);
}
llvm::errs()
<< "Found " << Walker.Graph.Nodes.size() << " symbols and "
<< Walker.Graph.Edges.size() << " relationships.\n";
int Success = EXIT_SUCCESS;
Success |= serializeSymbolGraph(Walker.Graph, Options);
for (auto Pair : Walker.ExtendedModuleGraphs) {
Success |= serializeSymbolGraph(*Pair.getSecond(), Options);
}
return Success;
}