CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
157 lines
6.2 KiB
C++
157 lines
6.2 KiB
C++
//===-- Generators.h - ClangDoc Generator ----------------------*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
// Generator classes for converting declaration information into documentation
|
|
// in a specified format.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_GENERATOR_H
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_GENERATOR_H
|
|
|
|
#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 {
|
|
namespace doc {
|
|
|
|
// Abstract base class for generators.
|
|
// This is expected to be implemented and exposed via the GeneratorRegistry.
|
|
class Generator {
|
|
public:
|
|
virtual ~Generator() = default;
|
|
|
|
// Write out the decl info for the objects in the given map in the specified
|
|
// format.
|
|
virtual llvm::Error generateDocumentation(StringRef RootDir,
|
|
llvm::StringMap<doc::Info *> 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.
|
|
// If the override method wants to run this it should call
|
|
// Generator::createResources(CDCtx);
|
|
virtual llvm::Error createResources(ClangDocContext &CDCtx);
|
|
|
|
// Write out one specific decl info to the destination stream.
|
|
virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
|
|
const ClangDocContext &CDCtx) = 0;
|
|
|
|
static void addInfoToIndex(Index &Idx, const doc::Info *Info);
|
|
};
|
|
|
|
typedef llvm::Registry<Generator> GeneratorRegistry;
|
|
|
|
llvm::Expected<std::unique_ptr<Generator>>
|
|
findGeneratorByName(llvm::StringRef Format);
|
|
|
|
llvm::StringRef 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<llvm::MemoryBuffer> Buffer;
|
|
|
|
public:
|
|
static Expected<std::unique_ptr<MustacheTemplateFile>>
|
|
createMustacheFile(StringRef FileName) {
|
|
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrError =
|
|
llvm::MemoryBuffer::getFile(FileName);
|
|
if (auto EC = BufferOrError.getError())
|
|
return createFileOpenError(FileName, EC);
|
|
return std::make_unique<MustacheTemplateFile>(
|
|
std::move(BufferOrError.get()));
|
|
}
|
|
|
|
llvm::Error registerPartialFile(StringRef Name, StringRef FileName) {
|
|
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrError =
|
|
llvm::MemoryBuffer::getFile(FileName);
|
|
if (auto EC = BufferOrError.getError())
|
|
return createFileOpenError(FileName, EC);
|
|
|
|
std::unique_ptr<llvm::MemoryBuffer> 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); }
|
|
|
|
void setEscapeCharacters(const llvm::DenseMap<char, std::string> Characters) {
|
|
T.overrideEscapeCharacters(Characters);
|
|
}
|
|
|
|
MustacheTemplateFile(std::unique_ptr<llvm::MemoryBuffer> &&B)
|
|
: Saver(Allocator), Ctx(Allocator, Saver), T(B->getBuffer(), Ctx),
|
|
Buffer(std::move(B)) {}
|
|
};
|
|
|
|
struct MustacheGenerator : public Generator {
|
|
Expected<std::string> 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<MustacheTemplateFile> &Template,
|
|
StringRef TemplatePath,
|
|
std::vector<std::pair<StringRef, StringRef>> 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<doc::Info *> 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;
|
|
extern volatile int MDGeneratorAnchorSource;
|
|
extern volatile int HTMLGeneratorAnchorSource;
|
|
extern volatile int JSONGeneratorAnchorSource;
|
|
extern volatile int MDMustacheGeneratorAnchorSource;
|
|
|
|
} // namespace doc
|
|
} // namespace clang
|
|
|
|
namespace llvm {
|
|
extern template class Registry<clang::doc::Generator>;
|
|
} // namespace llvm
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_GENERATOR_H
|