From 3e2bb7b4db7f39bb138c167bec991d31bc5206ff Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 7 Nov 2025 10:22:42 -0800 Subject: [PATCH] MustacheGenerator inherits from Generator, use generateDocumentation as base --- clang-tools-extra/clang-doc/Generators.cpp | 136 +++++++++++ clang-tools-extra/clang-doc/Generators.h | 88 ++++++- clang-tools-extra/clang-doc/HTMLGenerator.cpp | 13 +- .../clang-doc/HTMLMustacheGenerator.cpp | 215 +++--------------- clang-tools-extra/clang-doc/JSONGenerator.cpp | 11 +- clang-tools-extra/clang-doc/MDGenerator.cpp | 13 +- clang-tools-extra/clang-doc/YAMLGenerator.cpp | 13 +- .../clang-doc/tool/ClangDocMain.cpp | 3 +- 8 files changed, 283 insertions(+), 209 deletions(-) diff --git a/clang-tools-extra/clang-doc/Generators.cpp b/clang-tools-extra/clang-doc/Generators.cpp index a5f6f1c7ea732..667e5d5a318f0 100644 --- a/clang-tools-extra/clang-doc/Generators.cpp +++ b/clang-tools-extra/clang-doc/Generators.cpp @@ -7,9 +7,15 @@ //===----------------------------------------------------------------------===// #include "Generators.h" +#include "support/File.h" +#include "llvm/Support/TimeProfiler.h" LLVM_INSTANTIATE_REGISTRY(clang::doc::GeneratorRegistry) +using namespace llvm; +using namespace llvm::json; +using namespace llvm::mustache; + namespace clang { namespace doc { @@ -42,6 +48,136 @@ std::string getTagType(TagTypeKind AS) { llvm_unreachable("Unknown TagTypeKind"); } +Error createFileOpenError(StringRef FileName, std::error_code EC) { + return createFileError("cannot open file " + FileName, EC); +} + +Error MustacheGenerator::setupTemplate( + std::unique_ptr &Template, StringRef TemplatePath, + std::vector> Partials) { + auto T = MustacheTemplateFile::createMustacheFile(TemplatePath); + if (Error Err = T.takeError()) + return Err; + Template = std::move(T.get()); + for (const auto &[Name, FileName] : Partials) + if (auto Err = Template->registerPartialFile(Name, FileName)) + return Err; + return Error::success(); +} + +Error MustacheGenerator::generateDocumentation( + StringRef RootDir, StringMap> Infos, + const clang::doc::ClangDocContext &CDCtx, std::string DirName) { + { + llvm::TimeTraceScope TS("Setup Templates"); + if (auto Err = setupTemplateFiles(CDCtx)) + return Err; + } + + { + llvm::TimeTraceScope TS("Generate JSON for Mustache"); + if (auto JSONGenerator = findGeneratorByName("json")) { + if (Error Err = JSONGenerator.get()->generateDocumentation( + RootDir, std::move(Infos), CDCtx)) + return Err; + } else + return JSONGenerator.takeError(); + } + + SmallString<128> JSONPath; + sys::path::native(RootDir.str() + "/json", JSONPath); + + { + llvm::TimeTraceScope TS("Iterate JSON files"); + std::error_code EC; + sys::fs::recursive_directory_iterator JSONIter(JSONPath, EC); + std::vector JSONFiles; + JSONFiles.reserve(Infos.size()); + if (EC) + return createStringError("Failed to create directory iterator."); + + SmallString<128> DocsDirPath(RootDir.str() + '/' + DirName); + sys::path::native(DocsDirPath); + if (auto EC = sys::fs::create_directories(DocsDirPath)) + return createFileError(DocsDirPath, EC); + while (JSONIter != sys::fs::recursive_directory_iterator()) { + // create the same directory structure in the docs format dir + if (JSONIter->type() == sys::fs::file_type::directory_file) { + SmallString<128> DocsClonedPath(JSONIter->path()); + sys::path::replace_path_prefix(DocsClonedPath, JSONPath, DocsDirPath); + if (auto EC = sys::fs::create_directories(DocsClonedPath)) { + return createFileError(DocsClonedPath, EC); + } + } + + if (EC) + return createFileError("Failed to iterate: " + JSONIter->path(), EC); + + auto Path = StringRef(JSONIter->path()); + if (!Path.ends_with(".json")) { + JSONIter.increment(EC); + continue; + } + + auto File = MemoryBuffer::getFile(Path); + if (EC = File.getError(); EC) { + // TODO: Buffer errors to report later, look into using Clang + // diagnostics. + llvm::errs() << "Failed to open file: " << Path << " " << EC.message() + << '\n'; + } + + auto Parsed = json::parse((*File)->getBuffer()); + if (!Parsed) + return Parsed.takeError(); + auto ValidJSON = Parsed.get(); + + std::error_code FileErr; + SmallString<128> DocsFilePath(JSONIter->path()); + sys::path::replace_path_prefix(DocsFilePath, JSONPath, DocsDirPath); + sys::path::replace_extension(DocsFilePath, DirName); + raw_fd_ostream InfoOS(DocsFilePath, FileErr, sys::fs::OF_None); + if (FileErr) + return createFileOpenError(Path, FileErr); + + auto RelativeRootPath = getRelativePathToRoot(DocsFilePath, DocsDirPath); + auto InfoTypeStr = + getInfoTypeStr(Parsed->getAsObject(), sys::path::stem(DocsFilePath)); + if (!InfoTypeStr) + return InfoTypeStr.takeError(); + if (Error Err = generateDocForJSON(*Parsed, InfoOS, CDCtx, + InfoTypeStr.get(), RelativeRootPath)) + return Err; + JSONIter.increment(EC); + } + } + + return Error::success(); +} + +Expected MustacheGenerator::getInfoTypeStr(Object *Info, + StringRef Filename) { + auto StrValue = (*Info)["InfoType"]; + if (StrValue.kind() != json::Value::Kind::String) + return createStringError("JSON file '%s' does not contain key: 'InfoType'.", + Filename.str().c_str()); + auto ObjTypeStr = StrValue.getAsString(); + if (!ObjTypeStr.has_value()) + return createStringError( + "JSON file '%s' does not contain 'InfoType' field as a string.", + Filename.str().c_str()); + return ObjTypeStr.value().str(); +} + +SmallString<128> +MustacheGenerator::getRelativePathToRoot(StringRef PathToFile, + StringRef DocsRootPath) { + SmallString<128> PathVec(PathToFile); + // Remove filename, or else the relative path will have an extra "../" + sys::path::remove_filename(PathVec); + return computeRelativePath(DocsRootPath, PathVec); +} + llvm::Error Generator::createResources(ClangDocContext &CDCtx) { return llvm::Error::success(); } diff --git a/clang-tools-extra/clang-doc/Generators.h b/clang-tools-extra/clang-doc/Generators.h index 92d3006e6002d..847722646b029 100644 --- a/clang-tools-extra/clang-doc/Generators.h +++ b/clang-tools-extra/clang-doc/Generators.h @@ -14,6 +14,8 @@ #include "Representation.h" #include "llvm/Support/Error.h" +#include "llvm/Support/JSON.h" +#include "llvm/Support/Mustache.h" #include "llvm/Support/Registry.h" namespace clang { @@ -27,10 +29,9 @@ class Generator { // Write out the decl info for the objects in the given map in the specified // format. - virtual llvm::Error - generateDocs(StringRef RootDir, - llvm::StringMap> Infos, - const ClangDocContext &CDCtx) = 0; + virtual llvm::Error generateDocumentation( + StringRef RootDir, llvm::StringMap> Infos, + const ClangDocContext &CDCtx, std::string DirName = "") = 0; // This function writes a file with the index previously constructed. // It can be overwritten by any of the inherited generators. @@ -52,6 +53,85 @@ findGeneratorByName(llvm::StringRef Format); std::string getTagType(TagTypeKind AS); +llvm::Error createFileOpenError(StringRef FileName, std::error_code EC); + +class MustacheTemplateFile { + llvm::BumpPtrAllocator Allocator; + llvm::StringSaver Saver; + llvm::mustache::MustacheContext Ctx; + llvm::mustache::Template T; + std::unique_ptr Buffer; + +public: + static Expected> + createMustacheFile(StringRef FileName) { + llvm::ErrorOr> BufferOrError = + llvm::MemoryBuffer::getFile(FileName); + if (auto EC = BufferOrError.getError()) + return createFileOpenError(FileName, EC); + return std::make_unique( + std::move(BufferOrError.get())); + } + + llvm::Error registerPartialFile(StringRef Name, StringRef FileName) { + llvm::ErrorOr> BufferOrError = + llvm::MemoryBuffer::getFile(FileName); + if (auto EC = BufferOrError.getError()) + return createFileOpenError(FileName, EC); + + std::unique_ptr Buffer = std::move(BufferOrError.get()); + StringRef FileContent = Buffer->getBuffer(); + T.registerPartial(Name.str(), FileContent.str()); + return llvm::Error::success(); + } + + void render(llvm::json::Value &V, raw_ostream &OS) { T.render(V, OS); } + + MustacheTemplateFile(std::unique_ptr &&B) + : Saver(Allocator), Ctx(Allocator, Saver), T(B->getBuffer(), Ctx), + Buffer(std::move(B)) {} +}; + +struct MustacheGenerator : public Generator { + Expected getInfoTypeStr(llvm::json::Object *Info, + StringRef Filename); + + /// Used to find the relative path from the file to the format's docs root. + /// Mainly used for the HTML resource paths. + SmallString<128> getRelativePathToRoot(StringRef PathToFile, + StringRef DocsRootPath); + virtual ~MustacheGenerator() = default; + + /// Initializes the template files from disk and calls setupTemplate to + /// register partials + virtual llvm::Error setupTemplateFiles(const ClangDocContext &CDCtx) = 0; + + /// Populates templates with data from JSON and calls any specifics for the + /// format. For example, for HTML it will render the paths for CSS and JS. + virtual llvm::Error generateDocForJSON(llvm::json::Value &JSON, + llvm::raw_fd_ostream &OS, + const ClangDocContext &CDCtx, + StringRef ObjectTypeStr, + StringRef RelativeRootPath) = 0; + + /// Registers partials to templates. + llvm::Error + setupTemplate(std::unique_ptr &Template, + StringRef TemplatePath, + std::vector> Partials); + + /// \brief The main orchestrator for Mustache-based documentation. + /// + /// 1. Initializes templates files from disk by calling setupTemplateFiles. + /// 2. Calls the JSON generator to write JSON to disk. + /// 3. Iterates over the JSON files, recreates the directory structure from + /// JSON, and calls generateDocForJSON for each file. + /// 4. A file of the desired format is created. + llvm::Error generateDocumentation( + StringRef RootDir, llvm::StringMap> Infos, + const clang::doc::ClangDocContext &CDCtx, std::string DirName) override; +}; + // This anchor is used to force the linker to link in the generated object file // and thus register the generators. extern volatile int YAMLGeneratorAnchorSource; diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp index 8294ff9118558..7c8c16b8e8aca 100644 --- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp @@ -897,9 +897,9 @@ class HTMLGenerator : public Generator { public: static const char *Format; - llvm::Error generateDocs(StringRef RootDir, - llvm::StringMap> Infos, - const ClangDocContext &CDCtx) override; + llvm::Error generateDocumentation( + StringRef RootDir, llvm::StringMap> Infos, + const ClangDocContext &CDCtx, std::string DirName) override; llvm::Error createResources(ClangDocContext &CDCtx) override; llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS, const ClangDocContext &CDCtx) override; @@ -907,10 +907,9 @@ class HTMLGenerator : public Generator { const char *HTMLGenerator::Format = "html"; -llvm::Error -HTMLGenerator::generateDocs(StringRef RootDir, - llvm::StringMap> Infos, - const ClangDocContext &CDCtx) { +llvm::Error HTMLGenerator::generateDocumentation( + StringRef RootDir, llvm::StringMap> Infos, + const ClangDocContext &CDCtx, std::string DirName) { // Track which directories we already tried to create. llvm::StringSet<> CreatedDirs; diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp index 1e757101549c6..c09f908c7eb22 100644 --- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp @@ -16,10 +16,7 @@ #include "Representation.h" #include "support/File.h" #include "llvm/Support/Error.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/Mustache.h" #include "llvm/Support/Path.h" -#include "llvm/Support/TimeProfiler.h" using namespace llvm; using namespace llvm::json; @@ -27,82 +24,30 @@ using namespace llvm::mustache; namespace clang { namespace doc { -static Error generateDocForJSON(json::Value &JSON, StringRef Filename, - StringRef Path, raw_fd_ostream &OS, - const ClangDocContext &CDCtx, - StringRef HTMLRootPath); -static Error createFileOpenError(StringRef FileName, std::error_code EC) { - return createFileError("cannot open file " + FileName, EC); -} +static std::unique_ptr NamespaceTemplate = nullptr; + +static std::unique_ptr RecordTemplate = nullptr; -class MustacheHTMLGenerator : public Generator { +class MustacheHTMLGenerator : public MustacheGenerator { public: static const char *Format; - Error generateDocs(StringRef RootDir, - StringMap> Infos, - const ClangDocContext &CDCtx) override; Error createResources(ClangDocContext &CDCtx) override; Error generateDocForInfo(Info *I, raw_ostream &OS, const ClangDocContext &CDCtx) override; + Error setupTemplateFiles(const ClangDocContext &CDCtx) override; + Error generateDocForJSON(json::Value &JSON, raw_fd_ostream &OS, + const ClangDocContext &CDCtx, StringRef ObjTypeStr, + StringRef RelativeRootPath) override; + // Populates templates with CSS stylesheets, JS scripts paths. + Error setupTemplateResources(const ClangDocContext &CDCtx, json::Value &V, + SmallString<128> RelativeRootPath); + llvm::Error generateDocumentation( + StringRef RootDir, llvm::StringMap> Infos, + const ClangDocContext &CDCtx, std::string DirName) override; }; -class MustacheTemplateFile { - BumpPtrAllocator Allocator; - StringSaver Saver; - MustacheContext Ctx; - Template T; - std::unique_ptr Buffer; - -public: - static Expected> - createMustacheFile(StringRef FileName) { - ErrorOr> BufferOrError = - MemoryBuffer::getFile(FileName); - if (auto EC = BufferOrError.getError()) - return createFileOpenError(FileName, EC); - return std::make_unique( - std::move(BufferOrError.get())); - } - - Error registerPartialFile(StringRef Name, StringRef FileName) { - ErrorOr> BufferOrError = - MemoryBuffer::getFile(FileName); - if (auto EC = BufferOrError.getError()) - return createFileOpenError(FileName, EC); - - std::unique_ptr Buffer = std::move(BufferOrError.get()); - StringRef FileContent = Buffer->getBuffer(); - T.registerPartial(Name.str(), FileContent.str()); - return Error::success(); - } - - void render(json::Value &V, raw_ostream &OS) { T.render(V, OS); } - - MustacheTemplateFile(std::unique_ptr &&B) - : Saver(Allocator), Ctx(Allocator, Saver), T(B->getBuffer(), Ctx), - Buffer(std::move(B)) {} -}; - -static std::unique_ptr NamespaceTemplate = nullptr; - -static std::unique_ptr RecordTemplate = nullptr; - -static Error -setupTemplate(std::unique_ptr &Template, - StringRef TemplatePath, - std::vector> Partials) { - auto T = MustacheTemplateFile::createMustacheFile(TemplatePath); - if (Error Err = T.takeError()) - return Err; - Template = std::move(T.get()); - for (const auto &[Name, FileName] : Partials) - if (auto Err = Template->registerPartialFile(Name, FileName)) - return Err; - return Error::success(); -} - -static Error setupTemplateFiles(const clang::doc::ClangDocContext &CDCtx) { +Error MustacheHTMLGenerator::setupTemplateFiles(const ClangDocContext &CDCtx) { // Template files need to use the native path when they're opened, // but have to be used in POSIX style when used in HTML. auto ConvertToNative = [](std::string &&Path) -> std::string { @@ -135,97 +80,17 @@ static Error setupTemplateFiles(const clang::doc::ClangDocContext &CDCtx) { return Error::success(); } -Error MustacheHTMLGenerator::generateDocs( - StringRef RootDir, StringMap> Infos, - const clang::doc::ClangDocContext &CDCtx) { - { - llvm::TimeTraceScope TS("Setup Templates"); - if (auto Err = setupTemplateFiles(CDCtx)) - return Err; - } - - { - llvm::TimeTraceScope TS("Generate JSON for Mustache"); - if (auto JSONGenerator = findGeneratorByName("json")) { - if (Error Err = JSONGenerator.get()->generateDocs( - RootDir, std::move(Infos), CDCtx)) - return Err; - } else - return JSONGenerator.takeError(); - } - SmallString<128> JSONPath; - sys::path::native(RootDir.str() + "/json", JSONPath); - - { - llvm::TimeTraceScope TS("Iterate JSON files"); - std::error_code EC; - sys::fs::recursive_directory_iterator JSONIter(JSONPath, EC); - std::vector JSONFiles; - JSONFiles.reserve(Infos.size()); - if (EC) - return createStringError("Failed to create directory iterator."); - - SmallString<128> HTMLDirPath(RootDir.str() + "/html"); - if (auto EC = sys::fs::create_directories(HTMLDirPath)) - return createFileError(HTMLDirPath, EC); - while (JSONIter != sys::fs::recursive_directory_iterator()) { - // create the same directory structure in the HTML dir - if (JSONIter->type() == sys::fs::file_type::directory_file) { - SmallString<128> HTMLClonedPath(JSONIter->path()); - sys::path::replace_path_prefix(HTMLClonedPath, JSONPath, HTMLDirPath); - if (auto EC = sys::fs::create_directories(HTMLClonedPath)) - return createFileError(HTMLClonedPath, EC); - } - - if (EC) - return createFileError("Failed to iterate: " + JSONIter->path(), EC); - - auto Path = StringRef(JSONIter->path()); - if (!Path.ends_with(".json")) { - JSONIter.increment(EC); - continue; - } - - auto File = MemoryBuffer::getFile(Path); - if (EC = File.getError(); EC) - // TODO: Buffer errors to report later, look into using Clang - // diagnostics. - llvm::errs() << "Failed to open file: " << Path << " " << EC.message() - << '\n'; - - auto Parsed = json::parse((*File)->getBuffer()); - if (!Parsed) - return Parsed.takeError(); - - std::error_code FileErr; - SmallString<128> HTMLFilePath(JSONIter->path()); - sys::path::replace_path_prefix(HTMLFilePath, JSONPath, HTMLDirPath); - sys::path::replace_extension(HTMLFilePath, "html"); - raw_fd_ostream InfoOS(HTMLFilePath, FileErr, sys::fs::OF_None); - if (FileErr) - return createFileOpenError(Path, FileErr); - - if (Error Err = - generateDocForJSON(*Parsed, sys::path::stem(HTMLFilePath), - HTMLFilePath, InfoOS, CDCtx, HTMLDirPath)) - return Err; - JSONIter.increment(EC); - } - } - - return Error::success(); -} - -static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V, - SmallString<128> RelativeHTMLPath) { +Error MustacheHTMLGenerator::setupTemplateResources( + const ClangDocContext &CDCtx, json::Value &V, + SmallString<128> RelativeRootPath) { V.getAsObject()->insert({"ProjectName", CDCtx.ProjectName}); json::Value StylesheetArr = Array(); - sys::path::native(RelativeHTMLPath, sys::path::Style::posix); + sys::path::native(RelativeRootPath, sys::path::Style::posix); auto *SSA = StylesheetArr.getAsArray(); SSA->reserve(CDCtx.UserStylesheets.size()); for (const auto &FilePath : CDCtx.UserStylesheets) { - SmallString<128> StylesheetPath = RelativeHTMLPath; + SmallString<128> StylesheetPath = RelativeRootPath; sys::path::append(StylesheetPath, sys::path::Style::posix, sys::path::filename(FilePath)); SSA->emplace_back(StylesheetPath); @@ -236,7 +101,7 @@ static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V, auto *SCA = ScriptArr.getAsArray(); SCA->reserve(CDCtx.JsScripts.size()); for (auto Script : CDCtx.JsScripts) { - SmallString<128> JsPath = RelativeHTMLPath; + SmallString<128> JsPath = RelativeRootPath; sys::path::append(JsPath, sys::path::Style::posix, sys::path::filename(Script)); SCA->emplace_back(JsPath); @@ -245,31 +110,18 @@ static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V, return Error::success(); } -static Error generateDocForJSON(json::Value &JSON, StringRef Filename, - StringRef Path, raw_fd_ostream &OS, - const ClangDocContext &CDCtx, - StringRef HTMLRootPath) { - auto StrValue = (*JSON.getAsObject())["InfoType"]; - if (StrValue.kind() != json::Value::Kind::String) - return createStringError("JSON file '%s' does not contain key: 'InfoType'.", - Filename.str().c_str()); - auto ObjTypeStr = StrValue.getAsString(); - if (!ObjTypeStr.has_value()) - return createStringError( - "JSON file '%s' does not contain 'InfoType' field as a string.", - Filename.str().c_str()); - - SmallString<128> PathVec(Path); - // Remove filename, or else the relative path will have an extra "../" - sys::path::remove_filename(PathVec); - auto RelativeHTMLPath = computeRelativePath(HTMLRootPath, PathVec); - if (ObjTypeStr.value() == "namespace") { - if (auto Err = setupTemplateValue(CDCtx, JSON, RelativeHTMLPath)) +Error MustacheHTMLGenerator::generateDocForJSON(json::Value &JSON, + raw_fd_ostream &OS, + const ClangDocContext &CDCtx, + StringRef ObjTypeStr, + StringRef RelativeRootPath) { + if (ObjTypeStr == "namespace") { + if (auto Err = setupTemplateResources(CDCtx, JSON, RelativeRootPath)) return Err; assert(NamespaceTemplate && "NamespaceTemplate is nullptr."); NamespaceTemplate->render(JSON, OS); - } else if (ObjTypeStr.value() == "record") { - if (auto Err = setupTemplateValue(CDCtx, JSON, RelativeHTMLPath)) + } else if (ObjTypeStr == "record") { + if (auto Err = setupTemplateResources(CDCtx, JSON, RelativeRootPath)) return Err; assert(RecordTemplate && "RecordTemplate is nullptr."); RecordTemplate->render(JSON, OS); @@ -306,6 +158,13 @@ Error MustacheHTMLGenerator::createResources(ClangDocContext &CDCtx) { return Error::success(); } +Error MustacheHTMLGenerator::generateDocumentation( + StringRef RootDir, llvm::StringMap> Infos, + const ClangDocContext &CDCtx, std::string DirName) { + return MustacheGenerator::generateDocumentation(RootDir, std::move(Infos), + CDCtx, "html"); +} + const char *MustacheHTMLGenerator::Format = "mustache"; static GeneratorRegistry::Add diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 9a770d7939a4b..c464252b94209 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -12,9 +12,10 @@ class JSONGenerator : public Generator { public: static const char *Format; - Error generateDocs(StringRef RootDir, - llvm::StringMap> Infos, - const ClangDocContext &CDCtx) override; + Error generateDocumentation(StringRef RootDir, + llvm::StringMap> Infos, + const ClangDocContext &CDCtx, + std::string DirName) override; Error createResources(ClangDocContext &CDCtx) override; Error generateDocForInfo(Info *I, llvm::raw_ostream &OS, const ClangDocContext &CDCtx) override; @@ -589,9 +590,9 @@ static SmallString<16> determineFileName(Info *I, SmallString<128> &Path) { return FileName; } -Error JSONGenerator::generateDocs( +Error JSONGenerator::generateDocumentation( StringRef RootDir, llvm::StringMap> Infos, - const ClangDocContext &CDCtx) { + const ClangDocContext &CDCtx, std::string DirName) { StringSet<> CreatedDirs; StringMap> FileToInfos; for (const auto &Group : Infos) { diff --git a/clang-tools-extra/clang-doc/MDGenerator.cpp b/clang-tools-extra/clang-doc/MDGenerator.cpp index 6f16f5bd2f528..fcb75af80f9e9 100644 --- a/clang-tools-extra/clang-doc/MDGenerator.cpp +++ b/clang-tools-extra/clang-doc/MDGenerator.cpp @@ -398,9 +398,9 @@ class MDGenerator : public Generator { public: static const char *Format; - llvm::Error generateDocs(StringRef RootDir, - llvm::StringMap> Infos, - const ClangDocContext &CDCtx) override; + llvm::Error generateDocumentation( + StringRef RootDir, llvm::StringMap> Infos, + const ClangDocContext &CDCtx, std::string DirName) override; llvm::Error createResources(ClangDocContext &CDCtx) override; llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS, const ClangDocContext &CDCtx) override; @@ -408,10 +408,9 @@ class MDGenerator : public Generator { const char *MDGenerator::Format = "md"; -llvm::Error -MDGenerator::generateDocs(StringRef RootDir, - llvm::StringMap> Infos, - const ClangDocContext &CDCtx) { +llvm::Error MDGenerator::generateDocumentation( + StringRef RootDir, llvm::StringMap> Infos, + const ClangDocContext &CDCtx, std::string DirName) { // Track which directories we already tried to create. llvm::StringSet<> CreatedDirs; diff --git a/clang-tools-extra/clang-doc/YAMLGenerator.cpp b/clang-tools-extra/clang-doc/YAMLGenerator.cpp index eeccdd804b669..ce4ef58e582e5 100644 --- a/clang-tools-extra/clang-doc/YAMLGenerator.cpp +++ b/clang-tools-extra/clang-doc/YAMLGenerator.cpp @@ -347,19 +347,18 @@ class YAMLGenerator : public Generator { public: static const char *Format; - llvm::Error generateDocs(StringRef RootDir, - llvm::StringMap> Infos, - const ClangDocContext &CDCtx) override; + llvm::Error generateDocumentation( + StringRef RootDir, llvm::StringMap> Infos, + const ClangDocContext &CDCtx, std::string DirName) override; llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS, const ClangDocContext &CDCtx) override; }; const char *YAMLGenerator::Format = "yaml"; -llvm::Error -YAMLGenerator::generateDocs(StringRef RootDir, - llvm::StringMap> Infos, - const ClangDocContext &CDCtx) { +llvm::Error YAMLGenerator::generateDocumentation( + StringRef RootDir, llvm::StringMap> Infos, + const ClangDocContext &CDCtx, std::string DirName) { for (const auto &Group : Infos) { doc::Info *Info = Group.getValue().get(); diff --git a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp index 3bb67baf65739..c86fd720d996b 100644 --- a/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp +++ b/clang-tools-extra/clang-doc/tool/ClangDocMain.cpp @@ -438,7 +438,8 @@ Example usage for a project using a compile commands database: // Run the generator. llvm::outs() << "Generating docs...\n"; - ExitOnErr(G->generateDocs(OutDirectory, std::move(USRToInfo), CDCtx)); + ExitOnErr( + G->generateDocumentation(OutDirectory, std::move(USRToInfo), CDCtx)); llvm::outs() << "Generating assets for docs...\n"; ExitOnErr(G->createResources(CDCtx)); llvm::timeTraceProfilerEnd();