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/Mutex.h"
27#include "llvm/Support/StringSaver.h"
42 llvm::sys::SmartScopedLock<true> Lock(PoolMutex);
43 return Saver.save(Name);
47 llvm::sys::SmartMutex<true> PoolMutex;
48 llvm::BumpPtrAllocator Alloc;
49 llvm::UniqueStringSaver Saver{Alloc};
58 if (T.isTriviallyEmpty())
61 if (T.isSingleStringRef()) {
62 StringRef S = T.getSingleStringRef();
68 SmallString<128> Buffer;
69 StringRef S = T.toStringRef(Buffer);
77 llvm::BumpPtrAllocator &Alloc) {
79 return llvm::ArrayRef<T>();
80 T *Allocated =
static_cast<T *
>(Alloc.Allocate<T>(V.size()));
81 std::uninitialized_move(V.begin(), V.end(), Allocated);
82 return llvm::ArrayRef<T>(Allocated, V.size());
87 llvm::BumpPtrAllocator &Alloc) {
89 return llvm::ArrayRef<T>();
90 T *Allocated =
static_cast<T *
>(Alloc.Allocate<T>(V.size()));
91 std::uninitialized_move(V.begin(), V.end(), Allocated);
92 return llvm::ArrayRef<T>(Allocated, V.size());
97 llvm::BumpPtrAllocator &Alloc) {
99 return llvm::ArrayRef<T>();
100 T *Allocated =
static_cast<T *
>(Alloc.Allocate<T>(V.size()));
101 for (
size_t Idx = 0; Idx < V.size(); ++Idx) {
102 new (Allocated + Idx) T(V[Idx], Alloc);
104 return llvm::ArrayRef<T>(Allocated, V.size());
110 return new (
TransientArena.Allocate<T>()) T(std::forward<Args>(args)...);
115 return new (
PersistentArena.Allocate<T>()) T(std::forward<Args>(args)...);
119template <
typename T,
typename... Args>
121 return new (Alloc.Allocate<T>()) T(std::forward<Args>(args)...);
124template <
typename T>
struct InfoNode :
public llvm::ilist_node<InfoNode<T>> {
128 operator T &() {
return *
Ptr; }
129 operator const T &()
const {
return *
Ptr; }
139 return *
Ptr == *Other.
Ptr;
151template <
typename T,
typename... Args>
157template <
typename T,
typename... Args>
171template <
typename T,
typename... Args>
182template <
typename T>
using DocList = llvm::simple_ilist<InfoNode<T>>;
187constexpr SymbolID GlobalNamespaceID = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
188 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
190struct BaseRecordInfo;
243 StringRef
Text = StringRef(), StringRef
Name = StringRef(),
310 StringRef
Path = StringRef())
393 TypeInfo(StringRef Name, StringRef Path = StringRef())
423 llvm::BumpPtrAllocator &Arena);
429 llvm::ArrayRef<TemplateParamInfo>
Params = {};
448 llvm::ArrayRef<TemplateParamInfo>
Params = {};
497 AccessSpecifier
Access = AccessSpecifier::AS_public;
532 StringRef
Name = StringRef(), StringRef
Path = StringRef())
535 Info(
const Info &Other, llvm::BumpPtrAllocator &Arena);
585 StringRef
Path = StringRef());
595 StringRef
Name = StringRef(), StringRef
Path = StringRef())
607 if (!
Loc.empty() && !Other.
Loc.empty() &&
Loc.front() != Other.
Loc.front())
608 return Loc.front() < Other.
Loc.front();
626 const StringRef
Name = StringRef())
635 llvm::ArrayRef<FieldTypeInfo>
Params = {};
658 llvm::ArrayRef<FieldTypeInfo>
Params = {};
668 AccessSpecifier
Access = AccessSpecifier::AS_public;
678 StringRef
Path = StringRef());
703 llvm::ArrayRef<BaseRecordInfo>
Bases =
742 AccessSpecifier
Access = AccessSpecifier::AS_public;
751 StringRef
Value = StringRef(
"0"),
836 llvm::BumpPtrAllocator &Arena);
845 tooling::ExecutionContext *
ECtx;
877static_assert(std::is_trivially_destructible_v<CommentInfo>);
878static_assert(std::is_trivially_destructible_v<ConceptInfo>);
879static_assert(std::is_trivially_destructible_v<ConstraintInfo>);
880static_assert(std::is_trivially_destructible_v<EnumInfo>);
881static_assert(std::is_trivially_destructible_v<FieldTypeInfo>);
882static_assert(std::is_trivially_destructible_v<FriendInfo>);
883static_assert(std::is_trivially_destructible_v<FunctionInfo>);
884static_assert(std::is_trivially_destructible_v<Info>);
885static_assert(std::is_trivially_destructible_v<Location>);
886static_assert(std::is_trivially_destructible_v<MemberTypeInfo>);
887static_assert(std::is_trivially_destructible_v<NamespaceInfo>);
888static_assert(std::is_trivially_destructible_v<RecordInfo>);
889static_assert(std::is_trivially_destructible_v<Reference>);
890static_assert(std::is_trivially_destructible_v<ScopeChildren>);
891static_assert(std::is_trivially_destructible_v<SymbolInfo>);
892static_assert(std::is_trivially_destructible_v<TemplateInfo>);
893static_assert(std::is_trivially_destructible_v<TemplateParamInfo>);
894static_assert(std::is_trivially_destructible_v<TemplateSpecializationInfo>);
895static_assert(std::is_trivially_destructible_v<TypeInfo>);
896static_assert(std::is_trivially_destructible_v<TypedefInfo>);
897static_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
thread_local llvm::BumpPtrAllocator PersistentArena
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)
thread_local llvm::BumpPtrAllocator TransientArena
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
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
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
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
std::optional< TemplateInfo > Template
bool mergeable(const FriendInfo &Other)
FunctionInfo(SymbolID USR=SymbolID())
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())
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
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())
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
StringRef TypeDeclaration
void merge(TypedefInfo &&I)
std::optional< TemplateInfo > Template
TypedefInfo(SymbolID USR=SymbolID())