13#include "llvm/ADT/STLExtras.h"
14#include "llvm/Support/YAMLTraits.h"
15#include "llvm/Support/raw_ostream.h"
24LLVM_YAML_IS_SEQUENCE_VECTOR(
Location)
27LLVM_YAML_IS_SEQUENCE_VECTOR(
EnumInfo)
37 const llvm::simple_ilist<T> &RHS) {
38 auto LIt = LHS.begin(), LEnd = LHS.end();
39 auto RIt = RHS.begin(), REnd = RHS.end();
40 for (; LIt != LEnd && RIt != REnd; ++LIt, ++RIt) {
44 return LIt == LEnd && RIt == REnd;
49 const llvm::simple_ilist<T> &RHS) {
57template <
typename T>
struct SequenceTraits<ArrayRef<T *>> {
58 static size_t size(IO &io, ArrayRef<T *> &seq) {
return seq.size(); }
59 static T *&
element(IO &io, ArrayRef<T *> &seq,
size_t index) {
61 return const_cast<T *&
>(seq[index]);
65template <
typename T>
struct SequenceTraits<
llvm::simple_ilist<T>> {
66 static size_t size(IO &io, llvm::simple_ilist<T> &seq) {
return seq.size(); }
67 static T &
element(IO &io, llvm::simple_ilist<T> &seq,
size_t index) {
68 return *std::next(seq.begin(), index);
75 return *(std::next(seq.begin(), index));
84 MappingTraits<T>::mapping(IO, *Val);
104template <
typename T>
struct SequenceTraits<ArrayRef<T>> {
105 static size_t size(IO &io, llvm::ArrayRef<T> &seq) {
return seq.size(); }
106 static T &
element(IO &io, llvm::ArrayRef<T> &seq,
size_t index) {
107 return const_cast<T &
>(seq[index]);
113template <>
struct ScalarEnumerationTraits<
clang::AccessSpecifier> {
115 IO.enumCase(Value,
"Public", clang::AccessSpecifier::AS_public);
116 IO.enumCase(Value,
"Protected", clang::AccessSpecifier::AS_protected);
117 IO.enumCase(Value,
"Private", clang::AccessSpecifier::AS_private);
118 IO.enumCase(Value,
"None", clang::AccessSpecifier::AS_none);
122template <>
struct ScalarEnumerationTraits<
clang::TagTypeKind> {
124 IO.enumCase(Value,
"Struct", clang::TagTypeKind::Struct);
125 IO.enumCase(Value,
"Interface", clang::TagTypeKind::Interface);
126 IO.enumCase(Value,
"Union", clang::TagTypeKind::Union);
127 IO.enumCase(Value,
"Class", clang::TagTypeKind::Class);
128 IO.enumCase(Value,
"Enum", clang::TagTypeKind::Enum);
132template <>
struct ScalarEnumerationTraits<
InfoType> {
145 IO.enumCase(Value,
"ParagraphComment",
148 IO.enumCase(Value,
"InlineCommandComment",
150 IO.enumCase(Value,
"HTMLStartTagComment",
152 IO.enumCase(Value,
"HTMLEndTagComment",
154 IO.enumCase(Value,
"BlockCommandComment",
156 IO.enumCase(Value,
"ParamCommandComment",
158 IO.enumCase(Value,
"TParamCommandComment",
160 IO.enumCase(Value,
"VerbatimBlockComment",
162 IO.enumCase(Value,
"VerbatimBlockLineComment",
164 IO.enumCase(Value,
"VerbatimLineComment",
175 OS << toHex(toStringRef(S));
179 if (Scalar.size() != 40)
180 return "Error: Incorrect scalar size for USR.";
187 std::string HexString = fromHex(Value);
188 llvm::copy(HexString, USR.begin());
192 static QuotingType
mustQuote(StringRef) {
return QuotingType::Single; }
200 explicit operator StringRef()
const {
return Ref; }
212 static QuotingType
mustQuote(StringRef) {
return QuotingType::Single; }
232 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
233 if (!IO.outputting())
237 IO.mapOptional(
"DefaultValue", QDefault,
QuotedString(StringRef()));
238 if (!IO.outputting())
243 IO.mapRequired(
"USR", I.
USR);
246 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
247 if (!IO.outputting())
251 IO.mapOptional(
"Path", QPath,
QuotedString(StringRef()));
252 if (!IO.outputting())
255 IO.mapOptional(
"Namespace", I.
Namespace, llvm::SmallVector<Reference, 4>());
261 IO.mapOptional(
"DefLocation", I.
DefLoc, std::optional<Location>());
262 IO.mapOptional(
"Location", I.
Loc);
267 IO.mapOptional(
"TagType", I.
TagType);
268 IO.mapOptional(
"IsTypeDef", I.
IsTypeDef,
false);
269 IO.mapOptional(
"Members", I.
Members);
270 IO.mapOptional(
"Bases", I.
Bases);
273 llvm::SmallVector<Reference, 4>());
278 IO.mapOptional(
"Template", I.
Template);
285 IO.mapOptional(
"Text", QText,
QuotedString(StringRef()));
286 if (!IO.outputting())
290 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
291 if (!IO.outputting())
295 IO.mapOptional(
"Direction", QDirection,
QuotedString(StringRef()));
296 if (!IO.outputting())
300 IO.mapOptional(
"ParamName", QParamName,
QuotedString(StringRef()));
301 if (!IO.outputting())
305 IO.mapOptional(
"CloseName", QCloseName,
QuotedString(StringRef()));
306 if (!IO.outputting())
309 IO.mapOptional(
"SelfClosing", I.
SelfClosing,
false);
310 IO.mapOptional(
"Explicit", I.
Explicit,
false);
312 std::vector<QuotedString> QArgs;
313 if (IO.outputting()) {
314 for (
auto &S : I.
Args)
317 IO.mapOptional(
"Args", QArgs, std::vector<QuotedString>());
319 std::vector<QuotedString> QAttrKeys;
320 if (IO.outputting()) {
324 IO.mapOptional(
"AttrKeys", QAttrKeys, std::vector<QuotedString>());
326 std::vector<QuotedString> QAttrValues;
327 if (IO.outputting()) {
331 IO.mapOptional(
"AttrValues", QAttrValues, std::vector<QuotedString>());
333 IO.mapOptional(
"Children", I.
Children);
343 IO.mapOptional(
"Filename", QFilename,
QuotedString(StringRef()));
344 if (!IO.outputting())
354 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
355 if (!IO.outputting())
359 IO.mapOptional(
"QualName", QQualName,
QuotedString(StringRef()));
360 if (!IO.outputting())
361 Ref.QualName = QQualName.
Ref;
366 IO.mapOptional(
"Path", QPath,
QuotedString(StringRef()));
367 if (!IO.outputting())
381 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
382 if (!IO.outputting())
386 IO.mapOptional(
"DefaultValue", QDefault,
QuotedString(StringRef()));
387 if (!IO.outputting())
398 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
406 std::vector<Reference> TempNamespaces;
408 TempNamespaces.push_back(N);
409 IO.mapOptional(
"ChildNamespaces", TempNamespaces, std::vector<Reference>());
424 IO.mapOptional(
"IsVirtual", I.
IsVirtual,
false);
428 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
429 IO.mapOptional(
"IsParent", I.
IsParent,
false);
436 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
437 if (!IO.outputting())
441 IO.mapOptional(
"Value", QValue,
QuotedString(StringRef()));
442 if (!IO.outputting())
446 IO.mapOptional(
"Expr", QExpr,
QuotedString(StringRef()));
447 if (!IO.outputting())
455 IO.mapOptional(
"Scoped", I.
Scoped,
false);
456 IO.mapOptional(
"BaseType", I.
BaseType);
457 IO.mapOptional(
"Members", I.
Members);
465 IO.mapOptional(
"IsUsing", I.
IsUsing,
false);
472 IO.mapOptional(
"IsMethod", I.
IsMethod,
false);
474 IO.mapOptional(
"Params", I.
Params);
479 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
480 IO.mapOptional(
"Template", I.
Template);
487 IO.mapOptional(
"Contents", QContents,
QuotedString(StringRef()));
488 if (!IO.outputting())
496 IO.mapOptional(
"Params", I.
Params);
502 IO.mapOptional(
"Params", I.
Params);
504 std::optional<TemplateSpecializationInfo>());
524 llvm::StringMap<doc::Info *> Infos,
526 std::string DirName)
override;
534 StringRef RootDir, llvm::StringMap<doc::Info *> Infos,
536 for (
const auto &Group : Infos) {
542 llvm::SmallString<128> Path;
543 llvm::sys::path::native(RootDir, Path);
545 llvm::sys::path::append(Path,
"index.yaml");
547 llvm::sys::path::append(Path, Group.getKey() +
".yaml");
550 std::error_code FileErr;
551 llvm::raw_fd_ostream InfoOS(Path, FileErr, llvm::sys::fs::OF_Text);
553 return llvm::createStringError(FileErr,
"Error opening file '%s'",
562 return llvm::Error::success();
567 llvm::yaml::Output InfoYAML(OS);
570 InfoYAML << *static_cast<clang::doc::NamespaceInfo *>(I);
573 InfoYAML << *static_cast<clang::doc::RecordInfo *>(I);
576 InfoYAML << *static_cast<clang::doc::EnumInfo *>(I);
579 InfoYAML << *static_cast<clang::doc::FunctionInfo *>(I);
582 InfoYAML << *static_cast<clang::doc::TypedefInfo *>(I);
589 return llvm::createStringError(llvm::inconvertibleErrorCode(),
590 "unexpected InfoType");
592 return llvm::Error::success();
596 "Generator for YAML output.");
Generator for YAML documentation.
llvm::Error generateDocumentation(StringRef RootDir, llvm::StringMap< doc::Info * > Infos, const ClangDocContext &CDCtx, std::string DirName) override
static const char * Format
llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS, const ClangDocContext &CDCtx) override
@ CK_InlineCommandComment
@ CK_VerbatimBlockLineComment
@ CK_VerbatimBlockComment
@ CK_TParamCommandComment
llvm::simple_ilist< InfoNode< T > > DocList
static GeneratorRegistry::Add< YAMLGenerator > YAML(YAMLGenerator::Format, "Generator for YAML output.")
volatile int YAMLGeneratorAnchorSource
std::array< uint8_t, 20 > SymbolID
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static void infoMapping(IO &IO, Info &I)
static void commentInfoMapping(IO &IO, CommentInfo &I)
static void fieldTypeInfoMapping(IO &IO, FieldTypeInfo &I)
static void symbolInfoMapping(IO &IO, SymbolInfo &I)
static void typeInfoMapping(IO &IO, TypeInfo &I)
static void recordInfoMapping(IO &IO, RecordInfo &I)
Some operations such as code completion produce a set of candidates.
static bool operator!=(const llvm::simple_ilist< T > &LHS, const llvm::simple_ilist< T > &RHS)
static bool operator==(const llvm::simple_ilist< T > &LHS, const llvm::simple_ilist< T > &RHS)
Represents a symbol occurrence in the source file.
llvm::ArrayRef< EnumValueInfo > Members
std::optional< TypeInfo > BaseType
llvm::ArrayRef< FieldTypeInfo > Params
std::optional< TemplateInfo > Template
DocList< CommentInfo > Description
llvm::ArrayRef< Reference > Namespace
DocList< CommentInfo > Description
llvm::ArrayRef< BaseRecordInfo > Bases
llvm::ArrayRef< Reference > VirtualParents
std::optional< TemplateInfo > Template
llvm::ArrayRef< Reference > Parents
llvm::ArrayRef< MemberTypeInfo > Members
DocList< Reference > Records
DocList< EnumInfo > Enums
DocList< FunctionInfo > Functions
DocList< Reference > Namespaces
DocList< TypedefInfo > Typedefs
std::optional< Location > DefLoc
llvm::ArrayRef< TemplateParamInfo > Params
std::optional< TemplateSpecializationInfo > Specialization
SymbolID SpecializationOf
llvm::ArrayRef< TemplateParamInfo > Params
static void mapping(IO &IO, BaseRecordInfo &I)
static void mapping(IO &IO, EnumInfo &I)
static void mapping(IO &IO, EnumValueInfo &I)
static void mapping(IO &IO, FieldTypeInfo &I)
static void mapping(IO &IO, FunctionInfo &I)
static void mapping(IO &IO, Location &Loc)
static void mapping(IO &IO, MemberTypeInfo &I)
static void mapping(IO &IO, NamespaceInfo &I)
static void mapping(IO &IO, RecordInfo &I)
static void mapping(IO &IO, Reference &Ref)
static void mapping(IO &IO, TemplateInfo &I)
static void mapping(IO &IO, TemplateParamInfo &I)
static void mapping(IO &IO, TemplateSpecializationInfo &I)
static void mapping(IO &IO, TypeInfo &I)
static void mapping(IO &IO, TypedefInfo &I)
static void mapping(IO &IO, T *&Val)
A wrapper for StringRef to force YAML traits to single-quote the string.
bool operator==(const QuotedString &Other) const
QuotedString(StringRef R)
static void enumeration(IO &IO, InfoType &Value)
static void enumeration(IO &IO, clang::AccessSpecifier &Value)
static void enumeration(IO &IO, clang::TagTypeKind &Value)
static StringRef input(StringRef Scalar, void *, QuotedString &Value)
static QuotingType mustQuote(StringRef)
static void output(const QuotedString &S, void *, llvm::raw_ostream &OS)
static SymbolID stringToSymbol(llvm::StringRef Value)
static StringRef input(StringRef Scalar, void *, SymbolID &Value)
static void output(const SymbolID &S, void *, llvm::raw_ostream &OS)
static QuotingType mustQuote(StringRef)
static T & element(IO &io, llvm::ArrayRef< T > &seq, size_t index)
static size_t size(IO &io, llvm::ArrayRef< T > &seq)
static size_t size(IO &io, ArrayRef< T * > &seq)
static T *& element(IO &io, ArrayRef< T * > &seq, size_t index)
static T & element(IO &io, clang::doc::DocList< T > &seq, size_t index)
static size_t size(IO &io, clang::doc::DocList< T > &seq)
static T & element(IO &io, llvm::simple_ilist< T > &seq, size_t index)
static size_t size(IO &io, llvm::simple_ilist< T > &seq)