11#include "llvm/ADT/StringRef.h"
12#include "llvm/Support/FileSystem.h"
13#include "llvm/Support/FormatVariadic.h"
14#include "llvm/Support/Path.h"
15#include "llvm/Support/raw_ostream.h"
26 return "*" + Text.str() +
"*";
30 return "**" + Text.str() +
"**";
36 llvm::raw_string_ostream Stream(Buffer);
37 for (
const auto &R : Refs) {
38 if (&R != Refs.begin())
45static void writeLine(
const Twine &Text, raw_ostream &OS) {
51static void writeHeader(
const Twine &Text,
unsigned int Num, raw_ostream &OS) {
52 OS << std::string(Num,
'#') +
" " + Text <<
"\n\n";
59 OS <<
"*Defined at " << L.
Filename <<
"#"
63 OS << formatv(
"*Defined at [#{0}{1}{2}](#{0}{1}{3})*",
72 const std::optional<Location> &DefLoc) {
104 for (
const auto &Child : I.
Children)
110 for (
const auto &Child : I.
Children)
124 llvm::raw_string_ostream Attrs(Buffer);
125 for (
unsigned Idx = 0; Idx < I.
AttrKeys.size(); ++Idx)
142 OS <<
"Unknown comment kind: " <<
static_cast<int>(I.
Kind) <<
".\n\n";
148 llvm::raw_ostream &OS) {
151 llvm::sys::path::native(Path, llvm::sys::path::Style::posix);
152 llvm::sys::path::append(Path, llvm::sys::path::Style::posix,
154 OS <<
"[" << R.
Name <<
"](" << Path <<
")";
158 llvm::raw_ostream &OS) {
166 llvm::raw_string_ostream Members(Buffer);
168 for (
const auto &N : I.
Members)
169 Members <<
"| " << N.Name <<
" |\n";
179 llvm::raw_ostream &OS) {
181 llvm::raw_string_ostream Stream(Buffer);
183 for (
const auto &N : I.
Params) {
186 Stream << N.Type.QualName +
" " + N.Name;
190 StringRef Access = getAccessSpelling(I.
Access);
194 "(" + Twine(Stream.str()) +
")"),
204 llvm::raw_ostream &OS) {
254 llvm::raw_ostream &OS) {
267 if (!Parents.empty() || !VParents.empty()) {
269 writeLine(
"Inherits from " + VParents, OS);
270 else if (VParents.empty())
271 writeLine(
"Inherits from " + Parents, OS);
273 writeLine(
"Inherits from " + Parents +
", " + VParents, OS);
279 for (
const auto &Member : I.
Members) {
280 StringRef Access = getAccessSpelling(Member.Access);
281 writeLine(Twine(Access) + (Access.empty() ?
"" :
" ") +
282 (Member.IsStatic ?
"static " :
"") +
283 Member.Type.Name.str() +
" " + Member.Name.str(),
310 llvm::raw_ostream &OS) {
316 OS <<
"##" << std::string(Level,
'#') <<
" ";
322 std::error_code FileErr;
323 llvm::SmallString<128> FilePath;
325 llvm::sys::path::append(FilePath,
"all_files.md");
326 llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_Text);
328 return llvm::createStringError(llvm::inconvertibleErrorCode(),
329 "error creating index file: " +
341 return llvm::Error::success();
345 std::error_code FileErr;
346 llvm::SmallString<128> FilePath;
348 llvm::sys::path::append(FilePath,
"index.md");
349 llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_Text);
351 return llvm::createStringError(llvm::inconvertibleErrorCode(),
352 "error creating index file: " +
355 OS <<
"# " << CDCtx.
ProjectName <<
" C/C++ Reference\n\n";
357 if (!C.Children.empty()) {
387 OS <<
"* " << Type <<
": [" << C.Name <<
"](";
390 OS << C.Name <<
")\n";
393 return llvm::Error::success();
402 llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
413 llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
416 llvm::StringSet<> CreatedDirs;
419 llvm::StringMap<std::vector<doc::Info *>> FileToInfos;
420 for (
const auto &Group : Infos) {
423 llvm::SmallString<128> Path;
424 llvm::sys::path::native(RootDir, Path);
426 if (!CreatedDirs.contains(Path)) {
427 if (std::error_code Err = llvm::sys::fs::create_directories(Path);
428 Err != std::error_code()) {
429 return llvm::createStringError(Err,
"Failed to create directory '%s'.",
432 CreatedDirs.insert(Path);
436 FileToInfos[Path].push_back(
Info);
439 for (
const auto &Group : FileToInfos) {
440 std::error_code FileErr;
441 llvm::raw_fd_ostream InfoOS(Group.getKey(), FileErr,
442 llvm::sys::fs::OF_Text);
444 return llvm::createStringError(FileErr,
"Error opening file '%s'",
445 Group.getKey().str().c_str());
448 for (
const auto &
Info : Group.getValue()) {
455 return llvm::Error::success();
481 return createStringError(llvm::inconvertibleErrorCode(),
482 "unexpected InfoType");
484 return llvm::Error::success();
498 return llvm::Error::success();
502 "Generator for MD output.");
Generator for Markdown documentation.
llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS, const ClangDocContext &CDCtx) override
llvm::Error createResources(ClangDocContext &CDCtx) override
llvm::Error generateDocs(StringRef RootDir, llvm::StringMap< std::unique_ptr< doc::Info > > Infos, const ClangDocContext &CDCtx) override
static const char * Format
std::string getTagType(TagTypeKind AS)
@ CK_InlineCommandComment
@ CK_VerbatimBlockLineComment
@ CK_VerbatimBlockComment
@ CK_TParamCommandComment
static void writeDescription(const CommentInfo &I, raw_ostream &OS)
static void maybeWriteSourceFileRef(std::vector< std::unique_ptr< TagNode > > &Out, const ClangDocContext &CDCtx, const std::optional< Location > &DefLoc)
static std::vector< std::unique_ptr< HTMLNode > > genReferenceList(const llvm::SmallVectorImpl< Reference > &Refs, const StringRef &CurrentDirectory)
static void serializeReference(const Reference &Ref, Object &ReferenceObj)
static llvm::Error serializeIndex(ClangDocContext &CDCtx)
static std::unique_ptr< TagNode > writeSourceFileRef(const ClangDocContext &CDCtx, const Location &L)
static GeneratorRegistry::Add< MDGenerator > MD(MDGenerator::Format, "Generator for MD output.")
static void writeHeader(const Twine &Text, unsigned int Num, raw_ostream &OS)
static void writeNameLink(const StringRef &CurrentPath, const Reference &R, llvm::raw_ostream &OS)
static llvm::Error genIndex(const ClangDocContext &CDCtx)
static void writeLine(const Twine &Text, raw_ostream &OS)
static std::string genItalic(const Twine &Text)
volatile int MDGeneratorAnchorSource
static std::string genEmphasis(const Twine &Text)
static void genMarkdown(const ClangDocContext &CDCtx, const EnumInfo &I, llvm::raw_ostream &OS)
static void writeNewLine(raw_ostream &OS)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.
std::optional< std::string > RepositoryUrl
std::optional< std::string > RepositoryLinePrefix
llvm::SmallVector< EnumValueInfo, 4 > Members
llvm::SmallVector< FieldTypeInfo, 4 > Params
std::vector< Index > Children
llvm::SmallString< 16 > getFileBaseName() const
Returns the basename that should be used for this Info.
std::vector< CommentInfo > Description
llvm::SmallString< 64 > getRelativeFilePath(const StringRef &CurrentPath) const
Returns the file path for this Info relative to CurrentPath.
SmallString< 32 > Filename
llvm::SmallVector< MemberTypeInfo, 4 > Members
llvm::SmallVector< Reference, 4 > VirtualParents
llvm::SmallVector< Reference, 4 > Parents
SmallString< 16 > QualName
llvm::SmallString< 64 > getRelativeFilePath(const StringRef &CurrentPath) const
Returns the path for this Reference relative to CurrentPath.
llvm::SmallString< 16 > getFileBaseName() const
Returns the basename that should be used for this Reference.
std::vector< Reference > Records
std::vector< FunctionInfo > Functions
std::vector< Reference > Namespaces
std::vector< EnumInfo > Enums
std::optional< Location > DefLoc