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") {
88 }
else if (I.
Kind ==
"TParamCommandComment") {
93 }
else if (I.
Kind ==
"VerbatimBlockComment") {
96 }
else if (I.
Kind ==
"VerbatimBlockLineComment") {
99 }
else if (I.
Kind ==
"VerbatimLineComment") {
102 }
else if (I.
Kind ==
"HTMLStartTagComment") {
106 llvm::raw_string_ostream Attrs(Buffer);
107 for (
unsigned Idx = 0; Idx < I.
AttrKeys.size(); ++Idx)
112 }
else if (I.
Kind ==
"HTMLEndTagComment") {
114 }
else if (I.
Kind ==
"TextComment") {
117 OS <<
"Unknown comment kind: " << I.
Kind <<
".\n\n";
122 llvm::raw_ostream &
OS) {
125 llvm::sys::path::native(
Path, llvm::sys::path::Style::posix);
126 llvm::sys::path::append(
Path, llvm::sys::path::Style::posix,
132 llvm::raw_ostream &
OS) {
140 llvm::raw_string_ostream Members(Buffer);
142 for (
const auto &N : I.
Members)
143 Members <<
"| " << N.Name <<
" |\n";
153 llvm::raw_ostream &
OS) {
155 llvm::raw_string_ostream Stream(Buffer);
157 for (
const auto &N : I.
Params) {
160 Stream << N.Type.Name +
" " + N.Name;
164 std::string Access = getAccessSpelling(I.
Access).str();
167 "(" + Stream.str() +
")"),
181 llvm::raw_ostream &
OS) {
231 llvm::raw_ostream &
OS) {
244 if (!Parents.empty() || !VParents.empty()) {
247 else if (VParents.empty())
250 writeLine(
"Inherits from " + Parents +
", " + VParents,
OS);
256 for (
const auto &Member : I.
Members) {
257 std::string Access = getAccessSpelling(Member.Access).str();
259 writeLine(Access +
" " + Member.Type.Name +
" " + Member.Name,
OS);
261 writeLine(Member.Type.Name +
" " + Member.Name,
OS);
287 llvm::raw_ostream &
OS) {
293 OS <<
"##" << std::string(Level,
'#') <<
" ";
299 std::error_code FileErr;
300 llvm::SmallString<128> FilePath;
302 llvm::sys::path::append(FilePath,
"all_files.md");
303 llvm::raw_fd_ostream
OS(FilePath, FileErr, llvm::sys::fs::OF_None);
305 return llvm::createStringError(llvm::inconvertibleErrorCode(),
306 "error creating index file: " +
318 return llvm::Error::success();
322 std::error_code FileErr;
323 llvm::SmallString<128> FilePath;
325 llvm::sys::path::append(FilePath,
"index.md");
326 llvm::raw_fd_ostream
OS(FilePath, FileErr, llvm::sys::fs::OF_None);
328 return llvm::createStringError(llvm::inconvertibleErrorCode(),
329 "error creating index file: " +
334 if (!
C.Children.empty()) {
355 OS <<
"* " <<
Type <<
": [" <<
C.Name <<
"](";
358 OS <<
C.Name <<
")\n";
361 return llvm::Error::success();
370 llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
381 llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
384 llvm::StringSet<> CreatedDirs;
387 llvm::StringMap<std::vector<doc::Info *>> FileToInfos;
388 for (
const auto &Group : Infos) {
391 llvm::SmallString<128>
Path;
392 llvm::sys::path::native(RootDir,
Path);
394 if (!CreatedDirs.contains(
Path)) {
395 if (std::error_code Err = llvm::sys::fs::create_directories(
Path);
396 Err != std::error_code()) {
397 return llvm::createStringError(Err,
"Failed to create directory '%s'.",
400 CreatedDirs.insert(
Path);
407 for (
const auto &Group : FileToInfos) {
408 std::error_code FileErr;
409 llvm::raw_fd_ostream InfoOS(Group.getKey(), FileErr,
410 llvm::sys::fs::OF_None);
412 return llvm::createStringError(FileErr,
"Error opening file '%s'",
413 Group.getKey().str().c_str());
416 for (
const auto &
Info : Group.getValue()) {
423 return llvm::Error::success();
445 return createStringError(llvm::inconvertibleErrorCode(),
446 "unexpected InfoType");
448 return llvm::Error::success();
462 return llvm::Error::success();
466 "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 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 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