11#include "llvm/ADT/ArrayRef.h"
12#include "llvm/ADT/StringRef.h"
13#include "llvm/Support/FileSystem.h"
14#include "llvm/Support/FormatVariadic.h"
15#include "llvm/Support/Path.h"
16#include "llvm/Support/raw_ostream.h"
27 return "*" + Text.str() +
"*";
31 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})*",
85 for (
const auto &C : Comments)
86 writeTableSafeComment(C);
97 void insertSeparator() {
100 if (NeedsParagraphBreak) {
102 NeedsParagraphBreak =
false;
109 void writeTableSafeComment(
const CommentInfo &I) {
112 for (
const auto &Child : I.Children)
113 writeTableSafeComment(Child);
117 for (
const auto &Child : I.Children)
118 writeTableSafeComment(Child);
120 NeedsParagraphBreak =
true;
124 if (!I.Text.empty()) {
133 for (
const auto &Child : I.Children)
134 writeTableSafeComment(Child);
139 llvm::raw_ostream &OS;
140 bool Started =
false;
141 bool NeedsParagraphBreak =
false;
146 const std::optional<Location> &DefLoc) {
154 for (
const auto &Child : I.
Children)
159 for (
const auto &Child : I.
Children)
166 for (
const auto &Child : I.
Children)
178 for (
const auto &Child : I.
Children)
184 for (
const auto &Child : I.
Children)
198 llvm::raw_string_ostream Attrs(Buffer);
199 for (
unsigned Idx = 0; Idx < I.
AttrKeys.size(); ++Idx)
216 OS <<
"Unknown comment kind: " <<
static_cast<int>(I.
Kind) <<
".\n\n";
222 llvm::raw_ostream &OS) {
225 llvm::sys::path::native(Path, llvm::sys::path::Style::posix);
226 llvm::sys::path::append(Path, llvm::sys::path::Style::posix,
228 OS <<
"[" << R.
Name <<
"](" << Path <<
")";
232 llvm::raw_ostream &OS) {
236 OS << (I.
Name.empty() ?
"(unnamed)" : StringRef(I.
Name)) <<
" ";
238 OS <<
": " << I.
BaseType->Type.QualName <<
" ";
242 OS <<
"| Name | Value |";
244 bool HasComments =
false;
245 for (
const auto &Member : I.
Members) {
246 if (!Member.Description.empty()) {
256 for (
const auto &N : I.
Members) {
257 OS <<
"| " << N.Name <<
" ";
258 if (!N.Value.empty())
259 OS <<
"| " << N.Value <<
" ";
263 CommentWriter.
write(N.Description);
278 llvm::raw_ostream &OS) {
280 llvm::raw_string_ostream Stream(Buffer);
282 for (
const auto &N : I.
Params) {
285 Stream << N.Type.QualName +
" " + N.Name;
289 StringRef Access = getAccessSpelling(I.
Access);
293 "(" + Twine(Stream.str()) +
")"),
303 llvm::raw_ostream &OS) {
353 llvm::raw_ostream &OS) {
366 if (!Parents.empty() || !VParents.empty()) {
368 writeLine(
"Inherits from " + VParents, OS);
369 else if (VParents.empty())
370 writeLine(
"Inherits from " + Parents, OS);
372 writeLine(
"Inherits from " + Parents +
", " + VParents, OS);
378 for (
const auto &Member : I.
Members) {
379 StringRef Access = getAccessSpelling(Member.Access);
380 writeLine(Twine(Access) + (Access.empty() ?
"" :
" ") +
381 (Member.IsStatic ?
"static " :
"") +
382 Member.Type.Name.str() +
" " + Member.Name.str(),
409 llvm::raw_ostream &OS) {
416 OS <<
"##" << std::string(Level,
'#') <<
" ";
422 std::error_code FileErr;
423 llvm::SmallString<128> FilePath;
425 llvm::sys::path::append(FilePath,
"all_files.md");
426 llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_Text);
428 return llvm::createStringError(llvm::inconvertibleErrorCode(),
429 "error creating index file: " +
439 for (
const auto *C : Children)
442 return llvm::Error::success();
446 std::error_code FileErr;
447 llvm::SmallString<128> FilePath;
449 llvm::sys::path::append(FilePath,
"index.md");
450 llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::OF_Text);
452 return llvm::createStringError(llvm::inconvertibleErrorCode(),
453 "error creating index file: " +
456 OS <<
"# " << CDCtx.
ProjectName <<
" C/C++ Reference\n\n";
458 for (
const auto *C : Children) {
459 if (!C->Children.empty()) {
461 switch (C->RefType) {
489 OS <<
"* " << Type <<
": [" << C->Name <<
"](";
490 if (!C->Path.empty())
491 OS << C->Path <<
"/";
492 OS << C->Name <<
")\n";
495 return llvm::Error::success();
517 llvm::StringSet<> CreatedDirs;
520 llvm::StringMap<std::vector<doc::Info *>> FileToInfos;
521 for (
const auto &Group : Infos) {
524 llvm::SmallString<128> Path;
525 llvm::sys::path::native(RootDir, Path);
527 if (!CreatedDirs.contains(Path)) {
528 if (std::error_code Err = llvm::sys::fs::create_directories(Path);
529 Err != std::error_code()) {
530 return llvm::createStringError(Err,
"Failed to create directory '%s'.",
533 CreatedDirs.insert(Path);
537 FileToInfos[Path].push_back(
Info);
540 for (
const auto &Group : FileToInfos) {
541 std::error_code FileErr;
542 llvm::raw_fd_ostream InfoOS(Group.getKey(), FileErr,
543 llvm::sys::fs::OF_Text);
545 return llvm::createStringError(FileErr,
"Error opening file '%s'",
546 Group.getKey().str().c_str());
549 for (
const auto &
Info : Group.getValue()) {
556 return llvm::Error::success();
582 return createStringError(llvm::inconvertibleErrorCode(),
583 "unexpected InfoType");
585 return llvm::Error::success();
599 return llvm::Error::success();
603 "Generator for MD output.");
Generator for Markdown documentation.
llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS, const ClangDocContext &CDCtx) override
llvm::Error generateDocumentation(StringRef RootDir, llvm::StringMap< doc::OwnedPtr< doc::Info > > Infos, const ClangDocContext &CDCtx, std::string DirName) override
llvm::Error createResources(ClangDocContext &CDCtx) override
static const char * Format
static void serializeReference(llvm::raw_fd_ostream &OS, const Index &I, int Level)
@ CK_InlineCommandComment
@ CK_VerbatimBlockLineComment
@ CK_VerbatimBlockComment
@ CK_TParamCommandComment
static void writeDescription(const CommentInfo &I, raw_ostream &OS)
llvm::simple_ilist< InfoNode< T > > DocList
static void writeSourceFileRef(const ClangDocContext &CDCtx, const Location &L, raw_ostream &OS)
T * getPtr(const OwnedPtr< T > &O)
llvm::StringRef getTagType(TagTypeKind AS)
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 maybeWriteSourceFileRef(llvm::raw_ostream &OS, const ClangDocContext &CDCtx, const std::optional< Location > &DefLoc)
static void writeNameLink(const StringRef &CurrentPath, const Reference &R, llvm::raw_ostream &OS)
static void writeLine(const Twine &Text, raw_ostream &OS)
static std::string genReferenceList(llvm::ArrayRef< Reference > Refs)
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::ArrayRef< EnumValueInfo > Members
std::optional< TypeInfo > BaseType
llvm::ArrayRef< FieldTypeInfo > Params
std::vector< const Index * > getSortedChildren() const
StringRef getRelativeFilePath(const StringRef &CurrentPath) const
Returns the file path for this Info relative to CurrentPath.
DocList< CommentInfo > Description
StringRef getFileBaseName() const
Returns the basename that should be used for this Info.
llvm::ArrayRef< Reference > VirtualParents
llvm::ArrayRef< Reference > Parents
llvm::ArrayRef< MemberTypeInfo > Members
StringRef getFileBaseName() const
Returns the basename that should be used for this Reference.
StringRef getRelativeFilePath(const StringRef &CurrentPath) const
Returns the path for this Reference relative to CurrentPath.
DocList< Reference > Records
DocList< EnumInfo > Enums
DocList< FunctionInfo > Functions
DocList< Reference > Namespaces
std::optional< Location > DefLoc