13#include "llvm/Support/YAMLTraits.h"
14#include "llvm/Support/raw_ostream.h"
23LLVM_YAML_IS_SEQUENCE_VECTOR(
Location)
26LLVM_YAML_IS_SEQUENCE_VECTOR(
EnumInfo)
31LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr<CommentInfo>)
32LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::SmallString<16>)
39template <>
struct ScalarEnumerationTraits<
clang::AccessSpecifier> {
40 static void enumeration(IO &IO, clang::AccessSpecifier &Value) {
41 IO.enumCase(Value,
"Public", clang::AccessSpecifier::AS_public);
42 IO.enumCase(Value,
"Protected", clang::AccessSpecifier::AS_protected);
43 IO.enumCase(Value,
"Private", clang::AccessSpecifier::AS_private);
44 IO.enumCase(Value,
"None", clang::AccessSpecifier::AS_none);
48template <>
struct ScalarEnumerationTraits<
clang::TagTypeKind> {
50 IO.enumCase(Value,
"Struct", clang::TagTypeKind::Struct);
51 IO.enumCase(Value,
"Interface", clang::TagTypeKind::Interface);
52 IO.enumCase(Value,
"Union", clang::TagTypeKind::Union);
53 IO.enumCase(Value,
"Class", clang::TagTypeKind::Class);
54 IO.enumCase(Value,
"Enum", clang::TagTypeKind::Enum);
58template <>
struct ScalarEnumerationTraits<
InfoType> {
60 IO.enumCase(Value,
"Namespace", InfoType::IT_namespace);
61 IO.enumCase(Value,
"Record", InfoType::IT_record);
62 IO.enumCase(Value,
"Function", InfoType::IT_function);
63 IO.enumCase(Value,
"Enum", InfoType::IT_enum);
64 IO.enumCase(Value,
"Default", InfoType::IT_default);
69template <
unsigned U>
struct ScalarTraits<SmallString<U>> {
71 static void output(
const SmallString<U> &S,
void *, llvm::raw_ostream &
OS) {
72 for (
const auto &
C : S)
76 static StringRef
input(StringRef Scalar,
void *, SmallString<U> &Value) {
77 Value.assign(Scalar.begin(), Scalar.end());
81 static QuotingType
mustQuote(StringRef) {
return QuotingType::Single; }
84template <>
struct ScalarTraits<std::array<unsigned char, 20>> {
86 static void output(
const std::array<unsigned char, 20> &S,
void *,
87 llvm::raw_ostream &
OS) {
88 OS << toHex(toStringRef(S));
91 static StringRef
input(StringRef Scalar,
void *,
92 std::array<unsigned char, 20> &Value) {
93 if (Scalar.size() != 40)
94 return "Error: Incorrect scalar size for USR.";
95 Value = StringToSymbol(Scalar);
101 std::string HexString = fromHex(Value);
102 std::copy(HexString.begin(), HexString.end(),
USR.begin());
106 static QuotingType
mustQuote(StringRef) {
return QuotingType::Single; }
117 IO.mapOptional(
"Name", I.
Name, SmallString<16>());
118 IO.mapOptional(
"DefaultValue", I.
DefaultValue, SmallString<16>());
122 IO.mapRequired(
"USR", I.
USR);
123 IO.mapOptional(
"Name", I.
Name, SmallString<16>());
124 IO.mapOptional(
"Path", I.
Path, SmallString<128>());
125 IO.mapOptional(
"Namespace", I.
Namespace, llvm::SmallVector<Reference, 4>());
131 IO.mapOptional(
"DefLocation", I.
DefLoc, std::optional<Location>());
132 IO.mapOptional(
"Location", I.
Loc, llvm::SmallVector<Location, 2>());
137 IO.mapOptional(
"TagType", I.
TagType);
138 IO.mapOptional(
"IsTypeDef", I.
IsTypeDef,
false);
139 IO.mapOptional(
"Members", I.
Members);
140 IO.mapOptional(
"Bases", I.
Bases);
141 IO.mapOptional(
"Parents", I.
Parents, llvm::SmallVector<Reference, 4>());
143 llvm::SmallVector<Reference, 4>());
144 IO.mapOptional(
"ChildRecords", I.
Children.
Records, std::vector<Reference>());
148 IO.mapOptional(
"Template", I.
Template);
152 IO.mapOptional(
"Kind", I.
Kind, SmallString<16>());
153 IO.mapOptional(
"Text", I.
Text, SmallString<64>());
154 IO.mapOptional(
"Name", I.
Name, SmallString<16>());
155 IO.mapOptional(
"Direction", I.
Direction, SmallString<8>());
156 IO.mapOptional(
"ParamName", I.
ParamName, SmallString<16>());
157 IO.mapOptional(
"CloseName", I.
CloseName, SmallString<16>());
158 IO.mapOptional(
"SelfClosing", I.
SelfClosing,
false);
159 IO.mapOptional(
"Explicit", I.
Explicit,
false);
160 IO.mapOptional(
"Args", I.
Args, llvm::SmallVector<SmallString<16>, 4>());
161 IO.mapOptional(
"AttrKeys", I.
AttrKeys,
162 llvm::SmallVector<SmallString<16>, 4>());
164 llvm::SmallVector<SmallString<16>, 4>());
165 IO.mapOptional(
"Children", I.
Children);
172 IO.mapOptional(
"LineNumber",
Loc.LineNumber, 0);
173 IO.mapOptional(
"Filename",
Loc.Filename, SmallString<32>());
179 IO.mapOptional(
"Type",
Ref.RefType, InfoType::IT_default);
180 IO.mapOptional(
"Name",
Ref.Name, SmallString<16>());
181 IO.mapOptional(
"QualName",
Ref.QualName, SmallString<16>());
183 IO.mapOptional(
"Path",
Ref.Path, SmallString<128>());
194 IO.mapOptional(
"Name", I.
Name, SmallString<16>());
195 IO.mapOptional(
"DefaultValue", I.
DefaultValue, SmallString<16>());
205 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
214 std::vector<Reference>());
216 std::vector<Reference>());
230 IO.mapOptional(
"IsVirtual", I.
IsVirtual,
false);
234 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
235 IO.mapOptional(
"IsParent", I.
IsParent,
false);
241 IO.mapOptional(
"Name", I.
Name);
242 IO.mapOptional(
"Value", I.
Value);
243 IO.mapOptional(
"Expr", I.
ValueExpr, SmallString<16>());
250 IO.mapOptional(
"Scoped", I.
Scoped,
false);
251 IO.mapOptional(
"BaseType", I.
BaseType);
252 IO.mapOptional(
"Members", I.
Members);
260 IO.mapOptional(
"IsUsing", I.
IsUsing,
false);
267 IO.mapOptional(
"IsMethod", I.
IsMethod,
false);
269 IO.mapOptional(
"Params", I.
Params);
274 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
275 IO.mapOptional(
"Template", I.
Template);
281 IO.mapOptional(
"Contents", I.
Contents);
288 IO.mapOptional(
"Params", I.
Params);
294 IO.mapOptional(
"Params", I.
Params);
296 std::optional<TemplateSpecializationInfo>());
304template <>
struct MappingTraits<std::unique_ptr<CommentInfo>> {
305 static void mapping(IO &IO, std::unique_ptr<CommentInfo> &I) {
323 llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
333 llvm::StringMap<std::unique_ptr<doc::Info>> Infos,
335 for (
const auto &Group : Infos) {
341 llvm::SmallString<128>
Path;
342 llvm::sys::path::native(RootDir,
Path);
344 llvm::sys::path::append(
Path,
"index.yaml");
346 llvm::sys::path::append(
Path, Group.getKey() +
".yaml");
349 std::error_code FileErr;
350 llvm::raw_fd_ostream InfoOS(
Path, FileErr, llvm::sys::fs::OF_None);
352 return llvm::createStringError(FileErr,
"Error opening file '%s'",
361 return llvm::Error::success();
366 llvm::yaml::Output InfoYAML(
OS);
369 InfoYAML << *static_cast<clang::doc::NamespaceInfo *>(I);
372 InfoYAML << *static_cast<clang::doc::RecordInfo *>(I);
375 InfoYAML << *static_cast<clang::doc::EnumInfo *>(I);
378 InfoYAML << *static_cast<clang::doc::FunctionInfo *>(I);
381 InfoYAML << *static_cast<clang::doc::TypedefInfo *>(I);
384 return llvm::createStringError(llvm::inconvertibleErrorCode(),
385 "unexpected InfoType");
387 return llvm::Error::success();
391 "Generator for YAML output.");
std::vector< HeaderHandle > Path
llvm::raw_string_ostream OS
Generator for YAML documentation.
llvm::Error generateDocs(StringRef RootDir, llvm::StringMap< std::unique_ptr< doc::Info > > Infos, const ClangDocContext &CDCtx) override
static const char * Format
llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS, const ClangDocContext &CDCtx) override
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 TypeInfoMapping(IO &IO, TypeInfo &I)
static void SymbolInfoMapping(IO &IO, SymbolInfo &I)
static void RecordInfoMapping(IO &IO, RecordInfo &I)
static void InfoMapping(IO &IO, Info &I)
static void FieldTypeInfoMapping(IO &IO, FieldTypeInfo &I)
static void CommentInfoMapping(IO &IO, CommentInfo &I)
Some operations such as code completion produce a set of candidates.
Represents a symbol occurrence in the source file.
llvm::SmallVector< EnumValueInfo, 4 > Members
std::optional< TypeInfo > BaseType
SmallString< 16 > ValueExpr
SmallString< 16 > DefaultValue
llvm::SmallVector< FieldTypeInfo, 4 > Params
std::optional< TemplateInfo > Template
std::vector< CommentInfo > Description
llvm::SmallString< 128 > Path
llvm::SmallVector< Reference, 4 > Namespace
std::vector< CommentInfo > Description
llvm::SmallVector< MemberTypeInfo, 4 > Members
std::optional< TemplateInfo > Template
llvm::SmallVector< Reference, 4 > VirtualParents
llvm::SmallVector< Reference, 4 > Parents
std::vector< BaseRecordInfo > Bases
std::vector< Reference > Records
std::vector< TypedefInfo > Typedefs
std::vector< FunctionInfo > Functions
std::vector< Reference > Namespaces
std::vector< EnumInfo > Enums
llvm::SmallVector< Location, 2 > Loc
std::optional< Location > DefLoc
std::vector< TemplateParamInfo > Params
std::optional< TemplateSpecializationInfo > Specialization
SmallString< 16 > Contents
SymbolID SpecializationOf
std::vector< 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 enumeration(IO &IO, InfoType &Value)
static void enumeration(IO &IO, clang::AccessSpecifier &Value)
static void enumeration(IO &IO, clang::TagTypeKind &Value)
static void output(const SmallString< U > &S, void *, llvm::raw_ostream &OS)
static QuotingType mustQuote(StringRef)
static StringRef input(StringRef Scalar, void *, SmallString< U > &Value)
static SymbolID StringToSymbol(llvm::StringRef Value)
static StringRef input(StringRef Scalar, void *, std::array< unsigned char, 20 > &Value)
static QuotingType mustQuote(StringRef)
static void output(const std::array< unsigned char, 20 > &S, void *, llvm::raw_ostream &OS)