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));
270 std::move(Other.Description.begin(), Other.Description.end(),
284 DefLoc = std::move(Other.DefLoc);
286 std::move(Other.Loc.begin(), Other.Loc.end(), std::back_inserter(
Loc));
288 auto *Last = llvm::unique(
Loc);
289 Loc.erase(Last,
Loc.end());
316 if (!llvm::to_underlying(
TagType))
320 Members = std::move(Other.Members);
322 Bases = std::move(Other.Bases);
324 Parents = std::move(Other.Parents);
328 Friends = std::move(Other.Friends);
334 SymbolInfo::merge(std::move(Other));
344 Members = std::move(Other.Members);
345 SymbolInfo::merge(std::move(Other));
357 Parent = std::move(Other.Parent);
359 Params = std::move(Other.Params);
360 SymbolInfo::merge(std::move(Other));
371 SymbolInfo::merge(std::move(Other));
381 Template.Constraints = std::move(Other.Template.Constraints);
383 Template.Params = std::move(Other.Template.Params);
384 SymbolInfo::merge(std::move(Other));
392 Type = std::move(Other.Type);
393 SymbolInfo::merge(std::move(Other));
415 return llvm::SmallString<16>(
"@GlobalNamespace");
419 return llvm::SmallString<16>(
"GlobalNamespace");
421 return llvm::SmallString<16>(
"@nonymous_record_" +
422 toHex(llvm::toStringRef(
USR)));
424 return llvm::SmallString<16>(
"@nonymous_enum_" +
425 toHex(llvm::toStringRef(
USR)));
427 return llvm::SmallString<16>(
"@nonymous_typedef_" +
428 toHex(llvm::toStringRef(
USR)));
430 return llvm::SmallString<16>(
"@nonymous_function_" +
431 toHex(llvm::toStringRef(
USR)));
433 return llvm::SmallString<16>(
"@nonymous_concept_" +
434 toHex(llvm::toStringRef(
USR)));
436 return llvm::SmallString<16>(
"@nonymous_variable_" +
437 toHex(llvm::toStringRef(
USR)));
439 return llvm::SmallString<16>(
"@nonymous_friend_" +
440 toHex(llvm::toStringRef(
USR)));
442 return llvm::SmallString<16>(
"@nonymous_" + toHex(llvm::toStringRef(
USR)));
444 llvm_unreachable(
"Invalid InfoType.");
445 return llvm::SmallString<16>(
"");
451 for (
unsigned I = 0; I <
Name.size() && I < Other.
Name.size(); ++I) {
453 int D = tolower(
Name[I]) - tolower(Other.
Name[I]);
462 if (
Name.size() == Other.
Name.size())
465 return Name.size() < Other.
Name.size();
480 clang::DiagnosticsEngine &
Diags,
485 llvm::SmallString<128> SourceRootDir(
SourceRoot);
488 llvm::sys::fs::current_path(SourceRootDir);
489 this->SourceRoot = std::string(SourceRootDir);
494 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
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)
TypedefInfo(SymbolID USR=SymbolID())