12#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_GENERATOR_H
13#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_GENERATOR_H
16#include "llvm/Support/Error.h"
17#include "llvm/Support/JSON.h"
18#include "llvm/Support/Mustache.h"
19#include "llvm/Support/Registry.h"
33 StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
51llvm::Expected<std::unique_ptr<Generator>>
59 llvm::BumpPtrAllocator Allocator;
60 llvm::StringSaver Saver;
61 llvm::mustache::MustacheContext Ctx;
62 llvm::mustache::Template T;
63 std::unique_ptr<llvm::MemoryBuffer> Buffer;
66 static Expected<std::unique_ptr<MustacheTemplateFile>>
68 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrError =
69 llvm::MemoryBuffer::getFile(FileName);
70 if (
auto EC = BufferOrError.getError())
72 return std::make_unique<MustacheTemplateFile>(
73 std::move(BufferOrError.get()));
77 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrError =
78 llvm::MemoryBuffer::getFile(FileName);
79 if (
auto EC = BufferOrError.getError())
82 std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(BufferOrError.get());
83 StringRef FileContent = Buffer->getBuffer();
84 T.registerPartial(Name.str(), FileContent.str());
85 return llvm::Error::success();
88 void render(llvm::json::Value &V, raw_ostream &OS) { T.render(V, OS); }
91 : Saver(Allocator), Ctx(Allocator, Saver), T(B->getBuffer(), Ctx),
92 Buffer(std::
move(B)) {}
102 StringRef DocsRootPath);
112 llvm::raw_fd_ostream &OS,
114 StringRef ObjectTypeStr,
115 StringRef RelativeRootPath) = 0;
119 setupTemplate(std::unique_ptr<MustacheTemplateFile> &Template,
120 StringRef TemplatePath,
121 std::vector<std::pair<StringRef, StringRef>> Partials);
131 StringRef RootDir, llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
147extern template class Registry<clang::doc::Generator>;
virtual llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS, const ClangDocContext &CDCtx)=0
virtual llvm::Error generateDocumentation(StringRef RootDir, llvm::StringMap< std::unique_ptr< doc::Info > > Infos, const ClangDocContext &CDCtx, std::string DirName="")=0
static void addInfoToIndex(Index &Idx, const doc::Info *Info)
virtual ~Generator()=default
virtual llvm::Error createResources(ClangDocContext &CDCtx)
static Expected< std::unique_ptr< MustacheTemplateFile > > createMustacheFile(StringRef FileName)
MustacheTemplateFile(std::unique_ptr< llvm::MemoryBuffer > &&B)
llvm::Error registerPartialFile(StringRef Name, StringRef FileName)
void render(llvm::json::Value &V, raw_ostream &OS)
std::string getTagType(TagTypeKind AS)
llvm::Expected< std::unique_ptr< Generator > > findGeneratorByName(llvm::StringRef Format)
volatile int JSONGeneratorAnchorSource
static GeneratorRegistry::Add< JSONGenerator > JSON(JSONGenerator::Format, "Generator for JSON output.")
volatile int HTMLGeneratorAnchorSource
volatile int YAMLGeneratorAnchorSource
Error createFileOpenError(StringRef FileName, std::error_code EC)
volatile int MDGeneratorAnchorSource
volatile int MHTMLGeneratorAnchorSource
llvm::Registry< Generator > GeneratorRegistry
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.
llvm::Error generateDocumentation(StringRef RootDir, llvm::StringMap< std::unique_ptr< doc::Info > > Infos, const clang::doc::ClangDocContext &CDCtx, std::string DirName) override
The main orchestrator for Mustache-based documentation.
Expected< std::string > getInfoTypeStr(llvm::json::Object *Info, StringRef Filename)
virtual llvm::Error setupTemplateFiles(const ClangDocContext &CDCtx)=0
Initializes the template files from disk and calls setupTemplate to register partials.
virtual llvm::Error generateDocForJSON(llvm::json::Value &JSON, llvm::raw_fd_ostream &OS, const ClangDocContext &CDCtx, StringRef ObjectTypeStr, StringRef RelativeRootPath)=0
Populates templates with data from JSON and calls any specifics for the format.
SmallString< 128 > getRelativePathToRoot(StringRef PathToFile, StringRef DocsRootPath)
Used to find the relative path from the file to the format's docs root.
llvm::Error setupTemplate(std::unique_ptr< MustacheTemplateFile > &Template, StringRef TemplatePath, std::vector< std::pair< StringRef, StringRef > > Partials)
Registers partials to templates.
virtual ~MustacheGenerator()=default