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");
89 if (Values.empty() || !Values[0])
90 return llvm::createStringError(llvm::inconvertibleErrorCode(),
91 "no value to reduce");
93 T *Tmp =
static_cast<T *
>(
getPtr(Merged));
94 for (
auto &I : Values)
95 Tmp->merge(std::move(*
static_cast<T *
>(
getPtr(I))));
96 return std::move(Merged);
103 for (
unsigned long I = 0; I < Children.size(); I++) {
104 if (ChildToMerge.USR == Children[I].USR)
113 for (
auto &ChildToMerge : ChildrenToMerge) {
115 if (MergeIdx == -1) {
116 Children.push_back(std::move(ChildToMerge));
119 Children[MergeIdx].merge(std::move(ChildToMerge));
125 if (Values.empty() || !Values[0])
126 return llvm::createStringError(llvm::inconvertibleErrorCode(),
127 "no info values to merge");
129 switch (Values[0]->IT) {
147 return llvm::createStringError(llvm::inconvertibleErrorCode(),
148 "unexpected info type");
150 llvm_unreachable(
"unhandled enumerator");
165 llvm::deref<std::equal_to<>>{});
176 if (FirstCI < SecondCI)
179 if (FirstCI == SecondCI) {
180 return std::lexicographical_compare(
182 Other.
Children.end(), llvm::deref<std::less<>>());
188static llvm::SmallString<64>
190 const StringRef &Name,
const StringRef &CurrentPath) {
191 llvm::SmallString<64> FilePath;
193 if (CurrentPath != Path) {
195 for (llvm::sys::path::const_iterator I =
196 llvm::sys::path::begin(CurrentPath);
197 I != llvm::sys::path::end(CurrentPath); ++I)
198 llvm::sys::path::append(FilePath,
"..");
199 llvm::sys::path::append(FilePath, Path);
205 llvm::sys::path::append(FilePath, Name);
207 return llvm::sys::path::relative_path(FilePath);
217 return llvm::SmallString<16>(
"index");
229 return llvm::SmallString<16>(
"index");
254 Ref.merge(std::move(Other.Ref));
255 SymbolInfo::merge(std::move(Other));
269 std::move(Other.Description.begin(), Other.Description.end(),
287 DefLoc = std::move(Other.DefLoc);
289 std::move(Other.Loc.begin(), Other.Loc.end(), std::back_inserter(
Loc));
291 auto *Last = llvm::unique(
Loc);
292 Loc.erase(Last,
Loc.end());
319 if (!llvm::to_underlying(
TagType))
323 Members = std::move(Other.Members);
325 Bases = std::move(Other.Bases);
327 Parents = std::move(Other.Parents);
331 Friends = std::move(Other.Friends);
337 SymbolInfo::merge(std::move(Other));
347 Members = std::move(Other.Members);
348 SymbolInfo::merge(std::move(Other));
360 Parent = std::move(Other.Parent);
362 Params = std::move(Other.Params);
363 SymbolInfo::merge(std::move(Other));
376 SymbolInfo::merge(std::move(Other));
386 Template.Constraints = std::move(Other.Template.Constraints);
388 Template.Params = std::move(Other.Template.Params);
389 SymbolInfo::merge(std::move(Other));
397 Type = std::move(Other.Type);
398 SymbolInfo::merge(std::move(Other));
420 return llvm::SmallString<16>(
"@GlobalNamespace");
424 return llvm::SmallString<16>(
"GlobalNamespace");
426 return llvm::SmallString<16>(
"@nonymous_record_" +
427 toHex(llvm::toStringRef(
USR)));
429 return llvm::SmallString<16>(
"@nonymous_enum_" +
430 toHex(llvm::toStringRef(
USR)));
432 return llvm::SmallString<16>(
"@nonymous_typedef_" +
433 toHex(llvm::toStringRef(
USR)));
435 return llvm::SmallString<16>(
"@nonymous_function_" +
436 toHex(llvm::toStringRef(
USR)));
438 return llvm::SmallString<16>(
"@nonymous_concept_" +
439 toHex(llvm::toStringRef(
USR)));
441 return llvm::SmallString<16>(
"@nonymous_variable_" +
442 toHex(llvm::toStringRef(
USR)));
444 return llvm::SmallString<16>(
"@nonymous_friend_" +
445 toHex(llvm::toStringRef(
USR)));
447 return llvm::SmallString<16>(
"@nonymous_" + toHex(llvm::toStringRef(
USR)));
449 llvm_unreachable(
"Invalid InfoType.");
450 return llvm::SmallString<16>(
"");
456 for (
unsigned I = 0; I <
Name.size() && I < Other.
Name.size(); ++I) {
458 int D = tolower(
Name[I]) - tolower(Other.
Name[I]);
467 if (
Name.size() == Other.
Name.size())
470 return Name.size() < Other.
Name.size();
475 SortedChildren.reserve(
Children.size());
477 SortedChildren.push_back(&C);
478 llvm::sort(SortedChildren,
479 [](
const Index *A,
const Index *B) {
return *A < *B; });
480 return SortedChildren;
494 clang::DiagnosticsEngine &
Diags,
500 llvm::SmallString<128> SourceRootDir(
SourceRoot);
503 llvm::sys::fs::current_path(SourceRootDir);
504 this->SourceRoot = std::string(SourceRootDir);
509 this->RepositoryUrl->insert(0,
"https://");
@ CK_InlineCommandComment
@ CK_VerbatimBlockLineComment
@ CK_VerbatimBlockComment
@ CK_TParamCommandComment
llvm::Expected< OwnedPtr< Info > > mergeInfos(OwningPtrArray< Info > &Values)
static llvm::SmallString< 64 > calculateRelativeFilePath(const InfoType &Type, const StringRef &Path, const StringRef &Name, const StringRef &CurrentPath)
std::unique_ptr< T > OwnedPtr
T * getPtr(const OwnedPtr< T > &O)
static int getChildIndexIfExists(OwningVec< T > &Children, T &ChildToMerge)
static void reduceChildren(OwningVec< T > &Children, OwningVec< T > &&ChildrenToMerge)
CommentKind stringToCommentKind(llvm::StringRef KindStr)
std::vector< OwnedPtr< T > > OwningPtrArray
static llvm::Expected< OwnedPtr< Info > > reduce(OwningPtrArray< Info > &Values)
std::vector< T > OwningVec
OwnedPtr< T > allocatePtr(Args &&...args)
std::array< uint8_t, 20 > SymbolID
llvm::StringRef commentKindToString(CommentKind Kind)
static const SymbolID EmptySID
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::optional< std::string > RepositoryUrl
std::vector< std::string > UserStylesheets
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, OutputFormatTy Format, bool FTimeTrace=false)
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
OwningVec< const Index * > getSortedChildren() const
bool operator<(const Index &Other) const
llvm::StringMap< Index > Children
SmallString< 16 > DocumentationFileName
Info(InfoType IT=InfoType::IT_default, SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
bool mergeable(const Info &Other)
OwningVec< CommentInfo > Description
llvm::SmallString< 16 > getFileBaseName() const
Returns the basename that should be used for this Info.
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)
OwningVec< BaseRecordInfo > Bases
llvm::SmallVector< MemberTypeInfo, 4 > Members
RecordInfo(SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
std::optional< TemplateInfo > Template
llvm::SmallVector< Reference, 4 > VirtualParents
llvm::SmallVector< Reference, 4 > Parents
void merge(RecordInfo &&I)
OwningVec< FriendInfo > Friends
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
OwningVec< FunctionInfo > Functions
OwningVec< TypedefInfo > Typedefs
OwningVec< EnumInfo > Enums
OwningVec< Reference > Records
OwningVec< Reference > Namespaces
OwningVec< ConceptInfo > Concepts
OwningVec< VarInfo > Variables
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())