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)
36template <
typename T>
struct SequenceTraits<
llvm::ArrayRef<T>> {
37 static size_t size(IO &io, llvm::ArrayRef<T> &seq) {
return seq.size(); }
38 static T &
element(IO &io, llvm::ArrayRef<T> &seq,
size_t index) {
39 return const_cast<T &
>(seq[index]);
45template <>
struct ScalarEnumerationTraits<
clang::AccessSpecifier> {
46 static void enumeration(IO &IO, clang::AccessSpecifier &Value) {
47 IO.enumCase(Value,
"Public", clang::AccessSpecifier::AS_public);
48 IO.enumCase(Value,
"Protected", clang::AccessSpecifier::AS_protected);
49 IO.enumCase(Value,
"Private", clang::AccessSpecifier::AS_private);
50 IO.enumCase(Value,
"None", clang::AccessSpecifier::AS_none);
54template <>
struct ScalarEnumerationTraits<
clang::TagTypeKind> {
56 IO.enumCase(Value,
"Struct", clang::TagTypeKind::Struct);
57 IO.enumCase(Value,
"Interface", clang::TagTypeKind::Interface);
58 IO.enumCase(Value,
"Union", clang::TagTypeKind::Union);
59 IO.enumCase(Value,
"Class", clang::TagTypeKind::Class);
60 IO.enumCase(Value,
"Enum", clang::TagTypeKind::Enum);
64template <>
struct ScalarEnumerationTraits<
InfoType> {
77 IO.enumCase(Value,
"ParagraphComment",
80 IO.enumCase(Value,
"InlineCommandComment",
82 IO.enumCase(Value,
"HTMLStartTagComment",
84 IO.enumCase(Value,
"HTMLEndTagComment",
86 IO.enumCase(Value,
"BlockCommandComment",
88 IO.enumCase(Value,
"ParamCommandComment",
90 IO.enumCase(Value,
"TParamCommandComment",
92 IO.enumCase(Value,
"VerbatimBlockComment",
94 IO.enumCase(Value,
"VerbatimBlockLineComment",
96 IO.enumCase(Value,
"VerbatimLineComment",
107 OS << toHex(toStringRef(S));
111 if (Scalar.size() != 40)
112 return "Error: Incorrect scalar size for USR.";
119 std::string HexString = fromHex(Value);
120 std::copy(HexString.begin(), HexString.end(), USR.begin());
124 static QuotingType
mustQuote(StringRef) {
return QuotingType::Single; }
132 operator StringRef()
const {
return Ref; }
144 static QuotingType
mustQuote(StringRef) {
return QuotingType::Single; }
164 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
165 if (!IO.outputting())
169 IO.mapOptional(
"DefaultValue", QDefault,
QuotedString(StringRef()));
170 if (!IO.outputting())
175 IO.mapRequired(
"USR", I.
USR);
178 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
179 if (!IO.outputting())
183 IO.mapOptional(
"Path", QPath,
QuotedString(StringRef()));
184 if (!IO.outputting())
187 IO.mapOptional(
"Namespace", I.
Namespace, llvm::SmallVector<Reference, 4>());
193 IO.mapOptional(
"DefLocation", I.
DefLoc, std::optional<Location>());
194 IO.mapOptional(
"Location", I.
Loc, llvm::SmallVector<Location, 2>());
199 IO.mapOptional(
"TagType", I.
TagType);
200 IO.mapOptional(
"IsTypeDef", I.
IsTypeDef,
false);
201 IO.mapOptional(
"Members", I.
Members);
202 IO.mapOptional(
"Bases", I.
Bases);
203 IO.mapOptional(
"Parents", I.
Parents, llvm::SmallVector<Reference, 4>());
205 llvm::SmallVector<Reference, 4>());
210 IO.mapOptional(
"Template", I.
Template);
217 IO.mapOptional(
"Text", QText,
QuotedString(StringRef()));
218 if (!IO.outputting())
222 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
223 if (!IO.outputting())
227 IO.mapOptional(
"Direction", QDirection,
QuotedString(StringRef()));
228 if (!IO.outputting())
232 IO.mapOptional(
"ParamName", QParamName,
QuotedString(StringRef()));
233 if (!IO.outputting())
237 IO.mapOptional(
"CloseName", QCloseName,
QuotedString(StringRef()));
238 if (!IO.outputting())
241 IO.mapOptional(
"SelfClosing", I.
SelfClosing,
false);
242 IO.mapOptional(
"Explicit", I.
Explicit,
false);
244 std::vector<QuotedString> QArgs;
245 if (IO.outputting()) {
246 for (
auto &S : I.
Args)
249 IO.mapOptional(
"Args", QArgs, std::vector<QuotedString>());
251 std::vector<QuotedString> QAttrKeys;
252 if (IO.outputting()) {
256 IO.mapOptional(
"AttrKeys", QAttrKeys, std::vector<QuotedString>());
258 std::vector<QuotedString> QAttrValues;
259 if (IO.outputting()) {
263 IO.mapOptional(
"AttrValues", QAttrValues, std::vector<QuotedString>());
265 IO.mapOptional(
"Children", I.
Children);
275 IO.mapOptional(
"Filename", QFilename,
QuotedString(StringRef()));
276 if (!IO.outputting())
286 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
287 if (!IO.outputting())
291 IO.mapOptional(
"QualName", QQualName,
QuotedString(StringRef()));
292 if (!IO.outputting())
293 Ref.QualName = QQualName.
Ref;
298 IO.mapOptional(
"Path", QPath,
QuotedString(StringRef()));
299 if (!IO.outputting())
313 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
314 if (!IO.outputting())
318 IO.mapOptional(
"DefaultValue", QDefault,
QuotedString(StringRef()));
319 if (!IO.outputting())
330 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
338 std::vector<Reference> TempNamespaces;
340 TempNamespaces.push_back(N);
341 IO.mapOptional(
"ChildNamespaces", TempNamespaces, std::vector<Reference>());
356 IO.mapOptional(
"IsVirtual", I.
IsVirtual,
false);
360 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
361 IO.mapOptional(
"IsParent", I.
IsParent,
false);
368 IO.mapOptional(
"Name", QName,
QuotedString(StringRef()));
369 if (!IO.outputting())
373 IO.mapOptional(
"Value", QValue,
QuotedString(StringRef()));
374 if (!IO.outputting())
378 IO.mapOptional(
"Expr", QExpr,
QuotedString(StringRef()));
379 if (!IO.outputting())
387 IO.mapOptional(
"Scoped", I.
Scoped,
false);
388 IO.mapOptional(
"BaseType", I.
BaseType);
389 IO.mapOptional(
"Members", I.
Members);
397 IO.mapOptional(
"IsUsing", I.
IsUsing,
false);
404 IO.mapOptional(
"IsMethod", I.
IsMethod,
false);
406 IO.mapOptional(
"Params", I.
Params);
411 IO.mapOptional(
"Access", I.
Access, clang::AccessSpecifier::AS_none);
412 IO.mapOptional(
"Template", I.
Template);
419 IO.mapOptional(
"Contents", QContents,
QuotedString(StringRef()));
420 if (!IO.outputting())
428 IO.mapOptional(
"Params", I.
Params);
434 IO.mapOptional(
"Params", I.
Params);
436 std::optional<TemplateSpecializationInfo>());
474 for (
const auto &Group : Infos) {
480 llvm::SmallString<128> Path;
481 llvm::sys::path::native(RootDir, Path);
483 llvm::sys::path::append(Path,
"index.yaml");
485 llvm::sys::path::append(Path, Group.getKey() +
".yaml");
488 std::error_code FileErr;
489 llvm::raw_fd_ostream InfoOS(Path, FileErr, llvm::sys::fs::OF_Text);
491 return llvm::createStringError(FileErr,
"Error opening file '%s'",
500 return llvm::Error::success();
505 llvm::yaml::Output InfoYAML(OS);
508 InfoYAML << *static_cast<clang::doc::NamespaceInfo *>(I);
511 InfoYAML << *static_cast<clang::doc::RecordInfo *>(I);
514 InfoYAML << *static_cast<clang::doc::EnumInfo *>(I);
517 InfoYAML << *static_cast<clang::doc::FunctionInfo *>(I);
520 InfoYAML << *static_cast<clang::doc::TypedefInfo *>(I);
527 return llvm::createStringError(llvm::inconvertibleErrorCode(),
528 "unexpected InfoType");
530 return llvm::Error::success();
534 "Generator for YAML output.");
Generator for YAML documentation.
llvm::Error generateDocumentation(StringRef RootDir, llvm::StringMap< doc::OwnedPtr< 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
std::unique_ptr< T > OwnedPtr
T * getPtr(const OwnedPtr< T > &O)
static GeneratorRegistry::Add< YAMLGenerator > YAML(YAMLGenerator::Format, "Generator for YAML output.")
volatile int YAMLGeneratorAnchorSource
std::vector< T > OwningVec
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::SmallVector< EnumValueInfo, 4 > Members
std::optional< TypeInfo > BaseType
llvm::SmallVector< FieldTypeInfo, 4 > Params
std::optional< TemplateInfo > Template
OwningVec< CommentInfo > Description
llvm::SmallVector< Reference, 4 > Namespace
OwningVec< CommentInfo > Description
OwningVec< BaseRecordInfo > Bases
llvm::SmallVector< MemberTypeInfo, 4 > Members
std::optional< TemplateInfo > Template
llvm::SmallVector< Reference, 4 > VirtualParents
llvm::SmallVector< Reference, 4 > Parents
OwningVec< FunctionInfo > Functions
OwningVec< TypedefInfo > Typedefs
OwningVec< EnumInfo > Enums
OwningVec< Reference > Records
llvm::simple_ilist< Reference > Namespaces
llvm::SmallVector< Location, 2 > Loc
std::optional< Location > DefLoc
OwningVec< TemplateParamInfo > Params
std::optional< TemplateSpecializationInfo > Specialization
SymbolID SpecializationOf
OwningVec< 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)
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)