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)
39template <
typename T>
struct SequenceTraits<ArrayRef<T *>> {
40 static size_t size(IO &io, ArrayRef<T *> &seq) {
return seq.size(); }
41 static T *&
element(IO &io, ArrayRef<T *> &seq,
size_t index) {
43 return const_cast<T *&
>(seq[index]);
47template <
typename T>
struct SequenceTraits<
llvm::simple_ilist<T>> {
48 static size_t size(IO &io, llvm::simple_ilist<T> &seq) {
return seq.size(); }
49 static T &
element(IO &io, llvm::simple_ilist<T> &seq,
size_t index) {
50 return *std::next(seq.begin(), index);
57 return *(std::next(seq.begin(), index));
66 MappingTraits<T>::mapping(IO, *Val);
86template <
typename T>
struct SequenceTraits<ArrayRef<T>> {
87 static size_t size(IO &io, llvm::ArrayRef<T> &seq) {
return seq.size(); }
88 static T &
element(IO &io, llvm::ArrayRef<T> &seq,
size_t index) {
89 return const_cast<T &
>(seq[index]);
95template <>
struct ScalarEnumerationTraits<
clang::AccessSpecifier> {
96 static void enumeration(IO &IO, clang::AccessSpecifier &Value) {
97 IO.enumCase(Value,
"Public", clang::AccessSpecifier::AS_public);
98 IO.enumCase(Value,
"Protected", clang::AccessSpecifier::AS_protected);
99 IO.enumCase(Value,
"Private", clang::AccessSpecifier::AS_private);
100 IO.enumCase(Value,
"None", clang::AccessSpecifier::AS_none);
104template <>
struct ScalarEnumerationTraits<
clang::TagTypeKind> {
106 IO.enumCase(Value,
"Struct", clang::TagTypeKind::Struct);
107 IO.enumCase(Value,
"Interface", clang::TagTypeKind::Interface);
108 IO.enumCase(Value,
"Union", clang::TagTypeKind::Union);
109 IO.enumCase(Value,
"Class", clang::TagTypeKind::Class);
110 IO.enumCase(Value,
"Enum", clang::TagTypeKind::Enum);
114template <>
struct ScalarEnumerationTraits<
InfoType> {
127 IO.enumCase(Value,
"ParagraphComment",
130 IO.enumCase(Value,
"InlineCommandComment",
132 IO.enumCase(Value,
"HTMLStartTagComment",
134 IO.enumCase(Value,
"HTMLEndTagComment",
136 IO.enumCase(Value,
"BlockCommandComment",
138 IO.enumCase(Value,
"ParamCommandComment",
140 IO.enumCase(Value,
"TParamCommandComment",
142 IO.enumCase(Value,
"VerbatimBlockComment",
144 IO.enumCase(Value,
"VerbatimBlockLineComment",
146 IO.enumCase(Value,
"VerbatimLineComment",
157 OS << toHex(toStringRef(S));
161 if (Scalar.size() != 40)
162 return "Error: Incorrect scalar size for USR.";
169 std::string HexString = fromHex(Value);
170 llvm::copy(HexString, USR.begin());
174 static QuotingType
mustQuote(StringRef) {
return QuotingType::Single; }
182 explicit operator StringRef()
const {
return Ref; }
194 static QuotingType
mustQuote(StringRef) {
return QuotingType::Single; }
214 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
215 if (!IO.outputting())
219 IO.mapOptional(
"DefaultValue", QDefault,
QuotedString(StringRef()));
220 if (!IO.outputting())
225 IO.mapRequired(
"USR", I.
USR);
228 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
229 if (!IO.outputting())
233 IO.mapOptional(
"Path", QPath,
QuotedString(StringRef()));
234 if (!IO.outputting())
237 IO.mapOptional(
"Namespace", I.
Namespace, llvm::SmallVector<Reference, 4>());
243 IO.mapOptional(
"DefLocation", I.
DefLoc, std::optional<Location>());
244 IO.mapOptional(
"Location", I.
Loc);
249 IO.mapOptional(
"TagType", I.
TagType);
250 IO.mapOptional(
"IsTypeDef", I.
IsTypeDef,
false);
251 IO.mapOptional(
"Members", I.
Members);
252 IO.mapOptional(
"Bases", I.
Bases);
255 llvm::SmallVector<Reference, 4>());
260 IO.mapOptional(
"Template", I.
Template);
267 IO.mapOptional(
"Text", QText,
QuotedString(StringRef()));
268 if (!IO.outputting())
272 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
273 if (!IO.outputting())
277 IO.mapOptional(
"Direction", QDirection,
QuotedString(StringRef()));
278 if (!IO.outputting())
282 IO.mapOptional(
"ParamName", QParamName,
QuotedString(StringRef()));
283 if (!IO.outputting())
287 IO.mapOptional(
"CloseName", QCloseName,
QuotedString(StringRef()));
288 if (!IO.outputting())
291 IO.mapOptional(
"SelfClosing", I.
SelfClosing,
false);
292 IO.mapOptional(
"Explicit", I.
Explicit,
false);
294 std::vector<QuotedString> QArgs;
295 if (IO.outputting()) {
296 for (
auto &S : I.
Args)
299 IO.mapOptional(
"Args", QArgs, std::vector<QuotedString>());
301 std::vector<QuotedString> QAttrKeys;
302 if (IO.outputting()) {
306 IO.mapOptional(
"AttrKeys", QAttrKeys, std::vector<QuotedString>());
308 std::vector<QuotedString> QAttrValues;
309 if (IO.outputting()) {
313 IO.mapOptional(
"AttrValues", QAttrValues, std::vector<QuotedString>());
315 IO.mapOptional(
"Children", I.
Children);
325 IO.mapOptional(
"Filename", QFilename,
QuotedString(StringRef()));
326 if (!IO.outputting())
336 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
337 if (!IO.outputting())
341 IO.mapOptional(
"QualName", QQualName,
QuotedString(StringRef()));
342 if (!IO.outputting())
343 Ref.QualName = QQualName.
Ref;
348 IO.mapOptional(
"Path", QPath,
QuotedString(StringRef()));
349 if (!IO.outputting())
363 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
364 if (!IO.outputting())
368 IO.mapOptional(
"DefaultValue", QDefault,
QuotedString(StringRef()));
369 if (!IO.outputting())
380 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
388 std::vector<Reference> TempNamespaces;
390 TempNamespaces.push_back(N);
391 IO.mapOptional(
"ChildNamespaces", TempNamespaces, std::vector<Reference>());
406 IO.mapOptional(
"IsVirtual", I.
IsVirtual,
false);
410 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
411 IO.mapOptional(
"IsParent", I.
IsParent,
false);
418 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
419 if (!IO.outputting())
423 IO.mapOptional(
"Value", QValue,
QuotedString(StringRef()));
424 if (!IO.outputting())
428 IO.mapOptional(
"Expr", QExpr,
QuotedString(StringRef()));
429 if (!IO.outputting())
437 IO.mapOptional(
"Scoped", I.
Scoped,
false);
438 IO.mapOptional(
"BaseType", I.
BaseType);
439 IO.mapOptional(
"Members", I.
Members);
447 IO.mapOptional(
"IsUsing", I.
IsUsing,
false);
454 IO.mapOptional(
"IsMethod", I.
IsMethod,
false);
456 IO.mapOptional(
"Params", I.
Params);
461 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
462 IO.mapOptional(
"Template", I.
Template);
469 IO.mapOptional(
"Contents", QContents,
QuotedString(StringRef()));
470 if (!IO.outputting())
478 IO.mapOptional(
"Params", I.
Params);
484 IO.mapOptional(
"Params", I.
Params);
486 std::optional<TemplateSpecializationInfo>());
506 llvm::StringMap<doc::Info *> Infos,
508 std::string DirName)
override;
516 StringRef RootDir, llvm::StringMap<doc::Info *> Infos,
518 for (
const auto &Group : Infos) {
524 llvm::SmallString<128> Path;
525 llvm::sys::path::native(RootDir, Path);
527 llvm::sys::path::append(Path,
"index.yaml");
529 llvm::sys::path::append(Path, Group.getKey() +
".yaml");
532 std::error_code FileErr;
533 llvm::raw_fd_ostream InfoOS(Path, FileErr, llvm::sys::fs::OF_Text);
535 return llvm::createStringError(FileErr,
"Error opening file '%s'",
544 return llvm::Error::success();
549 llvm::yaml::Output InfoYAML(OS);
552 InfoYAML << *cast<NamespaceInfo>(I);
555 InfoYAML << *cast<RecordInfo>(I);
558 InfoYAML << *cast<EnumInfo>(I);
561 InfoYAML << *cast<FunctionInfo>(I);
564 InfoYAML << *cast<TypedefInfo>(I);
571 return llvm::createStringError(llvm::inconvertibleErrorCode(),
572 "unexpected InfoType");
574 return llvm::Error::success();
578 "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.
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)