14#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
15#define LLVM_CLANG_TOOLS_EXTRA_CLANG_DOC_REPRESENTATION_H
17#include "clang/AST/Type.h"
18#include "clang/Basic/Diagnostic.h"
19#include "clang/Basic/Specifiers.h"
20#include "clang/Tooling/Execution.h"
21#include "llvm/ADT/SmallString.h"
22#include "llvm/ADT/SmallVector.h"
23#include "llvm/ADT/ilist_node.h"
24#include "llvm/ADT/simple_ilist.h"
25#include "llvm/Support/Allocator.h"
26#include "llvm/Support/Casting.h"
27#include "llvm/Support/Mutex.h"
28#include "llvm/Support/StringSaver.h"
43 llvm::sys::SmartScopedLock<true> Lock(PoolMutex);
44 return Saver.save(Name);
48 llvm::sys::SmartMutex<true> PoolMutex;
49 llvm::BumpPtrAllocator Alloc;
50 llvm::UniqueStringSaver Saver{Alloc};
59 if (T.isTriviallyEmpty())
62 if (T.isSingleStringRef()) {
63 StringRef S = T.getSingleStringRef();
69 SmallString<128> Buffer;
70 StringRef S = T.toStringRef(Buffer);
78 llvm::BumpPtrAllocator &Alloc) {
80 return llvm::ArrayRef<T>();
81 T *Allocated =
static_cast<T *
>(Alloc.Allocate<T>(V.size()));
82 std::uninitialized_move(V.begin(), V.end(), Allocated);
83 return llvm::ArrayRef<T>(Allocated, V.size());
88 llvm::BumpPtrAllocator &Alloc) {
90 return llvm::ArrayRef<T>();
91 T *Allocated =
static_cast<T *
>(Alloc.Allocate<T>(V.size()));
92 std::uninitialized_move(V.begin(), V.end(), Allocated);
93 return llvm::ArrayRef<T>(Allocated, V.size());
98 llvm::BumpPtrAllocator &Alloc) {
100 return llvm::ArrayRef<T>();
101 T *Allocated =
static_cast<T *
>(Alloc.Allocate<T>(V.size()));
102 for (
size_t Idx = 0; Idx < V.size(); ++Idx) {
103 new (Allocated + Idx) T(V[Idx], Alloc);
105 return llvm::ArrayRef<T>(Allocated, V.size());
117 T(std::forward<Args>(args)...);
121template <
typename T,
typename... Args>
123 return new (Alloc.Allocate<T>()) T(std::forward<Args>(args)...);
126template <
typename T>
struct InfoNode :
public llvm::ilist_node<InfoNode<T>> {
130 operator T &() {
return *
Ptr; }
131 operator const T &()
const {
return *
Ptr; }
141 return *
Ptr == *Other.
Ptr;
153template <
typename T,
typename... Args>
159template <
typename T,
typename... Args>
173template <
typename T,
typename... Args>
184template <
typename T>
using DocList = llvm::simple_ilist<InfoNode<T>>;
189constexpr SymbolID GlobalNamespaceID = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
190 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
192struct BaseRecordInfo;
245 StringRef
Text = StringRef(), StringRef
Name = StringRef(),
312 StringRef
Path = StringRef())
395 TypeInfo(StringRef Name, StringRef Path = StringRef())
425 llvm::BumpPtrAllocator &Arena);
431 llvm::ArrayRef<TemplateParamInfo>
Params = {};
450 llvm::ArrayRef<TemplateParamInfo>
Params = {};
499 AccessSpecifier
Access = AccessSpecifier::AS_public;
534 StringRef
Name = StringRef(), StringRef
Path = StringRef())
537 Info(
const Info &Other, llvm::BumpPtrAllocator &Arena);
587 StringRef
Path = StringRef());
599 StringRef
Name = StringRef(), StringRef
Path = StringRef())
629 if (!
Loc.empty() && !Other.
Loc.empty() &&
Loc.front() != Other.
Loc.front())
630 return Loc.front() < Other.
Loc.front();
648 const StringRef
Name = StringRef())
660 llvm::ArrayRef<FieldTypeInfo>
Params = {};
687 llvm::ArrayRef<FieldTypeInfo>
Params = {};
697 AccessSpecifier
Access = AccessSpecifier::AS_public;
707 StringRef
Path = StringRef());
734 llvm::ArrayRef<BaseRecordInfo>
Bases =
775 AccessSpecifier
Access = AccessSpecifier::AS_public;
784 StringRef
Value = StringRef(
"0"),
868llvm::Expected<Info *>
mergeInfos(SmallVectorImpl<Info *> &Values);
873 llvm::BumpPtrAllocator &Arena);
882 tooling::ExecutionContext *
ECtx;
914static_assert(std::is_trivially_destructible_v<CommentInfo>);
915static_assert(std::is_trivially_destructible_v<ConceptInfo>);
916static_assert(std::is_trivially_destructible_v<ConstraintInfo>);
917static_assert(std::is_trivially_destructible_v<EnumInfo>);
918static_assert(std::is_trivially_destructible_v<FieldTypeInfo>);
919static_assert(std::is_trivially_destructible_v<FriendInfo>);
920static_assert(std::is_trivially_destructible_v<FunctionInfo>);
921static_assert(std::is_trivially_destructible_v<Info>);
922static_assert(std::is_trivially_destructible_v<Location>);
923static_assert(std::is_trivially_destructible_v<MemberTypeInfo>);
924static_assert(std::is_trivially_destructible_v<NamespaceInfo>);
925static_assert(std::is_trivially_destructible_v<RecordInfo>);
926static_assert(std::is_trivially_destructible_v<Reference>);
927static_assert(std::is_trivially_destructible_v<ScopeChildren>);
928static_assert(std::is_trivially_destructible_v<SymbolInfo>);
929static_assert(std::is_trivially_destructible_v<TemplateInfo>);
930static_assert(std::is_trivially_destructible_v<TemplateParamInfo>);
931static_assert(std::is_trivially_destructible_v<TemplateSpecializationInfo>);
932static_assert(std::is_trivially_destructible_v<TypeInfo>);
933static_assert(std::is_trivially_destructible_v<TypedefInfo>);
934static_assert(std::is_trivially_destructible_v<VarInfo>);
static llvm::cl::opt< std::string > RepositoryCodeLinePrefix("repository-line-prefix", llvm::cl::desc("Prefix of line code for repository."), llvm::cl::cat(ClangDocCategory))
clang::find_all_symbols::SymbolInfo SymbolInfo
StringRef intern(StringRef Name)
T * allocatePtr(llvm::BumpPtrAllocator &Alloc, Args &&...args)
@ CK_InlineCommandComment
@ CK_VerbatimBlockLineComment
@ CK_VerbatimBlockComment
@ CK_TParamCommandComment
llvm::simple_ilist< InfoNode< T > > DocList
llvm::BumpPtrAllocator & getPersistentArena()
T * allocatePersistent(Args &&...args)
T * allocateTransient(Args &&...args)
ConcurrentStringPool & getGlobalStringPool()
CommentKind stringToCommentKind(llvm::StringRef KindStr)
llvm::ArrayRef< T > deepCopyArray(llvm::ArrayRef< T > V, llvm::BumpPtrAllocator &Alloc)
InfoNode< T > * allocateListNodePersistent(Args &&...args)
InfoNode< T > * allocateListNode(llvm::BumpPtrAllocator &Alloc, Args &&...args)
StringRef internString(const Twine &T)
llvm::ArrayRef< T > allocateArray(llvm::SmallVectorImpl< T > &V, llvm::BumpPtrAllocator &Alloc)
llvm::Expected< Info * > mergeInfos(SmallVectorImpl< Info * > &Values)
InfoNode< T > * allocateListNodeTransient(Args &&...args)
constexpr SymbolID GlobalNamespaceID
llvm::BumpPtrAllocator & getTransientArena()
std::array< uint8_t, 20 > SymbolID
llvm::StringRef commentKindToString(CommentKind Kind)
llvm::Error mergeSingleInfo(doc::Info *&Reduced, doc::Info *NewInfo, llvm::BumpPtrAllocator &Arena)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
std::optional< std::string > RepositoryUrl
std::vector< std::string > UserStylesheets
llvm::StringMap< std::string > MustacheTemplates
std::vector< std::string > JsScripts
tooling::ExecutionContext * ECtx
clang::DiagnosticsEngine & Diags
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, bool Pretty=false)
std::optional< std::string > RepositoryLinePrefix
static bool classof(const Info *I)
ConceptInfo(SymbolID USR)
void merge(ConceptInfo &&I)
StringRef ConstraintExpression
ConstraintInfo(SymbolID USR, StringRef Name)
Context(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName, StringRef Path, StringRef DocumentationFileName)
llvm::ArrayRef< EnumValueInfo > Members
std::optional< TypeInfo > BaseType
static bool classof(const Info *I)
DocList< CommentInfo > Description
Comment description of this field.
bool operator==(const EnumValueInfo &Other) const
EnumValueInfo(StringRef Name=StringRef(), StringRef Value=StringRef("0"), StringRef ValueExpr=StringRef())
FieldTypeInfo(const TypeInfo &TI, StringRef Name=StringRef(), StringRef DefaultValue=StringRef())
bool operator==(const FieldTypeInfo &Other) const
FriendInfo(const InfoType IT, const SymbolID &USR, const StringRef Name=StringRef())
std::optional< TypeInfo > ReturnType
void merge(FriendInfo &&Other)
llvm::ArrayRef< FieldTypeInfo > Params
static bool classof(const Info *I)
std::optional< TemplateInfo > Template
bool mergeable(const FriendInfo &Other)
FunctionInfo(SymbolID USR=SymbolID())
static bool classof(const Info *I)
llvm::ArrayRef< FieldTypeInfo > Params
void merge(FunctionInfo &&I)
std::optional< TemplateInfo > Template
Index(StringRef Name, StringRef JumpToSection)
bool operator<(const Index &Other) const
std::optional< StringRef > JumpToSection
bool operator==(const SymbolID &Other) const
Index(SymbolID USR, StringRef Name, InfoType IT, StringRef Path)
llvm::StringMap< Index > Children
std::vector< const Index * > getSortedChildren() const
bool operator<(const InfoNode< T > &Other) const
bool operator!=(const InfoNode< T > &Other) const
const T * operator->() const
const T & operator*() const
bool operator==(const InfoNode< T > &Other) const
StringRef getRelativeFilePath(const StringRef &CurrentPath) const
Returns the file path for this Info relative to CurrentPath.
Info & operator=(Info &&Other)=default
Info(InfoType IT=InfoType::IT_default, SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
bool mergeable(const Info &Other)
DocList< CommentInfo > Description
llvm::ArrayRef< Reference > Namespace
StringRef extractName() const
StringRef DocumentationFileName
Info(Info &&Other)=default
Info(const Info &Other)=delete
StringRef getFileBaseName() const
Returns the basename that should be used for this Info.
bool operator==(const Location &Other) const
Location(int StartLineNumber=0, int EndLineNumber=0, StringRef Filename=StringRef(), bool IsFileInRootDir=false)
bool operator<(const Location &Other) const
bool operator!=(const Location &Other) const
MemberTypeInfo(const TypeInfo &TI, StringRef Name, AccessSpecifier Access, bool IsStatic=false)
DocList< CommentInfo > Description
bool operator==(const MemberTypeInfo &Other) const
NamespaceInfo(SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
static bool classof(const Info *I)
void merge(NamespaceInfo &&I)
llvm::ArrayRef< BaseRecordInfo > Bases
llvm::ArrayRef< FriendInfo > Friends
RecordInfo(SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
llvm::ArrayRef< Reference > VirtualParents
std::optional< TemplateInfo > Template
static bool classof(const Info *I)
llvm::ArrayRef< Reference > Parents
llvm::ArrayRef< MemberTypeInfo > Members
void merge(RecordInfo &&I)
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName, StringRef Path, StringRef DocumentationFileName)
void merge(Reference &&I)
StringRef DocumentationFileName
Reference(SymbolID USR, StringRef Name, InfoType IT, StringRef QualName, StringRef Path=StringRef())
Reference(SymbolID USR=SymbolID(), StringRef Name=StringRef(), InfoType IT=InfoType::IT_default)
bool mergeable(const Reference &Other)
StringRef getFileBaseName() const
Returns the basename that should be used for this Reference.
StringRef getRelativeFilePath(const StringRef &CurrentPath) const
Returns the path for this Reference relative to CurrentPath.
bool operator<(const Reference &Other) const
bool operator==(const Reference &Other) const
DocList< Reference > Records
DocList< EnumInfo > Enums
DocList< ConceptInfo > Concepts
DocList< VarInfo > Variables
DocList< FunctionInfo > Functions
DocList< Reference > Namespaces
DocList< TypedefInfo > Typedefs
SymbolInfo(InfoType IT, SymbolID USR=SymbolID(), StringRef Name=StringRef(), StringRef Path=StringRef())
static bool classof(const Info *I)
bool operator<(const SymbolInfo &Other) const
std::optional< Location > DefLoc
void merge(SymbolInfo &&I)
llvm::ArrayRef< TemplateParamInfo > Params
llvm::ArrayRef< ConstraintInfo > Constraints
std::optional< TemplateSpecializationInfo > Specialization
TemplateParamInfo()=default
TemplateParamInfo(StringRef Contents)
SymbolID SpecializationOf
TemplateSpecializationInfo()=default
llvm::ArrayRef< TemplateParamInfo > Params
TypeInfo(StringRef Name, StringRef Path=StringRef())
TypeInfo(const Reference &R)
bool operator==(const TypeInfo &Other) const
static bool classof(const Info *I)
StringRef TypeDeclaration
void merge(TypedefInfo &&I)
std::optional< TemplateInfo > Template
TypedefInfo(SymbolID USR=SymbolID())
static bool classof(const Info *I)