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())
43 static void writeLine(
const Twine &Text, raw_ostream &OS) {
49 static void writeHeader(
const Twine &Text,
unsigned int Num, raw_ostream &OS) {
50 OS << std::string(Num,
'#') +
" " + Text <<
"\n\n";
60 if (I.
Kind ==
"FullComment") {
63 }
else if (I.
Kind ==
"ParagraphComment") {
67 }
else if (I.
Kind ==
"BlockCommandComment") {
71 }
else if (I.
Kind ==
"InlineCommandComment") {
73 }
else if (I.
Kind ==
"ParamCommandComment") {
76 }
else if (I.
Kind ==
"TParamCommandComment") {
79 }
else if (I.
Kind ==
"VerbatimBlockComment") {
82 }
else if (I.
Kind ==
"VerbatimBlockLineComment") {
85 }
else if (I.
Kind ==
"VerbatimLineComment") {
88 }
else if (I.
Kind ==
"HTMLStartTagComment") {
92 llvm::raw_string_ostream Attrs(Buffer);
93 for (
unsigned Idx = 0; Idx < I.
AttrKeys.size(); ++Idx)
98 }
else if (I.
Kind ==
"HTMLEndTagComment") {
100 }
else if (I.
Kind ==
"TextComment") {
103 OS <<
"Unknown comment kind: " << I.
Kind <<
".\n\n";
115 llvm::raw_string_ostream Members(Buffer);
117 for (
const auto &N : I.
Members)
118 Members <<
"| " << N <<
" |\n";
129 llvm::raw_string_ostream Stream(Buffer);
131 for (
const auto &N : I.
Params) {
134 Stream << N.Type.Name +
" " + N.Name;
141 "(" + Stream.str() +
")"),
206 if (!Parents.empty() || !VParents.empty()) {
208 writeLine(
"Inherits from " + VParents, OS);
209 else if (VParents.empty())
210 writeLine(
"Inherits from " + Parents, OS);
212 writeLine(
"Inherits from " + Parents +
", " + VParents, OS);
218 for (
const auto Member : I.
Members) {
219 std::string Access =
getAccess(Member.Access);
221 writeLine(Access +
" " + Member.Type.Name +
" " + Member.Name, OS);
223 writeLine(Member.Type.Name +
" " + Member.Name, OS);
253 llvm::Error generateDocForInfo(
Info *I, llvm::raw_ostream &OS)
override;
256 const char *MDGenerator::Format =
"md";
258 llvm::Error MDGenerator::generateDocForInfo(
Info *I, llvm::raw_ostream &OS) {
260 case InfoType::IT_namespace:
261 genMarkdown(*static_cast<clang::doc::NamespaceInfo *>(I), OS);
263 case InfoType::IT_record:
264 genMarkdown(*static_cast<clang::doc::RecordInfo *>(I), OS);
266 case InfoType::IT_enum:
267 genMarkdown(*static_cast<clang::doc::EnumInfo *>(I), OS);
269 case InfoType::IT_function:
270 genMarkdown(*static_cast<clang::doc::FunctionInfo *>(I), OS);
272 case InfoType::IT_default:
273 return llvm::make_error<llvm::StringError>(
"Unexpected info type.\n",
274 llvm::inconvertibleErrorCode());
276 return llvm::Error::success();
279 static GeneratorRegistry::Add<MDGenerator>
MD(MDGenerator::Format,
280 "Generator for MD output.");
static void writeHeader(const Twine &Text, unsigned int Num, raw_ostream &OS)
Some operations such as code completion produce a set of candidates.
static std::string genReferenceList(const llvm::SmallVectorImpl< Reference > &Refs)
static void writeDescription(const CommentInfo &I, raw_ostream &OS)
llvm::Optional< Location > DefLoc
std::vector< FunctionInfo > ChildFunctions
std::vector< FunctionInfo > ChildFunctions
std::vector< EnumInfo > ChildEnums
static void genMarkdown(const RecordInfo &I, llvm::raw_ostream &OS)
std::vector< Reference > ChildRecords
llvm::SmallVector< Reference, 4 > VirtualParents
std::string getAccess(AccessSpecifier AS)
llvm::SmallVector< FieldTypeInfo, 4 > Params
static std::string genEmphasis(const Twine &Text)
llvm::SmallVector< SmallString< 16 >, 4 > Members
std::vector< CommentInfo > Description
std::string getTagType(TagTypeKind AS)
static void writeNewLine(raw_ostream &OS)
llvm::SmallVector< Reference, 4 > Parents
static void writeLine(const Twine &Text, raw_ostream &OS)
static const char * Format
static void writeFileDefinition(const Location &L, raw_ostream &OS)
volatile int MDGeneratorAnchorSource
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static GeneratorRegistry::Add< MDGenerator > MD(MDGenerator::Format, "Generator for MD output.")
std::vector< Reference > ChildNamespaces
std::vector< Reference > ChildRecords
Generator for Markdown documentation.
SmallString< 32 > Filename
std::vector< EnumInfo > ChildEnums
llvm::SmallVector< MemberTypeInfo, 4 > Members
static std::string genItalic(const Twine &Text)