11#include "llvm/ADT/StringRef.h"
12#include "llvm/Support/FileSystem.h"
13#include "llvm/Support/Path.h"
24 return "*" +
Text.str() +
"*";
28 return "**" +
Text.str() +
"**";
34 llvm::raw_string_ostream Stream(Buffer);
35 for (
const auto &R : Refs) {
36 if (&R != Refs.begin())
50 OS << std::string(Num,
'#') +
" " +
Text <<
"\n\n";
57 OS <<
"*Defined at " << L.Filename <<
"#" << std::to_string(L.LineNumber)
60 OS <<
"*Defined at [" << L.Filename <<
"#" << std::to_string(L.LineNumber)
62 << llvm::sys::path::relative_path(L.Filename) <<
"#"
63 << std::to_string(L.LineNumber) <<
")"
70 if (I.
Kind ==
"FullComment") {
73 }
else if (I.
Kind ==
"ParagraphComment") {
77 }
else if (I.
Kind ==
"BlockCommandComment") {
81 }
else if (I.
Kind ==
"InlineCommandComment") {
83 }
else if (I.
Kind ==
"ParamCommandComment") {
86 }
else if (I.
Kind ==
"TParamCommandComment") {
89 }
else if (I.
Kind ==
"VerbatimBlockComment") {
92 }
else if (I.
Kind ==
"VerbatimBlockLineComment") {
95 }
else if (I.
Kind ==
"VerbatimLineComment") {
98 }
else if (I.
Kind ==
"HTMLStartTagComment") {
102 llvm::raw_string_ostream Attrs(Buffer);
103 for (
unsigned Idx = 0; Idx < I.
AttrKeys.size(); ++Idx)
108 }
else if (I.
Kind ==
"HTMLEndTagComment") {
110 }
else if (I.
Kind ==
"TextComment") {
113 OS <<
"Unknown comment kind: " << I.
Kind <<
".\n\n";
118 llvm::raw_ostream &
OS) {
121 llvm::sys::path::native(
Path, llvm::sys::path::Style::posix);
122 llvm::sys::path::append(
Path, llvm::sys::path::Style::posix,
128 llvm::raw_ostream &
OS) {
136 llvm::raw_string_ostream Members(Buffer);
138 for (
const auto &N : I.
Members)
139 Members <<
"| " << N.Name <<
" |\n";
149 llvm::raw_ostream &
OS) {
151 llvm::raw_string_ostream Stream(Buffer);
153 for (
const auto &N : I.
Params) {
156 Stream << N.Type.Name +
" " + N.Name;
160 std::string Access = getAccessSpelling(I.
Access).str();
163 "(" + Stream.str() +
")"),
177 llvm::raw_ostream &
OS) {
227 llvm::raw_ostream &
OS) {
240 if (!Parents.empty() || !VParents.empty()) {
243 else if (VParents.empty())
246 writeLine(
"Inherits from " + Parents +
", " + VParents,
OS);
252 for (
const auto &Member : I.
Members) {
253 std::string Access = getAccessSpelling(Member.Access).str();
255 writeLine(Access +
" " + Member.Type.Name +
" " + Member.Name,
OS);
257 writeLine(Member.Type.Name +
" " + Member.Name,
OS);
283 llvm::raw_ostream &
OS) {
289 OS <<
"##" << std::string(Level,
'#') <<
" ";
295 std::error_code FileErr;
296 llvm::SmallString<128> FilePath;
298 llvm::sys::path::append(FilePath,
"all_files.md");
299 llvm::raw_fd_ostream
OS(FilePath, FileErr, llvm::sys::fs::OF_None);
301 return llvm::createStringError(llvm::inconvertibleErrorCode(),
302 "error creating index file: " +
314 return llvm::Error::success();
318 std::error_code FileErr;
319 llvm::SmallString<128> FilePath;
321 llvm::sys::path::append(FilePath,
"index.md");
322 llvm::raw_fd_ostream
OS(FilePath, FileErr, llvm::sys::fs::OF_None);
324 return llvm::createStringError(llvm::inconvertibleErrorCode(),
325 "error creating index file: " +
330 if (!
C.Children.empty()) {
351 OS <<
"* " <<
Type <<
": [" <<
C.Name <<
"](";
354 OS <<
C.Name <<
")\n";
357 return llvm::Error::success();
366 llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
377 llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
380 llvm::StringSet<> CreatedDirs;
383 llvm::StringMap<std::vector<doc::Info *>> FileToInfos;
384 for (
const auto &Group : Infos) {
387 llvm::SmallString<128>
Path;
388 llvm::sys::path::native(RootDir,
Path);
390 if (!CreatedDirs.contains(
Path)) {
391 if (std::error_code Err = llvm::sys::fs::create_directories(
Path);
392 Err != std::error_code()) {
393 return llvm::createStringError(Err,
"Failed to create directory '%s'.",
396 CreatedDirs.insert(
Path);
403 for (
const auto &Group : FileToInfos) {
404 std::error_code FileErr;
405 llvm::raw_fd_ostream InfoOS(Group.getKey(), FileErr,
406 llvm::sys::fs::OF_None);
408 return llvm::createStringError(FileErr,
"Error opening file '%s'",
409 Group.getKey().str().c_str());
412 for (
const auto &
Info : Group.getValue()) {
419 return llvm::Error::success();
441 return createStringError(llvm::inconvertibleErrorCode(),
442 "unexpected InfoType");
444 return llvm::Error::success();
458 return llvm::Error::success();
462 "Generator for MD output.");
std::vector< HeaderHandle > Path
llvm::raw_string_ostream OS
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)
static void writeDescription(const CommentInfo &I, raw_ostream &OS)
static std::vector< std::unique_ptr< HTMLNode > > genReferenceList(const llvm::SmallVectorImpl< Reference > &Refs, const StringRef &CurrentDirectory)
static llvm::Error serializeIndex(ClangDocContext &CDCtx)
static GeneratorRegistry::Add< MDGenerator > MD(MDGenerator::Format, "Generator for MD output.")
static void writeHeader(const Twine &Text, unsigned int Num, raw_ostream &OS)
static llvm::Error genIndex(ClangDocContext &CDCtx)
static void writeNameLink(const StringRef &CurrentPath, const Reference &R, llvm::raw_ostream &OS)
static void writeLine(const Twine &Text, raw_ostream &OS)
static void serializeReference(llvm::raw_fd_ostream &OS, Index &I, int Level)
static std::unique_ptr< TagNode > writeFileDefinition(const Location &L, std::optional< StringRef > RepositoryUrl=std::nullopt)
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
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.
llvm::SmallVector< MemberTypeInfo, 4 > Members
llvm::SmallVector< Reference, 4 > VirtualParents
llvm::SmallVector< Reference, 4 > Parents
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