23#include "llvm/ADT/StringMap.h"
24#include "llvm/Support/Error.h"
25#include "llvm/Support/Path.h"
31 static const llvm::StringMap<CommentKind> KindMap = {
46 auto It = KindMap.find(KindStr);
47 if (It != KindMap.end()) {
58 return "ParagraphComment";
62 return "InlineCommandComment";
64 return "HTMLStartTagComment";
66 return "HTMLEndTagComment";
68 return "BlockCommandComment";
70 return "ParamCommandComment";
72 return "TParamCommandComment";
74 return "VerbatimBlockComment";
76 return "VerbatimBlockLineComment";
78 return "VerbatimLineComment";
82 llvm_unreachable(
"Unhandled CommentKind");
88static llvm::Expected<std::unique_ptr<Info>>
89reduce(std::vector<std::unique_ptr<Info>> &Values) {
90 if (Values.empty() || !Values[0])
91 return llvm::createStringError(llvm::inconvertibleErrorCode(),
92 "no value to reduce");
93 std::unique_ptr<Info> Merged = std::make_unique<T>(Values[0]->USR);
94 T *Tmp =
static_cast<T *
>(Merged.get());
95 for (
auto &I : Values)
96 Tmp->merge(std::move(*
static_cast<T *
>(I.get())));
97 return std::move(Merged);
104 for (
unsigned long I = 0; I < Children.size(); I++) {
105 if (ChildToMerge.USR == Children[I].USR)
113 std::vector<T> &&ChildrenToMerge) {
114 for (
auto &ChildToMerge : ChildrenToMerge) {
116 if (MergeIdx == -1) {
117 Children.push_back(std::move(ChildToMerge));
120 Children[MergeIdx].merge(std::move(ChildToMerge));
125llvm::Expected<std::unique_ptr<Info>>
127 if (Values.empty() || !Values[0])
128 return llvm::createStringError(llvm::inconvertibleErrorCode(),
129 "no info values to merge");
131 switch (Values[0]->IT) {
149 return llvm::createStringError(llvm::inconvertibleErrorCode(),
150 "unexpected info type");
152 llvm_unreachable(
"unhandled enumerator");
167 llvm::deref<std::equal_to<>>{});
178 if (FirstCI < SecondCI)
181 if (FirstCI == SecondCI) {
182 return std::lexicographical_compare(
184 Other.
Children.end(), llvm::deref<std::less<>>());
190static llvm::SmallString<64>
192 const StringRef &Name,
const StringRef &CurrentPath) {
193 llvm::SmallString<64> FilePath;
195 if (CurrentPath != Path) {
197 for (llvm::sys::path::const_iterator I =
198 llvm::sys::path::begin(CurrentPath);
199 I != llvm::sys::path::end(CurrentPath); ++I)
200 llvm::sys::path::append(FilePath,
"..");
201 llvm::sys::path::append(FilePath, Path);
207 llvm::sys::path::append(FilePath, Name);
209 return llvm::sys::path::relative_path(FilePath);
219 return llvm::SmallString<16>(
"index");
231 return llvm::SmallString<16>(
"index");
256 Ref.merge(std::move(Other.Ref));
257 SymbolInfo::merge(std::move(Other));
271 std::move(Other.Description.begin(), Other.Description.end(),
289 DefLoc = std::move(Other.DefLoc);
291 std::move(Other.Loc.begin(), Other.Loc.end(), std::back_inserter(
Loc));
293 auto *Last = llvm::unique(
Loc);
294 Loc.erase(Last,
Loc.end());
321 if (!llvm::to_underlying(
TagType))
325 Members = std::move(Other.Members);
327 Bases = std::move(Other.Bases);
329 Parents = std::move(Other.Parents);
333 Friends = std::move(Other.Friends);
339 SymbolInfo::merge(std::move(Other));
349 Members = std::move(Other.Members);
350 SymbolInfo::merge(std::move(Other));
362 Parent = std::move(Other.Parent);
364 Params = std::move(Other.Params);
365 SymbolInfo::merge(std::move(Other));
378 SymbolInfo::merge(std::move(Other));
388 Template.Constraints = std::move(Other.Template.Constraints);
390 Template.Params = std::move(Other.Template.Params);
391 SymbolInfo::merge(std::move(Other));
399 Type = std::move(Other.Type);
400 SymbolInfo::merge(std::move(Other));
422 return llvm::SmallString<16>(
"@GlobalNamespace");
426 return llvm::SmallString<16>(
"GlobalNamespace");
428 return llvm::SmallString<16>(
"@nonymous_record_" +
429 toHex(llvm::toStringRef(
USR)));
431 return llvm::SmallString<16>(
"@nonymous_enum_" +
432 toHex(llvm::toStringRef(
USR)));
434 return llvm::SmallString<16>(
"@nonymous_typedef_" +
435 toHex(llvm::toStringRef(
USR)));
437 return llvm::SmallString<16>(
"@nonymous_function_" +
438 toHex(llvm::toStringRef(
USR)));
440 return llvm::SmallString<16>(
"@nonymous_concept_" +
441 toHex(llvm::toStringRef(
USR)));
443 return llvm::SmallString<16>(
"@nonymous_variable_" +
444 toHex(llvm::toStringRef(
USR)));
446 return llvm::SmallString<16>(
"@nonymous_friend_" +
447 toHex(llvm::toStringRef(
USR)));
449 return llvm::SmallString<16>(
"@nonymous_" + toHex(llvm::toStringRef(
USR)));
451 llvm_unreachable(
"Invalid InfoType.");
452 return llvm::SmallString<16>(
"");
458 for (
unsigned I = 0; I <
Name.size() && I < Other.
Name.size(); ++I) {
460 int D = tolower(
Name[I]) - tolower(Other.
Name[I]);
469 if (
Name.size() == Other.
Name.size())
472 return Name.size() < Other.
Name.size();
487 clang::DiagnosticsEngine &
Diags,
492 llvm::SmallString<128> SourceRootDir(
SourceRoot);
495 llvm::sys::fs::current_path(SourceRootDir);
496 this->SourceRoot = std::string(SourceRootDir);
501 this->RepositoryUrl->insert(0,
"https://");
llvm::Expected< std::unique_ptr< Info > > mergeInfos(std::vector< std::unique_ptr< Info > > &Values)
@ CK_InlineCommandComment
@ CK_VerbatimBlockLineComment
@ CK_VerbatimBlockComment
@ CK_TParamCommandComment
static llvm::SmallString< 64 > calculateRelativeFilePath(const InfoType &Type, const StringRef &Path, const StringRef &Name, const StringRef &CurrentPath)
static void reduceChildren(std::vector< T > &Children, std::vector< T > &&ChildrenToMerge)
CommentKind stringToCommentKind(llvm::StringRef KindStr)
std::array< uint8_t, 20 > SymbolID
llvm::StringRef commentKindToString(CommentKind Kind)
static int getChildIndexIfExists(std::vector< T > &Children, T &ChildToMerge)
static llvm::Expected< std::unique_ptr< Info > > reduce(std::vector< std::unique_ptr< Info > > &Values)
static const SymbolID EmptySID
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::optional< std::string > RepositoryUrl
ClangDocContext(tooling::ExecutionContext *ECtx, StringRef ProjectName, bool PublicOnly, StringRef OutDirectory, StringRef SourceRoot, StringRef RepositoryUrl, StringRef RepositoryCodeLinePrefix, StringRef Base, std::vector< std::string > UserStylesheets, clang::DiagnosticsEngine &Diags, bool FTimeTrace=false)
std::vector< std::string > UserStylesheets
tooling::ExecutionContext * ECtx
clang::DiagnosticsEngine & Diags
std::optional< std::string > RepositoryLinePrefix
void merge(ConceptInfo &&I)
SmallString< 16 > ConstraintExpression
llvm::SmallVector< EnumValueInfo, 4 > Members
void merge(FriendInfo &&Other)
bool mergeable(const FriendInfo &Other)
FunctionInfo(SymbolID USR=SymbolID())
llvm::SmallVector< FieldTypeInfo, 4 > Params
void merge(FunctionInfo &&I)
std::optional< TemplateInfo > Template
std::vector< Index > Children
bool operator<(const Index &Other) const
SmallString< 16 > DocumentationFileName
Info(InfoType IT=InfoType::IT_default, SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
bool mergeable(const Info &Other)
llvm::SmallString< 16 > getFileBaseName() const
Returns the basename that should be used for this Info.
std::vector< CommentInfo > Description
llvm::SmallString< 128 > Path
llvm::SmallString< 16 > extractName() const
llvm::SmallString< 64 > getRelativeFilePath(const StringRef &CurrentPath) const
Returns the file path for this Info relative to CurrentPath.
llvm::SmallVector< Reference, 4 > Namespace
NamespaceInfo(SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
void merge(NamespaceInfo &&I)
llvm::SmallVector< MemberTypeInfo, 4 > Members
RecordInfo(SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
std::optional< TemplateInfo > Template
std::vector< FriendInfo > Friends
llvm::SmallVector< Reference, 4 > VirtualParents
llvm::SmallVector< Reference, 4 > Parents
void merge(RecordInfo &&I)
std::vector< BaseRecordInfo > Bases
void merge(Reference &&I)
Reference(SymbolID USR=SymbolID(), StringRef Name=StringRef(), InfoType IT=InfoType::IT_default)
bool mergeable(const Reference &Other)
llvm::SmallString< 128 > Path
llvm::SmallString< 64 > getRelativeFilePath(const StringRef &CurrentPath) const
Returns the path for this Reference relative to CurrentPath.
llvm::SmallString< 16 > getFileBaseName() const
Returns the basename that should be used for this Reference.
SmallString< 16 > DocumentationFileName
std::vector< Reference > Records
std::vector< TypedefInfo > Typedefs
std::vector< FunctionInfo > Functions
std::vector< Reference > Namespaces
std::vector< VarInfo > Variables
std::vector< EnumInfo > Enums
std::vector< ConceptInfo > Concepts
SymbolInfo(InfoType IT, SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
llvm::SmallVector< Location, 2 > Loc
std::optional< Location > DefLoc
SmallString< 16 > MangledName
void merge(TypedefInfo &&I)
std::optional< TemplateInfo > Template
TypedefInfo(SymbolID USR=SymbolID())