25 #include "clang/AST/AST.h" 26 #include "clang/AST/Decl.h" 27 #include "clang/ASTMatchers/ASTMatchFinder.h" 28 #include "clang/ASTMatchers/ASTMatchersInternal.h" 29 #include "clang/Driver/Options.h" 30 #include "clang/Frontend/FrontendActions.h" 31 #include "clang/Tooling/CommonOptionsParser.h" 32 #include "clang/Tooling/Execution.h" 33 #include "clang/Tooling/Tooling.h" 34 #include "llvm/ADT/APFloat.h" 35 #include "llvm/Support/CommandLine.h" 36 #include "llvm/Support/Error.h" 37 #include "llvm/Support/FileSystem.h" 38 #include "llvm/Support/Path.h" 39 #include "llvm/Support/Process.h" 40 #include "llvm/Support/Signals.h" 41 #include "llvm/Support/raw_ostream.h" 46 using namespace clang;
48 static llvm::cl::extrahelp
CommonHelp(CommonOptionsParser::HelpMessage);
51 static llvm::cl::opt<std::string>
53 llvm::cl::desc(
"Directory for outputting generated files."),
56 static llvm::cl::opt<bool>
57 PublicOnly(
"public", llvm::cl::desc(
"Document only public declarations."),
62 llvm::cl::desc(
"Use only doxygen-style comments to generate docs."),
71 static llvm::cl::opt<OutputFormatTy>
72 FormatEnum(
"format", llvm::cl::desc(
"Format for outputted docs."),
74 "Documentation in YAML format."),
76 "Documentation in MD format."),
78 "Documentation in HTML format.")),
91 llvm_unreachable(
"Unknown OutputFormatTy");
96 llvm::SmallString<128> DocsRootPath;
98 std::error_code RemoveStatus = llvm::sys::fs::remove_directories(DirName);
99 if (RemoveStatus != OK) {
100 llvm::errs() <<
"Unable to remove existing documentation directory for " 105 std::error_code DirectoryStatus = llvm::sys::fs::create_directories(DirName);
106 if (DirectoryStatus != OK) {
107 llvm::errs() <<
"Unable to create documentation directories.\n";
129 StringRef RelativePath,
133 llvm::SmallString<128>
Path;
134 llvm::sys::path::native(Root, Path);
135 llvm::sys::path::append(Path, RelativePath);
137 return llvm::make_error<llvm::StringError>(
"Unable to create directory.\n",
138 llvm::inconvertibleErrorCode());
139 llvm::sys::path::append(Path, Name + Ext);
147 llvm::StringMap<std::vector<std::unique_ptr<doc::Info>>> &Output) {
149 Results.forEachResult([&](StringRef Key, StringRef Value) {
150 llvm::BitstreamCursor Stream(Value);
154 llvm::errs() <<
toString(Infos.takeError()) <<
"\n";
158 for (
auto &I : Infos.get()) {
160 Output.try_emplace(Key, std::vector<std::unique_ptr<doc::Info>>());
161 R.first->second.emplace_back(std::move(I));
167 int main(
int argc,
const char **argv) {
168 llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
171 ExecutorName.setInitialValue(
"all-TUs");
172 auto Exec = clang::tooling::createExecutorFromCommandLineArgs(
176 llvm::errs() <<
toString(Exec.takeError()) <<
"\n";
182 llvm::outs() <<
"Emiting docs in " << Format <<
" format.\n";
185 llvm::errs() <<
toString(G.takeError()) <<
"\n";
189 ArgumentsAdjuster ArgAdjuster;
191 ArgAdjuster = combineAdjusters(
192 getInsertArgumentAdjuster(
"-fparse-all-comments",
193 tooling::ArgumentInsertPosition::END),
197 llvm::outs() <<
"Mapping decls...\n";
203 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
210 llvm::outs() <<
"Collecting infos...\n";
211 llvm::StringMap<std::vector<std::unique_ptr<doc::Info>>> USRToInfos;
216 llvm::outs() <<
"Reducing " << USRToInfos.size() <<
" infos...\n";
217 for (
auto &Group : USRToInfos) {
228 llvm::errs() <<
toString(InfoPath.takeError()) <<
"\n";
231 std::error_code FileErr;
232 llvm::raw_fd_ostream InfoOS(InfoPath.get(), FileErr, llvm::sys::fs::F_None);
234 llvm::errs() <<
"Error opening info file: " << FileErr.message() <<
"\n";
238 if (
auto Err = G->get()->generateDocForInfo(I, InfoOS))
239 llvm::errs() <<
toString(std::move(Err)) <<
"\n";
llvm::SmallString< 16 > extractName()
static llvm::cl::opt< OutputFormatTy > FormatEnum("format", llvm::cl::desc("Format for outputted docs."), llvm::cl::values(clEnumValN(OutputFormatTy::yaml, "yaml", "Documentation in YAML format."), clEnumValN(OutputFormatTy::md, "md", "Documentation in MD format."), clEnumValN(OutputFormatTy::html, "html", "Documentation in HTML format.")), llvm::cl::init(OutputFormatTy::yaml), llvm::cl::cat(ClangDocCategory))
static llvm::StringRef toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K)
std::vector< CodeCompletionResult > Results
bool CreateDirectory(const Twine &DirName, bool ClearDirectory=false)
std::vector< HeaderHandle > Path
static llvm::cl::opt< bool > PublicOnly("public", llvm::cl::desc("Document only public declarations."), llvm::cl::init(false), llvm::cl::cat(ClangDocCategory))
bool bitcodeResultsToInfos(tooling::ToolResults &Results, llvm::StringMap< std::vector< std::unique_ptr< doc::Info >>> &Output)
llvm::Expected< std::unique_ptr< Generator > > findGeneratorByName(llvm::StringRef Format)
static llvm::cl::opt< std::string > OutDirectory("output", llvm::cl::desc("Directory for outputting generated files."), llvm::cl::init("docs"), llvm::cl::cat(ClangDocCategory))
static llvm::cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage)
int main(int argc, const char **argv)
static llvm::cl::opt< bool > DoxygenOnly("doxygen", llvm::cl::desc("Use only doxygen-style comments to generate docs."), llvm::cl::init(false), llvm::cl::cat(ClangDocCategory))
llvm::Expected< std::unique_ptr< Info > > mergeInfos(std::vector< std::unique_ptr< Info >> &Values)
static constexpr llvm::StringLiteral Name
llvm::Expected< std::vector< std::unique_ptr< Info > > > readBitcode()
std::string getFormatString()
llvm::SmallString< 128 > Path
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::Expected< llvm::SmallString< 128 > > getInfoOutputFile(StringRef Root, StringRef RelativePath, StringRef Name, StringRef Ext)
static llvm::cl::OptionCategory ClangDocCategory("clang-doc options")
std::unique_ptr< tooling::FrontendActionFactory > newMapperActionFactory(ClangDocContext CDCtx)